From: <sag...@us...> - 2013-11-13 19:23:34
|
Revision: 3209 http://sourceforge.net/p/modplug/code/3209 Author: saga-games Date: 2013-11-13 19:23:27 +0000 (Wed, 13 Nov 2013) Log Message: ----------- [New] Tree view: Backspace can now be used to go up one directory in the instrument library. [Fix] Tree view: Highlighting the previously selected directory in the instrument library when changing directories broke during refactoring. [Mod] OpenMPT: Version is now 1.22.06.02 Modified Paths: -------------- trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/mptrack/View_tre.h Modified: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h 2013-11-13 18:56:32 UTC (rev 3208) +++ trunk/OpenMPT/common/versionNumber.h 2013-11-13 19:23:27 UTC (rev 3209) @@ -17,7 +17,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 22 #define VER_MINOR 06 -#define VER_MINORMINOR 02 +#define VER_MINORMINOR 03 //Version string. For example "1.17.02.28" #define MPT_VERSION_STR VER_STRINGIZE(VER_MAJORMAJOR) "." VER_STRINGIZE(VER_MAJOR) "." VER_STRINGIZE(VER_MINOR) "." VER_STRINGIZE(VER_MINORMINOR) Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-13 18:56:32 UTC (rev 3208) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-13 19:23:27 UTC (rev 3209) @@ -178,20 +178,20 @@ } ModifyStyle(dwRemove, dwAdd); - m_szInstrLibPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_SAMPLES); - if(m_szInstrLibPath.empty()) + m_InstrLibPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_SAMPLES); + if(m_InstrLibPath.empty()) { - m_szInstrLibPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_INSTRUMENTS); - if(m_szInstrLibPath.empty()) + m_InstrLibPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_INSTRUMENTS); + if(m_InstrLibPath.empty()) { // Resort to current directory. WCHAR curDir[MAX_PATH]; GetCurrentDirectoryW(CountOf(curDir), curDir); - m_szInstrLibPath = mpt::PathString::FromNative(curDir); + m_InstrLibPath = mpt::PathString::FromNative(curDir); } } - if(!m_szInstrLibPath.HasTrailingSlash()) - m_szInstrLibPath += MPT_PATHSTRING("\\"); + if(!m_InstrLibPath.HasTrailingSlash()) + m_InstrLibPath += MPT_PATHSTRING("\\"); SetImageList(CMainFrame::GetMainFrame()->GetImageList(), TVSIL_NORMAL); if (!IsSampleBrowser()) @@ -217,12 +217,13 @@ if (!pMsg) return TRUE; if (pMsg->message == WM_KEYDOWN) { - if (pMsg->wParam == VK_SPACE) + switch(pMsg->wParam) { - if (!(pMsg->lParam & 0x40000000)) OnPlayTreeItem(); + case VK_SPACE: + if(!(pMsg->lParam & 0x40000000)) OnPlayTreeItem(); return TRUE; - } else if (pMsg->wParam == VK_RETURN) - { + + case VK_RETURN: if(doLabelEdit) { // End editing by making edit box lose focus. @@ -230,14 +231,14 @@ return TRUE; } - if (!(pMsg->lParam & 0x40000000)) + if(!(pMsg->lParam & 0x40000000)) { HTREEITEM hItem = GetSelectedItem(); - if (hItem) + if(hItem) { - if (!ExecuteItem(hItem)) + if(!ExecuteItem(hItem)) { - if (ItemHasChildren(hItem)) + if(ItemHasChildren(hItem)) { Expand(hItem, TVE_TOGGLE); } @@ -245,13 +246,22 @@ } } return TRUE; - } else if(pMsg->wParam == VK_TAB) - { + + case VK_TAB: + // Tab: Switch between folder and file view. if(this == CMainFrame::GetMainFrame()->GetUpperTreeview()) CMainFrame::GetMainFrame()->GetLowerTreeview()->SetFocus(); else CMainFrame::GetMainFrame()->GetUpperTreeview()->SetFocus(); return TRUE; + + case VK_BACK: + // Backspace: Go up one directory + if(!IsSampleBrowser() && GetParentRootItem(GetSelectedItem()) == m_hInsLib) + { + InstrumentLibraryChDir(MPT_PATHSTRING(".."), false); + } + return TRUE; } } //rewbs.customKeys @@ -279,7 +289,7 @@ mpt::PathString CModTree::InsLibGetFullPath(HTREEITEM hItem) const //---------------------------------------------------------------- { - mpt::PathString fullPath = m_szInstrLibPath; + mpt::PathString fullPath = m_InstrLibPath; if(!fullPath.HasTrailingSlash()) fullPath += MPT_PATHSTRING("\\"); return fullPath + mpt::PathString::FromWide(GetItemTextW(hItem)); } @@ -288,13 +298,13 @@ void CModTree::InsLibSetFullPath(const mpt::PathString &libPath, const mpt::PathString &songName) //----------------------------------------------------------------------------------------------- { - m_szInstrLibPath = libPath; - if(!songName.empty() && mpt::PathString::CompareNoCase(m_szSongName, songName)) + m_InstrLibPath = libPath; + if(!songName.empty() && mpt::PathString::CompareNoCase(m_SongFileName, songName)) { // Load module for previewing its instruments CMappedFile f; - if (f.Open(libPath + songName)) + if(f.Open(libPath + songName)) { FileReader file = f.GetFile(); if (file.IsValid()) @@ -316,7 +326,7 @@ } } } - m_szSongName = songName; + m_SongFileName = songName; } @@ -388,12 +398,7 @@ CModDoc *CModTree::GetDocumentFromItem(HTREEITEM hItem) //----------------------------------------------------- { - for (int ilimit=0; ilimit<10; ilimit++) - { - HTREEITEM h = GetParentItem(hItem); - if (h == nullptr) break; - hItem = h; - } + hItem = GetParentRootItem(hItem); if (hItem != nullptr) { // Root item has moddoc pointer @@ -654,7 +659,7 @@ SetRedraw(TRUE); if (m_pDataTree) { - m_pDataTree->InsLibSetFullPath(m_szInstrLibPath, m_szSongName); + m_pDataTree->InsLibSetFullPath(m_InstrLibPath, m_SongFileName); m_pDataTree->RefreshInstrumentLibrary(); } } @@ -1070,15 +1075,9 @@ DWORD_PTR itemData = GetItemData(hItem); CModDoc *pModDoc = GetDocumentFromItem(hItem); - if ((hRootParent != NULL) && !IsSampleBrowser()) + if(hRootParent != nullptr && !IsSampleBrowser()) { - HTREEITEM h; - for (;;) - { - h = GetParentItem(hRootParent); - if ((!h) || (h == hRootParent)) break; - hRootParent = h; - } + hRootParent = GetParentRootItem(hRootParent); } // Midi Library if ((hRootParent == m_hMidiLib) && !IsSampleBrowser()) @@ -1299,7 +1298,7 @@ case MODITEM_INSLIB_SAMPLE: case MODITEM_INSLIB_INSTRUMENT: - if(!m_szSongName.empty()) + if(!m_SongFileName.empty()) { // Preview sample / instrument in module char szName[16]; @@ -1572,10 +1571,10 @@ if (!m_hInsLib) return; SetRedraw(FALSE); - if(!m_szSongName.empty() && IsSampleBrowser() && m_SongFile) + if(!m_SongFileName.empty() && IsSampleBrowser() && m_SongFile) { // Fill browser with samples / instruments of module file - SetItemText(m_hInsLib, m_szSongName.AsNative().c_str()); + SetItemText(m_hInsLib, m_SongFileName.AsNative().c_str()); SetItemImage(m_hInsLib, IMAGE_FOLDERSONG, IMAGE_FOLDERSONG); for(INSTRUMENTINDEX ins = 1; ins <= m_SongFile->GetNumInstruments(); ins++) { @@ -1602,11 +1601,11 @@ std::wstring text; if(!IsSampleBrowser()) { - text = L"Instrument Library (" + m_szInstrLibPath.ToWide() + L")"; + text = L"Instrument Library (" + m_InstrLibPath.ToWide() + L")"; SetItemText(m_hInsLib, text.c_str()); } else { - SetItemText(m_hInsLib, m_szInstrLibPath.ToWide().c_str()); + SetItemText(m_hInsLib, m_InstrLibPath.ToWide().c_str()); SetItemImage(m_hInsLib, IMAGE_FOLDER, IMAGE_FOLDER); } @@ -1638,7 +1637,7 @@ std::vector<const char *> modExts = CSoundFile::GetSupportedExtensions(false); // Enumerating Directories and samples/instruments - const mpt::PathString path = m_szInstrLibPath + MPT_PATHSTRING("*.*"); + const mpt::PathString path = m_InstrLibPath + MPT_PATHSTRING("*.*"); HANDLE hFind; WIN32_FIND_DATAW wfd; @@ -1754,7 +1753,7 @@ if(m_hWatchDir == nullptr) { - m_hWatchDir = FindFirstChangeNotificationW(m_szInstrLibPath.AsNative().c_str(), FALSE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME); + m_hWatchDir = FindFirstChangeNotificationW(m_InstrLibPath.AsNative().c_str(), FALSE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME); } } @@ -1797,7 +1796,7 @@ dwId = 3; break; case IMAGE_SAMPLES: - if(!m_szSongName.empty()) { dwId = 5; break; } + if(!m_SongFileName.empty()) { dwId = 5; break; } case IMAGE_INSTRUMENTS: dwId = 4; break; @@ -1854,11 +1853,10 @@ bool ok = false; if(isSong) { - m_szOldPath = MPT_PATHSTRING(".."); - m_szSongName = dir; - if (m_pDataTree) + m_InstrLibHighlightPath = m_SongFileName = dir; + if(!IsSampleBrowser()) { - m_pDataTree->InsLibSetFullPath(m_szInstrLibPath, m_szSongName); + m_pDataTree->InsLibSetFullPath(m_InstrLibPath, m_SongFileName); m_pDataTree->RefreshInstrumentLibrary(); } else { @@ -1870,10 +1868,11 @@ if(dir == MPT_PATHSTRING("..")) { // Go one dir up. - std::wstring prevDir = m_szInstrLibPath.GetPath().ToWide(); + std::wstring prevDir = m_InstrLibPath.GetPath().ToWide(); std::wstring::size_type pos = prevDir.find_last_of(L"\\/", prevDir.length() - 2); if(pos != std::wstring::npos) { + m_InstrLibHighlightPath = mpt::PathString::FromWide(prevDir.substr(pos + 1, prevDir.length() - pos - 2)); // Highlight previously accessed directory prevDir = prevDir.substr(0, pos + 1); } dir = mpt::PathString::FromWide(prevDir); @@ -1881,15 +1880,16 @@ { // Drives are formatted like "E:\", folders are just folder name without slash. if(!dir.HasTrailingSlash()) - dir = m_szInstrLibPath + dir + MPT_PATHSTRING("\\"); + dir = m_InstrLibPath + dir + MPT_PATHSTRING("\\"); + m_InstrLibHighlightPath = MPT_PATHSTRING(".."); // Highlight first entry } if(GetFileAttributesW(dir.AsNative().c_str()) & FILE_ATTRIBUTE_DIRECTORY) { - m_szSongName = MPT_PATHSTRING(""); + m_SongFileName = MPT_PATHSTRING(""); delete m_SongFile; m_SongFile = nullptr; - m_szInstrLibPath = dir; + m_InstrLibPath = dir; PostMessage(WM_COMMAND, ID_MODTREE_REFRESHINSTRLIB); ok = true; } @@ -1942,7 +1942,7 @@ case MODITEM_INSLIB_SAMPLE: case MODITEM_INSLIB_INSTRUMENT: - if(!m_szSongName.empty()) + if(!m_SongFileName.empty()) { CHAR s[32]; mpt::String::CopyN(s, GetItemText(m_hItemDrag)); @@ -2574,7 +2574,7 @@ case MODITEM_INSLIB_SAMPLE: case MODITEM_INSLIB_INSTRUMENT: nDefault = ID_MODTREE_PLAY; - if(!m_szSongName.empty()) + if(!m_SongFileName.empty()) { AppendMenu(hMenu, MF_STRING, ID_MODTREE_PLAY, "&Play"); } else @@ -3227,21 +3227,21 @@ if (!IsSampleBrowser()) { hActive = NULL; - if(!m_szOldPath.empty() || !m_szSongName.empty()) + if(!m_InstrLibHighlightPath.empty() || !m_SongFileName.empty()) { HTREEITEM hItem = GetChildItem(m_hInsLib); while (hItem != NULL) { const mpt::PathString str = mpt::PathString::FromWide(GetItemTextW(hItem)); - if((!m_szSongName.empty() && !mpt::PathString::CompareNoCase(str, m_szSongName)) - || (m_szSongName.empty() && !mpt::PathString::CompareNoCase(str, m_szOldPath))) + if((!m_SongFileName.empty() && !mpt::PathString::CompareNoCase(str, m_SongFileName)) + || (m_SongFileName.empty() && !mpt::PathString::CompareNoCase(str, m_InstrLibHighlightPath))) { hActive = hItem; break; } hItem = GetNextItem(hItem, TVGN_NEXT); } - if(m_szSongName.empty()) m_szOldPath = MPT_PATHSTRING(""); + if(m_SongFileName.empty()) m_InstrLibHighlightPath = MPT_PATHSTRING(""); } SelectSetFirstVisible(m_hInsLib); if (hActive != NULL) SelectItem(hActive); @@ -3390,6 +3390,23 @@ } +// Gets the root parent of an item, i.e. if C is a child of B and B is a child of A, GetParentRootItem(C) returns A. +HTREEITEM CModTree::GetParentRootItem(HTREEITEM hItem) +//---------------------------------------------------- +{ + if(hItem != nullptr) + { + for(;;) + { + const HTREEITEM h = GetParentItem(hItem); + if(h == nullptr || h == hItem) break; + hItem = h; + } + } + return hItem; +} + + // Editing sample, instrument, order, pattern, etc. labels void CModTree::OnBeginLabelEdit(NMHDR *nmhdr, LRESULT *result) //------------------------------------------------------------ Modified: trunk/OpenMPT/mptrack/View_tre.h =================================================================== --- trunk/OpenMPT/mptrack/View_tre.h 2013-11-13 18:56:32 UTC (rev 3208) +++ trunk/OpenMPT/mptrack/View_tre.h 2013-11-13 19:23:27 UTC (rev 3209) @@ -176,10 +176,14 @@ HTREEITEM m_tiPerc[128]; std::vector<HTREEITEM> m_tiDLS; std::vector<ModTreeDocInfo *> DocInfo; + // Instrument library - bool m_bShowAllFiles, doLabelEdit; - mpt::PathString m_szInstrLibPath, m_szOldPath; - mpt::PathString m_szSongName; // Name of open module, without path (== m_szInstrLibPath). + mpt::PathString m_InstrLibPath; // Current path to be explored + mpt::PathString m_InstrLibHighlightPath; // Folder to highlight in browser after a refresh + mpt::PathString m_SongFileName; // Name of open module, without path (== m_szInstrLibPath). + bool m_bShowAllFiles; + + bool doLabelEdit; public: CModTree(CModTree *pDataTree); @@ -216,6 +220,7 @@ bool IsItemExpanded(HTREEITEM hItem); void DeleteChildren(HTREEITEM hItem); HTREEITEM GetNthChildItem(HTREEITEM hItem, int index); + HTREEITEM GetParentRootItem(HTREEITEM hItem); bool IsSampleBrowser() const { return m_pDataTree == nullptr; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-13 19:38:10
|
Revision: 3210 http://sourceforge.net/p/modplug/code/3210 Author: manxorist Date: 2013-11-13 19:38:03 +0000 (Wed, 13 Nov 2013) Log Message: ----------- [Ref] Remove mpt::PathString::NativeRef() and replace the only usage site with an explicit copy from AsNative() (scope life-time of .c_str() is neede in FileDialog::Show()). [Fix] Do not return string values by const reference in getter functions. This could silently cause temporary objects to be created by accident later on if the type of the return expression is changed to a type implicitely convertible to the return type by some other (potentially not directly related) refactoring. All users have been reviewed if they actually depended on the reference semantics (and none of them did). Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/FileDialog.cpp trunk/OpenMPT/mptrack/FileDialog.h trunk/OpenMPT/soundlib/tuning.h trunk/OpenMPT/soundlib/tuningbase.h trunk/OpenMPT/soundlib/tuningcollection.h Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -73,10 +73,6 @@ return a.AsNative() != b.AsNative(); } bool empty() const { return path.empty(); } - const RawPathString &NativeRef() const - { - return path; - } #if defined(WIN32) static int CompareNoCase(const PathString & a, const PathString & b) Modified: trunk/OpenMPT/mptrack/FileDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/FileDialog.cpp 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/mptrack/FileDialog.cpp 2013-11-13 19:38:03 UTC (rev 3210) @@ -31,6 +31,8 @@ filenameBuffer.insert(filenameBuffer.begin(), defaultFilename.begin(), defaultFilename.end()); filenameBuffer.push_back(0); + const std::wstring workingDirectoryNative = workingDirectory.AsNative(); + // First, set up the dialog... OPENFILENAMEW ofn; MemsetZero(ofn); @@ -45,7 +47,7 @@ ofn.nMaxFile = filenameBuffer.size(); ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = workingDirectory.empty() ? NULL : workingDirectory.NativeRef().c_str(); + ofn.lpstrInitialDir = workingDirectory.empty() ? NULL : workingDirectoryNative.c_str(); ofn.lpstrTitle = NULL; ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_ENABLESIZING | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | (multiSelect ? OFN_ALLOWMULTISELECT : 0) | (load ? 0 : (OFN_OVERWRITEPROMPT | OFN_NOREADONLYRETURN)); ofn.nFileOffset = 0; Modified: trunk/OpenMPT/mptrack/FileDialog.h =================================================================== --- trunk/OpenMPT/mptrack/FileDialog.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/mptrack/FileDialog.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -55,13 +55,22 @@ bool Show(); // Get some selected file. Mostly useful when only one selected file is possible anyway. - const mpt::PathString &GetFirstFile() const { return filenames.front(); } - // Gets all selected files. + mpt::PathString GetFirstFile() const + { + if(!filenames.empty()) + { + return filenames.front(); + } else + { + return mpt::PathString(); + } + } + // Gets a reference to all selected filenames. const PathList &GetFilenames() const { return filenames; } // Gets directory in which the selected files are placed. - const mpt::PathString &GetWorkingDirectory() const { return workingDirectory; } + mpt::PathString GetWorkingDirectory() const { return workingDirectory; } // Gets the extension of the first selected file, without dot. - const mpt::PathString &GetExtension() const { return extension; } + mpt::PathString GetExtension() const { return extension; } protected: static UINT_PTR CALLBACK OFNHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam); @@ -100,7 +109,7 @@ bool Show(); // Gets selected directory. - const mpt::PathString &GetDirectory() const { return workingDirectory; } + mpt::PathString GetDirectory() const { return workingDirectory; } protected: static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData); Modified: trunk/OpenMPT/soundlib/tuning.h =================================================================== --- trunk/OpenMPT/soundlib/tuning.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/soundlib/tuning.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -131,7 +131,7 @@ //For example GetRefNote(-1) is to return note :'groupsize-1'. NOTEINDEXTYPE GetRefNote(NOTEINDEXTYPE note) const; - virtual const std::string& GetDerivedClassID() const {return s_DerivedclassID;} + virtual std::string GetDerivedClassID() const {return s_DerivedclassID;} private: //PRIVATE METHODS: Modified: trunk/OpenMPT/soundlib/tuningbase.h =================================================================== --- trunk/OpenMPT/soundlib/tuningbase.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/soundlib/tuningbase.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -226,7 +226,7 @@ TUNINGTYPE GetType() const {return m_TuningType;} //This is appended to baseclassID in serialization with which objects are identified when loading. - virtual const std::string& GetDerivedClassID() const = 0; + virtual std::string GetDerivedClassID() const = 0; //Return true if data loading failed, false otherwise. virtual bool ProProcessUnserializationdata() = 0; Modified: trunk/OpenMPT/soundlib/tuningcollection.h =================================================================== --- trunk/OpenMPT/soundlib/tuningcollection.h 2013-11-13 19:23:27 UTC (rev 3209) +++ trunk/OpenMPT/soundlib/tuningcollection.h 2013-11-13 19:38:03 UTC (rev 3210) @@ -92,10 +92,10 @@ size_t GetNumTunings() const {return m_Tunings.size();} - const std::string& GetName() const {return m_Name;} + std::string GetName() const {return m_Name;} void SetSavefilePath(const mpt::PathString &psz) {m_SavefilePath = psz;} - const mpt::PathString& GetSaveFilePath() const {return m_SavefilePath;} + mpt::PathString GetSaveFilePath() const {return m_SavefilePath;} std::string GetVersionString() const {return Stringify(static_cast<int>(s_SerializationVersion));} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-14 17:27:57
|
Revision: 3213 http://sourceforge.net/p/modplug/code/3213 Author: manxorist Date: 2013-11-14 17:27:46 +0000 (Thu, 14 Nov 2013) Log Message: ----------- [Ref] Rename CharsetUS_ASCII to simply CharsetASCII. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/Settings.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-13 22:31:02 UTC (rev 3212) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-14 17:27:46 UTC (rev 3213) @@ -65,7 +65,7 @@ { case CharsetLocale: return CP_ACP; break; case CharsetUTF8: return CP_UTF8; break; - case CharsetUS_ASCII: return 20127; break; + case CharsetASCII: return 20127; break; case CharsetISO8859_1: return 28591; break; case CharsetISO8859_15: return 28605; break; case CharsetCP437: return 437; break; @@ -80,7 +80,7 @@ { case CharsetLocale: return ""; break; // "char" breaks with glibc when no locale is set case CharsetUTF8: return "UTF-8"; break; - case CharsetUS_ASCII: return "ASCII"; break; + case CharsetASCII: return "ASCII"; break; case CharsetISO8859_1: return "ISO-8859-1"; break; case CharsetISO8859_15: return "ISO-8859-15"; break; case CharsetCP437: return "CP437"; break; @@ -94,7 +94,7 @@ { case CharsetLocale: return "//TRANSLIT"; break; // "char" breaks with glibc when no locale is set case CharsetUTF8: return "UTF-8//TRANSLIT"; break; - case CharsetUS_ASCII: return "ASCII//TRANSLIT"; break; + case CharsetASCII: return "ASCII//TRANSLIT"; break; case CharsetISO8859_1: return "ISO-8859-1//TRANSLIT"; break; case CharsetISO8859_15: return "ISO-8859-15//TRANSLIT"; break; case CharsetCP437: return "CP437//TRANSLIT"; break; Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-13 22:31:02 UTC (rev 3212) +++ trunk/OpenMPT/common/mptString.h 2013-11-14 17:27:46 UTC (rev 3213) @@ -140,7 +140,7 @@ CharsetUTF8, - CharsetUS_ASCII, // strictly 7-bit ASCII + CharsetASCII, // strictly 7-bit ASCII CharsetISO8859_1, CharsetISO8859_15, Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-13 22:31:02 UTC (rev 3212) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-14 17:27:46 UTC (rev 3213) @@ -221,16 +221,16 @@ std::string module_impl::mod_string_to_utf8( const std::string & encoded ) const { std::string encoding = m_sndFile->GetCharset().second; std::transform( encoding.begin(), encoding.end(), encoding.begin(), tolower ); - mpt::Charset charset = mpt::CharsetUS_ASCII; - if ( encoding == "" ) { charset = mpt::CharsetUS_ASCII; } // fallback + mpt::Charset charset = mpt::CharsetASCII; + if ( encoding == "" ) { charset = mpt::CharsetASCII; } // fallback else if ( encoding == "utf-8" ) { charset = mpt::CharsetUTF8; } - else if ( encoding == "ascii" ) { charset = mpt::CharsetUS_ASCII; } - else if ( encoding == "us-ascii" ) { charset = mpt::CharsetUS_ASCII; } + else if ( encoding == "ascii" ) { charset = mpt::CharsetASCII; } + else if ( encoding == "us-ascii" ) { charset = mpt::CharsetASCII; } else if ( encoding == "iso-8859-1" ) { charset = mpt::CharsetISO8859_1; } else if ( encoding == "iso-8859-15" ) { charset = mpt::CharsetISO8859_15; } else if ( encoding == "cp437" ) { charset = mpt::CharsetCP437; } else if ( encoding == "windows-1252" ) { charset = mpt::CharsetWindows1252; } - else { charset = mpt::CharsetUS_ASCII; } // fallback + else { charset = mpt::CharsetASCII; } // fallback return mpt::String::Convert( encoded, charset, mpt::CharsetUTF8 ); } void module_impl::apply_mixer_settings( std::int32_t samplerate, int channels ) { Modified: trunk/OpenMPT/mptrack/Settings.cpp =================================================================== --- trunk/OpenMPT/mptrack/Settings.cpp 2013-11-13 22:31:02 UTC (rev 3212) +++ trunk/OpenMPT/mptrack/Settings.cpp 2013-11-14 17:27:46 UTC (rev 3213) @@ -113,7 +113,7 @@ } if(HasTypeTag() && !GetTypeTag().empty()) { - result += L":" + mpt::String::Decode(GetTypeTag(), mpt::CharsetUS_ASCII); + result += L":" + mpt::String::Decode(GetTypeTag(), mpt::CharsetASCII); } return result; } Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-13 22:31:02 UTC (rev 3212) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-14 17:27:46 UTC (rev 3213) @@ -448,7 +448,7 @@ for(UINT iMidi = 0; iMidi < 128; iMidi++) { DWORD dwImage = IMAGE_NOINSTRUMENT; - s = StringifyW(iMidi) + L": " + mpt::String::Decode(szMidiProgramNames[iMidi], mpt::CharsetUS_ASCII); + s = StringifyW(iMidi) + L": " + mpt::String::Decode(szMidiProgramNames[iMidi], mpt::CharsetASCII); const LPARAM param = (MODITEM_MIDIINSTRUMENT << MIDILIB_SHIFT) | iMidi; if(!midiLib.MidiMap[iMidi].empty()) { @@ -482,7 +482,7 @@ for (UINT iPerc=24; iPerc<=84; iPerc++) { DWORD dwImage = IMAGE_NOSAMPLE; - s = mpt::String::Decode(szDefaultNoteNames[iPerc], mpt::CharsetUS_ASCII) + L": " + mpt::String::Decode(szMidiPercussionNames[iPerc - 24], mpt::CharsetUS_ASCII); + s = mpt::String::Decode(szDefaultNoteNames[iPerc], mpt::CharsetUS_ASCII) + L": " + mpt::String::Decode(szMidiPercussionNames[iPerc - 24], mpt::CharsetASCII); const LPARAM param = (MODITEM_MIDIPERCUSSION << MIDILIB_SHIFT) | iPerc; if(!midiLib.MidiMap[iPerc | 0x80].empty()) { Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-13 22:31:02 UTC (rev 3212) +++ trunk/OpenMPT/test/test.cpp 2013-11-14 17:27:46 UTC (rev 3213) @@ -700,11 +700,11 @@ VERIFY_EQUAL(mpt::String::Encode(L"a", mpt::CharsetLocale), "a"); VERIFY_EQUAL(mpt::String::Encode(L"a", mpt::CharsetUTF8), "a"); VERIFY_EQUAL(mpt::String::Encode(L"a", mpt::CharsetISO8859_1), "a"); - VERIFY_EQUAL(mpt::String::Encode(L"a", mpt::CharsetUS_ASCII), "a"); + VERIFY_EQUAL(mpt::String::Encode(L"a", mpt::CharsetASCII), "a"); VERIFY_EQUAL(mpt::String::Decode("a", mpt::CharsetLocale), L"a"); VERIFY_EQUAL(mpt::String::Decode("a", mpt::CharsetUTF8), L"a"); VERIFY_EQUAL(mpt::String::Decode("a", mpt::CharsetISO8859_1), L"a"); - VERIFY_EQUAL(mpt::String::Decode("a", mpt::CharsetUS_ASCII), L"a"); + VERIFY_EQUAL(mpt::String::Decode("a", mpt::CharsetASCII), L"a"); // Path conversions #ifdef MODPLUG_TRACKER This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-14 18:31:20
|
Revision: 3215 http://sourceforge.net/p/modplug/code/3215 Author: manxorist Date: 2013-11-14 18:31:11 +0000 (Thu, 14 Nov 2013) Log Message: ----------- [Ref] Add string encoding functions with shorter syntax which are easier to type. Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/mptrack/Settings.cpp trunk/OpenMPT/mptrack/Settings.h Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-14 17:31:14 UTC (rev 3214) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-14 18:31:11 UTC (rev 3215) @@ -115,29 +115,29 @@ #if defined(WIN32) // conversions - MPT_DEPRECATED_PATH std::string ToLocale() const { return mpt::String::Encode(path, mpt::CharsetLocale); } - std::string ToUTF8() const { return mpt::String::Encode(path, mpt::CharsetUTF8); } + MPT_DEPRECATED_PATH std::string ToLocale() const { return mpt::ToLocale(path); } + std::string ToUTF8() const { return mpt::To(mpt::CharsetUTF8, path); } std::wstring ToWide() const { return path; } - MPT_DEPRECATED_PATH static PathString FromLocale(const std::string &path) { return PathString(mpt::String::Decode(path, mpt::CharsetLocale)); } - static PathString FromUTF8(const std::string &path) { return PathString(mpt::String::Decode(path, mpt::CharsetUTF8)); } + MPT_DEPRECATED_PATH static PathString FromLocale(const std::string &path) { return PathString(mpt::ToWide(mpt::CharsetLocale, path)); } + static PathString FromUTF8(const std::string &path) { return PathString(mpt::ToWide(mpt::CharsetUTF8, path)); } static PathString FromWide(const std::wstring &path) { return PathString(path); } RawPathString AsNative() const { return path; } static PathString FromNative(const RawPathString &path) { return PathString(path); } #if defined(_MFC_VER) // CString TCHAR, so this is CHAR or WCHAR, depending on UNICODE - MPT_DEPRECATED_PATH CString ToCString() const { return mpt::String::ToCString(path); } - MPT_DEPRECATED_PATH static PathString FromCString(const CString &path) { return PathString(mpt::String::FromCString(path)); } + MPT_DEPRECATED_PATH CString ToCString() const { return mpt::ToCString(path); } + MPT_DEPRECATED_PATH static PathString FromCString(const CString &path) { return PathString(mpt::ToWide(path)); } #endif #else // !WIN32 // conversions std::string ToLocale() const { return path; } - std::string ToUTF8() const { return mpt::String::Convert(path, mpt::CharsetLocale, mpt::CharsetUTF8); } - std::wstring ToWide() const { return mpt::String::Decode(path, mpt::CharsetLocale); } + std::string ToUTF8() const { return mpt::To(mpt::CharsetUTF8, mpt::CharsetLocale, path); } + std::wstring ToWide() const { return mpt::ToWide(mpt::CharsetLocale, path); } static PathString FromLocale(const std::string &path) { return PathString(path); } - static PathString FromUTF8(const std::string &path) { return PathString(mpt::String::Convert(path, mpt::CharsetUTF8, mpt::CharsetLocale)); } - static PathString FromWide(const std::wstring &path) { return PathString(mpt::String::Encode(path, mpt::CharsetLocale)); } + static PathString FromUTF8(const std::string &path) { return PathString(mpt::To(mpt::CharsetLocale, mpt::CharsetUTF8, path)); } + static PathString FromWide(const std::wstring &path) { return PathString(mpt::To(mpt::CharsetLocale, path)); } RawPathString AsNative() const { return path; } static PathString FromNative(const RawPathString &path) { return PathString(path); } Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-14 17:31:14 UTC (rev 3214) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-14 18:31:11 UTC (rev 3215) @@ -105,18 +105,21 @@ #endif // WIN32 -std::string Encode(const std::wstring &src, Charset charset) +// templated on 8bit strings because of type-safe variants +template<typename Tdststring> +Tdststring EncodeImpl(Charset charset, const std::wstring &src) { + STATIC_ASSERT(sizeof(typename Tdststring::value_type) == sizeof(char)); #if defined(WIN32) const UINT codepage = CharsetToCodepage(charset); int required_size = WideCharToMultiByte(codepage, 0, src.c_str(), -1, nullptr, 0, nullptr, nullptr); if(required_size <= 0) { - return std::string(); + return Tdststring(); } std::vector<CHAR> encoded_string(required_size); WideCharToMultiByte(codepage, 0, src.c_str(), -1, &encoded_string[0], required_size, nullptr, nullptr); - return &encoded_string[0]; + return reinterpret_cast<const typename Tdststring::value_type*>(&encoded_string[0]); #else // !WIN32 iconv_t conv = iconv_t(); conv = iconv_open(CharsetToStringTranslit(charset), "wchar_t"); @@ -148,27 +151,30 @@ { iconv_close(conv); conv = iconv_t(); - return std::string(); + return Tdststring(); } } iconv_close(conv); conv = iconv_t(); - return &encoded_string[0]; + return reinterpret_cast<const typename Tdststring::value_type*>(&encoded_string[0]); #endif // WIN32 } -std::wstring Decode(const std::string &src, Charset charset) +// templated on 8bit strings because of type-safe variants +template<typename Tsrcstring> +std::wstring DecodeImpl(Charset charset, const Tsrcstring &src) { + STATIC_ASSERT(sizeof(typename Tsrcstring::value_type) == sizeof(char)); #if defined(WIN32) const UINT codepage = CharsetToCodepage(charset); - int required_size = MultiByteToWideChar(codepage, 0, src.c_str(), -1, nullptr, 0); + int required_size = MultiByteToWideChar(codepage, 0, reinterpret_cast<const char*>(src.c_str()), -1, nullptr, 0); if(required_size <= 0) { return std::wstring(); } std::vector<WCHAR> decoded_string(required_size); - MultiByteToWideChar(codepage, 0, src.c_str(), -1, &decoded_string[0], required_size); + MultiByteToWideChar(codepage, 0, reinterpret_cast<const char*>(src.c_str()), -1, &decoded_string[0], required_size); return &decoded_string[0]; #else // !WIN32 iconv_t conv = iconv_t(); @@ -177,7 +183,7 @@ { throw std::runtime_error("iconv conversion not working"); } - std::vector<char> encoded_string(src.c_str(), src.c_str() + src.length() + 1); + std::vector<char> encoded_string(reinterpret_cast<const char*>(src.c_str()), reinterpret_cast<const char*>(src.c_str()) + src.length() + 1); std::vector<wchar_t> wide_string(encoded_string.size() * 8); // large enough char * inbuf = &encoded_string[0]; size_t inbytesleft = encoded_string.size(); @@ -215,10 +221,18 @@ } -std::string Convert(const std::string &src, Charset from, Charset to) +// templated on 8bit strings because of type-safe variants +template<typename Tdststring, typename Tsrcstring> +Tdststring ConvertImpl(Charset to, Charset from, const Tsrcstring &src) { + STATIC_ASSERT(sizeof(typename Tdststring::value_type) == sizeof(char)); + STATIC_ASSERT(sizeof(typename Tsrcstring::value_type) == sizeof(char)); + if(to == from) + { + return Tdststring(reinterpret_cast<const typename Tdststring::value_type*>(&*src.begin()), reinterpret_cast<const typename Tdststring::value_type*>(&*src.end())); + } #if defined(WIN32) - return Encode(Decode(src, from), to); + return EncodeImpl<Tdststring>(to, DecodeImpl(from, src)); #else // !WIN32 iconv_t conv = iconv_t(); conv = iconv_open(CharsetToStringTranslit(to), CharsetToString(from)); @@ -230,7 +244,7 @@ throw std::runtime_error("iconv conversion not working"); } } - std::vector<char> src_string(src.c_str(), src.c_str() + src.length() + 1); + std::vector<char> src_string(reinterpret_cast<const char*>(src.c_str()), reinterpret_cast<const char*>(src.c_str()) + src.length() + 1); std::vector<char> dst_string(src_string.size() * 8); // large enough char * inbuf = &src_string[0]; size_t inbytesleft = src_string.size(); @@ -250,16 +264,34 @@ { iconv_close(conv); conv = iconv_t(); - return std::string(); + return Tdststring(); } } iconv_close(conv); conv = iconv_t(); - return &dst_string[0]; + return reinterpret_cast<const typename Tdststring::value_type*>(&dst_string[0]); #endif // WIN32 } +std::string Encode(const std::wstring &src, Charset to) +{ + return EncodeImpl<std::string>(to, src); +} + + +std::wstring Decode(const std::string &src, Charset from) +{ + return DecodeImpl(from, src); +} + + +std::string Convert(const std::string &src, Charset from, Charset to) +{ + return ConvertImpl<std::string>(to, from, src); +} + + #if defined(_MFC_VER) CString ToCString(const std::string &src, Charset charset) @@ -301,10 +333,83 @@ #endif -} } // namespace mpt::String +} // namespace String +std::wstring ToWide(Charset from, const std::string &str) +{ + return String::DecodeImpl(from, str); +} +std::string ToLocale(const std::wstring &str) +{ + return String::EncodeImpl<std::string>(CharsetLocale, str); +} +std::string ToLocale(Charset from, const std::string &str) +{ + return String::ConvertImpl<std::string>(CharsetLocale, from, str); +} + +std::string To(Charset to, const std::wstring &str) +{ + return String::EncodeImpl<std::string>(to, str); +} +std::string To(Charset to, Charset from, const std::string &str) +{ + return String::ConvertImpl<std::string>(to, from, str); +} + + +#if defined(_MFC_VER) + +CString ToCString(const std::wstring &str) +{ + #ifdef UNICODE + return str.c_str(); + #else + return ToLocale(str).c_str(); + #endif +} +CString ToCString(Charset from, const std::string &str) +{ + #ifdef UNICODE + return ToWide(from, str).c_str(); + #else + return ToLocale(from, str).c_str(); + #endif +} +std::wstring ToWide(const CString &str) +{ + #ifdef UNICODE + return str.GetString(); + #else + return ToWide(CharsetLocale, str.GetString()); + #endif +} +std::string ToLocale(const CString &str) +{ + #ifdef UNICODE + return ToLocale(str.GetString()); + #else + return str.GetString(); + #endif +} +std::string To(Charset to, const CString &str) +{ + #ifdef UNICODE + return To(to, str.GetString()); + #else + return To(to, CharsetLocale, str.GetString()); + #endif +} + +#endif + + +} // namespace mpt + + + namespace mpt { Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-14 17:31:14 UTC (rev 3214) +++ trunk/OpenMPT/common/mptString.h 2013-11-14 18:31:11 UTC (rev 3215) @@ -151,17 +151,38 @@ }; +static inline std::wstring ToWide(const std::wstring &str) { return str; } + +std::wstring ToWide(Charset from, const std::string &str); + +std::string ToLocale(const std::wstring &str); +std::string ToLocale(Charset from, const std::string &str); + +std::string To(Charset to, const std::wstring &str); +std::string To(Charset to, Charset from, const std::string &str); + +#if defined(_MFC_VER) +static inline CString ToCString(const CString &str) { return str; } +CString ToCString(const std::wstring &str); +CString ToCString(Charset from, const std::string &str); +std::wstring ToWide(const CString &str); +std::string ToLocale(const CString &str); +std::string To(Charset to, const CString &str); +#endif + + + namespace String { // Encode a wide unicode string into the specified encoding. // Invalid unicode code points, or code points not representable are silently substituted. // The wide encoding is UTF-16 or UTF-32, based on sizeof(wchar_t). -std::string Encode(const std::wstring &src, Charset charset); +std::string Encode(const std::wstring &src, Charset to); // Decode a 8-bit or multi-byte encoded string from the specified charset into a wide unicode string. // Invalid char sequences are silently substituted. // The wide encoding is UTF-16 or UTF-32, based on sizeof(wchar_t). -std::wstring Decode(const std::string &src, Charset charset); +std::wstring Decode(const std::string &src, Charset from); // Convert from one 8-bit charset to another. // This is semantically equivalent to Encode(Decode(src, from), to). Modified: trunk/OpenMPT/mptrack/Settings.cpp =================================================================== --- trunk/OpenMPT/mptrack/Settings.cpp 2013-11-14 17:31:14 UTC (rev 3214) +++ trunk/OpenMPT/mptrack/Settings.cpp 2013-11-14 18:31:11 UTC (rev 3215) @@ -113,7 +113,7 @@ } if(HasTypeTag() && !GetTypeTag().empty()) { - result += L":" + mpt::String::Decode(GetTypeTag(), mpt::CharsetASCII); + result += L":" + mpt::ToWide(mpt::CharsetASCII, GetTypeTag()); } return result; } @@ -375,7 +375,7 @@ { ::WritePrivateProfileStringW(GetSection(path).c_str(), GetKey(path).c_str(), val.c_str(), filename.AsNative().c_str()); - if(mpt::String::Decode(mpt::String::Encode(val, mpt::CharsetLocale), mpt::CharsetLocale) != val) + if(mpt::ToWide(mpt::CharsetLocale, mpt::ToLocale(val)) != val) // explicit round-trip { // Value is not representable in ANSI CP. // Now check if the string got stored correctly. @@ -471,7 +471,7 @@ } const mpt::PathString backupFilename = filename + mpt::PathString::FromWide(backupTag.empty() ? L".ansi.bak" : L".ansi." + backupTag + L".bak"); CopyFileW(filename.AsNative().c_str(), backupFilename.AsNative().c_str(), FALSE); - WriteFileUTF16LE(filename, mpt::String::Decode(std::string(&data[0], &data[0] + data.size()), mpt::CharsetLocale)); + WriteFileUTF16LE(filename, mpt::ToWide(mpt::CharsetLocale, std::string(&data[0], &data[0] + data.size()))); } SettingValue IniFileSettingsBackend::ReadSetting(const SettingPath &path, const SettingValue &def) const Modified: trunk/OpenMPT/mptrack/Settings.h =================================================================== --- trunk/OpenMPT/mptrack/Settings.h 2013-11-14 17:31:14 UTC (rev 3214) +++ trunk/OpenMPT/mptrack/Settings.h 2013-11-14 18:31:11 UTC (rev 3215) @@ -121,13 +121,13 @@ { Init(); type = SettingTypeString; - valueString = mpt::String::Decode(val, mpt::CharsetLocale); + valueString = mpt::ToWide(mpt::CharsetLocale, val); } SettingValue(const std::string &val) { Init(); type = SettingTypeString; - valueString = mpt::String::Decode(val, mpt::CharsetLocale); + valueString = mpt::ToWide(mpt::CharsetLocale, val); } SettingValue(const wchar_t *val) { @@ -173,14 +173,14 @@ Init(); type = SettingTypeString; typeTag = typeTag_; - valueString = mpt::String::Decode(val, mpt::CharsetLocale); + valueString = mpt::ToWide(mpt::CharsetLocale, val); } SettingValue(const std::string &val, const std::string &typeTag_) { Init(); type = SettingTypeString; typeTag = typeTag_; - valueString = mpt::String::Decode(val, mpt::CharsetLocale); + valueString = mpt::ToWide(mpt::CharsetLocale, val); } SettingValue(const wchar_t *val, const std::string &typeTag_) { @@ -238,7 +238,7 @@ operator std::string () const { ASSERT(type == SettingTypeString); - return mpt::String::Encode(valueString, mpt::CharsetLocale); + return mpt::ToLocale(valueString); } operator std::wstring () const { @@ -293,8 +293,8 @@ // You may use the SettingValue(value, typeTag) constructor in ToSettingValue // and check the typeTag FromSettingsValue to implement runtime type-checking for custom types. -template<> inline SettingValue ToSettingValue(const CString &val) { return SettingValue(std::basic_string<TCHAR>(val.GetString())); } -template<> inline CString FromSettingValue(const SettingValue &val) { return CString(val.as<std::basic_string<TCHAR> >().c_str()); } +template<> inline SettingValue ToSettingValue(const CString &val) { return SettingValue(mpt::ToWide(val)); } +template<> inline CString FromSettingValue(const SettingValue &val) { return mpt::ToCString(val.as<std::wstring>()); } template<> inline SettingValue ToSettingValue(const mpt::PathString &val) { return SettingValue(val.AsNative()); } template<> inline mpt::PathString FromSettingValue(const SettingValue &val) { return mpt::PathString::FromNative(val); } @@ -402,8 +402,8 @@ return; } SettingPath(const std::string §ion_, const std::string &key_) - : section(mpt::String::Decode(section_, mpt::CharsetLocale)) - , key(mpt::String::Decode(key_, mpt::CharsetLocale)) + : section(mpt::ToWide(mpt::CharsetLocale, section_)) + , key(mpt::ToWide(mpt::CharsetLocale, key_)) { return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-14 19:15:59
|
Revision: 3216 http://sourceforge.net/p/modplug/code/3216 Author: manxorist Date: 2013-11-14 19:15:48 +0000 (Thu, 14 Nov 2013) Log Message: ----------- [Ref] Convert a lot of places to the shorter charset conversion syntax. [Ref] Some tiny realted cleanups. Modified Paths: -------------- trunk/OpenMPT/common/mptFstream.h trunk/OpenMPT/common/mptPathString.cpp trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/AutoSaver.cpp trunk/OpenMPT/mptrack/CommandSet.cpp trunk/OpenMPT/mptrack/Ctrl_seq.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/ExceptionHandler.cpp trunk/OpenMPT/mptrack/FileDialog.h trunk/OpenMPT/mptrack/Moptions.cpp trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/TuningDialog.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Tagging.cpp trunk/OpenMPT/soundlib/WAVTools.cpp trunk/OpenMPT/unarchiver/unrar.cpp Modified: trunk/OpenMPT/common/mptFstream.h =================================================================== --- trunk/OpenMPT/common/mptFstream.h 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/common/mptFstream.h 2013-11-14 19:15:48 UTC (rev 3216) @@ -59,7 +59,7 @@ template<typename Tbase> inline void fstream_open(Tbase & base, const std::string & filename, std::ios_base::openmode mode) { - detail::fstream_open<Tbase>(base, mpt::String::Decode(filename, mpt::CharsetLocale), mode); + detail::fstream_open<Tbase>(base, mpt::ToWide(mpt::CharsetLocale, filename), mode); } template<typename Tbase> Modified: trunk/OpenMPT/common/mptPathString.cpp =================================================================== --- trunk/OpenMPT/common/mptPathString.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/common/mptPathString.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -76,7 +76,7 @@ //----------------------------------------------------------------- { #if defined(WIN32) - return _wfopen(filename.AsNative().c_str(), mode ? mpt::String::Decode(mode, mpt::CharsetLocale).c_str() : nullptr); + return _wfopen(filename.AsNative().c_str(), mode ? mpt::ToWide(mpt::CharsetLocale, mode).c_str() : nullptr); #else // !WIN32 return fopen(filename.AsNative().c_str(), mode); #endif // WIN32 @@ -88,7 +88,7 @@ #if defined(WIN32) return _wfopen(filename.AsNative().c_str(), mode); #else // !WIN32 - return fopen(filename.AsNative().c_str(), mode ? mpt::String::Encode(mode, mpt::CharsetLocale).c_str() : nullptr); + return fopen(filename.AsNative().c_str(), mode ? mpt::ToLocale(mode).c_str() : nullptr); #endif // WIN32 } Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -292,47 +292,6 @@ } -#if defined(_MFC_VER) - -CString ToCString(const std::string &src, Charset charset) -{ - #ifdef UNICODE - return mpt::String::Decode(src, charset).c_str(); - #else - return mpt::String::Convert(src, charset, mpt::CharsetLocale).c_str(); - #endif -} - -CString ToCString(const std::wstring &src) -{ - #ifdef UNICODE - return src.c_str(); - #else - return mpt::String::Encode(src, mpt::CharsetLocale).c_str(); - #endif -} - -std::string FromCString(const CString &src, Charset charset) -{ - #ifdef UNICODE - return mpt::String::Encode(src.GetString(), charset); - #else - return mpt::String::Convert(src.GetString(), mpt::CharsetLocale, charset); - #endif -} - -std::wstring FromCString(const CString &src) -{ - #ifdef UNICODE - return src.GetString(); - #else - return mpt::String::Decode(src.GetString(), mpt::CharsetLocale); - #endif -} - -#endif - - } // namespace String @@ -439,7 +398,7 @@ } std::string ToString(const char & x) { return std::string(1, x); } -std::string ToString(const wchar_t & x) { return mpt::String::Encode(std::wstring(1, x), mpt::CharsetLocale); } +std::string ToString(const wchar_t & x) { return mpt::ToLocale(std::wstring(1, x)); } std::string ToString(const bool & x) { return ToStringHelper(x); } std::string ToString(const signed char & x) { return ToStringHelper(x); } std::string ToString(const unsigned char & x) { return ToStringHelper(x); } @@ -455,7 +414,7 @@ std::string ToString(const double & x) { return ToStringHelper(x); } std::string ToString(const long double & x) { return ToStringHelper(x); } -std::wstring ToWString(const char & x) { return mpt::String::Decode(std::string(1, x), mpt::CharsetLocale); } +std::wstring ToWString(const char & x) { return mpt::ToWide(mpt::CharsetLocale, std::string(1, x)); } std::wstring ToWString(const wchar_t & x) { return std::wstring(1, x); } std::wstring ToWString(const bool & x) { return ToWStringHelper(x); } std::wstring ToWString(const signed char & x) { return ToWStringHelper(x); } Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/common/mptString.h 2013-11-14 19:15:48 UTC (rev 3216) @@ -162,12 +162,21 @@ std::string To(Charset to, Charset from, const std::string &str); #if defined(_MFC_VER) + +// Convert to a MFC CString. The CString encoding depends on UNICODE. +// This should also be used when converting to TCHAR strings. +// If UNICODE is defined, this is a completely lossless operation. static inline CString ToCString(const CString &str) { return str; } CString ToCString(const std::wstring &str); CString ToCString(Charset from, const std::string &str); + +// Convert from a MFC CString. The CString encoding depends on UNICODE. +// This should also be used when converting from TCHAR strings. +// If UNICODE is defined, this is a completely lossless operation. std::wstring ToWide(const CString &str); std::string ToLocale(const CString &str); std::string To(Charset to, const CString &str); + #endif @@ -177,31 +186,17 @@ // Encode a wide unicode string into the specified encoding. // Invalid unicode code points, or code points not representable are silently substituted. // The wide encoding is UTF-16 or UTF-32, based on sizeof(wchar_t). -std::string Encode(const std::wstring &src, Charset to); +MPT_DEPRECATED std::string Encode(const std::wstring &src, Charset to); // Decode a 8-bit or multi-byte encoded string from the specified charset into a wide unicode string. // Invalid char sequences are silently substituted. // The wide encoding is UTF-16 or UTF-32, based on sizeof(wchar_t). -std::wstring Decode(const std::string &src, Charset from); +MPT_DEPRECATED std::wstring Decode(const std::string &src, Charset from); // Convert from one 8-bit charset to another. // This is semantically equivalent to Encode(Decode(src, from), to). -std::string Convert(const std::string &src, Charset from, Charset to); +MPT_DEPRECATED std::string Convert(const std::string &src, Charset from, Charset to); -#if defined(_MFC_VER) -// Convert to a MFC CString. The CString encoding depends on UNICODE. -// This should also be used when converting to TCHAR strings. -// If UNICODE is defined, this is a completely lossless operation. -CString ToCString(const std::string &src, Charset charset); -CString ToCString(const std::wstring &src); - -// Convert from a MFC CString. The CString encoding depends on UNICODE. -// This should also be used when converting from TCHAR strings. -// If UNICODE is defined, this is a completely lossless operation. -std::string FromCString(const CString &src, Charset charset); -std::wstring FromCString(const CString &src); -#endif - } // namespace String } // namespace mpt Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -231,7 +231,7 @@ else if ( encoding == "cp437" ) { charset = mpt::CharsetCP437; } else if ( encoding == "windows-1252" ) { charset = mpt::CharsetWindows1252; } else { charset = mpt::CharsetASCII; } // fallback - return mpt::String::Convert( encoded, charset, mpt::CharsetUTF8 ); + return mpt::To( mpt::CharsetUTF8, charset, encoded ); } void module_impl::apply_mixer_settings( std::int32_t samplerate, int channels ) { if ( Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp =================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -206,7 +206,7 @@ mpt::PathString CAutoSaver::BuildFileName(CModDoc &modDoc) //-------------------------------------------------------- { - std::wstring timeStamp = mpt::String::FromCString((CTime::GetCurrentTime()).Format("%Y%m%d.%H%M%S")); + std::wstring timeStamp = mpt::ToWide((CTime::GetCurrentTime()).Format("%Y%m%d.%H%M%S")); mpt::PathString name; if(m_bUseOriginalPath) Modified: trunk/OpenMPT/mptrack/CommandSet.cpp =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/CommandSet.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -1663,7 +1663,7 @@ if(!errText.IsEmpty()) { std::wstring err = L"The following problems have been encountered while trying to load the key binding file " + filenameDescription + L":\n"; - err += mpt::String::FromCString(errText); + err += mpt::ToWide(errText); Reporting::Warning(err); } Modified: trunk/OpenMPT/mptrack/Ctrl_seq.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -1345,7 +1345,7 @@ CSoundFile &sndFile = m_pModDoc.GetrSoundFile(); if(nSeq == MAX_SEQUENCES + 2) { - std::wstring str = L"Delete sequence " + StringifyW(sndFile.Order.GetCurrentSequenceIndex()) + L": " + mpt::String::Decode(sndFile.Order.GetName(), mpt::CharsetLocale) + L"?"; + std::wstring str = L"Delete sequence " + StringifyW(sndFile.Order.GetCurrentSequenceIndex()) + L": " + mpt::ToWide(mpt::CharsetLocale, sndFile.Order.GetName()) + L"?"; if (Reporting::Confirm(str) == cnfYes) sndFile.Order.RemoveSequence(); else Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -1065,9 +1065,9 @@ SanitizeFilename(sSampleName); SanitizeFilename(sSampleFilename); - fileName = mpt::PathString::FromWide(mpt::String::Replace(fileName.ToWide(), L"%sample_number%", mpt::String::FromCString(sSampleNumber))); - fileName = mpt::PathString::FromWide(mpt::String::Replace(fileName.ToWide(), L"%sample_filename%", mpt::String::FromCString(sSampleFilename))); - fileName = mpt::PathString::FromWide(mpt::String::Replace(fileName.ToWide(), L"%sample_name%", mpt::String::FromCString(sSampleName))); + fileName = mpt::PathString::FromWide(mpt::String::Replace(fileName.ToWide(), L"%sample_number%", mpt::ToWide(sSampleNumber))); + fileName = mpt::PathString::FromWide(mpt::String::Replace(fileName.ToWide(), L"%sample_filename%", mpt::ToWide(sSampleFilename))); + fileName = mpt::PathString::FromWide(mpt::String::Replace(fileName.ToWide(), L"%sample_name%", mpt::ToWide(sSampleName))); } if(!mpt::PathString::CompareNoCase(ext, MPT_PATHSTRING("raw"))) ok = m_sndFile.SaveRAWSample(smp, fileName); Modified: trunk/OpenMPT/mptrack/ExceptionHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -39,7 +39,7 @@ { CMainFrame* pMainFrame = CMainFrame::GetMainFrame(); - const mpt::PathString timestampDir = mpt::PathString::FromWide(mpt::String::FromCString((CTime::GetCurrentTime()).Format("%Y-%m-%d %H.%M.%S\\"))); + const mpt::PathString timestampDir = mpt::PathString::FromWide(mpt::ToWide((CTime::GetCurrentTime()).Format("%Y-%m-%d %H.%M.%S\\"))); mpt::PathString baseRescuePath; { // Create a crash directory @@ -53,7 +53,7 @@ baseRescuePath += timestampDir; if(!PathIsDirectoryW(baseRescuePath.AsNative().c_str()) && !CreateDirectoryW(baseRescuePath.AsNative().c_str(), nullptr)) { - errorMessage.AppendFormat("\n\nCould not create the following directory for saving debug information and modified files to:\n%s", mpt::String::ToCString(baseRescuePath.ToWide())); + errorMessage.AppendFormat("\n\nCould not create the following directory for saving debug information and modified files to:\n%s", mpt::ToCString(baseRescuePath.ToWide())); } } Modified: trunk/OpenMPT/mptrack/FileDialog.h =================================================================== --- trunk/OpenMPT/mptrack/FileDialog.h 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/FileDialog.h 2013-11-14 19:15:48 UTC (rev 3216) @@ -37,15 +37,15 @@ // Default extension to use if none is specified. FileDialog &DefaultExtension(const mpt::PathString &ext) { defaultExtension = ext.ToWide(); return *this; } FileDialog &DefaultExtension(const std::wstring &ext) { defaultExtension = ext; return *this; } - FileDialog &DefaultExtension(const std::string &ext) { defaultExtension = mpt::String::Decode(ext, mpt::CharsetLocale); return *this; } + FileDialog &DefaultExtension(const std::string &ext) { defaultExtension = mpt::ToWide(mpt::CharsetLocale, ext); return *this; } // Default suggested filename. FileDialog &DefaultFilename(const mpt::PathString &name) { defaultFilename = name.ToWide(); return *this; } FileDialog &DefaultFilename(const std::wstring &name) { defaultFilename = name; return *this; } - FileDialog &DefaultFilename(const std::string &name) { defaultFilename = mpt::String::Decode(name, mpt::CharsetLocale); return *this; } + FileDialog &DefaultFilename(const std::string &name) { defaultFilename = mpt::ToWide(mpt::CharsetLocale, name); return *this; } // List of possible extensions. Format: "description|extensions|...|description|extensions||" FileDialog &ExtensionFilter(const mpt::PathString &filter) { extFilter = filter.ToWide(); return *this; } FileDialog &ExtensionFilter(const std::wstring &filter) { extFilter = filter; return *this; } - FileDialog &ExtensionFilter(const std::string &filter) { extFilter = mpt::String::Decode(filter, mpt::CharsetLocale); return *this; } + FileDialog &ExtensionFilter(const std::string &filter) { extFilter = mpt::ToWide(mpt::CharsetLocale, filter); return *this; } // Default directory of the dialog. FileDialog &WorkingDirectory(const mpt::PathString &dir) { workingDirectory = dir; return *this; } // Pointer to a variable holding the index of the last extension filter to use. Holds the selected filter after the dialog has been closed. @@ -103,7 +103,7 @@ std::wstring caption; public: - BrowseForFolder(const mpt::PathString &dir, const CString &caption) : workingDirectory(dir), caption(mpt::String::FromCString(caption)) { } + BrowseForFolder(const mpt::PathString &dir, const CString &caption) : workingDirectory(dir), caption(mpt::ToWide(caption)) { } // Show the folder selection dialog. bool Show(); Modified: trunk/OpenMPT/mptrack/Moptions.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moptions.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/Moptions.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -707,10 +707,10 @@ } -static std::string FormatSetting(const SettingPath &path, const SettingValue &val) -//-------------------------------------------------------------------------------- +static CString FormatSetting(const SettingPath &path, const SettingValue &val) +//---------------------------------------------------------------------------- { - return mpt::String::Encode(path.FormatAsString() + L" = " + val.FormatAsString(), mpt::CharsetLocale); + return mpt::ToCString(path.FormatAsString() + L" = " + val.FormatAsString()); } @@ -730,7 +730,7 @@ m_IndexToPath.clear(); for(SettingsContainer::SettingsMap::const_iterator it = theApp.GetSettings().begin(); it != theApp.GetSettings().end(); ++it) { - int index = m_List.AddString(FormatSetting(it->first, it->second).c_str()); + int index = m_List.AddString(FormatSetting(it->first, it->second)); m_IndexToPath[index] = it->first; } } @@ -762,15 +762,15 @@ } const SettingPath path = m_IndexToPath[index]; SettingValue val = theApp.GetSettings().GetMap().find(path)->second; - CInputDlg inputDlg(this, mpt::String::Encode(path.FormatAsString(), mpt::CharsetLocale).c_str(), mpt::String::Encode(val.FormatValueAsString(), mpt::CharsetLocale).c_str()); + CInputDlg inputDlg(this, mpt::ToCString(path.FormatAsString()), mpt::ToCString(val.FormatValueAsString())); if(inputDlg.DoModal() != IDOK) { return; } - val.SetFromString(mpt::String::Decode(inputDlg.resultString.GetString(), mpt::CharsetLocale)); + val.SetFromString(mpt::ToWide(inputDlg.resultString)); theApp.GetSettings().Write(path, val); m_List.DeleteString(index); - m_List.InsertString(index, FormatSetting(path, val).c_str()); + m_List.InsertString(index, FormatSetting(path, val)); m_List.SetCurSel(index); OnSettingsChanged(); } Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -224,7 +224,7 @@ } { - std::string name = mpt::String::Encode(it->name, mpt::CharsetLocale); + CString name = mpt::ToCString(it->name); cbi.mask = CBEIF_IMAGE | CBEIF_LPARAM | CBEIF_TEXT | CBEIF_SELECTEDIMAGE | CBEIF_OVERLAY; cbi.iItem = iItem; cbi.cchTextMax = 0; @@ -247,7 +247,7 @@ cbi.iImage = IMAGE_WAVEOUT; // No image available for now, // prepend API name to name. - name = mpt::String::Encode(it->apiName, mpt::CharsetLocale) + " - " + name; + name = mpt::ToCString(it->apiName) + TEXT(" - ") + name; break; default: cbi.iImage = IMAGE_WAVEOUT; @@ -257,8 +257,9 @@ cbi.iOverlay = cbi.iImage; cbi.iIndent = 0; cbi.lParam = it->id.GetIdRaw(); - mpt::String::Copy(s, name); - cbi.pszText = s; + TCHAR tmp[256]; + _tcscpy(tmp, name); + cbi.pszText = tmp; int pos = m_CbnDevice.InsertItem(&cbi); if(cbi.lParam == m_nSoundDevice.GetIdRaw()) { Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -1470,7 +1470,7 @@ SetDlgItemText(IDC_EDIT2, CString("Build Date: ") + MptVersion::GetBuildDateString().c_str()); SetDlgItemText(IDC_EDIT3, CString("OpenMPT ") + MptVersion::GetVersionStringExtended().c_str()); m_static.SubclassDlgItem(IDC_CREDITS,this); - m_static.SetCredits((mpt::String::Replace(mpt::String::Convert(MptVersion::GetFullCreditsString(), mpt::CharsetUTF8, mpt::CharsetLocale), "\n", "|") + "|" + mpt::String::Replace(MptVersion::GetContactString(), "\n", "|" ) + "||||||").c_str()); + m_static.SetCredits((mpt::String::Replace(mpt::To(mpt::CharsetLocale, mpt::CharsetUTF8, MptVersion::GetFullCreditsString()), "\n", "|") + "|" + mpt::String::Replace(MptVersion::GetContactString(), "\n", "|" ) + "||||||").c_str()); m_static.SetSpeed(DISPLAY_SLOW); m_static.SetColor(BACKGROUND_COLOR, RGB(138, 165, 219)); // Background Colour m_static.SetTransparent(); // Set parts of bitmaps with RGB(192,192,192) transparent Modified: trunk/OpenMPT/mptrack/TuningDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/TuningDialog.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/TuningDialog.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -738,7 +738,7 @@ } else { - sLoadReport += L"-Unable to import " + fileNameExt + L": " + mpt::String::FromCString(GetSclImportFailureMsg(a)) + L".\n"; + sLoadReport += L"-Unable to import " + fileNameExt + L": " + mpt::ToWide(GetSclImportFailureMsg(a)) + L".\n"; } } else // scl import successful. Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -448,7 +448,7 @@ for(UINT iMidi = 0; iMidi < 128; iMidi++) { DWORD dwImage = IMAGE_NOINSTRUMENT; - s = StringifyW(iMidi) + L": " + mpt::String::Decode(szMidiProgramNames[iMidi], mpt::CharsetASCII); + s = StringifyW(iMidi) + L": " + mpt::ToWide(mpt::CharsetASCII, szMidiProgramNames[iMidi]); const LPARAM param = (MODITEM_MIDIINSTRUMENT << MIDILIB_SHIFT) | iMidi; if(!midiLib.MidiMap[iMidi].empty()) { @@ -482,7 +482,7 @@ for (UINT iPerc=24; iPerc<=84; iPerc++) { DWORD dwImage = IMAGE_NOSAMPLE; - s = mpt::String::Decode(szDefaultNoteNames[iPerc], mpt::CharsetASCII) + L": " + mpt::String::Decode(szMidiPercussionNames[iPerc - 24], mpt::CharsetASCII); + s = mpt::ToWide(mpt::CharsetASCII, szDefaultNoteNames[iPerc]) + L": " + mpt::ToWide(mpt::CharsetASCII, szMidiPercussionNames[iPerc - 24]); const LPARAM param = (MODITEM_MIDIPERCUSSION << MIDILIB_SHIFT) | iPerc; if(!midiLib.MidiMap[iPerc | 0x80].empty()) { @@ -1589,7 +1589,7 @@ if(pIns) { WCHAR s[MAX_INSTRUMENTNAME + 10]; - swprintf(s, CountOf(s), L"%3d: %s", ins, mpt::String::Decode(pIns->name, mpt::CharsetLocale).c_str()); + swprintf(s, CountOf(s), L"%3d: %s", ins, mpt::ToWide(mpt::CharsetLocale, pIns->name).c_str()); ModTreeInsert(s, IMAGE_INSTRUMENTS); } } @@ -1599,7 +1599,7 @@ if(sample.pSample) { WCHAR s[MAX_SAMPLENAME + 10]; - swprintf(s, CountOf(s), L"%3d: %s", smp, mpt::String::Decode(m_SongFile->m_szNames[smp], mpt::CharsetLocale).c_str()); + swprintf(s, CountOf(s), L"%3d: %s", smp, mpt::ToWide(mpt::CharsetLocale, m_SongFile->m_szNames[smp]).c_str()); ModTreeInsert(s, IMAGE_SAMPLES); } } @@ -1674,7 +1674,7 @@ } else if(wfd.nFileSizeHigh > 0 || wfd.nFileSizeLow >= 16) { // Get lower-case file extension without dot. - const std::string ext = mpt::String::Encode(mpt::PathString::FromNative(wfd.cFileName).GetFileExt().ToWide(), mpt::CharsetUTF8); + const std::string ext = mpt::To(mpt::CharsetUTF8, mpt::PathString::FromNative(wfd.cFileName).GetFileExt().ToWide()); char s[16]; mpt::String::Copy(s, ext); Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -64,7 +64,7 @@ } const std::wstring keyname = keynameBuf; #ifdef ASIO_LOG - Log("ASIO: Found \"%s\":\n", mpt::String::Encode(keynameBuf, mpt::CharsetLocale).c_str()); + Log("ASIO: Found \"%s\":\n", mpt::ToLocale(keyname).c_str()); #endif HKEY hksub = NULL; @@ -80,7 +80,7 @@ if(ERROR_SUCCESS == RegQueryValueExW(hksub, L"Description", 0, &datatype, (LPBYTE)descriptionBuf, &datasize)) { #ifdef ASIO_LOG - Log(" description =\"%s\":\n", mpt::String::Encode(descriptionBuf, mpt::CharsetLocale).c_str()); + Log(" description =\"%s\":\n", mpt::ToLocale(description).c_str()); #endif description = descriptionBuf; } else @@ -97,7 +97,7 @@ if(Util::IsCLSID(internalID)) { #ifdef ASIO_LOG - Log(" clsid=\"%s\"\n", mpt::String::Encode(idBuf, mpt::CharsetLocale).c_str()); + Log(" clsid=\"%s\"\n", mpt::ToLocale(internalID).c_str()); #endif if(SoundDeviceIndexIsValid(devices.size())) @@ -157,7 +157,7 @@ #ifdef ASIO_LOG Log("CASIODevice::Open(%d:\"%s\"): %d-bit, %d channels, %dHz\n", - GetDeviceIndex(), mpt::String::Encode(GetDeviceInternalID(), mpt::CharsetLocale).c_str(), (int)m_Settings.sampleFormat.GetBitsPerSample(), m_Settings.Channels, m_Settings.Samplerate); + GetDeviceIndex(), mpt::ToLocale(GetDeviceInternalID()).c_str(), (int)m_Settings.sampleFormat.GetBitsPerSample(), m_Settings.Channels, m_Settings.Samplerate); #endif OpenDevice(); Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -311,13 +311,8 @@ if(!Pa_GetDeviceInfo(dev)) return false; result.id = SoundDeviceID(HostApiToSndDevType(hostapi), index); - result.name = mpt::String::Decode( - mpt::String::Format("%s%s", - Pa_GetDeviceInfo(dev)->name, - Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == (PaDeviceIndex)dev ? " (Default)" : "" - ), - mpt::CharsetUTF8); - result.apiName = mpt::String::Decode(HostApiToString(Pa_GetDeviceInfo(dev)->hostApi).c_str(), mpt::CharsetUTF8); + result.name = mpt::ToWide(mpt::CharsetUTF8, std::string(Pa_GetDeviceInfo(dev)->name) + std::string(Pa_GetHostApiInfo(Pa_GetDeviceInfo(dev)->hostApi)->defaultOutputDevice == (PaDeviceIndex)dev ? " (Default)" : "")); + result.apiName = mpt::ToWide(mpt::CharsetUTF8, HostApiToString(Pa_GetDeviceInfo(dev)->hostApi)); return true; } Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -479,8 +479,8 @@ file.WriteExtraInformation(sample, GetType()); FileTags tags; - tags.title = mpt::String::Decode(m_szNames[nSample], mpt::CharsetLocale); - tags.encoder = mpt::String::Decode(MptVersion::GetOpenMPTVersionStr(), mpt::CharsetLocale); + tags.title = mpt::ToWide(mpt::CharsetLocale, m_szNames[nSample]); + tags.encoder = mpt::ToWide(mpt::CharsetLocale, MptVersion::GetOpenMPTVersionStr()); file.WriteMetatags(tags); return true; Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -889,8 +889,8 @@ std::string sUrl = "http://resources.openmpt.org/plugins/search.php?p="; for(std::vector<PLUGINDEX>::iterator i = notFoundIDs.begin(); i != notFoundIDs.end(); ++i) { - sUrl += mpt::String::Format("%08X", LittleEndian(m_MixPlugins[*i].Info.dwPluginId2)); - sUrl += mpt::String::Convert(m_MixPlugins[*i].GetLibraryName(), mpt::CharsetLocale, mpt::CharsetUTF8); + sUrl += mpt::fmt::HEX0<8>(LittleEndian(m_MixPlugins[*i].Info.dwPluginId2)); + sUrl += mpt::To(mpt::CharsetUTF8, mpt::CharsetLocale, m_MixPlugins[*i].GetLibraryName()); sUrl += "%0a"; } CTrackApp::OpenURL(mpt::PathString::FromUTF8(sUrl)); Modified: trunk/OpenMPT/soundlib/Tagging.cpp =================================================================== --- trunk/OpenMPT/soundlib/Tagging.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/soundlib/Tagging.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -17,7 +17,7 @@ FileTags::FileTags() //------------------ { - encoder = mpt::String::Decode(MptVersion::GetOpenMPTVersionStr(), mpt::CharsetLocale); + encoder = mpt::ToWide(mpt::CharsetASCII, MptVersion::GetOpenMPTVersionStr()); } #endif // MODPLUG_NO_FILESAVE Modified: trunk/OpenMPT/soundlib/WAVTools.cpp =================================================================== --- trunk/OpenMPT/soundlib/WAVTools.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/soundlib/WAVTools.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -504,7 +504,7 @@ void WAVWriter::WriteTag(RIFFChunk::id_type id, const std::wstring &wideText) //--------------------------------------------------------------------------- { - std::string text = mpt::String::Encode(wideText, mpt::CharsetWindows1252); + std::string text = mpt::To(mpt::CharsetWindows1252, wideText); if(!text.empty()) { const size_t length = text.length() + 1; Modified: trunk/OpenMPT/unarchiver/unrar.cpp =================================================================== --- trunk/OpenMPT/unarchiver/unrar.cpp 2013-11-14 18:31:11 UTC (rev 3215) +++ trunk/OpenMPT/unarchiver/unrar.cpp 2013-11-14 19:15:48 UTC (rev 3216) @@ -76,7 +76,7 @@ Array<wchar> rarComment; if(rarData->Arc.GetComment(&rarComment)) { - comment = mpt::String::Encode(std::wstring(&rarComment[0], rarComment.Size()), mpt::CharsetLocale); + comment = mpt::ToLocale(std::wstring(&rarComment[0], rarComment.Size())); } // Scan all files @@ -84,7 +84,7 @@ while(rarData->Arc.SearchBlock(HEAD_FILE) > 0) { ArchiveFileInfo fileInfo; - fileInfo.name = mpt::String::Encode(rarData->Arc.FileHead.FileName, mpt::CharsetLocale); + fileInfo.name = mpt::ToLocale(std::wstring(rarData->Arc.FileHead.FileName)); fileInfo.type = ArchiveFileNormal; fileInfo.size = rarData->Arc.FileHead.UnpSize; contents.push_back(fileInfo); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-14 20:27:32
|
Revision: 3220 http://sourceforge.net/p/modplug/code/3220 Author: manxorist Date: 2013-11-14 20:27:22 +0000 (Thu, 14 Nov 2013) Log Message: ----------- [Ref] Improve string conversion functions for wide string literals. Modified Paths: -------------- trunk/OpenMPT/common/mptString.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-14 20:05:27 UTC (rev 3219) +++ trunk/OpenMPT/common/mptString.h 2013-11-14 20:27:22 UTC (rev 3220) @@ -194,6 +194,12 @@ std::string ToLocale(const CString &str); std::string To(Charset to, const CString &str); +// Provide un-ambiguous conversion from wide string literal. +static inline std::wstring ToWide(const wchar_t * str) { return ToWide(str ? std::wstring(str) : std::wstring()); } +static inline std::string ToLocale(const wchar_t * str) { return ToLocale(str ? std::wstring(str) : std::wstring()); } +static inline std::string To(Charset to, const wchar_t * str) { return To(to, str ? std::wstring(str) : std::wstring()); } +static inline CString ToCString(const wchar_t * str) { return ToCString(str ? std::wstring(str) : std::wstring()); } + #endif Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-14 20:05:27 UTC (rev 3219) +++ trunk/OpenMPT/test/test.cpp 2013-11-14 20:27:22 UTC (rev 3220) @@ -697,10 +697,10 @@ } // Charset conversions (basic sanity checks) - VERIFY_EQUAL(mpt::ToLocale(std::wstring(L"a")), "a"); - VERIFY_EQUAL(mpt::To(mpt::CharsetUTF8, std::wstring(L"a")), "a"); - VERIFY_EQUAL(mpt::To(mpt::CharsetISO8859_1, std::wstring(L"a")), "a"); - VERIFY_EQUAL(mpt::To(mpt::CharsetASCII, std::wstring(L"a")), "a"); + VERIFY_EQUAL(mpt::ToLocale(L"a"), "a"); + VERIFY_EQUAL(mpt::To(mpt::CharsetUTF8, L"a"), "a"); + VERIFY_EQUAL(mpt::To(mpt::CharsetISO8859_1, L"a"), "a"); + VERIFY_EQUAL(mpt::To(mpt::CharsetASCII, L"a"), "a"); VERIFY_EQUAL(mpt::ToWide(mpt::CharsetLocale, "a"), L"a"); VERIFY_EQUAL(mpt::ToWide(mpt::CharsetUTF8, "a"), L"a"); VERIFY_EQUAL(mpt::ToWide(mpt::CharsetISO8859_1, "a"), L"a"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-14 21:46:02
|
Revision: 3223 http://sourceforge.net/p/modplug/code/3223 Author: manxorist Date: 2013-11-14 21:45:54 +0000 (Thu, 14 Nov 2013) Log Message: ----------- [Ref] Convert unarchiver to unicode. Modified Paths: -------------- trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/unarchiver/archive.h trunk/OpenMPT/unarchiver/unarchiver.cpp trunk/OpenMPT/unarchiver/unarchiver.h trunk/OpenMPT/unarchiver/unlha.cpp trunk/OpenMPT/unarchiver/unrar.cpp trunk/OpenMPT/unarchiver/unzip.cpp Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-14 20:40:27 UTC (rev 3222) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-14 21:45:54 UTC (rev 3223) @@ -744,7 +744,7 @@ // Read archive comment if there is no song comment if(songMessage.empty()) { - songMessage.assign(unarchiver.GetComment()); + songMessage.assign(mpt::ToLocale(unarchiver.GetComment())); } #endif Modified: trunk/OpenMPT/unarchiver/archive.h =================================================================== --- trunk/OpenMPT/unarchiver/archive.h 2013-11-14 20:40:27 UTC (rev 3222) +++ trunk/OpenMPT/unarchiver/archive.h 2013-11-14 21:45:54 UTC (rev 3223) @@ -22,14 +22,14 @@ struct ArchiveFileInfo { - std::string name; + mpt::PathString name; ArchiveFileType type; uint64 size; std::string comment; uint64 cookie1; uint64 cookie2; ArchiveFileInfo() - : name(std::string()) + : name(mpt::PathString()) , type(ArchiveFileInvalid) , size(0) , comment(std::string()) @@ -52,7 +52,7 @@ virtual ~IArchive() {}; public: virtual bool IsArchive() const = 0; - virtual std::string GetComment() const = 0; + virtual std::wstring GetComment() const = 0; virtual bool ExtractFile(std::size_t index) = 0; virtual FileReader GetOutputFile() const = 0; virtual std::size_t size() const = 0; @@ -68,7 +68,7 @@ { protected: FileReader inFile; - std::string comment; + std::wstring comment; std::vector<ArchiveFileInfo> contents; std::vector<char> data; public: @@ -87,7 +87,7 @@ { return !contents.empty(); } - virtual std::string GetComment() const + virtual std::wstring GetComment() const { return comment; } Modified: trunk/OpenMPT/unarchiver/unarchiver.cpp =================================================================== --- trunk/OpenMPT/unarchiver/unarchiver.cpp 2013-11-14 20:40:27 UTC (rev 3222) +++ trunk/OpenMPT/unarchiver/unarchiver.cpp 2013-11-14 21:45:54 UTC (rev 3223) @@ -67,16 +67,16 @@ }; -static inline std::string GetExtension(const std::string &filename) -//----------------------------------------------------------------- +static inline std::wstring GetExtension(const std::wstring &filename) +//------------------------------------------------------------------- { - if(filename.find_last_of(".") != std::string::npos) + if(filename.find_last_of(L".") != std::wstring::npos) { - std::string ext = filename.substr(filename.find_last_of(".") + 1); + std::wstring ext = filename.substr(filename.find_last_of(L".") + 1); std::transform(ext.begin(), ext.end(), ext.begin(), tolower); return ext; } - return std::string(); + return std::wstring(); } @@ -95,7 +95,7 @@ { continue; } - const std::string ext = GetExtension(at(i).name); + const std::string ext = mpt::To(mpt::CharsetUTF8, GetExtension(at(i).name.ToWide())); // Compare with list of preferred extensions if(std::find_if(extensions.begin(), extensions.end(), find_str(ext.c_str())) != extensions.end()) @@ -139,8 +139,8 @@ } -std::string CUnarchiver::GetComment() const -//----------------------------------------- +std::wstring CUnarchiver::GetComment() const +//------------------------------------------ { return impl->GetComment(); } Modified: trunk/OpenMPT/unarchiver/unarchiver.h =================================================================== --- trunk/OpenMPT/unarchiver/unarchiver.h 2013-11-14 20:40:27 UTC (rev 3222) +++ trunk/OpenMPT/unarchiver/unarchiver.h 2013-11-14 21:45:54 UTC (rev 3223) @@ -63,7 +63,7 @@ virtual ~CUnarchiver(); virtual bool IsArchive() const; - virtual std::string GetComment() const; + virtual std::wstring GetComment() const; virtual bool ExtractFile(std::size_t index); virtual FileReader GetOutputFile() const; virtual std::size_t size() const; Modified: trunk/OpenMPT/unarchiver/unlha.cpp =================================================================== --- trunk/OpenMPT/unarchiver/unlha.cpp 2013-11-14 20:40:27 UTC (rev 3222) +++ trunk/OpenMPT/unarchiver/unlha.cpp 2013-11-14 21:45:54 UTC (rev 3223) @@ -53,7 +53,7 @@ for(LHAFileHeader *fileheader = firstfile; fileheader; fileheader = lha_reader_next_file(reader)) { ArchiveFileInfo info; - info.name = fileheader->filename; + info.name = mpt::PathString::FromWide(mpt::ToWide(mpt::CharsetISO8859_1, fileheader->filename)); info.size = fileheader->length; info.type = ArchiveFileNormal; contents.push_back(info); Modified: trunk/OpenMPT/unarchiver/unrar.cpp =================================================================== --- trunk/OpenMPT/unarchiver/unrar.cpp 2013-11-14 20:40:27 UTC (rev 3222) +++ trunk/OpenMPT/unarchiver/unrar.cpp 2013-11-14 21:45:54 UTC (rev 3223) @@ -76,7 +76,7 @@ Array<wchar> rarComment; if(rarData->Arc.GetComment(&rarComment)) { - comment = mpt::ToLocale(std::wstring(&rarComment[0], rarComment.Size())); + comment = std::wstring(&rarComment[0], rarComment.Size()); } // Scan all files @@ -84,7 +84,7 @@ while(rarData->Arc.SearchBlock(HEAD_FILE) > 0) { ArchiveFileInfo fileInfo; - fileInfo.name = mpt::ToLocale(std::wstring(rarData->Arc.FileHead.FileName)); + fileInfo.name = mpt::PathString::FromWide(std::wstring(rarData->Arc.FileHead.FileName)); fileInfo.type = ArchiveFileNormal; fileInfo.size = rarData->Arc.FileHead.UnpSize; contents.push_back(fileInfo); Modified: trunk/OpenMPT/unarchiver/unzip.cpp =================================================================== --- trunk/OpenMPT/unarchiver/unzip.cpp 2013-11-14 20:40:27 UTC (rev 3222) +++ trunk/OpenMPT/unarchiver/unzip.cpp 2013-11-14 21:45:54 UTC (rev 3223) @@ -133,7 +133,7 @@ if(unzGetGlobalComment(zipFile, &commentData[0], info.size_comment) >= 0) { commentData[info.size_comment - 1] = '\0'; - comment = &commentData[0]; + comment = mpt::ToWide(mpt::CharsetCP437, &commentData[0]); } } } @@ -154,7 +154,7 @@ char name[256]; unzGetCurrentFileInfo(zipFile, &info, name, sizeof(name), nullptr, 0, nullptr, 0); - fileinfo.name = name; + fileinfo.name = mpt::PathString::FromWide(mpt::ToWide(mpt::CharsetCP437, std::string(name))); fileinfo.size = info.uncompressed_size; unzGetFilePos(zipFile, &bestFile); @@ -246,7 +246,7 @@ if(mz_zip_reader_file_stat(zip, i, &stat)) { info.type = ArchiveFileNormal; - info.name = stat.m_filename; + info.name = mpt::PathString::FromWide(mpt::ToWide(mpt::CharsetCP437, stat.m_filename)); info.size = stat.m_uncomp_size; } if(mz_zip_reader_is_file_a_directory(zip, i)) @@ -308,7 +308,7 @@ { return false; } - comment = std::string(stat.m_comment, stat.m_comment + stat.m_comment_size); + comment = mpt::ToWide(mpt::CharsetCP437, std::string(stat.m_comment, stat.m_comment + stat.m_comment_size)); return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-14 22:37:36
|
Revision: 3224 http://sourceforge.net/p/modplug/code/3224 Author: manxorist Date: 2013-11-14 22:37:30 +0000 (Thu, 14 Nov 2013) Log Message: ----------- [Ref] Move windows.h include near the other windows related includes in stdafx.h. [Ref] Rework handling of NO_WINDOWS_H into BuildSettings.h. [Fix] Add shlwapi.h to stdafx.h. VS2008 SDK needs this for PathFileExistsW. Modified Paths: -------------- trunk/OpenMPT/common/BuildSettings.h trunk/OpenMPT/common/stdafx.h trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/unarchiver/unarchiver.cpp Modified: trunk/OpenMPT/common/BuildSettings.h =================================================================== --- trunk/OpenMPT/common/BuildSettings.h 2013-11-14 21:45:54 UTC (rev 3223) +++ trunk/OpenMPT/common/BuildSettings.h 2013-11-14 22:37:30 UTC (rev 3224) @@ -240,7 +240,8 @@ #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif -#ifdef _WIN32 +#if defined(_WIN32) && !defined(NO_WINDOWS_H) + #if MPT_COMPILER_MSVC && MPT_MSVC_AT_LEAST(2010,0) #define _WIN32_WINNT 0x0501 // _WIN32_WINNT_WINXP #else Modified: trunk/OpenMPT/common/stdafx.h =================================================================== --- trunk/OpenMPT/common/stdafx.h 2013-11-14 21:45:54 UTC (rev 3223) +++ trunk/OpenMPT/common/stdafx.h 2013-11-14 22:37:30 UTC (rev 3224) @@ -25,7 +25,9 @@ #include <afxdlgs.h> #include <afxole.h> +#include <windows.h> #include <windowsx.h> +#include <shlwapi.h> #if MPT_COMPILER_MSVC #pragma warning(disable:4201) Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-11-14 21:45:54 UTC (rev 3223) +++ trunk/OpenMPT/common/typedefs.h 2013-11-14 22:37:30 UTC (rev 3224) @@ -332,15 +332,8 @@ -#if defined(_WIN32) && !defined(NO_WINDOWS_H) +#if !defined(WIN32) -#ifndef NOMINMAX -#define NOMINMAX -#endif -#include <windows.h> // defines WIN32 - -#else // !_WIN32 - // openmpt assumes these type have exact WIN32 semantics typedef std::int32_t BOOL; @@ -361,7 +354,7 @@ #define TRUE (1) #define FALSE (0) -#endif // _WIN32 +#endif // !WIN32 Modified: trunk/OpenMPT/unarchiver/unarchiver.cpp =================================================================== --- trunk/OpenMPT/unarchiver/unarchiver.cpp 2013-11-14 21:45:54 UTC (rev 3223) +++ trunk/OpenMPT/unarchiver/unarchiver.cpp 2013-11-14 22:37:30 UTC (rev 3224) @@ -9,8 +9,6 @@ #include "stdafx.h" -#include <Windows.h> - #include "unarchiver.h" #include "../soundlib/FileReader.h" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-15 06:27:36
|
Revision: 3226 http://sourceforge.net/p/modplug/code/3226 Author: manxorist Date: 2013-11-15 06:27:22 +0000 (Fri, 15 Nov 2013) Log Message: ----------- [Ref] sounddev: Cleanup and reorder the ISoundDevice interface so that the class definition is almost readable as documentation. [Ref] sounddev: Return time values as double seconds instead of float milliseconds. [Ref] sounddev: Cleanup sound device opening in CMainFrame and provide slithly better error messages. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.h trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.h trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp trunk/OpenMPT/sounddev/SoundDeviceWaveout.h Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-15 06:27:22 UTC (rev 3226) @@ -747,9 +747,25 @@ } -bool CMainFrame::audioTryOpeningDevice() -//-------------------------------------- +bool CMainFrame::IsAudioDeviceOpen() const +//---------------------------------------- { + return gpSoundDevice && gpSoundDevice->IsOpen(); +} + + +bool CMainFrame::audioOpenDevice() +//-------------------------------- +{ + if(IsAudioDeviceOpen()) + { + return true; + } + if(!TrackerSettings::Instance().GetMixerSettings().IsValid()) + { + Reporting::Error("Unable to open sound device: Invalid mixer settings."); + return false; + } const SoundDeviceID deviceID = TrackerSettings::Instance().m_nWaveDevice; if(gpSoundDevice && (gpSoundDevice->GetDeviceID() != deviceID)) { @@ -762,48 +778,24 @@ } if(!gpSoundDevice) { + Reporting::Error("Unable to open sound device: Could not find sound device."); return false; } gpSoundDevice->SetMessageReceiver(this); gpSoundDevice->SetSource(this); if(!gpSoundDevice->Open(TrackerSettings::Instance().GetSoundDeviceSettings())) { + Reporting::Error("Unable to open sound device: Could not open sound device."); return false; } - return true; -} - - -bool CMainFrame::IsAudioDeviceOpen() const -//---------------------------------------- -{ - return gpSoundDevice && gpSoundDevice->IsOpen(); -} - - -bool CMainFrame::audioOpenDevice() -//-------------------------------- -{ - if(IsAudioDeviceOpen()) + SampleFormat actualSampleFormat = gpSoundDevice->GetActualSampleFormat(); + if(!actualSampleFormat.IsValid()) { - return true; + Reporting::Error("Unable to open sound device: Unknown sample format."); + return false; } - if(TrackerSettings::Instance().GetMixerSettings().IsValid()) - { - if(audioTryOpeningDevice()) - { - SampleFormat actualSampleFormat = gpSoundDevice->GetActualSampleFormat(); - if(actualSampleFormat.IsValid()) - { - TrackerSettings::Instance().m_SampleFormat = actualSampleFormat; - // Device is ready - return true; - } - } - } - // Display error message box - Reporting::Error("Unable to open sound device!"); - return false; + TrackerSettings::Instance().m_SampleFormat = actualSampleFormat; + return true; } Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2013-11-15 06:27:22 UTC (rev 3226) @@ -335,7 +335,6 @@ // from ISoundMessageReceiver void AudioMessage(const std::string &str); - bool audioTryOpeningDevice(); bool audioOpenDevice(); bool audioReopenDevice(); void audioCloseDevice(); Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-15 06:27:22 UTC (rev 3226) @@ -545,10 +545,10 @@ { CHAR s[256]; _snprintf(s, 255, "Buffers: %d\r\nUpdate interval: %4.1f ms\r\nLatency: %4.1f ms\r\nCurrent Latency: %4.1f ms", - pMainFrm->gpSoundDevice->GetNumBuffers(), - (float)pMainFrm->gpSoundDevice->GetRealUpdateIntervalMS(), - (float)pMainFrm->gpSoundDevice->GetRealLatencyMS(), - (float)pMainFrm->gpSoundDevice->GetCurrentRealLatencyMS() + pMainFrm->gpSoundDevice->GetRealNumBuffers(), + (float)(pMainFrm->gpSoundDevice->GetRealUpdateInterval() * 1000.0f), + (float)(pMainFrm->gpSoundDevice->GetRealLatency() * 1000.0f), + (float)(pMainFrm->gpSoundDevice->GetCurrentRealLatency() * 1000.0f) ); m_EditStatistics.SetWindowText(s); } else Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-15 06:27:22 UTC (rev 3226) @@ -39,8 +39,9 @@ , m_InternalID(internalID) { - m_RealLatencyMS = static_cast<float>(m_Settings.LatencyMS); - m_RealUpdateIntervalMS = static_cast<float>(m_Settings.UpdateIntervalMS); + m_RealLatency = m_Settings.LatencyMS / 1000.0; + m_RealUpdateInterval = m_Settings.UpdateIntervalMS / 1000.0; + m_RealNumBuffers = 0; m_IsPlaying = false; m_StreamPositionRenderFrames = 0; @@ -109,8 +110,9 @@ if(m_Settings.LatencyMS > SNDDEV_MAXLATENCY_MS) m_Settings.LatencyMS = SNDDEV_MAXLATENCY_MS; if(m_Settings.UpdateIntervalMS < SNDDEV_MINUPDATEINTERVAL_MS) m_Settings.UpdateIntervalMS = SNDDEV_MINUPDATEINTERVAL_MS; if(m_Settings.UpdateIntervalMS > SNDDEV_MAXUPDATEINTERVAL_MS) m_Settings.UpdateIntervalMS = SNDDEV_MAXUPDATEINTERVAL_MS; - m_RealLatencyMS = static_cast<float>(m_Settings.LatencyMS); - m_RealUpdateIntervalMS = static_cast<float>(m_Settings.UpdateIntervalMS); + m_RealLatency = m_Settings.LatencyMS / 1000.0; + m_RealUpdateInterval = m_Settings.UpdateIntervalMS / 1000.0; + m_RealNumBuffers = 0; return InternalOpen(); } @@ -525,7 +527,7 @@ { CPriorityBooster priorityBooster(*this, m_SoundDevice.m_Settings.BoostThreadPriority); - CPeriodicWaker periodicWaker(*this, 0.001 * m_SoundDevice.GetRealUpdateIntervalMS()); + CPeriodicWaker periodicWaker(*this, m_SoundDevice.GetRealUpdateInterval()); m_SoundDevice.StartFromSoundThread(); Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-15 06:27:22 UTC (rev 3226) @@ -219,15 +219,18 @@ const SoundDeviceID m_ID; + std::wstring m_InternalID; + protected: - std::wstring m_InternalID; - SoundDeviceSettings m_Settings; - float m_RealLatencyMS; - float m_RealUpdateIntervalMS; +private: + double m_RealLatency; + double m_RealUpdateInterval; + int m_RealNumBuffers; + bool m_IsPlaying; mutable Util::mutex m_StreamPositionMutex; @@ -235,20 +238,46 @@ int64 m_StreamPositionOutputFrames; protected: + virtual void FillAudioBuffer() = 0; + void SourceFillAudioBufferLocked(); void SourceAudioRead(void *buffer, std::size_t numFrames); void SourceAudioDone(std::size_t numFrames, int32 framesLatency); + void AudioSendMessage(const std::string &str); +protected: + + bool FillWaveFormatExtensible(WAVEFORMATEXTENSIBLE &WaveFormat); + + void UpdateLatencyInfo(double latency, double updateInterval, int numBuffers) + { + m_RealLatency = latency; + m_RealUpdateInterval = updateInterval; + m_RealNumBuffers = numBuffers; + } + + virtual bool InternalHasGetStreamPosition() const { return false; } + virtual int64 InternalGetStreamPositionFrames() const { return 0; } + + virtual bool InternalIsOpen() const = 0; + + virtual bool InternalOpen() = 0; + virtual void InternalStart() = 0; + virtual void InternalStop() = 0; + virtual bool InternalClose() = 0; + public: + ISoundDevice(SoundDeviceID id, const std::wstring &internalID); virtual ~ISoundDevice(); + void SetSource(ISoundSource *source) { m_Source = source; } ISoundSource *GetSource() const { return m_Source; } void SetMessageReceiver(ISoundMessageReceiver *receiver) { m_MessageReceiver = receiver; } ISoundMessageReceiver *GetMessageReceiver() const { return m_MessageReceiver; } -public: + SoundDeviceID GetDeviceID() const { return m_ID; } SoundDeviceType GetDeviceType() const { return m_ID.GetType(); } SoundDeviceIndex GetDeviceIndex() const { return m_ID.GetIndex(); } @@ -256,32 +285,24 @@ virtual SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); -public: - float GetRealLatencyMS() const { return m_RealLatencyMS; } - float GetRealUpdateIntervalMS() const { return m_RealUpdateIntervalMS; } + bool Open(const SoundDeviceSettings &settings); + bool Close(); + void Start(); + void Stop(); + + bool IsOpen() const { return InternalIsOpen(); } bool IsPlaying() const { return m_IsPlaying; } -protected: - bool FillWaveFormatExtensible(WAVEFORMATEXTENSIBLE &WaveFormat); + SampleFormat GetActualSampleFormat() { return IsOpen() ? m_Settings.sampleFormat : SampleFormatInvalid; } -protected: - virtual bool InternalOpen() = 0; - virtual void InternalStart() = 0; - virtual void InternalStop() = 0; - virtual bool InternalClose() = 0; - virtual bool InternalHasGetStreamPosition() const { return false; } - virtual int64 InternalGetStreamPositionFrames() const { return 0; } + double GetRealLatency() const { return m_RealLatency; } // seconds + double GetRealUpdateInterval() const { return m_RealUpdateInterval; } // seconds + int GetRealNumBuffers() const { return m_RealNumBuffers; } -public: - bool Open(const SoundDeviceSettings &settings); - bool Close(); - void Start(); - void Stop(); + virtual double GetCurrentRealLatency() const { return GetRealLatency(); } + int64 GetStreamPositionFrames() const; - SampleFormat GetActualSampleFormat() { return IsOpen() ? m_Settings.sampleFormat : SampleFormatInvalid; } - virtual bool IsOpen() const = 0; - virtual UINT GetNumBuffers() { return 0; } - virtual float GetCurrentRealLatencyMS() { return GetRealLatencyMS(); } + }; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-15 06:27:22 UTC (rev 3226) @@ -270,8 +270,10 @@ } m_nAsioBufferLen = n; } - m_RealLatencyMS = m_nAsioBufferLen * 2 * 1000.0f / m_Settings.Samplerate; - m_RealUpdateIntervalMS = m_nAsioBufferLen * 1000.0f / m_Settings.Samplerate; + UpdateLatencyInfo( + m_nAsioBufferLen * 2.0 / m_Settings.Samplerate, + m_nAsioBufferLen * 1.0 / m_Settings.Samplerate, + 2); #ifdef ASIO_LOG Log(" Using buffersize=%d samples\n", m_nAsioBufferLen); #endif Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-11-15 06:27:22 UTC (rev 3226) @@ -61,9 +61,7 @@ void FillAudioBuffer(); void InternalStart(); void InternalStop(); - bool IsOpen() const { return (m_pAsioDrv != nullptr); } - UINT GetNumBuffers() { return 2; } - float GetCurrentRealLatencyMS() { return m_nAsioBufferLen * 2 * 1000.0f / m_Settings.Samplerate; } + bool InternalIsOpen() const { return (m_pAsioDrv != nullptr); } SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-11-15 06:27:22 UTC (rev 3226) @@ -251,8 +251,10 @@ m_pMixBuffer->GetStatus(&dwStat); if (dwStat & DSBSTATUS_BUFFERLOST) m_pMixBuffer->Restore(); } - m_RealLatencyMS = m_nDSoundBufferSize * 1000.0f / m_Settings.GetBytesPerSecond(); - m_RealUpdateIntervalMS = CLAMP(static_cast<float>(m_Settings.UpdateIntervalMS), 1.0f, m_nDSoundBufferSize * 1000.0f / ( 2.0f * m_Settings.GetBytesPerSecond() ) ); + UpdateLatencyInfo( + m_nDSoundBufferSize * 1.0 / m_Settings.GetBytesPerSecond(), + std::min(m_Settings.UpdateIntervalMS / 1000.0, m_nDSoundBufferSize / (2.0 * m_Settings.GetBytesPerSecond())), + 1); m_dwWritePos = 0xFFFFFFFF; return true; } Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-11-15 06:27:22 UTC (rev 3226) @@ -45,9 +45,8 @@ void FillAudioBuffer(); void StartFromSoundThread(); void StopFromSoundThread(); - bool IsOpen() const { return (m_pMixBuffer != NULL); } - UINT GetNumBuffers() { return 1; } // meaning 1 ring buffer - float GetCurrentRealLatencyMS() { return m_dwLatency * 1000.0f / m_Settings.GetBytesPerSecond(); } + bool InternalIsOpen() const { return (m_pMixBuffer != NULL); } + double GetCurrentRealLatency() const { return 1.0 * m_dwLatency / m_Settings.GetBytesPerSecond(); } SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); protected: Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-15 06:27:22 UTC (rev 3226) @@ -34,7 +34,7 @@ MemsetZero(m_StreamParameters); m_Stream = 0; m_CurrentFrameCount = 0; - m_CurrentRealLatencyMS = 0.0f; + m_CurrentRealLatency = 0.0; } @@ -89,8 +89,10 @@ m_Stream = 0; return false; } - m_RealLatencyMS = static_cast<float>(Pa_GetStreamInfo(m_Stream)->outputLatency) * 1000.0f; - m_RealUpdateIntervalMS = static_cast<float>(m_Settings.UpdateIntervalMS); + UpdateLatencyInfo( + Pa_GetStreamInfo(m_Stream)->outputLatency, + m_Settings.UpdateIntervalMS / 1000.0, + 1); return true; } @@ -102,7 +104,10 @@ { Pa_AbortStream(m_Stream); Pa_CloseStream(m_Stream); - if(Pa_GetDeviceInfo(m_StreamParameters.device)->hostApi == Pa_HostApiTypeIdToHostApiIndex(paWDMKS)) Pa_Sleep((long)(m_RealLatencyMS*2)); // wait for broken wdm drivers not closing the stream immediatly + if(Pa_GetDeviceInfo(m_StreamParameters.device)->hostApi == Pa_HostApiTypeIdToHostApiIndex(paWDMKS)) + { + Pa_Sleep((long)(GetRealLatency() * 2.0 * 1000.0)); // wait for broken wdm drivers not closing the stream immediatly + } MemsetZero(m_StreamParameters); m_Stream = 0; m_CurrentFrameCount = 0; @@ -131,7 +136,7 @@ { if(m_CurrentFrameCount == 0) return; SourceAudioRead(m_CurrentFrameBuffer, m_CurrentFrameCount); - SourceAudioDone(m_CurrentFrameCount, static_cast<ULONG>(m_CurrentRealLatencyMS * Pa_GetStreamInfo(m_Stream)->sampleRate / 1000.0f)); + SourceAudioDone(m_CurrentFrameCount, static_cast<ULONG>(m_CurrentRealLatency * Pa_GetStreamInfo(m_Stream)->sampleRate)); } @@ -143,10 +148,10 @@ } -float CPortaudioDevice::GetCurrentRealLatencyMS() -//----------------------------------------------- +double CPortaudioDevice::GetCurrentRealLatency() const +//---------------------------------------------------- { - return m_CurrentRealLatencyMS; + return m_CurrentRealLatency; } @@ -201,10 +206,10 @@ { // For WDM-KS, timeInfo->outputBufferDacTime seems to contain bogus values. // Work-around it by using the slightly less accurate per-stream latency estimation. - m_CurrentRealLatencyMS = static_cast<float>( Pa_GetStreamInfo(m_Stream)->outputLatency * 1000.0 ); + m_CurrentRealLatency = Pa_GetStreamInfo(m_Stream)->outputLatency; } else { - m_CurrentRealLatencyMS = static_cast<float>( timeInfo->outputBufferDacTime - timeInfo->currentTime ) * 1000.0f; + m_CurrentRealLatency = timeInfo->outputBufferDacTime - timeInfo->currentTime; } m_CurrentFrameBuffer = output; m_CurrentFrameCount = frameCount; Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-11-15 06:27:22 UTC (rev 3226) @@ -36,7 +36,7 @@ void * m_CurrentFrameBuffer; unsigned long m_CurrentFrameCount; - float m_CurrentRealLatencyMS; + double m_CurrentRealLatency; // seconds public: CPortaudioDevice(SoundDeviceID id, const std::wstring &internalID); @@ -48,9 +48,8 @@ void FillAudioBuffer(); void InternalStart(); void InternalStop(); - bool IsOpen() const { return m_Stream ? true : false; } - UINT GetNumBuffers() { return 1; } - float GetCurrentRealLatencyMS(); + bool InternalIsOpen() const { return m_Stream ? true : false; } + double GetCurrentRealLatency() const; bool InternalHasGetStreamPosition() const { return false; } int64 InternalGetStreamPositionFrames() const; SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-11-15 06:27:22 UTC (rev 3226) @@ -93,8 +93,10 @@ Close(); return false; } - m_RealLatencyMS = m_nWaveBufferSize * m_nPreparedHeaders * 1000.0f / m_Settings.GetBytesPerSecond(); - m_RealUpdateIntervalMS = m_nWaveBufferSize * 1000.0f / m_Settings.GetBytesPerSecond(); + UpdateLatencyInfo( + m_nWaveBufferSize * m_nPreparedHeaders * 1.0 / m_Settings.GetBytesPerSecond(), + m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(), + m_nPreparedHeaders); m_nBuffersPending = 0; m_nWriteBuffer = 0; return true; Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-11-14 23:10:53 UTC (rev 3225) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-11-15 06:27:22 UTC (rev 3226) @@ -30,7 +30,7 @@ bool m_JustStarted; ULONG m_nPreparedHeaders; ULONG m_nWriteBuffer; - LONG m_nBuffersPending; + mutable LONG m_nBuffersPending; std::vector<WAVEHDR> m_WaveBuffers; std::vector<std::vector<char> > m_WaveBuffersData; @@ -44,9 +44,8 @@ void FillAudioBuffer(); void StartFromSoundThread(); void StopFromSoundThread(); - bool IsOpen() const { return (m_hWaveOut != NULL); } - UINT GetNumBuffers() { return m_nPreparedHeaders; } - float GetCurrentRealLatencyMS() { return InterlockedExchangeAdd(&m_nBuffersPending, 0) * m_nWaveBufferSize * 1000.0f / m_Settings.GetBytesPerSecond(); } + bool InternalIsOpen() const { return (m_hWaveOut != NULL); } + double GetCurrentRealLatency() const { return InterlockedExchangeAdd(&m_nBuffersPending, 0) * m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); } bool InternalHasGetStreamPosition() const { return true; } int64 InternalGetStreamPositionFrames() const; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-15 15:59:00
|
Revision: 3228 http://sourceforge.net/p/modplug/code/3228 Author: manxorist Date: 2013-11-15 15:58:53 +0000 (Fri, 15 Nov 2013) Log Message: ----------- [Fix] RelativePathToAbsolute and AbsolutePathToRelative return the modified path for mpt::PathString instead of modifying the parameter in-place to allow usage in function arguments. This hab been overlooked in a few places during the mpt::PathString conversion. Assign the return value in all cases. [Ref] Remove non-mpt::PathString variants. These are unused by now. Modified Paths: -------------- trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-15 14:10:44 UTC (rev 3227) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-15 15:58:53 UTC (rev 3228) @@ -425,7 +425,7 @@ if(!szFileName.empty()) { if(theApp.IsPortableMode()) - theApp.AbsolutePathToRelative(szFileName); + szFileName = theApp.AbsolutePathToRelative(szFileName); file.Write<mpt::PathString>("Midi Library", s, szFileName); } } @@ -1948,7 +1948,7 @@ mpt::PathString plugPath = theApp.GetSettings().Read<mpt::PathString>("VST Plugins", tmp, MPT_PATHSTRING("")); if(!plugPath.empty()) { - RelativePathToAbsolute(plugPath); + plugPath = RelativePathToAbsolute(plugPath); if(plugPath == failedPlugin) { @@ -1989,7 +1989,7 @@ mpt::PathString plugPath = pPlug->dllPath; if(theApp.IsPortableMode()) { - AbsolutePathToRelative(plugPath); + plugPath = AbsolutePathToRelative(plugPath); } theApp.GetSettings().Write<mpt::PathString>("VST Plugins", tmp, plugPath); plug++; @@ -2071,23 +2071,7 @@ return result; } -template <size_t nLength> -void CTrackApp::AbsolutePathToRelative(TCHAR (&szPath)[nLength]) -//--------------------------------------------------------------- -{ - STATIC_ASSERT(nLength >= 3); - if(_tcslen(szPath) == 0) - return; - mpt::String::Copy(szPath, AbsolutePathToRelative(mpt::PathString::ToCString(szPath)).ToCString()); -} -CString CTrackApp::AbsolutePathToRelative(const CString &path) -//------------------------------------------------------------ -{ - return AbsolutePathToRelative(mpt::PathString::FromCString(path)).ToCString(); -} - - // Convert a relative path to an absolute path. // Paths are relative to the executable path. mpt::PathString CTrackApp::RelativePathToAbsolute(const mpt::PathString &path) @@ -2113,23 +2097,6 @@ return result; } -template <size_t nLength> -void CTrackApp::RelativePathToAbsolute(TCHAR (&szPath)[nLength]) -//--------------------------------------------------------------- -{ - STATIC_ASSERT(nLength >= 3); - if(_tcslen(szPath) == 0) - return; - mpt::String::Copy(szPath, RelativePathToAbsolute(mpt::PathString::ToCString(szPath)).ToCString()); -} - -CString CTrackApp::RelativePathToAbsolute(const CString &path) -//------------------------------------------------------------ -{ - return RelativePathToAbsolute(mpt::PathString::FromCString(path)).ToCString(); -} - - void CTrackApp::RemoveMruItem(const int nItem) //-------------------------------------------- { Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2013-11-15 14:10:44 UTC (rev 3227) +++ trunk/OpenMPT/mptrack/Mptrack.h 2013-11-15 15:58:53 UTC (rev 3228) @@ -207,12 +207,6 @@ // Relative / absolute paths conversion mpt::PathString AbsolutePathToRelative(const mpt::PathString &path); mpt::PathString RelativePathToAbsolute(const mpt::PathString &path); - template <size_t nLength> - MPT_DEPRECATED_PATH void AbsolutePathToRelative(TCHAR (&szPath)[nLength]); - MPT_DEPRECATED_PATH CString AbsolutePathToRelative(const CString &path); - template <size_t nLength> - MPT_DEPRECATED_PATH void RelativePathToAbsolute(TCHAR (&szPath)[nLength]); - MPT_DEPRECATED_PATH CString RelativePathToAbsolute(const CString &path); /// Removes item from MRU-list; most recent item has index zero. void RemoveMruItem(const int nItem); Modified: trunk/OpenMPT/soundlib/plugins/PluginManager.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-15 14:10:44 UTC (rev 3227) +++ trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-15 15:58:53 UTC (rev 3228) @@ -400,7 +400,7 @@ mpt::PathString writePath = dllPath; if(theApp.IsPortableMode()) { - theApp.AbsolutePathToRelative(writePath); + writePath = theApp.AbsolutePathToRelative(writePath); } cacheFile.Write<mpt::PathString>(cacheSection, IDs, writePath); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-15 18:19:15
|
Revision: 3234 http://sourceforge.net/p/modplug/code/3234 Author: saga-games Date: 2013-11-15 18:19:09 +0000 (Fri, 15 Nov 2013) Log Message: ----------- [Ref] Memory-mapped files: Joined Close and Unlock functions. The only place that called Unlock was closing the file afterwards anyway. Modified Paths: -------------- trunk/OpenMPT/mptrack/MemoryMappedFile.cpp trunk/OpenMPT/mptrack/MemoryMappedFile.h trunk/OpenMPT/soundlib/Dlsbank.cpp Modified: trunk/OpenMPT/mptrack/MemoryMappedFile.cpp =================================================================== --- trunk/OpenMPT/mptrack/MemoryMappedFile.cpp 2013-11-15 18:16:14 UTC (rev 3233) +++ trunk/OpenMPT/mptrack/MemoryMappedFile.cpp 2013-11-15 18:19:09 UTC (rev 3234) @@ -42,7 +42,23 @@ void CMappedFile::Close() //----------------------- { - if(m_pData) Unlock(); + // Unlock file + if(m_hFMap) + { + if(m_pData) + { + UnmapViewOfFile(m_pData); + m_pData = nullptr; + } + CloseHandle(m_hFMap); + m_hFMap = nullptr; + } else if(m_pData) + { + free(m_pData); + m_pData = nullptr; + } + + // Close file handle if(m_hFile) { CloseHandle(m_hFile); @@ -124,23 +140,3 @@ { return FileReader(Lock(), GetLength()); } - - -void CMappedFile::Unlock() -//------------------------ -{ - if(m_hFMap) - { - if(m_pData) - { - UnmapViewOfFile(m_pData); - m_pData = nullptr; - } - CloseHandle(m_hFMap); - m_hFMap = nullptr; - } else if(m_pData) - { - free(m_pData); - m_pData = nullptr; - } -} Modified: trunk/OpenMPT/mptrack/MemoryMappedFile.h =================================================================== --- trunk/OpenMPT/mptrack/MemoryMappedFile.h 2013-11-15 18:16:14 UTC (rev 3233) +++ trunk/OpenMPT/mptrack/MemoryMappedFile.h 2013-11-15 18:19:09 UTC (rev 3234) @@ -34,5 +34,4 @@ size_t GetLength(); const void *Lock(); FileReader GetFile(); - void Unlock(); }; Modified: trunk/OpenMPT/soundlib/Dlsbank.cpp =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-11-15 18:16:14 UTC (rev 3233) +++ trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-11-15 18:19:09 UTC (rev 3234) @@ -1199,8 +1199,6 @@ || ((priff->id_DLS != IFFID_DLS) && (priff->id_DLS != IFFID_MLS) && (priff->id_DLS != IFFID_sfbk)) || (dwMemPos + priff->riff_len > dwMemLength-8)) { - MapFile.Unlock(); - MapFile.Close(); #ifdef DLSBANK_LOG Log("Invalid DLS bank!\n"); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-16 17:37:23
|
Revision: 3237 http://sourceforge.net/p/modplug/code/3237 Author: saga-games Date: 2013-11-16 17:37:15 +0000 (Sat, 16 Nov 2013) Log Message: ----------- [Imp] Mod Export is no longer limited to 2GB files. [Mod] OpenMPT: Version is now 1.22.07.01 Modified Paths: -------------- trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/mptrack/Mod2wave.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/mod2wave.h Modified: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h 2013-11-16 14:58:33 UTC (rev 3236) +++ trunk/OpenMPT/common/versionNumber.h 2013-11-16 17:37:15 UTC (rev 3237) @@ -16,8 +16,8 @@ //Version definitions. The only thing that needs to be changed when changing version number. #define VER_MAJORMAJOR 1 #define VER_MAJOR 22 -#define VER_MINOR 06 -#define VER_MINORMINOR 03 +#define VER_MINOR 07 +#define VER_MINORMINOR 01 //Version string. For example "1.17.02.28" #define MPT_VERSION_STR VER_STRINGIZE(VER_MAJORMAJOR) "." VER_STRINGIZE(VER_MAJOR) "." VER_STRINGIZE(VER_MINOR) "." VER_STRINGIZE(VER_MINORMINOR) Modified: trunk/OpenMPT/mptrack/Mod2wave.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mod2wave.cpp 2013-11-16 14:58:33 UTC (rev 3236) +++ trunk/OpenMPT/mptrack/Mod2wave.cpp 2013-11-16 17:37:15 UTC (rev 3237) @@ -861,7 +861,7 @@ static int mixbuffer[MIXBUFFERSIZE * 4]; // channels MSG msg; - CHAR s[80]; + TCHAR s[80]; HWND progress = ::GetDlgItem(m_hWnd, IDC_PROGRESS1); UINT ok = IDOK, pos = 0; uint64 ullSamples = 0, ullMaxSamples; @@ -938,7 +938,7 @@ m_SndFile.SetMixerSettings(mixersettings); m_SndFile.SetResamplerSettings(TrackerSettings::Instance().GetResamplerSettings()); m_SndFile.InitPlayer(TRUE); - if ((!m_dwFileLimit) || (m_dwFileLimit > 2047*1024)) m_dwFileLimit = 2047*1024; // 2GB + if(!m_dwFileLimit) m_dwFileLimit = Util::MaxValueOfType(m_dwFileLimit) >> 10; m_dwFileLimit <<= 10; fileEnc->SetFormat(encSettings); @@ -1002,7 +1002,7 @@ // For giving away some processing time every now and then DWORD dwSleepTime = dwStartTime; - size_t bytesWritten = 0; + uint64 bytesWritten = 0; CMainFrame::GetMainFrame()->PauseMod(); m_SndFile.m_SongFlags.reset(SONG_STEP | SONG_PATTERNLOOP); @@ -1069,7 +1069,7 @@ fileEnc->WriteInterleavedConverted(lRead, buffer); } const std::streampos newPos = fileStream.tellp(); - bytesWritten += static_cast<std::size_t>(newPos - oldPos); + bytesWritten += static_cast<uint64>(newPos - oldPos); if(bytesWritten >= m_dwFileLimit) { @@ -1087,18 +1087,18 @@ DWORD l = (DWORD)(ullSamples / m_SndFile.m_MixerSettings.gdwMixingFreq); const DWORD dwCurrentTime = timeGetTime(); - DWORD timeRemaining = 0; // estimated remainig time + uint32 timeRemaining = 0; // estimated remainig time if((ullSamples > 0) && (ullSamples < max)) { - timeRemaining = static_cast<DWORD>(((dwCurrentTime - dwStartTime) * (max - ullSamples) / ullSamples) / 1000); + timeRemaining = static_cast<uint32>(((dwCurrentTime - dwStartTime) * (max - ullSamples) / ullSamples) / 1000); } if(m_Settings.Normalize) { - wsprintf(s, "Rendering file... (%umn%02us, %umn%02us remaining)", l / 60, l % 60, timeRemaining / 60, timeRemaining % 60); + _stprintf(s, _T("Rendering file... (%umn%02us, %umn%02us remaining)"), l / 60, l % 60, timeRemaining / 60, timeRemaining % 60u); } else { - wsprintf(s, "Writing file... (%uKB, %umn%02us, %umn%02us remaining)", bytesWritten >> 10, l / 60, l % 60, timeRemaining / 60, timeRemaining % 60); + _stprintf(s, _T("Writing file... (%lluKB, %umn%02us, %umn%02us remaining)"), bytesWritten >> 10, l / 60, l % 60u, timeRemaining / 60, timeRemaining % 60u); } SetDlgItemText(IDC_TEXT1, s); @@ -1186,7 +1186,7 @@ int percent = static_cast<int>(100 * framesProcessed / framesTotal); if(percent != lastPercent) { - wsprintf(s, "Normalizing... (%d%%)", percent); + _stprintf(s, _T("Normalizing... (%d%%)"), percent); SetDlgItemText(IDC_TEXT1, s); ::SendMessage(progress, PBM_SETPOS, percent, 0); lastPercent = percent; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-16 14:58:33 UTC (rev 3236) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-16 17:37:15 UTC (rev 3237) @@ -1793,7 +1793,7 @@ // Render song (or current channel, or current sample/instrument) CDoWaveConvert dwcdlg(m_SndFile, thisName, wsdlg.m_Settings, pMainFrm); - dwcdlg.m_dwFileLimit = static_cast<DWORD>(wsdlg.m_dwFileLimit); + dwcdlg.m_dwFileLimit = wsdlg.m_dwFileLimit; dwcdlg.m_bGivePlugsIdleTime = wsdlg.m_bGivePlugsIdleTime; dwcdlg.m_dwSongLimit = wsdlg.m_dwSongLimit; Modified: trunk/OpenMPT/mptrack/mod2wave.h =================================================================== --- trunk/OpenMPT/mptrack/mod2wave.h 2013-11-16 14:58:33 UTC (rev 3236) +++ trunk/OpenMPT/mptrack/mod2wave.h 2013-11-16 17:37:15 UTC (rev 3237) @@ -68,8 +68,7 @@ CWaveConvertSettings m_Settings; const Encoder::Traits *encTraits; CSoundFile &m_SndFile; - uint64 m_dwFileLimit; - DWORD m_dwSongLimit; + uint64 m_dwFileLimit, m_dwSongLimit; ORDERINDEX m_nNumOrders; CComboBox m_CbnFileType, m_CbnSampleRate, m_CbnChannels, m_CbnSampleFormat; @@ -125,7 +124,7 @@ const CWaveConvertSettings &m_Settings; CSoundFile &m_SndFile; mpt::PathString m_lpszFileName; - DWORD m_dwFileLimit, m_dwSongLimit; + uint64 m_dwFileLimit, m_dwSongLimit; bool m_bAbort, m_bGivePlugsIdleTime; public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-16 18:09:13
|
Revision: 3238 http://sourceforge.net/p/modplug/code/3238 Author: manxorist Date: 2013-11-16 18:09:05 +0000 (Sat, 16 Nov 2013) Log Message: ----------- [Mod] Rework the MFC code path that manages filenames for MDI documents. This causes problems for us because we are trying to pass wide filenames through MFC classes which expect CP_ACP CStrings in ANSI builds (which we still use). This should make working with unicode paths (in particular for modules themselves) in almost all cases in OpenMPT work without too annoying problems. [Ref] Convert remaining parst of auto saving functionaluity to mpt::PathString. [Var] More detailed documentation for our hack/workaround (also found in the code itself): mptrack/Mptrack.h: OK, this is a really dirty hack for ANSI builds (which are still used because the code is not yet UNICODE compatible). To support wide path names even in ansi builds, we use mpt::PathString everywhere. Except, there is one set of cases, where MFC dictates TCHAR/CString on us: The filename handling for MDI documents. Here, if in ANSI build, we encode the wide string in utf8 and pass it around through MFC. When MFC calls us again, we unpack it again. This works surprisingly well for the hackish nature this has. Rough edges: - CDocument::GetTitle is still ANSI encoded and returns replacement chars for non-representable chars. - CWinApp::AddToRecentFileList chokes on filenames it cannot access. We simply avoid passing non-ansi-representable filenames there. Modified MFC functionality: CTrackApp: CWinApp::OpenDocument CWinApp::AddToRecentFileList CModDocManager: CDocManager::OpenDocumentFile CModDocTemplate: CMultiDocTemplate::OpenDocumentFile CModDoc: CDocument::GetPathName CDocument::SetPathName CDocument::DoSave CDocument::OnOpenDocument CDocument::OnSaveDocument mptrack/Moddoc.h: As paths are faked into utf8 when !UNICODE, explicitly set the title in locale again. This replaces non-ANSI characters in the title with replacement character but overall the unicode handling is sane and consistent this way. common/mptPathString.cpp: Since MFC code can call into our code from a lot of places, we cannot assume that filenames we get from MFC are always encoded in our hacked UTF8-in-CString encoding. Instead, we use a rough heuristic: if the string is parseable as UTF8, we assume it is. This fails for CP_ACP strings, that are also valid UTF8. That's the trade-off here. Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.cpp trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/AutoSaver.cpp trunk/OpenMPT/mptrack/CloseMainDialog.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/ExceptionHandler.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptPathString.cpp =================================================================== --- trunk/OpenMPT/common/mptPathString.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/common/mptPathString.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -67,6 +67,54 @@ return name + ext; } +PathString PathString::ReplaceExt(const mpt::PathString &newExt) const +{ + return GetDrive() + GetDir() + GetFileName() + newExt; +} + +PathString PathString::SanitizeComponent() const +{ + PathString result = *this; + SanitizeFilename(result); + return result; +} + +#if defined(WIN32) +#if defined(_MFC_VER) + +mpt::PathString PathString::TunnelOutofCString(const CString &path) +{ + #ifdef UNICODE + return mpt::PathString::FromWide(path.GetString()); + #else + // Since MFC code can call into our code from a lot of places, we cannot assume + // that filenames we get from MFC are always encoded in our hacked UTF8-in-CString encoding. + // Instead, we use a rough heuristic: if the string is parseable as UTF8, we assume it is. + // This fails for CP_ACP strings, that are also valid UTF8. That's the trade-off here. + if(mpt::To(mpt::CharsetUTF8, mpt::ToWide(mpt::CharsetUTF8, path.GetString())) == path.GetString()) + { + // utf8 + return mpt::PathString::FromUTF8(path.GetString()); + } else + { + // ANSI + return mpt::PathString::FromWide(mpt::ToWide(path)); + } + #endif +} + +CString PathString::TunnelIntoCString(const mpt::PathString &path) +{ + #ifdef UNICODE + return path.ToWide().c_str(); + #else + return path.ToUTF8().c_str(); + #endif +} + +#endif +#endif + } // namespace mpt #endif Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-16 18:09:05 UTC (rev 3238) @@ -64,6 +64,10 @@ { return PathString(a).append(b); } + friend bool operator < (const PathString & a, const PathString & b) + { + return a.AsNative() < b.AsNative(); + } friend bool operator == (const PathString & a, const PathString & b) { return a.AsNative() == b.AsNative(); @@ -93,6 +97,14 @@ PathString GetFileExt() const; // Extension including dot, e.g. ".exe" PathString GetFullFileName() const; // File name + extension, e.g. "mptrack.exe" + // Return the same path string with a different (or appended) extension (including "."), e.g. "foo.bar",".txt" -> "foo.txt" or "C:\OpenMPT\foo",".txt" -> "C:\OpenMPT\foo.txt" + PathString ReplaceExt(const mpt::PathString &newExt) const; + + // Removes special characters from a filename component and replaces them with a safe replacement character ("_" on windows). + // Returns the result. + // Note that this also removes path component separators, so this should only be used on single-component PathString objects. + PathString SanitizeComponent() const; + bool HasTrailingSlash() const { if(empty()) @@ -127,6 +139,9 @@ // CString TCHAR, so this is CHAR or WCHAR, depending on UNICODE MPT_DEPRECATED_PATH CString ToCString() const { return mpt::ToCString(path); } MPT_DEPRECATED_PATH static PathString FromCString(const CString &path) { return PathString(mpt::ToWide(path)); } + // really special purpose, if !UNICODE, encode unicode in CString as UTF8: + static mpt::PathString TunnelOutofCString(const CString &path); + static CString TunnelIntoCString(const mpt::PathString &path); #endif #else // !WIN32 Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp =================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -214,15 +214,15 @@ if(modDoc.m_bHasValidPath) { // Check that the file has a user-chosen path - name = mpt::PathString::FromCString(modDoc.GetPathName()); + name = modDoc.GetPathNameMpt(); } else { // if it doesnt, put it in settings dir - name = theApp.GetConfigPath() + mpt::PathString::FromCString(modDoc.GetTitle()); + name = theApp.GetConfigPath() + mpt::PathString::FromWide(mpt::ToWide(modDoc.GetTitle())).SanitizeComponent(); } } else { - name = m_csPath + mpt::PathString::FromCString(modDoc.GetTitle()); + name = m_csPath + mpt::PathString::FromWide(mpt::ToWide(modDoc.GetTitle())).SanitizeComponent(); } name += MPT_PATHSTRING(".AutoSave."); //append backup tag @@ -286,44 +286,50 @@ void CAutoSaver::CleanUpBackups(CModDoc &modDoc) //---------------------------------------------- { - CString path; + mpt::PathString path; if (m_bUseOriginalPath) { if (modDoc.m_bHasValidPath) // Check that the file has a user-chosen path { - CString fullPath = modDoc.GetPathName(); - path = fullPath.Left(fullPath.GetLength() - modDoc.GetTitle().GetLength()); //remove file name if necessary + mpt::PathString fullPath = modDoc.GetPathNameMpt(); + path = fullPath.GetDrive() + fullPath.GetDir(); // remove file name } else { - path = theApp.GetConfigPath().ToCString(); + path = theApp.GetConfigPath(); } } else { - path = m_csPath.ToCString(); + path = m_csPath; } - CString searchPattern = path + modDoc.GetTitle() + ".AutoSave.*"; + std::vector<mpt::PathString> foundfiles; + mpt::PathString searchPattern = path + mpt::PathString::FromWide(mpt::ToWide(modDoc.GetTitle())).SanitizeComponent() + MPT_PATHSTRING(".AutoSave.*"); - CFileFind finder; - BOOL bResult = finder.FindFile(searchPattern); - std::vector<CString> foundfiles; - - while(bResult) + WIN32_FIND_DATAW findData; + MemsetZero(findData); + HANDLE hFindFile = FindFirstFileW(searchPattern.AsNative().c_str(), &findData); + if(hFindFile != INVALID_HANDLE_VALUE) { - bResult = finder.FindNextFile(); - foundfiles.push_back(path + finder.GetFileName()); + while(true) + { + if(!(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + foundfiles.push_back(path + mpt::PathString::FromNative(findData.cFileName)); + } + if(FindNextFileW(hFindFile, &findData) == FALSE) + { + break; + } + } + FindClose(hFindFile); + hFindFile = INVALID_HANDLE_VALUE; } - finder.Close(); + std::sort(foundfiles.begin(), foundfiles.end()); - std::sort(foundfiles.begin(), foundfiles.end()); while(foundfiles.size() > m_nBackupHistory) { - try - { - CString toRemove = foundfiles[0]; - CFile::Remove(toRemove); - } catch (CFileException* /*pEx*/){} + DeleteFileW(foundfiles[0].AsNative().c_str()); foundfiles.erase(foundfiles.begin()); } @@ -371,7 +377,7 @@ CheckDlgButton(IDC_AUTOSAVE_ENABLE, m_pAutoSaver->IsEnabled()?BST_CHECKED:BST_UNCHECKED); //SetDlgItemText(IDC_AUTOSAVE_FNTEMPLATE, m_pAutoSaver->GetFilenameTemplate()); SetDlgItemInt(IDC_AUTOSAVE_HISTORY, m_pAutoSaver->GetHistoryDepth()); //TODO - SetDlgItemText(IDC_AUTOSAVE_PATH, m_pAutoSaver->GetPath().ToCString()); + ::SetDlgItemTextW(m_hWnd, IDC_AUTOSAVE_PATH, m_pAutoSaver->GetPath().AsNative().c_str()); SetDlgItemInt(IDC_AUTOSAVE_INTERVAL, m_pAutoSaver->GetSaveInterval()); CheckDlgButton(IDC_AUTOSAVE_USEORIGDIR, m_pAutoSaver->GetUseOriginalPath()?BST_CHECKED:BST_UNCHECKED); CheckDlgButton(IDC_AUTOSAVE_USECUSTOMDIR, m_pAutoSaver->GetUseOriginalPath()?BST_UNCHECKED:BST_CHECKED); @@ -386,29 +392,32 @@ void CAutoSaverGUI::OnOK() { - CString tempPath; + WCHAR tempPath[MAX_PATH]; IsDlgButtonChecked(IDC_AUTOSAVE_ENABLE) ? m_pAutoSaver->Enable() : m_pAutoSaver->Disable(); m_pAutoSaver->SetFilenameTemplate(MPT_PATHSTRING("")); //TODO m_pAutoSaver->SetHistoryDepth(GetDlgItemInt(IDC_AUTOSAVE_HISTORY)); m_pAutoSaver->SetSaveInterval(GetDlgItemInt(IDC_AUTOSAVE_INTERVAL)); m_pAutoSaver->SetUseOriginalPath(IsDlgButtonChecked(IDC_AUTOSAVE_USEORIGDIR) == BST_CHECKED); - GetDlgItemText(IDC_AUTOSAVE_PATH, tempPath); - if (!tempPath.IsEmpty() && (tempPath.Right(1)!="\\")) - tempPath.Append("\\"); - m_pAutoSaver->SetPath(mpt::PathString::FromCString(tempPath)); + ::GetDlgItemTextW(m_hWnd, IDC_AUTOSAVE_PATH, tempPath, CountOf(tempPath)); + mpt::PathString path = mpt::PathString::FromNative(tempPath); + if(!path.empty() && !path.HasTrailingSlash()) + { + path += MPT_PATHSTRING("\\"); + } + m_pAutoSaver->SetPath(path); CPropertyPage::OnOK(); } void CAutoSaverGUI::OnBnClickedAutosaveBrowse() { - TCHAR szPath[_MAX_PATH] = TEXT(""); - GetDlgItemText(IDC_AUTOSAVE_PATH, szPath, CountOf(szPath)); + WCHAR szPath[MAX_PATH] = L""; + ::GetDlgItemTextW(m_hWnd, IDC_AUTOSAVE_PATH, szPath, CountOf(szPath)); - BrowseForFolder dlg(mpt::PathString::FromCString(szPath), TEXT("Select a folder to store autosaved files in...")); + BrowseForFolder dlg(mpt::PathString::FromNative(szPath), TEXT("Select a folder to store autosaved files in...")); if(dlg.Show()) { - SetDlgItemText(IDC_AUTOSAVE_PATH, dlg.GetDirectory().ToCString()); + ::SetDlgItemTextW(m_hWnd, IDC_AUTOSAVE_PATH, dlg.GetDirectory().AsNative().c_str()); OnSettingsChanged(); } } Modified: trunk/OpenMPT/mptrack/CloseMainDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/CloseMainDialog.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/CloseMainDialog.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -36,7 +36,7 @@ CString CloseMainDialog::FormatTitle(const CModDoc *pModDoc, bool fullPath) //------------------------------------------------------------------------- { - const CString &path = (!fullPath || pModDoc->GetPathName().IsEmpty()) ? pModDoc->GetTitle() : pModDoc->GetPathName(); + const CString &path = (!fullPath || pModDoc->GetPathNameMpt().empty()) ? pModDoc->GetTitle() : pModDoc->GetPathNameMpt().ToCString(); return CString(pModDoc->GetrSoundFile().GetTitle().c_str()) + CString(" (") + path + CString(")"); } Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -1007,7 +1007,7 @@ } else { // save all samples - fileName = mpt::PathString::FromCString(m_sndFile.GetpModDoc()->GetPathName()).GetFileName(); + fileName = m_sndFile.GetpModDoc()->GetPathNameMpt().GetFileName(); if(fileName.empty()) fileName = MPT_PATHSTRING("untitled"); fileName += MPT_PATHSTRING(" - %sample_number% - "); Modified: trunk/OpenMPT/mptrack/ExceptionHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -109,9 +109,15 @@ // Show the rescue directory in Explorer... CTrackApp::OpenDirectory(baseRescuePath); } - CString filename; - filename.Format("%s%d_%s.%s", baseRescuePath.ToCString(), ++numFiles, pModDoc->GetTitle(), pModDoc->GetSoundFile()->GetModSpecifications().fileExtension); + mpt::PathString filename; + filename += baseRescuePath; + filename += mpt::PathString::FromWide(mpt::ToWString(++numFiles)); + filename += MPT_PATHSTRING("_"); + filename += mpt::PathString::FromWide(mpt::ToWide(pModDoc->GetTitle())).SanitizeComponent(); + filename += MPT_PATHSTRING("."); + filename += mpt::PathString::FromUTF8(pModDoc->GetSoundFile()->GetModSpecifications().fileExtension); + try { pModDoc->OnSaveDocument(filename); Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -491,7 +491,7 @@ if(::DragQueryFileW(hDropInfo, f, fileName, CountOf(fileName))) { const mpt::PathString file = mpt::PathString::FromNative(fileName); - theApp.OpenDocumentFile(file.ToCString()); + theApp.OpenDocumentFile(file); } } ::DragFinish(hDropInfo); @@ -2132,7 +2132,7 @@ const bool bAvailable = Util::sdOs::IsPathFileAvailable(sPath, Util::sdOs::FileModeRead); if (bAvailable) { - CDocument* pDoc = theApp.OpenDocumentFile(sPath.ToCString(), bTemplateFile ? FALSE : TRUE); + CDocument* pDoc = theApp.OpenDocumentFile(sPath, bTemplateFile ? FALSE : TRUE); if (pDoc != nullptr) { ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CModDoc)) == TRUE); Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -208,14 +208,14 @@ } -BOOL CModDoc::OnOpenDocument(LPCTSTR lpszPathName) -//------------------------------------------------ +BOOL CModDoc::OnOpenDocument(const mpt::PathString &filename) +//----------------------------------------------------------- { BOOL bModified = TRUE; ScopedLogCapturer logcapturer(*this); - if (!lpszPathName) return OnNewDocument(); + if(filename.empty()) return OnNewDocument(); BeginWaitCursor(); #ifndef NO_FILEREADER_STD_ISTREAM @@ -224,7 +224,7 @@ #else { CMappedFile f; - if (f.Open(mpt::PathString::FromCString(lpszPathName))) + if (f.Open(filename)) { FileReader file = f.GetFile(); if(file.IsValid()) @@ -237,7 +237,7 @@ EndWaitCursor(); logcapturer.ShowLog(std::string() - + "File: " + lpszPathName + "\n" + + "File: " + filename.ToLocale() + "\n" + "Last saved with: " + m_SndFile.madeWithTracker + ", you are using OpenMPT " + MptVersion::str + "\n" + "\n" ); @@ -249,10 +249,10 @@ CDLSBank *pCachedBank = NULL, *pEmbeddedBank = NULL; mpt::PathString szCachedBankFile = MPT_PATHSTRING(""); - if (CDLSBank::IsDLSBank(mpt::PathString::FromCString(lpszPathName))) + if (CDLSBank::IsDLSBank(filename)) { pEmbeddedBank = new CDLSBank(); - pEmbeddedBank->Open(mpt::PathString::FromCString(lpszPathName)); + pEmbeddedBank->Open(filename); } m_SndFile.ChangeModTypeTo(MOD_TYPE_IT); BeginWaitCursor(); @@ -407,27 +407,26 @@ } -BOOL CModDoc::OnSaveDocument(LPCTSTR lpszPathName, const bool bTemplateFile) -//-------------------------------------------------------------------------- +BOOL CModDoc::OnSaveDocument(const mpt::PathString &filename, const bool bTemplateFile) +//------------------------------------------------------------------------------------- { ScopedLogCapturer logcapturer(*this); static int greccount = 0; BOOL bOk = FALSE; m_SndFile.m_dwLastSavedWithVersion = MptVersion::num; - if (!lpszPathName) + if(filename.empty()) return FALSE; MODTYPE type = m_SndFile.GetType(); // CModSpecifications::ExtensionToType(fext); if (type == MOD_TYPE_NONE && !greccount) { greccount++; - bOk = DoSave(NULL, TRUE); + bOk = DoSave(mpt::PathString(), TRUE); greccount--; return bOk; } BeginWaitCursor(); FixNullStrings(); - const mpt::PathString filename = mpt::PathString::FromCString(lpszPathName); switch(type) { case MOD_TYPE_MOD: bOk = m_SndFile.SaveMod(filename); break; @@ -442,7 +441,7 @@ if (!bTemplateFile) { // Set new path for this file, unless we are saving a template, in which case we want to keep the old file path. - SetPathName(lpszPathName); + SetPathName(filename); } logcapturer.ShowLog(true); if (bTemplateFile) @@ -549,12 +548,11 @@ } -BOOL CModDoc::DoSave(LPCSTR lpszPathName, BOOL) -//--------------------------------------------- +BOOL CModDoc::DoSave(const mpt::PathString &filename, BOOL) +//--------------------------------------------------------- { - CHAR s[_MAX_PATH] = ""; - CHAR path[_MAX_PATH]="", drive[_MAX_DRIVE]=""; - CHAR fname[_MAX_FNAME]="", fext[_MAX_EXT]=""; + const mpt::PathString docFileName = GetPathNameMpt(); + std::string defaultExtension = m_SndFile.GetModSpecifications().fileExtension; switch(m_SndFile.GetType()) @@ -591,57 +589,51 @@ return FALSE; } - strcpy(fext, "."); - strcat(fext, defaultExtension.c_str()); + mpt::PathString ext = MPT_PATHSTRING(".") + mpt::PathString::FromUTF8(defaultExtension); - if ((!lpszPathName) || (!lpszPathName[0]) || m_ShowSavedialog) + mpt::PathString saveFileName; + + if(filename.empty() || m_ShowSavedialog) { - _splitpath(m_strPathName, drive, path, fname, NULL); - if (!fname[0]) strcpy(fname, GetTitle()); - strcpy(s, drive); - strcat(s, path); - strcat(s, fname); - strcat(s, fext); + mpt::PathString drive = docFileName.GetDrive(); + mpt::PathString dir = docFileName.GetDir(); + mpt::PathString fileName = docFileName.GetFileName(); + if(fileName.empty()) + { + fileName = mpt::PathString::FromWide(mpt::ToWide(GetTitle())).SanitizeComponent(); + } + mpt::PathString defaultSaveName = drive + dir + fileName + ext; FileDialog dlg = SaveFileDialog() .DefaultExtension(defaultExtension) - .DefaultFilename(s) + .DefaultFilename(defaultSaveName) .ExtensionFilter(ModTypeToFilter(m_SndFile)) .WorkingDirectory(TrackerDirectories::Instance().GetWorkingDirectory(DIR_MODS)); if(!dlg.Show()) return FALSE; TrackerDirectories::Instance().SetWorkingDirectory(dlg.GetWorkingDirectory(), DIR_MODS, true); - strcpy(s, dlg.GetFirstFile().ToLocale().c_str()); - _splitpath(s, drive, path, fname, fext); + saveFileName = dlg.GetFirstFile(); } else { - _splitpath(lpszPathName, drive, path, fname, NULL); - strcpy(s, drive); - strcat(s, path); - strcat(s, fname); - strcat(s, fext); + saveFileName = filename.ReplaceExt(ext); } + // Do we need to create a backup file ? - if ((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_CREATEBACKUP) - && (IsModified()) && (!lstrcmpi(s, m_strPathName))) + if((TrackerSettings::Instance().m_dwPatternSetup & PATTERN_CREATEBACKUP) + && (IsModified()) && (!mpt::PathString::CompareNoCase(saveFileName, docFileName))) { - CFileStatus rStatus; - if (CFile::GetStatus(s, rStatus)) + if(PathFileExistsW(saveFileName.AsNative().c_str())) { - CHAR bkname[_MAX_PATH] = ""; - _splitpath(s, bkname, path, fname, NULL); - strcat(bkname, path); - strcat(bkname, fname); - strcat(bkname, ".bak"); - if (CFile::GetStatus(bkname, rStatus)) + mpt::PathString backupFileName = saveFileName.ReplaceExt(MPT_PATHSTRING(".bak")); + if(PathFileExistsW(backupFileName.AsNative().c_str())) { - DeleteFile(bkname); + DeleteFileW(backupFileName.AsNative().c_str()); } - MoveFile(s, bkname); + MoveFileW(saveFileName.AsNative().c_str(), backupFileName.AsNative().c_str()); } } - if (OnSaveDocument(s)) + if(OnSaveDocument(saveFileName)) { SetModified(FALSE); m_bHasValidPath=true; @@ -1661,7 +1653,7 @@ FileDialog dlg = SaveFileDialog() .DefaultExtension(extension) - .DefaultFilename(mpt::PathString::FromCString(GetPathName()).GetFileName() + MPT_PATHSTRING(".") + mpt::PathString::FromUTF8(extension)) + .DefaultFilename(GetPathNameMpt().GetFileName() + MPT_PATHSTRING(".") + mpt::PathString::FromUTF8(extension)) .ExtensionFilter(encFactory->GetTraits().fileDescription + " (*." + extension + ")|*." + extension + "||") .WorkingDirectory(TrackerDirectories::Instance().GetWorkingDirectory(DIR_EXPORT)); if(!dlg.Show()) return; @@ -1869,20 +1861,15 @@ void CModDoc::OnFileMidiConvert() //------------------------------- { - CHAR path[_MAX_PATH]="", drive[_MAX_DRIVE]=""; - CHAR s[_MAX_PATH], fname[_MAX_FNAME]=""; CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); if ((!pMainFrm) || (!m_SndFile.GetType())) return; - _splitpath(GetPathName(), drive, path, fname, NULL); - strcpy(s, drive); - strcat(s, path); - strcat(s, fname); - strcat(s, ".mid"); + mpt::PathString filename = GetPathNameMpt().ReplaceExt(MPT_PATHSTRING(".mid")); + FileDialog dlg = SaveFileDialog() .DefaultExtension("mid") - .DefaultFilename(s) + .DefaultFilename(filename) .ExtensionFilter("Midi Files (*.mid,*.rmi)|*.mid;*.rmi||"); if(!dlg.Show()) return; @@ -1902,7 +1889,7 @@ CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); if (!pMainFrm) return; - std::string ext, pattern, filename; + std::string pattern; const MODTYPE type = m_SndFile.GetType(); @@ -1920,21 +1907,25 @@ // Not available for this format. return; } - ext = m_SndFile.GetModSpecifications().fileExtension; + std::string ext = m_SndFile.GetModSpecifications().fileExtension; + + mpt::PathString filename; + { - CHAR path[_MAX_PATH]="", drive[_MAX_DRIVE]=""; - CHAR fname[_MAX_FNAME]=""; - _splitpath(GetPathName(), drive, path, fname, NULL); + mpt::PathString drive; + mpt::PathString dir; + mpt::PathString fileName; + GetPathNameMpt().SplitPath(&drive, &dir, &fileName, nullptr); filename = drive; - filename += path; - filename += fname; - if (!strstr(fname, "compat")) - filename += ".compat."; + filename += dir; + filename += fileName; + if(!strstr(fileName.ToUTF8().c_str(), "compat")) + filename += MPT_PATHSTRING(".compat."); else - filename += "."; - filename += ext; + filename += MPT_PATHSTRING("."); + filename += mpt::PathString::FromUTF8(ext); } FileDialog dlg = SaveFileDialog() @@ -2553,8 +2544,8 @@ case kcFileExportCompat: OnFileCompatibilitySave(); break; case kcEstimateSongLength: OnEstimateSongLength(); break; case kcApproxRealBPM: OnApproximateBPM(); break; - case kcFileSave: DoSave(m_strPathName, 0); break; - case kcFileSaveAs: DoSave(NULL, TRUE); break; + case kcFileSave: DoSave(GetPathNameMpt(), 0); break; + case kcFileSaveAs: DoSave(mpt::PathString(), TRUE); break; case kcFileSaveTemplate: OnSaveTemplateModule(); break; case kcFileClose: SafeFileClose(); break; @@ -2593,18 +2584,22 @@ //------------------------------------------------- { //Not making path if path is empty(case only(?) for new file) - if(GetPathName().GetLength() > 0) + if(!GetPathNameMpt().empty()) { - CHAR path[_MAX_PATH], drive[_MAX_PATH], fname[_MAX_FNAME], ext[_MAX_EXT]; - _splitpath(GetPathName(), drive, path, fname, ext); + mpt::PathString drive; + mpt::PathString dir; + mpt::PathString fname; + mpt::PathString fext; + GetPathNameMpt().SplitPath(&drive, &dir, &fname, &fext); - CString newPath = drive; - newPath += path; + mpt::PathString newPath; + newPath += drive; + newPath += dir; //Catch case where we don't have a filename yet. - if (fname[0] == 0) + if(fname.empty()) { - newPath += GetTitle(); + newPath += mpt::PathString::FromWide(mpt::ToWide(GetTitle())).SanitizeComponent(); } else { newPath += fname; @@ -2612,19 +2607,19 @@ switch(nNewType) { - case MOD_TYPE_XM: newPath += ".xm"; break; - case MOD_TYPE_IT: newPath += m_SndFile.m_SongFlags[SONG_ITPROJECT] ? ".itp" : ".it"; break; - case MOD_TYPE_MPT: newPath += ".mptm"; break; - case MOD_TYPE_S3M: newPath += ".s3m"; break; - case MOD_TYPE_MOD: newPath += ".mod"; break; + case MOD_TYPE_XM: newPath += MPT_PATHSTRING(".xm"); break; + case MOD_TYPE_IT: newPath += m_SndFile.m_SongFlags[SONG_ITPROJECT] ? MPT_PATHSTRING(".itp") : MPT_PATHSTRING(".it"); break; + case MOD_TYPE_MPT: newPath += MPT_PATHSTRING(".mptm"); break; + case MOD_TYPE_S3M: newPath += MPT_PATHSTRING(".s3m"); break; + case MOD_TYPE_MOD: newPath += MPT_PATHSTRING(".mod"); break; default: ASSERT(false); } if(nNewType != MOD_TYPE_IT || (nNewType == MOD_TYPE_IT && ( - (!strcmp(ext, ".it") && m_SndFile.m_SongFlags[SONG_ITPROJECT]) || - (!strcmp(ext, ".itp") && !m_SndFile.m_SongFlags[SONG_ITPROJECT]) + (!mpt::PathString::CompareNoCase(fext, MPT_PATHSTRING(".it")) && m_SndFile.m_SongFlags[SONG_ITPROJECT]) || + (!mpt::PathString::CompareNoCase(fext, MPT_PATHSTRING(".itp")) && !m_SndFile.m_SongFlags[SONG_ITPROJECT]) ) ) ) @@ -2634,8 +2629,6 @@ SetPathName(newPath, FALSE); - - } UpdateAllViews(NULL, HINT_MODTYPE); @@ -2898,7 +2891,7 @@ return; const CString sOldPath = m_strPathName; - OnSaveDocument(dlg.GetFirstFile().ToCString(), true/*template file*/); + OnSaveDocument(dlg.GetFirstFile(), true/*template file*/); m_strPathName = sOldPath; } Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/Moddoc.h 2013-11-16 18:09:05 UTC (rev 3238) @@ -379,19 +379,60 @@ //{{AFX_VIRTUAL(CModDoc) public: virtual BOOL OnNewDocument(); - virtual BOOL OnOpenDocument(LPCTSTR lpszPathName); - virtual BOOL OnSaveDocument(LPCTSTR lpszPathName) {return OnSaveDocument(lpszPathName, false);} + MPT_DEPRECATED_PATH virtual BOOL OnOpenDocument(LPCTSTR lpszPathName) + { + return OnOpenDocument(lpszPathName ? mpt::PathString::TunnelOutofCString(lpszPathName) : mpt::PathString()); + } + virtual BOOL OnOpenDocument(const mpt::PathString &filename); + MPT_DEPRECATED_PATH virtual BOOL OnSaveDocument(LPCTSTR lpszPathName) + { + return OnSaveDocument(lpszPathName ? mpt::PathString::TunnelOutofCString(lpszPathName) : mpt::PathString(), false); + } + BOOL OnSaveDocument(const mpt::PathString &filename) + { + return OnSaveDocument(filename, false); + } virtual void OnCloseDocument(); void SafeFileClose(); - BOOL OnSaveDocument(LPCTSTR lpszPathName, const bool bTemplateFile); + BOOL OnSaveDocument(const mpt::PathString &filename, const bool bTemplateFile); + MPT_DEPRECATED_PATH virtual void SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU = TRUE) + { + return SetPathName(lpszPathName ? mpt::PathString::TunnelOutofCString(lpszPathName) : mpt::PathString(), bAddToMRU); + } + virtual void SetPathName(const mpt::PathString &filename, BOOL bAddToMRU = TRUE) + { + CDocument::SetPathName(mpt::PathString::TunnelIntoCString(filename), bAddToMRU); + #ifndef UNICODE + // As paths are faked into utf8 when !UNICODE, + // explicitly set the title in locale again. + // This replaces non-ANSI characters in the title + // with replacement character but overall the + // unicode handling is sane and consistent this + // way. + SetTitle(mpt::ToCString(filename.GetFileName().ToWide())); + #endif + } + MPT_DEPRECATED_PATH const CString& GetPathName() const + { + return CDocument::GetPathName(); + } + mpt::PathString GetPathNameMpt() const + { + return mpt::PathString::TunnelOutofCString(CDocument::GetPathName()); + } + // -> CODE#0023 // -> DESC="IT project files (.itp)" virtual BOOL SaveModified(); bool SaveInstrument(INSTRUMENTINDEX instr); // -! NEW_FEATURE#0023 - virtual BOOL DoSave(LPCSTR lpszPathName, BOOL bSaveAs=TRUE); + MPT_DEPRECATED_PATH virtual BOOL DoSave(LPCSTR lpszPathName, BOOL bSaveAs=TRUE) + { + return DoSave(lpszPathName ? mpt::PathString::TunnelOutofCString(lpszPathName) : mpt::PathString(), bSaveAs); + } + virtual BOOL DoSave(const mpt::PathString &filename, BOOL bSaveAs=TRUE); virtual void DeleteContents(); virtual void SetModifiedFlag(BOOL bModified=TRUE); //}}AFX_VIRTUAL Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -47,65 +47,37 @@ CTrackApp theApp; -///////////////////////////////////////////////////////////////////////////// -// Document Template - -//============================================= -class CModDocTemplate: public CMultiDocTemplate -//============================================= +CDocument *CModDocTemplate::OpenDocumentFile(const mpt::PathString &filename, BOOL addToMru, BOOL makeVisible) +//------------------------------------------------------------------------------------------------------------ { -public: - CModDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass): - CMultiDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass) {} - #if MPT_COMPILER_MSVC && MPT_MSVC_BEFORE(2010,0) - virtual CDocument* OpenDocumentFile(LPCTSTR path, BOOL makeVisible = TRUE); - #else - virtual CDocument* OpenDocumentFile(LPCTSTR path, BOOL addToMru = TRUE, BOOL makeVisible = TRUE); - #endif -}; - -#if MPT_COMPILER_MSVC && MPT_MSVC_BEFORE(2010,0) - CDocument *CModDocTemplate::OpenDocumentFile(LPCTSTR path, BOOL makeVisible) -#else - CDocument *CModDocTemplate::OpenDocumentFile(LPCTSTR path, BOOL addToMru, BOOL makeVisible) -#endif -//----------------------------------------------------------------------------------------- -{ - if (path) + if(!mpt::PathString::CompareNoCase(filename.GetFileExt(), MPT_PATHSTRING(".dll"))) { - TCHAR s[_MAX_EXT]; - _tsplitpath(path, NULL, NULL, NULL, s); - if (!_tcsicmp(s, _TEXT(".dll"))) + CVstPluginManager *pPluginManager = theApp.GetPluginManager(); + if(pPluginManager) { - CVstPluginManager *pPluginManager = theApp.GetPluginManager(); - if (pPluginManager) - { - pPluginManager->AddPlugin(mpt::PathString::FromCString(path)); - return NULL; - } + pPluginManager->AddPlugin(filename); + return NULL; } } #if MPT_COMPILER_MSVC && MPT_MSVC_BEFORE(2010,0) - CDocument *pDoc = CMultiDocTemplate::OpenDocumentFile(path, makeVisible); + CDocument *pDoc = CMultiDocTemplate::OpenDocumentFile(filename.empty() ? NULL : mpt::PathString::TunnelIntoCString(filename).GetString(), makeVisible); #else - CDocument *pDoc = CMultiDocTemplate::OpenDocumentFile(path, addToMru, makeVisible); + CDocument *pDoc = CMultiDocTemplate::OpenDocumentFile(filename.empty() ? NULL : mpt::PathString::TunnelIntoCString(filename).GetString(), addToMru, makeVisible); #endif - if (pDoc) - { + if(pDoc) + { CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); if (pMainFrm) pMainFrm->OnDocumentCreated(static_cast<CModDoc *>(pDoc)); } else //Case: pDoc == 0, opening document failed. { - if(path != NULL) + if(!filename.empty()) { - if(PathFileExists(path) == FALSE) + if(PathFileExistsW(filename.AsNative().c_str()) == FALSE) { - CString str; - str.Format(GetStrI18N(_TEXT("Unable to open \"%s\": file does not exist.")), path); - Reporting::Error(str); + Reporting::Error(L"Unable to open \"" + filename.ToWide() + L"\": file does not exist."); } else //Case: Valid path but opening fails. { @@ -116,7 +88,7 @@ "recognised. If the former is true, it's " "recommended to close some documents as otherwise crash is likely" "(currently there %s %d document%s open).")), - path, (nOdc == 1) ? "is" : "are", nOdc, (nOdc == 1) ? "" : "s"); + filename.ToCString().GetString(), (nOdc == 1) ? "is" : "are", nOdc, (nOdc == 1) ? "" : "s"); Reporting::Notification(str); } } @@ -137,6 +109,14 @@ public: CModDocManager() {} virtual BOOL OnDDECommand(LPTSTR lpszCommand); + MPT_DEPRECATED_PATH virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName) + { + return OpenDocumentFile(lpszFileName ? mpt::PathString::TunnelOutofCString(lpszFileName) : mpt::PathString()); + } + virtual CDocument* OpenDocumentFile(const mpt::PathString &filename) + { + return CDocManager::OpenDocumentFile(filename.empty() ? NULL : mpt::PathString::TunnelIntoCString(filename).GetString()); + } }; @@ -181,13 +161,13 @@ { bResult = TRUE; bActivate = TRUE; - OpenDocumentFile(pszData); + OpenDocumentFile(mpt::PathString::FromCString(pszData)); } } else // New if (!lstrcmpi(pszCmd, "New")) { - OpenDocumentFile(NULL); + OpenDocumentFile(mpt::PathString()); bResult = TRUE; bActivate = TRUE; } @@ -644,6 +624,24 @@ } +void CTrackApp::AddToRecentFileList(LPCTSTR lpszPathName) +//------------------------------------------------------- +{ + mpt::PathString filename = mpt::PathString::TunnelOutofCString(lpszPathName); + #ifdef UNICODE + CWinApp::AddToRecentFileList(filename.AsNative().c_str()); + #else + if(filename.AsNative() != (mpt::PathString::FromCString(filename.ToCString())).AsNative()) + { + // MFC ANSI builds fire strict assertions if the file path is invalid. + // Only proceed for string representable in CP_ACP. + return; + } + CWinApp::AddToRecentFileList(filename.ToCString()); + #endif +} + + ///////////////////////////////////////////////////////////////////////////// // CTrackApp initialization @@ -1015,7 +1013,7 @@ // -! NEW_FEATURE#0023 SetDefaultDocType(MOD_TYPE_MOD); - if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(NULL); + if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(mpt::PathString()); } @@ -1028,7 +1026,7 @@ // -! NEW_FEATURE#0023 SetDefaultDocType(MOD_TYPE_S3M); - if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(NULL); + if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(mpt::PathString()); } @@ -1041,7 +1039,7 @@ // -! NEW_FEATURE#0023 SetDefaultDocType(MOD_TYPE_XM); - if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(NULL); + if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(mpt::PathString()); } @@ -1054,7 +1052,7 @@ // -! NEW_FEATURE#0023 SetDefaultDocType(MOD_TYPE_IT); - if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(NULL); + if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(mpt::PathString()); } void CTrackApp::OnFileNewMPT() @@ -1062,7 +1060,7 @@ { SetAsProject(FALSE); SetDefaultDocType(MOD_TYPE_MPT); - if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(NULL); + if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(mpt::PathString()); } @@ -1074,7 +1072,7 @@ { SetAsProject(TRUE); SetDefaultDocType(MOD_TYPE_IT); - if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(NULL); + if (m_pModTemplate) m_pModTemplate->OpenDocumentFile(mpt::PathString()); } // -! NEW_FEATURE#0023 @@ -1125,7 +1123,7 @@ const FileDialog::PathList &files = dlg.GetFilenames(); for(size_t counter = 0; counter < files.size(); counter++) { - OpenDocumentFile(files[counter].ToCString()); + OpenDocumentFile(files[counter]); } } Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/Mptrack.h 2013-11-16 18:09:05 UTC (rev 3238) @@ -82,6 +82,57 @@ ///////////////////////////////////////////////////////////////////////////// +// Document Template + +// OK, this is a really dirty hack for ANSI builds (which are still used because the code is not yet UNICODE compatible). +// To support wide path names even in ansi builds, we use mpt::PathString everywhere. +// Except, there is one set of cases, where MFC dictates TCHAR/CString on us: The filename handling for MDI documents. +// Here, if in ANSI build, we encode the wide string in utf8 and pass it around through MFC. When MFC calls us again, +// we unpack it again. This works surprisingly well for the hackish nature this has. +// Rough edges: +// - CDocument::GetTitle is still ANSI encoded and returns replacement chars for non-representable chars. +// - CWinApp::AddToRecentFileList chokes on filenames it cannot access. We simply avoid passing non-ansi-representable filenames there. +// Modified MFC functionality: +// CTrackApp: +// CWinApp::OpenDocument +// CWinApp::AddToRecentFileList +// CModDocManager: +// CDocManager::OpenDocumentFile +// CModDocTemplate: +// CMultiDocTemplate::OpenDocumentFile +// CModDoc: +// CDocument::GetPathName +// CDocument::SetPathName +// CDocument::DoSave +// CDocument::OnOpenDocument +// CDocument::OnSaveDocument + +//============================================= +class CModDocTemplate: public CMultiDocTemplate +//============================================= +{ +public: + CModDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass): + CMultiDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass) {} + + CDocument* OpenDocumentFile(const mpt::PathString &filename, BOOL addToMru = TRUE, BOOL makeVisible = TRUE); + + // inherited members, overload them all + #if MPT_COMPILER_MSVC && MPT_MSVC_BEFORE(2010,0) + MPT_DEPRECATED_PATH virtual CDocument* OpenDocumentFile(LPCTSTR path, BOOL makeVisible = TRUE) + { + return OpenDocumentFile(path ? mpt::PathString::TunnelOutofCString(path) : mpt::PathString(), TRUE, makeVisible); + } + #else + MPT_DEPRECATED_PATH virtual CDocument* OpenDocumentFile(LPCTSTR path, BOOL addToMru = TRUE, BOOL makeVisible = TRUE) + { + return OpenDocumentFile(path ? mpt::PathString::TunnelOutofCString(path) : mpt::PathString(), addToMru, makeVisible); + } + #endif +}; + + +///////////////////////////////////////////////////////////////////////////// // CTrackApp: // See mptrack.cpp for the implementation of this class // @@ -101,16 +152,31 @@ static std::vector<CDLSBank *> gpDLSBanks; #if MPT_COMPILER_MSVC && MPT_MSVC_BEFORE(2010,0) - virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU = TRUE) + MPT_DEPRECATED_PATH virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU = TRUE) { - CDocument* pDoc = CWinApp::OpenDocumentFile(lpszFileName); + return OpenDocumentFile(lpszFileName ? mpt::PathString::TunnelOutofCString(lpszFileName) : mpt::PathString(), bAddToMRU); + } + virtual CDocument* OpenDocumentFile(const mpt::PathString &filename, BOOL bAddToMRU = TRUE) + { + CDocument* pDoc = CWinApp::OpenDocumentFile(filename.empty() ? NULL : mpt::PathString::TunnelIntoCString(filename).GetString()); if (pDoc && bAddToMRU != TRUE) RemoveMruItem(0); // This doesn't result to the same behaviour as not adding to MRU // (if the new item got added, it might have already dropped the last item out) return pDoc; } +#else + MPT_DEPRECATED_PATH virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU = TRUE) + { + return CWinApp::OpenDocumentFile(lpszFileName, bAddToMRU); + } + virtual CDocument* OpenDocumentFile(const mpt::PathString &filename, BOOL bAddToMRU = TRUE) + { + return CWinApp::OpenDocumentFile(filename.empty() ? NULL : mpt::PathString::TunnelIntoCString(filename).GetString(), bAddToMRU); + } #endif + MPT_DEPRECATED_PATH virtual void AddToRecentFileList(LPCTSTR lpszPathName); + protected: DWORD m_GuiThreadId; @@ -120,7 +186,7 @@ SettingsContainer *m_pSettings; TrackerSettings *m_pTrackerSettings; IniFileSettingsContainer *m_pPluginCache; - CMultiDocTemplate *m_pModTemplate; + CModDocTemplate *m_pModTemplate; CVstPluginManager *m_pPluginManager; SoundDevicesManager *m_pSoundDevicesManager; BOOL m_bInitialized; @@ -172,7 +238,7 @@ public: bool InGuiThread() const { return GetCurrentThreadId() == m_GuiThreadId; } - CDocTemplate *GetModDocTemplate() const { return m_pModTemplate; } + CModDocTemplate *GetModDocTemplate() const { return m_pModTemplate; } CVstPluginManager *GetPluginManager() const { return m_pPluginManager; } SoundDevicesManager *GetSoundDevicesManager() const { return m_pSoundDevicesManager; } void GetDefaultMidiMacro(MIDIMacroConfig &cfg) const { cfg = m_MidiCfg; } Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -693,7 +693,7 @@ s[0] = 0; if ((hintFlagPart & (HINT_MODGENERAL|HINT_MODTYPE)) || (!pInfo->hSong)) { - _splitpath(pDoc->GetPathName(), NULL, NULL, s, NULL); + _tcscpy(s, pDoc->GetPathNameMpt().GetFileName().ToCString().GetString()); if (!s[0]) strcpy(s, "untitled"); MemsetZero(tvi); } @@ -1506,7 +1506,7 @@ { case MODITEM_INSLIB_SONG: { - theApp.OpenDocumentFile(InsLibGetFullPath(hItem).ToCString()); + theApp.OpenDocumentFile(InsLibGetFullPath(hItem)); } break; } @@ -2698,7 +2698,7 @@ { if (dropinfo.dwDropType == DRAGONDROP_SONG) { - theApp.OpenDocumentFile(fullPath.ToCString()); + theApp.OpenDocumentFile(fullPath); } else { ::SendMessage(m_hDropWnd, WM_MOD_DRAGONDROPPING, TRUE, (LPARAM)&dropinfo); Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-16 17:37:15 UTC (rev 3237) +++ trunk/OpenMPT/test/test.cpp 2013-11-16 18:09:05 UTC (rev 3238) @@ -1522,7 +1522,7 @@ static TSoundFileContainer CreateSoundFileContainer(const mpt::PathString &filename) { - CModDoc *pModDoc = (CModDoc *)theApp.OpenDocumentFile(filename.ToCString(), FALSE); + CModDoc *pModDoc = (CModDoc *)theApp.OpenDocumentFile(filename, FALSE); return pModDoc; } @@ -1533,21 +1533,21 @@ static void SaveIT(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.ToCString()); + sndFile->DoSave(filename); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } static void SaveXM(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.ToCString()); + sndFile->DoSave(filename); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } static void SaveS3M(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.ToCString()); + sndFile->DoSave(filename); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-16 20:28:26
|
Revision: 3243 http://sourceforge.net/p/modplug/code/3243 Author: manxorist Date: 2013-11-16 20:28:19 +0000 (Sat, 16 Nov 2013) Log Message: ----------- [Fix] Convert error message formatting to type-safe message formatting API in PluginManager.cpp. Correct reporting for unicode filenames. [Ref] Use unicode filenames in plugin cache. Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-16 20:08:07 UTC (rev 3242) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-16 20:28:19 UTC (rev 3243) @@ -160,6 +160,9 @@ }; +MPT_DEPRECATED_PATH static inline std::string ToString(const mpt::PathString & x) { return mpt::ToLocale(x.ToWide()); } +static inline std::wstring ToWString(const mpt::PathString & x) { return x.ToWide(); } + } // namespace mpt #if defined(WIN32) Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-16 20:08:07 UTC (rev 3242) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-16 20:28:19 UTC (rev 3243) @@ -1935,7 +1935,7 @@ #endif - CString nonFoundPlugs; + std::wstring nonFoundPlugs; const mpt::PathString failedPlugin = theApp.GetSettings().Read<mpt::PathString>("VST Plugins", "FailedPlugin", MPT_PATHSTRING("")); for(size_t plug = 0; plug < numPlugins; plug++) @@ -1958,10 +1958,9 @@ m_pPluginManager->AddPlugin(plugPath, true, true, &nonFoundPlugs); } } - if(nonFoundPlugs.GetLength() > 0) + if(!nonFoundPlugs.empty()) { - nonFoundPlugs.Insert(0, "Problems were encountered with plugins:\n"); - Reporting::Notification(nonFoundPlugs); + Reporting::Notification(L"Problems were encountered with plugins:\n" + nonFoundPlugs); } return FALSE; } Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2013-11-16 20:08:07 UTC (rev 3242) +++ trunk/OpenMPT/mptrack/Vstplug.h 2013-11-16 20:28:19 UTC (rev 3243) @@ -331,11 +331,13 @@ public: VSTPluginLib *GetFirstPlugin() const { return m_pVstHead; } bool IsValidPlugin(const VSTPluginLib *pLib); - VSTPluginLib *AddPlugin(const mpt::PathString &dllPath, bool fromCache = true, const bool checkFileExistence = false, CString* const errStr = 0); + VSTPluginLib *AddPlugin(const mpt::PathString &dllPath, bool fromCache = true, const bool checkFileExistence = false, std::wstring* const errStr = nullptr); bool RemovePlugin(VSTPluginLib *); bool CreateMixPlugin(SNDMIXPLUGIN &, CSoundFile &); void OnIdle(); static void ReportPlugException(LPCSTR format,...); + static void ReportPlugException(const std::wstring &msg); + static void ReportPlugException(const std::string &msg); protected: void EnumerateDirectXDMOs(); Modified: trunk/OpenMPT/soundlib/plugins/PluginManager.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-16 20:08:07 UTC (rev 3242) +++ trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-16 20:28:19 UTC (rev 3243) @@ -193,7 +193,7 @@ } } catch(...) { - CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pluginPath.ToLocale().c_str()); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception caught in LoadLibrary (%1)", pluginPath)); } if(library != nullptr && library != INVALID_HANDLE_VALUE) @@ -250,8 +250,8 @@ // ID100000ID200000 = FullDllPath // ID100000ID200000.Flags = Plugin Flags (isInstrument + category). -VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, CString *const errStr) -//---------------------------------------------------------------------------------------------------------------------------------------------- +VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, std::wstring *const errStr) +//--------------------------------------------------------------------------------------------------------------------------------------------------- { const mpt::PathString fileName = dllPath.GetFileName(); @@ -259,8 +259,8 @@ { if(errStr) { - *errStr += "\nUnable to find "; - *errStr += dllPath.ToCString(); + *errStr += L"\nUnable to find "; + *errStr += dllPath.ToWide(); } } @@ -274,8 +274,9 @@ if(fromCache) { SettingsContainer & cacheFile = theApp.GetPluginCache(); - const char *cacheSection = "PluginCache"; - const std::string IDs = cacheFile.Read<std::string>(cacheSection, fileName.ToLocale(), ""); + const char *const cacheSection = "PluginCache"; + const wchar_t *const cacheSectionW = L"PluginCache"; + const std::string IDs = cacheFile.Read<std::string>(cacheSectionW, fileName.ToWide(), ""); if(IDs.length() >= 16) { @@ -383,7 +384,7 @@ FreeLibrary(hLib); } catch(...) { - CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->libraryName); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to load plugin \"%1\"!\n", p->libraryName)); } // Now it should be safe to assume that this plugin loaded properly. :) @@ -393,7 +394,8 @@ if(validPlug) { SettingsContainer &cacheFile = theApp.GetPluginCache(); - const char *cacheSection = "PluginCache"; + const char *const cacheSection = "PluginCache"; + const wchar_t *const cacheSectionW = L"PluginCache"; const std::string IDs = mpt::String::Format("%08X%08X", p->pluginId1, p->pluginId2); const std::string flagsKey = mpt::String::Format("%s.Flags", IDs); @@ -405,7 +407,7 @@ cacheFile.Write<mpt::PathString>(cacheSection, IDs, writePath); cacheFile.Write<mpt::PathString>(cacheSection, IDs, dllPath); - cacheFile.Write<std::string>(cacheSection, p->libraryName.ToLocale(), IDs); + cacheFile.Write<std::string>(cacheSectionW, p->libraryName.ToWide(), IDs); cacheFile.Write<int32>(cacheSection, flagsKey, p->EncodeCacheFlags()); } else { @@ -441,7 +443,7 @@ delete p; } catch (...) { - CVstPluginManager::ReportPlugException("Exception while trying to release plugin \"%s\"!\n", pFactory->libraryName); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to release plugin \"%1\"!\n", pFactory->libraryName)); } return true; @@ -563,7 +565,7 @@ } } catch(...) { - CVstPluginManager::ReportPlugException("Exception while trying to create plugin \"%s\"!\n", pFound->libraryName); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to create plugin \"%1\"!\n", pFound->libraryName)); } return validPlugin; @@ -629,4 +631,20 @@ va_end(va); } +void CVstPluginManager::ReportPlugException(const std::string &msg) +{ + Reporting::Notification(msg.c_str()); +#ifdef VST_LOG + Log("%s", msg.c_str()); +#endif +} + +void CVstPluginManager::ReportPlugException(const std::wstring &msg) +{ + Reporting::Notification(msg); +#ifdef VST_LOG + Log("%s", mpt::ToLocale(msg).c_str()); +#endif +} + #endif // NO_VST This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-16 21:26:50
|
Revision: 3246 http://sourceforge.net/p/modplug/code/3246 Author: manxorist Date: 2013-11-16 21:26:22 +0000 (Sat, 16 Nov 2013) Log Message: ----------- [Ref] Make silenced PathString conversions more explicit by using mpt::PathString::FromCStringSilent instead of cascades through ToWide. Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/AutoSaver.cpp trunk/OpenMPT/mptrack/ExceptionHandler.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/View_tre.cpp Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-16 21:23:47 UTC (rev 3245) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-16 21:26:22 UTC (rev 3246) @@ -139,6 +139,9 @@ // CString TCHAR, so this is CHAR or WCHAR, depending on UNICODE MPT_DEPRECATED_PATH CString ToCString() const { return mpt::ToCString(path); } MPT_DEPRECATED_PATH static PathString FromCString(const CString &path) { return PathString(mpt::ToWide(path)); } + // Non-warning-generating versions of the above. Use with extra care. + CString ToCStringSilent() const { return mpt::ToCString(path); } + static PathString FromCStringSilent(const CString &path) { return PathString(mpt::ToWide(path)); } // really special purpose, if !UNICODE, encode unicode in CString as UTF8: static mpt::PathString TunnelOutofCString(const CString &path); static CString TunnelIntoCString(const mpt::PathString &path); Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp =================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-16 21:23:47 UTC (rev 3245) +++ trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-16 21:26:22 UTC (rev 3246) @@ -218,11 +218,11 @@ } else { // if it doesnt, put it in settings dir - name = theApp.GetConfigPath() + mpt::PathString::FromWide(mpt::ToWide(modDoc.GetTitle())).SanitizeComponent(); + name = theApp.GetConfigPath() + mpt::PathString::FromCStringSilent(modDoc.GetTitle()).SanitizeComponent(); } } else { - name = m_csPath + mpt::PathString::FromWide(mpt::ToWide(modDoc.GetTitle())).SanitizeComponent(); + name = m_csPath + mpt::PathString::FromCStringSilent(modDoc.GetTitle()).SanitizeComponent(); } name += MPT_PATHSTRING(".AutoSave."); //append backup tag @@ -304,7 +304,7 @@ } std::vector<mpt::PathString> foundfiles; - mpt::PathString searchPattern = path + mpt::PathString::FromWide(mpt::ToWide(modDoc.GetTitle())).SanitizeComponent() + MPT_PATHSTRING(".AutoSave.*"); + mpt::PathString searchPattern = path + mpt::PathString::FromCStringSilent(modDoc.GetTitle()).SanitizeComponent() + MPT_PATHSTRING(".AutoSave.*"); WIN32_FIND_DATAW findData; MemsetZero(findData); Modified: trunk/OpenMPT/mptrack/ExceptionHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-11-16 21:23:47 UTC (rev 3245) +++ trunk/OpenMPT/mptrack/ExceptionHandler.cpp 2013-11-16 21:26:22 UTC (rev 3246) @@ -39,7 +39,7 @@ { CMainFrame* pMainFrame = CMainFrame::GetMainFrame(); - const mpt::PathString timestampDir = mpt::PathString::FromWide(mpt::ToWide((CTime::GetCurrentTime()).Format("%Y-%m-%d %H.%M.%S\\"))); + const mpt::PathString timestampDir = mpt::PathString::FromCStringSilent((CTime::GetCurrentTime()).Format("%Y-%m-%d %H.%M.%S\\")); mpt::PathString baseRescuePath; { // Create a crash directory @@ -114,7 +114,7 @@ filename += baseRescuePath; filename += mpt::PathString::FromWide(mpt::ToWString(++numFiles)); filename += MPT_PATHSTRING("_"); - filename += mpt::PathString::FromWide(mpt::ToWide(pModDoc->GetTitle())).SanitizeComponent(); + filename += mpt::PathString::FromCStringSilent(pModDoc->GetTitle()).SanitizeComponent(); filename += MPT_PATHSTRING("."); filename += mpt::PathString::FromUTF8(pModDoc->GetSoundFile()->GetModSpecifications().fileExtension); Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-16 21:23:47 UTC (rev 3245) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-16 21:26:22 UTC (rev 3246) @@ -600,7 +600,7 @@ mpt::PathString fileName = docFileName.GetFileName(); if(fileName.empty()) { - fileName = mpt::PathString::FromWide(mpt::ToWide(GetTitle())).SanitizeComponent(); + fileName = mpt::PathString::FromCStringSilent(GetTitle()).SanitizeComponent(); } mpt::PathString defaultSaveName = drive + dir + fileName + ext; @@ -2617,7 +2617,7 @@ //Catch case where we don't have a filename yet. if(fname.empty()) { - newPath += mpt::PathString::FromWide(mpt::ToWide(GetTitle())).SanitizeComponent(); + newPath += mpt::PathString::FromCStringSilent(GetTitle()).SanitizeComponent(); } else { newPath += fname; Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-16 21:23:47 UTC (rev 3245) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-16 21:26:22 UTC (rev 3246) @@ -696,7 +696,7 @@ { // Module folder + sub folders std::wstring name = pDoc->GetPathNameMpt().GetFileName().ToWide(); - if(name.empty()) name = mpt::PathString::FromWide(mpt::ToWide(pInfo->pModDoc->GetTitle())).SanitizeComponent().ToWide(); + if(name.empty()) name = mpt::PathString::FromCStringSilent(pInfo->pModDoc->GetTitle()).SanitizeComponent().ToWide(); if(!pInfo->hSong) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-16 23:10:50
|
Revision: 3248 http://sourceforge.net/p/modplug/code/3248 Author: saga-games Date: 2013-11-16 23:10:41 +0000 (Sat, 16 Nov 2013) Log Message: ----------- [Mod] Store plugin library names as UTF-8 in module files. This won't make a difference in 99% of all plugin names probably - I've never come across a plugin DLL with non-ASCII characters. Note: Library name is still converted to ANSI in GUI for this reason. Modified Paths: -------------- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/mptrack/view_com.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/plugins/PlugInterface.h trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Modified: trunk/OpenMPT/mptrack/AbstractVstEditor.cpp =================================================================== --- trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2013-11-16 21:28:43 UTC (rev 3247) +++ trunk/OpenMPT/mptrack/AbstractVstEditor.cpp 2013-11-16 23:10:41 UTC (rev 3248) @@ -346,7 +346,7 @@ if(strcmp(m_VstPlugin.m_pMixStruct->GetName(), "")) Title.Append(m_VstPlugin.m_pMixStruct->GetName()); else - Title.Append(m_VstPlugin.m_pMixStruct->GetLibraryName()); + Title.Append(mpt::ToLocale(mpt::CharsetUTF8, m_VstPlugin.m_pMixStruct->GetLibraryName()).c_str()); SetWindowText(Title); } @@ -869,7 +869,7 @@ m_nInstrument = nIns; _snprintf(pIns->name, CountOf(pIns->name) - 1, _T("%d: %s"), m_VstPlugin.GetSlot() + 1, sndFile.m_MixPlugins[m_VstPlugin.GetSlot()].GetName()); - mpt::String::CopyN(pIns->filename, sndFile.m_MixPlugins[m_VstPlugin.GetSlot()].GetLibraryName()); + mpt::String::Copy(pIns->filename, mpt::ToLocale(mpt::CharsetUTF8, sndFile.m_MixPlugins[m_VstPlugin.GetSlot()].GetLibraryName())); pIns->nMixPlug = (PLUGINDEX)m_VstPlugin.GetSlot() + 1; pIns->nMidiChannel = 1; // People will forget to change this anyway, so the following lines can lead to some bad surprises after re-opening the module. Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-16 21:28:43 UTC (rev 3247) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-16 23:10:41 UTC (rev 3248) @@ -2635,7 +2635,7 @@ str.Preallocate(80); str.Format(_T("FX%d: "), iPlug + 1); const int size0 = str.GetLength(); - str += (librarynames) ? plugin.GetLibraryName() : plugin.GetName(); + str += (librarynames) ? mpt::ToLocale(mpt::CharsetUTF8, plugin.GetLibraryName()).c_str() : plugin.GetName(); if(str.GetLength() <= size0) str += _T("undefined"); CBox.SetItemData(CBox.AddString(str), iPlug + 1); Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-16 21:28:43 UTC (rev 3247) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-16 23:10:41 UTC (rev 3248) @@ -148,9 +148,8 @@ break; } - const std::string libraryName = pFactory->libraryName.ToLocale(); - mpt::String::Copy(m_pPlugin->Info.szName, libraryName); - mpt::String::Copy(m_pPlugin->Info.szLibraryName, libraryName); + mpt::String::Copy(m_pPlugin->Info.szName, pFactory->libraryName.ToLocale().c_str()); + mpt::String::Copy(m_pPlugin->Info.szLibraryName, pFactory->libraryName.ToUTF8().c_str()); cs.Leave(); Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2013-11-16 21:28:43 UTC (rev 3247) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2013-11-16 23:10:41 UTC (rev 3248) @@ -550,12 +550,13 @@ const SNDMIXPLUGIN &plugin = pSndFile->m_MixPlugins[iOut]; if(plugin.IsValidPlugin()) { - if(!strcmp(plugin.GetLibraryName(), plugin.GetName()) || !strcmp(plugin.GetName(), "")) + std::string libName = mpt::ToLocale(mpt::CharsetUTF8, plugin.GetLibraryName()); + if(!strcmp(plugin.GetName(), "") || libName != plugin.GetName()) { - wsprintf(s, "FX%d: %s", iOut + 1, plugin.GetLibraryName()); + wsprintf(s, "FX%d: %s", iOut + 1, libName.c_str()); } else { - wsprintf(s, "FX%d: %s (%s)", iOut + 1, plugin.GetLibraryName(), plugin.GetName()); + wsprintf(s, "FX%d: %s (%s)", iOut + 1, libName.c_str(), plugin.GetName()); } int n = m_CbnOutput.AddString(s); Modified: trunk/OpenMPT/mptrack/view_com.cpp =================================================================== --- trunk/OpenMPT/mptrack/view_com.cpp 2013-11-16 21:28:43 UTC (rev 3247) +++ trunk/OpenMPT/mptrack/view_com.cpp 2013-11-16 23:10:41 UTC (rev 3248) @@ -420,7 +420,7 @@ case INSLIST_PLUGIN: if (pIns != nullptr && pIns->nMixPlug > 0 && pSndFile->m_MixPlugins[pIns->nMixPlug - 1].pMixPlugin != nullptr) { - wsprintf(s, "FX%02d: %s", pIns->nMixPlug, pSndFile->m_MixPlugins[pIns->nMixPlug - 1].GetLibraryName()); + wsprintf(s, "FX%02d: %s", pIns->nMixPlug, mpt::ToLocale(mpt::CharsetUTF8, pSndFile->m_MixPlugins[pIns->nMixPlug - 1].GetLibraryName()).c_str()); } break; // -> CODE#0023 Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-16 21:28:43 UTC (rev 3247) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-16 23:10:41 UTC (rev 3248) @@ -884,13 +884,13 @@ { notFoundText = "The following plugins have not been found:\n\n" + notFoundText + "\nDo you want to search for them online?"; } - if (Reporting::Confirm(notFoundText.c_str(), "OpenMPT - Plugins missing", false, true) == cnfYes) + if (Reporting::Confirm(mpt::ToWide(mpt::CharsetUTF8, notFoundText.c_str()), L"OpenMPT - Plugins missing", false, true) == cnfYes) { std::string sUrl = "http://resources.openmpt.org/plugins/search.php?p="; for(std::vector<PLUGINDEX>::iterator i = notFoundIDs.begin(); i != notFoundIDs.end(); ++i) { sUrl += mpt::fmt::HEX0<8>(LittleEndian(m_MixPlugins[*i].Info.dwPluginId2)); - sUrl += mpt::To(mpt::CharsetUTF8, mpt::CharsetLocale, m_MixPlugins[*i].GetLibraryName()); + sUrl += m_MixPlugins[*i].GetLibraryName(); sUrl += "%0a"; } CTrackApp::OpenURL(mpt::PathString::FromUTF8(sUrl)); @@ -2348,5 +2348,15 @@ } } + if(m_dwLastSavedWithVersion < MAKE_VERSION_NUMERIC(1, 22, 07, 01)) + { + // Convert ANSI plugin path names to UTF-8 (irrelevant in probably 99% of all cases anyway, I think I've never seen a VST plugin with a non-ASCII file name) + for(PLUGINDEX i = 0; i < MAX_MIXPLUGINS; i++) + { + const std::string name = mpt::To(mpt::CharsetUTF8, mpt::CharsetLocale, m_MixPlugins[i].Info.szLibraryName); + mpt::String::Copy(m_MixPlugins[i].Info.szLibraryName, name); + } + } + Patterns.ForEachModCommand(UpgradePatternData(*this)); } \ No newline at end of file Modified: trunk/OpenMPT/soundlib/plugins/PlugInterface.h =================================================================== --- trunk/OpenMPT/soundlib/plugins/PlugInterface.h 2013-11-16 21:28:43 UTC (rev 3247) +++ trunk/OpenMPT/soundlib/plugins/PlugInterface.h 2013-11-16 23:10:41 UTC (rev 3248) @@ -121,8 +121,8 @@ uint8 reserved; uint32 dwOutputRouting; // 0 = send to master 0x80 + x = send to plugin x uint32 dwReserved[4]; // Reserved for routing info - char szName[32]; // User-chosen plugin name - char szLibraryName[64]; // original DLL name + char szName[32]; // User-chosen plugin name - this is locale ANSI! + char szLibraryName[64]; // original DLL name - this is UTF-8! // Should only be called from SNDMIXPLUGIN::SetBypass() and IMixPlugin::Bypass() void SetBypass(bool bypass = true) { if(bypass) routingFlags |= irBypass; else routingFlags &= ~irBypass; } Modified: trunk/OpenMPT/soundlib/plugins/PluginManager.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-16 21:28:43 UTC (rev 3247) +++ trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-16 23:10:41 UTC (rev 3248) @@ -254,6 +254,8 @@ //--------------------------------------------------------------------------------------------------------------------------------------------------- { const mpt::PathString fileName = dllPath.GetFileName(); + const char *const cacheSection = "PluginCache"; + const wchar_t *const cacheSectionW = L"PluginCache"; if(checkFileExistence && (PathFileExistsW(dllPath.AsNative().c_str()) == FALSE)) { @@ -274,8 +276,6 @@ if(fromCache) { SettingsContainer & cacheFile = theApp.GetPluginCache(); - const char *const cacheSection = "PluginCache"; - const wchar_t *const cacheSectionW = L"PluginCache"; const std::string IDs = cacheFile.Read<std::string>(cacheSectionW, fileName.ToWide(), ""); if(IDs.length() >= 16) @@ -394,8 +394,6 @@ if(validPlug) { SettingsContainer &cacheFile = theApp.GetPluginCache(); - const char *const cacheSection = "PluginCache"; - const wchar_t *const cacheSectionW = L"PluginCache"; const std::string IDs = mpt::String::Format("%08X%08X", p->pluginId1, p->pluginId2); const std::string flagsKey = mpt::String::Format("%s.Flags", IDs); @@ -458,6 +456,8 @@ //----------------------------------------------------------------------------------- { VSTPluginLib *pFound = nullptr; + const char *cacheSection = "PluginCache"; + const wchar_t *cacheSectionW = L"PluginCache"; // Find plugin in library VSTPluginLib *p = m_pVstHead; @@ -466,7 +466,7 @@ { const bool matchID = (p->pluginId1 == mixPlugin.Info.dwPluginId1) && (p->pluginId2 == mixPlugin.Info.dwPluginId2); - const bool matchName = !mpt::strnicmp(p->libraryName.ToLocale().c_str(), mixPlugin.GetLibraryName(), CountOf(mixPlugin.Info.szLibraryName)); + const bool matchName = !mpt::PathString::CompareNoCase(p->libraryName, mpt::PathString::FromUTF8(mixPlugin.GetLibraryName())); if(matchID && matchName) { @@ -508,14 +508,13 @@ { fullPath += MPT_PATHSTRING("\\"); } - fullPath += mpt::PathString::FromLocale(mixPlugin.GetLibraryName()) + MPT_PATHSTRING(".dll"); + fullPath += mpt::PathString::FromUTF8(mixPlugin.GetLibraryName()) + MPT_PATHSTRING(".dll"); pFound = AddPlugin(fullPath); if(!pFound) { SettingsContainer &cacheFile = theApp.GetPluginCache(); - const char *cacheSection = "PluginCache"; - std::string IDs = cacheFile.Read<std::string>(cacheSection, mixPlugin.GetLibraryName(), ""); + std::string IDs = cacheFile.Read<std::string>(cacheSectionW, mpt::ToWide(mpt::CharsetUTF8, mixPlugin.GetLibraryName()), ""); if(IDs.length() >= 16) { fullPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING("")); @@ -547,7 +546,6 @@ { // Update cached information SettingsContainer &cacheFile = theApp.GetPluginCache(); - const char *cacheSection = "PluginCache"; std::string flagsKey = mpt::String::Format("%08X%08X.Flags", pFound->pluginId1, pFound->pluginId2); cacheFile.Write<int32>(cacheSection, flagsKey, pFound->EncodeCacheFlags()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-17 00:41:07
|
Revision: 3249 http://sourceforge.net/p/modplug/code/3249 Author: saga-games Date: 2013-11-17 00:40:57 +0000 (Sun, 17 Nov 2013) Log Message: ----------- [Mod] Path names in ITP files are now unicode and, if possible, relative to the ITP file. Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.cpp trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptPathString.cpp =================================================================== --- trunk/OpenMPT/common/mptPathString.cpp 2013-11-16 23:10:41 UTC (rev 3248) +++ trunk/OpenMPT/common/mptPathString.cpp 2013-11-17 00:40:57 UTC (rev 3249) @@ -31,58 +31,119 @@ } PathString PathString::GetDrive() const +//------------------------------------- { PathString drive; SplitPath(&drive, nullptr, nullptr, nullptr); return drive; } PathString PathString::GetDir() const +//----------------------------------- { PathString dir; SplitPath(nullptr, &dir, nullptr, nullptr); return dir; } PathString PathString::GetPath() const +//------------------------------------ { PathString drive, dir; SplitPath(&drive, &dir, nullptr, nullptr); return drive + dir; } PathString PathString::GetFileName() const +//---------------------------------------- { PathString fname; SplitPath(nullptr, nullptr, &fname, nullptr); return fname; } PathString PathString::GetFileExt() const +//--------------------------------------- { PathString ext; SplitPath(nullptr, nullptr, nullptr, &ext); return ext; } PathString PathString::GetFullFileName() const +//-------------------------------------------- { PathString name, ext; SplitPath(nullptr, nullptr, &name, &ext); return name + ext; } + PathString PathString::ReplaceExt(const mpt::PathString &newExt) const +//-------------------------------------------------------------------- { return GetDrive() + GetDir() + GetFileName() + newExt; } + PathString PathString::SanitizeComponent() const +//---------------------------------------------- { PathString result = *this; SanitizeFilename(result); return result; } + +// Convert an absolute path to a path that's relative to OpenMPT's directory. +// Paths are relative to the executable path. +PathString PathString::AbsolutePathToRelative(const PathString &relativeTo) const +//------------------------------------------------------------------------------- +{ + mpt::PathString result = path; + if(path.empty()) + { + return result; + } + if(!_wcsnicmp(relativeTo.AsNative().c_str(), AsNative().c_str(), relativeTo.AsNative().length())) + { + // Path is OpenMPT's directory or a sub directory ("C:\OpenMPT\Somepath" => ".\Somepath") + result = MPT_PATHSTRING(".\\"); // ".\" + result += mpt::PathString::FromNative(AsNative().substr(relativeTo.AsNative().length())); + } else if(!_wcsnicmp(relativeTo.AsNative().c_str(), AsNative().c_str(), 2)) + { + // Path is on the same drive as OpenMPT ("C:\Somepath" => "\Somepath") + result = mpt::PathString::FromNative(AsNative().substr(2)); + } + return result; +} + + +// Convert a relative path to an absolute path. +// Paths are relative to the executable path. +PathString PathString::RelativePathToAbsolute(const PathString &relativeTo) const +//------------------------------------------------------------------------------- +{ + mpt::PathString result = path; + if(path.empty()) + { + return result; + } + if(AsNative().length() >= 2 && AsNative().substr(0, 1) == L"\\" && AsNative().substr(0, 2) != L"\\\\") + { + // Path is on the same drive as OpenMPT ("\Somepath\" => "C:\Somepath\"), but ignore network paths starting with "\\" + result = mpt::PathString::FromNative(relativeTo.AsNative().substr(0, 2)); + result += path; + } else if(AsNative().length() >= 2 && AsNative().substr(0, 2) == L".\\") + { + // Path is OpenMPT's directory or a sub directory (".\Somepath\" => "C:\OpenMPT\Somepath\") + result = relativeTo; // "C:\OpenMPT\" + result += mpt::PathString::FromNative(AsNative().substr(2)); + } + return result; +} + + #if defined(WIN32) #if defined(_MFC_VER) mpt::PathString PathString::TunnelOutofCString(const CString &path) +//----------------------------------------------------------------- { #ifdef UNICODE return mpt::PathString::FromWide(path.GetString()); @@ -103,7 +164,9 @@ #endif } + CString PathString::TunnelIntoCString(const mpt::PathString &path) +//---------------------------------------------------------------- { #ifdef UNICODE return path.ToWide().c_str(); Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-16 23:10:41 UTC (rev 3248) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-17 00:40:57 UTC (rev 3249) @@ -120,6 +120,10 @@ return false; } + // Relative / absolute paths conversion + mpt::PathString AbsolutePathToRelative(const mpt::PathString &relativeTo) const; + mpt::PathString RelativePathToAbsolute(const mpt::PathString &relativeTo) const; + #endif // MODPLUG_TRACKER public: Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-16 23:10:41 UTC (rev 3248) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-17 00:40:57 UTC (rev 3249) @@ -219,7 +219,7 @@ BeginWaitCursor(); #ifndef NO_FILEREADER_STD_ISTREAM - mpt::ifstream f(lpszPathName, std::ios_base::binary); + mpt::ifstream f(filename, std::ios_base::binary); m_SndFile.Create(FileReader(&f), CSoundFile::loadCompleteModule, this); #else { @@ -229,6 +229,9 @@ FileReader file = f.GetFile(); if(file.IsValid()) { + ASSERT(GetPathNameMpt() == mpt::PathString()); + SetPathName(filename, FALSE); // Path is not set yet, but ITP loader needs this for relative paths. + m_SndFile.Create(file, CSoundFile::loadCompleteModule, this); } } Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-16 23:10:41 UTC (rev 3248) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-17 00:40:57 UTC (rev 3249) @@ -2041,56 +2041,6 @@ } -// Convert an absolute path to a path that's relative to OpenMPT's directory. -// Paths are relative to the executable path. -mpt::PathString CTrackApp::AbsolutePathToRelative(const mpt::PathString &path) -//---------------------------------------------------------------------------- -{ - mpt::PathString result = path; - if(path.empty()) - { - return result; - } - mpt::PathString exePath = GetAppDirPath(); - if(!_wcsnicmp(exePath.AsNative().c_str(), path.AsNative().c_str(), exePath.AsNative().length())) - { - // Path is OpenMPT's directory or a sub directory ("C:\OpenMPT\Somepath" => ".\Somepath") - result = MPT_PATHSTRING(".\\"); // ".\" - result += mpt::PathString::FromNative(path.AsNative().substr(exePath.AsNative().length())); - } else if(!_wcsnicmp(exePath.AsNative().c_str(), path.AsNative().c_str(), 2)) - { - // Path is on the same drive as OpenMPT ("C:\Somepath" => "\Somepath") - result = mpt::PathString::FromNative(path.AsNative().substr(2)); - } - return result; -} - - -// Convert a relative path to an absolute path. -// Paths are relative to the executable path. -mpt::PathString CTrackApp::RelativePathToAbsolute(const mpt::PathString &path) -//---------------------------------------------------------------------------- -{ - mpt::PathString result = path; - if(path.empty()) - { - return result; - } - mpt::PathString exePath = GetAppDirPath(); - if(path.AsNative().length() >= 2 && path.AsNative().substr(0, 1) == L"\\" && path.AsNative().substr(0, 2) != L"\\\\") - { - // Path is on the same drive as OpenMPT ("\Somepath\" => "C:\Somepath\"), but ignore network paths starting with "\\" - result = mpt::PathString::FromNative(exePath.AsNative().substr(0, 2)); - result += path; - } else if(path.AsNative().length() >= 2 && path.AsNative().substr(0, 2) == L".\\") - { - // Path is OpenMPT's directory or a sub directory (".\Somepath\" => "C:\OpenMPT\Somepath\") - result = exePath; // "C:\OpenMPT\" - result += mpt::PathString::FromNative(path.AsNative().substr(2)); - } - return result; -} - void CTrackApp::RemoveMruItem(const int nItem) //-------------------------------------------- { Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2013-11-16 23:10:41 UTC (rev 3248) +++ trunk/OpenMPT/mptrack/Mptrack.h 2013-11-17 00:40:57 UTC (rev 3249) @@ -210,9 +210,6 @@ static VOID SetAsProject(BOOL n) { m_nProject = n; } // -! NEW_FEATURE#0023 -#if defined(ENABLE_TESTS) - static void SetAppDirPath(mpt::PathString exePath) {m_szExePath=exePath;} -#endif static mpt::PathString GetAppDirPath() {return m_szExePath;} // Returns '\'-ended executable directory path. static MODTYPE GetDefaultDocType() { return m_nDefaultDocType; } static void SetDefaultDocType(MODTYPE n) { m_nDefaultDocType = n; } @@ -271,8 +268,8 @@ void SetupPaths(bool overridePortable); // Relative / absolute paths conversion - mpt::PathString AbsolutePathToRelative(const mpt::PathString &path); - mpt::PathString RelativePathToAbsolute(const mpt::PathString &path); + mpt::PathString AbsolutePathToRelative(const mpt::PathString &path) { return path.AbsolutePathToRelative(GetAppDirPath()); } + mpt::PathString RelativePathToAbsolute(const mpt::PathString &path) { return path.RelativePathToAbsolute(GetAppDirPath()); } /// Removes item from MRU-list; most recent item has index zero. void RemoveMruItem(const int nItem); Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-16 23:10:41 UTC (rev 3248) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-17 00:40:57 UTC (rev 3249) @@ -7,7 +7,8 @@ * with the IT format, but keeping the instrument files with big samples separate * from the pattern data, to keep the work files small and handy. * The current design of the format is quite flawed, though, so expect this to - * change in the (far?) future. + * change in the (far?) future. Most likely, the new MPTM format will contain + * optional functionality to link samples and instruments instead of embedding them. * Authors: OpenMPT Devs * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. */ @@ -18,13 +19,21 @@ #include "../mptrack/mptrack.h" #include "../mptrack/TrackerSettings.h" #include "../mptrack/MemoryMappedFile.h" +#include "../mptrack/Moddoc.h" #endif #include "../common/version.h" #include "Loaders.h" #include "ITTools.h" +// Version changelog: +// v1.03: - Relative unicode instrument paths instead of absolute ANSI paths +// - Per-path variable string length +// - Embedded samples are IT-compressed +// (rev. 3249) +// v1.02: Explicitely updated format to use new instrument flags representation (rev. 483) +// v1.01: Added option to embed instrument headers -#define ITP_VERSION 0x00000102 // v1.02 +#define ITP_VERSION 0x00000103 // v1.03 #define ITP_FILE_ID 0x2E697470 // .itp ASCII @@ -63,7 +72,7 @@ if(!file.CanRead(12 + 4 + 24 + 4) || file.ReadUint32LE() != ITP_FILE_ID // Magic bytes || (version = file.ReadUint32LE()) > ITP_VERSION // Format version - || !ReadITPString(songName, file)) // Song name + || !ReadITPString(songName, file)) // Song name { return false; } else if(loadFlags == onlyVerifyHeader) @@ -129,12 +138,28 @@ } // Instruments' paths - size = file.ReadUint32LE(); // path string length + if(version <= 0x00000102) + { + size = file.ReadUint32LE(); // path string length + } for(INSTRUMENTINDEX ins = 0; ins < GetNumInstruments(); ins++) { + if(version > 0x00000102) + { + size = file.ReadUint32LE(); // path string length + } std::string path; file.ReadString<mpt::String::maybeNullTerminated>(path, size); - m_szInstrumentPath[ins] = mpt::PathString::FromLocale(path); + if(version <= 0x00000102) + { + path = mpt::To(mpt::CharsetUTF8, mpt::CharsetLocale, path); + } + m_szInstrumentPath[ins] = mpt::PathString::FromUTF8(path); + + if(GetpModDoc() != nullptr) + { + m_szInstrumentPath[ins] = m_szInstrumentPath[ins].RelativePathToAbsolute(GetpModDoc()->GetPathNameMpt()); + } } // Song Orders @@ -390,17 +415,14 @@ id = m_nInstruments; fwrite(&id, 1, sizeof(id), f); - // path name string length - id = _MAX_PATH; - fwrite(&id, 1, sizeof(id), f); - // instruments' path for(i = 0; i < m_nInstruments; i++) { - char path[_MAX_PATH]; - MemsetZero(path); - strncpy(path, m_szInstrumentPath[i].ToLocale().c_str(), _MAX_PATH); - fwrite(path, 1, _MAX_PATH, f); + const std::string path = m_szInstrumentPath[i].AbsolutePathToRelative(filename).ToUTF8(); + // path name string length + id = path.length(); + fwrite(&id, 1, sizeof(id), f); + fwrite(path.c_str(), 1, path.length(), f); } // Song Orders @@ -482,7 +504,7 @@ if(!sampleUsed[nsmp] && Samples[nsmp].pSample) { ITSample itss; - itss.ConvertToIT(Samples[nsmp], GetType(), false, false); + itss.ConvertToIT(Samples[nsmp], GetType(), true, true); mpt::String::Write<mpt::String::nullTerminated>(itss.name, m_szNames[nsmp]); Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-16 23:10:41 UTC (rev 3248) +++ trunk/OpenMPT/test/test.cpp 2013-11-17 00:40:57 UTC (rev 3249) @@ -708,18 +708,15 @@ // Path conversions #ifdef MODPLUG_TRACKER - const mpt::PathString realExePath = theApp.GetAppDirPath(); const mpt::PathString exePath = MPT_PATHSTRING("C:\\OpenMPT\\"); - theApp.SetAppDirPath(exePath); - VERIFY_EQUAL(theApp.AbsolutePathToRelative(MPT_PATHSTRING("C:\\OpenMPT\\")), MPT_PATHSTRING(".\\")); - VERIFY_EQUAL(theApp.AbsolutePathToRelative(MPT_PATHSTRING("c:\\OpenMPT\\foo")), MPT_PATHSTRING(".\\foo")); - VERIFY_EQUAL(theApp.AbsolutePathToRelative(MPT_PATHSTRING("C:\\foo")), MPT_PATHSTRING("\\foo")); - VERIFY_EQUAL(theApp.RelativePathToAbsolute(MPT_PATHSTRING(".\\")), MPT_PATHSTRING("C:\\OpenMPT\\")); - VERIFY_EQUAL(theApp.RelativePathToAbsolute(MPT_PATHSTRING(".\\foo")), MPT_PATHSTRING("C:\\OpenMPT\\foo")); - VERIFY_EQUAL(theApp.RelativePathToAbsolute(MPT_PATHSTRING("\\foo")), MPT_PATHSTRING("C:\\foo")); - VERIFY_EQUAL(theApp.AbsolutePathToRelative(MPT_PATHSTRING("\\\\server\\path\\file")), MPT_PATHSTRING("\\\\server\\path\\file")); - VERIFY_EQUAL(theApp.RelativePathToAbsolute(MPT_PATHSTRING("\\\\server\\path\\file")), MPT_PATHSTRING("\\\\server\\path\\file")); - theApp.SetAppDirPath(realExePath); + VERIFY_EQUAL(MPT_PATHSTRING("C:\\OpenMPT\\").AbsolutePathToRelative(exePath), MPT_PATHSTRING(".\\")); + VERIFY_EQUAL(MPT_PATHSTRING("c:\\OpenMPT\\foo").AbsolutePathToRelative(exePath), MPT_PATHSTRING(".\\foo")); + VERIFY_EQUAL(MPT_PATHSTRING("C:\\foo").AbsolutePathToRelative(exePath), MPT_PATHSTRING("\\foo")); + VERIFY_EQUAL(MPT_PATHSTRING(".\\").RelativePathToAbsolute(exePath), MPT_PATHSTRING("C:\\OpenMPT\\")); + VERIFY_EQUAL(MPT_PATHSTRING(".\\foo").RelativePathToAbsolute(exePath), MPT_PATHSTRING("C:\\OpenMPT\\foo")); + VERIFY_EQUAL(MPT_PATHSTRING("\\foo").RelativePathToAbsolute(exePath), MPT_PATHSTRING("C:\\foo")); + VERIFY_EQUAL(MPT_PATHSTRING("\\\\server\\path\\file").AbsolutePathToRelative(exePath), MPT_PATHSTRING("\\\\server\\path\\file")); + VERIFY_EQUAL(MPT_PATHSTRING("\\\\server\\path\\file").RelativePathToAbsolute(exePath), MPT_PATHSTRING("\\\\server\\path\\file")); #endif } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-17 16:02:17
|
Revision: 3250 http://sourceforge.net/p/modplug/code/3250 Author: manxorist Date: 2013-11-17 16:02:07 +0000 (Sun, 17 Nov 2013) Log Message: ----------- [Ref] sounddev: Cleanup naming of buffer attributes statistics. [Ref] sounddev: Clarify that GetCurrentLatency() is informational only and should not be used for timing. [Imp] sounddev: Add current buffer usage to sound card statistics. [Imp] sounddev: Improve accuracy of latency and update interval statistics for portaudio based devices. [Ref] sounddev: Explicitly pass around the wanted update interval for sound devices where we manage the rendering thread instead of relying on the value from the buffer attributes structure. Modified Paths: -------------- trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.h trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp trunk/OpenMPT/sounddev/SoundDeviceWaveout.h trunk/OpenMPT/sounddev/SoundDevices.h Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-17 16:02:07 UTC (rev 3250) @@ -544,11 +544,13 @@ if(pMainFrm->gpSoundDevice && pMainFrm->IsPlaying()) { CHAR s[256]; - _snprintf(s, 255, "Buffers: %d\r\nUpdate interval: %4.1f ms\r\nLatency: %4.1f ms\r\nCurrent Latency: %4.1f ms", - pMainFrm->gpSoundDevice->GetRealNumBuffers(), - (float)(pMainFrm->gpSoundDevice->GetRealUpdateInterval() * 1000.0f), - (float)(pMainFrm->gpSoundDevice->GetRealLatency() * 1000.0f), - (float)(pMainFrm->gpSoundDevice->GetCurrentRealLatency() * 1000.0f) + const SoundBufferAttributes bufferAttributes = pMainFrm->gpSoundDevice->GetBufferAttributes(); + const double currentLatency = pMainFrm->gpSoundDevice->GetCurrentLatency(); + _snprintf(s, 255, "Buffers: %d (%d%%)\r\nUpdate interval: %4.1f ms\r\nLatency: %4.1f ms\r\nCurrent Latency: %4.1f ms", + (int)bufferAttributes.NumBuffers, (bufferAttributes.Latency > 0.0) ? Util::Round<int>(currentLatency / bufferAttributes.Latency * 100.0) : 0, + (float)(bufferAttributes.UpdateInterval * 1000.0f), + (float)(bufferAttributes.Latency * 1000.0f), + (float)(currentLatency * 1000.0f) ); m_EditStatistics.SetWindowText(s); } else Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-17 16:02:07 UTC (rev 3250) @@ -39,9 +39,9 @@ , m_InternalID(internalID) { - m_RealLatency = m_Settings.LatencyMS / 1000.0; - m_RealUpdateInterval = m_Settings.UpdateIntervalMS / 1000.0; - m_RealNumBuffers = 0; + m_BufferAttributes.Latency = m_Settings.LatencyMS / 1000.0; + m_BufferAttributes.UpdateInterval = m_Settings.UpdateIntervalMS / 1000.0; + m_BufferAttributes.NumBuffers = 0; m_IsPlaying = false; m_StreamPositionRenderFrames = 0; @@ -98,6 +98,13 @@ } +void ISoundDevice::UpdateBufferAttributes(SoundBufferAttributes attributes) +//------------------------------------------------------------------------- +{ + m_BufferAttributes = attributes; +} + + bool ISoundDevice::Open(const SoundDeviceSettings &settings) //---------------------------------------------------------- { @@ -110,9 +117,9 @@ if(m_Settings.LatencyMS > SNDDEV_MAXLATENCY_MS) m_Settings.LatencyMS = SNDDEV_MAXLATENCY_MS; if(m_Settings.UpdateIntervalMS < SNDDEV_MINUPDATEINTERVAL_MS) m_Settings.UpdateIntervalMS = SNDDEV_MINUPDATEINTERVAL_MS; if(m_Settings.UpdateIntervalMS > SNDDEV_MAXUPDATEINTERVAL_MS) m_Settings.UpdateIntervalMS = SNDDEV_MAXUPDATEINTERVAL_MS; - m_RealLatency = m_Settings.LatencyMS / 1000.0; - m_RealUpdateInterval = m_Settings.UpdateIntervalMS / 1000.0; - m_RealNumBuffers = 0; + m_BufferAttributes.Latency = m_Settings.LatencyMS / 1000.0; + m_BufferAttributes.UpdateInterval = m_Settings.UpdateIntervalMS / 1000.0; + m_BufferAttributes.NumBuffers = 0; return InternalOpen(); } @@ -276,6 +283,7 @@ } } + m_WakeupInterval = 0.0; m_hPlayThread = NULL; m_dwPlayThreadId = 0; m_hAudioWakeUp = NULL; @@ -527,7 +535,7 @@ { CPriorityBooster priorityBooster(*this, m_SoundDevice.m_Settings.BoostThreadPriority); - CPeriodicWaker periodicWaker(*this, m_SoundDevice.GetRealUpdateInterval()); + CPeriodicWaker periodicWaker(*this, m_WakeupInterval); m_SoundDevice.StartFromSoundThread(); @@ -561,6 +569,13 @@ } +void CAudioThread::SetWakeupInterval(double seconds) +//-------------------------------------------------- +{ + m_WakeupInterval = seconds; +} + + void CAudioThread::Activate() //--------------------------- { @@ -595,6 +610,13 @@ } +void CSoundDeviceWithThread::SetWakeupInterval(double seconds) +//------------------------------------------------------------ +{ + m_AudioThread.SetWakeupInterval(seconds); +} + + void CSoundDeviceWithThread::InternalStart() //------------------------------------------ { Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-17 16:02:07 UTC (rev 3250) @@ -206,6 +206,21 @@ class SoundDevicesManager; +struct SoundBufferAttributes +{ + double Latency; // seconds + double UpdateInterval; // seconds + int NumBuffers; + SoundBufferAttributes() + : Latency(0.0) + , UpdateInterval(0.0) + , NumBuffers(0) + { + return; + } +}; + + //============================================= class ISoundDevice : protected IFillAudioBuffer //============================================= @@ -227,9 +242,7 @@ private: - double m_RealLatency; - double m_RealUpdateInterval; - int m_RealNumBuffers; + SoundBufferAttributes m_BufferAttributes; bool m_IsPlaying; @@ -251,12 +264,7 @@ bool FillWaveFormatExtensible(WAVEFORMATEXTENSIBLE &WaveFormat); - void UpdateLatencyInfo(double latency, double updateInterval, int numBuffers) - { - m_RealLatency = latency; - m_RealUpdateInterval = updateInterval; - m_RealNumBuffers = numBuffers; - } + void UpdateBufferAttributes(SoundBufferAttributes attributes); virtual bool InternalHasGetStreamPosition() const { return false; } virtual int64 InternalGetStreamPositionFrames() const { return 0; } @@ -295,11 +303,11 @@ SampleFormat GetActualSampleFormat() { return IsOpen() ? m_Settings.sampleFormat : SampleFormatInvalid; } - double GetRealLatency() const { return m_RealLatency; } // seconds - double GetRealUpdateInterval() const { return m_RealUpdateInterval; } // seconds - int GetRealNumBuffers() const { return m_RealNumBuffers; } + SoundBufferAttributes GetBufferAttributes() const { return m_BufferAttributes; } - virtual double GetCurrentRealLatency() const { return GetRealLatency(); } + // Informational only, do not use for timing. + // Use GetStreamPositionFrames() for timing + virtual double GetCurrentLatency() const { return m_BufferAttributes.Latency; } int64 GetStreamPositionFrames() const; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-17 16:02:07 UTC (rev 3250) @@ -270,10 +270,11 @@ } m_nAsioBufferLen = n; } - UpdateLatencyInfo( - m_nAsioBufferLen * 2.0 / m_Settings.Samplerate, - m_nAsioBufferLen * 1.0 / m_Settings.Samplerate, - 2); + SoundBufferAttributes bufferAttributes; + bufferAttributes.Latency = m_nAsioBufferLen * 2.0 / m_Settings.Samplerate; + bufferAttributes.UpdateInterval = m_nAsioBufferLen * 1.0 / m_Settings.Samplerate; + bufferAttributes.NumBuffers = 2; + UpdateBufferAttributes(bufferAttributes); #ifdef ASIO_LOG Log(" Using buffersize=%d samples\n", m_nAsioBufferLen); #endif Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2013-11-17 16:02:07 UTC (rev 3250) @@ -251,11 +251,13 @@ m_pMixBuffer->GetStatus(&dwStat); if (dwStat & DSBSTATUS_BUFFERLOST) m_pMixBuffer->Restore(); } - UpdateLatencyInfo( - m_nDSoundBufferSize * 1.0 / m_Settings.GetBytesPerSecond(), - std::min(m_Settings.UpdateIntervalMS / 1000.0, m_nDSoundBufferSize / (2.0 * m_Settings.GetBytesPerSecond())), - 1); m_dwWritePos = 0xFFFFFFFF; + SetWakeupInterval(std::min(m_Settings.UpdateIntervalMS / 1000.0, m_nDSoundBufferSize / (2.0 * m_Settings.GetBytesPerSecond()))); + SoundBufferAttributes bufferAttributes; + bufferAttributes.Latency = m_nDSoundBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); + bufferAttributes.UpdateInterval = std::min(m_Settings.UpdateIntervalMS / 1000.0, m_nDSoundBufferSize / (2.0 * m_Settings.GetBytesPerSecond())); + bufferAttributes.NumBuffers = 1; + UpdateBufferAttributes(bufferAttributes); return true; } Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.h 2013-11-17 16:02:07 UTC (rev 3250) @@ -46,7 +46,7 @@ void StartFromSoundThread(); void StopFromSoundThread(); bool InternalIsOpen() const { return (m_pMixBuffer != NULL); } - double GetCurrentRealLatency() const { return 1.0 * m_dwLatency / m_Settings.GetBytesPerSecond(); } + double GetCurrentLatency() const { return 1.0 * m_dwLatency / m_Settings.GetBytesPerSecond(); } SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); protected: Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-17 16:02:07 UTC (rev 3250) @@ -33,6 +33,7 @@ m_HostApi = SndDevTypeToHostApi(id.GetType()); MemsetZero(m_StreamParameters); m_Stream = 0; + m_StreamInfo = 0; m_CurrentFrameCount = 0; m_CurrentRealLatency = 0.0; } @@ -50,6 +51,7 @@ { MemsetZero(m_StreamParameters); m_Stream = 0; + m_StreamInfo = 0; m_CurrentFrameBuffer = 0; m_CurrentFrameCount = 0; m_StreamParameters.device = HostApiOutputIndexToGlobalDeviceIndex(GetDeviceIndex(), m_HostApi); @@ -83,16 +85,18 @@ } if(Pa_IsFormatSupported(NULL, &m_StreamParameters, m_Settings.Samplerate) != paFormatIsSupported) return false; if(Pa_OpenStream(&m_Stream, NULL, &m_StreamParameters, m_Settings.Samplerate, /*static_cast<long>(m_UpdateIntervalMS * pwfx->nSamplesPerSec / 1000.0f)*/ paFramesPerBufferUnspecified, paNoFlag, StreamCallbackWrapper, (void*)this) != paNoError) return false; - if(!Pa_GetStreamInfo(m_Stream)) + m_StreamInfo = Pa_GetStreamInfo(m_Stream); + if(!m_StreamInfo) { Pa_CloseStream(m_Stream); m_Stream = 0; return false; } - UpdateLatencyInfo( - Pa_GetStreamInfo(m_Stream)->outputLatency, - m_Settings.UpdateIntervalMS / 1000.0, - 1); + SoundBufferAttributes bufferAttributes; + bufferAttributes.Latency = m_StreamInfo->outputLatency; + bufferAttributes.UpdateInterval = m_Settings.UpdateIntervalMS / 1000.0; + bufferAttributes.NumBuffers = 1; + UpdateBufferAttributes(bufferAttributes); return true; } @@ -106,9 +110,10 @@ Pa_CloseStream(m_Stream); if(Pa_GetDeviceInfo(m_StreamParameters.device)->hostApi == Pa_HostApiTypeIdToHostApiIndex(paWDMKS)) { - Pa_Sleep((long)(GetRealLatency() * 2.0 * 1000.0)); // wait for broken wdm drivers not closing the stream immediatly + Pa_Sleep(Util::Round<long>(GetBufferAttributes().Latency * 2.0 * 1000.0 + 0.5)); // wait for broken wdm drivers not closing the stream immediatly } MemsetZero(m_StreamParameters); + m_StreamInfo = 0; m_Stream = 0; m_CurrentFrameCount = 0; m_CurrentFrameBuffer = 0; @@ -136,7 +141,7 @@ { if(m_CurrentFrameCount == 0) return; SourceAudioRead(m_CurrentFrameBuffer, m_CurrentFrameCount); - SourceAudioDone(m_CurrentFrameCount, static_cast<ULONG>(m_CurrentRealLatency * Pa_GetStreamInfo(m_Stream)->sampleRate)); + SourceAudioDone(m_CurrentFrameCount, static_cast<ULONG>(m_CurrentRealLatency * m_StreamInfo->sampleRate)); } @@ -144,12 +149,12 @@ //-------------------------------------------------------------- { if(Pa_IsStreamActive(m_Stream) != 1) return 0; - return static_cast<int64>(Pa_GetStreamTime(m_Stream) * Pa_GetStreamInfo(m_Stream)->sampleRate); + return static_cast<int64>(Pa_GetStreamTime(m_Stream) * m_StreamInfo->sampleRate); } -double CPortaudioDevice::GetCurrentRealLatency() const -//---------------------------------------------------- +double CPortaudioDevice::GetCurrentLatency() const +//------------------------------------------------ { return m_CurrentRealLatency; } @@ -206,11 +211,16 @@ { // For WDM-KS, timeInfo->outputBufferDacTime seems to contain bogus values. // Work-around it by using the slightly less accurate per-stream latency estimation. - m_CurrentRealLatency = Pa_GetStreamInfo(m_Stream)->outputLatency; + m_CurrentRealLatency = m_StreamInfo->outputLatency; } else { m_CurrentRealLatency = timeInfo->outputBufferDacTime - timeInfo->currentTime; } + SoundBufferAttributes bufferAttributes; + bufferAttributes.Latency = m_StreamInfo->outputLatency; + bufferAttributes.UpdateInterval = (double)frameCount / (double)m_StreamInfo->sampleRate; + bufferAttributes.NumBuffers = 1; + UpdateBufferAttributes(bufferAttributes); m_CurrentFrameBuffer = output; m_CurrentFrameCount = frameCount; SourceFillAudioBufferLocked(); Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.h 2013-11-17 16:02:07 UTC (rev 3250) @@ -33,6 +33,7 @@ PaStreamParameters m_StreamParameters; PaWasapiStreamInfo m_WasapiStreamInfo; PaStream * m_Stream; + const PaStreamInfo * m_StreamInfo; void * m_CurrentFrameBuffer; unsigned long m_CurrentFrameCount; @@ -49,7 +50,7 @@ void InternalStart(); void InternalStop(); bool InternalIsOpen() const { return m_Stream ? true : false; } - double GetCurrentRealLatency() const; + double GetCurrentLatency() const; bool InternalHasGetStreamPosition() const { return false; } int64 InternalGetStreamPositionFrames() const; SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2013-11-17 16:02:07 UTC (rev 3250) @@ -93,12 +93,14 @@ Close(); return false; } - UpdateLatencyInfo( - m_nWaveBufferSize * m_nPreparedHeaders * 1.0 / m_Settings.GetBytesPerSecond(), - m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(), - m_nPreparedHeaders); m_nBuffersPending = 0; m_nWriteBuffer = 0; + SetWakeupInterval(m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond()); + SoundBufferAttributes bufferAttributes; + bufferAttributes.Latency = m_nWaveBufferSize * m_nPreparedHeaders * 1.0 / m_Settings.GetBytesPerSecond(); + bufferAttributes.UpdateInterval = m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); + bufferAttributes.NumBuffers = m_nPreparedHeaders; + UpdateBufferAttributes(bufferAttributes); return true; } Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.h 2013-11-17 16:02:07 UTC (rev 3250) @@ -45,7 +45,7 @@ void StartFromSoundThread(); void StopFromSoundThread(); bool InternalIsOpen() const { return (m_hWaveOut != NULL); } - double GetCurrentRealLatency() const { return InterlockedExchangeAdd(&m_nBuffersPending, 0) * m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); } + double GetCurrentLatency() const { return InterlockedExchangeAdd(&m_nBuffersPending, 0) * m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); } bool InternalHasGetStreamPosition() const { return true; } int64 InternalGetStreamPositionFrames() const; Modified: trunk/OpenMPT/sounddev/SoundDevices.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevices.h 2013-11-17 00:40:57 UTC (rev 3249) +++ trunk/OpenMPT/sounddev/SoundDevices.h 2013-11-17 16:02:07 UTC (rev 3250) @@ -38,6 +38,7 @@ FAvSetMmThreadCharacteristics pAvSetMmThreadCharacteristics; FAvRevertMmThreadCharacteristics pAvRevertMmThreadCharacteristics; + double m_WakeupInterval; HANDLE m_hAudioWakeUp; HANDLE m_hPlayThread; HANDLE m_hAudioThreadTerminateRequest; @@ -52,6 +53,7 @@ ~CAudioThread(); void Activate(); void Deactivate(); + void SetWakeupInterval(double seconds); }; @@ -62,6 +64,8 @@ CAudioThread m_AudioThread; private: void FillAudioBufferLocked(); +protected: + void SetWakeupInterval(double seconds); public: CSoundDeviceWithThread(SoundDeviceID id, const std::wstring &internalID) : ISoundDevice(id, internalID), m_AudioThread(*this) {} virtual ~CSoundDeviceWithThread() {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-17 17:35:02
|
Revision: 3251 http://sourceforge.net/p/modplug/code/3251 Author: manxorist Date: 2013-11-17 17:34:53 +0000 (Sun, 17 Nov 2013) Log Message: ----------- [Ref] sounddev: Provide accurate current update interval statistics for all sound devices. Modified Paths: -------------- trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-17 16:02:07 UTC (rev 3250) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-17 17:34:53 UTC (rev 3251) @@ -543,16 +543,15 @@ CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); if(pMainFrm->gpSoundDevice && pMainFrm->IsPlaying()) { - CHAR s[256]; const SoundBufferAttributes bufferAttributes = pMainFrm->gpSoundDevice->GetBufferAttributes(); const double currentLatency = pMainFrm->gpSoundDevice->GetCurrentLatency(); - _snprintf(s, 255, "Buffers: %d (%d%%)\r\nUpdate interval: %4.1f ms\r\nLatency: %4.1f ms\r\nCurrent Latency: %4.1f ms", - (int)bufferAttributes.NumBuffers, (bufferAttributes.Latency > 0.0) ? Util::Round<int>(currentLatency / bufferAttributes.Latency * 100.0) : 0, - (float)(bufferAttributes.UpdateInterval * 1000.0f), - (float)(bufferAttributes.Latency * 1000.0f), - (float)(currentLatency * 1000.0f) - ); - m_EditStatistics.SetWindowText(s); + const double currentUpdateInterval = pMainFrm->gpSoundDevice->GetCurrentUpdateInterval(); + std::string s; + s += mpt::String::Print("Buffer: %1%%\r\n", (bufferAttributes.Latency > 0.0) ? Util::Round<int64>(currentLatency / bufferAttributes.Latency * 100.0) : 0); + s += mpt::String::Print("Buffers: %1 (current: %2)\r\n", bufferAttributes.NumBuffers, (currentUpdateInterval > 0.0) ? Util::Round<int64>(bufferAttributes.Latency / currentUpdateInterval) : 0); + s += mpt::String::Print("Latency: %1 ms (current: %2 ms)\r\n", mpt::Format("%4.1f").ToString(bufferAttributes.Latency * 1000.0), mpt::Format("%4.1f").ToString(currentLatency * 1000.0)); + s += mpt::String::Print("Update Interval: %1 ms (current: %2 ms)\r\n", mpt::Format("%4.1f").ToString(bufferAttributes.UpdateInterval * 1000.0), mpt::Format("%4.1f").ToString(currentUpdateInterval * 1000.0)); + m_EditStatistics.SetWindowText(s.c_str()); } else { m_EditStatistics.SetWindowText(""); Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-17 16:02:07 UTC (rev 3250) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-17 17:34:53 UTC (rev 3251) @@ -44,6 +44,7 @@ m_BufferAttributes.NumBuffers = 0; m_IsPlaying = false; + m_CurrentUpdateInterval = 0.0; m_StreamPositionRenderFrames = 0; m_StreamPositionOutputFrames = 0; } @@ -164,6 +165,7 @@ int64 framesRendered = 0; { Util::lock_guard<Util::mutex> lock(m_StreamPositionMutex); + m_CurrentUpdateInterval = (double)numFrames / (double)m_Settings.Samplerate; m_StreamPositionRenderFrames += numFrames; m_StreamPositionOutputFrames = m_StreamPositionRenderFrames - framesLatency; framesRendered = m_StreamPositionRenderFrames; @@ -190,6 +192,7 @@ { { Util::lock_guard<Util::mutex> lock(m_StreamPositionMutex); + m_CurrentUpdateInterval = 0.0; m_StreamPositionRenderFrames = 0; m_StreamPositionOutputFrames = 0; } @@ -209,6 +212,7 @@ m_IsPlaying = false; { Util::lock_guard<Util::mutex> lock(m_StreamPositionMutex); + m_CurrentUpdateInterval = 0.0; m_StreamPositionRenderFrames = 0; m_StreamPositionOutputFrames = 0; } @@ -216,8 +220,16 @@ } +double ISoundDevice::GetCurrentUpdateInterval() const +//--------------------------------------------------- +{ + Util::lock_guard<Util::mutex> lock(m_StreamPositionMutex); + return m_CurrentUpdateInterval; +} + + int64 ISoundDevice::GetStreamPositionFrames() const -//-------------------------------------------------- +//------------------------------------------------- { if(!IsOpen()) return 0; if(InternalHasGetStreamPosition()) Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-17 16:02:07 UTC (rev 3250) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-17 17:34:53 UTC (rev 3251) @@ -247,6 +247,7 @@ bool m_IsPlaying; mutable Util::mutex m_StreamPositionMutex; + double m_CurrentUpdateInterval; int64 m_StreamPositionRenderFrames; int64 m_StreamPositionOutputFrames; @@ -308,6 +309,7 @@ // Informational only, do not use for timing. // Use GetStreamPositionFrames() for timing virtual double GetCurrentLatency() const { return m_BufferAttributes.Latency; } + double GetCurrentUpdateInterval() const; int64 GetStreamPositionFrames() const; Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-17 16:02:07 UTC (rev 3250) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2013-11-17 17:34:53 UTC (rev 3251) @@ -216,11 +216,6 @@ { m_CurrentRealLatency = timeInfo->outputBufferDacTime - timeInfo->currentTime; } - SoundBufferAttributes bufferAttributes; - bufferAttributes.Latency = m_StreamInfo->outputLatency; - bufferAttributes.UpdateInterval = (double)frameCount / (double)m_StreamInfo->sampleRate; - bufferAttributes.NumBuffers = 1; - UpdateBufferAttributes(bufferAttributes); m_CurrentFrameBuffer = output; m_CurrentFrameCount = frameCount; SourceFillAudioBufferLocked(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-17 18:20:02
|
Revision: 3252 http://sourceforge.net/p/modplug/code/3252 Author: manxorist Date: 2013-11-17 18:19:54 +0000 (Sun, 17 Nov 2013) Log Message: ----------- [Ref] sounddev: Pass the ASIO base channel through the regular SoundDeviceSettings struct instead of using a global variable. Modified Paths: -------------- trunk/OpenMPT/mptrack/TrackerSettings.cpp trunk/OpenMPT/mptrack/TrackerSettings.h trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.h Modified: trunk/OpenMPT/mptrack/TrackerSettings.cpp =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-11-17 17:34:53 UTC (rev 3251) +++ trunk/OpenMPT/mptrack/TrackerSettings.cpp 2013-11-17 18:19:54 UTC (rev 3252) @@ -160,6 +160,7 @@ , m_SampleFormat(conf, "Sound Settings", "BitsPerSample", SoundDeviceSettings().sampleFormat) , m_SoundDeviceExclusiveMode(conf, "Sound Settings", "ExclusiveMode", SoundDeviceSettings().ExclusiveMode) , m_SoundDeviceBoostThreadPriority(conf, "Sound Settings", "BoostThreadPriority", SoundDeviceSettings().BoostThreadPriority) + , m_SoundDeviceBaseChannel(conf, "Sound Settings", "ASIOBaseChannel", SoundDeviceSettings().BaseChannel) , MixerMaxChannels(conf, "Sound Settings", "MixChannels", MixerSettings().m_nMaxMixChannels) , MixerDSPMask(conf, "Sound Settings", "Quality", MixerSettings().DSPMask) , MixerFlags(conf, "Sound Settings", "SoundSetup", MixerSettings().MixerFlags) @@ -375,9 +376,6 @@ conf.Remove(MixerVolumeRampSamples_DEPRECATED.GetPath()); } Limit(ResamplerCutoffPercent, 0, 100); -#ifndef NO_ASIO - CASIODevice::baseChannel = conf.Read<int32>("Sound Settings", "ASIOBaseChannel", CASIODevice::baseChannel); -#endif // NO_ASIO // Misc if(defaultModType == MOD_TYPE_NONE) @@ -466,6 +464,7 @@ settings.sampleFormat = m_SampleFormat; settings.ExclusiveMode = m_SoundDeviceExclusiveMode; settings.BoostThreadPriority = m_SoundDeviceBoostThreadPriority; + settings.BaseChannel = m_SoundDeviceBaseChannel; return settings; } @@ -479,6 +478,7 @@ m_SampleFormat = settings.sampleFormat; m_SoundDeviceExclusiveMode = settings.ExclusiveMode; m_SoundDeviceBoostThreadPriority = settings.BoostThreadPriority; + m_SoundDeviceBaseChannel = settings.BaseChannel; } Modified: trunk/OpenMPT/mptrack/TrackerSettings.h =================================================================== --- trunk/OpenMPT/mptrack/TrackerSettings.h 2013-11-17 17:34:53 UTC (rev 3251) +++ trunk/OpenMPT/mptrack/TrackerSettings.h 2013-11-17 18:19:54 UTC (rev 3252) @@ -276,6 +276,7 @@ Setting<SampleFormat> m_SampleFormat; Setting<bool> m_SoundDeviceExclusiveMode; Setting<bool> m_SoundDeviceBoostThreadPriority; + Setting<uint32> m_SoundDeviceBaseChannel; SoundDeviceSettings GetSoundDeviceSettings() const; void SetSoundDeviceSettings(const SoundDeviceSettings &settings); Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-17 17:34:53 UTC (rev 3251) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-17 18:19:54 UTC (rev 3252) @@ -151,6 +151,7 @@ SampleFormat sampleFormat; bool ExclusiveMode; // Use hardware buffers directly bool BoostThreadPriority; // Boost thread priority for glitch-free audio rendering + uint32 BaseChannel; SoundDeviceSettings() : hWnd(NULL) , LatencyMS(100) @@ -160,6 +161,7 @@ , sampleFormat(SampleFormatInt16) , ExclusiveMode(false) , BoostThreadPriority(true) + , BaseChannel(0) { return; } @@ -174,6 +176,7 @@ && sampleFormat == cmp.sampleFormat && ExclusiveMode == cmp.ExclusiveMode && BoostThreadPriority == cmp.BoostThreadPriority + && BaseChannel == cmp.BaseChannel ; } bool operator != (const SoundDeviceSettings &cmp) const Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-17 17:34:53 UTC (rev 3251) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-17 18:19:54 UTC (rev 3252) @@ -37,8 +37,6 @@ CASIODevice *CASIODevice::gpCurrentAsio = nullptr; -int CASIODevice::baseChannel = 0; - static DWORD g_dwBuffer = 0; static int g_asio_startcount = 0; @@ -192,7 +190,7 @@ ich, m_ChannelInfo[ich].isActive, m_ChannelInfo[ich].channelGroup, m_ChannelInfo[ich].type, m_ChannelInfo[ich].name); #endif m_BufferInfo[ich].isInput = ASIOFalse; - m_BufferInfo[ich].channelNum = ich + CASIODevice::baseChannel; // map MPT channel i to ASIO channel i + m_BufferInfo[ich].channelNum = ich + m_Settings.BaseChannel; // map MPT channel i to ASIO channel i m_BufferInfo[ich].buffers[0] = NULL; m_BufferInfo[ich].buffers[1] = NULL; m_Float = false; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-11-17 17:34:53 UTC (rev 3251) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-11-17 18:19:54 UTC (rev 3252) @@ -49,9 +49,6 @@ void SetRenderSilence(bool silence, bool wait=false); public: - static int baseChannel; - -public: CASIODevice(SoundDeviceID id, const std::wstring &internalID); ~CASIODevice(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-17 21:44:55
|
Revision: 3254 http://sourceforge.net/p/modplug/code/3254 Author: manxorist Date: 2013-11-17 21:44:48 +0000 (Sun, 17 Nov 2013) Log Message: ----------- [Ref] sounddev: Also display latency and update interval values in frames in addition to milliseconds. Modified Paths: -------------- trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/sounddev/SoundDevice.h Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-17 21:22:42 UTC (rev 3253) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-17 21:44:48 UTC (rev 3254) @@ -546,11 +546,12 @@ const SoundBufferAttributes bufferAttributes = pMainFrm->gpSoundDevice->GetBufferAttributes(); const double currentLatency = pMainFrm->gpSoundDevice->GetCurrentLatency(); const double currentUpdateInterval = pMainFrm->gpSoundDevice->GetCurrentUpdateInterval(); + const uint32 samplerate = pMainFrm->gpSoundDevice->GetSettings().Samplerate; std::string s; s += mpt::String::Print("Buffer: %1%%\r\n", (bufferAttributes.Latency > 0.0) ? Util::Round<int64>(currentLatency / bufferAttributes.Latency * 100.0) : 0); s += mpt::String::Print("Buffers: %1 (current: %2)\r\n", bufferAttributes.NumBuffers, (currentUpdateInterval > 0.0) ? Util::Round<int64>(bufferAttributes.Latency / currentUpdateInterval) : 0); - s += mpt::String::Print("Latency: %1 ms (current: %2 ms)\r\n", mpt::Format("%4.1f").ToString(bufferAttributes.Latency * 1000.0), mpt::Format("%4.1f").ToString(currentLatency * 1000.0)); - s += mpt::String::Print("Update Interval: %1 ms (current: %2 ms)\r\n", mpt::Format("%4.1f").ToString(bufferAttributes.UpdateInterval * 1000.0), mpt::Format("%4.1f").ToString(currentUpdateInterval * 1000.0)); + s += mpt::String::Print("Latency: %1 ms (current: %2 ms, %3 frames)\r\n", mpt::Format("%4.1f").ToString(bufferAttributes.Latency * 1000.0), mpt::Format("%4.1f").ToString(currentLatency * 1000.0), Util::Round<int64>(currentLatency * samplerate)); + s += mpt::String::Print("Update Interval: %1 ms (current: %2 ms, %3 frames)\r\n", mpt::Format("%4.1f").ToString(bufferAttributes.UpdateInterval * 1000.0), mpt::Format("%4.1f").ToString(currentUpdateInterval * 1000.0), Util::Round<int64>(currentUpdateInterval * samplerate)); m_EditStatistics.SetWindowText(s.c_str()); } else { Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-17 21:22:42 UTC (rev 3253) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-17 21:44:48 UTC (rev 3254) @@ -305,7 +305,8 @@ bool IsOpen() const { return InternalIsOpen(); } bool IsPlaying() const { return m_IsPlaying; } - SampleFormat GetActualSampleFormat() { return IsOpen() ? m_Settings.sampleFormat : SampleFormatInvalid; } + SoundDeviceSettings GetSettings() const { return m_Settings; } + SampleFormat GetActualSampleFormat() const { return IsOpen() ? m_Settings.sampleFormat : SampleFormatInvalid; } SoundBufferAttributes GetBufferAttributes() const { return m_BufferAttributes; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-17 22:13:42
|
Revision: 3255 http://sourceforge.net/p/modplug/code/3255 Author: saga-games Date: 2013-11-17 22:13:33 +0000 (Sun, 17 Nov 2013) Log Message: ----------- [Ref] Plugin manager: Plugin list is now stored as vector of VSTPluginLib pointers instead of hand-written pointer magic. Maaaaybe this fixes the loss of plugins that happens sometimes (http://bugs.openmpt.org/view.php?id=18). [Mod] OpenMPT: Version is now 1.22.07.02 Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.cpp trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.h trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Modified: trunk/OpenMPT/common/mptPathString.cpp =================================================================== --- trunk/OpenMPT/common/mptPathString.cpp 2013-11-17 21:44:48 UTC (rev 3254) +++ trunk/OpenMPT/common/mptPathString.cpp 2013-11-17 22:13:33 UTC (rev 3255) @@ -90,8 +90,7 @@ } -// Convert an absolute path to a path that's relative to OpenMPT's directory. -// Paths are relative to the executable path. +// Convert an absolute path to a path that's relative to "&relativeTo". PathString PathString::AbsolutePathToRelative(const PathString &relativeTo) const //------------------------------------------------------------------------------- { @@ -114,8 +113,7 @@ } -// Convert a relative path to an absolute path. -// Paths are relative to the executable path. +// Convert a path that is relative to "&relativeTo" to an absolute path. PathString PathString::RelativePathToAbsolute(const PathString &relativeTo) const //------------------------------------------------------------------------------- { Modified: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h 2013-11-17 21:44:48 UTC (rev 3254) +++ trunk/OpenMPT/common/versionNumber.h 2013-11-17 22:13:33 UTC (rev 3255) @@ -17,7 +17,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 22 #define VER_MINOR 07 -#define VER_MINORMINOR 01 +#define VER_MINORMINOR 02 //Version string. For example "1.17.02.28" #define MPT_VERSION_STR VER_STRINGIZE(VER_MAJORMAJOR) "." VER_STRINGIZE(VER_MAJOR) "." VER_STRINGIZE(VER_MINOR) "." VER_STRINGIZE(VER_MINORMINOR) Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-17 21:44:48 UTC (rev 3254) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-17 22:13:33 UTC (rev 3255) @@ -1936,6 +1936,7 @@ std::wstring nonFoundPlugs; const mpt::PathString failedPlugin = theApp.GetSettings().Read<mpt::PathString>("VST Plugins", "FailedPlugin", MPT_PATHSTRING("")); + m_pPluginManager->reserve(numPlugins); for(size_t plug = 0; plug < numPlugins; plug++) { char tmp[32]; @@ -1970,17 +1971,15 @@ if(!m_pPluginManager) return FALSE; #ifndef NO_VST - VSTPluginLib *pPlug; - pPlug = m_pPluginManager->GetFirstPlugin(); size_t plug = 0; - while(pPlug) + for(CVstPluginManager::const_iterator pPlug = m_pPluginManager->begin(); pPlug != m_pPluginManager->end(); pPlug++) { - if(pPlug->pluginId1 != kDmoMagic) + if((**pPlug).pluginId1 != kDmoMagic) { char tmp[32]; wsprintf(tmp, "Plugin%d", plug); - mpt::PathString plugPath = pPlug->dllPath; + mpt::PathString plugPath = (**pPlug).dllPath; if(theApp.IsPortableMode()) { plugPath = AbsolutePathToRelative(plugPath); @@ -1988,7 +1987,6 @@ theApp.GetSettings().Write<mpt::PathString>("VST Plugins", tmp, plugPath); plug++; } - pPlug = pPlug->pNext; } theApp.GetSettings().Write<int32>("VST Plugins", "NumPlugins", plug); #endif // NO_VST Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-17 21:44:48 UTC (rev 3254) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-17 22:13:33 UTC (rev 3255) @@ -317,23 +317,23 @@ { bool first = true; - VSTPluginLib *p = pManager->GetFirstPlugin(); - while(p) + for(CVstPluginManager::const_iterator p = pManager->begin(); p != pManager->end(); p++) { + ASSERT(*p); + const VSTPluginLib &plug = **p; if(nameFilterActive) { // Apply name filter - std::wstring displayName = p->libraryName.ToWide(); + std::wstring displayName = plug.libraryName.ToWide(); for(size_t i = 0; i < displayName.length(); i++) displayName[i] = ::towlower(displayName[i]); if(displayName.find(m_nameFilter, 0) == displayName.npos) { - p = p->pNext; continue; } } - HTREEITEM h = AddTreeItem(p->libraryName.AsNative().c_str(), p->isInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, categoryFolders[p->category], reinterpret_cast<LPARAM>(p)); - categoryUsed[p->category] = true; + HTREEITEM h = AddTreeItem(plug.libraryName.AsNative().c_str(), plug.isInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, categoryFolders[plug.category], reinterpret_cast<LPARAM>(&plug)); + categoryUsed[plug.category] = true; if(nameFilterActive) { @@ -350,7 +350,7 @@ { //Which plugin should be selected? - if(forceSelect != 0 && p->pluginId2 == forceSelect) + if(forceSelect != 0 && plug.pluginId2 == forceSelect) { //forced selection (e.g. just after add plugin) currentPlug = h; @@ -358,19 +358,19 @@ { //Current slot's plugin CVstPlugin *pVstPlug = (CVstPlugin *)m_pPlugin->pMixPlugin; - if (&pVstPlug->GetPluginFactory() == p) + if (&pVstPlug->GetPluginFactory() == &plug) { currentPlug = h; } } else if(m_pPlugin->Info.dwPluginId1 != 0 || m_pPlugin->Info.dwPluginId2 != 0) { //Plugin with matching ID to current slot's plug - if(p->pluginId1 == m_pPlugin->Info.dwPluginId1 - && p->pluginId2 == m_pPlugin->Info.dwPluginId2) + if(plug.pluginId1 == m_pPlugin->Info.dwPluginId1 + && plug.pluginId2 == m_pPlugin->Info.dwPluginId2) { currentPlug = h; } - } else if(p->pluginId2 == TrackerSettings::Instance().gnPlugWindowLast) + } else if(plug.pluginId2 == TrackerSettings::Instance().gnPlugWindowLast) { // Previously selected plugin currentPlug = h; @@ -381,8 +381,6 @@ foundCurrentPlug = true; } } - - p = p->pNext; } } @@ -450,8 +448,8 @@ } -bool CSelectPluginDlg::VerifyPlug(VSTPluginLib *plug) -//--------------------------------------------------- +bool CSelectPluginDlg::VerifyPlug(const VSTPluginLib *plug) +//--------------------------------------------------------- { // TODO: Keep this list up-to-date. static const struct Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.h =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.h 2013-11-17 21:44:48 UTC (rev 3254) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.h 2013-11-17 22:13:33 UTC (rev 3255) @@ -34,7 +34,7 @@ ~CSelectPluginDlg(); void DoClose(); void UpdatePluginsList(VstInt32 forceSelect = 0); - bool VerifyPlug(VSTPluginLib *plug); + bool VerifyPlug(const VSTPluginLib *plug); virtual void DoDataExchange(CDataExchange* pDX); virtual BOOL OnInitDialog(); virtual void OnOK(); Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2013-11-17 21:44:48 UTC (rev 3254) +++ trunk/OpenMPT/mptrack/Vstplug.h 2013-11-17 22:13:33 UTC (rev 3255) @@ -59,8 +59,7 @@ numCategories, }; - VSTPluginLib *pPrev, *pNext; - CVstPlugin *pPluginsList; + CVstPlugin *pPluginsList; // Pointer to first plugin instance (this instance carries pointers to other instances) mpt::PathString libraryName; // Display name mpt::PathString dllPath; // Full path name VstInt32 pluginId1; @@ -69,7 +68,7 @@ bool isInstrument; VSTPluginLib(const mpt::PathString &dllPath, const mpt::PathString &libraryName) - : pPrev(nullptr), pNext(nullptr), pPluginsList(nullptr), + : pPluginsList(nullptr), libraryName(libraryName), dllPath(dllPath), pluginId1(0), pluginId2(0), category(catUnknown), @@ -322,14 +321,22 @@ { #ifndef NO_VST protected: - VSTPluginLib *m_pVstHead; + std::vector<VSTPluginLib *> pluginList; public: CVstPluginManager(); ~CVstPluginManager(); public: - VSTPluginLib *GetFirstPlugin() const { return m_pVstHead; } + typedef std::vector<VSTPluginLib *>::iterator iterator; + typedef std::vector<VSTPluginLib *>::const_iterator const_iterator; + + iterator begin() { return pluginList.begin(); } + const_iterator begin() const { return pluginList.begin(); } + iterator end() { return pluginList.end(); } + const_iterator end() const { return pluginList.end(); } + void reserve(size_t num) { pluginList.reserve(num); } + bool IsValidPlugin(const VSTPluginLib *pLib); VSTPluginLib *AddPlugin(const mpt::PathString &dllPath, bool fromCache = true, const bool checkFileExistence = false, std::wstring* const errStr = nullptr); bool RemovePlugin(VSTPluginLib *); @@ -357,8 +364,12 @@ #else // NO_VST public: - VSTPluginLib *AddPlugin(const mpt::PathString &, bool = true, const bool = false, CString* const = 0) {return 0;} - VSTPluginLib *GetFirstPlugin() const { return 0; } + VSTPluginLib *AddPlugin(const mpt::PathString &, bool = true, const bool = false, std::wstring* const = nullptr) { return 0; } + + const VSTPluginLib **begin() const { return nullptr; } + const VSTPluginLib **end() const { return nullptr; } + void reserve(size_t num) { } + void OnIdle() {} #endif // NO_VST }; Modified: trunk/OpenMPT/soundlib/plugins/PluginManager.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-17 21:44:48 UTC (rev 3254) +++ trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-17 22:13:33 UTC (rev 3255) @@ -75,7 +75,6 @@ CVstPluginManager::CVstPluginManager() //------------------------------------ { - m_pVstHead = nullptr; CSoundFile::gpMixPluginCreateProc = CreateMixPluginProc; EnumerateDirectXDMOs(); } @@ -85,17 +84,13 @@ //------------------------------------- { CSoundFile::gpMixPluginCreateProc = nullptr; - while (m_pVstHead) + for(const_iterator p = begin(); p != end(); p++) { - VSTPluginLib *p = m_pVstHead; - m_pVstHead = m_pVstHead->pNext; - if (m_pVstHead) m_pVstHead->pPrev = nullptr; - p->pPrev = p->pNext = nullptr; - while ((volatile void *)(p->pPluginsList) != nullptr) + while((**p).pPluginsList != nullptr) { - p->pPluginsList->Release(); + (**p).pPluginsList->Release(); } - delete p; + delete *p; } } @@ -103,11 +98,9 @@ bool CVstPluginManager::IsValidPlugin(const VSTPluginLib *pLib) //------------------------------------------------------------- { - VSTPluginLib *p = m_pVstHead; - while (p) + for(const_iterator p = begin(); p != end(); p++) { - if (p == pLib) return true; - p = p->pNext; + if(*p == pLib) return true; } return false; } @@ -141,16 +134,17 @@ { StringFromGUID2(clsid, keyname, 100); - VSTPluginLib *p = new VSTPluginLib(mpt::PathString::FromNative(keyname), mpt::PathString::FromWide(name)); - p->pNext = m_pVstHead; - p->pluginId1 = kDmoMagic; - p->pluginId2 = clsid.Data1; - p->category = VSTPluginLib::catDMO; + VSTPluginLib *plug = new (std::nothrow) VSTPluginLib(mpt::PathString::FromNative(keyname), mpt::PathString::FromWide(name)); + if(plug != nullptr) + { + pluginList.push_back(plug); + plug->pluginId1 = kDmoMagic; + plug->pluginId2 = clsid.Data1; + plug->category = VSTPluginLib::catDMO; #ifdef DMO_LOG - Log("Found \"%s\" clsid=%s\n", p->libraryName.AsNative().c_str(), p->dllPath.AsNative().c_str()); + Log("Found \"%s\" clsid=%s\n", plug->libraryName.AsNative().c_str(), plug->dllPath.AsNative().c_str()); #endif - if (m_pVstHead) m_pVstHead->pPrev = p; - m_pVstHead = p; + } } RegCloseKey(hksub); } @@ -266,12 +260,12 @@ } } - VSTPluginLib *pDup = m_pVstHead; - while(pDup != nullptr) + // Check if this is already a known plugin. + for(const_iterator dupePlug = begin(); dupePlug != end(); dupePlug++) { - if(!dllPath.CompareNoCase(dllPath, pDup->dllPath)) return pDup; - pDup = pDup->pNext; + if(!dllPath.CompareNoCase(dllPath, (**dupePlug).dllPath)) return *dupePlug; } + // Look if the plugin info is stored in the PluginCache if(fromCache) { @@ -286,14 +280,12 @@ if(!realPath.empty() && !dllPath.CompareNoCase(realPath, dllPath)) { - VSTPluginLib *p = new (std::nothrow) VSTPluginLib(dllPath, fileName); - if(p == nullptr) + VSTPluginLib *plug = new (std::nothrow) VSTPluginLib(dllPath, fileName); + if(plug == nullptr) { return nullptr; } - p->pNext = m_pVstHead; - if (m_pVstHead) m_pVstHead->pPrev = p; - m_pVstHead = p; + pluginList.push_back(plug); // Extract plugin Ids for (UINT i=0; i<16; i++) @@ -303,26 +295,26 @@ n &= 0x0f; if (i < 8) { - p->pluginId1 = (p->pluginId1 << 4) | n; + plug->pluginId1 = (plug->pluginId1 << 4) | n; } else { - p->pluginId2 = (p->pluginId2 << 4) | n; + plug->pluginId2 = (plug->pluginId2 << 4) | n; } } std::string flagKey = mpt::String::Format("%s.Flags", IDs.c_str()); - p->DecodeCacheFlags(cacheFile.Read<int32>(cacheSection, flagKey, 0)); + plug->DecodeCacheFlags(cacheFile.Read<int32>(cacheSection, flagKey, 0)); #ifdef VST_USE_ALTERNATIVE_MAGIC - if( p->pluginId1 == kEffectMagic ) + if( plug->pluginId1 == kEffectMagic ) { - p->pluginId1 = CalculateCRC32fromFilename(p->libraryName); // Make Plugin ID unique for sure (for VSTs with same UID) + plug->pluginId1 = CalculateCRC32fromFilename(plug->libraryName); // Make Plugin ID unique for sure (for VSTs with same UID) }; #endif // VST_USE_ALTERNATIVE_MAGIC #ifdef VST_LOG - Log("Plugin \"%s\" found in PluginCache\n", p->libraryName); + Log("Plugin \"%s\" found in PluginCache\n", plug->libraryName.ToLocale().c_str()); #endif // VST_LOG - return p; + return plug; } else { #ifdef VST_LOG @@ -339,12 +331,11 @@ HINSTANCE hLib; bool validPlug = false; - VSTPluginLib *p = new (std::nothrow) VSTPluginLib(dllPath, fileName); - if(p == nullptr) + VSTPluginLib *plug = new (std::nothrow) VSTPluginLib(dllPath, fileName); + if(plug == nullptr) { return nullptr; } - p->pNext = m_pVstHead; try { @@ -354,23 +345,20 @@ { pEffect->dispatcher(pEffect, effOpen, 0, 0, 0, 0); - if (m_pVstHead) m_pVstHead->pPrev = p; - m_pVstHead = p; - #ifdef VST_USE_ALTERNATIVE_MAGIC - p->pluginId1 = CalculateCRC32fromFilename(p->libraryName); // Make Plugin ID unique for sure + plug.pluginId1 = CalculateCRC32fromFilename(plug->libraryName); // Make Plugin ID unique for sure #else - p->pluginId1 = pEffect->magic; + plug->pluginId1 = pEffect->magic; #endif // VST_USE_ALTERNATIVE_MAGIC - p->pluginId2 = pEffect->uniqueID; + plug->pluginId2 = pEffect->uniqueID; - GetPluginInformation(pEffect, *p); + GetPluginInformation(pEffect, *plug); #ifdef VST_LOG int nver = pEffect->dispatcher(pEffect, effGetVstVersion, 0,0, nullptr, 0); if (!nver) nver = pEffect->version; Log("%-20s: v%d.0, %d in, %d out, %2d programs, %2d params, flags=0x%04X realQ=%d offQ=%d\n", - p->libraryName, nver, + plug->libraryName.ToLocale().c_str(), nver, pEffect->numInputs, pEffect->numOutputs, pEffect->numPrograms, pEffect->numParams, pEffect->flags, pEffect->realQualities, pEffect->offQualities); @@ -384,7 +372,7 @@ FreeLibrary(hLib); } catch(...) { - CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to load plugin \"%1\"!\n", p->libraryName)); + CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to load plugin \"%1\"!\n", plug->libraryName)); } // Now it should be safe to assume that this plugin loaded properly. :) @@ -393,8 +381,10 @@ // If OK, write the information in PluginCache if(validPlug) { + pluginList.push_back(plug); + SettingsContainer &cacheFile = theApp.GetPluginCache(); - const std::string IDs = mpt::String::Format("%08X%08X", p->pluginId1, p->pluginId2); + const std::string IDs = mpt::String::Format("%08X%08X", plug->pluginId1, plug->pluginId2); const std::string flagsKey = mpt::String::Format("%s.Flags", IDs); mpt::PathString writePath = dllPath; @@ -405,40 +395,32 @@ cacheFile.Write<mpt::PathString>(cacheSection, IDs, writePath); cacheFile.Write<mpt::PathString>(cacheSection, IDs, dllPath); - cacheFile.Write<std::string>(cacheSectionW, p->libraryName.ToWide(), IDs); - cacheFile.Write<int32>(cacheSection, flagsKey, p->EncodeCacheFlags()); - } else - { - delete p; + cacheFile.Write<std::string>(cacheSectionW, plug->libraryName.ToWide(), IDs); + cacheFile.Write<int32>(cacheSection, flagsKey, plug->EncodeCacheFlags()); } - return (validPlug ? m_pVstHead : nullptr); + return (validPlug ? plug : nullptr); } bool CVstPluginManager::RemovePlugin(VSTPluginLib *pFactory) //---------------------------------------------------------- { - VSTPluginLib *p = m_pVstHead; - - while (p) + for(const_iterator p = begin(); p != end(); p++) { - if (p == pFactory) + VSTPluginLib *plug = *p; + if(plug == pFactory) { - if (p == m_pVstHead) m_pVstHead = p->pNext; - if (p->pPrev) p->pPrev->pNext = p->pNext; - if (p->pNext) p->pNext->pPrev = p->pPrev; - p->pPrev = p->pNext = nullptr; - try { CriticalSection cs; - while ((volatile void *)(p->pPluginsList) != nullptr) + while(plug->pPluginsList != nullptr) { - p->pPluginsList->Release(); + plug->pPluginsList->Release(); } - delete p; + pluginList.erase(p); + delete plug; } catch (...) { CVstPluginManager::ReportPlugException(mpt::String::PrintW(L"Exception while trying to release plugin \"%1\"!\n", pFactory->libraryName)); @@ -446,7 +428,6 @@ return true; } - p = p->pNext; } return false; } @@ -460,28 +441,27 @@ const wchar_t *cacheSectionW = L"PluginCache"; // Find plugin in library - VSTPluginLib *p = m_pVstHead; int match = 0; - while(p) + for(const_iterator p = begin(); p != end(); p++) { - const bool matchID = (p->pluginId1 == mixPlugin.Info.dwPluginId1) - && (p->pluginId2 == mixPlugin.Info.dwPluginId2); - const bool matchName = !mpt::PathString::CompareNoCase(p->libraryName, mpt::PathString::FromUTF8(mixPlugin.GetLibraryName())); + VSTPluginLib *plug = *p; + const bool matchID = (plug->pluginId1 == mixPlugin.Info.dwPluginId1) + && (plug->pluginId2 == mixPlugin.Info.dwPluginId2); + const bool matchName = !mpt::PathString::CompareNoCase(plug->libraryName, mpt::PathString::FromUTF8(mixPlugin.GetLibraryName())); if(matchID && matchName) { - pFound = p; + pFound = plug; break; } else if(matchID && match < 2) { match = 2; - pFound = p; + pFound = plug; } else if(matchName && match < 1) { match = 1; - pFound = p; + pFound = plug; } - p = p->pNext; } if(mixPlugin.Info.dwPluginId1 == kDmoMagic) @@ -581,11 +561,9 @@ void CVstPluginManager::OnIdle() //------------------------------ { - VSTPluginLib *pFactory = m_pVstHead; - - while (pFactory) + for(const_iterator pFactory = begin(); pFactory != end(); pFactory++) { - CVstPlugin *p = pFactory->pPluginsList; + CVstPlugin *p = (**pFactory).pPluginsList; while (p) { //rewbs. VSTCompliance: A specific plug has requested indefinite periodic processing time. @@ -603,7 +581,6 @@ p = p->m_pNext; } - pFactory = pFactory->pNext; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-18 16:03:06
|
Revision: 3261 http://sourceforge.net/p/modplug/code/3261 Author: manxorist Date: 2013-11-18 16:02:58 +0000 (Mon, 18 Nov 2013) Log Message: ----------- [Imp] sounddev: Allow selecting the base (first) channel to use with ASIO drivers. [Imp] sounddev: Get the channel names from ASIO drivers. (code mostly by Saga_Musix) [Imp] sounddev: Add a button to open the ASIO driver panel from the soundcard options dialog. (code mostly by Saga_Musix) [Fix] sounddev: Disable some soundcard options dialog controls that dont do anything for certain device types. Modified Paths: -------------- trunk/OpenMPT/mptrack/Mpdlgs.cpp trunk/OpenMPT/mptrack/Mpdlgs.h trunk/OpenMPT/mptrack/mptrack.rc trunk/OpenMPT/sounddev/SoundDevice.cpp trunk/OpenMPT/sounddev/SoundDevice.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.h Modified: trunk/OpenMPT/mptrack/Mpdlgs.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-18 00:53:40 UTC (rev 3260) +++ trunk/OpenMPT/mptrack/Mpdlgs.cpp 2013-11-18 16:02:58 UTC (rev 3261) @@ -74,9 +74,11 @@ ON_CBN_SELCHANGE(IDC_COMBO4, OnSettingsChanged) ON_CBN_SELCHANGE(IDC_COMBO5, OnSettingsChanged) ON_CBN_SELCHANGE(IDC_COMBO6, OnSettingsChanged) + ON_CBN_SELCHANGE(IDC_COMBO9, OnSettingsChanged) ON_CBN_EDITCHANGE(IDC_COMBO2, OnSettingsChanged) ON_CBN_EDITCHANGE(IDC_COMBO_UPDATEINTERVAL, OnSettingsChanged) ON_COMMAND(IDC_BUTTON1, OnSoundCardRescan) + ON_COMMAND(IDC_BUTTON2, OnSoundCardDriverPanel) END_MESSAGE_MAP() @@ -92,6 +94,8 @@ DDX_Control(pDX, IDC_COMBO4, m_CbnPolyphony); DDX_Control(pDX, IDC_COMBO5, m_CbnChannels); DDX_Control(pDX, IDC_COMBO6, m_CbnSampleFormat); + DDX_Control(pDX, IDC_COMBO9, m_CbnBaseChannel); + DDX_Control(pDX, IDC_BUTTON2, m_BtnDriverPanel); DDX_Control(pDX, IDC_SLIDER1, m_SliderStereoSep); DDX_Control(pDX, IDC_SLIDER_PREAMP, m_SliderPreAmp); DDX_Control(pDX, IDC_EDIT_STATISTICS, m_EditStatistics); @@ -99,6 +103,24 @@ } +COptionsSoundcard::COptionsSoundcard(const SoundDeviceSettings &settings, SoundDeviceID sd) +//----------------------------------------------------------------------------------------- + : CPropertyPage(IDD_OPTIONS_SOUNDCARD) + , m_Settings(settings) +{ + m_PreAmpNoteShowed = false; + SetDevice(sd); +} + + +void COptionsSoundcard::SetDevice(SoundDeviceID dev) +//-------------------------------------------------- +{ + m_CurrentDeviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(dev) ? *(theApp.GetSoundDevicesManager()->FindDeviceInfo(dev)) : SoundDeviceInfo(); + m_CurrentDeviceCaps = theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice, true); +} + + void COptionsSoundcard::OnSoundCardRescan() //----------------------------------------- { @@ -133,7 +155,7 @@ CheckDlgButton(IDC_CHECK5, m_Settings.BoostThreadPriority ? MF_CHECKED : MF_UNCHECKED); // Sampling Rate - UpdateSampleRates(m_nSoundDevice); + UpdateSampleRates(); // Max Mixing Channels { @@ -261,31 +283,38 @@ _tcscpy(tmp, name); cbi.pszText = tmp; int pos = m_CbnDevice.InsertItem(&cbi); - if(cbi.lParam == m_nSoundDevice.GetIdRaw()) + if(cbi.lParam == m_CurrentDeviceInfo.id.GetIdRaw()) { m_CbnDevice.SetCurSel(pos); } iItem++; } } - UpdateControls(m_nSoundDevice); + UpdateControls(); } - UpdateChannels(m_nSoundDevice); - UpdateSampleFormat(m_nSoundDevice); + UpdateChannels(); + UpdateSampleFormat(); } -void COptionsSoundcard::UpdateChannels(SoundDeviceID dev) -//------------------------------------------------------- +void COptionsSoundcard::UpdateChannels() +//-------------------------------------- { - MPT_UNREFERENCED_PARAMETER(dev); CHAR s[128]; UINT n = 0; m_CbnChannels.ResetContent(); - for(UINT channels = 4; channels >= 1; channels /= 2) + UINT maxChannels = 0; + if(m_CurrentDeviceCaps.channelNames.size() > 0) { + maxChannels = std::min<std::size_t>(4, m_CurrentDeviceCaps.channelNames.size()); + } else + { + maxChannels = 4; + } + for(UINT channels = maxChannels; channels >= 1; channels /= 2) + { wsprintf(s, "%s", gszChnCfgNames[(channels+2)/2-1]); UINT ndx = m_CbnChannels.AddString(s); m_CbnChannels.SetItemData(ndx, channels); @@ -295,15 +324,37 @@ } } m_CbnChannels.SetCurSel(n); + if(m_CurrentDeviceInfo.id.GetType() == SNDDEV_ASIO) + { + m_CbnBaseChannel.ResetContent(); + m_CbnBaseChannel.EnableWindow(TRUE); + m_BtnDriverPanel.ShowWindow(SW_SHOW); + int sel = 0; + for(std::size_t channel = 0; channel < m_CurrentDeviceCaps.channelNames.size(); ++channel) + { + int ndx = m_CbnBaseChannel.AddString(mpt::ToCString(m_CurrentDeviceCaps.channelNames[channel])); + m_CbnBaseChannel.SetItemData(ndx, channel); + if(channel == m_Settings.BaseChannel) + { + sel = ndx; + } + } + m_CbnBaseChannel.SetCurSel(sel); + } else + { + m_CbnBaseChannel.ResetContent(); + m_CbnBaseChannel.EnableWindow(FALSE); + m_BtnDriverPanel.ShowWindow(SW_HIDE); + } } -void COptionsSoundcard::UpdateSampleFormat(SoundDeviceID dev) -//----------------------------------------------------------- +void COptionsSoundcard::UpdateSampleFormat() +//------------------------------------------ { UINT n = 0; m_CbnSampleFormat.ResetContent(); - const bool asio = dev.GetType() == SNDDEV_ASIO; + const bool asio = m_CurrentDeviceInfo.id.GetType() == SNDDEV_ASIO; if(asio) { m_Settings.sampleFormat = TrackerSettings::Instance().m_SampleFormat; @@ -400,25 +451,32 @@ //--------------------------------------- { int n = m_CbnDevice.GetCurSel(); - if (n >= 0) + if(n >= 0) { - SoundDeviceID dev = SoundDeviceID::FromIdRaw(m_CbnDevice.GetItemData(n)); - UpdateControls(dev); - UpdateSampleRates(dev); - UpdateChannels(dev); - UpdateSampleFormat(dev); + SetDevice(SoundDeviceID::FromIdRaw(m_CbnDevice.GetItemData(n))); + UpdateControls(); + UpdateSampleRates(); + UpdateChannels(); + UpdateSampleFormat(); OnSettingsChanged(); } } +void COptionsSoundcard::OnSoundCardDriverPanel() +//---------------------------------------------- +{ + theApp.GetSoundDevicesManager()->OpenDriverSettings(SoundDeviceID::FromIdRaw(m_CbnDevice.GetItemData(m_CbnDevice.GetCurSel())), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice); +} + + // Fill the dropdown box with a list of valid sample rates, depending on the selected sound device. -void COptionsSoundcard::UpdateSampleRates(SoundDeviceID dev) -//---------------------------------------------------------- +void COptionsSoundcard::UpdateSampleRates() +//----------------------------------------- { m_CbnMixingFreq.ResetContent(); - std::vector<uint32> samplerates = theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice).supportedSampleRates; + std::vector<uint32> samplerates = m_CurrentDeviceCaps.supportedSampleRates; if(samplerates.empty()) { @@ -442,10 +500,12 @@ } -void COptionsSoundcard::UpdateControls(SoundDeviceID dev) -//------------------------------------------------------- +void COptionsSoundcard::UpdateControls() +//-------------------------------------- { + const SoundDeviceID dev = m_CurrentDeviceInfo.id; GetDlgItem(IDC_CHECK4)->EnableWindow((dev.GetType() == SNDDEV_DSOUND || dev.GetType() == SNDDEV_PORTAUDIO_WASAPI) ? TRUE : FALSE); + GetDlgItem(IDC_CHECK5)->EnableWindow((dev.GetType() == SNDDEV_WAVEOUT || dev.GetType() == SNDDEV_DSOUND) ? TRUE : FALSE); GetDlgItem(IDC_STATIC_UPDATEINTERVAL)->EnableWindow((dev.GetType() == SNDDEV_ASIO) ? FALSE : TRUE); GetDlgItem(IDC_COMBO_UPDATEINTERVAL)->EnableWindow((dev.GetType() == SNDDEV_ASIO) ? FALSE : TRUE); if(dev.GetType() == SNDDEV_DSOUND) @@ -507,9 +567,10 @@ int n = m_CbnDevice.GetCurSel(); if(n >= 0) { - m_nSoundDevice = SoundDeviceID::FromIdRaw(m_CbnDevice.GetItemData(n)); + SetDevice(SoundDeviceID::FromIdRaw(m_CbnDevice.GetItemData(n))); } } + const SoundDeviceID dev = m_CurrentDeviceInfo.id; // Latency { CHAR s[32]; @@ -530,12 +591,22 @@ wsprintf(s, "%d ms", m_Settings.UpdateIntervalMS); m_CbnUpdateIntervalMS.SetWindowText(s); } - CMainFrame::GetMainFrame()->SetupSoundCard(m_Settings, m_nSoundDevice); - UpdateSampleFormat(m_nSoundDevice); + // Base Channel + { + if(m_CurrentDeviceInfo.id.GetType() == SNDDEV_ASIO) + { + m_Settings.BaseChannel = m_CbnBaseChannel.GetItemData(m_CbnBaseChannel.GetCurSel()); + } + } + CMainFrame::GetMainFrame()->SetupSoundCard(m_Settings, m_CurrentDeviceInfo.id); + SetDevice(m_CurrentDeviceInfo.id); // Poll changed ASIO channel names + UpdateSampleFormat(); + UpdateChannels(); UpdateStatistics(); CPropertyPage::OnOK(); } + void COptionsSoundcard::UpdateStatistics() //---------------------------------------- { Modified: trunk/OpenMPT/mptrack/Mpdlgs.h =================================================================== --- trunk/OpenMPT/mptrack/Mpdlgs.h 2013-11-18 00:53:40 UTC (rev 3260) +++ trunk/OpenMPT/mptrack/Mpdlgs.h 2013-11-18 16:02:58 UTC (rev 3261) @@ -21,24 +21,27 @@ CComboBoxEx m_CbnDevice; CComboBox m_CbnLatencyMS, m_CbnUpdateIntervalMS, m_CbnMixingFreq, m_CbnPolyphony, m_CbnChannels, m_CbnSampleFormat; CSliderCtrl m_SliderStereoSep, m_SliderPreAmp; + CComboBox m_CbnBaseChannel; CEdit m_EditStatistics; - CButton m_BtnRescan; + CButton m_BtnDriverPanel; SoundDeviceSettings m_Settings; - SoundDeviceID m_nSoundDevice; bool m_PreAmpNoteShowed; + void SetDevice(SoundDeviceID dev); + SoundDeviceInfo m_CurrentDeviceInfo; + SoundDeviceCaps m_CurrentDeviceCaps; + public: - COptionsSoundcard(const SoundDeviceSettings &settings, SoundDeviceID sd):CPropertyPage(IDD_OPTIONS_SOUNDCARD) - { m_Settings = settings; m_nSoundDevice = sd; m_PreAmpNoteShowed = false; } + COptionsSoundcard(const SoundDeviceSettings &settings, SoundDeviceID sd); void UpdateStatistics(); private: void UpdateEverything(); - void UpdateSampleRates(SoundDeviceID dev); - void UpdateChannels(SoundDeviceID dev); - void UpdateSampleFormat(SoundDeviceID dev); - void UpdateControls(SoundDeviceID dev); + void UpdateSampleRates(); + void UpdateChannels(); + void UpdateSampleFormat(); + void UpdateControls(); void SetPreAmpSliderPosition(); protected: @@ -52,6 +55,7 @@ afx_msg void OnHScroll(UINT, UINT, CScrollBar *); afx_msg void OnVScroll(UINT, UINT, CScrollBar *); afx_msg void OnSoundCardRescan(); + afx_msg void OnSoundCardDriverPanel(); DECLARE_MESSAGE_MAP() }; Modified: trunk/OpenMPT/mptrack/mptrack.rc =================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc 2013-11-18 00:53:40 UTC (rev 3260) +++ trunk/OpenMPT/mptrack/mptrack.rc 2013-11-18 16:02:58 UTC (rev 3261) @@ -1310,10 +1310,13 @@ COMBOBOX IDC_COMBO3,72,84,66,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO5,144,84,42,80,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_COMBO6,192,84,66,80,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - LTEXT "Max. Polyphony:",IDC_STATIC,12,102,54,12,SS_CENTERIMAGE - COMBOBOX IDC_COMBO4,72,102,66,88,CBS_DROPDOWNLIST | WS_TABSTOP + LTEXT "Base channel:",IDC_STATIC,12,102,54,12,SS_CENTERIMAGE + COMBOBOX IDC_COMBO9,72,102,114,90,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "Driver Panel",IDC_BUTTON2,192,102,66,12 GROUPBOX "",IDC_STATIC,6,126,258,90 - CONTROL "Soft Panning",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,12,138,78,12 + LTEXT "Max. Polyphony:",IDC_STATIC,12,138,54,12,SS_CENTERIMAGE + COMBOBOX IDC_COMBO4,72,138,66,88,CBS_DROPDOWNLIST | WS_TABSTOP + CONTROL "Soft Panning",IDC_CHECK2,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,180,138,78,12 LTEXT "Stereo Separation:",IDC_STATIC,12,157,62,8 LTEXT "100%",IDC_TEXT1,80,157,20,8 RTEXT "Low",IDC_STATIC,22,168,15,14,SS_CENTERIMAGE Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-18 00:53:40 UTC (rev 3260) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-18 16:02:58 UTC (rev 3261) @@ -711,11 +711,32 @@ } -SoundDeviceCaps SoundDevicesManager::GetDeviceCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver, ISoundDevice *currentSoundDevice) -//---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +bool SoundDevicesManager::OpenDriverSettings(SoundDeviceID id, ISoundMessageReceiver *messageReceiver, ISoundDevice *currentSoundDevice) +//-------------------------------------------------------------------------------------------------------------------------------------- { - if(m_DeviceCaps.find(id) == m_DeviceCaps.end()) + bool result = false; + if(currentSoundDevice && FindDeviceInfo(id) && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id)->internalID)) { + result = currentSoundDevice->OpenDriverSettings(); + } else + { + ISoundDevice *dummy = CreateSoundDevice(id); + if(dummy) + { + dummy->SetMessageReceiver(messageReceiver); + result = dummy->OpenDriverSettings(); + } + delete dummy; + } + return result; +} + + +SoundDeviceCaps SoundDevicesManager::GetDeviceCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver, ISoundDevice *currentSoundDevice, bool update) +//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +{ + if((m_DeviceCaps.find(id) == m_DeviceCaps.end()) || update) + { if(currentSoundDevice && FindDeviceInfo(id) && (currentSoundDevice->GetDeviceID() == id) && (currentSoundDevice->GetDeviceInternalID() == FindDeviceInfo(id)->internalID)) { m_DeviceCaps[id] = currentSoundDevice->GetDeviceCaps(baseSampleRates); Modified: trunk/OpenMPT/sounddev/SoundDevice.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-18 00:53:40 UTC (rev 3260) +++ trunk/OpenMPT/sounddev/SoundDevice.h 2013-11-18 16:02:58 UTC (rev 3261) @@ -198,6 +198,7 @@ { uint32 currentSampleRate; std::vector<uint32> supportedSampleRates; // Which samplerates are actually supported by the device. Currently only implemented properly for ASIO, DirectSound and PortAudio. + std::vector<std::wstring> channelNames; SoundDeviceCaps() : currentSampleRate(0) { @@ -317,6 +318,7 @@ int64 GetStreamPositionFrames() const; + virtual bool OpenDriverSettings() { return false; }; }; @@ -360,8 +362,10 @@ const SoundDeviceInfo * FindDeviceInfo(SoundDeviceID id) const; - SoundDeviceCaps GetDeviceCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr); + bool OpenDriverSettings(SoundDeviceID id, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr); + SoundDeviceCaps GetDeviceCaps(SoundDeviceID id, const std::vector<uint32> &baseSampleRates, ISoundMessageReceiver *messageReceiver = nullptr, ISoundDevice *currentSoundDevice = nullptr, bool update = false); + ISoundDevice * CreateSoundDevice(SoundDeviceID id); }; Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-18 00:53:40 UTC (rev 3260) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-18 16:02:58 UTC (rev 3261) @@ -26,6 +26,32 @@ #include <algorithm> +// Helper class to temporarily open a device for a query. +class TemporaryASIODeviceOpener +{ +protected: + CASIODevice &device; + const bool wasOpen; + +public: + TemporaryASIODeviceOpener(CASIODevice &d) : device(d), wasOpen(d.IsOpen()) + { + if(!wasOpen) + { + device.OpenDevice(); + } + } + + ~TemporaryASIODeviceOpener() + { + if(!wasOpen) + { + device.CloseDevice(); + } + } +}; + + /////////////////////////////////////////////////////////////////////////////////////// // // ASIO Device implementation @@ -679,14 +705,10 @@ { SoundDeviceCaps caps; - const bool wasOpen = (m_pAsioDrv != NULL); - if(!wasOpen) + TemporaryASIODeviceOpener opener(*this); + if(!IsOpen()) { - OpenDevice(); - if(m_pAsioDrv == NULL) - { - return caps; - } + return caps; } ASIOSampleRate samplerate; @@ -703,14 +725,40 @@ caps.supportedSampleRates.push_back(baseSampleRates[i]); } } - - if(!wasOpen) + long inputChannels = 0; + long outputChannels = 0; + if(m_pAsioDrv->getChannels(&inputChannels, &outputChannels) == ASE_OK) { - CloseDevice(); + for(long i = 0; i < outputChannels; ++i) + { + ASIOChannelInfo channelInfo; + MemsetZero(channelInfo); + channelInfo.channel = i; + if(m_pAsioDrv->getChannelInfo(&channelInfo) == ASE_OK) + { + mpt::String::SetNullTerminator(channelInfo.name); + caps.channelNames.push_back(mpt::ToWide(mpt::CharsetLocale, channelInfo.name)); + } else + { + caps.channelNames.push_back(mpt::ToWString(i)); + } + } } return caps; } +bool CASIODevice::OpenDriverSettings() +//------------------------------------ +{ + TemporaryASIODeviceOpener opener(*this); + if(!IsOpen()) + { + return false; + } + return m_pAsioDrv->controlPanel() == ASE_OK; +} + + #endif // NO_ASIO Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-11-18 00:53:40 UTC (rev 3260) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-11-18 16:02:58 UTC (rev 3261) @@ -29,6 +29,8 @@ class CASIODevice: public ISoundDevice //==================================== { + friend class TemporaryASIODeviceOpener; + enum { ASIO_MAX_CHANNELS=4 }; enum { ASIO_BLOCK_LEN=1024 }; protected: @@ -61,6 +63,7 @@ bool InternalIsOpen() const { return (m_pAsioDrv != nullptr); } SoundDeviceCaps GetDeviceCaps(const std::vector<uint32> &baseSampleRates); + bool OpenDriverSettings(); public: static std::vector<SoundDeviceInfo> EnumerateDevices(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-18 19:44:22
|
Revision: 3265 http://sourceforge.net/p/modplug/code/3265 Author: manxorist Date: 2013-11-18 19:44:15 +0000 (Mon, 18 Nov 2013) Log Message: ----------- [Ref] Add a Util::MultimediaClock RAII wrapper around timeBeginPeriod/timeEndPeriod/timeGetTime. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/sounddev/SoundDevice.cpp Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2013-11-18 19:08:35 UTC (rev 3264) +++ trunk/OpenMPT/common/misc_util.cpp 2013-11-18 19:44:15 UTC (rev 3265) @@ -79,7 +79,91 @@ long double ConvertStrToLongDouble(const std::wstring &str) { return ConvertStrToHelper<long double>(str); } +#ifdef MODPLUG_TRACKER +namespace Util +{ + +void MultimediaClock::Init() +{ + m_CurrentPeriod = 0; +} + +void MultimediaClock::SetPeriod(uint32 ms) +{ + TIMECAPS caps; + MemsetZero(caps); + if(timeGetDevCaps(&caps, sizeof(caps)) != MMSYSERR_NOERROR) + { + return; + } + if((caps.wPeriodMax == 0) || (caps.wPeriodMin > caps.wPeriodMax)) + { + return; + } + ms = Clamp<uint32>(ms, caps.wPeriodMin, caps.wPeriodMax); + if(timeBeginPeriod(ms) != MMSYSERR_NOERROR) + { + return; + } + m_CurrentPeriod = ms; +} + +void MultimediaClock::Cleanup() +{ + if(m_CurrentPeriod > 0) + { + if(timeEndPeriod(m_CurrentPeriod) != MMSYSERR_NOERROR) + { + // should not happen + ASSERT(false); + } + m_CurrentPeriod = 0; + } +} + +MultimediaClock::MultimediaClock() +{ + Init(); +} + +MultimediaClock::MultimediaClock(uint32 ms) +{ + Init(); + SetResolution(ms); +} + +MultimediaClock::~MultimediaClock() +{ + Cleanup(); +} + +uint32 MultimediaClock::SetResolution(uint32 ms) +{ + if(m_CurrentPeriod == ms) + { + return m_CurrentPeriod; + } + Cleanup(); + SetPeriod(ms); + return GetResolution(); +} + +uint32 MultimediaClock::GetResolution() const +{ + return m_CurrentPeriod; +} + +uint32 MultimediaClock::Now() const +{ + return timeGetTime(); +} + +} // namespace Util + +#endif // MODPLUG_TRACKER + + #if defined(ENABLE_ASM) Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-11-18 19:08:35 UTC (rev 3264) +++ trunk/OpenMPT/common/misc_util.h 2013-11-18 19:44:15 UTC (rev 3265) @@ -503,6 +503,44 @@ } // namespace Util +#ifdef MODPLUG_TRACKER + +namespace Util +{ + +// RAII wrapper around timeBeginPeriod/timeEndPeriod/timeGetTime (on Windows). +// This clock is monotonic, even across changing its resolution. +// This is needed to synchronize time in Steinberg APIs (ASIO and VST). +class MultimediaClock +{ +private: + UINT m_CurrentPeriod; +private: + void Init(); + void SetPeriod(uint32 ms); + void Cleanup(); +public: + MultimediaClock(); + MultimediaClock(uint32 ms); + ~MultimediaClock(); +public: + // Sets the desired resolution in milliseconds, returns the obtained resolution in milliseconds. + // A parameter of 0 causes the resolution to be reset to system defaults. + // A return value of 0 means the resolution is unknown, but timestamps will still be valid. + uint32 SetResolution(uint32 ms); + // Returns obtained resolution in milliseconds. + // A return value of 0 means the resolution is unknown, but timestamps will still be valid. + uint32 GetResolution() const; + // Returns current instantaneous timestamp in milliseconds. + // The epoch (offset) of the timestamps is undefined but constant until the next system reboot. + // The resolution is the value returned from GetResolution(). + uint32 Now() const; +}; + +} // namespace Util + +#endif + #ifdef ENABLE_ASM #define PROCSUPPORT_MMX 0x00001 // Processor supports MMX instructions #define PROCSUPPORT_SSE 0x00010 // Processor supports SSE instructions Modified: trunk/OpenMPT/sounddev/SoundDevice.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-18 19:08:35 UTC (rev 3264) +++ trunk/OpenMPT/sounddev/SoundDevice.cpp 2013-11-18 19:44:15 UTC (rev 3265) @@ -419,6 +419,8 @@ long sleepMilliseconds; int64 sleep100Nanoseconds; + Util::MultimediaClock clock_noxp; + bool period_noxp_set; bool periodic_xp_timer; @@ -455,7 +457,8 @@ } else { sleepEvent = CreateEvent(NULL, FALSE, FALSE, NULL); - period_noxp_set = (timeBeginPeriod(1) == TIMERR_NOERROR); // increase resolution of multimedia timer + clock_noxp.SetResolution(1); // increase resolution of multimedia timer + period_noxp_set = true; } } @@ -504,7 +507,7 @@ { if(period_noxp_set) { - timeEndPeriod(1); + clock_noxp.SetResolution(0); period_noxp_set = false; } CloseHandle(sleepEvent); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-18 21:47:09
|
Revision: 3267 http://sourceforge.net/p/modplug/code/3267 Author: manxorist Date: 2013-11-18 21:46:59 +0000 (Mon, 18 Nov 2013) Log Message: ----------- [Fix] ASIO: Allow buffer sizes smaller than 32 samples. [Fix] ASIO: Actually honor user-selected latency value for devices that require power-of-2 buffer sizes instead of blindly falling back to peferred size (broken since at least r37 ). [Ref] ASIO: Rewrite buffer size selection code to be more tolerant about broken ASIO drivers. Revision Links: -------------- http://sourceforge.net/p/modplug/code/37 Modified Paths: -------------- trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp trunk/OpenMPT/sounddev/SoundDeviceASIO.h Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-11-18 20:39:03 UTC (rev 3266) +++ trunk/OpenMPT/common/misc_util.h 2013-11-18 21:46:59 UTC (rev 3267) @@ -382,6 +382,18 @@ const T intval = static_cast<T>(valRounded); return intval; } + + template<typename T> + T Weight(T x) + { + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + T c; + for(c = 0; x; x >>= 1) + { + c += x & 1; + } + return c; + } } Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-18 20:39:03 UTC (rev 3266) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-18 21:46:59 UTC (rev 3267) @@ -267,32 +267,52 @@ minSize, maxSize, preferredSize, granularity); #endif m_nAsioBufferLen = ((m_Settings.LatencyMS * m_Settings.Samplerate) / 2000); - if (m_nAsioBufferLen < (UINT)minSize) m_nAsioBufferLen = minSize; else - if (m_nAsioBufferLen > (UINT)maxSize) m_nAsioBufferLen = maxSize; else - if (granularity < 0) - { - //rewbs.ASIOfix: - /*UINT n = (minSize < 32) ? 32 : minSize; - if (n % granularity) n = (n + granularity - 1) - (n % granularity); - while ((n+(n>>1) < m_nAsioBufferLen) && (n*2 <= (UINT)maxSize)) + if(minSize <= 0 || maxSize <= 0 || minSize > maxSize) + { // limits make no sense + if(preferredSize > 0) { - n *= 2; + m_nAsioBufferLen = preferredSize; + } else + { + // just leave the user value, perhaps it works } - m_nAsioBufferLen = n;*/ - //end rewbs.ASIOfix - m_nAsioBufferLen = preferredSize; - - } else - if (granularity > 0) - { - int n = (minSize < 32) ? 32 : minSize; - n = (n + granularity-1); - n -= (n % granularity); - while ((n+(granularity>>1) < (int)m_nAsioBufferLen) && (n+granularity <= maxSize)) + } else if(granularity < -1) + { // granularity value not allowed, just clamp value + m_nAsioBufferLen = Clamp(m_nAsioBufferLen, minSize, maxSize); + } else if(granularity == -1 && (Util::Weight(minSize) != 1 || Util::Weight(maxSize) != 1)) + { // granularity tells us we need power-of-2 sizes, but min or max sizes are no power-of-2 + m_nAsioBufferLen = Clamp(m_nAsioBufferLen, minSize, maxSize); + // just start at 1 and find a matching power-of-2 in range + const long bufTarget = m_nAsioBufferLen; + for(long bufSize = 1; bufSize <= maxSize && bufSize <= bufTarget; bufSize *= 2) { - n += granularity; + if(bufSize >= minSize) + { + m_nAsioBufferLen = bufSize; + } } - m_nAsioBufferLen = n; + // if no power-of-2 in range is found, just leave the clamped value alone, perhaps it works + } else if(granularity == -1) + { // sane values, power-of-2 size required between min and max + m_nAsioBufferLen = Clamp(m_nAsioBufferLen, minSize, maxSize); + // get the largest allowed buffer size that is smaller or equal to the target size + const long bufTarget = m_nAsioBufferLen; + for(long bufSize = minSize; bufSize <= maxSize && bufSize <= bufTarget; bufSize *= 2) + { + m_nAsioBufferLen = bufSize; + } + } else if(granularity > 0) + { // buffer size in granularity steps from min to max allowed + m_nAsioBufferLen = Clamp(m_nAsioBufferLen, minSize, maxSize); + // get the largest allowed buffer size that is smaller or equal to the target size + const long bufTarget = m_nAsioBufferLen; + for(long bufSize = minSize; bufSize <= maxSize && bufSize <= bufTarget; bufSize += granularity) + { + m_nAsioBufferLen = bufSize; + } + } else + { // should not happen + ASSERT(false); } #ifdef ASIO_LOG Log(" Using buffersize=%d samples\n", m_nAsioBufferLen); Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-11-18 20:39:03 UTC (rev 3266) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.h 2013-11-18 21:46:59 UTC (rev 3267) @@ -34,7 +34,7 @@ enum { ASIO_MAX_CHANNELS=4 }; protected: IASIO *m_pAsioDrv; - UINT m_nAsioBufferLen; + long m_nAsioBufferLen; UINT m_nAsioSampleSize; bool m_Float; bool m_CanOutputReady; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |