From: <man...@us...> - 2013-11-08 22:56:29
|
Revision: 3139 http://sourceforge.net/p/modplug/code/3139 Author: manxorist Date: 2013-11-08 22:56:21 +0000 (Fri, 08 Nov 2013) Log Message: ----------- [Ref] Kill MPT_TEXT. The only real remaining usage is in MIDIMacros.cpp in tracker-only MFC code. TEXT() can be used there just fine (and in other MFC/WIN32 related places). Modified Paths: -------------- trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/MIDIMacros.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-11-08 22:53:54 UTC (rev 3138) +++ trunk/OpenMPT/common/typedefs.h 2013-11-08 22:56:21 UTC (rev 3139) @@ -339,8 +339,6 @@ #endif #include <windows.h> // defines WIN32 -#define MPT_TEXT(x) TEXT(x) - #else // !_WIN32 // openmpt assumes these type have exact WIN32 semantics @@ -363,8 +361,6 @@ #define TRUE (1) #define FALSE (0) -#define MPT_TEXT(x) x - #endif // _WIN32 Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-11-08 22:53:54 UTC (rev 3138) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-11-08 22:56:21 UTC (rev 3139) @@ -647,8 +647,8 @@ #ifndef MODPLUG_NO_FILESAVE -#define str_tooMuchPatternData (GetStrI18N((MPT_TEXT("Warning: File format limit was reached. Some pattern data may not get written to file.")))) -#define str_pattern (GetStrI18N((MPT_TEXT("pattern")))) +#define str_tooMuchPatternData (GetStrI18N("Warning: File format limit was reached. Some pattern data may not get written to file.")) +#define str_pattern (GetStrI18N("pattern")) bool CSoundFile::SaveXM(const char *lpszFileName, bool compatibilityExport) Modified: trunk/OpenMPT/soundlib/MIDIMacros.cpp =================================================================== --- trunk/OpenMPT/soundlib/MIDIMacros.cpp 2013-11-08 22:53:54 UTC (rev 3138) +++ trunk/OpenMPT/soundlib/MIDIMacros.cpp 2013-11-08 22:56:21 UTC (rev 3139) @@ -224,23 +224,23 @@ } if (paramName.IsEmpty()) { - return MPT_TEXT("N/A"); + return TEXT("N/A"); } CString formattedName; - formattedName.Format(MPT_TEXT("Param %d (%s)"), param, paramName); + formattedName.Format(TEXT("Param %d (%s)"), param, paramName); return formattedName; } else #endif // NO_VST { - return MPT_TEXT("N/A - No Plugin"); + return TEXT("N/A - No Plugin"); } } case sfx_cc: { CString formattedCC; - formattedCC.Format(MPT_TEXT("MIDI CC %d"), MacroToMidiCC(macroIndex)); + formattedCC.Format(TEXT("MIDI CC %d"), MacroToMidiCC(macroIndex)); return formattedCC; } @@ -257,26 +257,26 @@ switch(macroType) { case sfx_unused: - return MPT_TEXT("Unused"); + return TEXT("Unused"); case sfx_cutoff: - return MPT_TEXT("Set Filter Cutoff"); + return TEXT("Set Filter Cutoff"); case sfx_reso: - return MPT_TEXT("Set Filter Resonance"); + return TEXT("Set Filter Resonance"); case sfx_mode: - return MPT_TEXT("Set Filter Mode"); + return TEXT("Set Filter Mode"); case sfx_drywet: - return MPT_TEXT("Set Plugin Dry/Wet Ratio"); + return TEXT("Set Plugin Dry/Wet Ratio"); case sfx_plug: - return MPT_TEXT("Control Plugin Parameter..."); + return TEXT("Control Plugin Parameter..."); case sfx_cc: - return MPT_TEXT("MIDI CC..."); + return TEXT("MIDI CC..."); case sfx_channelAT: - return MPT_TEXT("Channel Aftertouch"); + return TEXT("Channel Aftertouch"); case sfx_polyAT: - return MPT_TEXT("Polyphonic Aftertouch"); + return TEXT("Polyphonic Aftertouch"); case sfx_custom: default: - return MPT_TEXT("Custom"); + return TEXT("Custom"); } } @@ -288,24 +288,24 @@ switch(macroType) { case zxx_unused: - return MPT_TEXT("Unused"); + return TEXT("Unused"); case zxx_reso4Bit: - return MPT_TEXT("Z80 - Z8F controls Resonant Filter Resonance"); + return TEXT("Z80 - Z8F controls Resonant Filter Resonance"); case zxx_reso7Bit: - return MPT_TEXT("Z80 - ZFF controls Resonant Filter Resonance"); + return TEXT("Z80 - ZFF controls Resonant Filter Resonance"); case zxx_cutoff: - return MPT_TEXT("Z80 - ZFF controls Resonant Filter Cutoff"); + return TEXT("Z80 - ZFF controls Resonant Filter Cutoff"); case zxx_mode: - return MPT_TEXT("Z80 - ZFF controls Resonant Filter Mode"); + return TEXT("Z80 - ZFF controls Resonant Filter Mode"); case zxx_resomode: - return MPT_TEXT("Z80 - Z9F controls Resonance + Filter Mode"); + return TEXT("Z80 - Z9F controls Resonance + Filter Mode"); case zxx_channelAT: - return MPT_TEXT("Z80 - ZFF controls Channel Aftertouch"); + return TEXT("Z80 - ZFF controls Channel Aftertouch"); case zxx_polyAT: - return MPT_TEXT("Z80 - ZFF controls Polyphonic Aftertouch"); + return TEXT("Z80 - ZFF controls Polyphonic Aftertouch"); case zxx_custom: default: - return MPT_TEXT("Custom"); + return TEXT("Custom"); } } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-08 22:53:54 UTC (rev 3138) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-08 22:56:21 UTC (rev 3139) @@ -1704,7 +1704,7 @@ const char* pData = nullptr; HGLOBAL hglob = nullptr; size_t nSize = 0; - if (LoadResource(MAKEINTRESOURCE(IDR_BUILTIN_TUNINGS), MPT_TEXT("TUNING"), pData, nSize, hglob) != nullptr) + if (LoadResource(MAKEINTRESOURCE(IDR_BUILTIN_TUNINGS), TEXT("TUNING"), pData, nSize, hglob) != nullptr) { std::istringstream iStrm(std::string(pData, nSize)); s_pTuningsSharedBuiltIn->Deserialize(iStrm); Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-08 22:53:54 UTC (rev 3138) +++ trunk/OpenMPT/test/test.cpp 2013-11-08 22:56:21 UTC (rev 3139) @@ -50,9 +50,6 @@ #endif #endif -#ifndef _T -#define _T MPT_TEXT -#endif namespace MptTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-09 10:34:21
|
Revision: 3140 http://sourceforge.net/p/modplug/code/3140 Author: manxorist Date: 2013-11-09 10:34:10 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Ref] Convert tuning code to mpt::PathString. [Ref] Reduce CString usage in Sndfile.cpp. [Ref] Small cleanup in Vstplug.cpp. Modified Paths: -------------- trunk/OpenMPT/mptrack/TuningDialog.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/tuningCollection.cpp trunk/OpenMPT/soundlib/tuningbase.cpp trunk/OpenMPT/soundlib/tuningbase.h trunk/OpenMPT/soundlib/tuningcollection.h Modified: trunk/OpenMPT/mptrack/TuningDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/TuningDialog.cpp 2013-11-08 22:56:21 UTC (rev 3139) +++ trunk/OpenMPT/mptrack/TuningDialog.cpp 2013-11-09 10:34:10 UTC (rev 3140) @@ -249,7 +249,7 @@ m_EditTuningCollectionVersion.SetWindowText(m_pActiveTuningCollection->GetVersionString().c_str()); m_EditTuningCollectionEditMask.SetWindowText(m_pActiveTuningCollection->GetEditMaskString().c_str()); m_EditTuningCollectionItemNum.SetWindowText(Stringify(m_pActiveTuningCollection->GetNumTunings()).c_str()); - m_EditTuningCollectionPath.SetWindowText(m_pActiveTuningCollection->GetSaveFilePath().c_str()); + m_EditTuningCollectionPath.SetWindowText(m_pActiveTuningCollection->GetSaveFilePath().ToCString()); } //<-- Updating tuning collection part @@ -770,7 +770,7 @@ // a separate collection - no possibility to // directly replace some collection. CTuningCollection* pNewTCol = new CTuningCollection; - pNewTCol->SetSavefilePath(files[counter].ToLocale()); + pNewTCol->SetSavefilePath(files[counter]); if (pNewTCol->Deserialize()) { delete pNewTCol; pNewTCol = 0; Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-08 22:56:21 UTC (rev 3139) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-09 10:34:10 UTC (rev 3140) @@ -1606,7 +1606,7 @@ mpt::String::SetNullTerminator(rawname); FileDialog dlg = SaveFileDialog() - .DefaultExtension(mpt::PathString::FromUTF8("fxb")) + .DefaultExtension("fxb") .DefaultFilename(rawname) .ExtensionFilter("VST Plugin Programs (*.fxp)|*.fxp|" "VST Plugin Banks (*.fxb)|*.fxb||") Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-08 22:56:21 UTC (rev 3139) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-09 10:34:10 UTC (rev 3140) @@ -886,12 +886,14 @@ } if (Reporting::Confirm(notFoundText.c_str(), "OpenMPT - Plugins missing", false, true) == cnfYes) { - CString sUrl = "http://resources.openmpt.org/plugins/search.php?p="; + std::string sUrl = "http://resources.openmpt.org/plugins/search.php?p="; for(std::vector<PLUGINDEX>::iterator i = notFoundIDs.begin(); i != notFoundIDs.end(); ++i) { - sUrl.AppendFormat("%08X%s%%0a", LittleEndian(m_MixPlugins[*i].Info.dwPluginId2), m_MixPlugins[*i].GetLibraryName()); + sUrl += mpt::String::Format("%08X", LittleEndian(m_MixPlugins[*i].Info.dwPluginId2)); + sUrl += mpt::String::Convert(m_MixPlugins[*i].GetLibraryName(), mpt::CharsetLocale, mpt::CharsetUTF8); + sUrl += "%0a"; } - CTrackApp::OpenURL(mpt::PathString::FromCString(sUrl)); + CTrackApp::OpenURL(mpt::PathString::FromUTF8(sUrl)); } } #endif // NO_VST @@ -1721,11 +1723,11 @@ } // Load local tunings. - s_pTuningsSharedLocal->SetSavefilePath(( + s_pTuningsSharedLocal->SetSavefilePath( TrackerDirectories::Instance().GetDefaultDirectory(DIR_TUNING) + mpt::PathString::FromUTF8("local_tunings") - + mpt::PathString::FromLocale(CTuningCollection::s_FileExtension) - ).ToLocale()); + + mpt::PathString::FromUTF8(CTuningCollection::s_FileExtension) + ); s_pTuningsSharedLocal->Deserialize(); // Enabling adding/removing of tunings for standard collection Modified: trunk/OpenMPT/soundlib/tuningCollection.cpp =================================================================== --- trunk/OpenMPT/soundlib/tuningCollection.cpp 2013-11-08 22:56:21 UTC (rev 3139) +++ trunk/OpenMPT/soundlib/tuningCollection.cpp 2013-11-09 10:34:10 UTC (rev 3140) @@ -27,7 +27,7 @@ -Handle const-status better(e.g. status check in unserialization) */ -const CHAR CTuningCollection::s_FileExtension[4] = ".tc"; +const char CTuningCollection::s_FileExtension[4] = ".tc"; namespace CTuningS11n { @@ -122,9 +122,9 @@ CTuningCollection::SERIALIZATION_RETURN_TYPE CTuningCollection::Serialize() const //------------------------------------------------------------------------------- { - if(m_SavefilePath.length() < 1) + if(m_SavefilePath.empty()) return SERIALIZATION_FAILURE; - mpt::ofstream fout(m_SavefilePath.c_str(), std::ios::binary); + mpt::ofstream fout(m_SavefilePath.AsNative().c_str(), std::ios::binary); if(!fout.good()) return SERIALIZATION_FAILURE; @@ -137,9 +137,9 @@ CTuningCollection::SERIALIZATION_RETURN_TYPE CTuningCollection::Deserialize() //--------------------------------------------------------------------------- { - if(m_SavefilePath.length() < 1) + if(m_SavefilePath.empty() < 1) return SERIALIZATION_FAILURE; - mpt::ifstream fin(m_SavefilePath.c_str(), std::ios::binary); + mpt::ifstream fin(m_SavefilePath.AsNative().c_str(), std::ios::binary); if(!fin.good()) return SERIALIZATION_FAILURE; Modified: trunk/OpenMPT/soundlib/tuningbase.cpp =================================================================== --- trunk/OpenMPT/soundlib/tuningbase.cpp 2013-11-08 22:56:21 UTC (rev 3139) +++ trunk/OpenMPT/soundlib/tuningbase.cpp 2013-11-09 10:34:10 UTC (rev 3140) @@ -48,7 +48,7 @@ const CTuningBase::SERIALIZATION_RETURN_TYPE CTuningBase::SERIALIZATION_FAILURE = true; -const CHAR CTuningBase::s_FileExtension[5] = ".tun"; +const char CTuningBase::s_FileExtension[5] = ".tun"; const CTuningBase::EDITMASK CTuningBase::EM_RATIOS = 1; //1b Modified: trunk/OpenMPT/soundlib/tuningbase.h =================================================================== --- trunk/OpenMPT/soundlib/tuningbase.h 2013-11-08 22:56:21 UTC (rev 3139) +++ trunk/OpenMPT/soundlib/tuningbase.h 2013-11-09 10:34:10 UTC (rev 3140) @@ -69,7 +69,7 @@ static const SERIALIZATION_RETURN_TYPE SERIALIZATION_SUCCESS; static const SERIALIZATION_RETURN_TYPE SERIALIZATION_FAILURE; - static const CHAR s_FileExtension[5]; + static const char s_FileExtension[5]; static const EDITMASK EM_RATIOS; static const EDITMASK EM_NOTENAME; Modified: trunk/OpenMPT/soundlib/tuningcollection.h =================================================================== --- trunk/OpenMPT/soundlib/tuningcollection.h 2013-11-08 22:56:21 UTC (rev 3139) +++ trunk/OpenMPT/soundlib/tuningcollection.h 2013-11-09 10:34:10 UTC (rev 3140) @@ -59,7 +59,7 @@ SERIALIZATION_FAILURE = true }; - static const CHAR s_FileExtension[4]; + static const char s_FileExtension[4]; static const size_t s_nMaxTuningCount = 255; //END PUBLIC STATIC CONSTS @@ -94,8 +94,8 @@ const std::string& GetName() const {return m_Name;} - void SetSavefilePath(const std::string &psz) {m_SavefilePath = psz;} - const std::string& GetSaveFilePath() const {return m_SavefilePath;} + void SetSavefilePath(const mpt::PathString &psz) {m_SavefilePath = psz;} + const mpt::PathString& GetSaveFilePath() const {return m_SavefilePath;} std::string GetVersionString() const {return Stringify(static_cast<int>(s_SerializationVersion));} @@ -124,7 +124,7 @@ //BEGIN: NONSERIALIZABLE DATA MEMBERS TUNINGVECTOR m_DeletedTunings; //See Remove()-method for explanation of this. - std::string m_SavefilePath; + mpt::PathString m_SavefilePath; //END: NONSERIALIZABLE DATA MEMBERS //END: DATA MEMBERS This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-09 12:34:20
|
Revision: 3142 http://sourceforge.net/p/modplug/code/3142 Author: manxorist Date: 2013-11-09 12:34:09 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Ref] Convert almost all fopen to mpt_fopen which takes a mpt::Pathname filename. (Leave Dlsbank.* alone for now) [Ref] Convert CCommandSet to mpt::PathString. [Ref] Convert most of the CSoundFile interface to mpt::PathString. (Leave Dlsbank.* and instrument paths alone for now) [Ref] Convert most of test.cpp to mpt::PathString. [Ref] Related conversions. [Fix] IT Compression test cases should only run if we are in the source code directory. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/common/typedefs.cpp trunk/OpenMPT/mptrack/AutoSaver.cpp trunk/OpenMPT/mptrack/CommandSet.cpp trunk/OpenMPT/mptrack/CommandSet.h trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/InputHandler.cpp trunk/OpenMPT/mptrack/KeyConfigDlg.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/soundlib/Load_mod.cpp trunk/OpenMPT/soundlib/Load_s3m.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/WAVTools.cpp trunk/OpenMPT/soundlib/WAVTools.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -268,6 +268,27 @@ #endif +FILE * mpt_fopen(const mpt::PathString &filename, const char *mode) +//----------------------------------------------------------------- +{ + #if defined(WIN32) + return _wfopen(filename.AsNative().c_str(), mode ? mpt::String::Decode(mode, mpt::CharsetLocale).c_str() : nullptr); + #else // !WIN32 + return fopen(filename.AsNative().c_str(), mode); + #endif // WIN32 +} + +FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode) +//-------------------------------------------------------------------- +{ + #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); + #endif // WIN32 +} + + #if defined(MODPLUG_TRACKER) static inline char SanitizeFilenameChar(char c) Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/common/mptString.h 2013-11-09 12:34:09 UTC (rev 3142) @@ -103,6 +103,18 @@ } +static inline std::wstring Replace(std::wstring str, const std::wstring &oldStr, const std::wstring &newStr) +{ + std::size_t pos = 0; + while((pos = str.find(oldStr, pos)) != std::string::npos) + { + str.replace(pos, oldStr.length(), newStr); + pos += newStr.length(); + } + return str; +} + + } // namespace String @@ -282,6 +294,9 @@ } // namespace mpt +FILE * mpt_fopen(const mpt::PathString &filename, const char *mode); +FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode); + #if defined(MODPLUG_TRACKER) // Sanitize a filename (remove special chars) Modified: trunk/OpenMPT/common/typedefs.cpp =================================================================== --- trunk/OpenMPT/common/typedefs.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/common/typedefs.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -123,7 +123,7 @@ static FILE * s_logfile = nullptr; if(!s_logfile) { - s_logfile = fopen("mptrack.log", "a"); + s_logfile = mpt_fopen(mpt::PathString::FromUTF8("mptrack.log"), "a"); } if(s_logfile) { Modified: trunk/OpenMPT/mptrack/AutoSaver.cpp =================================================================== --- trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/AutoSaver.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -247,7 +247,7 @@ // list with backups... hence we have duplicated code.. :( CSoundFile &sndFile = modDoc.GetrSoundFile(); - CString fileName = BuildFileName(modDoc).ToCString(); + mpt::PathString fileName = BuildFileName(modDoc); // We are acutally not going to show the log for autosaved files. ScopedLogCapturer logcapturer(modDoc, "", nullptr, false); Modified: trunk/OpenMPT/mptrack/CommandSet.cpp =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/CommandSet.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1484,8 +1484,8 @@ } -bool CCommandSet::SaveFile(CString fileName) -//------------------------------------------ +bool CCommandSet::SaveFile(const mpt::PathString &filename) +//--------------------------------------------------------- { //TODO: Make C++ /* Layout: @@ -1500,7 +1500,7 @@ FILE *outStream; KeyCombination kc; - if( (outStream = fopen( fileName, "w" )) == NULL ) + if((outStream = mpt_fopen(filename, "w")) == NULL) { ErrorBox(IDS_CANT_OPEN_FILE_FOR_WRITING); return false; @@ -1541,8 +1541,8 @@ } -bool CCommandSet::LoadFile(std::istream& iStrm, LPCTSTR szFilename) -//----------------------------------------------------------------- +bool CCommandSet::LoadFile(std::istream& iStrm, const CString &filenameDescription) +//--------------------------------------------------------------------------------- { KeyCombination kc; CommandID cmd=kcNumCommands; @@ -1660,8 +1660,7 @@ } if(!errText.IsEmpty()) { - CString err; - err.Format("The following problems have been encountered while trying to load the key binding file %s:\n", szFilename); + CString err = TEXT("The following problems have been encountered while trying to load the key binding file ") + filenameDescription + TEXT(":\n"); err += errText; Reporting::Warning(err); } @@ -1675,19 +1674,19 @@ } -bool CCommandSet::LoadFile(CString fileName) -//------------------------------------------ +bool CCommandSet::LoadFile(const mpt::PathString &filename) +//--------------------------------------------------------- { - mpt::ifstream fin(fileName); + mpt::ifstream fin(filename.AsNative().c_str()); if (fin.fail()) { CString strMsg; - AfxFormatString1(strMsg, IDS_CANT_OPEN_KEYBINDING_FILE, fileName); + AfxFormatString1(strMsg, IDS_CANT_OPEN_KEYBINDING_FILE, filename.ToCString()); Reporting::Warning(strMsg); return false; } else - return LoadFile(fin, fileName); + return LoadFile(fin, filename.ToCString()); } Modified: trunk/OpenMPT/mptrack/CommandSet.h =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.h 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/CommandSet.h 2013-11-09 12:34:09 UTC (rev 3142) @@ -1263,9 +1263,9 @@ //Pululation ;) void Copy(CCommandSet *source); // copy the contents of a commandset into this command set void GenKeyMap(KeyMap &km); // Generate a keymap from this command set - bool SaveFile(CString FileName); - bool LoadFile(CString FileName); - bool LoadFile(std::istream& iStrm, LPCTSTR szFilename); + bool SaveFile(const mpt::PathString &filename); + bool LoadFile(const mpt::PathString &filename); + bool LoadFile(std::istream& iStrm, const CString &filenameDescription); bool LoadDefaultKeymap(); void UpgradeKeymap(CCommandSet *pCommands, int oldVersion); Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1756,9 +1756,9 @@ _splitpath(dlg.GetFirstFile().ToLocale().c_str(), drive, path, NULL, ext); bool ok = false; if (!lstrcmpi(ext, ".iti")) - ok = m_sndFile.SaveITIInstrument(m_nInstrument, dlg.GetFirstFile().ToLocale().c_str(), index == (m_sndFile.GetType() == MOD_TYPE_XM ? 3 : 2)); + ok = m_sndFile.SaveITIInstrument(m_nInstrument, dlg.GetFirstFile(), index == (m_sndFile.GetType() == MOD_TYPE_XM ? 3 : 2)); else - ok = m_sndFile.SaveXIInstrument(m_nInstrument, dlg.GetFirstFile().ToLocale().c_str()); + ok = m_sndFile.SaveXIInstrument(m_nInstrument, dlg.GetFirstFile()); // -> CODE#0023 // -> DESC="IT project files (.itp)" Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1047,12 +1047,12 @@ BeginWaitCursor(); - TCHAR ext[_MAX_EXT]; - mpt::String::Copy(ext, dlg.GetFirstFile().GetFileExt().ToCString().GetString()); + CString ext = dlg.GetFirstFile().GetFileExt().ToCString(); bool bOk = false; SAMPLEINDEX iMinSmp = m_nSample, iMaxSmp = m_nSample; - CString sFilename = dlg.GetFirstFile().ToCString(), sNumberFormat; + mpt::PathString sFilename = dlg.GetFirstFile(); + CString sNumberFormat; if(doBatchSave) { iMinSmp = 1; @@ -1075,14 +1075,14 @@ SanitizeFilename(sSampleName); SanitizeFilename(sSampleFilename); - sFilename = dlg.GetFirstFile().ToCString(); - sFilename.Replace("%sample_number%", sSampleNumber); - sFilename.Replace("%sample_filename%", sSampleFilename); - sFilename.Replace("%sample_name%", sSampleName); + sFilename = dlg.GetFirstFile(); + sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_number%", mpt::String::FromCString(sSampleNumber))); + sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_filename%", mpt::String::FromCString(sSampleFilename))); + sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_name%", mpt::String::FromCString(sSampleName))); } - if(!lstrcmpi(ext, ".raw")) + if(!ext.CompareNoCase(".raw")) bOk = m_sndFile.SaveRAWSample(iSmp, sFilename); - else if(!lstrcmpi(ext, ".flac")) + else if(!ext.CompareNoCase(".flac")) bOk = m_sndFile.SaveFLACSample(iSmp, sFilename); else bOk = m_sndFile.SaveWAVSample(iSmp, sFilename); Modified: trunk/OpenMPT/mptrack/InputHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/InputHandler.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/InputHandler.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -30,9 +30,9 @@ //Init CommandSet and Load defaults activeCommandSet = new CCommandSet(); - CString sDefaultPath = theApp.GetConfigPath().ToCString() + TEXT("Keybindings.mkb"); - if (sDefaultPath.GetLength() > MAX_PATH - 1) - sDefaultPath = ""; + mpt::PathString sDefaultPath = theApp.GetConfigPath() + mpt::PathString::FromUTF8("Keybindings.mkb"); + if(sDefaultPath.AsNative().length() > MAX_PATH - 1) + sDefaultPath = mpt::PathString(); const bool bNoExistingKbdFileSetting = TrackerSettings::Instance().m_szKbdFile.empty(); @@ -42,12 +42,12 @@ // 4. If there were no keybinging setting already, create a keybinding file to default location // and set it's path to settings. - if (bNoExistingKbdFileSetting || !(activeCommandSet->LoadFile(TrackerSettings::Instance().m_szKbdFile.ToCString()))) + if (bNoExistingKbdFileSetting || !(activeCommandSet->LoadFile(TrackerSettings::Instance().m_szKbdFile))) { if (bNoExistingKbdFileSetting) - TrackerSettings::Instance().m_szKbdFile = mpt::PathString::FromCString(sDefaultPath); + TrackerSettings::Instance().m_szKbdFile = sDefaultPath; bool bSuccess = false; - if (PathFileExists(sDefaultPath) == TRUE) + if (PathFileExistsW(sDefaultPath.AsNative().c_str()) == TRUE) bSuccess = activeCommandSet->LoadFile(sDefaultPath); if (bSuccess == false) { @@ -56,14 +56,14 @@ bSuccess = activeCommandSet->LoadDefaultKeymap(); if (bSuccess && bNoExistingKbdFileSetting) { - activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile.ToCString()); + activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile); } } if (bSuccess == false) ErrorBox(IDS_UNABLE_TO_LOAD_KEYBINDINGS); } // We will only overwrite the default Keybindings.mkb file from now on. - TrackerSettings::Instance().m_szKbdFile = mpt::PathString::FromCString(sDefaultPath); + TrackerSettings::Instance().m_szKbdFile = sDefaultPath; //Get Keymap activeCommandSet->GenKeyMap(keyMap); Modified: trunk/OpenMPT/mptrack/KeyConfigDlg.cpp =================================================================== --- trunk/OpenMPT/mptrack/KeyConfigDlg.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/KeyConfigDlg.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -846,7 +846,7 @@ if(!dlg.Show()) return; m_sFullPathName = dlg.GetFirstFile(); - plocalCmdSet->LoadFile(m_sFullPathName.ToCString()); + plocalCmdSet->LoadFile(m_sFullPathName); ForceUpdateGUI(); //TentativeSetToDefaultFile(m_sFullPathName); } @@ -863,7 +863,7 @@ if(!dlg.Show()) return; m_sFullPathName = dlg.GetFirstFile(); - plocalCmdSet->SaveFile(m_sFullPathName.ToCString()); + plocalCmdSet->SaveFile(m_sFullPathName); //TentativeSetToDefaultFile(m_sFullPathName); } Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -467,7 +467,7 @@ if(m_InputHandler && m_InputHandler->activeCommandSet) { - m_InputHandler->activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile.ToCString()); + m_InputHandler->activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile); } EndWaitCursor(); Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -428,13 +428,14 @@ } BeginWaitCursor(); FixNullStrings(); + const mpt::PathString filename = mpt::PathString::FromCString(lpszPathName); switch(type) { - case MOD_TYPE_MOD: bOk = m_SndFile.SaveMod(lpszPathName); break; - case MOD_TYPE_S3M: bOk = m_SndFile.SaveS3M(lpszPathName); break; - case MOD_TYPE_XM: bOk = m_SndFile.SaveXM(lpszPathName); break; - case MOD_TYPE_IT: bOk = (m_SndFile.m_SongFlags[SONG_ITPROJECT] ? m_SndFile.SaveITProject(lpszPathName) : m_SndFile.SaveIT(lpszPathName)); break; - case MOD_TYPE_MPT: bOk = m_SndFile.SaveIT(lpszPathName); break; + case MOD_TYPE_MOD: bOk = m_SndFile.SaveMod(filename); break; + case MOD_TYPE_S3M: bOk = m_SndFile.SaveS3M(filename); break; + case MOD_TYPE_XM: bOk = m_SndFile.SaveXM(filename); break; + case MOD_TYPE_IT: bOk = (m_SndFile.m_SongFlags[SONG_ITPROJECT] ? m_SndFile.SaveITProject(filename) : m_SndFile.SaveIT(filename)); break; + case MOD_TYPE_MPT: bOk = m_SndFile.SaveIT(filename); break; } EndWaitCursor(); if (bOk) @@ -511,9 +512,9 @@ const bool xi = !_stricmp(&m_SndFile.m_szInstrumentPath[instr][len - 2], "xi"); if(iti || (!xi && m_SndFile.GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT))) - success = m_SndFile.SaveITIInstrument(instr + 1, m_SndFile.m_szInstrumentPath[instr].c_str(), false); + success = m_SndFile.SaveITIInstrument(instr + 1, mpt::PathString::FromLocale(m_SndFile.m_szInstrumentPath[instr]), false); else - success = m_SndFile.SaveXIInstrument(instr + 1, m_SndFile.m_szInstrumentPath[instr].c_str()); + success = m_SndFile.SaveXIInstrument(instr + 1, mpt::PathString::FromLocale(m_SndFile.m_szInstrumentPath[instr])); if(success) m_bsInstrumentModified.reset(instr); @@ -1953,10 +1954,10 @@ switch (type) { case MOD_TYPE_XM: - m_SndFile.SaveXM(dlg.GetFirstFile().ToLocale().c_str(), true); + m_SndFile.SaveXM(dlg.GetFirstFile(), true); break; case MOD_TYPE_IT: - m_SndFile.SaveIT(dlg.GetFirstFile().ToLocale().c_str(), true); + m_SndFile.SaveIT(dlg.GetFirstFile(), true); break; } } Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1110,8 +1110,8 @@ #include "../mptrack/Mptrack.h" // For config filename #endif // MODPLUG_TRACKER -bool CSoundFile::SaveIT(const char *lpszFileName, bool compatibilityExport) -//------------------------------------------------------------------------- +bool CSoundFile::SaveIT(const mpt::PathString &filename, bool compatibilityExport) +//-------------------------------------------------------------------------------- { const CModSpecifications &specs = (GetType() == MOD_TYPE_MPT ? ModSpecs::mptm : (compatibilityExport ? ModSpecs::it : ModSpecs::itEx)); @@ -1120,7 +1120,7 @@ DWORD dwPos = 0, dwHdrPos = 0, dwExtra = 0; FILE *f; - if ((!lpszFileName) || ((f = fopen(lpszFileName, "wb")) == NULL)) return false; + if(filename.empty() || ((f = mpt_fopen(filename, "wb")) == NULL)) return false; // Writing Header MemsetZero(itHeader); Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -279,11 +279,11 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveITProject(const char *lpszFileName) -//------------------------------------------------------ +bool CSoundFile::SaveITProject(const mpt::PathString &filename) +//------------------------------------------------------------- { #ifndef MODPLUG_TRACKER - MPT_UNREFERENCED_PARAMETER(lpszFileName); + MPT_UNREFERENCED_PARAMETER(filename); return false; #else // MODPLUG_TRACKER @@ -299,7 +299,7 @@ FILE *f; - if((!lpszFileName) || ((f = fopen(lpszFileName, "wb")) == NULL)) return false; + if(filename.empty() || ((f = mpt_fopen(filename, "wb")) == NULL)) return false; // File ID Modified: trunk/OpenMPT/soundlib/Load_mod.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mod.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_mod.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1095,13 +1095,13 @@ #include "../mptrack/moddoc.h" #endif // MODPLUG_TRACKER -bool CSoundFile::SaveMod(const char *lpszFileName) const -//------------------------------------------------------ +bool CSoundFile::SaveMod(const mpt::PathString &filename) const +//------------------------------------------------------------- { FILE *f; - if(m_nChannels == 0 || lpszFileName == nullptr) return false; - if((f = fopen(lpszFileName, "wb")) == nullptr) return false; + if(m_nChannels == 0 || filename.empty()) return false; + if((f = mpt_fopen(filename, "wb")) == nullptr) return false; // Write song title { Modified: trunk/OpenMPT/soundlib/Load_s3m.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_s3m.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_s3m.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -539,8 +539,8 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveS3M(const char *lpszFileName) const -//------------------------------------------------------ +bool CSoundFile::SaveS3M(const mpt::PathString &filename) const +//------------------------------------------------------------- { static const uint8 filler[16] = { @@ -549,8 +549,8 @@ }; FILE *f; - if(m_nChannels == 0 || lpszFileName == nullptr) return false; - if((f = fopen(lpszFileName, "wb")) == nullptr) return false; + if(m_nChannels == 0 || filename.empty()) return false; + if((f = mpt_fopen(filename, "wb")) == nullptr) return false; S3MFileHeader fileHeader; MemsetZero(fileHeader); Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -651,11 +651,11 @@ #define str_pattern (GetStrI18N("pattern")) -bool CSoundFile::SaveXM(const char *lpszFileName, bool compatibilityExport) -//------------------------------------------------------------------------- +bool CSoundFile::SaveXM(const mpt::PathString &filename, bool compatibilityExport) +//-------------------------------------------------------------------------------- { FILE *f; - if(lpszFileName == nullptr || (f = fopen(lpszFileName, "wb")) == nullptr) + if(filename.empty() || (f = mpt_fopen(filename, "wb")) == nullptr) { return false; } Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -453,10 +453,10 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveWAVSample(SAMPLEINDEX nSample, const char *lpszFileName) const -//--------------------------------------------------------------------------------- +bool CSoundFile::SaveWAVSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const +//---------------------------------------------------------------------------------------- { - WAVWriter file(lpszFileName); + WAVWriter file(filename); if(!file.IsValid()) { @@ -494,11 +494,11 @@ /////////////////////////////////////////////////////////////// // Save RAW -bool CSoundFile::SaveRAWSample(SAMPLEINDEX nSample, const char *lpszFileName) const -//--------------------------------------------------------------------------------- +bool CSoundFile::SaveRAWSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const +//---------------------------------------------------------------------------------------- { FILE *f; - if ((f = fopen(lpszFileName, "wb")) == NULL) return false; + if((f = mpt_fopen(filename, "wb")) == NULL) return false; const ModSample &sample = Samples[nSample]; SampleIO( @@ -953,17 +953,17 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveXIInstrument(INSTRUMENTINDEX nInstr, const char *lpszFileName) const -//--------------------------------------------------------------------------------------- +bool CSoundFile::SaveXIInstrument(INSTRUMENTINDEX nInstr, const mpt::PathString &filename) const +//---------------------------------------------------------------------------------------------- { ModInstrument *pIns = Instruments[nInstr]; - if(pIns == nullptr || lpszFileName == nullptr) + if(pIns == nullptr || filename.empty()) { return false; } FILE *f; - if((f = fopen(lpszFileName, "wb")) == nullptr) + if((f = mpt_fopen(filename, "wb")) == nullptr) { return false; } @@ -1535,15 +1535,15 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveITIInstrument(INSTRUMENTINDEX nInstr, const char *lpszFileName, bool compress) const -//------------------------------------------------------------------------------------------------------- +bool CSoundFile::SaveITIInstrument(INSTRUMENTINDEX nInstr, const mpt::PathString &filename, bool compress) const +//-------------------------------------------------------------------------------------------------------------- { ITInstrumentEx iti; ModInstrument *pIns = Instruments[nInstr]; FILE *f; - if((!pIns) || (!lpszFileName)) return false; - if((f = fopen(lpszFileName, "wb")) == NULL) return false; + if((!pIns) || filename.empty()) return false; + if((f = mpt_fopen(filename, "wb")) == NULL) return false; size_t instSize = iti.ConvertToIT(*pIns, false, *this); @@ -2044,8 +2044,8 @@ #ifndef MODPLUG_NO_FILESAVE -bool CSoundFile::SaveFLACSample(SAMPLEINDEX nSample, const char *lpszFileName) const -//---------------------------------------------------------------------------------- +bool CSoundFile::SaveFLACSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const +//----------------------------------------------------------------------------------------- { #ifndef NO_FLAC FLAC__StreamEncoder *encoder = FLAC__stream_encoder_new(); @@ -2144,7 +2144,7 @@ FLAC__stream_encoder_set_compression_level(encoder, compression); #endif // MODPLUG_TRACKER - if(FLAC__stream_encoder_init_file(encoder, lpszFileName, nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) + if(FLAC__stream_encoder_init_file(encoder, filename.ToLocale().c_str(), nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { return false; } Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-11-09 12:34:09 UTC (rev 3142) @@ -565,11 +565,11 @@ // Save Functions #ifndef MODPLUG_NO_FILESAVE - bool SaveXM(const char *lpszFileName, bool compatibilityExport = false); - bool SaveS3M(const char *lpszFileName) const; - bool SaveMod(const char *lpszFileName) const; - bool SaveIT(const char *lpszFileName, bool compatibilityExport = false); - bool SaveITProject(const char *lpszFileName); // -> CODE#0023 -> DESC="IT project files (.itp)" -! NEW_FEATURE#0023 + bool SaveXM(const mpt::PathString &filename, bool compatibilityExport = false); + bool SaveS3M(const mpt::PathString &filename) const; + bool SaveMod(const mpt::PathString &filename) const; + bool SaveIT(const mpt::PathString &filename, bool compatibilityExport = false); + bool SaveITProject(const mpt::PathString &filename); // -> CODE#0023 -> DESC="IT project files (.itp)" -! NEW_FEATURE#0023 UINT SaveMixPlugins(FILE *f=NULL, BOOL bUpdate=TRUE); void WriteInstrumentPropertyForAllInstruments(uint32 code, int16 size, FILE* f, UINT nInstruments) const; void SaveExtendedInstrumentProperties(UINT nInstruments, FILE* f) const; @@ -749,9 +749,9 @@ bool ReadFLACSample(SAMPLEINDEX sample, FileReader &file); bool ReadMP3Sample(SAMPLEINDEX sample, FileReader &file); #ifndef MODPLUG_NO_FILESAVE - bool SaveWAVSample(SAMPLEINDEX nSample, const char *lpszFileName) const; - bool SaveRAWSample(SAMPLEINDEX nSample, const char *lpszFileName) const; - bool SaveFLACSample(SAMPLEINDEX nSample, const char *lpszFileName) const; + bool SaveWAVSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const; + bool SaveRAWSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const; + bool SaveFLACSample(SAMPLEINDEX nSample, const mpt::PathString &filename) const; #endif // Instrument file I/O @@ -761,8 +761,8 @@ bool ReadPATInstrument(INSTRUMENTINDEX nInstr, const LPBYTE lpMemFile, DWORD dwFileLength); bool ReadSampleAsInstrument(INSTRUMENTINDEX nInstr, FileReader &file, bool mayNormalize=false); #ifndef MODPLUG_NO_FILESAVE - bool SaveXIInstrument(INSTRUMENTINDEX nInstr, const char *lpszFileName) const; - bool SaveITIInstrument(INSTRUMENTINDEX nInstr, const char *lpszFileName, bool compress) const; + bool SaveXIInstrument(INSTRUMENTINDEX nInstr, const mpt::PathString &filename) const; + bool SaveITIInstrument(INSTRUMENTINDEX nInstr, const mpt::PathString &filename, bool compress) const; #endif // I/O from another sound file Modified: trunk/OpenMPT/soundlib/WAVTools.cpp =================================================================== --- trunk/OpenMPT/soundlib/WAVTools.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/WAVTools.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -252,10 +252,10 @@ // Output to file: Initialize with filename. -WAVWriter::WAVWriter(const char *filename) : f(nullptr), fileOwned(false), s(nullptr), memory(nullptr), memSize(0) -//---------------------------------------------------------------------------------------------------------------- +WAVWriter::WAVWriter(const mpt::PathString &filename) : f(nullptr), fileOwned(false), s(nullptr), memory(nullptr), memSize(0) +//--------------------------------------------------------------------------------------------------------------------------- { - f = fopen(filename, "w+b"); + f = mpt_fopen(filename, "w+b"); fileOwned = true; Init(); } Modified: trunk/OpenMPT/soundlib/WAVTools.h =================================================================== --- trunk/OpenMPT/soundlib/WAVTools.h 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/soundlib/WAVTools.h 2013-11-09 12:34:09 UTC (rev 3142) @@ -404,7 +404,7 @@ public: // Output to file: Initialize with filename. The created FILE* is owned by this instance. - WAVWriter(const char *filename); + WAVWriter(const mpt::PathString &filename); // Output to file: Initialize with FILE*. WAVWriter(FILE *file); // Output to stream: Initialize with std::ostream*. Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-09 11:42:37 UTC (rev 3141) +++ trunk/OpenMPT/test/test.cpp 2013-11-09 12:34:09 UTC (rev 3142) @@ -1340,20 +1340,23 @@ #ifdef MODPLUG_TRACKER -static const char * debugPaths [] = { "mptrack\\Debug", "bin\\Win32-Debug", "bin\\x64-Debug" }; +static const char * debugPaths [] = { "mptrack\\Debug\\", "bin\\Win32-Debug\\", "bin\\x64-Debug\\" }; -static bool PathEndsIn(const CString &path, const CString &match) +static bool PathEndsIn(const mpt::PathString &path_, const mpt::PathString &match_) { - return path.Mid(path.GetLength() - match.GetLength() - 1, match.GetLength()) == match; + std::wstring path = path_.ToWide(); + std::wstring match = match_.ToWide(); + return path.rfind(match) == (path.length() - match.length()); } static bool ShouldRunTests() { - CString theFile = theApp.GetAppDirPath().ToCString(); + mpt::PathString theFile = theApp.GetAppDirPath(); // Only run the tests when we're in the project directory structure. for(std::size_t i = 0; i < CountOf(debugPaths); ++i) { - if(PathEndsIn(theFile, debugPaths[i])) + const mpt::PathString debugPath = mpt::PathString::FromUTF8(debugPaths[i]); + if(PathEndsIn(theFile, debugPath)) { return true; } @@ -1361,20 +1364,20 @@ return false; } -static std::string GetTestFilenameBase() +static mpt::PathString GetTestFilenameBase() { - CString theFile = theApp.GetAppDirPath().ToCString(); + mpt::PathString theFile = theApp.GetAppDirPath(); for(std::size_t i = 0; i < CountOf(debugPaths); ++i) { - if(PathEndsIn(theFile, debugPaths[i])) + const mpt::PathString debugPath = mpt::PathString::FromUTF8(debugPaths[i]); + if(PathEndsIn(theFile, debugPath)) { - std::size_t count = CString(debugPaths[i]).GetLength() + 1; - theFile.Delete(theFile.GetLength() - count, count); + theFile = mpt::PathString::FromWide(theFile.ToWide().substr(0, theFile.ToWide().length() - debugPath.ToWide().length())); break; } } - theFile.Append("test/test."); - return theFile.GetString(); + theFile += mpt::PathString::FromUTF8("test/test."); + return theFile; } typedef CModDoc *TSoundFileContainer; @@ -1384,9 +1387,9 @@ return sndFile->GetrSoundFile(); } -static TSoundFileContainer CreateSoundFileContainer(const std::string filename) +static TSoundFileContainer CreateSoundFileContainer(const mpt::PathString &filename) { - CModDoc *pModDoc = (CModDoc *)theApp.OpenDocumentFile(filename.c_str(), FALSE); + CModDoc *pModDoc = (CModDoc *)theApp.OpenDocumentFile(filename.ToCString(), FALSE); return pModDoc; } @@ -1395,23 +1398,23 @@ sndFile->OnCloseDocument(); } -static void SaveIT(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveIT(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.c_str()); + sndFile->DoSave(filename.ToCString()); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } -static void SaveXM(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveXM(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.c_str()); + sndFile->DoSave(filename.ToCString()); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } -static void SaveS3M(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveS3M(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->DoSave(filename.c_str()); + sndFile->DoSave(filename.ToCString()); // Saving the file puts it in the MRU list... theApp.RemoveMruItem(0); } @@ -1423,9 +1426,9 @@ return true; } -static std::string GetTestFilenameBase() +static mpt::PathString GetTestFilenameBase() { - return "../test/test."; + return mpt::PathString::FromUTF8("../test/test."); } typedef std::shared_ptr<CSoundFile> TSoundFileContainer; @@ -1435,9 +1438,9 @@ return *sndFile.get(); } -static TSoundFileContainer CreateSoundFileContainer(const std::string &filename) +static TSoundFileContainer CreateSoundFileContainer(const mpt::PathString &filename) { - mpt::ifstream stream(filename, std::ios::binary); + mpt::ifstream stream(filename.AsNative().c_str(), std::ios::binary); FileReader file(&stream); std::shared_ptr<CSoundFile> pSndFile(new CSoundFile()); pSndFile->Create(file, CSoundFile::loadCompleteModule); @@ -1451,19 +1454,19 @@ #ifndef MODPLUG_NO_FILESAVE -static void SaveIT(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveIT(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->SaveIT(filename.c_str(), false); + sndFile->SaveIT(filename, false); } -static void SaveXM(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveXM(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->SaveXM(filename.c_str(), false); + sndFile->SaveXM(filename, false); } -static void SaveS3M(const TSoundFileContainer &sndFile, const std::string &filename) +static void SaveS3M(const TSoundFileContainer &sndFile, const mpt::PathString &filename) { - sndFile->SaveS3M(filename.c_str()); + sndFile->SaveS3M(filename); } #endif @@ -1480,17 +1483,17 @@ { return; } - std::string filenameBase = GetTestFilenameBase(); + mpt::PathString filenameBase = GetTestFilenameBase(); // Test MPTM file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "mptm"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("mptm")); TestLoadMPTMFile(GetrSoundFile(sndFileContainer)); #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveIT(sndFileContainer, filenameBase + "saved.mptm"); + SaveIT(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.mptm")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1499,7 +1502,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "saved.mptm"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.mptm")); TestLoadMPTMFile(GetrSoundFile(sndFileContainer)); @@ -1509,7 +1512,7 @@ // Test XM file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "xm"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("xm")); TestLoadXMFile(GetrSoundFile(sndFileContainer)); @@ -1523,7 +1526,7 @@ #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveXM(sndFileContainer, filenameBase + "saved.xm"); + SaveXM(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.xm")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1532,7 +1535,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "saved.xm"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.xm")); TestLoadXMFile(GetrSoundFile(sndFileContainer)); @@ -1542,13 +1545,13 @@ // Test S3M file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "s3m"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("s3m")); TestLoadS3MFile(GetrSoundFile(sndFileContainer), false); #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveS3M(sndFileContainer, filenameBase + "saved.s3m"); + SaveS3M(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.s3m")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1557,7 +1560,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + "saved.s3m"); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.s3m")); TestLoadS3MFile(GetrSoundFile(sndFileContainer), true); @@ -1570,7 +1573,7 @@ void RunITCompressionTest(const std::vector<int8> &sampleData, ChannelFlags smpFormat, bool it215, int testcount) //--------------------------------------------------------------------------------------------------------------- { - std::string filename = GetTestFilenameBase() + "itcomp" + Stringify(testcount) + ".raw"; + mpt::PathString filename = GetTestFilenameBase() + mpt::PathString::FromUTF8("itcomp" + Stringify(testcount) + ".raw"); ModSample smp; smp.uFlags = smpFormat; @@ -1578,13 +1581,13 @@ smp.nLength = sampleData.size() / smp.GetBytesPerSample(); { - FILE *f = fopen(filename.c_str(), "wb"); + FILE *f = mpt_fopen(filename, "wb"); ITCompression compression(smp, it215, f); fclose(f); } { - FILE *f = fopen(filename.c_str(), "rb"); + FILE *f = mpt_fopen(filename, "rb"); fseek(f, 0, SEEK_END); std::vector<int8> fileData(ftell(f), 0); fseek(f, 0, SEEK_SET); @@ -1598,7 +1601,7 @@ VERIFY_EQUAL_NONCONT(memcmp(&sampleData[0], &sampleDataNew[0], sampleData.size()), 0); fclose(f); } - while(remove(filename.c_str()) == EACCES) + while(remove(filename.ToLocale().c_str()) == EACCES) { // wait for windows virus scanners #ifdef WIN32 @@ -1611,6 +1614,10 @@ void TestITCompression() //---------------------- { + if(!ShouldRunTests()) + { + return; + } // Test loading / saving of IT-compressed samples const int sampleDataSize = 65536; std::vector<int8> sampleData(sampleDataSize, 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-09 13:29:11
|
Revision: 3144 http://sourceforge.net/p/modplug/code/3144 Author: manxorist Date: 2013-11-09 13:29:02 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Fix] Fix CharsetLocale for non-windows. [Imp] Add very basic charset conversion sanity check test cases. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-09 12:40:56 UTC (rev 3143) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-09 13:29:02 UTC (rev 3144) @@ -10,6 +10,7 @@ #include "stdafx.h" #include "mptString.h" +#include <stdexcept> #include <vector> #include <cstdarg> @@ -68,7 +69,7 @@ { switch(charset) { - case CharsetLocale: return "char"; break; + 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 CharsetISO8859_1: return "ISO-8859-1"; break; @@ -96,6 +97,10 @@ #else // !WIN32 iconv_t conv = iconv_t(); conv = iconv_open(CharsetToString(charset), "wchar_t"); + if(!conv) + { + throw std::runtime_error("iconv conversion not working"); + } std::vector<wchar_t> wide_string(src.c_str(), src.c_str() + src.length() + 1); std::vector<char> encoded_string(wide_string.size() * 8); // large enough char * inbuf = (char*)&wide_string[0]; @@ -130,6 +135,10 @@ #else // !WIN32 iconv_t conv = iconv_t(); conv = iconv_open("wchar_t", CharsetToString(charset)); + if(!conv) + { + throw std::runtime_error("iconv conversion not working"); + } std::vector<char> encoded_string(src.c_str(), src.c_str() + src.length() + 1); std::vector<wchar_t> wide_string(encoded_string.size() * 8); // large enough char * inbuf = &encoded_string[0]; @@ -156,6 +165,10 @@ #else // !WIN32 iconv_t conv = iconv_t(); conv = iconv_open(CharsetToString(to), CharsetToString(from)); + if(!conv) + { + 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> dst_string(src_string.size() * 8); // large enough char * inbuf = &src_string[0]; Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-09 12:40:56 UTC (rev 3143) +++ trunk/OpenMPT/test/test.cpp 2013-11-09 13:29:02 UTC (rev 3144) @@ -572,6 +572,16 @@ VERIFY_EQUAL(strlen(ModSpecs::Collection[i]->commands), MAX_EFFECTS); VERIFY_EQUAL(strlen(ModSpecs::Collection[i]->volcommands), MAX_VOLCMDS); } + + // Charset conversions (basic sanity checks) + 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::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"); // 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-09 14:03:16
|
Revision: 3147 http://sourceforge.net/p/modplug/code/3147 Author: manxorist Date: 2013-11-09 14:03:07 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Ref] Use a simple MPT_PATHSTRING(x) macro for constructing mpt::PathString objects from string literals instead of using mpt::PathString::FromUTF8 and raw char * literals which would result in runtime conversion. Modified Paths: -------------- trunk/OpenMPT/common/mptString.h trunk/OpenMPT/common/typedefs.cpp trunk/OpenMPT/mptrack/InputHandler.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/soundlib/Load_mo3.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/common/mptString.h 2013-11-09 14:03:07 UTC (rev 3147) @@ -294,6 +294,16 @@ } // namespace mpt +#if defined(WIN32) + +#define MPT_PATHSTRING(x) mpt::PathString::FromNative( L ## x ) + +#else // !WIN32 + +#define MPT_PATHSTRING(x) mpt::PathString::FromNative( x ) + +#endif // WIN32 + FILE * mpt_fopen(const mpt::PathString &filename, const char *mode); FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode); Modified: trunk/OpenMPT/common/typedefs.cpp =================================================================== --- trunk/OpenMPT/common/typedefs.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/common/typedefs.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -123,7 +123,7 @@ static FILE * s_logfile = nullptr; if(!s_logfile) { - s_logfile = mpt_fopen(mpt::PathString::FromUTF8("mptrack.log"), "a"); + s_logfile = mpt_fopen(MPT_PATHSTRING("mptrack.log"), "a"); } if(s_logfile) { Modified: trunk/OpenMPT/mptrack/InputHandler.cpp =================================================================== --- trunk/OpenMPT/mptrack/InputHandler.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/mptrack/InputHandler.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -30,7 +30,7 @@ //Init CommandSet and Load defaults activeCommandSet = new CCommandSet(); - mpt::PathString sDefaultPath = theApp.GetConfigPath() + mpt::PathString::FromUTF8("Keybindings.mkb"); + mpt::PathString sDefaultPath = theApp.GetConfigPath() + MPT_PATHSTRING("Keybindings.mkb"); if(sDefaultPath.AsNative().length() > MAX_PATH - 1) sDefaultPath = mpt::PathString(); Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -2507,7 +2507,7 @@ //----------------------- { mpt::PathString helpFile = theApp.GetAppDirPath(); - helpFile += mpt::PathString::FromUTF8("OpenMPT Manual.pdf"); + helpFile += MPT_PATHSTRING("OpenMPT Manual.pdf"); if(!theApp.OpenFile(helpFile)) { Reporting::Error(std::string("Could not find help file:\n" + helpFile.ToLocale()).c_str()); Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -721,7 +721,7 @@ // Check if the user prefers to use the app's directory m_szConfigFileName = m_szExePath; // config file - m_szConfigFileName += mpt::PathString::FromUTF8("mptrack.ini"); + m_szConfigFileName += MPT_PATHSTRING("mptrack.ini"); if(GetPrivateProfileIntW(L"Paths", L"UseAppDataDirectory", 1, m_szConfigFileName.AsNative().c_str()) == 0) { bIsAppDir = true; @@ -730,7 +730,7 @@ if(!bIsAppDir) { // Store our app settings in %APPDATA% or "My Files" - m_szConfigDirectory += mpt::PathString::FromUTF8("\\OpenMPT\\"); + m_szConfigDirectory += MPT_PATHSTRING("\\OpenMPT\\"); // Path doesn't exist yet, so it has to be created if(PathIsDirectoryW(m_szConfigDirectory.AsNative().c_str()) == 0) @@ -740,8 +740,8 @@ #ifdef WIN32 // Legacy stuff // Move the config files if they're still in the old place. - MoveConfigFile(mpt::PathString::FromUTF8("mptrack.ini")); - MoveConfigFile(mpt::PathString::FromUTF8("plugin.cache")); + MoveConfigFile(MPT_PATHSTRING("mptrack.ini")); + MoveConfigFile(MPT_PATHSTRING("plugin.cache")); #endif // WIN32 Legacy Stuff } else { @@ -749,7 +749,7 @@ } // Create tunings dir - mpt::PathString sTuningPath = m_szConfigDirectory + mpt::PathString::FromUTF8("tunings\\"); + mpt::PathString sTuningPath = m_szConfigDirectory + MPT_PATHSTRING("tunings\\"); TrackerDirectories::Instance().SetDefaultDirectory(sTuningPath, DIR_TUNING); if(PathIsDirectoryW(TrackerDirectories::Instance().GetDefaultDirectory(DIR_TUNING).AsNative().c_str()) == 0) @@ -762,13 +762,13 @@ // Import old tunings mpt::PathString sOldTunings; sOldTunings = m_szExePath; - sOldTunings += mpt::PathString::FromUTF8("tunings\\"); + sOldTunings += MPT_PATHSTRING("tunings\\"); if(PathIsDirectoryW(sOldTunings.AsNative().c_str()) != 0) { mpt::PathString sSearchPattern; sSearchPattern = sOldTunings; - sSearchPattern += mpt::PathString::FromUTF8("*.*"); + sSearchPattern += MPT_PATHSTRING("*.*"); WIN32_FIND_DATAW FindFileData; HANDLE hFind; hFind = FindFirstFileW(sSearchPattern.AsNative().c_str(), &FindFileData); @@ -776,7 +776,7 @@ { do { - MoveConfigFile(mpt::PathString::FromNative(FindFileData.cFileName), mpt::PathString::FromUTF8("tunings\\")); + MoveConfigFile(mpt::PathString::FromNative(FindFileData.cFileName), MPT_PATHSTRING("tunings\\")); } while(FindNextFileW(hFind, &FindFileData) != 0); } FindClose(hFind); @@ -786,13 +786,13 @@ // Set up default file locations m_szConfigFileName = m_szConfigDirectory; // config file - m_szConfigFileName += mpt::PathString::FromUTF8("mptrack.ini"); + m_szConfigFileName += MPT_PATHSTRING("mptrack.ini"); - m_szPluginCacheFileName = m_szConfigDirectory + mpt::PathString::FromUTF8("plugin.cache"); // plugin cache + m_szPluginCacheFileName = m_szConfigDirectory + MPT_PATHSTRING("plugin.cache"); // plugin cache mpt::PathString szTemplatePath; szTemplatePath = m_szConfigDirectory; - szTemplatePath += mpt::PathString::FromUTF8("TemplateModules\\"); + szTemplatePath += MPT_PATHSTRING("TemplateModules\\"); TrackerDirectories::Instance().SetDefaultDirectory(szTemplatePath, DIR_TEMPLATE_FILES_USER); //Force use of custom ini file rather than windowsDir\executableName.ini @@ -2088,7 +2088,7 @@ 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::FromUTF8(".\\"); // ".\" + 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)) { Modified: trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp =================================================================== --- trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/mptrack/StreamEncoderMP3.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -319,11 +319,11 @@ LameDynBind() { Reset(); - if(!hLame) TryLoad(mpt::PathString::FromUTF8("libmp3lame.dll"), true); - if(!hLame) TryLoad(mpt::PathString::FromUTF8("liblame.dll"), true); - if(!hLame) TryLoad(mpt::PathString::FromUTF8("mp3lame.dll"), true); - if(!hLame) TryLoad(mpt::PathString::FromUTF8("lame.dll"), true); - if(!hLame) TryLoad(mpt::PathString::FromUTF8("lame_enc.dll"), false); + if(!hLame) TryLoad(MPT_PATHSTRING("libmp3lame.dll"), true); + if(!hLame) TryLoad(MPT_PATHSTRING("liblame.dll"), true); + if(!hLame) TryLoad(MPT_PATHSTRING("mp3lame.dll"), true); + if(!hLame) TryLoad(MPT_PATHSTRING("lame.dll"), true); + if(!hLame) TryLoad(MPT_PATHSTRING("lame_enc.dll"), false); } void TryLoad(mpt::PathString filename, bool warn) { @@ -648,12 +648,12 @@ Reset(); if(!hBlade) { - TryLoad(mpt::PathString::FromUTF8("lame_enc.dll")); + TryLoad(MPT_PATHSTRING("lame_enc.dll")); if(hBlade) lame = 1; } if(!hBlade) { - TryLoad(mpt::PathString::FromUTF8("bladeenc.dll")); + TryLoad(MPT_PATHSTRING("bladeenc.dll")); if(hBlade) lame = 0; } } Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -1618,7 +1618,7 @@ TrackerDirectories::Instance().SetWorkingDirectory(dlg.GetWorkingDirectory(), DIR_PLUGINPRESETS, true); } - bool bank = (dlg.GetExtension() == mpt::PathString::FromUTF8("fxb")); + bool bank = (dlg.GetExtension() == MPT_PATHSTRING("fxb")); mpt::fstream f(dlg.GetFirstFile().AsNative().c_str(), std::ios::out | std::ios::trunc | std::ios::binary); if(f.good() && VSTPresets::SaveFile(f, *this, bank)) Modified: trunk/OpenMPT/soundlib/Load_mo3.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mo3.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/soundlib/Load_mo3.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -49,12 +49,12 @@ // Try to load unmo3 dynamically. #ifdef _WIN32 #ifdef MODPLUG_TRACKER - HMODULE unmo3 = LoadLibraryW((theApp.GetAppDirPath() + mpt::PathString::FromUTF8("unmo3.dll")).AsNative().c_str()); + HMODULE unmo3 = LoadLibraryW((theApp.GetAppDirPath() + MPT_PATHSTRING("unmo3.dll")).AsNative().c_str()); #else - HMODULE unmo3 = LoadLibraryW(mpt::PathString::FromUTF8("unmo3.dll").AsNative().c_str()); + HMODULE unmo3 = LoadLibraryW(MPT_PATHSTRING("unmo3.dll").AsNative().c_str()); #endif // MODPLUG_TRACKER #else - void unmo3 = dlopen(mpt::PathString::FromUTF8("libunmo3.so").AsNative().c_str(), RTLD_LAZY); + void unmo3 = dlopen(MPT_PATHSTRING("libunmo3.so").AsNative().c_str(), RTLD_LAZY); #endif // _WIN32 if(unmo3 == nullptr) Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -2287,11 +2287,11 @@ } #ifdef MODPLUG_TRACKER - if(!mp3lib) mp3lib = LoadLibraryW((theApp.GetAppDirPath() + mpt::PathString::FromUTF8("libmpg123-0.dll")).AsNative().c_str()); - if(!mp3lib) mp3lib = LoadLibraryW((theApp.GetAppDirPath() + mpt::PathString::FromUTF8("libmpg123.dll")).AsNative().c_str()); + if(!mp3lib) mp3lib = LoadLibraryW((theApp.GetAppDirPath() + MPT_PATHSTRING("libmpg123-0.dll")).AsNative().c_str()); + if(!mp3lib) mp3lib = LoadLibraryW((theApp.GetAppDirPath() + MPT_PATHSTRING("libmpg123.dll")).AsNative().c_str()); #else - if(!mp3lib) mp3lib = LoadLibraryW(mpt::PathString::FromUTF8("libmpg123-0.dll").AsNative().c_str()); - if(!mp3lib) mp3lib = LoadLibraryW(mpt::PathString::FromUTF8("libmpg123.dll").AsNative().c_str()); + if(!mp3lib) mp3lib = LoadLibraryW(MPT_PATHSTRING("libmpg123-0.dll").AsNative().c_str()); + if(!mp3lib) mp3lib = LoadLibraryW(MPT_PATHSTRING("libmpg123.dll").AsNative().c_str()); #endif // MODPLUG_TRACKER if(!mp3lib) return false; Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -1725,7 +1725,7 @@ // Load local tunings. s_pTuningsSharedLocal->SetSavefilePath( TrackerDirectories::Instance().GetDefaultDirectory(DIR_TUNING) - + mpt::PathString::FromUTF8("local_tunings") + + MPT_PATHSTRING("local_tunings") + mpt::PathString::FromUTF8(CTuningCollection::s_FileExtension) ); s_pTuningsSharedLocal->Deserialize(); Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-09 13:44:41 UTC (rev 3146) +++ trunk/OpenMPT/test/test.cpp 2013-11-09 14:03:07 UTC (rev 3147) @@ -1386,7 +1386,7 @@ break; } } - theFile += mpt::PathString::FromUTF8("test/test."); + theFile += MPT_PATHSTRING("test/test."); return theFile; } @@ -1438,7 +1438,7 @@ static mpt::PathString GetTestFilenameBase() { - return mpt::PathString::FromUTF8("../test/test."); + return MPT_PATHSTRING("../test/test."); } typedef std::shared_ptr<CSoundFile> TSoundFileContainer; @@ -1497,13 +1497,13 @@ // Test MPTM file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("mptm")); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + MPT_PATHSTRING("mptm")); TestLoadMPTMFile(GetrSoundFile(sndFileContainer)); #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveIT(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.mptm")); + SaveIT(sndFileContainer, filenameBase + MPT_PATHSTRING("saved.mptm")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1512,7 +1512,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.mptm")); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + MPT_PATHSTRING("saved.mptm")); TestLoadMPTMFile(GetrSoundFile(sndFileContainer)); @@ -1522,7 +1522,7 @@ // Test XM file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("xm")); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + MPT_PATHSTRING("xm")); TestLoadXMFile(GetrSoundFile(sndFileContainer)); @@ -1536,7 +1536,7 @@ #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveXM(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.xm")); + SaveXM(sndFileContainer, filenameBase + MPT_PATHSTRING("saved.xm")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1545,7 +1545,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.xm")); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + MPT_PATHSTRING("saved.xm")); TestLoadXMFile(GetrSoundFile(sndFileContainer)); @@ -1555,13 +1555,13 @@ // Test S3M file loading { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("s3m")); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + MPT_PATHSTRING("s3m")); TestLoadS3MFile(GetrSoundFile(sndFileContainer), false); #ifndef MODPLUG_NO_FILESAVE // Test file saving - SaveS3M(sndFileContainer, filenameBase + mpt::PathString::FromUTF8("saved.s3m")); + SaveS3M(sndFileContainer, filenameBase + MPT_PATHSTRING("saved.s3m")); #endif DestroySoundFileContainer(sndFileContainer); @@ -1570,7 +1570,7 @@ // Reload the saved file and test if everything is still working correctly. #ifndef MODPLUG_NO_FILESAVE { - TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + mpt::PathString::FromUTF8("saved.s3m")); + TSoundFileContainer sndFileContainer = CreateSoundFileContainer(filenameBase + MPT_PATHSTRING("saved.s3m")); TestLoadS3MFile(GetrSoundFile(sndFileContainer), true); @@ -1583,7 +1583,7 @@ void RunITCompressionTest(const std::vector<int8> &sampleData, ChannelFlags smpFormat, bool it215, int testcount) //--------------------------------------------------------------------------------------------------------------- { - mpt::PathString filename = GetTestFilenameBase() + mpt::PathString::FromUTF8("itcomp" + Stringify(testcount) + ".raw"); + mpt::PathString filename = GetTestFilenameBase() + MPT_PATHSTRING("itcomp" + Stringify(testcount) + ".raw"); ModSample smp; smp.uFlags = smpFormat; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-09 15:35:19
|
Revision: 3151 http://sourceforge.net/p/modplug/code/3151 Author: manxorist Date: 2013-11-09 15:35:10 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Ref] Add case-insensitive comparison function to mpt::PathString (windows only). [Ref] Convert CDlsBank to mpt::PathString. [Ref] Related cleanups and conversions. Modified Paths: -------------- trunk/OpenMPT/common/mptString.h trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/View_ins.cpp trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/soundlib/Dlsbank.cpp trunk/OpenMPT/soundlib/Dlsbank.h Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/common/mptString.h 2013-11-09 15:35:10 UTC (rev 3151) @@ -245,6 +245,13 @@ return path; } +#if defined(WIN32) + static int CompareNoCase(const PathString & a, const PathString & b) + { + return lstrcmpiW(a.ToWide().c_str(), b.ToWide().c_str()); + } +#endif + public: #if defined(MODPLUG_TRACKER) Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -1857,7 +1857,7 @@ const FileDialog::PathList &files = dlg.GetFilenames(); for(size_t counter = 0; counter < files.size(); counter++) { - CTrackApp::AddDLSBank(files[counter].ToLocale().c_str()); + CTrackApp::AddDLSBank(files[counter]); } m_wndTree.RefreshDlsBanks(); EndWaitCursor(); @@ -1876,7 +1876,7 @@ if(!dlg.Show()) return; BeginWaitCursor(); - CTrackApp::ImportMidiConfig(dlg.GetFirstFile().ToLocale().c_str()); + CTrackApp::ImportMidiConfig(dlg.GetFirstFile()); m_wndTree.RefreshMidiLibrary(); EndWaitCursor(); } @@ -2527,7 +2527,7 @@ for(size_t i = 0; i < 2; i++) // 0: app items, 1: user items { // To avoid duplicates, check whether app path and config path are the same. - if (i == 1 && _tcsicmp(CTrackApp::GetAppDirPath().ToCString(), theApp.GetConfigPath().ToCString()) == 0) + if (i == 1 && mpt::PathString::CompareNoCase(CTrackApp::GetAppDirPath(), theApp.GetConfigPath()) == 0) break; CFileFind fileFind; CFixedStringT<CString, MAX_PATH> sPath; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -250,10 +250,10 @@ CDLSBank *pCachedBank = NULL, *pEmbeddedBank = NULL; CHAR szCachedBankFile[_MAX_PATH] = ""; - if (CDLSBank::IsDLSBank(lpszPathName)) + if (CDLSBank::IsDLSBank(mpt::PathString::FromCString(lpszPathName))) { pEmbeddedBank = new CDLSBank(); - pEmbeddedBank->Open(lpszPathName); + pEmbeddedBank->Open(mpt::PathString::FromCString(lpszPathName)); } m_SndFile.ChangeModTypeTo(MOD_TYPE_IT); BeginWaitCursor(); @@ -300,7 +300,7 @@ if ((pszMidiMapName) && (pszMidiMapName[0]) && (!bEmbedded)) { // Load From DLS Bank - if (CDLSBank::IsDLSBank(pszMidiMapName)) + if (CDLSBank::IsDLSBank(mpt::PathString::FromLocale(pszMidiMapName))) { CDLSBank *pDLSBank = NULL; @@ -312,7 +312,7 @@ if (pCachedBank) delete pCachedBank; pCachedBank = new CDLSBank; strcpy(szCachedBankFile, pszMidiMapName); - if (pCachedBank->Open(pszMidiMapName)) pDLSBank = pCachedBank; + if (pCachedBank->Open(mpt::PathString::FromLocale(pszMidiMapName))) pDLSBank = pCachedBank; } if (pDLSBank) { Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -304,10 +304,10 @@ LPMIDILIBSTRUCT CTrackApp::glpMidiLibrary = NULL; -BOOL CTrackApp::ImportMidiConfig(LPCSTR lpszConfigFile, BOOL bNoWarn) -//------------------------------------------------------------------- +BOOL CTrackApp::ImportMidiConfig(const mpt::PathString &filename, BOOL bNoWarn) +//----------------------------------------------------------------------------- { - if ((!lpszConfigFile) || (!lpszConfigFile[0])) return FALSE; + if(filename.empty()) return FALSE; if (!glpMidiLibrary) { @@ -316,7 +316,7 @@ MemsetZero(*glpMidiLibrary); } - if (CDLSBank::IsDLSBank(lpszConfigFile)) + if (CDLSBank::IsDLSBank(filename)) { ConfirmAnswer result = cnfYes; if (!bNoWarn) @@ -328,7 +328,7 @@ if (result == cnfCancel) return FALSE; const bool bReplaceAll = (result == cnfNo); CDLSBank dlsbank; - if (dlsbank.Open(lpszConfigFile)) + if (dlsbank.Open(filename)) { for (UINT iIns=0; iIns<256; iIns++) { @@ -343,7 +343,7 @@ { if ((glpMidiLibrary->MidiMap[iIns] = new CHAR[_MAX_PATH]) == NULL) break; } - strcpy(glpMidiLibrary->MidiMap[iIns], lpszConfigFile); + strcpy(glpMidiLibrary->MidiMap[iIns], filename.ToLocale().c_str()); } } } @@ -351,7 +351,7 @@ return TRUE; } - IniFileSettingsContainer file(mpt::PathString::FromLocale(lpszConfigFile)); + IniFileSettingsContainer file(filename); return ImportMidiConfig(file); } @@ -414,11 +414,11 @@ } -BOOL CTrackApp::ExportMidiConfig(LPCSTR lpszConfigFile) -//----------------------------------------------------- +BOOL CTrackApp::ExportMidiConfig(const mpt::PathString &filename) +//--------------------------------------------------------------- { - if ((!glpMidiLibrary) || (!lpszConfigFile) || (!lpszConfigFile[0])) return FALSE; - IniFileSettingsContainer file(mpt::PathString::FromLocale(lpszConfigFile)); + if((!glpMidiLibrary) || filename.empty()) return FALSE; + IniFileSettingsContainer file(filename); return ExportMidiConfig(file); } @@ -458,8 +458,7 @@ BOOL CTrackApp::LoadDefaultDLSBanks() //----------------------------------- { - CHAR szFileName[MAX_PATH]; - HKEY key; + mpt::PathString filename; CString storedVersion = theApp.GetSettings().Read<CString>("Version", "Version", ""); //If version number stored in INI is 1.17.02.40 or later, load DLS from INI file. @@ -471,10 +470,9 @@ for(size_t i = 0; i < numBanks; i++) { wsprintf(s, _T("Bank%d"), i + 1); - TCHAR szPath[_MAX_PATH]; - mpt::String::Copy(szPath, theApp.GetSettings().Read<std::string>("DLS Banks", s, "")); - theApp.RelativePathToAbsolute(szPath); - AddDLSBank(szPath); + mpt::PathString path = theApp.GetSettings().Read<mpt::PathString>("DLS Banks", s, mpt::PathString()); + path = theApp.RelativePathToAbsolute(path); + AddDLSBank(path); } } else { @@ -483,29 +481,35 @@ SaveDefaultDLSBanks(); // This will avoid a crash the next time if we crash while loading the bank - szFileName[0] = 0; - GetSystemDirectory(szFileName, CountOf(szFileName)); - lstrcat(szFileName, "\\GM.DLS"); - if (!AddDLSBank(szFileName)) + WCHAR szFileNameW[MAX_PATH]; + szFileNameW[0] = 0; + GetSystemDirectoryW(szFileNameW, CountOf(szFileNameW)); + filename = mpt::PathString::FromNative(szFileNameW); + filename += MPT_PATHSTRING("\\GM.DLS"); + if(!AddDLSBank(filename)) { - GetWindowsDirectory(szFileName, CountOf(szFileName)); - lstrcat(szFileName, "\\SYSTEM32\\DRIVERS\\GM.DLS"); - if (!AddDLSBank(szFileName)) + szFileNameW[0] = 0; + GetWindowsDirectoryW(szFileNameW, CountOf(szFileNameW)); + filename = mpt::PathString::FromNative(szFileNameW); + filename += MPT_PATHSTRING("\\SYSTEM32\\DRIVERS\\GM.DLS"); + if(!AddDLSBank(filename)) { + HKEY key; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectMusic", 0, KEY_READ, &key) == ERROR_SUCCESS) { + CHAR szFileName[MAX_PATH]; DWORD dwRegType = REG_SZ; DWORD dwSize = sizeof(szFileName); szFileName[0] = 0; if (RegQueryValueEx(key, "GMFilePath", NULL, &dwRegType, (LPBYTE)&szFileName, &dwSize) == ERROR_SUCCESS) { - AddDLSBank(szFileName); + AddDLSBank(mpt::PathString::FromLocale(szFileName)); } RegCloseKey(key); } } } - if (glpMidiLibrary) ImportMidiConfig(szFileName, TRUE); + if(glpMidiLibrary) ImportMidiConfig(filename, TRUE); return TRUE; } @@ -531,7 +535,7 @@ dwRegType = REG_SZ; dwSize = sizeof(szFileNameX); RegQueryValueEx(keyX, s, NULL, &dwRegType, (LPBYTE)szFileNameX, &dwSize); - AddDLSBank(szFileNameX); + AddDLSBank(mpt::PathString::FromLocale(szFileNameX)); } } RegCloseKey(keyX); @@ -543,22 +547,21 @@ //----------------------------------- { TCHAR s[64]; - TCHAR szPath[_MAX_PATH]; DWORD nBanks = 0; for(size_t i = 0; i < gpDLSBanks.size(); i++) { - if(!gpDLSBanks[i] || !gpDLSBanks[i]->GetFileName() || !gpDLSBanks[i]->GetFileName()[0]) + if(!gpDLSBanks[i] || gpDLSBanks[i]->GetFileName().empty()) continue; - _tcsncpy(szPath, gpDLSBanks[i]->GetFileName(), CountOf(szPath) - 1); + mpt::PathString path = gpDLSBanks[i]->GetFileName(); if(theApp.IsPortableMode()) { - theApp.AbsolutePathToRelative(szPath); + path = theApp.AbsolutePathToRelative(path); } wsprintf(s, _T("Bank%d"), nBanks+1); - theApp.GetSettings().Write<std::string>("DLS Banks", s, szPath); + theApp.GetSettings().Write<mpt::PathString>("DLS Banks", s, path); nBanks++; } @@ -578,17 +581,17 @@ } -BOOL CTrackApp::AddDLSBank(LPCSTR lpszFileName) -//--------------------------------------------- +BOOL CTrackApp::AddDLSBank(const mpt::PathString &filename) +//--------------------------------------------------------- { - if(!lpszFileName || !lpszFileName[0] || !CDLSBank::IsDLSBank(lpszFileName)) return FALSE; + if(filename.empty() || !CDLSBank::IsDLSBank(filename)) return FALSE; // Check for dupes for(size_t i = 0; i < gpDLSBanks.size(); i++) { - if(gpDLSBanks[i] && !lstrcmpi(lpszFileName, gpDLSBanks[i]->GetFileName())) return TRUE; + if(gpDLSBanks[i] && !mpt::PathString::CompareNoCase(filename, gpDLSBanks[i]->GetFileName())) return TRUE; } CDLSBank *bank = new CDLSBank; - if(bank->Open(lpszFileName)) + if(bank->Open(filename)) { gpDLSBanks.push_back(bank); return TRUE; Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/Mptrack.h 2013-11-09 15:35:10 UTC (rev 3151) @@ -138,15 +138,15 @@ static MODTYPE GetDefaultDocType() { return m_nDefaultDocType; } static void SetDefaultDocType(MODTYPE n) { m_nDefaultDocType = n; } static LPMIDILIBSTRUCT GetMidiLibrary() { return glpMidiLibrary; } - static BOOL ImportMidiConfig(LPCSTR lpszFileName, BOOL bNoWarning=FALSE); - static BOOL ExportMidiConfig(LPCSTR lpszFileName); + static BOOL ImportMidiConfig(const mpt::PathString &filename, BOOL bNoWarning=FALSE); + static BOOL ExportMidiConfig(const mpt::PathString &filename); static BOOL ImportMidiConfig(SettingsContainer &file); static BOOL ExportMidiConfig(SettingsContainer &file); static void RegisterExtensions(); static BOOL LoadDefaultDLSBanks(); static BOOL SaveDefaultDLSBanks(); static BOOL RemoveDLSBank(UINT nBank); - static BOOL AddDLSBank(LPCSTR); + static BOOL AddDLSBank(const mpt::PathString &filename); static bool OpenURL(const char *url); static bool OpenURL(const std::string &url); static bool OpenURL(const CString &url); Modified: trunk/OpenMPT/mptrack/View_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_ins.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/View_ins.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -2059,10 +2059,10 @@ break; case DRAGONDROP_MIDIINSTR: - if (CDLSBank::IsDLSBank((LPCSTR)lpDropInfo->lDropParam)) + if (CDLSBank::IsDLSBank(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) { CDLSBank dlsbank; - if (dlsbank.Open((LPCSTR)lpDropInfo->lDropParam)) + if (dlsbank.Open(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) { DLSINSTRUMENT *pDlsIns; UINT nIns = 0, nRgn = 0xFF; Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -2296,10 +2296,10 @@ break; case DRAGONDROP_MIDIINSTR: - if (CDLSBank::IsDLSBank((LPCSTR)lpDropInfo->lDropParam)) + if (CDLSBank::IsDLSBank(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) { CDLSBank dlsbank; - if (dlsbank.Open((LPCSTR)lpDropInfo->lDropParam)) + if (dlsbank.Open(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) { DLSINSTRUMENT *pDlsIns; UINT nIns = 0, nRgn = 0xFF; Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -503,7 +503,7 @@ TV_SORTCB tvs; CDLSBank *pDlsBank = CTrackApp::gpDLSBanks[iDls]; // Add DLS file folder - _splitpath(pDlsBank->GetFileName(), NULL, NULL, szName, szExt); + _splitpath(pDlsBank->GetFileName().ToLocale().c_str(), NULL, NULL, szName, szExt); strcat(szName, szExt); m_tiDLS[iDls] = InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, szName, IMAGE_FOLDER, IMAGE_FOLDER, 0, 0, iDls, TVI_ROOT, hDlsRoot); @@ -3155,7 +3155,7 @@ "All Files (*.*)|*.*||"); if(!dlg.Show()) return; - CTrackApp::ExportMidiConfig(dlg.GetFirstFile().ToLocale().c_str()); + CTrackApp::ExportMidiConfig(dlg.GetFirstFile()); } Modified: trunk/OpenMPT/soundlib/Dlsbank.cpp =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-11-09 15:35:10 UTC (rev 3151) @@ -500,13 +500,13 @@ } -BOOL CDLSBank::IsDLSBank(const char *lpszFileName) -//------------------------------------------------ +BOOL CDLSBank::IsDLSBank(const mpt::PathString &filename) +//------------------------------------------------------- { RIFFCHUNKID riff; FILE *f; - if ((!lpszFileName) || (!lpszFileName[0])) return FALSE; - if ((f = fopen(lpszFileName, "rb")) == NULL) return FALSE; + if(filename.empty()) return FALSE; + if((f = mpt_fopen(filename, "rb")) == NULL) return FALSE; MemsetZero(riff); fread(&riff, sizeof(RIFFCHUNKID), 1, f); // Check for embedded DLS sections @@ -1138,8 +1138,8 @@ /////////////////////////////////////////////////////////////// // Open: opens a DLS bank -BOOL CDLSBank::Open(const char *lpszFileName) -//------------------------------------------- +BOOL CDLSBank::Open(const mpt::PathString &filename) +//-------------------------------------------------- { SF2LOADERINFO sf2info; const BYTE *lpMemFile; // Pointer to memory-mapped file @@ -1147,12 +1147,12 @@ DWORD dwMemPos, dwMemLength; UINT nInsDef; - if ((!lpszFileName) || (!lpszFileName[0])) return FALSE; - strcpy(m_szFileName, lpszFileName); + if(filename.empty()) return FALSE; + m_szFileName = filename; lpMemFile = NULL; // Memory-Mapped file CMappedFile MapFile; - if (!MapFile.Open(lpszFileName)) return FALSE; + if (!MapFile.Open(filename.ToLocale().c_str())) return FALSE; dwMemLength = MapFile.GetLength(); if (dwMemLength >= 256) lpMemFile = (const BYTE *)MapFile.Lock(); if (!lpMemFile) @@ -1450,7 +1450,7 @@ return FALSE; } dwOffset = m_pWaveForms[nWaveLink] + m_dwWavePoolOffset; - if ((f = fopen(m_szFileName, "rb")) == NULL) return FALSE; + if((f = mpt_fopen(m_szFileName, "rb")) == NULL) return FALSE; if (fseek(f, dwOffset, SEEK_SET) == 0) { if (m_nType & SOUNDBANK_TYPE_SF2) Modified: trunk/OpenMPT/soundlib/Dlsbank.h =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.h 2013-11-09 14:37:36 UTC (rev 3150) +++ trunk/OpenMPT/soundlib/Dlsbank.h 2013-11-09 15:35:10 UTC (rev 3151) @@ -115,7 +115,7 @@ { protected: SOUNDBANKINFO m_BankInfo; - CHAR m_szFileName[_MAX_PATH]; + mpt::PathString m_szFileName; UINT m_nType; DWORD m_dwWavePoolOffset; // DLS Information @@ -129,13 +129,13 @@ CDLSBank(); virtual ~CDLSBank(); void Destroy(); - static BOOL IsDLSBank(const char *lpszFileName); + static BOOL IsDLSBank(const mpt::PathString &filename); static DWORD MakeMelodicCode(UINT bank, UINT instr) { return ((bank << 16) | (instr));} static DWORD MakeDrumCode(UINT rgn, UINT instr) { return (0x80000000 | (rgn << 16) | (instr));} public: - BOOL Open(const char *lpszFileName); - const char *GetFileName() const { return m_szFileName; } + BOOL Open(const mpt::PathString &filename); + mpt::PathString GetFileName() const { return m_szFileName; } UINT GetBankType() const { return m_nType; } UINT GetBankInfo(SOUNDBANKINFO *pBankInfo=NULL) const { if (pBankInfo) *pBankInfo = m_BankInfo; return m_nType; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-09 18:05:10
|
Revision: 3152 http://sourceforge.net/p/modplug/code/3152 Author: manxorist Date: 2013-11-09 18:05:00 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Ref] Rework CMappedFile to be based on CreateFileW instead of CFile so that unicode paths work. [Ref] Avoid using CFile for file i/o and replace it with mpt_fopen or mpt::ifstream. [Ref] Make CMappedFile take a mpt::PathString instead of const char*. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/MemoryMappedFile.cpp trunk/OpenMPT/mptrack/MemoryMappedFile.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/TuningDialog.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/mod2midi.cpp trunk/OpenMPT/soundlib/Dlsbank.cpp trunk/OpenMPT/soundlib/Load_itp.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -1399,7 +1399,7 @@ BOOL bFirst, bOk; BeginWaitCursor(); - if ((!lpszFileName) || (!f.Open(lpszFileName))) + if ((!lpszFileName) || (!f.Open(mpt::PathString::FromLocale(lpszFileName)))) { EndWaitCursor(); return FALSE; Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -738,7 +738,7 @@ { CMappedFile f; BeginWaitCursor(); - if ((!lpszFileName) || (!f.Open(lpszFileName))) + if ((!lpszFileName) || (!f.Open(mpt::PathString::FromLocale(lpszFileName)))) { EndWaitCursor(); return false; Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -1426,7 +1426,7 @@ { CMappedFile f; - if(f.Open(lpszFileName)) + if(f.Open(mpt::PathString::FromLocale(lpszFileName))) { FileReader file = f.GetFile(); if(file.IsValid()) Modified: trunk/OpenMPT/mptrack/MemoryMappedFile.cpp =================================================================== --- trunk/OpenMPT/mptrack/MemoryMappedFile.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/MemoryMappedFile.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -19,10 +19,23 @@ } -bool CMappedFile::Open(const char * lpszFileName) -//----------------------------------------------- +bool CMappedFile::Open(const mpt::PathString &filename) +//----------------------------------------------------- { - return m_File.Open(lpszFileName, CFile::modeRead | CFile::typeBinary | CFile::shareDenyWrite) != FALSE; + m_hFile = CreateFileW( + filename.AsNative().c_str(), + GENERIC_READ, + FILE_SHARE_READ, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); + if(m_hFile == INVALID_HANDLE_VALUE) + { + m_hFile = nullptr; + return false; + } + return true; } @@ -30,14 +43,23 @@ //----------------------- { if(m_pData) Unlock(); - m_File.Close(); + if(m_hFile) + { + CloseHandle(m_hFile); + m_hFile = nullptr; + } } size_t CMappedFile::GetLength() //----------------------------- { - return mpt::saturate_cast<size_t>(m_File.GetLength()); + LARGE_INTEGER size; + if(GetFileSizeEx(m_hFile, &size) == FALSE) + { + return 0; + } + return mpt::saturate_cast<size_t>(size.QuadPart); } @@ -50,7 +72,7 @@ void *lpStream; HANDLE hmf = CreateFileMapping( - m_File.m_hFile, + m_hFile, NULL, PAGE_READONLY, 0, 0, @@ -76,7 +98,22 @@ // Fallback if memory-mapping fails for some weird reason if((lpStream = malloc(length)) == nullptr) return nullptr; - m_File.Read(lpStream, length); + memset(lpStream, 0, length); + size_t bytesToRead = length; + size_t bytesRead = 0; + while(bytesToRead > 0) + { + DWORD chunkToRead = mpt::saturate_cast<DWORD>(length); + DWORD chunkRead = 0; + if(ReadFile(m_hFile, (char*)lpStream + bytesRead, chunkToRead, &chunkRead, NULL) == FALSE) + { + // error + free(lpStream); + return nullptr; + } + bytesRead += chunkRead; + bytesToRead -= chunkRead; + } m_pData = lpStream; return lpStream; } @@ -106,4 +143,4 @@ free(m_pData); m_pData = nullptr; } -} \ No newline at end of file +} Modified: trunk/OpenMPT/mptrack/MemoryMappedFile.h =================================================================== --- trunk/OpenMPT/mptrack/MemoryMappedFile.h 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/MemoryMappedFile.h 2013-11-09 18:05:00 UTC (rev 3152) @@ -20,16 +20,16 @@ //=============== { protected: - CFile m_File; + HANDLE m_hFile; HANDLE m_hFMap; void *m_pData; public: - CMappedFile() : m_hFMap(nullptr), m_pData(nullptr) { } + CMappedFile() : m_hFile(nullptr), m_hFMap(nullptr), m_pData(nullptr) { } ~CMappedFile(); public: - bool Open(const char *lpszFileName); + bool Open(const mpt::PathString &filename); void Close(); size_t GetLength(); const void *Lock(); Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -224,7 +224,7 @@ #else { CMappedFile f; - if (f.Open(lpszPathName)) + if (f.Open(mpt::PathString::FromCString(lpszPathName))) { FileReader file = f.GetFile(); if(file.IsValid()) @@ -341,7 +341,7 @@ CHAR szName[_MAX_FNAME], szExt[_MAX_EXT]; CMappedFile f; - if(f.Open(pszMidiMapName)) + if(f.Open(mpt::PathString::FromLocale(pszMidiMapName))) { FileReader file = f.GetFile(); if(file.IsValid()) Modified: trunk/OpenMPT/mptrack/TuningDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/TuningDialog.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/TuningDialog.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -1484,17 +1484,11 @@ CTuningDialog::EnSclImport CTuningDialog::ImportScl(LPCTSTR pszPath, LPCTSTR pszName) //----------------------------------------------------------------------------------- { - CFile file; - if (file.Open(pszPath, CFile::modeRead) == 0) + mpt::ifstream iStrm(pszPath, std::ios::in | std::ios::binary); + if(!iStrm) + { return enSclImportFailUnableToOpenFile; - - size_t nSize = static_cast<size_t>(file.GetLength()); - - std::vector<char> data(nSize + 1, 0); - nSize = file.Read(&data[0], nSize); - file.Close(); - - std::istringstream iStrm(std::string(&data[0], nSize)); + } return ImportScl(iStrm, pszName); } Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -267,7 +267,7 @@ CMappedFile f; SetCurrentDirectory(m_szInstrLibPath); - if (f.Open(pszSongName)) + if (f.Open(mpt::PathString::FromLocale(pszSongName))) { FileReader file = f.GetFile(); if (file.IsValid()) Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -1660,7 +1660,7 @@ CMappedFile f; const char *errorStr = nullptr; - if(f.Open(dlg.GetFirstFile().ToCString())) + if(f.Open(dlg.GetFirstFile())) { FileReader file = f.GetFile(); errorStr = VSTPresets::GetErrorMessage(VSTPresets::LoadFile(file, *this)); Modified: trunk/OpenMPT/mptrack/mod2midi.cpp =================================================================== --- trunk/OpenMPT/mptrack/mod2midi.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/mptrack/mod2midi.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -371,9 +371,10 @@ CHAR s[256]; UINT nTickMultiplier, nClock, nOrder, nRow; UINT nSpeed; - CFile f; + FILE *f = nullptr; - if (!f.Open(m_szFileName, CFile::modeCreate | CFile::modeWrite)) + f = mpt_fopen(mpt::PathString::FromLocale(m_szFileName), "wb"); + if(!f) { return FALSE; } @@ -392,8 +393,8 @@ mthd.wTrks = static_cast<uint16>(Tracks.size()); // 1 track/channel mthd.wTrks = BigEndianW(mthd.wTrks); //Convert to big endian value. mthd.wDivision = BigEndianW(wPPQN); - if (m_bRmi) f.Write(&rmid, sizeof(rmid)); - f.Write(&mthd, sizeof(mthd)); + if (m_bRmi) fwrite(&rmid, 1, sizeof(rmid), f); + fwrite(&mthd, 1, sizeof(mthd), f); // Add Song Name on track 0 const std::string modTitle = m_pSndFile->GetTitle(); @@ -566,11 +567,11 @@ Tracks[iTrk].Write(tmp, 4); mtrk.id = 0x6B72544D; mtrk.len = BigEndian(Tracks[iTrk].nTrackSize); - f.Write(&mtrk, sizeof(mtrk)); + fwrite(&mtrk, 1, sizeof(mtrk), f); rmid.filelen += sizeof(mtrk) + Tracks[iTrk].nTrackSize; if (Tracks[iTrk].nTrackSize > 0) { - f.Write(Tracks[iTrk].pTrackData, Tracks[iTrk].nTrackSize); + fwrite(Tracks[iTrk].pTrackData, 1, Tracks[iTrk].nTrackSize, f); delete[] Tracks[iTrk].pTrackData; } } @@ -578,10 +579,10 @@ if (m_bRmi) { // Update header file size - f.SeekToBegin(); - f.Write(&rmid, sizeof(rmid)); + fseek(f, 0, SEEK_SET); + fwrite(&rmid, 1, sizeof(rmid), f); } - f.Close(); + fclose(f); return TRUE; } Modified: trunk/OpenMPT/soundlib/Dlsbank.cpp =================================================================== --- trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/soundlib/Dlsbank.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -1152,7 +1152,7 @@ lpMemFile = NULL; // Memory-Mapped file CMappedFile MapFile; - if (!MapFile.Open(filename.ToLocale().c_str())) return FALSE; + if (!MapFile.Open(filename)) return FALSE; dwMemLength = MapFile.GetLength(); if (dwMemLength >= 256) lpMemFile = (const BYTE *)MapFile.Lock(); if (!lpMemFile) Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-09 15:35:10 UTC (rev 3151) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-09 18:05:00 UTC (rev 3152) @@ -223,7 +223,7 @@ CMappedFile f; for(INSTRUMENTINDEX ins = 0; ins < GetNumInstruments(); ins++) { - if(m_szInstrumentPath[ins].empty() || !f.Open(m_szInstrumentPath[ins].c_str())) continue; + if(m_szInstrumentPath[ins].empty() || !f.Open(mpt::PathString::FromLocale(m_szInstrumentPath[ins]))) continue; FileReader file = f.GetFile(); if(file.IsValid()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-09 18:18:11
|
Revision: 3153 http://sourceforge.net/p/modplug/code/3153 Author: manxorist Date: 2013-11-09 18:18:04 +0000 (Sat, 09 Nov 2013) Log Message: ----------- [Ref] Silence some warnings in test.cpp. [Ref] SanitizeFilename works totally fine on standard non-path strings, un-deprecate it. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-09 18:05:00 UTC (rev 3152) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-09 18:18:04 UTC (rev 3153) @@ -339,7 +339,7 @@ } void SanitizeFilename(mpt::PathString &filename) -//----------------------------------------------- +//---------------------------------------------- { mpt::RawPathString tmp = filename.AsNative(); for(mpt::RawPathString::iterator it = tmp.begin(); it != tmp.end(); ++it) Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-09 18:05:00 UTC (rev 3152) +++ trunk/OpenMPT/common/mptString.h 2013-11-09 18:18:04 UTC (rev 3153) @@ -319,23 +319,23 @@ // Sanitize a filename (remove special chars) void SanitizeFilename(mpt::PathString &filename); -MPT_DEPRECATED_PATH void SanitizeFilename(char *beg, char *end); -MPT_DEPRECATED_PATH void SanitizeFilename(wchar_t *beg, wchar_t *end); +void SanitizeFilename(char *beg, char *end); +void SanitizeFilename(wchar_t *beg, wchar_t *end); -MPT_DEPRECATED_PATH void SanitizeFilename(std::string &str); -MPT_DEPRECATED_PATH void SanitizeFilename(std::wstring &str); +void SanitizeFilename(std::string &str); +void SanitizeFilename(std::wstring &str); template <std::size_t size> -MPT_DEPRECATED_PATH void SanitizeFilename(char (&buffer)[size]) -//------------------------------------------------------------- +void SanitizeFilename(char (&buffer)[size]) +//----------------------------------------- { STATIC_ASSERT(size > 0); SanitizeFilename(buffer, buffer + size); } template <std::size_t size> -MPT_DEPRECATED_PATH void SanitizeFilename(wchar_t (&buffer)[size]) -//---------------------------------------------------------------- +void SanitizeFilename(wchar_t (&buffer)[size]) +//-------------------------------------------- { STATIC_ASSERT(size > 0); SanitizeFilename(buffer, buffer + size); Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-09 18:05:00 UTC (rev 3152) +++ trunk/OpenMPT/test/test.cpp 2013-11-09 18:18:04 UTC (rev 3153) @@ -586,16 +586,16 @@ // Path conversions #ifdef MODPLUG_TRACKER const mpt::PathString realExePath = theApp.GetAppDirPath(); - const CString exePath = "C:\\OpenMPT\\"; - theApp.SetAppDirPath(mpt::PathString::FromCString(exePath)); - VERIFY_EQUAL(theApp.AbsolutePathToRelative("C:\\OpenMPT\\"), ".\\"); - VERIFY_EQUAL(theApp.AbsolutePathToRelative("c:\\OpenMPT\\foo"), ".\\foo"); - VERIFY_EQUAL(theApp.AbsolutePathToRelative("C:\\foo"), "\\foo"); - VERIFY_EQUAL(theApp.RelativePathToAbsolute(".\\"), "C:\\OpenMPT\\"); - VERIFY_EQUAL(theApp.RelativePathToAbsolute(".\\foo"), "C:\\OpenMPT\\foo"); - VERIFY_EQUAL(theApp.RelativePathToAbsolute("\\foo"), "C:\\foo"); - VERIFY_EQUAL(theApp.AbsolutePathToRelative("\\\\server\\path\\file"), "\\\\server\\path\\file"); - VERIFY_EQUAL(theApp.RelativePathToAbsolute("\\\\server\\path\\file"), "\\\\server\\path\\file"); + 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); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-10 00:16:09
|
Revision: 3159 http://sourceforge.net/p/modplug/code/3159 Author: manxorist Date: 2013-11-10 00:15:58 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Do not use std::stringstream for simple string concatenation. Modified Paths: -------------- trunk/OpenMPT/common/version.cpp trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/Moddoc.cpp Modified: trunk/OpenMPT/common/version.cpp =================================================================== --- trunk/OpenMPT/common/version.cpp 2013-11-09 23:33:29 UTC (rev 3158) +++ trunk/OpenMPT/common/version.cpp 2013-11-10 00:15:58 UTC (rev 3159) @@ -10,7 +10,7 @@ #include "stdafx.h" #include "version.h" -#include <sstream> +#include "misc_util.h" #include <cstdlib> @@ -219,21 +219,21 @@ std::string GetRevisionString() { + std::string str; if(GetRevision() == 0) { - return ""; + return str; } - std::ostringstream str; - str << "-r" << GetRevision(); + str = std::string("-r") + Stringify(GetRevision()); if(HasMixedRevisions()) { - str << "!"; + str += "!"; } if(IsDirty()) { - str << "+"; + str += "+"; } - return str.str(); + return str; } std::string GetVersionStringExtended() @@ -263,9 +263,7 @@ { url = url.substr(baseurl.length()); } - std::ostringstream str; - str << url << "@" << GetRevision() << GetStateString(); - return str.str(); + return url + "@" + Stringify(GetRevision()) + GetStateString(); } std::string GetContactString() Modified: trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp 2013-11-09 23:33:29 UTC (rev 3158) +++ trunk/OpenMPT/libopenmpt/libopenmpt_c.cpp 2013-11-10 00:15:58 UTC (rev 3159) @@ -15,7 +15,6 @@ #include "libopenmpt_impl.hpp" #include <limits> -#include <sstream> #include <stdexcept> #include <cmath> @@ -109,25 +108,25 @@ }; // class logfunc_logger static std::string format_exception( const char * const function ) { - std::ostringstream err; + std::string err; try { throw; } catch ( openmpt::exception & e ) { - err - << function << ": " - << "ERROR: " - << e.what(); + err += function; + err += ": "; + err += "ERROR: "; + err += e.what(); } catch ( std::exception & e ) { - err - << function << ": " - << "INTERNAL ERROR: " - << e.what(); + err += function; + err += ": "; + err += "INTERNAL ERROR: "; + err += e.what(); } catch ( ... ) { - err - << function << ": " - << "UNKOWN INTERNAL ERROR"; + err += function; + err += ": "; + err += "UNKOWN INTERNAL ERROR"; } - return err.str(); + return err; } static void report_exception( const char * const function, openmpt_log_func const logfunc = 0, void * const user = 0, openmpt::module_impl * const impl = 0 ) { Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-09 23:33:29 UTC (rev 3158) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-10 00:15:58 UTC (rev 3159) @@ -17,7 +17,6 @@ #include <algorithm> #include <iostream> #include <iterator> -#include <sstream> #include <cmath> #include <cstdlib> @@ -41,19 +40,25 @@ } static std::string get_library_version_string() { - std::ostringstream str; + std::string str; std::uint32_t version = get_library_version(); if ( ( version & 0xffff ) == 0 ) { - str << ((version>>24) & 0xff) << "." << ((version>>16) & 0xff); + str += Stringify((version>>24) & 0xff); + str += "."; + str += Stringify((version>>16) & 0xff); } else { - str << ((version>>24) & 0xff) << "." << ((version>>16) & 0xff) << "." << ((version>>0) & 0xffff); + str += Stringify((version>>24) & 0xff); + str += "."; + str += Stringify((version>>16) & 0xff); + str += "."; + str += Stringify((version>>0) & 0xffff); } if ( MptVersion::IsDirty() ) { - str << ".2-modified"; + str += ".2-modified"; } else if ( MptVersion::HasMixedRevisions() ) { - str << ".1-modified"; + str += ".1-modified"; } - return str.str(); + return str; } static std::string get_core_version_string() { @@ -629,45 +634,47 @@ } else if ( key == std::string("message") ) { std::string retval = m_sndFile->songMessage.GetFormatted( SongMessage::leLF ); if ( retval.empty() ) { - std::ostringstream tmp; + std::string tmp; bool valid = false; for ( INSTRUMENTINDEX i = 1; i <= m_sndFile->GetNumInstruments(); ++i ) { std::string instname = m_sndFile->GetInstrumentName( i ); if ( !instname.empty() ) { valid = true; } - tmp << instname << std::endl; + tmp += instname; + tmp += "\n"; } if ( valid ) { - retval = tmp.str(); + retval = tmp; } } if ( retval.empty() ) { - std::ostringstream tmp; + std::string tmp; bool valid = false; for ( SAMPLEINDEX i = 1; i <= m_sndFile->GetNumSamples(); ++i ) { std::string samplename = m_sndFile->GetSampleName( i ); if ( !samplename.empty() ) { valid = true; } - tmp << samplename << std::endl; + tmp += samplename; + tmp += "\n"; } if ( valid ) { - retval = tmp.str(); + retval = tmp; } } return mod_string_to_utf8( retval ); } else if ( key == std::string("warnings") ) { - std::ostringstream retval; + std::string retval; bool first = true; for ( std::vector<std::string>::const_iterator i = m_loaderMessages.begin(); i != m_loaderMessages.end(); ++i ) { if ( !first ) { - retval << std::endl; + retval += "\n"; first = false; } - retval << *i; + retval += *i; } - return retval.str(); + return retval; } return ""; } Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-09 23:33:29 UTC (rev 3158) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-10 00:15:58 UTC (rev 3159) @@ -236,12 +236,11 @@ #endif EndWaitCursor(); - std::ostringstream str; - str - << "File: " << lpszPathName << std::endl - << "Last saved with: " << m_SndFile.madeWithTracker << ", you are using OpenMPT " << MptVersion::str << std::endl - << std::endl; - logcapturer.ShowLog(str.str()); + logcapturer.ShowLog(std::string() + + "File: " + lpszPathName + "\n" + + "Last saved with: " + m_SndFile.madeWithTracker + ", you are using OpenMPT " + MptVersion::str + "\n" + + "\n" + ); if ((m_SndFile.m_nType == MOD_TYPE_NONE) || (!m_SndFile.GetNumChannels())) return FALSE; // Midi Import @@ -858,12 +857,13 @@ std::string CModDoc::GetLogString() const //--------------------------------------- { - std::ostringstream ret; + std::string ret; for(std::vector<LogEntry>::const_iterator i=m_Log.begin(); i!=m_Log.end(); ++i) { - ret << (*i).message << "\r\n";//std::endl; + ret += (*i).message; + ret += "\r\n"; } - return ret.str(); + return ret; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-10 00:28:08
|
Revision: 3160 http://sourceforge.net/p/modplug/code/3160 Author: saga-games Date: 2013-11-10 00:27:57 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Update VST plugin paths to mpt::PathString. Loading plugins and presets from unicode paths works perfectly now. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.h trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/soundlib/plugins/JBridge.cpp trunk/OpenMPT/soundlib/plugins/JBridge.h Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -326,6 +326,12 @@ 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; Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/common/mptString.h 2013-11-10 00:27:57 UTC (rev 3160) @@ -259,9 +259,24 @@ void SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const; PathString GetDrive() const; PathString GetDir() const; + PathString GetPath() const; PathString GetFileName() const; PathString GetFileExt() const; + bool HasTrailingSlash() const + { + if(empty()) + return false; +#if defined(WIN32) + if(path.back() == L'\\' || path.back() == L'/') + return true; +#else + if(path.back() == '/') + return true; +#endif + return false; + } + #endif // MODPLUG_TRACKER public: Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -81,7 +81,7 @@ CVstPluginManager *pPluginManager = theApp.GetPluginManager(); if (pPluginManager) { - pPluginManager->AddPlugin(path); + pPluginManager->AddPlugin(mpt::PathString::FromCString(path)); return NULL; } } @@ -1943,8 +1943,6 @@ BOOL CTrackApp::InitializeDXPlugins() //----------------------------------- { - TCHAR s[_MAX_PATH], tmp[32]; - m_pPluginManager = new CVstPluginManager; if(!m_pPluginManager) return FALSE; const size_t numPlugins = theApp.GetSettings().Read<int32>("VST Plugins", "NumPlugins", 0); @@ -1968,26 +1966,26 @@ CString nonFoundPlugs; - const CString failedPlugin = theApp.GetSettings().Read<CString>("VST Plugins", "FailedPlugin", ""); + const mpt::PathString failedPlugin = theApp.GetSettings().Read<mpt::PathString>("VST Plugins", "FailedPlugin", MPT_PATHSTRING("")); for(size_t plug = 0; plug < numPlugins; plug++) { - s[0] = 0; + char tmp[32]; wsprintf(tmp, "Plugin%d", plug); - mpt::String::Copy(s, theApp.GetSettings().Read<std::string>("VST Plugins", tmp, "")); - if (s[0]) + mpt::PathString plugPath = theApp.GetSettings().Read<mpt::PathString>("VST Plugins", tmp, MPT_PATHSTRING("")); + if(!plugPath.empty()) { - RelativePathToAbsolute(s); + RelativePathToAbsolute(plugPath); - if(!failedPlugin.Compare(s)) + if(plugPath == failedPlugin) { - const CString text = "The following plugin has previously crashed OpenMPT during initialisation:\n\n" + failedPlugin + "\n\nDo you still want to load it?"; + const CString text = "The following plugin has previously crashed OpenMPT during initialisation:\n\n" + failedPlugin.ToCString() + "\n\nDo you still want to load it?"; if(Reporting::Confirm(text, false, true) == cnfNo) { continue; } } - m_pPluginManager->AddPlugin(s, true, true, &nonFoundPlugs); + m_pPluginManager->AddPlugin(plugPath, true, true, &nonFoundPlugs); } } if(nonFoundPlugs.GetLength() > 0) @@ -2005,23 +2003,22 @@ if(!m_pPluginManager) return FALSE; #ifndef NO_VST - TCHAR s[_MAX_PATH], tmp[32]; VSTPluginLib *pPlug; pPlug = m_pPluginManager->GetFirstPlugin(); size_t plug = 0; while(pPlug) { - if(pPlug->dwPluginId1 != kDmoMagic) + if(pPlug->pluginId1 != kDmoMagic) { - s[0] = 0; + char tmp[32]; wsprintf(tmp, "Plugin%d", plug); - strcpy(s, pPlug->szDllPath); + mpt::PathString plugPath = pPlug->dllPath; if(theApp.IsPortableMode()) { - AbsolutePathToRelative(s); + AbsolutePathToRelative(plugPath); } - theApp.GetSettings().Write<std::string>("VST Plugins", tmp, s); + theApp.GetSettings().Write<mpt::PathString>("VST Plugins", tmp, plugPath); plug++; } pPlug = pPlug->pNext; Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -138,8 +138,8 @@ // Initialize plugin info MemsetZero(m_pPlugin->Info); - m_pPlugin->Info.dwPluginId1 = pFactory->dwPluginId1; - m_pPlugin->Info.dwPluginId2 = pFactory->dwPluginId2; + m_pPlugin->Info.dwPluginId1 = pFactory->pluginId1; + m_pPlugin->Info.dwPluginId2 = pFactory->pluginId2; switch(m_pPlugin->Info.dwPluginId2) { @@ -149,8 +149,9 @@ break; } - mpt::String::Copy(m_pPlugin->Info.szName, pFactory->szLibraryName); - mpt::String::Copy(m_pPlugin->Info.szLibraryName, pFactory->szLibraryName); + const std::string libraryName = pFactory->libraryName.ToLocale(); + mpt::String::Copy(m_pPlugin->Info.szName, libraryName); + mpt::String::Copy(m_pPlugin->Info.szLibraryName, libraryName); cs.Leave(); @@ -165,7 +166,6 @@ s[0] = 0; if ((p->GetDefaultEffectName(s)) && (s[0])) { - s[31] = 0; mpt::String::Copy(m_pPlugin->Info.szName, s); } } @@ -291,7 +291,7 @@ if(nameFilterActive) { // Apply name filter - CString displayName = p->szLibraryName; + CString displayName = p->libraryName.ToCString(); if (displayName.MakeLower().Find(m_sNameFilter) == -1) { p = p->pNext; @@ -299,7 +299,7 @@ } } - HTREEITEM h = AddTreeItem(p->szLibraryName, p->isInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, categoryFolders[p->category], reinterpret_cast<LPARAM>(p)); + HTREEITEM h = AddTreeItem(p->libraryName.ToCString(), p->isInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, categoryFolders[p->category], reinterpret_cast<LPARAM>(p)); categoryUsed[p->category] = true; if(nameFilterActive) @@ -317,7 +317,7 @@ { //Which plugin should be selected? - if(forceSelect != 0 && p->dwPluginId2 == forceSelect) + if(forceSelect != 0 && p->pluginId2 == forceSelect) { //forced selection (e.g. just after add plugin) currentPlug = h; @@ -332,12 +332,12 @@ } else if(m_pPlugin->Info.dwPluginId1 != 0 || m_pPlugin->Info.dwPluginId2 != 0) { //Plugin with matching ID to current slot's plug - if(p->dwPluginId1 == m_pPlugin->Info.dwPluginId1 - && p->dwPluginId2 == m_pPlugin->Info.dwPluginId2) + if(p->pluginId1 == m_pPlugin->Info.dwPluginId1 + && p->pluginId2 == m_pPlugin->Info.dwPluginId2) { currentPlug = h; } - } else if(p->dwPluginId2 == TrackerSettings::Instance().gnPlugWindowLast) + } else if(p->pluginId2 == TrackerSettings::Instance().gnPlugWindowLast) { // Previously selected plugin currentPlug = h; @@ -375,9 +375,18 @@ } -HTREEITEM CSelectPluginDlg::AddTreeItem(const char *title, int image, bool sort, HTREEITEM hParent, LPARAM lParam) -//---------------------------------------------------------------------------------------------------------------- +HTREEITEM CSelectPluginDlg::AddTreeItem(const TCHAR *title, int image, bool sort, HTREEITEM hParent, LPARAM lParam) +//----------------------------------------------------------------------------------------------------------------- { + /*TVINSERTSTRUCTW tvi; + MemsetZero(tvi); + tvi.hInsertAfter = (sort ? TVI_SORT : TVI_FIRST); + tvi.hParent = hParent; + tvi.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT; + tvi.item.iImage = tvi.item.iSelectedImage = image; + tvi.item.pszText = title; + tvi.item.lParam = lParam; + return (HTREEITEM)::SendMessage(m_treePlugins.m_hWnd, TVM_INSERTITEMW, 0, (LPARAM)&tvi);*/ return m_treePlugins.InsertItem( TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT, title, @@ -410,7 +419,7 @@ VSTPluginLib *pPlug = (VSTPluginLib *)m_treePlugins.GetItemData(m_treePlugins.GetSelectedItem()); if ((pManager) && (pManager->IsValidPlugin(pPlug))) { - SetDlgItemText(IDC_TEXT_CURRENT_VSTPLUG, pPlug->szDllPath); + SetDlgItemTextW(m_hWnd, IDC_TEXT_CURRENT_VSTPLUG, pPlug->dllPath.ToWide().c_str()); } else { SetDlgItemText(IDC_TEXT_CURRENT_VSTPLUG, ""); @@ -439,7 +448,7 @@ for(size_t p = 0; p < CountOf(problemPlugs); p++) { - if(problemPlugs[p].id2 == plug->dwPluginId2 /*&& gProblemPlugs[p].id1 == plug->dwPluginId1*/) + if(problemPlugs[p].id2 == plug->pluginId2 /*&& gProblemPlugs[p].id1 == plug->dwPluginId1*/) { CString s; s.Format("WARNING: This plugin has been identified as %s,\nwhich is known to have the following problem with OpenMPT:\n\n%s\n\nWould you still like to add this plugin to the library?", problemPlugs[p].name, problemPlugs[p].problem); @@ -470,12 +479,9 @@ const FileDialog::PathList &files = dlg.GetFilenames(); for(size_t counter = 0; counter < files.size(); counter++) { - - CString sFilename = files[counter].ToCString(); - if (pManager) { - plugLib = pManager->AddPlugin(sFilename, false); + plugLib = pManager->AddPlugin(files[counter], false); if (plugLib) { bOk = true; @@ -489,7 +495,7 @@ if (bOk) { // Force selection to last added plug. - UpdatePluginsList(plugLib ? plugLib->dwPluginId2 : 0); + UpdatePluginsList(plugLib ? plugLib->pluginId2 : 0); } else { Reporting::Error("At least one selected file was not a valid VST Plugin."); Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.h =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.h 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.h 2013-11-10 00:27:57 UTC (rev 3160) @@ -26,7 +26,7 @@ CTreeCtrl m_treePlugins; CString m_sNameFilter; - HTREEITEM AddTreeItem(const char *title, int image, bool sort, HTREEITEM hParent = TVI_ROOT, LPARAM lParam = NULL); + HTREEITEM AddTreeItem(const TCHAR *title, int image, bool sort, HTREEITEM hParent = TVI_ROOT, LPARAM lParam = NULL); public: CSelectPluginDlg(CModDoc *pModDoc, int nPlugSlot, CWnd *parent); Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -128,9 +128,7 @@ //-------------------------------------------- { HKEY hkEnum; - CHAR keyname[128]; - CHAR s[256]; - WCHAR w[100]; + WCHAR keyname[128]; LONG cr; DWORD index; @@ -138,36 +136,31 @@ index = 0; while (cr == ERROR_SUCCESS) { - if ((cr = RegEnumKey(hkEnum, index, (LPTSTR)keyname, sizeof(keyname))) == ERROR_SUCCESS) + if ((cr = RegEnumKeyW(hkEnum, index, keyname, CountOf(keyname))) == ERROR_SUCCESS) { CLSID clsid; - - wsprintf(s, "{%s}", keyname); - MultiByteToWideChar(CP_ACP, 0, (LPCSTR)s,-1,(LPWSTR)w,98); - if (CLSIDFromString(w, &clsid) == S_OK) + std::wstring formattedKey = std::wstring(L"{") + std::wstring(keyname) + std::wstring(L"}"); + if(CLSIDFromString(formattedKey.c_str(), &clsid) == S_OK) { HKEY hksub; - - wsprintf(s, "software\\classes\\DirectShow\\MediaObjects\\%s", keyname); - if (RegOpenKey(HKEY_LOCAL_MACHINE, s, &hksub) == ERROR_SUCCESS) + formattedKey = std::wstring(L"software\\classes\\DirectShow\\MediaObjects\\") + std::wstring(keyname); + if (RegOpenKeyW(HKEY_LOCAL_MACHINE, formattedKey.c_str(), &hksub) == ERROR_SUCCESS) { + WCHAR name[64]; DWORD datatype = REG_SZ; - DWORD datasize = 64; + DWORD datasize = sizeof(name); - if (ERROR_SUCCESS == RegQueryValueEx(hksub, nullptr, 0, &datatype, (LPBYTE)s, &datasize)) + if(ERROR_SUCCESS == RegQueryValueExW(hksub, nullptr, 0, &datatype, (LPBYTE)name, &datasize)) { - VSTPluginLib *p = new VSTPluginLib(); + StringFromGUID2(clsid, keyname, 100); + + VSTPluginLib *p = new VSTPluginLib(mpt::PathString::FromWide(keyname), mpt::PathString::FromWide(name)); p->pNext = m_pVstHead; - p->dwPluginId1 = kDmoMagic; - p->dwPluginId2 = clsid.Data1; + p->pluginId1 = kDmoMagic; + p->pluginId2 = clsid.Data1; p->category = VSTPluginLib::catDMO; - mpt::String::Copy(p->szLibraryName, s); - - StringFromGUID2(clsid, w, 100); - WideCharToMultiByte(CP_ACP, 0, w, -1, p->szDllPath, sizeof(p->szDllPath), nullptr, nullptr); - mpt::String::SetNullTerminator(p->szDllPath); #ifdef DMO_LOG - Log("Found \"%s\" clsid=%s\n", p->szLibraryName, p->szDllPath); + Log("Found \"%s\" clsid=%s\n", p->libraryName.AsNative().c_str(), p->dllPath.AsNative().c_str()); #endif if (m_pVstHead) m_pVstHead->pPrev = p; m_pVstHead = p; @@ -182,15 +175,15 @@ } -void CVstPluginManager::LoadPlugin(const char *pluginPath, AEffect *&effect, HINSTANCE &library) -//---------------------------------------------------------------------------------------------- +void CVstPluginManager::LoadPlugin(const mpt::PathString &pluginPath, AEffect *&effect, HINSTANCE &library) +//--------------------------------------------------------------------------------------------------------- { library = nullptr; effect = nullptr; try { - library = LoadLibrary(pluginPath); + library = LoadLibraryW(pluginPath.ToWide().c_str()); if(library == nullptr) { @@ -213,7 +206,7 @@ } } catch(...) { - CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pluginPath); + CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pluginPath.ToLocale().c_str()); } if(library != nullptr && library != INVALID_HANDLE_VALUE) @@ -269,52 +262,47 @@ // ID100000ID200000 = FullDllPath // ID100000ID200000.Flags = Plugin Flags (isInstrument + category). -VSTPluginLib *CVstPluginManager::AddPlugin(LPCSTR pszDllPath, bool fromCache, const bool checkFileExistence, CString *const errStr) -//--------------------------------------------------------------------------------------------------------------------------------- +VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, CString *const errStr) +//---------------------------------------------------------------------------------------------------------------------------------------------- { - TCHAR szPath[_MAX_PATH]; - - if(checkFileExistence && (PathFileExists(pszDllPath) == FALSE)) + const mpt::PathString fileName = dllPath.GetFileName(); + + if(checkFileExistence && (PathFileExistsW(dllPath.AsNative().c_str()) == FALSE)) { if(errStr) { *errStr += "\nUnable to find "; - *errStr += pszDllPath; + *errStr += dllPath.ToCString(); } } VSTPluginLib *pDup = m_pVstHead; while(pDup != nullptr) { - if (!lstrcmpi(pszDllPath, pDup->szDllPath)) return pDup; + if(!dllPath.CompareNoCase(dllPath, pDup->dllPath)) return pDup; pDup = pDup->pNext; } // Look if the plugin info is stored in the PluginCache if(fromCache) { - const std::string cacheSection = "PluginCache"; + const char *cacheSection = "PluginCache"; SettingsContainer & cacheFile = theApp.GetPluginCache(); - char fileName[_MAX_PATH]; - _splitpath(pszDllPath, nullptr, nullptr, fileName, nullptr); - std::string IDs = cacheFile.Read<std::string>(cacheSection, fileName, ""); + std::string IDs = cacheFile.Read<std::string>(cacheSection, fileName.ToLocale(), ""); - if (IDs.length() >= 16) + if(IDs.length() >= 16) { // Get path from cache file - mpt::String::Copy(szPath, cacheFile.Read<std::string>(cacheSection, IDs, "")); - mpt::String::SetNullTerminator(szPath); - theApp.RelativePathToAbsolute(szPath); + mpt::PathString realPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING("")); + realPath = theApp.RelativePathToAbsolute(realPath); - if ((szPath[0]) && (!lstrcmpi(szPath, pszDllPath))) + if(!realPath.empty() && !dllPath.CompareNoCase(realPath, dllPath)) { - VSTPluginLib *p = new (std::nothrow) VSTPluginLib(pszDllPath); + VSTPluginLib *p = new (std::nothrow) VSTPluginLib(dllPath, fileName); if(p == nullptr) { return nullptr; } - _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); - p->szLibraryName[63] = '\0'; p->pNext = m_pVstHead; if (m_pVstHead) m_pVstHead->pPrev = p; m_pVstHead = p; @@ -327,10 +315,10 @@ n &= 0x0f; if (i < 8) { - p->dwPluginId1 = (p->dwPluginId1 << 4) | n; + p->pluginId1 = (p->pluginId1 << 4) | n; } else { - p->dwPluginId2 = (p->dwPluginId2 << 4) | n; + p->pluginId2 = (p->pluginId2 << 4) | n; } } @@ -338,43 +326,41 @@ p->DecodeCacheFlags(cacheFile.Read<int32>(cacheSection, flagKey, 0)); #ifdef VST_USE_ALTERNATIVE_MAGIC - if( p->dwPluginId1 == kEffectMagic ) + if( p->pluginId1 == kEffectMagic ) { - p->dwPluginId1 = CalculateCRC32fromFilename(p->szLibraryName); // Make Plugin ID unique for sure (for VSTs with same UID) + p->pluginId1 = CalculateCRC32fromFilename(p->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->szLibraryName); + Log("Plugin \"%s\" found in PluginCache\n", p->libraryName); #endif // VST_LOG return p; } else { #ifdef VST_LOG - Log("Plugin \"%s\" mismatch in PluginCache: \"%s\" [%s]=\"%s\"\n", s, pszDllPath, (LPCTSTR)IDs, (LPCTSTR)strFullPath); + Log("Plugin \"%s\" mismatch in PluginCache: \"%s\" [%s]=\"%s\"\n", s, dllPath, (LPCTSTR)IDs, (LPCTSTR)strFullPath); #endif // VST_LOG } } } // If this key contains a file name on program launch, a plugin previously crashed OpenMPT. - theApp.GetSettings().Write<std::string>("VST Plugins", "FailedPlugin", pszDllPath); + theApp.GetSettings().Write<mpt::PathString>("VST Plugins", "FailedPlugin", dllPath); AEffect *pEffect; HINSTANCE hLib; bool validPlug = false; - VSTPluginLib *p = new (std::nothrow) VSTPluginLib(pszDllPath); + VSTPluginLib *p = new (std::nothrow) VSTPluginLib(dllPath, fileName); if(p == nullptr) { return nullptr; } - _splitpath(pszDllPath, nullptr, nullptr, p->szLibraryName, nullptr); - p->szLibraryName[63] = 0; p->pNext = m_pVstHead; try { - LoadPlugin(pszDllPath, pEffect, hLib); + LoadPlugin(dllPath, pEffect, hLib); if(pEffect != nullptr && pEffect->magic == kEffectMagic && pEffect->dispatcher != nullptr) { @@ -384,11 +370,11 @@ m_pVstHead = p; #ifdef VST_USE_ALTERNATIVE_MAGIC - p->dwPluginId1 = CalculateCRC32fromFilename(p->szLibraryName); // Make Plugin ID unique for sure + p->pluginId1 = CalculateCRC32fromFilename(p->libraryName); // Make Plugin ID unique for sure #else - p->dwPluginId1 = pEffect->magic; + p->pluginId1 = pEffect->magic; #endif // VST_USE_ALTERNATIVE_MAGIC - p->dwPluginId2 = pEffect->uniqueID; + p->pluginId2 = pEffect->uniqueID; GetPluginInformation(pEffect, *p); @@ -396,7 +382,7 @@ 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->szLibraryName, nver, + p->libraryName, nver, pEffect->numInputs, pEffect->numOutputs, pEffect->numPrograms, pEffect->numParams, pEffect->flags, pEffect->realQualities, pEffect->offQualities); @@ -410,7 +396,7 @@ FreeLibrary(hLib); } catch(...) { - CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->szLibraryName); + CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->libraryName); } // Now it should be safe to assume that this plugin loaded properly. :) @@ -421,19 +407,18 @@ { const std::string cacheSection = "PluginCache"; SettingsContainer & cacheFile = theApp.GetPluginCache(); - std::string IDs = mpt::String::Format("%08X%08X", p->dwPluginId1, p->dwPluginId2); + std::string IDs = mpt::String::Format("%08X%08X", p->pluginId1, p->pluginId2); std::string flagsKey = mpt::String::Format("%s.Flags", IDs); - _tcsncpy(szPath, pszDllPath, CountOf(szPath) - 1); + mpt::PathString writePath = dllPath; if(theApp.IsPortableMode()) { - theApp.AbsolutePathToRelative(szPath); + theApp.AbsolutePathToRelative(writePath); } - mpt::String::SetNullTerminator(szPath); - cacheFile.Write<std::string>(cacheSection, IDs, szPath); - cacheFile.Write<CString>(cacheSection, IDs, pszDllPath); - cacheFile.Write<std::string>(cacheSection, p->szLibraryName, IDs); + 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<int32>(cacheSection, flagsKey, p->EncodeCacheFlags()); } else { @@ -469,7 +454,7 @@ delete p; } catch (...) { - CVstPluginManager::ReportPlugException("Exception while trying to release plugin \"%s\"!\n", pFactory->szLibraryName); + CVstPluginManager::ReportPlugException("Exception while trying to release plugin \"%s\"!\n", pFactory->libraryName); } return true; @@ -488,29 +473,29 @@ VSTPluginLib *p = m_pVstHead; - while (p) + while(p) { bool b1 = false, b2 = false; - if ((p->dwPluginId1 == mixPlugin.Info.dwPluginId1) - && (p->dwPluginId2 == mixPlugin.Info.dwPluginId2)) + if((p->pluginId1 == mixPlugin.Info.dwPluginId1) + && (p->pluginId2 == mixPlugin.Info.dwPluginId2)) { b1 = true; } - if (!mpt::strnicmp(p->szLibraryName, mixPlugin.GetLibraryName(), 64)) + if(!mpt::strnicmp(p->libraryName.ToLocale().c_str(), mixPlugin.GetLibraryName(), 64)) { b2 = true; } - if ((b1) && (b2)) + if((b1) && (b2)) { nMatch = 3; pFound = p; } else - if ((b1) && (nMatch < 2)) + if((b1) && (nMatch < 2)) { nMatch = 2; pFound = p; } else - if ((b2) && (nMatch < 1)) + if((b2) && (nMatch < 1)) { nMatch = 1; pFound = p; @@ -518,7 +503,7 @@ p = p->pNext; } - if (mixPlugin.Info.dwPluginId1 == kDmoMagic) + if(mixPlugin.Info.dwPluginId1 == kDmoMagic) { if (!pFound) return FALSE; AEffect *pEffect = DmoToVst(pFound); @@ -534,35 +519,31 @@ } } - if ((!pFound) && strcmp(mixPlugin.GetLibraryName(), "")) + if((!pFound) && strcmp(mixPlugin.GetLibraryName(), "")) { // Try finding the plugin DLL in the plugin directory instead. - CHAR s[_MAX_PATH]; - mpt::String::Copy(s, TrackerDirectories::Instance().GetDefaultDirectory(DIR_PLUGINS).ToLocale()); - if(!s[0]) + mpt::PathString fullPath; + fullPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_PLUGINS); + if(fullPath.empty()) { - mpt::String::CopyN(s, theApp.GetAppDirPath().ToLocale().c_str()); + fullPath = theApp.GetAppDirPath() + MPT_PATHSTRING("Plugins\\"); } - size_t len = strlen(s); - if((len > 0) && (s[len - 1] != '\\') && (s[len - 1] != '/')) + if(!fullPath.HasTrailingSlash()) { - strcat(s, "\\"); + fullPath += MPT_PATHSTRING("\\"); } - strncat(s, mixPlugin.GetLibraryName(), CountOf(s)); - strncat(s, ".dll", CountOf(s)); + fullPath += mpt::PathString::FromLocale(mixPlugin.GetLibraryName()) + MPT_PATHSTRING(".dll"); - mpt::String::SetNullTerminator(s); - - pFound = AddPlugin(s); - if (!pFound) + pFound = AddPlugin(fullPath); + if(!pFound) { std::string cacheSection = "PluginCache"; SettingsContainer & cacheFile = theApp.GetPluginCache(); std::string IDs = cacheFile.Read<std::string>(cacheSection, mixPlugin.GetLibraryName(), ""); if (IDs.length() >= 16) { - CString strFullPath = cacheFile.Read<CString>(cacheSection, IDs, ""); - if ((strFullPath) && (strFullPath[0])) pFound = AddPlugin(strFullPath); + fullPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING("")); + if(!fullPath.empty()) pFound = AddPlugin(fullPath); } } } @@ -576,7 +557,7 @@ try { - LoadPlugin(pFound->szDllPath, pEffect, hLibrary); + LoadPlugin(pFound->dllPath, pEffect, hLibrary); if(pEffect != nullptr && pEffect->dispatcher != nullptr && pEffect->magic == kEffectMagic) { @@ -592,7 +573,7 @@ // Update cached information const std::string cacheSection = "PluginCache"; SettingsContainer & cacheFile = theApp.GetPluginCache(); - std::string flagsKey = mpt::String::Format("%08X%08X.Flags", pFound->dwPluginId1, pFound->dwPluginId2); + std::string flagsKey = mpt::String::Format("%08X%08X.Flags", pFound->pluginId1, pFound->pluginId2); cacheFile.Write<int32>(cacheSection, flagsKey, pFound->EncodeCacheFlags()); } @@ -609,7 +590,7 @@ } } catch(...) { - CVstPluginManager::ReportPlugException("Exception while trying to create plugin \"%s\"!\n", pFound->szLibraryName); + CVstPluginManager::ReportPlugException("Exception while trying to create plugin \"%s\"!\n", pFound->libraryName); } return validPlugin; @@ -1396,7 +1377,7 @@ #ifdef VST_LOG Log("%s: vst ver %d.0, flags=%04X, %d programs, %d parameters\n", - m_Factory.szLibraryName, (m_bIsVst2) ? 2 : 1, m_Effect.flags, + m_Factory.libraryName, (m_bIsVst2) ? 2 : 1, m_Effect.flags, m_Effect.numPrograms, m_Effect.numParams); #endif @@ -1592,12 +1573,11 @@ bool CVstPlugin::SaveProgram() //---------------------------- { - std::string defaultDir = TrackerDirectories::Instance().GetWorkingDirectory(DIR_PLUGINPRESETS).ToLocale(); + mpt::PathString defaultDir = TrackerDirectories::Instance().GetWorkingDirectory(DIR_PLUGINPRESETS); bool useDefaultDir = !defaultDir.empty(); if(!useDefaultDir) { - defaultDir = m_Factory.szDllPath; - defaultDir = defaultDir.substr(0, defaultDir.find_last_of("\\/")); + defaultDir = m_Factory.dllPath.GetPath(); } char rawname[MAX(kVstMaxProgNameLen + 1, 256)] = ""; // kVstMaxProgNameLen is 24... @@ -1610,7 +1590,7 @@ .DefaultFilename(rawname) .ExtensionFilter("VST Plugin Programs (*.fxp)|*.fxp|" "VST Plugin Banks (*.fxb)|*.fxb||") - .WorkingDirectory(mpt::PathString::FromLocale(defaultDir)); + .WorkingDirectory(defaultDir); if(!dlg.Show()) return false; if(useDefaultDir) @@ -1636,12 +1616,11 @@ bool CVstPlugin::LoadProgram() //---------------------------- { - std::string defaultDir = TrackerDirectories::Instance().GetWorkingDirectory(DIR_PLUGINPRESETS).ToLocale(); + mpt::PathString defaultDir = TrackerDirectories::Instance().GetWorkingDirectory(DIR_PLUGINPRESETS); bool useDefaultDir = !defaultDir.empty(); if(!useDefaultDir) { - defaultDir = m_Factory.szDllPath; - defaultDir = defaultDir.substr(0, defaultDir.find_last_of("\\/")); + defaultDir = m_Factory.dllPath.GetPath(); } FileDialog dlg = OpenFileDialog() @@ -1650,7 +1629,7 @@ "VST Plugin Programs (*.fxp)|*.fxp|" "VST Plugin Banks (*.fxb)|*.fxb|" "All Files|*.*||") - .WorkingDirectory(mpt::PathString::FromLocale(defaultDir)); + .WorkingDirectory(defaultDir); if(!dlg.Show()) return false; if(useDefaultDir) @@ -1694,13 +1673,13 @@ if(m_Effect.dispatcher != nullptr) { #ifdef VST_LOG - Log("About to Dispatch(%d) (Plugin=\"%s\"), index: %d, value: %d, value: %h, value: %f!\n", opCode, m_Factory.szLibraryName, index, value, ptr, opt); + Log("About to Dispatch(%d) (Plugin=\"%s\"), index: %d, value: %d, value: %h, value: %f!\n", opCode, m_Factory.libraryName, index, value, ptr, opt); #endif result = m_Effect.dispatcher(&m_Effect, opCode, index, value, ptr, opt); } } catch (...) { - CVstPluginManager::ReportPlugException("Exception in Dispatch(%d) (Plugin=\"%s\")!\n", opCode, m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in Dispatch(%d) (Plugin=\"%s\")!\n", opCode, m_Factory.libraryName); } return result; @@ -1819,7 +1798,7 @@ } } catch (...) { - CVstPluginManager::ReportPlugException("Exception in SetParameter(%d, 0.%03d) (Plugin=%s)\n", nIndex, (int)(fValue*1000), m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in SetParameter(%d, 0.%03d) (Plugin=%s)\n", nIndex, (int)(fValue*1000), m_Factory.libraryName); } } @@ -1923,7 +1902,7 @@ m_bPlugResumed = true; } catch (...) { - CVstPluginManager::ReportPlugException("Exception in Resume() (Plugin=%s)\n", m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in Resume() (Plugin=%s)\n", m_Factory.libraryName); } } @@ -1940,7 +1919,7 @@ m_bPlugResumed = false; } catch (...) { - CVstPluginManager::ReportPlugException("Exception in Suspend() (Plugin=%s)\n", m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in Suspend() (Plugin=%s)\n", m_Factory.libraryName); } } } @@ -1959,7 +1938,7 @@ } catch (...) { CVstPluginManager::ReportPlugException("Exception in ProcessVSTEvents() (Plugin=%s, numEvents:%d)\n", - m_Factory.szLibraryName, vstEvents.GetNumEvents()); + m_Factory.libraryName, vstEvents.GetNumEvents()); } } } @@ -2801,7 +2780,7 @@ } } catch (...) { - CVstPluginManager::ReportPlugException("Exception in ToggleEditor() (Plugin=%s)\n", m_Factory.szLibraryName); + CVstPluginManager::ReportPlugException("Exception in ToggleEditor() (Plugin=%s)\n", m_Factory.libraryName); } } @@ -3471,12 +3450,9 @@ AEffect *DmoToVst(VSTPluginLib *pLib) //----------------------------------- { - WCHAR w[100]; CLSID clsid; - MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pLib->szDllPath, -1, (LPWSTR)w, CountOf(w)); - w[99] = 0; - if (CLSIDFromString(w, &clsid) == S_OK) + if (CLSIDFromString(pLib->dllPath.ToWide().c_str(), &clsid) == S_OK) { IMediaObject *pMO = nullptr; IMediaObjectInPlace *pMOIP = nullptr; @@ -3496,11 +3472,11 @@ return (p) ? p->GetEffect() : nullptr; } #ifdef DMO_LOG - Log("%s: Unable to use this DMO\n", pLib->szLibraryName); + Log("%s: Unable to use this DMO\n", pLib->libraryName); #endif } #ifdef DMO_LOG - else Log("%s: Failed to get IMediaObject & IMediaObjectInPlace interfaces\n", pLib->szLibraryName); + else Log("%s: Failed to get IMediaObject & IMediaObjectInPlace interfaces\n", pLib->libraryName); #endif if (pMO) pMO->Release(); if (pMOIP) pMOIP->Release(); Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/mptrack/Vstplug.h 2013-11-10 00:27:57 UTC (rev 3160) @@ -62,24 +62,20 @@ VSTPluginLib *pPrev, *pNext; CVstPlugin *pPluginsList; - VstInt32 dwPluginId1; - VstInt32 dwPluginId2; + mpt::PathString libraryName; // Display name + mpt::PathString dllPath; // Full path name + VstInt32 pluginId1; + VstInt32 pluginId2; PluginCategory category; bool isInstrument; - CHAR szLibraryName[_MAX_FNAME]; - CHAR szDllPath[_MAX_PATH]; - VSTPluginLib(const CHAR *dllPath = nullptr) + VSTPluginLib(const mpt::PathString &dllPath, const mpt::PathString &libraryName) + : pPrev(nullptr), pNext(nullptr), pPluginsList(nullptr), + libraryName(libraryName), dllPath(dllPath), + pluginId1(0), pluginId2(0), + category(catUnknown), + isInstrument(false) { - pPrev = pNext = nullptr; - dwPluginId1 = dwPluginId2 = 0; - isInstrument = false; - pPluginsList = nullptr; - category = catUnknown; - if(dllPath != nullptr) - { - mpt::String::CopyN(szDllPath, dllPath); - } } uint32 EncodeCacheFlags() @@ -336,7 +332,7 @@ public: VSTPluginLib *GetFirstPlugin() const { return m_pVstHead; } bool IsValidPlugin(const VSTPluginLib *pLib); - VSTPluginLib *AddPlugin(LPCSTR pszDllPath, bool fromCache = true, const bool checkFileExistence = false, CString* const errStr = 0); + VSTPluginLib *AddPlugin(const mpt::PathString &dllPath, bool fromCache = true, const bool checkFileExistence = false, CString* const errStr = 0); bool RemovePlugin(VSTPluginLib *); bool CreateMixPlugin(SNDMIXPLUGIN &, CSoundFile &); void OnIdle(); @@ -344,7 +340,7 @@ protected: void EnumerateDirectXDMOs(); - void LoadPlugin(const char *pluginPath, AEffect *&effect, HINSTANCE &library); + void LoadPlugin(const mpt::PathString &pluginPath, AEffect *&effect, HINSTANCE &library); protected: VstIntPtr VstCallback(AEffect *effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void *ptr, float opt); @@ -360,7 +356,7 @@ #else // NO_VST public: - VSTPluginLib *AddPlugin(LPCSTR, bool = true, const bool = false, CString* const = 0) {return 0;} + VSTPluginLib *AddPlugin(const mpt::PathString &, bool = true, const bool = false, CString* const = 0) {return 0;} VSTPluginLib *GetFirstPlugin() const { return 0; } void OnIdle() {} #endif // NO_VST Modified: trunk/OpenMPT/soundlib/plugins/JBridge.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/JBridge.cpp 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/soundlib/plugins/JBridge.cpp 2013-11-10 00:27:57 UTC (rev 3160) @@ -36,12 +36,12 @@ //Check if it's a plugin_name.xx.dll -bool IsBootStrapDll(const char *path) -//----------------------------------- +bool IsBootStrapDll(const mpt::PathString &path) +//---------------------------------------------- { bool ret = false; - HMODULE hModule = LoadLibrary(path); + HMODULE hModule = LoadLibraryW(path.ToWide().c_str()); if(!hModule) { // Some error... @@ -61,8 +61,8 @@ } -AEffect *LoadBridgedPlugin(audioMasterCallback audioMaster, const char *pluginPath) -//--------------------------------------------------------------------------------- +AEffect *LoadBridgedPlugin(audioMasterCallback audioMaster, const mpt::PathString &pluginPath) +//-------------------------------------------------------------------------------------------- { // Ignore JBridge bootstrap DLLs if(IsBootStrapDll(pluginPath)) @@ -105,7 +105,7 @@ return nullptr; } - return pfnBridgeMain(audioMaster, pluginPath); + return pfnBridgeMain(audioMaster, pluginPath.ToLocale().c_str()); } } Modified: trunk/OpenMPT/soundlib/plugins/JBridge.h =================================================================== --- trunk/OpenMPT/soundlib/plugins/JBridge.h 2013-11-10 00:15:58 UTC (rev 3159) +++ trunk/OpenMPT/soundlib/plugins/JBridge.h 2013-11-10 00:27:57 UTC (rev 3160) @@ -18,8 +18,8 @@ namespace JBridge { #ifdef ENABLE_JBRIDGE - AEffect *LoadBridgedPlugin(audioMasterCallback audioMaster, const char *pluginPath); + AEffect *LoadBridgedPlugin(audioMasterCallback audioMaster, const mpt::PathString &pluginPath); #else - inline void *LoadBridgedPlugin(void *, const char *) { return nullptr; } + inline void *LoadBridgedPlugin(void *, const mpt::PathString &) { return nullptr; } #endif // ENABLE_JBRIDGE } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-10 01:20:45
|
Revision: 3161 http://sourceforge.net/p/modplug/code/3161 Author: saga-games Date: 2013-11-10 01:20:37 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Convert complete file I/O chain in sample/instrument editor to mpt::PathString. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_ins.h trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/Ctrl_smp.h trunk/OpenMPT/soundlib/SampleFormats.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-10 00:27:57 UTC (rev 3160) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-10 01:20:37 UTC (rev 3161) @@ -1077,7 +1077,7 @@ break; case CTRLMSG_INS_OPENFILE: - if (lParam) return OpenInstrument((LPCSTR)lParam); + if (lParam) return OpenInstrument(mpt::PathString::FromCString((LPCSTR)lParam)); break; case CTRLMSG_INS_SONGDROP: @@ -1392,14 +1392,14 @@ } -BOOL CCtrlInstruments::OpenInstrument(LPCSTR lpszFileName) -//-------------------------------------------------------- +BOOL CCtrlInstruments::OpenInstrument(const mpt::PathString &fileName) +//-------------------------------------------------------------------- { CMappedFile f; BOOL bFirst, bOk; BeginWaitCursor(); - if ((!lpszFileName) || (!f.Open(mpt::PathString::FromLocale(lpszFileName)))) + if(!f.Open(fileName)) { EndWaitCursor(); return FALSE; @@ -1424,7 +1424,7 @@ m_modDoc.UpdateAllViews(NULL, HINT_SAMPLEINFO | HINT_MODTYPE, NULL); // -> CODE#0023 // -> DESC="IT project files (.itp)" - m_sndFile.m_szInstrumentPath[m_nInstrument - 1] = lpszFileName; + m_sndFile.m_szInstrumentPath[m_nInstrument - 1] = fileName.ToLocale(); SetInstrumentModified(false); // -! NEW_FEATURE#0023 bOk = TRUE; @@ -1434,21 +1434,21 @@ EndWaitCursor(); if (bOk) { + TrackerDirectories::Instance().SetWorkingDirectory(fileName, DIR_INSTRUMENTS, true); ModInstrument *pIns = m_sndFile.Instruments[m_nInstrument]; if (pIns) { - TCHAR szName[_MAX_FNAME], szExt[_MAX_EXT]; - _tsplitpath(lpszFileName, nullptr, nullptr, szName, szExt); - TrackerDirectories::Instance().SetWorkingDirectory(mpt::PathString::FromCString(lpszFileName), DIR_INSTRUMENTS, true); + mpt::PathString name, ext; + fileName.SplitPath(nullptr, nullptr, &name, &ext); if (!pIns->name[0] && m_sndFile.GetModSpecifications().instrNameLengthMax > 0) { - mpt::String::CopyN(pIns->name, szName, m_sndFile.GetModSpecifications().instrNameLengthMax); + mpt::String::CopyN(pIns->name, name.ToLocale().c_str(), m_sndFile.GetModSpecifications().instrNameLengthMax); } if (!pIns->filename[0] && m_sndFile.GetModSpecifications().instrFilenameLengthMax > 0) { - strcat(szName, szExt); - mpt::String::CopyN(pIns->filename, szName, m_sndFile.GetModSpecifications().instrFilenameLengthMax); + name += ext; + mpt::String::CopyN(pIns->filename, name.ToLocale().c_str(), m_sndFile.GetModSpecifications().instrFilenameLengthMax); } SetCurrentInstrument(m_nInstrument); @@ -1711,7 +1711,7 @@ OnInstrumentNew(); } - if(!OpenInstrument(files[counter].ToCString())) + if(!OpenInstrument(files[counter])) ErrorBox(IDS_ERR_FILEOPEN, this); } @@ -1723,7 +1723,7 @@ void CCtrlInstruments::OnInstrumentSave() //--------------------------------------- { - TCHAR szFileName[_MAX_PATH] = "", drive[_MAX_DRIVE], path[_MAX_PATH], ext[_MAX_EXT]; + TCHAR szFileName[_MAX_PATH] = ""; ModInstrument *pIns = m_sndFile.Instruments[m_nInstrument]; if (!pIns) return; @@ -1753,12 +1753,11 @@ BeginWaitCursor(); - _splitpath(dlg.GetFirstFile().ToLocale().c_str(), drive, path, NULL, ext); bool ok = false; - if (!lstrcmpi(ext, ".iti")) + if(!mpt::PathString::CompareNoCase(dlg.GetExtension(), MPT_PATHSTRING("xi"))) + ok = m_sndFile.SaveXIInstrument(m_nInstrument, dlg.GetFirstFile()); + else ok = m_sndFile.SaveITIInstrument(m_nInstrument, dlg.GetFirstFile(), index == (m_sndFile.GetType() == MOD_TYPE_XM ? 3 : 2)); - else - ok = m_sndFile.SaveXIInstrument(m_nInstrument, dlg.GetFirstFile()); // -> CODE#0023 // -> DESC="IT project files (.itp)" @@ -1769,9 +1768,6 @@ EndWaitCursor(); if (!ok) ErrorBox(IDS_ERR_SAVEINS, this); else { - strcpy(szFileName, drive); - strcat(szFileName, path); - TrackerDirectories::Instance().SetWorkingDirectory(dlg.GetWorkingDirectory(), DIR_INSTRUMENTS); // -> CODE#0023 Modified: trunk/OpenMPT/mptrack/Ctrl_ins.h =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.h 2013-11-10 00:27:57 UTC (rev 3160) +++ trunk/OpenMPT/mptrack/Ctrl_ins.h 2013-11-10 01:20:37 UTC (rev 3161) @@ -124,7 +124,7 @@ public: void SetInstrumentModified(const bool modified = true); BOOL SetCurrentInstrument(UINT nIns, BOOL bUpdNum=TRUE); - BOOL OpenInstrument(LPCSTR lpszFileName); + BOOL OpenInstrument(const mpt::PathString &fileName); BOOL OpenInstrument(CSoundFile &sndFile, INSTRUMENTINDEX nInstr); BOOL EditSample(UINT nSample); VOID UpdateFilterText(); Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-10 00:27:57 UTC (rev 3160) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-10 01:20:37 UTC (rev 3161) @@ -426,7 +426,7 @@ break; case CTRLMSG_SMP_OPENFILE: - if (lParam) return OpenSample((LPCSTR)lParam) ? TRUE : FALSE; + if (lParam) return OpenSample(mpt::PathString::FromCString((LPCSTR)lParam)) ? TRUE : FALSE; break; case CTRLMSG_SMP_SONGDROP: @@ -733,12 +733,12 @@ } -bool CCtrlSamples::OpenSample(LPCSTR lpszFileName) -//------------------------------------------------ +bool CCtrlSamples::OpenSample(const mpt::PathString &fileName) +//------------------------------------------------------------ { CMappedFile f; BeginWaitCursor(); - if ((!lpszFileName) || (!f.Open(mpt::PathString::FromLocale(lpszFileName)))) + if(!f.Open(fileName)) { EndWaitCursor(); return false; @@ -753,6 +753,7 @@ m_modDoc.GetSampleUndo().PrepareUndo(m_nSample, sundo_replace); bool bOk = m_sndFile.ReadSampleFromFile(m_nSample, file, TrackerSettings::Instance().m_MayNormalizeSamplesOnLoad); + ModSample &sample = m_sndFile.GetSample(m_nSample); if (!bOk) { @@ -769,7 +770,6 @@ rememberRawFormat = dlg.GetRemeberFormat(); BeginWaitCursor(); - ModSample &sample = m_sndFile.GetSample(m_nSample); m_sndFile.DestroySampleThreadsafe(m_nSample); sample.nLength = file.GetLength(); @@ -818,17 +818,16 @@ EndWaitCursor(); if (bOk) { - ModSample &sample = m_sndFile.GetSample(m_nSample); - TrackerDirectories::Instance().SetWorkingDirectory(mpt::PathString::FromLocale(lpszFileName), DIR_SAMPLES, true); + TrackerDirectories::Instance().SetWorkingDirectory(fileName, DIR_SAMPLES, true); if (!sample.filename[0]) { - CHAR szName[_MAX_PATH], szExt[_MAX_EXT]; - _splitpath(lpszFileName, 0, 0, szName, szExt); + mpt::PathString name, ext; + fileName.SplitPath(nullptr, nullptr, &name, &ext); - if(!m_sndFile.m_szNames[m_nSample][0]) mpt::String::Copy(m_sndFile.m_szNames[m_nSample], szName); + if(!m_sndFile.m_szNames[m_nSample][0]) mpt::String::Copy(m_sndFile.m_szNames[m_nSample], name.ToLocale()); - if (strlen(szName) < 9) strcat(szName, szExt); - mpt::String::Copy(sample.filename, szName); + if(name.AsNative().length() < 9) name += ext; + mpt::String::Copy(sample.filename, name.ToLocale()); } if ((m_sndFile.GetType() & MOD_TYPE_XM) && !sample.uFlags[CHN_PANNING]) { @@ -976,7 +975,7 @@ OnSampleNew(); } - if(!OpenSample(files[counter].ToCString())) + if(!OpenSample(files[counter])) ErrorBox(IDS_ERR_FILEOPEN, this); } SwitchToView(); @@ -986,7 +985,7 @@ void CCtrlSamples::OnSampleSave() //------------------------------- { - TCHAR szFileName[_MAX_PATH] = ""; + mpt::PathString fileName; bool doBatchSave = CMainFrame::GetInputHandler()->ShiftPressed(); bool defaultFLAC = false; @@ -1000,33 +999,24 @@ } if(m_sndFile.GetType() & (MOD_TYPE_S3M|MOD_TYPE_IT|MOD_TYPE_MPT)) { - mpt::String::Copy(szFileName, m_sndFile.GetSample(m_nSample).filename); + fileName = mpt::PathString::FromLocale(m_sndFile.GetSample(m_nSample).filename); } - if(!szFileName[0]) - { - mpt::String::Copy(szFileName, m_sndFile.m_szNames[m_nSample]); - } - if(!szFileName[0]) strcpy(szFileName, "untitled"); - if(strlen(szFileName) >= 5 && !_strcmpi(szFileName + strlen(szFileName) - 5, ".flac")) - { - defaultFLAC = true; - } + if(fileName.empty()) fileName = mpt::PathString::FromLocale(m_sndFile.m_szNames[m_nSample]); + if(fileName.empty()) fileName = MPT_PATHSTRING("untitled"); + if(mpt::PathString::CompareNoCase(fileName.GetFileExt(), MPT_PATHSTRING(".flac"))) defaultFLAC = true; } else { // save all samples - CString sPath = m_sndFile.GetpModDoc()->GetPathName(); - if(sPath.IsEmpty()) sPath = "untitled"; + fileName = mpt::PathString::FromCString(m_sndFile.GetpModDoc()->GetPathName()).GetFileName(); + if(fileName.empty()) fileName = MPT_PATHSTRING("untitled"); - sPath += " - %sample_number% - "; + fileName += MPT_PATHSTRING(" - %sample_number% - "); if(m_sndFile.GetType() & (MOD_TYPE_XM|MOD_TYPE_MOD)) - sPath += "%sample_name%.wav"; + fileName += MPT_PATHSTRING("%sample_name%"); else - sPath += "%sample_filename%.wav"; - sPath += ".wav"; - _splitpath(sPath, NULL, NULL, szFileName, NULL); + fileName += MPT_PATHSTRING("%sample_filename%"); } - mpt::String::SetNullTerminator(szFileName); - SanitizeFilename(szFileName); + SanitizeFilename(fileName); CString format = theApp.GetSettings().Read<CString>("Sample Editor", "DefaultFormat", defaultFLAC ? "flac" : "wav"); int filter = 1; @@ -1036,8 +1026,8 @@ filter = 3; FileDialog dlg = SaveFileDialog() - .DefaultExtension(std::string(format)) - .DefaultFilename(szFileName) + .DefaultExtension(mpt::PathString::FromCString(format)) + .DefaultFilename(fileName) .ExtensionFilter("Wave File (*.wav)|*.wav|" "FLAC File (*.flac)|*.flac|" "RAW Audio (*.raw)|*.raw||") @@ -1047,50 +1037,49 @@ BeginWaitCursor(); - CString ext = dlg.GetFirstFile().GetFileExt().ToCString(); + const mpt::PathString ext = dlg.GetExtension(); - bool bOk = false; - SAMPLEINDEX iMinSmp = m_nSample, iMaxSmp = m_nSample; - mpt::PathString sFilename = dlg.GetFirstFile(); + SAMPLEINDEX minSmp = m_nSample, maxSmp = m_nSample; CString sNumberFormat; if(doBatchSave) { - iMinSmp = 1; - iMaxSmp = m_sndFile.GetNumSamples(); - sNumberFormat.Format("%s%d%s", "%.", ((int)log10((float)iMaxSmp)) + 1, "d"); + minSmp = 1; + maxSmp = m_sndFile.GetNumSamples(); + sNumberFormat.Format("%s%d%s", "%.", ((int)log10((float)maxSmp)) + 1, "d"); } - for(SAMPLEINDEX iSmp = iMinSmp; iSmp <= iMaxSmp; iSmp++) + bool ok = false; + for(SAMPLEINDEX smp = minSmp; smp <= maxSmp; smp++) { - if (m_sndFile.GetSample(iSmp).pSample) + if (m_sndFile.GetSample(smp).pSample) { + mpt::PathString fileName = dlg.GetFirstFile(); if(doBatchSave) { CString sSampleNumber; TCHAR sSampleName[64], sSampleFilename[64]; - sSampleNumber.Format(sNumberFormat, iSmp); + sSampleNumber.Format(sNumberFormat, smp); - strcpy(sSampleName, (m_sndFile.m_szNames[iSmp]) ? m_sndFile.m_szNames[iSmp] : "untitled"); - strcpy(sSampleFilename, (m_sndFile.GetSample(iSmp).filename[0]) ? m_sndFile.GetSample(iSmp).filename : m_sndFile.m_szNames[iSmp]); + strcpy(sSampleName, (m_sndFile.m_szNames[smp]) ? m_sndFile.m_szNames[smp] : "untitled"); + strcpy(sSampleFilename, (m_sndFile.GetSample(smp).filename[0]) ? m_sndFile.GetSample(smp).filename : m_sndFile.m_szNames[smp]); SanitizeFilename(sSampleName); SanitizeFilename(sSampleFilename); - sFilename = dlg.GetFirstFile(); - sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_number%", mpt::String::FromCString(sSampleNumber))); - sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_filename%", mpt::String::FromCString(sSampleFilename))); - sFilename = mpt::PathString::FromWide(mpt::String::Replace(sFilename.ToWide(), L"%sample_name%", mpt::String::FromCString(sSampleName))); + 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))); } - if(!ext.CompareNoCase(".raw")) - bOk = m_sndFile.SaveRAWSample(iSmp, sFilename); - else if(!ext.CompareNoCase(".flac")) - bOk = m_sndFile.SaveFLACSample(iSmp, sFilename); + if(!mpt::PathString::CompareNoCase(ext, MPT_PATHSTRING("raw"))) + ok = m_sndFile.SaveRAWSample(smp, fileName); + else if(!mpt::PathString::CompareNoCase(ext, MPT_PATHSTRING("flac"))) + ok = m_sndFile.SaveFLACSample(smp, fileName); else - bOk = m_sndFile.SaveWAVSample(iSmp, sFilename); + ok = m_sndFile.SaveWAVSample(smp, fileName); } } EndWaitCursor(); - if (!bOk) + if (!ok) { ErrorBox(IDS_ERR_SAVESMP, this); } else Modified: trunk/OpenMPT/mptrack/Ctrl_smp.h =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.h 2013-11-10 00:27:57 UTC (rev 3160) +++ trunk/OpenMPT/mptrack/Ctrl_smp.h 2013-11-10 01:20:37 UTC (rev 3161) @@ -67,7 +67,7 @@ ~CCtrlSamples(); bool SetCurrentSample(SAMPLEINDEX nSmp, LONG lZoom = -1, bool bUpdNum = true); - bool OpenSample(LPCSTR lpszFileName); + bool OpenSample(const mpt::PathString &fileName); bool OpenSample(const CSoundFile &sndFile, SAMPLEINDEX nSample); Setting<LONG>* GetSplitPosRef() {return &TrackerSettings::Instance().glSampleWindowHeight;} //rewbs.varWindowSize Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-10 00:27:57 UTC (rev 3160) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-10 01:20:37 UTC (rev 3161) @@ -2040,6 +2040,23 @@ dst[i] = in[i]; } }; + +// RAII-style helper struct for FLAC encoder +struct FLAC__StreamEncoder_RAII +{ + FLAC__StreamEncoder *encoder; + FILE *f; + + operator FLAC__StreamEncoder *() { return encoder; } + + FLAC__StreamEncoder_RAII() : encoder(FLAC__stream_encoder_new()), f(nullptr) { } + ~FLAC__StreamEncoder_RAII() + { + FLAC__stream_encoder_delete(encoder); + if(f != nullptr) fclose(f); + } +}; + #endif @@ -2048,7 +2065,7 @@ //----------------------------------------------------------------------------------------- { #ifndef NO_FLAC - FLAC__StreamEncoder *encoder = FLAC__stream_encoder_new(); + FLAC__StreamEncoder_RAII encoder; if(encoder == nullptr) { return false; @@ -2144,7 +2161,8 @@ FLAC__stream_encoder_set_compression_level(encoder, compression); #endif // MODPLUG_TRACKER - if(FLAC__stream_encoder_init_file(encoder, filename.ToLocale().c_str(), nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) + encoder.f = mpt_fopen(filename, "wb"); + if(encoder.f == nullptr || FLAC__stream_encoder_init_FILE(encoder, encoder.f, nullptr, nullptr) != FLAC__STREAM_ENCODER_INIT_STATUS_OK) { return false; } @@ -2178,7 +2196,6 @@ FLAC__metadata_object_delete(metadata[i]); } - FLAC__stream_encoder_delete(encoder); return true; #else MPT_UNREFERENCED_PARAMETER(nSample); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-10 10:04:30
|
Revision: 3165 http://sourceforge.net/p/modplug/code/3165 Author: manxorist Date: 2013-11-10 10:04:22 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Convert internal itp instrument paths to mpt::PathString. The file format is untouched for now and continues to store locale encoded paths. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/mptrack/view_com.cpp trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-10 02:51:11 UTC (rev 3164) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-10 10:04:22 UTC (rev 3165) @@ -1424,7 +1424,7 @@ m_modDoc.UpdateAllViews(NULL, HINT_SAMPLEINFO | HINT_MODTYPE, NULL); // -> CODE#0023 // -> DESC="IT project files (.itp)" - m_sndFile.m_szInstrumentPath[m_nInstrument - 1] = fileName.ToLocale(); + m_sndFile.m_szInstrumentPath[m_nInstrument - 1] = fileName; SetInstrumentModified(false); // -! NEW_FEATURE#0023 bOk = TRUE; @@ -1761,7 +1761,7 @@ // -> CODE#0023 // -> DESC="IT project files (.itp)" - m_sndFile.m_szInstrumentPath[m_nInstrument - 1] = dlg.GetFirstFile().ToLocale(); + m_sndFile.m_szInstrumentPath[m_nInstrument - 1] = dlg.GetFirstFile(); SetInstrumentModified(false); // -! NEW_FEATURE#0023 Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-10 02:51:11 UTC (rev 3164) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-10 10:04:22 UTC (rev 3165) @@ -506,19 +506,19 @@ instr--; if(!m_SndFile.m_szInstrumentPath[instr].empty()) { - const size_t len = m_SndFile.m_szInstrumentPath[instr].length(); - const bool iti = !_stricmp(&m_SndFile.m_szInstrumentPath[instr][len - 3], "iti"); - const bool xi = !_stricmp(&m_SndFile.m_szInstrumentPath[instr][len - 2], "xi"); + const mpt::PathString dotExt = m_SndFile.m_szInstrumentPath[instr].GetFileExt(); + const bool iti = !mpt::PathString::CompareNoCase(dotExt, MPT_PATHSTRING(".iti")); + const bool xi = !mpt::PathString::CompareNoCase(dotExt, MPT_PATHSTRING(".xi")); if(iti || (!xi && m_SndFile.GetType() & (MOD_TYPE_IT | MOD_TYPE_MPT))) - success = m_SndFile.SaveITIInstrument(instr + 1, mpt::PathString::FromLocale(m_SndFile.m_szInstrumentPath[instr]), false); + success = m_SndFile.SaveITIInstrument(instr + 1, m_SndFile.m_szInstrumentPath[instr], false); else - success = m_SndFile.SaveXIInstrument(instr + 1, mpt::PathString::FromLocale(m_SndFile.m_szInstrumentPath[instr])); + success = m_SndFile.SaveXIInstrument(instr + 1, m_SndFile.m_szInstrumentPath[instr]); if(success) m_bsInstrumentModified.reset(instr); else - Reporting::Error(("Error while saving\n" + m_SndFile.m_szInstrumentPath[instr] + "!").c_str()); + Reporting::Error(("Error while saving\n" + m_SndFile.m_szInstrumentPath[instr].ToLocale() + "!").c_str()); } } return success; Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-10 02:51:11 UTC (rev 3164) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-10 10:04:22 UTC (rev 3165) @@ -3089,7 +3089,7 @@ .ExtensionFilter("All files(*.*)|*.*||"); if(!dlg.Show()) return; - pSndFile->m_szInstrumentPath[modItem.val1 - 1] = dlg.GetFirstFile().ToLocale(); + pSndFile->m_szInstrumentPath[modItem.val1 - 1] = dlg.GetFirstFile(); OnRefreshTree(); } } @@ -3117,7 +3117,7 @@ "FastTracker II Instruments (*.xi)|*.xi||"); if(!dlg.Show()) return; - pSndFile->m_szInstrumentPath[modItem.val1 - 1] = dlg.GetFirstFile().ToLocale(); + pSndFile->m_szInstrumentPath[modItem.val1 - 1] = dlg.GetFirstFile(); } pModDoc->SaveInstrument(static_cast<INSTRUMENTINDEX>(modItem.val1)); Modified: trunk/OpenMPT/mptrack/view_com.cpp =================================================================== --- trunk/OpenMPT/mptrack/view_com.cpp 2013-11-10 02:51:11 UTC (rev 3164) +++ trunk/OpenMPT/mptrack/view_com.cpp 2013-11-10 10:04:22 UTC (rev 3165) @@ -428,7 +428,7 @@ case INSLIST_PATH: if (pIns) { - strncpy(s, pSndFile->m_szInstrumentPath[iIns].c_str(), _MAX_PATH); + strncpy(s, pSndFile->m_szInstrumentPath[iIns].ToLocale().c_str(), _MAX_PATH); s[_MAX_PATH] = 0; } break; Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-10 02:51:11 UTC (rev 3164) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2013-11-10 10:04:22 UTC (rev 3165) @@ -132,9 +132,9 @@ size = file.ReadUint32LE(); // path string length for(INSTRUMENTINDEX ins = 0; ins < GetNumInstruments(); ins++) { - char path[_MAX_PATH]; + std::string path; file.ReadString<mpt::String::maybeNullTerminated>(path, size); - m_szInstrumentPath[ins] = path; + m_szInstrumentPath[ins] = mpt::PathString::FromLocale(path); } // Song Orders @@ -223,7 +223,7 @@ CMappedFile f; for(INSTRUMENTINDEX ins = 0; ins < GetNumInstruments(); ins++) { - if(m_szInstrumentPath[ins].empty() || !f.Open(mpt::PathString::FromLocale(m_szInstrumentPath[ins]))) continue; + if(m_szInstrumentPath[ins].empty() || !f.Open(m_szInstrumentPath[ins])) continue; FileReader file = f.GetFile(); if(file.IsValid()) @@ -399,7 +399,7 @@ { char path[_MAX_PATH]; MemsetZero(path); - strncpy(path, m_szInstrumentPath[i].c_str(), _MAX_PATH); + strncpy(path, m_szInstrumentPath[i].ToLocale().c_str(), _MAX_PATH); fwrite(path, 1, _MAX_PATH, f); } Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-10 02:51:11 UTC (rev 3164) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-11-10 10:04:22 UTC (rev 3165) @@ -181,7 +181,7 @@ #ifdef MODPLUG_TRACKER // -> CODE#0023 // -> DESC="IT project files (.itp)" - m_szInstrumentPath[nInstr - 1].clear(); + m_szInstrumentPath[nInstr - 1] = mpt::PathString(); if(GetpModDoc()) { GetpModDoc()->m_bsInstrumentModified.reset(nInstr - 1); Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-11-10 02:51:11 UTC (rev 3164) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-11-10 10:04:22 UTC (rev 3165) @@ -406,7 +406,7 @@ #ifdef MODPLUG_TRACKER // -> CODE#0023 // -> DESC="IT project files (.itp)" - std::string m_szInstrumentPath[MAX_INSTRUMENTS]; + mpt::PathString m_szInstrumentPath[MAX_INSTRUMENTS]; // -! NEW_FEATURE#0023 #endif // 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-10 17:48:09
|
Revision: 3180 http://sourceforge.net/p/modplug/code/3180 Author: manxorist Date: 2013-11-10 17:47:59 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Convert credits string to ascii-escaped utf8. Fixes clang 3.3 warnings. Modified Paths: -------------- trunk/OpenMPT/common/version.cpp trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/Mptrack.cpp Modified: trunk/OpenMPT/common/version.cpp =================================================================== --- trunk/OpenMPT/common/version.cpp 2013-11-10 17:16:19 UTC (rev 3179) +++ trunk/OpenMPT/common/version.cpp 2013-11-10 17:47:59 UTC (rev 3180) @@ -283,12 +283,12 @@ #else "libopenmpt (based on OpenMPT / ModPlug Tracker)\n" #endif - "Copyright \xA9 2004-2013 Contributors\n" - "Copyright \xA9 1997-2003 Olivier Lapicque\n" + "Copyright \xC2\xA9 2004-2013 Contributors\n" + "Copyright \xC2\xA9 1997-2003 Olivier Lapicque\n" "\n" "Contributors:\n" "Johannes Schultz (2008-2013)\n" - "Ahti Lepp\xE4nen (2005-2011, 2013)\n" + "Ahti Lepp\xC3\xA4nen (2005-2011, 2013)\n" "Joern Heusipp (2012-2013)\n" "Robin Fernandes (2004-2007)\n" "Sergiy Pylypenko (2007)\n" Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-10 17:16:19 UTC (rev 3179) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-11-10 17:47:59 UTC (rev 3180) @@ -70,11 +70,11 @@ } static std::string get_credits_string() { - return mpt::String::Convert( MptVersion::GetFullCreditsString(), mpt::CharsetISO8859_1, mpt::CharsetUTF8 ); + return MptVersion::GetFullCreditsString(); } static std::string get_contact_string() { - return mpt::String::Convert( MptVersion::GetContactString(), mpt::CharsetISO8859_1, mpt::CharsetUTF8 ); + return MptVersion::GetContactString(); } std::string get_string( const std::string & key ) { Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-10 17:16:19 UTC (rev 3179) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-10 17:47:59 UTC (rev 3180) @@ -1489,7 +1489,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(MptVersion::GetFullCreditsString(), "\n", "|") + "|" + mpt::String::Replace(MptVersion::GetContactString(), "\n", "|" ) + "||||||").c_str()); + 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.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 @@ -2149,4 +2149,4 @@ { if (m_pRecentFileList && nItem >= 0 && nItem < m_pRecentFileList->GetSize()) m_pRecentFileList->Remove(nItem); -} \ No newline at end of file +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-10 18:17:56
|
Revision: 3181 http://sourceforge.net/p/modplug/code/3181 Author: saga-games Date: 2013-11-10 18:17:47 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Drag&Dropping unicode filenames from OS works for samples and instruments [Ref] Treeview is now unicode (except for MIDI library) Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_ins.cpp trunk/OpenMPT/mptrack/Ctrl_seq.cpp trunk/OpenMPT/mptrack/Ctrl_smp.cpp trunk/OpenMPT/mptrack/Globals.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/View_ins.cpp trunk/OpenMPT/mptrack/View_ins.h trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/mptrack/View_smp.h trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/mptrack/View_tre.h trunk/OpenMPT/soundlib/Load_it.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/Ctrl_ins.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -1077,13 +1077,13 @@ break; case CTRLMSG_INS_OPENFILE: - if (lParam) return OpenInstrument(mpt::PathString::FromCString((LPCSTR)lParam)); + if (lParam) return OpenInstrument(*reinterpret_cast<const mpt::PathString *>(lParam)); break; case CTRLMSG_INS_SONGDROP: if (lParam) { - LPDRAGONDROP pDropInfo = (LPDRAGONDROP)lParam; + const DRAGONDROP *pDropInfo = (const DRAGONDROP *)lParam; CSoundFile *pSndFile = (CSoundFile *)(pDropInfo->lDropParam); if (pDropInfo->pModDoc) pSndFile = pDropInfo->pModDoc->GetSoundFile(); if (pSndFile) return OpenInstrument(*pSndFile, pDropInfo->dwDropItem); Modified: trunk/OpenMPT/mptrack/Ctrl_seq.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -1286,7 +1286,7 @@ LRESULT COrderList::OnDragonDropping(WPARAM doDrop, LPARAM lParam) //----------------------------------------------------------------- { - LPDRAGONDROP pDropInfo = (LPDRAGONDROP)lParam; + const DRAGONDROP *pDropInfo = (const DRAGONDROP *)lParam; ORDERINDEX posdest; BOOL canDrop; CPoint pt; Modified: trunk/OpenMPT/mptrack/Ctrl_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/Ctrl_smp.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -426,13 +426,13 @@ break; case CTRLMSG_SMP_OPENFILE: - if (lParam) return OpenSample(mpt::PathString::FromCString((LPCSTR)lParam)) ? TRUE : FALSE; + if (lParam) return OpenSample(*reinterpret_cast<const mpt::PathString *>(lParam)); break; case CTRLMSG_SMP_SONGDROP: if (lParam) { - LPDRAGONDROP pDropInfo = (LPDRAGONDROP)lParam; + const DRAGONDROP *pDropInfo = (const DRAGONDROP *)lParam; CSoundFile *pSndFile = (CSoundFile *)(pDropInfo->lDropParam); if (pDropInfo->pModDoc) pSndFile = pDropInfo->pModDoc->GetSoundFile(); if (pSndFile) return OpenSample(*pSndFile, (SAMPLEINDEX)pDropInfo->dwDropItem) ? TRUE : FALSE; Modified: trunk/OpenMPT/mptrack/Globals.h =================================================================== --- trunk/OpenMPT/mptrack/Globals.h 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/Globals.h 2013-11-10 18:17:47 UTC (rev 3181) @@ -210,7 +210,7 @@ virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint); virtual void UpdateView(DWORD, CObject *) {} virtual LRESULT OnModViewMsg(WPARAM wParam, LPARAM lParam); - virtual BOOL OnDragonDrop(BOOL, LPDRAGONDROP) { return FALSE; } + virtual BOOL OnDragonDrop(BOOL, const DRAGONDROP *) { return FALSE; } virtual LRESULT OnPlayerNotify(Notification *) { return 0; } //}}AFX_VIRTUAL @@ -219,7 +219,7 @@ afx_msg void OnDestroy(); afx_msg LRESULT OnReceiveModViewMsg(WPARAM wParam, LPARAM lParam); afx_msg BOOL OnMouseWheel(UINT fFlags, short zDelta, CPoint point); - afx_msg LRESULT OnDragonDropping(WPARAM bDoDrop, LPARAM lParam) { return OnDragonDrop((BOOL)bDoDrop, (LPDRAGONDROP)lParam); } + afx_msg LRESULT OnDragonDropping(WPARAM bDoDrop, LPARAM lParam) { return OnDragonDrop((BOOL)bDoDrop, (const DRAGONDROP *)lParam); } LRESULT OnUpdatePosition(WPARAM, LPARAM); //}}AFX_MSG DECLARE_MESSAGE_MAP() Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -256,9 +256,9 @@ } m_SndFile.ChangeModTypeTo(MOD_TYPE_IT); BeginWaitCursor(); - LPMIDILIBSTRUCT lpMidiLib = CTrackApp::GetMidiLibrary(); + MIDILIBSTRUCT &midiLib = CTrackApp::GetMidiLibrary(); // Scan Instruments - if (lpMidiLib) for (INSTRUMENTINDEX nIns = 1; nIns <= m_SndFile.m_nInstruments; nIns++) if (m_SndFile.Instruments[nIns]) + for (INSTRUMENTINDEX nIns = 1; nIns <= m_SndFile.m_nInstruments; nIns++) if (m_SndFile.Instruments[nIns]) { mpt::PathString pszMidiMapName; ModInstrument *pIns = m_SndFile.Instruments[nIns]; @@ -269,7 +269,7 @@ nMidiCode = 0x80 | (pIns->nMidiDrumKey & 0x7F); else nMidiCode = pIns->nMidiProgram & 0x7F; - pszMidiMapName = lpMidiLib->MidiMap[nMidiCode]; + pszMidiMapName = midiLib.MidiMap[nMidiCode]; if (pEmbeddedBank) { UINT nDlsIns = 0, nDrumRgn = 0; Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -302,19 +302,13 @@ ///////////////////////////////////////////////////////////////////////////// // Midi Library -LPMIDILIBSTRUCT CTrackApp::glpMidiLibrary = NULL; +MIDILIBSTRUCT CTrackApp::midiLibrary; BOOL CTrackApp::ImportMidiConfig(const mpt::PathString &filename, BOOL bNoWarn) //----------------------------------------------------------------------------- { if(filename.empty()) return FALSE; - if (!glpMidiLibrary) - { - glpMidiLibrary = new MIDILIBSTRUCT; - if (!glpMidiLibrary) return FALSE; - } - if (CDLSBank::IsDLSBank(filename)) { ConfirmAnswer result = cnfYes; @@ -331,14 +325,14 @@ { for (UINT iIns=0; iIns<256; iIns++) { - if((bReplaceAll) || glpMidiLibrary->MidiMap[iIns].empty()) + if((bReplaceAll) || midiLibrary.MidiMap[iIns].empty()) { DWORD dwProgram = (iIns < 128) ? iIns : 0xFF; DWORD dwKey = (iIns < 128) ? 0xFF : iIns & 0x7F; DWORD dwBank = (iIns < 128) ? 0 : F_INSTRUMENT_DRUMS; if (dlsbank.FindInstrument((iIns < 128) ? FALSE : TRUE, dwBank, dwProgram, dwKey)) { - glpMidiLibrary->MidiMap[iIns] = filename; + midiLibrary.MidiMap[iIns] = filename; } } } @@ -356,12 +350,6 @@ TCHAR s[_MAX_PATH]; mpt::PathString UltraSndPath; - if (!glpMidiLibrary) - { - glpMidiLibrary = new MIDILIBSTRUCT; - if (!glpMidiLibrary) return FALSE; - } - UltraSndPath = file.Read<mpt::PathString>("Ultrasound", "PatchDir", mpt::PathString()); if(UltraSndPath == MPT_PATHSTRING(".\\")) UltraSndPath = mpt::PathString(); if(UltraSndPath.empty()) @@ -405,7 +393,7 @@ if(!filename.empty()) { filename = theApp.RelativePathToAbsolute(filename); - glpMidiLibrary->MidiMap[iMidi] = filename; + midiLibrary.MidiMap[iMidi] = filename; } } return FALSE; @@ -415,7 +403,7 @@ BOOL CTrackApp::ExportMidiConfig(const mpt::PathString &filename) //--------------------------------------------------------------- { - if((!glpMidiLibrary) || filename.empty()) return FALSE; + if(filename.empty()) return FALSE; IniFileSettingsContainer file(filename); return ExportMidiConfig(file); } @@ -425,15 +413,14 @@ { CHAR s[128]; - if (!glpMidiLibrary) return FALSE; - for(size_t iMidi = 0; iMidi < 256; iMidi++) if (!glpMidiLibrary->MidiMap[iMidi].empty()) + for(size_t iMidi = 0; iMidi < 256; iMidi++) if (!midiLibrary.MidiMap[iMidi].empty()) { if (iMidi < 128) wsprintf(s, _T("Midi%d"), iMidi); else wsprintf(s, _T("Perc%d"), iMidi & 0x7F); - mpt::PathString szFileName = glpMidiLibrary->MidiMap[iMidi]; + mpt::PathString szFileName = midiLibrary.MidiMap[iMidi]; if(!szFileName.empty()) { @@ -507,7 +494,7 @@ } } } - if(glpMidiLibrary) ImportMidiConfig(filename, TRUE); + ImportMidiConfig(filename, TRUE); return TRUE; } @@ -939,12 +926,7 @@ { delete m_pSoundDevicesManager; m_pSoundDevicesManager = nullptr; - if (glpMidiLibrary) - { - ExportMidiConfig(theApp.GetSettings()); - delete glpMidiLibrary; - glpMidiLibrary = NULL; - } + ExportMidiConfig(theApp.GetSettings()); SaveDefaultDLSBanks(); for(size_t i = 0; i < gpDLSBanks.size(); i++) { Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/Mptrack.h 2013-11-10 18:17:47 UTC (rev 3181) @@ -39,23 +39,25 @@ ///////////////////////////////////////////////////////////////////////////// // Midi Library -typedef struct MIDILIBSTRUCT +struct MIDILIBSTRUCT { mpt::PathString MidiMap[128*2]; // 128 instruments + 128 percussions -} MIDILIBSTRUCT, *LPMIDILIBSTRUCT; +}; ////////////////////////////////////////////////////////////////////////// // Dragon Droppings -typedef struct DRAGONDROP +struct DRAGONDROP { CModDoc *pModDoc; DWORD dwDropType; DWORD dwDropItem; LPARAM lDropParam; -} DRAGONDROP, *LPDRAGONDROP; + const mpt::PathString &GetPath() const { return *reinterpret_cast<const mpt::PathString *>(lDropParam); } +}; + enum { DRAGONDROP_NOTHING=0, // |------< Drop Type >-------------|--< dwDropItem >---|--< lDropParam >---| DRAGONDROP_DLS, // | Instrument from a DLS bank | DLS Bank # | DLS Instrument | @@ -83,8 +85,8 @@ // static data protected: static MODTYPE m_nDefaultDocType; - static LPMIDILIBSTRUCT glpMidiLibrary; static BOOL m_nProject; + static MIDILIBSTRUCT midiLibrary; public: static std::vector<CDLSBank *> gpDLSBanks; @@ -137,7 +139,7 @@ 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; } - static LPMIDILIBSTRUCT GetMidiLibrary() { return glpMidiLibrary; } + static MIDILIBSTRUCT &GetMidiLibrary() { return midiLibrary; } static BOOL ImportMidiConfig(const mpt::PathString &filename, BOOL bNoWarning=FALSE); static BOOL ExportMidiConfig(const mpt::PathString &filename); static BOOL ImportMidiConfig(SettingsContainer &file); Modified: trunk/OpenMPT/mptrack/View_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_ins.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/View_ins.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -1980,18 +1980,19 @@ } +// Drop files from Windows void CViewInstrument::OnDropFiles(HDROP hDropInfo) //------------------------------------------------ { - const UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); + const UINT nFiles = ::DragQueryFileW(hDropInfo, (UINT)-1, NULL, 0); + CMainFrame::GetMainFrame()->SetForegroundWindow(); for(UINT f = 0; f < nFiles; f++) { - TCHAR szFileName[_MAX_PATH] = ""; - CMainFrame::GetMainFrame()->SetForegroundWindow(); - ::DragQueryFile(hDropInfo, f, szFileName, _MAX_PATH); - if(szFileName[0]) + WCHAR fileName[MAX_PATH]; + if(::DragQueryFileW(hDropInfo, f, fileName, CountOf(fileName))) { - if(SendCtrlMessage(CTRLMSG_INS_OPENFILE, (LPARAM)szFileName) && f < nFiles - 1) + const mpt::PathString file = mpt::PathString::FromNative(fileName); + if(SendCtrlMessage(CTRLMSG_INS_OPENFILE, (LPARAM)&file) && f < nFiles - 1) { // Insert more instrument slots SendCtrlMessage(IDC_INSTRUMENT_NEW); @@ -2002,8 +2003,8 @@ } -BOOL CViewInstrument::OnDragonDrop(BOOL bDoDrop, LPDRAGONDROP lpDropInfo) -//----------------------------------------------------------------------- +BOOL CViewInstrument::OnDragonDrop(BOOL bDoDrop, const DRAGONDROP *lpDropInfo) +//---------------------------------------------------------------------------- { CModDoc *pModDoc = GetDocument(); BOOL bCanDrop = FALSE; @@ -2033,8 +2034,7 @@ case DRAGONDROP_SOUNDFILE: case DRAGONDROP_MIDIINSTR: - bCanDrop = ((lpDropInfo->lDropParam) - && (*((LPCSTR)lpDropInfo->lDropParam))); + bCanDrop = !lpDropInfo->GetPath().empty(); break; } if ((!bCanDrop) || (!bDoDrop)) return bCanDrop; @@ -2059,10 +2059,10 @@ break; case DRAGONDROP_MIDIINSTR: - if (CDLSBank::IsDLSBank(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) + if (CDLSBank::IsDLSBank(lpDropInfo->GetPath())) { CDLSBank dlsbank; - if (dlsbank.Open(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) + if (dlsbank.Open(lpDropInfo->GetPath())) { DLSINSTRUMENT *pDlsIns; UINT nIns = 0, nRgn = 0xFF; Modified: trunk/OpenMPT/mptrack/View_ins.h =================================================================== --- trunk/OpenMPT/mptrack/View_ins.h 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/View_ins.h 2013-11-10 18:17:47 UTC (rev 3181) @@ -162,7 +162,7 @@ virtual void OnInitialUpdate(); virtual void UpdateView(DWORD dwHintMask=0, CObject *pObj=NULL); virtual LRESULT OnModViewMsg(WPARAM, LPARAM); - virtual BOOL OnDragonDrop(BOOL, LPDRAGONDROP); + virtual BOOL OnDragonDrop(BOOL, const DRAGONDROP *); virtual LRESULT OnPlayerNotify(Notification *); //}}AFX_VIRTUAL Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -2223,18 +2223,19 @@ } +// Drop files from Windows void CViewSample::OnDropFiles(HDROP hDropInfo) //-------------------------------------------- { - const UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); + const UINT nFiles = ::DragQueryFileW(hDropInfo, (UINT)-1, NULL, 0); + CMainFrame::GetMainFrame()->SetForegroundWindow(); for(UINT f = 0; f < nFiles; f++) { - TCHAR szFileName[_MAX_PATH] = ""; - CMainFrame::GetMainFrame()->SetForegroundWindow(); - ::DragQueryFile(hDropInfo, f, szFileName, _MAX_PATH); - if(szFileName[0]) + WCHAR fileName[MAX_PATH]; + if(::DragQueryFileW(hDropInfo, f, fileName, CountOf(fileName))) { - if(SendCtrlMessage(CTRLMSG_SMP_OPENFILE, (LPARAM)szFileName) && f < nFiles - 1) + const mpt::PathString file = mpt::PathString::FromNative(fileName); + if(SendCtrlMessage(CTRLMSG_SMP_OPENFILE, (LPARAM)&file) && f < nFiles - 1) { // Insert more sample slots SendCtrlMessage(IDC_SAMPLE_NEW); @@ -2245,8 +2246,8 @@ } -BOOL CViewSample::OnDragonDrop(BOOL bDoDrop, LPDRAGONDROP lpDropInfo) -//------------------------------------------------------------------- +BOOL CViewSample::OnDragonDrop(BOOL bDoDrop, const DRAGONDROP *lpDropInfo) +//------------------------------------------------------------------------ { CModDoc *pModDoc = GetDocument(); CSoundFile *pSndFile; @@ -2275,8 +2276,7 @@ case DRAGONDROP_SOUNDFILE: case DRAGONDROP_MIDIINSTR: - bCanDrop = ((lpDropInfo->lDropParam) - && (*((LPCSTR)lpDropInfo->lDropParam))); + bCanDrop = !lpDropInfo->GetPath().empty(); break; } if ((!bCanDrop) || (!bDoDrop)) return bCanDrop; @@ -2296,10 +2296,10 @@ break; case DRAGONDROP_MIDIINSTR: - if (CDLSBank::IsDLSBank(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) + if (CDLSBank::IsDLSBank(lpDropInfo->GetPath())) { CDLSBank dlsbank; - if (dlsbank.Open(mpt::PathString::FromCString((LPCSTR)lpDropInfo->lDropParam))) + if (dlsbank.Open(lpDropInfo->GetPath())) { DLSINSTRUMENT *pDlsIns; UINT nIns = 0, nRgn = 0xFF; @@ -2329,7 +2329,7 @@ } MPT_FALLTHROUGH; case DRAGONDROP_SOUNDFILE: - SendCtrlMessage(CTRLMSG_SMP_OPENFILE, (LPARAM)lpDropInfo->lDropParam); + SendCtrlMessage(CTRLMSG_SMP_OPENFILE, lpDropInfo->lDropParam); break; case DRAGONDROP_DLS: Modified: trunk/OpenMPT/mptrack/View_smp.h =================================================================== --- trunk/OpenMPT/mptrack/View_smp.h 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/View_smp.h 2013-11-10 18:17:47 UTC (rev 3181) @@ -98,7 +98,7 @@ virtual void UpdateView(DWORD dwHintMask=0, CObject *pObj=NULL); virtual LRESULT OnModViewMsg(WPARAM, LPARAM); virtual BOOL OnScrollBy(CSize sizeScroll, BOOL bDoScroll=TRUE); - virtual BOOL OnDragonDrop(BOOL, LPDRAGONDROP); + virtual BOOL OnDragonDrop(BOOL, const DRAGONDROP *); virtual LRESULT OnPlayerNotify(Notification *); virtual BOOL PreTranslateMessage(MSG *pMsg); //rewbs.customKeys //}}AFX_VIRTUAL Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -120,9 +120,6 @@ m_dwStatus = 0; m_bShowAllFiles = false; m_hItemDrag = m_hItemDrop = NULL; - m_szInstrLibPath[0] = 0; - m_szOldPath[0] = 0; - m_szSongName[0] = 0; m_hDropWnd = NULL; m_hInsLib = m_hMidiLib = NULL; m_nDocNdx = m_nDragDocNdx = 0; @@ -143,6 +140,12 @@ delete (*iter); } DocInfo.clear(); + + if(m_SongFile != nullptr) + { + delete m_SongFile; + m_SongFile = nullptr; + } } @@ -164,7 +167,22 @@ m_dwStatus |= TREESTATUS_SINGLEEXPAND; } ModifyStyle(dwRemove, dwAdd); - mpt::String::Copy(m_szInstrLibPath, TrackerDirectories::Instance().GetDefaultDirectory(DIR_SAMPLES).ToLocale()); + + m_szInstrLibPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_SAMPLES); + if(m_szInstrLibPath.empty()) + { + m_szInstrLibPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_INSTRUMENTS); + if(m_szInstrLibPath.empty()) + { + // Resort to current directory. + WCHAR curDir[MAX_PATH]; + GetCurrentDirectoryW(CountOf(curDir), curDir); + m_szInstrLibPath = mpt::PathString::FromNative(curDir); + } + } + if(!m_szInstrLibPath.HasTrailingSlash()) + m_szInstrLibPath += MPT_PATHSTRING("\\"); + SetImageList(CMainFrame::GetMainFrame()->GetImageList(), TVSIL_NORMAL); if (!IsSampleBrowser()) { @@ -248,26 +266,57 @@ } -void CModTree::InsLibGetFullPath(HTREEITEM hItem, LPSTR pszFullPath) const -//------------------------------------------------------------------------ +std::wstring CModTree::GetItemTextW(HTREEITEM item) const +//------------------------------------------------------- { - strcpy(pszFullPath, m_szInstrLibPath); - if ((pszFullPath[0]) && (pszFullPath[strlen(pszFullPath)-1] != '\\')) strcat(pszFullPath, "\\"); - strcat(pszFullPath, GetItemText(hItem)); + WCHAR name[MAX_PATH]; // Maximum displayed text length according to documentation. + TVITEMW tvi; + MemsetZero(tvi); + tvi.hItem = item; + tvi.mask = TVIF_TEXT; + tvi.pszText = name; + tvi.cchTextMax = CountOf(name); + if(::SendMessage(m_hWnd, TVM_GETITEMW, 0, (LPARAM)&tvi)) + { + return tvi.pszText; + } else + { + return L""; + } } -void CModTree::InsLibSetFullPath(LPCSTR pszLibPath, LPCSTR pszSongName) -//--------------------------------------------------------------------- +void CModTree::SetItemTextW(HTREEITEM item, const WCHAR *text) +//------------------------------------------------------------ { - strcpy(m_szInstrLibPath, pszLibPath); - if ((pszSongName[0]) && (_stricmp(m_szSongName, pszSongName))) + TVITEMW tvi; + MemsetZero(tvi); + tvi.hItem = item; + tvi.mask = TVIF_TEXT; + tvi.pszText = const_cast<WCHAR *>(text); + ::SendMessage(m_hWnd, TVM_SETITEMW, 0, (LPARAM)&tvi); +} + + +mpt::PathString CModTree::InsLibGetFullPath(HTREEITEM hItem) const +//---------------------------------------------------------------- +{ + mpt::PathString fullPath = m_szInstrLibPath; + if(!fullPath.HasTrailingSlash()) fullPath += MPT_PATHSTRING("\\"); + return fullPath + mpt::PathString::FromWide(GetItemTextW(hItem)); +} + + +void CModTree::InsLibSetFullPath(const mpt::PathString &libPath, const mpt::PathString &songName) +//----------------------------------------------------------------------------------------------- +{ + m_szInstrLibPath = libPath; + if(!songName.empty() && mpt::PathString::CompareNoCase(m_szSongName, songName)) { // Load module for previewing its instruments CMappedFile f; - SetCurrentDirectory(m_szInstrLibPath); - if (f.Open(mpt::PathString::FromLocale(pszSongName))) + if (f.Open(libPath + songName)) { FileReader file = f.GetFile(); if (file.IsValid()) @@ -286,11 +335,10 @@ m_SongFile->Patterns.DestroyPatterns(); m_SongFile->songMessage.clear(); } - f.Unlock(); } } } - strcpy(m_szSongName, pszSongName); + m_szSongName = songName; } @@ -402,7 +450,7 @@ CHAR s[256], stmp[256]; TV_ITEM tvi; CHAR szName[_MAX_FNAME], szExt[_MAX_EXT]; - LPMIDILIBSTRUCT lpMidiLib = CTrackApp::GetMidiLibrary(); + const MIDILIBSTRUCT &midiLib = CTrackApp::GetMidiLibrary(); if (IsSampleBrowser()) return; // Midi Programs @@ -411,9 +459,9 @@ DWORD dwImage = IMAGE_NOINSTRUMENT; wsprintf(s, "%u: %s", iMidi, szMidiProgramNames[iMidi]); const LPARAM param = (MODITEM_MIDIINSTRUMENT << MIDILIB_SHIFT) | iMidi; - if((lpMidiLib) && (!lpMidiLib->MidiMap[iMidi].empty())) + if(!midiLib.MidiMap[iMidi].empty()) { - _splitpath(lpMidiLib->MidiMap[iMidi].ToLocale().c_str(), NULL, NULL, szName, szExt); + _splitpath(midiLib.MidiMap[iMidi].ToLocale().c_str(), NULL, NULL, szName, szExt); strncat(s, ": ", sizeof(s)); s[sizeof(s)-1] = 0; strncat(s, szName, sizeof(s)); @@ -447,9 +495,9 @@ DWORD dwImage = IMAGE_NOSAMPLE; wsprintf(s, "%s: %s", szDefaultNoteNames[iPerc], szMidiPercussionNames[iPerc-24]); const LPARAM param = (MODITEM_MIDIPERCUSSION << MIDILIB_SHIFT) | iPerc; - if((lpMidiLib) && (!lpMidiLib->MidiMap[iPerc|0x80].empty())) + if(!midiLib.MidiMap[iPerc|0x80].empty()) { - _splitpath(lpMidiLib->MidiMap[iPerc|0x80].ToLocale().c_str(), NULL, NULL, szName, szExt); + _splitpath(midiLib.MidiMap[iPerc|0x80].ToLocale().c_str(), NULL, NULL, szName, szExt); strncat(s, ": ", sizeof(s)); mpt::String::SetNullTerminator(s); strncat(s, szName, sizeof(s)); @@ -1210,7 +1258,7 @@ case MODITEM_INSLIB_SONG: case MODITEM_INSLIB_FOLDER: - InstrumentLibraryChDir(GetItemText(hItem)); + InstrumentLibraryChDir(mpt::PathString::FromWide(GetItemTextW(hItem)), modItem.type == MODITEM_INSLIB_SONG); return TRUE; case MODITEM_HDR_SONG: @@ -1281,7 +1329,7 @@ case MODITEM_INSLIB_SAMPLE: case MODITEM_INSLIB_INSTRUMENT: - if (m_szSongName[0]) + if(!m_szSongName.empty()) { // Preview sample / instrument in module char szName[16]; @@ -1301,10 +1349,8 @@ } else { // Preview sample / instrument file - CHAR szFullPath[_MAX_PATH] = ""; - InsLibGetFullPath(hItem, szFullPath); CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); - if (pMainFrm) pMainFrm->PlaySoundFile(mpt::PathString::FromLocale(szFullPath), nParam); + if (pMainFrm) pMainFrm->PlaySoundFile(InsLibGetFullPath(hItem), nParam); } return TRUE; @@ -1312,11 +1358,11 @@ modItemID |= 0x80; case MODITEM_MIDIINSTRUMENT: { - LPMIDILIBSTRUCT lpMidiLib = CTrackApp::GetMidiLibrary(); - if((lpMidiLib) && (modItemID < 256) && (!lpMidiLib->MidiMap[modItemID].empty())) + MIDILIBSTRUCT &midiLib = CTrackApp::GetMidiLibrary(); + if(modItemID < 256 && !midiLib.MidiMap[modItemID].empty()) { CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); - if (pMainFrm) pMainFrm->PlaySoundFile(lpMidiLib->MidiMap[modItemID], static_cast<ModCommand::NOTE>(nParam)); + if (pMainFrm) pMainFrm->PlaySoundFile(midiLib.MidiMap[modItemID], static_cast<ModCommand::NOTE>(nParam)); } } return TRUE; @@ -1351,13 +1397,13 @@ } -BOOL CModTree::SetMidiInstrument(UINT nIns, LPCTSTR lpszFileName) -//-------------------------------------------------------------- +BOOL CModTree::SetMidiInstrument(UINT nIns, const mpt::PathString &fileName) +//-------------------------------------------------------------------------- { - LPMIDILIBSTRUCT lpMidiLib = CTrackApp::GetMidiLibrary(); - if ((lpMidiLib) && (nIns < 128)) + MIDILIBSTRUCT &midiLib = CTrackApp::GetMidiLibrary(); + if(nIns < 128) { - lpMidiLib->MidiMap[nIns] = mpt::PathString::FromCString(lpszFileName); + midiLib.MidiMap[nIns] = fileName; RefreshMidiLibrary(); return TRUE; } @@ -1365,14 +1411,14 @@ } -BOOL CModTree::SetMidiPercussion(UINT nPerc, LPCTSTR lpszFileName) -//--------------------------------------------------------------- +BOOL CModTree::SetMidiPercussion(UINT nPerc, const mpt::PathString &fileName) +//--------------------------------------------------------------------------- { - LPMIDILIBSTRUCT lpMidiLib = CTrackApp::GetMidiLibrary(); - if ((lpMidiLib) && (nPerc < 128)) + MIDILIBSTRUCT &midiLib = CTrackApp::GetMidiLibrary(); + if(nPerc < 128) { UINT nIns = nPerc | 0x80; - lpMidiLib->MidiMap[nIns] = mpt::PathString::FromCString(lpszFileName); + midiLib.MidiMap[nIns] = fileName; RefreshMidiLibrary(); return TRUE; } @@ -1438,11 +1484,11 @@ break; case MODITEM_MIDIINSTRUMENT: - SetMidiInstrument(modItemID, ""); + SetMidiInstrument(modItemID, MPT_PATHSTRING("")); RefreshMidiLibrary(); break; case MODITEM_MIDIPERCUSSION: - SetMidiPercussion(modItemID, ""); + SetMidiPercussion(modItemID, MPT_PATHSTRING("")); RefreshMidiLibrary(); break; @@ -1455,16 +1501,14 @@ case MODITEM_INSLIB_SAMPLE: case MODITEM_INSLIB_INSTRUMENT: { - CHAR szFullPath[_MAX_PATH] = ""; - SHFILEOPSTRUCT fos; - - InsLibGetFullPath(hItem, szFullPath); + SHFILEOPSTRUCTW fos; + mpt::PathString fullPath = InsLibGetFullPath(hItem); memset(&fos, 0, sizeof(fos)); fos.hwnd = m_hWnd; fos.wFunc = FO_DELETE; - fos.pFrom = szFullPath; + fos.pFrom = fullPath.AsNative().c_str(); fos.fFlags = FOF_ALLOWUNDO; - if ((0 == SHFileOperation(&fos)) && (!fos.fAnyOperationsAborted)) RefreshInstrumentLibrary(); + if ((0 == SHFileOperationW(&fos)) && (!fos.fAnyOperationsAborted)) RefreshInstrumentLibrary(); } break; } @@ -1481,9 +1525,7 @@ { case MODITEM_INSLIB_SONG: { - CHAR szFullPath[_MAX_PATH] = ""; - InsLibGetFullPath(hItem, szFullPath); - theApp.OpenDocumentFile(szFullPath); + theApp.OpenDocumentFile(InsLibGetFullPath(hItem).ToCString()); } break; } @@ -1513,9 +1555,9 @@ if(!dlg.Show()) return FALSE; if (dwItem & 0x80) - return SetMidiPercussion(dwItem & 0x7F, dlg.GetFirstFile().ToCString()); + return SetMidiPercussion(dwItem & 0x7F, dlg.GetFirstFile()); else - return SetMidiInstrument(dwItem, dlg.GetFirstFile().ToCString()); + return SetMidiInstrument(dwItem, dlg.GetFirstFile()); } @@ -1557,68 +1599,55 @@ void CModTree::FillInstrumentLibrary() //------------------------------------ { - TV_INSERTSTRUCT tvis; - char s[_MAX_PATH+32], szPath[_MAX_PATH] = ""; - if (!m_hInsLib) return; SetRedraw(FALSE); - if(m_szSongName[0] && IsSampleBrowser() && m_SongFile) + if(!m_szSongName.empty() && IsSampleBrowser() && m_SongFile) { - wsprintf(s, "%s", m_szSongName); - SetItemText(m_hInsLib, s); + // Fill browser with samples / instruments of module file + SetItemTextW(m_hInsLib, m_szSongName.AsNative().c_str()); SetItemImage(m_hInsLib, IMAGE_FOLDERSONG, IMAGE_FOLDERSONG); - for(INSTRUMENTINDEX iIns = 1; iIns <= m_SongFile->GetNumInstruments(); iIns++) + for(INSTRUMENTINDEX ins = 1; ins <= m_SongFile->GetNumInstruments(); ins++) { - ModInstrument *pIns = m_SongFile->Instruments[iIns]; + ModInstrument *pIns = m_SongFile->Instruments[ins]; if(pIns) { - mpt::String::Copy(szPath, pIns->name); - wsprintf(s, "%3d: %s", iIns, szPath); - ModTreeBuildTVIParam(tvis, s, IMAGE_INSTRUMENTS); - InsertItem(&tvis); + WCHAR s[MAX_INSTRUMENTNAME + 10]; + swprintf(s, CountOf(s), L"%3d: %s", ins, mpt::String::Decode(pIns->name, mpt::CharsetLocale).c_str()); + ModTreeInsert(s, IMAGE_INSTRUMENTS); } } - for(SAMPLEINDEX iSmp = 1; iSmp <= m_SongFile->GetNumSamples(); iSmp++) + for(SAMPLEINDEX smp = 1; smp <= m_SongFile->GetNumSamples(); smp++) { - const ModSample &sample = m_SongFile->GetSample(iSmp); - strcpy(szPath, m_SongFile->m_szNames[iSmp]); - if (sample.pSample) + const ModSample &sample = m_SongFile->GetSample(smp); + if(sample.pSample) { - wsprintf(s, "%3d: %s", iSmp, szPath); - ModTreeBuildTVIParam(tvis, s, IMAGE_SAMPLES); - InsertItem(&tvis); + 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()); + ModTreeInsert(s, IMAGE_SAMPLES); } } } else { - CHAR szFileName[_MAX_PATH]; - WIN32_FIND_DATA wfd; - HANDLE hFind; - - if (m_szInstrLibPath[0]) - strcpy(szPath, m_szInstrLibPath); - else - GetCurrentDirectory(sizeof(szPath), szPath); - if (!IsSampleBrowser()) + std::wstring text; + if(!IsSampleBrowser()) { - wsprintf(s, "Instrument Library (%s)", szPath); - strcpy(&s[80], "..."); // Limit text - SetItemText(m_hInsLib, s); + text = L"Instrument Library (" + m_szInstrLibPath.ToWide() + L")"; + SetItemTextW(m_hInsLib, text.c_str()); } else { - wsprintf(s, "%s", szPath); - strcpy(&s[80], "..."); // Limit text - SetItemText(m_hInsLib, s); + SetItemTextW(m_hInsLib, m_szInstrLibPath.ToWide().c_str()); SetItemImage(m_hInsLib, IMAGE_FOLDER, IMAGE_FOLDER); } + // Enumerating Drives... - if (!IsSampleBrowser()) + if(!IsSampleBrowser()) { - strcpy(s, "?:\\"); - for (UINT iDrive='A'; iDrive<='Z'; iDrive++) + WCHAR s[16]; + wcscpy(s, L"?:\\"); + for(UINT iDrive = 'A'; iDrive <= 'Z'; iDrive++) { - s[0] = (CHAR)iDrive; - UINT nDriveType = GetDriveType(s); + s[0] = (WCHAR)iDrive; + UINT nDriveType = GetDriveTypeW(s); int nImage = 0; switch(nDriveType) { @@ -1628,62 +1657,49 @@ case DRIVE_CDROM: nImage = IMAGE_CDROMDRIVE; break; case DRIVE_RAMDISK: nImage = IMAGE_RAMDRIVE; break; } - if (nImage) + if(nImage) { - ModTreeBuildTVIParam(tvis, s, nImage); - InsertItem(&tvis); + ModTreeInsert(s, nImage); } } } - // The path is too long - we can't continue. This can actually only happen with an invalid path - if(strlen(szPath) >= CountOf(szPath) - 1) - return; - std::vector<const char *> modExts = CSoundFile::GetSupportedExtensions(false); // Enumerating Directories and samples/instruments - if (szPath[strlen(szPath) - 1] != '\\') - strcat(szPath, "\\"); - strcpy(m_szInstrLibPath, szPath); - strcat(szPath, "*.*"); - memset(&wfd, 0, sizeof(wfd)); - if ((hFind = FindFirstFile(szPath, &wfd)) != INVALID_HANDLE_VALUE) + const mpt::PathString path = m_szInstrLibPath + MPT_PATHSTRING("*.*"); + + HANDLE hFind; + WIN32_FIND_DATAW wfd; + MemsetZero(wfd); + if((hFind = FindFirstFileW(path.AsNative().c_str(), &wfd)) != INVALID_HANDLE_VALUE) { do { // Up Directory - if (!strcmp(wfd.cFileName, "..")) + if(!wcscmp(wfd.cFileName, L"..")) { - if (!IsSampleBrowser()) + if(!IsSampleBrowser()) { - ModTreeBuildTVIParam(tvis, wfd.cFileName, IMAGE_FOLDERPARENT); - InsertItem(&tvis); + ModTreeInsert(wfd.cFileName, IMAGE_FOLDERPARENT); } - } else - // Ignore these files - if (wfd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN| - FILE_ATTRIBUTE_OFFLINE| - FILE_ATTRIBUTE_TEMPORARY| - FILE_ATTRIBUTE_SYSTEM - )) + } else if (wfd.dwFileAttributes & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_SYSTEM)) { - // skip it - } else - // Directory - if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + // Ignore these files + continue; + } else if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - if ((strcmp(wfd.cFileName, ".")) && !IsSampleBrowser()) + // Directory + if(wcscmp(wfd.cFileName, L".") && !IsSampleBrowser()) { - ModTreeBuildTVIParam(tvis, wfd.cFileName, IMAGE_FOLDER); - InsertItem(&tvis); + ModTreeInsert(wfd.cFileName, IMAGE_FOLDER); } - } else - if ((!wfd.nFileSizeHigh) && (wfd.nFileSizeLow >= 16)) + } else if(wfd.nFileSizeHigh > 0 || wfd.nFileSizeLow >= 16) { - strcpy(szFileName, m_szInstrLibPath); - strncat(szFileName, wfd.cFileName, sizeof(szFileName)); - _splitpath(szFileName, NULL, NULL, NULL, s); + // Get lower-case file extension without dot. + const std::string ext = mpt::String::Encode(mpt::PathString::FromNative(wfd.cFileName).GetFileExt().ToWide(), mpt::CharsetUTF8); + char s[16]; + mpt::String::Copy(s, ext); if(s[0]) { @@ -1694,23 +1710,21 @@ } } - // Instruments + // Instruments if ((!strcmp(s, "xi")) - || (!strcmp(s, "iti")) - || (!strcmp(s, "pat")) ) + || (!strcmp(s, "iti")) + || (!strcmp(s, "pat")) ) { if (IsSampleBrowser()) { - ModTreeBuildTVIParam(tvis, wfd.cFileName, IMAGE_INSTRUMENTS); - InsertItem(&tvis); + ModTreeInsert(wfd.cFileName, IMAGE_INSTRUMENTS); } } else if(std::find_if(modExts.begin(), modExts.end(), find_str(s)) != modExts.end()) { // Songs if (!IsSampleBrowser()) { - ModTreeBuildTVIParam(tvis, wfd.cFileName, IMAGE_FOLDERSONG); - InsertItem(&tvis); + ModTreeInsert(wfd.cFileName, IMAGE_FOLDERSONG); } } else // Samples @@ -1749,12 +1763,11 @@ { if (IsSampleBrowser()) { - ModTreeBuildTVIParam(tvis, wfd.cFileName, IMAGE_SAMPLES); - InsertItem(&tvis); + ModTreeInsert(wfd.cFileName, IMAGE_SAMPLES); } } } - } while (FindNextFile(hFind, &wfd)); + } while (FindNextFileW(hFind, &wfd)); FindClose(hFind); } } @@ -1769,11 +1782,13 @@ } -void CModTree::ModTreeBuildTVIParam(TV_INSERTSTRUCT &tvis, LPCSTR lpszName, int iImage) -//------------------------------------------------------------------------------------- +// Insert sample browser item. +void CModTree::ModTreeInsert(const WCHAR *name, int image) +//-------------------------------------------------------- { + TV_INSERTSTRUCTW tvis; DWORD dwId = 0; - switch(iImage) + switch(image) { case IMAGE_FOLDERPARENT: dwId = 1; @@ -1785,7 +1800,7 @@ dwId = 3; break; case IMAGE_SAMPLES: - if (m_szSongName[0]) { dwId = 5; break; } + if(!m_szSongName.empty()) { dwId = 5; break; } case IMAGE_INSTRUMENTS: dwId = 4; break; @@ -1796,12 +1811,14 @@ tvis.item.hItem = 0; tvis.item.state = 0; tvis.item.stateMask = 0; - tvis.item.pszText = (LPSTR)lpszName; + tvis.item.pszText = const_cast<WCHAR *>(name); tvis.item.cchTextMax = 0; - tvis.item.iImage = iImage; - tvis.item.iSelectedImage = iImage; + tvis.item.iImage = image; + tvis.item.iSelectedImage = image; tvis.item.cChildren = 0; tvis.item.lParam = (LPARAM)dwId; + + ::SendMessage(m_hWnd, TVM_INSERTITEMW, 0, (LPARAM)&tvis); } @@ -1840,48 +1857,18 @@ } -BOOL CModTree::InstrumentLibraryChDir(LPCSTR lpszDir) -//--------------------------------------------------- +void CModTree::InstrumentLibraryChDir(mpt::PathString dir, bool isSong) +//--------------------------------------------------------------------- { - CHAR s[_MAX_PATH+80], sdrive[_MAX_DRIVE]; - BOOL bOk = FALSE, bSong = FALSE; + if(dir.empty()) return; - if ((!lpszDir) || (!lpszDir[0])) return FALSE; BeginWaitCursor(); - if (!GetCurrentDirectory(CountOf(s), s)) s[0] = 0; - if (!strcmp(lpszDir+1, ":\\")) + + bool ok = false; + if(isSong) { - sdrive[0] = lpszDir[0]; - sdrive[1] = lpszDir[1]; - sdrive[2] = 0; - lpszDir = sdrive; - } - SetCurrentDirectory(m_szInstrLibPath); - if (!lstrcmpi(lpszDir, "..")) - { - UINT k = strlen(m_szInstrLibPath); - if ((k > 0) && (m_szInstrLibPath[k-1] == '\\')) k--; - while ((k > 0) && (m_szInstrLibPath[k-1] != '\\')) k--; - m_szOldPath[0] = 0; - if (k > 0) - { - strcpy(m_szOldPath, &m_szInstrLibPath[k]); - k = strlen(m_szOldPath); - if ((k > 0) && (m_szOldPath[k-1] == '\\')) m_szOldPath[k-1] = 0; - } - } else - { - CFileStatus status; - if ((CFile::GetStatus(lpszDir, status)) && (!(status.m_attribute & CFile::directory))) - { - bSong = TRUE; - } - strcpy(m_szOldPath, ".."); - } - if (bSong) - { - GetCurrentDirectory(sizeof(m_szInstrLibPath), m_szInstrLibPath); - strcpy(m_szSongName, lpszDir); + m_szOldPath = MPT_PATHSTRING(".."); + m_szSongName = dir; if (m_pDataTree) { m_pDataTree->InsLibSetFullPath(m_szInstrLibPath, m_szSongName); @@ -1890,119 +1877,132 @@ { PostMessage(WM_COMMAND, ID_MODTREE_REFRESHINSTRLIB); } - bOk = TRUE; + ok = true; } else { - if(SetCurrentDirectory(lpszDir)) + if(dir == MPT_PATHSTRING("..")) { - m_szSongName[0] = 0; + // Go one dir up. + std::wstring prevDir = m_szInstrLibPath.GetPath().ToWide(); + std::wstring::size_type pos = prevDir.find_last_of(L"\\/", prevDir.length() - 2); + if(pos != std::wstring::npos) + { + prevDir = prevDir.substr(0, pos + 1); + } + dir = mpt::PathString::FromWide(prevDir); + } else + { + // Drives are formatted like "E:\", folders are just folder name without slash. + if(!dir.HasTrailingSlash()) + dir = m_szInstrLibPath + dir + MPT_PATHSTRING("\\"); + } + + if(GetFileAttributesW(dir.AsNative().c_str()) & FILE_ATTRIBUTE_DIRECTORY) + { + m_szSongName = MPT_PATHSTRING(""); delete m_SongFile; m_SongFile = nullptr; - GetCurrentDirectory(sizeof(m_szInstrLibPath), m_szInstrLibPath); + m_szInstrLibPath = dir; PostMessage(WM_COMMAND, ID_MODTREE_REFRESHINSTRLIB); - bOk = TRUE; + ok = true; } } - if (s[0]) SetCurrentDirectory(s); EndWaitCursor(); - if (!bOk) + + if(!ok) { - wsprintf(s, "Unable to browse to \"%s\"", lpszDir); + std::wstring s = L"Unable to browse to \"" + dir.AsNative() + L"\""; Reporting::Error(s); } - return TRUE; } -BOOL CModTree::GetDropInfo(LPDRAGONDROP pdropinfo, LPSTR pszFullPath) -//------------------------------------------------------------------- +bool CModTree::GetDropInfo(DRAGONDROP &dropInfo, mpt::PathString &fullPath) +//------------------------------------------------------------------------- { ModTreeDocInfo *pInfo = (m_nDragDocNdx < DocInfo.size() ? DocInfo[m_nDragDocNdx] : nullptr); - pdropinfo->pModDoc = (pInfo) ? pInfo->pModDoc : nullptr; - pdropinfo->dwDropType = DRAGONDROP_NOTHING; - pdropinfo->dwDropItem = m_itemDrag.val1; - pdropinfo->lDropParam = 0; + dropInfo.pModDoc = (pInfo) ? pInfo->pModDoc : nullptr; + dropInfo.dwDropType = DRAGONDROP_NOTHING; + dropInfo.dwDropItem = m_itemDrag.val1; + dropInfo.lDropParam = 0; switch(m_itemDrag.type) { case MODITEM_ORDER: - pdropinfo->dwDropType = DRAGONDROP_ORDER; + dropInfo.dwDropType = DRAGONDROP_ORDER; break; case MODITEM_PATTERN: - pdropinfo->dwDropType = DRAGONDROP_PATTERN; + dropInfo.dwDropType = DRAGONDROP_PATTERN; break; case MODITEM_SAMPLE: - pdropinfo->dwDropType = DRAGONDROP_SAMPLE; + dropInfo.dwDropType = DRAGONDROP_SAMPLE; break; case MODITEM_INSTRUMENT: - pdropinfo->dwDropType = DRAGONDROP_INSTRUMENT; + dropInfo.dwDropType = DRAGONDROP_INSTRUMENT; break; case MODITEM_SEQUENCE: case MODITEM_HDR_ORDERS: - pdropinfo->dwDropType = DRAGONDROP_SEQUENCE; + dropInfo.dwDropType = DRAGONDROP_SEQUENCE; break; case MODITEM_INSLIB_SAMPLE: case MODITEM_INSLIB_INSTRUMENT: - if (m_szSongName[0]) + if(!m_szSongName.empty()) { CHAR s[32]; mpt::String::CopyN(s, GetItemText(m_hItemDrag)); - UINT n = 0; - if (s[0] >= '0') n += (s[0] - '0'); - if ((s[1] >= '0') && (s[1] <= '9')) n = n*10 + (s[1] - '0'); - if ((s[2] >= '0') && (s[2] <= '9')) n = n*10 + (s[2] - '0'); - pdropinfo->dwDropType = (m_itemDrag.type == MODITEM_INSLIB_SAMPLE) ? DRAGONDROP_SAMPLE : DRAGONDROP_INSTRUMENT; - pdropinfo->dwDropItem = n; - pdropinfo->pModDoc = nullptr; - pdropinfo->lDropParam = (LPARAM)m_SongFile; + const uint32 n = ConvertStrTo<uint32>(s); + dropInfo.dwDropType = (m_itemDrag.type == MODITEM_INSLIB_SAMPLE) ? DRAGONDROP_SAMPLE : DRAGONDROP_INSTRUMENT; + dropInfo.dwDropItem = n; + dropInfo.pModDoc = nullptr; + dropInfo.lDropParam = (LPARAM)m_SongFile; } else { - InsLibGetFullPath(m_hItemDrag, pszFullPath); - pdropinfo->dwDropType = DRAGONDROP_SOUNDFILE; - pdropinfo->lDropParam = (LPARAM)pszFullPath; + fullPath = InsLibGetFullPath(m_hItemDrag); + dropInfo.dwDropType = DRAGONDROP_SOUNDFILE; + dropInfo.lDropParam = (LPARAM)&fullPath; } break; case MODITEM_MIDIPERCUSSION: - pdropinfo->dwDropItem |= 0x80; + dropInfo.dwDropItem |= 0x80; case MODITEM_MIDIINSTRUMENT: { - LPMIDILIBSTRUCT lpMidiLib = CTrackApp::GetMidiLibrary(); - if((lpMidiLib) && (!lpMidiLib->MidiMap[pdropinfo->dwDropItem&0xFF].empty())) + MIDILIBSTRUCT &midiLib = CTrackApp::GetMidiLibrary(); + if(!midiLib.MidiMap[dropInfo.dwDropItem & 0xFF].empty()) { - strcpy(pszFullPath, lpMidiLib->MidiMap[pdropinfo->dwDropItem&0xFF].ToLocale().c_str()); - pdropinfo->dwDropType = DRAGONDROP_MIDIINSTR; - pdropinfo->lDropParam = (LPARAM)pszFullPath; + fullPath = midiLib.MidiMap[dropInfo.dwDropItem & 0xFF]; + dropInfo.dwDropType = DRAGONDROP_MIDIINSTR; + dropInfo.lDropParam = (LPARAM)&fullPath; } } break; case MODITEM_INSLIB_SONG: - InsLibGetFullPath(m_hItemDrag, pszFullPath); - pdropinfo->pModDoc = NULL; - pdropinfo->dwDropType = DRAGONDROP_SONG; - pdropinfo->dwDropItem = 0; - pdropinfo->lDropParam = (LPARAM)pszFullPath; + fullPath = InsLibGetFullPath(m_hItemDrag); + dropInfo.pModDoc = NULL; + dropInfo.dwDropType = DRAGONDROP_SONG; + dropInfo.dwDropItem = 0; + dropInfo.lDropParam = (LPARAM)&fullPath; break; case MODITEM_DLSBANK_INSTRUMENT: { const DlsItem &item = *static_cast<const DlsItem *>(&m_itemDrag); ASSERT(item.IsInstr() || item.IsPercussion()); - pdropinfo->dwDropType = DRAGONDROP_DLS; + dropInfo.dwDropType = DRAGONDROP_DLS; // dwDropItem = DLS Bank # - pdropinfo->dwDropItem = item.GetBankIndex(); // bank # + dropInfo.dwDropItem = item.GetBankIndex(); // bank # // Melodic: (Instrument) // Drums: (0x80000000) | (Region << 16) | (Instrument) - pdropinfo->lDropParam = (LPARAM)((m_itemDrag.val1 & (DLS_TYPEPERC | DLS_REGIONMASK | DLS_INSTRMASK))); + dropInfo.lDropParam = (LPARAM)((m_itemDrag.val1 & (DLS_TYPEPERC | DLS_REGIONMASK | DLS_INSTRMASK))); } break; } - return (pdropinfo->dwDropType != DRAGONDROP_NOTHING); + return (dropInfo.dwDropType != DRAGONDROP_NOTHING); } @@ -2175,12 +2175,11 @@ { if (bDoDrop) { - CHAR szFullPath[_MAX_PATH] = ""; - InsLibGetFullPath(m_hItemDrag, szFullPath); + mpt::PathString fullPath = InsLibGetFullPath(m_hItemDrag); if (modItemDrop.type == MODITEM_MIDIINSTRUMENT) - SetMidiInstrument(modItemDropID, szFullPath); + SetMidiInstrument(modItemDropID, fullPath); else - SetMidiPercussion(modItemDropID, szFullPath); + SetMidiPercussion(modItemDropID, fullPath); } return true; } @@ -2583,7 +2582,7 @@ case MODITEM_INSLIB_SAMPLE: case MODITEM_INSLIB_INSTRUMENT: nDefault = ID_MODTREE_PLAY; - if (m_szSongName[0]) + if(!m_szSongName.empty()) { AppendMenu(hMenu, MF_STRING, ID_MODTREE_PLAY, "&Play"); } else @@ -2691,12 +2690,12 @@ if (m_hDropWnd) { DRAGONDROP dropinfo; - CHAR szFullPath[_MAX_PATH] = ""; - if (GetDropInfo(&dropinfo, szFullPath)) + mpt::PathString fullPath; + if(GetDropInfo(dropinfo, fullPath)) { if (dropinfo.dwDropType == DRAGONDROP_SONG) { - theApp.OpenDocumentFile((LPCTSTR)dropinfo.lDropParam); + theApp.OpenDocumentFile(fullPath.ToCString()); } else { ::SendMessage(m_hDropWnd, WM_MOD_DRAGONDROPPING, TRUE, (LPARAM)&dropinfo); @@ -2767,8 +2766,8 @@ if (hwnd != NULL) { DRAGONDROP dropinfo; - CHAR szFullPath[_MAX_PATH] = ""; - if (GetDropInfo(&dropinfo, szFullPath)) + mpt::PathString fullPath; + if(GetDropInfo(dropinfo, fullPath)) { if (dropinfo.dwDropType == DRAGONDROP_SONG) { @@ -3194,7 +3193,6 @@ BOOL CModTree::OnDrop(COleDataObject* pDataObject, DROPEFFECT, CPoint) //-------------------------------------------------------------------- { - TCHAR szFileName[_MAX_PATH] = ""; STGMEDIUM stgm; HDROP hDropInfo; UINT nFiles; @@ -3205,19 +3203,19 @@ if (stgm.tymed != TYMED_HGLOBAL) return FALSE; if (stgm.hGlobal == NULL) return FALSE; hDropInfo = (HDROP)stgm.hGlobal; - nFiles = DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); + nFiles = DragQueryFileW(hDropInfo, (UINT)-1, NULL, 0); if (nFiles) { - DragQueryFile(hDropInfo, 0, szFileName, _MAX_PATH); - if (szFileName[0]) + WCHAR fileName[_MAX_PATH]; + if(DragQueryFileW(hDropInfo, 0, fileName, _MAX_PATH)) { switch(m_itemDrag.type) { case MODITEM_MIDIINSTRUMENT: - bOk = SetMidiInstrument(m_itemDrag.val1, szFileName); + bOk = SetMidiInstrument(m_itemDrag.val1, mpt::PathString::FromNative(fileName)); break; case MODITEM_MIDIPERCUSSION: - bOk = SetMidiPercussion(m_itemDrag.val1, szFileName); + bOk = SetMidiPercussion(m_itemDrag.val1, mpt::PathString::FromNative(fileName)); break; } } @@ -3237,21 +3235,21 @@ if (!IsSampleBrowser()) { hActive = NULL; - if ((m_szOldPath[0]) || (m_szSongName[0])) + if(!m_szOldPath.empty() || !m_szSongName.empty()) { HTREEITEM hItem = GetChildItem(m_hInsLib); while (hItem != NULL) { - CString str = GetItemText(hItem); - if (((m_szSongName[0]) && (!lstrcmpi(str, m_szSongName))) - || ((!m_szSongName[0]) && (!lstrcmpi(str, m_szOldPath)))) + 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))) { hActive = hItem; break; } hItem = GetNextItem(hItem, TVGN_NEXT); } - if (!m_szSongName[0]) m_szOldPath[0] = 0; + if(m_szSongName.empty()) m_szOldPath = MPT_PATHSTRING(""); } SelectSetFirstVisible(m_hInsLib); if (hActive != NULL) SelectItem(hActive); Modified: trunk/OpenMPT/mptrack/View_tre.h =================================================================== --- trunk/OpenMPT/mptrack/View_tre.h 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/mptrack/View_tre.h 2013-11-10 18:17:47 UTC (rev 3181) @@ -173,7 +173,8 @@ std::vector<ModTreeDocInfo *> DocInfo; // Instrument library bool m_bShowAllFiles, doLabelEdit; - CHAR m_szInstrLibPath[_MAX_PATH], m_szOldPath[_MAX_PATH], m_szSongName[_MAX_PATH]; + mpt::PathString m_szInstrLibPath, m_szOldPath; + mpt::PathString m_szSongName; // Name of open module, without path (== m_szInstrLibPath). public: CModTree(CModTree *pDataTree); @@ -182,23 +183,23 @@ // Attributes public: void Init(); - void InsLibSetFullPath(LPCSTR pszLibPath, LPCSTR pszSongFolder); - void InsLibGetFullPath(HTREEITEM hItem, LPSTR pszFullPath) const; + void InsLibSetFullPath(const mpt::PathString &libPath, const mpt::PathString &songFolder); + mpt::PathString InsLibGetFullPath(HTREEITEM hItem) const; void RefreshMidiLibrary(); void RefreshDlsBanks(); void RefreshInstrumentLibrary(); void EmptyInstrumentLibrary(); void FillInstrumentLibrary(); ModItem GetModItem(HTREEITEM hItem); - BOOL SetMidiInstrument(UINT nIns, LPCTSTR lpszFileName); - BOOL SetMidiPercussion(UINT nPerc, LPCTSTR lpszFileName); + BOOL SetMidiInstrument(UINT nIns, const mpt::PathString &fileName); + BOOL SetMidiPercussion(UINT nPerc, const mpt::PathString &fileName); BOOL ExecuteItem(HTREEITEM hItem); BOOL DeleteTreeItem(HTREEITEM hItem); BOOL PlayItem(HTREEITEM hItem, ModCommand::NOTE nParam); BOOL OpenTreeItem(HTREEITEM hItem); BOOL OpenMidiInstrument(DWORD dwItem); - BOOL InstrumentLibraryChDir(LPCSTR lpszDir); - BOOL GetDropInfo(LPDRAGONDROP pdropinfo, LPSTR lpszPath); + void InstrumentLibraryChDir(mpt::PathString dir, bool isSong); + bool GetDropInfo(DRAGONDROP &dropInfo, mpt::PathString &fullPath); void OnOptionsChanged(); void AddDocument(CModDoc *pModDoc); void RemoveDocument(CModDoc *pModDoc); @@ -212,6 +213,9 @@ bool IsSampleBrowser() const { return m_pDataTree == nullptr; } + std::wstring GetItemTextW(HTREEITEM item) const; + void SetItemTextW(HTREEITEM item, const WCHAR *text); + // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CModTree) @@ -228,7 +232,7 @@ protected: static int CALLBACK ModTreeInsLibCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); static int CALLBACK ModTreeDrumCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); - void ModTreeBuildTVIParam(TV_INSERTSTRUCT &tvis, LPCSTR lpszName, int iImage); + void ModTreeInsert(const WCHAR *name, int image); CModDoc *GetDocumentFromItem(HTREEITEM hItem); ModTreeDocInfo *GetDocumentInfoFromModDoc(CModDoc *pModDoc); Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2013-11-10 17:47:59 UTC (rev 3180) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-11-10 18:17:47 UTC (rev 3181) @@ -675,7 +675,7 @@ m_nMinPeriod = 8; m_nMaxPeriod = 0xF000; - const PATTERNINDEX numPats = std::min(static_cast<PATTERNINDEX>(patPos.size()), GetModSpecifications().patternsMax); + PATTERNINDEX numPats = std::min(static_cast<PATTERNINDEX>(patPos.size()), GetModSpecifications().patternsMax); if(numPats != patPos.size()) { @@ -683,10 +683,15 @@ AddToLog(mpt::String::Format(str_PatternSetTruncationNote, (unsigned int)patPos.size(), numPats)); } + if(!(loadFlags & loadPatternData)) + { + numPats = 0; + } + // Checking for number of used channels, which is not explicitely specified in the file. for(PATTERNINDEX pat = 0; pat < numPats; pat++) { - if(!(loadFlags & loadPatternData) || patPos[pat] == 0 || !file.Seek(patPos[pat])) + if(patPos[pat] == 0 || !file.Seek(patPos[pat])) continue; uint16 len = file.ReadUint16LE(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-10 19:10:34
|
Revision: 3184 http://sourceforge.net/p/modplug/code/3184 Author: manxorist Date: 2013-11-10 19:10:25 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] Split mpt::PathString into its own header file. Modified Paths: -------------- trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/common/stdafx.h trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters Added Paths: ----------- trunk/OpenMPT/common/mptPathString.cpp trunk/OpenMPT/common/mptPathString.h Added: trunk/OpenMPT/common/mptPathString.cpp =================================================================== --- trunk/OpenMPT/common/mptPathString.cpp (rev 0) +++ trunk/OpenMPT/common/mptPathString.cpp 2013-11-10 19:10:25 UTC (rev 3184) @@ -0,0 +1,183 @@ +/* + * mptPathString.cpp + * ----------------- + * Purpose: Wrapper class around the platform-native representation of path names. Should be the only type that is used to store path names. + * Notes : Currently none. + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + +#include "stdafx.h" +#include "mptPathString.h" + + +#if defined(MODPLUG_TRACKER) + +namespace mpt +{ + +void PathString::SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const +//------------------------------------------------------------------------------------------------------ +{ + wchar_t tempDrive[_MAX_DRIVE]; + wchar_t tempDir[_MAX_DIR]; + wchar_t tempFname[_MAX_FNAME]; + wchar_t tempExt[_MAX_EXT]; + _wsplitpath(path.c_str(), tempDrive, tempDir, tempFname, tempExt); + if(drive) *drive = mpt::PathString::FromNative(tempDrive); + if(dir) *dir = mpt::PathString::FromNative(tempDir); + if(fname) *fname = mpt::PathString::FromNative(tempFname); + if(ext) *ext = mpt::PathString::FromNative(tempExt); +} + +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; +} + +} // namespace mpt + +#endif + + +FILE * mpt_fopen(const mpt::PathString &filename, const char *mode) +//----------------------------------------------------------------- +{ + #if defined(WIN32) + return _wfopen(filename.AsNative().c_str(), mode ? mpt::String::Decode(mode, mpt::CharsetLocale).c_str() : nullptr); + #else // !WIN32 + return fopen(filename.AsNative().c_str(), mode); + #endif // WIN32 +} + +FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode) +//-------------------------------------------------------------------- +{ + #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); + #endif // WIN32 +} + + +#if defined(MODPLUG_TRACKER) + +static inline char SanitizeFilenameChar(char c) +//--------------------------------------------- +{ + if( c == '\\' || + c == '\"' || + c == '/' || + c == ':' || + c == '?' || + c == '<' || + c == '>' || + c == '*') + { + c = '_'; + } + return c; +} + +static inline wchar_t SanitizeFilenameChar(wchar_t c) +//--------------------------------------------------- +{ + if( c == L'\\' || + c == L'\"' || + c == L'/' || + c == L':' || + c == L'?' || + c == L'<' || + c == L'>' || + c == L'*') + { + c = L'_'; + } + return c; +} + +void SanitizeFilename(mpt::PathString &filename) +//---------------------------------------------- +{ + mpt::RawPathString tmp = filename.AsNative(); + for(mpt::RawPathString::iterator it = tmp.begin(); it != tmp.end(); ++it) + { + *it = SanitizeFilenameChar(*it); + } + filename = mpt::PathString::FromNative(tmp); +} + +void SanitizeFilename(char *beg, char *end) +//----------------------------------------- +{ + for(char *it = beg; it != end; ++it) + { + *it = SanitizeFilenameChar(*it); + } +} + +void SanitizeFilename(wchar_t *beg, wchar_t *end) +//----------------------------------------------- +{ + for(wchar_t *it = beg; it != end; ++it) + { + *it = SanitizeFilenameChar(*it); + } +} + +void SanitizeFilename(std::string &str) +//------------------------------------- +{ + for(size_t i = 0; i < str.length(); i++) + { + str[i] = SanitizeFilenameChar(str[i]); + } +} + +void SanitizeFilename(std::wstring &str) +//-------------------------------------- +{ + for(size_t i = 0; i < str.length(); i++) + { + str[i] = SanitizeFilenameChar(str[i]); + } +} + +#if defined(_MFC_VER) +void SanitizeFilename(CString &str) +//--------------------------------- +{ + std::basic_string<TCHAR> tmp = str; + SanitizeFilename(tmp); + str = tmp.c_str(); +} +#endif + +#endif // MODPLUG_TRACKER Property changes on: trunk/OpenMPT/common/mptPathString.cpp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-c++src \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h (rev 0) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-10 19:10:25 UTC (rev 3184) @@ -0,0 +1,196 @@ +/* + * mptPathString.h + * --------------- + * Purpose: Wrapper class around the platform-native representation of path names. Should be the only type that is used to store path names. + * Notes : Currently none. + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#pragma once + +//#define MPT_DEPRECATED_PATH +#define MPT_DEPRECATED_PATH MPT_DEPRECATED + +namespace mpt +{ + +#if defined(WIN32) +typedef std::wstring RawPathString; +#else // !WIN32 +typedef std::string RawPathString; +#endif // WIN32 + +class PathString +{ +private: + RawPathString path; +private: + PathString(const RawPathString & path) + : path(path) + { + return; + } +public: + PathString() + { + return; + } + PathString(const PathString & other) + : path(other.path) + { + return; + } + PathString & assign(const PathString & other) + { + path = other.path; + return *this; + } + PathString & operator = (const PathString & other) + { + return assign(other); + } + PathString & append(const PathString & other) + { + path.append(other.path); + return *this; + } + PathString & operator += (const PathString & other) + { + return append(other); + } + friend PathString operator + (const PathString & a, const PathString & b) + { + 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(); + } + bool empty() const { return path.empty(); } + const RawPathString &NativeRef() const + { + return path; + } + +#if defined(WIN32) + static int CompareNoCase(const PathString & a, const PathString & b) + { + return lstrcmpiW(a.ToWide().c_str(), b.ToWide().c_str()); + } +#endif + +public: + +#if defined(MODPLUG_TRACKER) + + void SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const; + PathString GetDrive() const; + PathString GetDir() const; + PathString GetPath() const; + PathString GetFileName() const; + PathString GetFileExt() const; + + bool HasTrailingSlash() const + { + if(empty()) + return false; +#if defined(WIN32) + if(path[path.length()-1] == L'\\' || path[path.length()-1] == L'/') + return true; +#else + if(path[path.length()-1] == '/') + return true; +#endif + return false; + } + +#endif // MODPLUG_TRACKER + +public: + +#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); } + 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)); } + 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)); } +#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); } + 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)); } + RawPathString AsNative() const { return path; } + static PathString FromNative(const RawPathString &path) { return PathString(path); } + +#endif // WIN32 + +}; + +} // namespace mpt + +#if defined(WIN32) + +#define MPT_PATHSTRING(x) mpt::PathString::FromNative( L ## x ) + +#else // !WIN32 + +#define MPT_PATHSTRING(x) mpt::PathString::FromNative( x ) + +#endif // WIN32 + +FILE * mpt_fopen(const mpt::PathString &filename, const char *mode); +FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode); + +#if defined(MODPLUG_TRACKER) + +// Sanitize a filename (remove special chars) +void SanitizeFilename(mpt::PathString &filename); + +void SanitizeFilename(char *beg, char *end); +void SanitizeFilename(wchar_t *beg, wchar_t *end); + +void SanitizeFilename(std::string &str); +void SanitizeFilename(std::wstring &str); + +template <std::size_t size> +void SanitizeFilename(char (&buffer)[size]) +//----------------------------------------- +{ + STATIC_ASSERT(size > 0); + SanitizeFilename(buffer, buffer + size); +} + +template <std::size_t size> +void SanitizeFilename(wchar_t (&buffer)[size]) +//-------------------------------------------- +{ + STATIC_ASSERT(size > 0); + SanitizeFilename(buffer, buffer + size); +} + +#if defined(_MFC_VER) +MPT_DEPRECATED_PATH void SanitizeFilename(CString &str); +#endif + +#endif // MODPLUG_TRACKER Property changes on: trunk/OpenMPT/common/mptPathString.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-10 19:05:34 UTC (rev 3183) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-10 19:10:25 UTC (rev 3184) @@ -294,174 +294,3 @@ } } // namespace mpt::String - -#if defined(MODPLUG_TRACKER) - -namespace mpt -{ - -void PathString::SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const -//------------------------------------------------------------------------------------------------------ -{ - wchar_t tempDrive[_MAX_DRIVE]; - wchar_t tempDir[_MAX_DIR]; - wchar_t tempFname[_MAX_FNAME]; - wchar_t tempExt[_MAX_EXT]; - _wsplitpath(path.c_str(), tempDrive, tempDir, tempFname, tempExt); - if(drive) *drive = mpt::PathString::FromNative(tempDrive); - if(dir) *dir = mpt::PathString::FromNative(tempDir); - if(fname) *fname = mpt::PathString::FromNative(tempFname); - if(ext) *ext = mpt::PathString::FromNative(tempExt); -} - -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; -} - -} // namespace mpt - -#endif - - -FILE * mpt_fopen(const mpt::PathString &filename, const char *mode) -//----------------------------------------------------------------- -{ - #if defined(WIN32) - return _wfopen(filename.AsNative().c_str(), mode ? mpt::String::Decode(mode, mpt::CharsetLocale).c_str() : nullptr); - #else // !WIN32 - return fopen(filename.AsNative().c_str(), mode); - #endif // WIN32 -} - -FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode) -//-------------------------------------------------------------------- -{ - #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); - #endif // WIN32 -} - - -#if defined(MODPLUG_TRACKER) - -static inline char SanitizeFilenameChar(char c) -//--------------------------------------------- -{ - if( c == '\\' || - c == '\"' || - c == '/' || - c == ':' || - c == '?' || - c == '<' || - c == '>' || - c == '*') - { - c = '_'; - } - return c; -} - -static inline wchar_t SanitizeFilenameChar(wchar_t c) -//--------------------------------------------------- -{ - if( c == L'\\' || - c == L'\"' || - c == L'/' || - c == L':' || - c == L'?' || - c == L'<' || - c == L'>' || - c == L'*') - { - c = L'_'; - } - return c; -} - -void SanitizeFilename(mpt::PathString &filename) -//---------------------------------------------- -{ - mpt::RawPathString tmp = filename.AsNative(); - for(mpt::RawPathString::iterator it = tmp.begin(); it != tmp.end(); ++it) - { - *it = SanitizeFilenameChar(*it); - } - filename = mpt::PathString::FromNative(tmp); -} - -void SanitizeFilename(char *beg, char *end) -//----------------------------------------- -{ - for(char *it = beg; it != end; ++it) - { - *it = SanitizeFilenameChar(*it); - } -} - -void SanitizeFilename(wchar_t *beg, wchar_t *end) -//----------------------------------------------- -{ - for(wchar_t *it = beg; it != end; ++it) - { - *it = SanitizeFilenameChar(*it); - } -} - -void SanitizeFilename(std::string &str) -//------------------------------------- -{ - for(size_t i = 0; i < str.length(); i++) - { - str[i] = SanitizeFilenameChar(str[i]); - } -} - -void SanitizeFilename(std::wstring &str) -//-------------------------------------- -{ - for(size_t i = 0; i < str.length(); i++) - { - str[i] = SanitizeFilenameChar(str[i]); - } -} - -#if defined(_MFC_VER) -void SanitizeFilename(CString &str) -//--------------------------------- -{ - std::basic_string<TCHAR> tmp = str; - SanitizeFilename(tmp); - str = tmp.c_str(); -} -#endif - -#endif // MODPLUG_TRACKER Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-10 19:05:34 UTC (rev 3183) +++ trunk/OpenMPT/common/mptString.h 2013-11-10 19:10:25 UTC (rev 3184) @@ -178,186 +178,4 @@ } // namespace String - - -//#define MPT_DEPRECATED_PATH -#define MPT_DEPRECATED_PATH MPT_DEPRECATED - -#if defined(WIN32) -typedef std::wstring RawPathString; -#else // !WIN32 -typedef std::string RawPathString; -#endif // WIN32 - -class PathString -{ -private: - RawPathString path; -private: - PathString(const RawPathString & path) - : path(path) - { - return; - } -public: - PathString() - { - return; - } - PathString(const PathString & other) - : path(other.path) - { - return; - } - PathString & assign(const PathString & other) - { - path = other.path; - return *this; - } - PathString & operator = (const PathString & other) - { - return assign(other); - } - PathString & append(const PathString & other) - { - path.append(other.path); - return *this; - } - PathString & operator += (const PathString & other) - { - return append(other); - } - friend PathString operator + (const PathString & a, const PathString & b) - { - 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(); - } - bool empty() const { return path.empty(); } - const RawPathString &NativeRef() const - { - return path; - } - -#if defined(WIN32) - static int CompareNoCase(const PathString & a, const PathString & b) - { - return lstrcmpiW(a.ToWide().c_str(), b.ToWide().c_str()); - } -#endif - -public: - -#if defined(MODPLUG_TRACKER) - - void SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const; - PathString GetDrive() const; - PathString GetDir() const; - PathString GetPath() const; - PathString GetFileName() const; - PathString GetFileExt() const; - - bool HasTrailingSlash() const - { - if(empty()) - return false; -#if defined(WIN32) - if(path[path.length()-1] == L'\\' || path[path.length()-1] == L'/') - return true; -#else - if(path[path.length()-1] == '/') - return true; -#endif - return false; - } - -#endif // MODPLUG_TRACKER - -public: - -#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); } - 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)); } - 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)); } -#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); } - 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)); } - RawPathString AsNative() const { return path; } - static PathString FromNative(const RawPathString &path) { return PathString(path); } - -#endif // WIN32 - -}; - } // namespace mpt - -#if defined(WIN32) - -#define MPT_PATHSTRING(x) mpt::PathString::FromNative( L ## x ) - -#else // !WIN32 - -#define MPT_PATHSTRING(x) mpt::PathString::FromNative( x ) - -#endif // WIN32 - -FILE * mpt_fopen(const mpt::PathString &filename, const char *mode); -FILE * mpt_fopen(const mpt::PathString &filename, const wchar_t *mode); - -#if defined(MODPLUG_TRACKER) - -// Sanitize a filename (remove special chars) -void SanitizeFilename(mpt::PathString &filename); - -void SanitizeFilename(char *beg, char *end); -void SanitizeFilename(wchar_t *beg, wchar_t *end); - -void SanitizeFilename(std::string &str); -void SanitizeFilename(std::wstring &str); - -template <std::size_t size> -void SanitizeFilename(char (&buffer)[size]) -//----------------------------------------- -{ - STATIC_ASSERT(size > 0); - SanitizeFilename(buffer, buffer + size); -} - -template <std::size_t size> -void SanitizeFilename(wchar_t (&buffer)[size]) -//-------------------------------------------- -{ - STATIC_ASSERT(size > 0); - SanitizeFilename(buffer, buffer + size); -} - -#if defined(_MFC_VER) -MPT_DEPRECATED_PATH void SanitizeFilename(CString &str); -#endif - -#endif // MODPLUG_TRACKER Modified: trunk/OpenMPT/common/stdafx.h =================================================================== --- trunk/OpenMPT/common/stdafx.h 2013-11-10 19:05:34 UTC (rev 3183) +++ trunk/OpenMPT/common/stdafx.h 2013-11-10 19:10:25 UTC (rev 3184) @@ -63,6 +63,8 @@ // <cstdio> // <stdio.h> // <windows.h> or just basic typedefs found in there +#include "../common/mptString.h" +#include "../common/mptPathString.h" //{{AFX_INSERT_LOCATION}} Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-11-10 19:05:34 UTC (rev 3183) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-11-10 19:10:25 UTC (rev 3184) @@ -416,6 +416,7 @@ <ClInclude Include="..\common\Logging.h" /> <ClInclude Include="..\common\misc_util.h" /> <ClInclude Include="..\common\mptFstream.h" /> + <ClInclude Include="..\common\mptPathString.h" /> <ClInclude Include="..\common\mptString.h" /> <ClInclude Include="..\common\mutex.h" /> <ClInclude Include="..\common\Profiler.h" /> @@ -486,6 +487,7 @@ <ItemGroup> <ClCompile Include="..\common\AudioCriticalSection.cpp" /> <ClCompile Include="..\common\misc_util.cpp" /> + <ClCompile Include="..\common\mptPathString.cpp" /> <ClCompile Include="..\common\mptString.cpp" /> <ClCompile Include="..\common\Profiler.cpp" /> <ClCompile Include="..\common\serialization_utils.cpp" /> Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-11-10 19:05:34 UTC (rev 3183) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-11-10 19:10:25 UTC (rev 3184) @@ -257,6 +257,9 @@ <ClInclude Include="..\common\mptFstream.h"> <Filter>Header Files\common</Filter> </ClInclude> + <ClInclude Include="..\common\mptPathString.h"> + <Filter>Header Files\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\common\AudioCriticalSection.cpp"> @@ -517,5 +520,8 @@ <ClCompile Include="..\include\miniz\miniz.c"> <Filter>Source Files\miniz</Filter> </ClCompile> + <ClCompile Include="..\common\mptPathString.cpp"> + <Filter>Source Files\common</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-11-10 19:05:34 UTC (rev 3183) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-11-10 19:10:25 UTC (rev 3184) @@ -443,6 +443,10 @@ > </File> <File + RelativePath="..\common\mptPathString.cpp" + > + </File> + <File RelativePath=".\mptrack.cpp" > </File> @@ -1053,6 +1057,10 @@ > </File> <File + RelativePath="..\common\mptPathString.h" + > + </File> + <File RelativePath=".\mptrack.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-11-10 19:05:34 UTC (rev 3183) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-11-10 19:10:25 UTC (rev 3184) @@ -440,6 +440,7 @@ <ItemGroup> <ClCompile Include="..\common\AudioCriticalSection.cpp" /> <ClCompile Include="..\common\misc_util.cpp" /> + <ClCompile Include="..\common\mptPathString.cpp" /> <ClCompile Include="..\common\mptString.cpp" /> <ClCompile Include="..\common\Profiler.cpp" /> <ClCompile Include="..\common\serialization_utils.cpp" /> @@ -624,6 +625,7 @@ <ClInclude Include="..\common\Logging.h" /> <ClInclude Include="..\common\misc_util.h" /> <ClInclude Include="..\common\mptFstream.h" /> + <ClInclude Include="..\common\mptPathString.h" /> <ClInclude Include="..\common\mptString.h" /> <ClInclude Include="..\common\mutex.h" /> <ClInclude Include="..\common\Profiler.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-11-10 19:05:34 UTC (rev 3183) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-11-10 19:10:25 UTC (rev 3184) @@ -490,6 +490,9 @@ <ClCompile Include="FileDialog.cpp"> <Filter>Source Files\mptrack</Filter> </ClCompile> + <ClCompile Include="..\common\mptPathString.cpp"> + <Filter>Source Files\common</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\soundlib\Loaders.h"> @@ -945,6 +948,9 @@ <ClInclude Include="FileDialog.h"> <Filter>Header Files\mptrack</Filter> </ClInclude> + <ClInclude Include="..\common\mptPathString.h"> + <Filter>Header Files\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-10 22:22:11
|
Revision: 3186 http://sourceforge.net/p/modplug/code/3186 Author: saga-games Date: 2013-11-10 22:22:01 +0000 (Sun, 10 Nov 2013) Log Message: ----------- [Ref] More unicode conversion in treeview + select plugin dialog. Introduce a new class, CTreeCtrlW, which adds unicode variants of some CTreeCtrl functions in non-unicode builds. [Fix] Deleting files in treeview broke during unicode conversion. Modified Paths: -------------- trunk/OpenMPT/common/mptPathString.cpp trunk/OpenMPT/common/mptPathString.h trunk/OpenMPT/mptrack/SelectPluginDialog.cpp trunk/OpenMPT/mptrack/SelectPluginDialog.h trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/mptrack/View_tre.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters Added Paths: ----------- trunk/OpenMPT/mptrack/CTreeCtrl.h Modified: trunk/OpenMPT/common/mptPathString.cpp =================================================================== --- trunk/OpenMPT/common/mptPathString.cpp 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/common/mptPathString.cpp 2013-11-10 22:22:01 UTC (rev 3186) @@ -60,6 +60,12 @@ SplitPath(nullptr, nullptr, nullptr, &ext); return ext; } +PathString PathString::GetFullFileName() const +{ + PathString name, ext; + SplitPath(nullptr, nullptr, &name, &ext); + return name + ext; +} } // namespace mpt Modified: trunk/OpenMPT/common/mptPathString.h =================================================================== --- trunk/OpenMPT/common/mptPathString.h 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/common/mptPathString.h 2013-11-10 22:22:01 UTC (rev 3186) @@ -90,21 +90,23 @@ #if defined(MODPLUG_TRACKER) void SplitPath(PathString *drive, PathString *dir, PathString *fname, PathString *ext) const; - PathString GetDrive() const; - PathString GetDir() const; - PathString GetPath() const; - PathString GetFileName() const; - PathString GetFileExt() const; + PathString GetDrive() const; // Drive letter + colon, e.g. "C:" + PathString GetDir() const; // Directory, e.g. "\OpenMPT\" + PathString GetPath() const; // Drive + Dir, e.g. "C:\OpenMPT\" + PathString GetFileName() const; // File name without extension, e.g. "mptrack" + PathString GetFileExt() const; // Extension including dot, e.g. ".exe" + PathString GetFullFileName() const; // File name + extension, e.g. "mptrack.exe" bool HasTrailingSlash() const { if(empty()) return false; + const RawPathString::value_type &c = path[path.length() - 1]; #if defined(WIN32) - if(path[path.length()-1] == L'\\' || path[path.length()-1] == L'/') + if(c == L'\\' || c == L'/') return true; #else - if(path[path.length()-1] == '/') + if(c == '/') return true; #endif return false; Added: trunk/OpenMPT/mptrack/CTreeCtrl.h =================================================================== --- trunk/OpenMPT/mptrack/CTreeCtrl.h (rev 0) +++ trunk/OpenMPT/mptrack/CTreeCtrl.h 2013-11-10 22:22:01 UTC (rev 3186) @@ -0,0 +1,123 @@ +/* + * CTreeCtrl.h + * ----------- + * Purpose: A class that extends MFC's CTreeCtrl to handle unicode strings in ANSI builds. + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#pragma once + + +class CTreeCtrlW : public CTreeCtrl +{ +public: + +#ifndef UNICODE + BOOL GetItem(TVITEMW *pItem) const + { + return ::SendMessage(m_hWnd, TVM_GETITEMW, 0, (LPARAM)pItem) ? TRUE : FALSE; + } + + BOOL SetItem(TVITEMW *pItem) + { + return ::SendMessage(m_hWnd, TVM_SETITEMW, 0, (LPARAM)pItem) ? TRUE : FALSE; + } + BOOL SetItem(HTREEITEM hItem, UINT nMask, const WCHAR *lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam) + { + TVITEMW tvi; + MemsetZero(tvi); + tvi.hItem = hItem; + tvi.mask = nMask; + tvi.state = nState; + tvi.stateMask = nStateMask; + tvi.iImage = nImage; + tvi.iSelectedImage = nSelectedImage; + tvi.pszText = const_cast<WCHAR *>(lpszItem); + tvi.lParam = lParam; + return SetItem(&tvi); + } + + HTREEITEM InsertItem(TVINSERTSTRUCTW &tvi) + { + return (HTREEITEM)::SendMessage(m_hWnd, TVM_INSERTITEMW, 0, (LPARAM)&tvi); + } + HTREEITEM InsertItem(UINT nMask, const WCHAR *lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent, HTREEITEM hInsertAfter) + { + TVINSERTSTRUCTW tvi; + MemsetZero(tvi); + tvi.hInsertAfter = hInsertAfter; + tvi.hParent = hParent; + tvi.item.mask = nMask; + tvi.item.state = nState; + tvi.item.stateMask = nStateMask; + tvi.item.iImage = nImage; + tvi.item.iSelectedImage = nSelectedImage; + tvi.item.pszText = const_cast<WCHAR *>(lpszItem); + tvi.item.lParam = lParam; + return InsertItem(tvi); + } + HTREEITEM InsertItem(const WCHAR *lpszItem, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST) + { + TVINSERTSTRUCTW tvi; + MemsetZero(tvi); + tvi.hInsertAfter = hInsertAfter; + tvi.hParent = hParent; + tvi.item.mask = TVIF_TEXT; + tvi.item.pszText = const_cast<WCHAR *>(lpszItem); + return InsertItem(tvi); + } + HTREEITEM InsertItem(const WCHAR *lpszItem, int nImage, int nSelectedImage, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST) + { + TVINSERTSTRUCTW tvi; + MemsetZero(tvi); + tvi.hInsertAfter = hInsertAfter; + tvi.hParent = hParent; + tvi.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE; + tvi.item.iImage = nImage; + tvi.item.iSelectedImage = nSelectedImage; + tvi.item.pszText = const_cast<WCHAR *>(lpszItem); + return InsertItem(tvi); + } + + void SetItemText(HTREEITEM item, const WCHAR *text) + { + TVITEMW tvi; + MemsetZero(tvi); + tvi.hItem = item; + tvi.mask = TVIF_TEXT; + tvi.pszText = const_cast<WCHAR *>(text); + ::SendMessage(m_hWnd, TVM_SETITEMW, 0, (LPARAM)&tvi); + } + +#endif // UNICODE + + std::wstring GetItemTextW(HTREEITEM item) const + { +#ifdef UNICODE + return GetItemText(item); +#else + WCHAR name[MAX_PATH]; // Maximum displayed text length according to documentation. + TVITEMW tvi; + MemsetZero(tvi); + tvi.hItem = item; + tvi.mask = TVIF_TEXT; + tvi.pszText = name; + tvi.cchTextMax = CountOf(name); + if(GetItem(&tvi)) + { + return tvi.pszText; + } else + { + return std::wstring(); + } +#endif // UNICODE + } + + using CTreeCtrl::GetItem; + using CTreeCtrl::SetItem; + using CTreeCtrl::SetItemText; + using CTreeCtrl::InsertItem; +}; Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.cpp 2013-11-10 22:22:01 UTC (rev 3186) @@ -250,22 +250,22 @@ static const struct { VSTPluginLib::PluginCategory category; - const char *description; + const WCHAR *description; } categories[] = { - { VSTPluginLib::catEffect, "Audio Effects" }, - { VSTPluginLib::catGenerator, "Tone Generators" }, - { VSTPluginLib::catRestoration, "Audio Restauration" }, - { VSTPluginLib::catSurroundFx, "Surround Effects" }, - { VSTPluginLib::catRoomFx, "Room Effects" }, - { VSTPluginLib::catSpacializer, "Spacializers" }, - { VSTPluginLib::catMastering, "Mastering Plugins" }, - { VSTPluginLib::catAnalysis, "Analysis Plugins" }, - { VSTPluginLib::catOfflineProcess, "Offline Processing" }, - { VSTPluginLib::catShell, "Shell Plugins" }, - { VSTPluginLib::catUnknown, "Unsorted" }, - { VSTPluginLib::catDMO, "DirectX Media Audio Effects" }, - { VSTPluginLib::catSynth, "Instrument Plugins" }, + { VSTPluginLib::catEffect, L"Audio Effects" }, + { VSTPluginLib::catGenerator, L"Tone Generators" }, + { VSTPluginLib::catRestoration, L"Audio Restauration" }, + { VSTPluginLib::catSurroundFx, L"Surround Effects" }, + { VSTPluginLib::catRoomFx, L"Room Effects" }, + { VSTPluginLib::catSpacializer, L"Spacializers" }, + { VSTPluginLib::catMastering, L"Mastering Plugins" }, + { VSTPluginLib::catAnalysis, L"Analysis Plugins" }, + { VSTPluginLib::catOfflineProcess, L"Offline Processing" }, + { VSTPluginLib::catShell, L"Shell Plugins" }, + { VSTPluginLib::catUnknown, L"Unsorted" }, + { VSTPluginLib::catDMO, L"DirectX Media Audio Effects" }, + { VSTPluginLib::catSynth, L"Instrument Plugins" }, }; std::bitset<VSTPluginLib::numCategories> categoryUsed; @@ -276,7 +276,7 @@ categoryFolders[categories[i].category] = AddTreeItem(categories[i].description, IMAGE_FOLDER, false); } - HTREEITEM noPlug = AddTreeItem("No plugin (empty slot)", IMAGE_NOPLUGIN, false); + HTREEITEM noPlug = AddTreeItem(L"No plugin (empty slot)", IMAGE_NOPLUGIN, false); HTREEITEM currentPlug = noPlug; bool foundCurrentPlug = false; @@ -299,7 +299,7 @@ } } - HTREEITEM h = AddTreeItem(p->libraryName.ToCString(), p->isInstrument ? IMAGE_PLUGININSTRUMENT : IMAGE_EFFECTPLUGIN, true, categoryFolders[p->category], reinterpret_cast<LPARAM>(p)); + 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; if(nameFilterActive) @@ -375,18 +375,9 @@ } -HTREEITEM CSelectPluginDlg::AddTreeItem(const TCHAR *title, int image, bool sort, HTREEITEM hParent, LPARAM lParam) +HTREEITEM CSelectPluginDlg::AddTreeItem(const WCHAR *title, int image, bool sort, HTREEITEM hParent, LPARAM lParam) //----------------------------------------------------------------------------------------------------------------- { - /*TVINSERTSTRUCTW tvi; - MemsetZero(tvi); - tvi.hInsertAfter = (sort ? TVI_SORT : TVI_FIRST); - tvi.hParent = hParent; - tvi.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT; - tvi.item.iImage = tvi.item.iSelectedImage = image; - tvi.item.pszText = title; - tvi.item.lParam = lParam; - return (HTREEITEM)::SendMessage(m_treePlugins.m_hWnd, TVM_INSERTITEMW, 0, (LPARAM)&tvi);*/ return m_treePlugins.InsertItem( TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM | TVIF_TEXT, title, Modified: trunk/OpenMPT/mptrack/SelectPluginDialog.h =================================================================== --- trunk/OpenMPT/mptrack/SelectPluginDialog.h 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/mptrack/SelectPluginDialog.h 2013-11-10 22:22:01 UTC (rev 3186) @@ -14,6 +14,7 @@ #define SELECTPLUGINDIALOG_H #include "Vstplug.h" +#include "CTreeCtrl.h" //==================================== class CSelectPluginDlg: public CDialog @@ -23,10 +24,10 @@ int m_nPlugSlot; SNDMIXPLUGIN *m_pPlugin; CModDoc *m_pModDoc; - CTreeCtrl m_treePlugins; + CTreeCtrlW m_treePlugins; CString m_sNameFilter; - HTREEITEM AddTreeItem(const TCHAR *title, int image, bool sort, HTREEITEM hParent = TVI_ROOT, LPARAM lParam = NULL); + HTREEITEM AddTreeItem(const WCHAR *title, int image, bool sort, HTREEITEM hParent = TVI_ROOT, LPARAM lParam = NULL); public: CSelectPluginDlg(CModDoc *pModDoc, int nPlugSlot, CWnd *parent); Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-10 22:22:01 UTC (rev 3186) @@ -113,21 +113,18 @@ ///////////////////////////////////////////////////////////////////////////// // CViewModTree construction/destruction -CModTree::CModTree(CModTree *pDataTree) +CModTree::CModTree(CModTree *pDataTree) : + m_pDataTree(pDataTree), + m_hDropWnd(nullptr), + m_dwStatus(0), + m_nDocNdx(0), m_nDragDocNdx(0), + m_hItemDrag(nullptr), m_hItemDrop(nullptr), + m_hInsLib(nullptr), m_hMidiLib(nullptr), + m_bShowAllFiles(false), doLabelEdit(false) //------------------------------------- { - m_pDataTree = pDataTree; - m_dwStatus = 0; - m_bShowAllFiles = false; - m_hItemDrag = m_hItemDrop = NULL; - m_hDropWnd = NULL; - m_hInsLib = m_hMidiLib = NULL; - m_nDocNdx = m_nDragDocNdx = 0; - doLabelEdit = false; - MemsetZero(m_tiMidiGrp); MemsetZero(m_tiMidi); MemsetZero(m_tiPerc); - DocInfo.clear(); } @@ -190,7 +187,7 @@ m_hMidiLib = InsertItem("MIDI Library", IMAGE_FOLDER, IMAGE_FOLDER, TVI_ROOT, TVI_LAST); for (UINT iMidGrp=0; iMidGrp<17; iMidGrp++) { - m_tiMidiGrp[iMidGrp] = InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, szMidiGroupNames[iMidGrp], IMAGE_FOLDER, IMAGE_FOLDER, 0, 0, (MODITEM_HDR_MIDIGROUP << MIDILIB_SHIFT) | iMidGrp, m_hMidiLib, TVI_LAST); + InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, szMidiGroupNames[iMidGrp], IMAGE_FOLDER, IMAGE_FOLDER, 0, 0, (MODITEM_HDR_MIDIGROUP << MIDILIB_SHIFT) | iMidGrp, m_hMidiLib, TVI_LAST); } } m_hInsLib = InsertItem("Instrument Library", IMAGE_FOLDER, IMAGE_FOLDER, TVI_ROOT, TVI_LAST); @@ -266,38 +263,6 @@ } -std::wstring CModTree::GetItemTextW(HTREEITEM item) const -//------------------------------------------------------- -{ - WCHAR name[MAX_PATH]; // Maximum displayed text length according to documentation. - TVITEMW tvi; - MemsetZero(tvi); - tvi.hItem = item; - tvi.mask = TVIF_TEXT; - tvi.pszText = name; - tvi.cchTextMax = CountOf(name); - if(::SendMessage(m_hWnd, TVM_GETITEMW, 0, (LPARAM)&tvi)) - { - return tvi.pszText; - } else - { - return L""; - } -} - - -void CModTree::SetItemTextW(HTREEITEM item, const WCHAR *text) -//------------------------------------------------------------ -{ - TVITEMW tvi; - MemsetZero(tvi); - tvi.hItem = item; - tvi.mask = TVIF_TEXT; - tvi.pszText = const_cast<WCHAR *>(text); - ::SendMessage(m_hWnd, TVM_SETITEMW, 0, (LPARAM)&tvi); -} - - mpt::PathString CModTree::InsLibGetFullPath(HTREEITEM hItem) const //---------------------------------------------------------------- { @@ -447,33 +412,28 @@ void CModTree::RefreshMidiLibrary() //--------------------------------- { - CHAR s[256], stmp[256]; - TV_ITEM tvi; - CHAR szName[_MAX_FNAME], szExt[_MAX_EXT]; + std::wstring s; + WCHAR stmp[256]; + TV_ITEMW tvi; const MIDILIBSTRUCT &midiLib = CTrackApp::GetMidiLibrary(); if (IsSampleBrowser()) return; // Midi Programs - for (UINT iMidi=0; iMidi<128; iMidi++) + HTREEITEM parent = GetChildItem(m_hMidiLib); + for(UINT iMidi = 0; iMidi < 128; iMidi++) { DWORD dwImage = IMAGE_NOINSTRUMENT; - wsprintf(s, "%u: %s", iMidi, szMidiProgramNames[iMidi]); + s = StringifyW(iMidi) + L": " + mpt::String::Decode(szMidiProgramNames[iMidi], mpt::CharsetUTF8); const LPARAM param = (MODITEM_MIDIINSTRUMENT << MIDILIB_SHIFT) | iMidi; if(!midiLib.MidiMap[iMidi].empty()) { - _splitpath(midiLib.MidiMap[iMidi].ToLocale().c_str(), NULL, NULL, szName, szExt); - strncat(s, ": ", sizeof(s)); - s[sizeof(s)-1] = 0; - strncat(s, szName, sizeof(s)); - s[sizeof(s)-1] = 0; - strncat(s, szExt, sizeof(s)); - s[sizeof(s)-1] = 0; - if (szName[0]) dwImage = IMAGE_INSTRUMENTS; + s += L": " + midiLib.MidiMap[iMidi].GetFullFileName().ToWide(); + dwImage = IMAGE_INSTRUMENTS; } if (!m_tiMidi[iMidi]) { m_tiMidi[iMidi] = InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, - s, dwImage, dwImage, 0, 0, param, m_tiMidiGrp[iMidi/8], TVI_LAST); + s.c_str(), dwImage, dwImage, 0, 0, param, parent, TVI_LAST); } else { tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; @@ -482,34 +442,32 @@ tvi.cchTextMax = sizeof(stmp); tvi.iImage = tvi.iSelectedImage = dwImage; GetItem(&tvi); - if ((strcmp(s, stmp)) || (tvi.iImage != (int)dwImage)) + if(s != stmp || tvi.iImage != (int)dwImage) { SetItem(m_tiMidi[iMidi], TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, - s, dwImage, dwImage, 0, 0, param); + s.c_str(), dwImage, dwImage, 0, 0, param); } } + if((iMidi % 8u) == 7u) + { + parent = GetNextSiblingItem(parent); + } } // Midi Percussions for (UINT iPerc=24; iPerc<=84; iPerc++) { DWORD dwImage = IMAGE_NOSAMPLE; - wsprintf(s, "%s: %s", szDefaultNoteNames[iPerc], szMidiPercussionNames[iPerc-24]); + s = mpt::String::Decode(szDefaultNoteNames[iPerc], mpt::CharsetUTF8) + L": " + mpt::String::Decode(szMidiPercussionNames[iPerc - 24], mpt::CharsetUTF8); const LPARAM param = (MODITEM_MIDIPERCUSSION << MIDILIB_SHIFT) | iPerc; - if(!midiLib.MidiMap[iPerc|0x80].empty()) + if(!midiLib.MidiMap[iPerc | 0x80].empty()) { - _splitpath(midiLib.MidiMap[iPerc|0x80].ToLocale().c_str(), NULL, NULL, szName, szExt); - strncat(s, ": ", sizeof(s)); - mpt::String::SetNullTerminator(s); - strncat(s, szName, sizeof(s)); - mpt::String::SetNullTerminator(s); - strncat(s, szExt, sizeof(s)); - mpt::String::SetNullTerminator(s); - if (szName[0]) dwImage = IMAGE_SAMPLES; + s += L": " + midiLib.MidiMap[iPerc | 0x80].GetFullFileName().ToWide(); + dwImage = IMAGE_SAMPLES; } if (!m_tiPerc[iPerc]) { m_tiPerc[iPerc] = InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, - s, dwImage, dwImage, 0, 0, param, m_tiMidiGrp[16], TVI_LAST); + s.c_str(), dwImage, dwImage, 0, 0, param, parent, TVI_LAST); } else { tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; @@ -518,10 +476,10 @@ tvi.cchTextMax = sizeof(stmp); tvi.iImage = tvi.iSelectedImage = dwImage; GetItem(&tvi); - if ((strcmp(s, stmp)) || (tvi.iImage != (int)dwImage)) + if(s != stmp || tvi.iImage != (int)dwImage) { SetItem(m_tiPerc[iPerc], TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE, - s, dwImage, dwImage, 0, 0, param); + s.c_str(), dwImage, dwImage, 0, 0, param); } } } @@ -547,14 +505,12 @@ { if(!m_tiDLS[iDls]) { - CHAR szName[_MAX_PATH] = "", szExt[_MAX_EXT] = ".dls"; TV_SORTCB tvs; CDLSBank *pDlsBank = CTrackApp::gpDLSBanks[iDls]; // Add DLS file folder - _splitpath(pDlsBank->GetFileName().ToLocale().c_str(), NULL, NULL, szName, szExt); - strcat(szName, szExt); + std::wstring name = pDlsBank->GetFileName().GetFullFileName().ToWide(); m_tiDLS[iDls] = InsertItem(TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM, - szName, IMAGE_FOLDER, IMAGE_FOLDER, 0, 0, iDls, TVI_ROOT, hDlsRoot); + name.c_str(), IMAGE_FOLDER, IMAGE_FOLDER, 0, 0, iDls, TVI_ROOT, hDlsRoot); // Memorize Banks WORD wBanks[16]; HTREEITEM hBanks[16]; @@ -571,6 +527,7 @@ DLSINSTRUMENT *pDlsIns = pDlsBank->GetInstrument(iIns); if (pDlsIns) { + CHAR szName[256]; wsprintf(szName, "%u: %s", pDlsIns->ulInstrument & 0x7F, pDlsIns->szName); // Drum Kit if (pDlsIns->ulBank & F_INSTRUMENT_DRUMS) @@ -722,7 +679,7 @@ tvi.mask |= TVIF_TEXT | TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE; tvi.hItem = pInfo->hSong; tvi.pszText = stmp; - tvi.cchTextMax = sizeof(stmp); + tvi.cchTextMax = CountOf(stmp); tvi.iImage = tvi.iSelectedImage = IMAGE_FOLDER; GetItem(&tvi); if ((strcmp(s, stmp)) || (tvi.iImage != IMAGE_FOLDER)) @@ -857,7 +814,7 @@ tvi.stateMask = TVIS_BOLD; tvi.hItem = pInfo->tiSequences[nSeq]; tvi.pszText = stmp; - tvi.cchTextMax = sizeof(stmp); + tvi.cchTextMax = CountOf(stmp); LPARAM param = (nSeq << SEQU_SHIFT) | ORDERINDEX_INVALID; GetItem(&tvi); if(tvi.state != state || tvi.pszText != sSeqName || tvi.lParam != param) @@ -915,7 +872,7 @@ tvi.stateMask = TVIS_BOLD; tvi.hItem = pInfo->tiOrders[nSeq][iOrd]; tvi.pszText = stmp; - tvi.cchTextMax = sizeof(stmp); + tvi.cchTextMax = CountOf(stmp); GetItem(&tvi); if ((strcmp(s, stmp)) || (tvi.state != state)) SetItem(pInfo->tiOrders[nSeq][iOrd], TVIF_TEXT | TVIF_STATE | TVIF_PARAM, s, 0, 0, state, TVIS_BOLD, param); @@ -959,7 +916,7 @@ tvi.mask = TVIF_TEXT | TVIF_HANDLE; tvi.hItem = pInfo->tiPatterns[iPat]; tvi.pszText = stmp; - tvi.cchTextMax = sizeof(stmp); + tvi.cchTextMax = CountOf(stmp); GetItem(&tvi); if (strcmp(s, stmp)) SetItem(pInfo->tiPatterns[iPat], TVIF_TEXT, s, 0, 0, 0, 0, 0); } else @@ -1007,7 +964,7 @@ tvi.mask = TVIF_TEXT | TVIF_HANDLE | TVIF_IMAGE; tvi.hItem = hChild; tvi.pszText = stmp; - tvi.cchTextMax = sizeof(stmp); + tvi.cchTextMax = CountOf(stmp); tvi.iImage = tvi.iSelectedImage = nImage; GetItem(&tvi); if ((strcmp(s, stmp)) || (tvi.iImage != nImage)) @@ -1064,7 +1021,7 @@ tvi.mask = TVIF_TEXT | TVIF_HANDLE | TVIF_IMAGE; tvi.hItem = hChild; tvi.pszText = stmp; - tvi.cchTextMax = sizeof(stmp); + tvi.cchTextMax = CountOf(stmp); tvi.iImage = tvi.iSelectedImage = nImage; GetItem(&tvi); if ((strcmp(s, stmp)) || (tvi.iImage != nImage)) @@ -1501,12 +1458,13 @@ case MODITEM_INSLIB_SAMPLE: case MODITEM_INSLIB_INSTRUMENT: { + // Create double-null-terminated path + const std::wstring fullPath = InsLibGetFullPath(hItem).ToWide() + L'\0'; SHFILEOPSTRUCTW fos; - mpt::PathString fullPath = InsLibGetFullPath(hItem); - memset(&fos, 0, sizeof(fos)); + MemsetZero(fos); fos.hwnd = m_hWnd; fos.wFunc = FO_DELETE; - fos.pFrom = fullPath.AsNative().c_str(); + fos.pFrom = fullPath.c_str(); fos.fFlags = FOF_ALLOWUNDO; if ((0 == SHFileOperationW(&fos)) && (!fos.fAnyOperationsAborted)) RefreshInstrumentLibrary(); } @@ -1604,7 +1562,7 @@ if(!m_szSongName.empty() && IsSampleBrowser() && m_SongFile) { // Fill browser with samples / instruments of module file - SetItemTextW(m_hInsLib, m_szSongName.AsNative().c_str()); + SetItemText(m_hInsLib, m_szSongName.AsNative().c_str()); SetItemImage(m_hInsLib, IMAGE_FOLDERSONG, IMAGE_FOLDERSONG); for(INSTRUMENTINDEX ins = 1; ins <= m_SongFile->GetNumInstruments(); ins++) { @@ -1632,10 +1590,10 @@ if(!IsSampleBrowser()) { text = L"Instrument Library (" + m_szInstrLibPath.ToWide() + L")"; - SetItemTextW(m_hInsLib, text.c_str()); + SetItemText(m_hInsLib, text.c_str()); } else { - SetItemTextW(m_hInsLib, m_szInstrLibPath.ToWide().c_str()); + SetItemText(m_hInsLib, m_szInstrLibPath.ToWide().c_str()); SetItemImage(m_hInsLib, IMAGE_FOLDER, IMAGE_FOLDER); } @@ -1786,7 +1744,6 @@ void CModTree::ModTreeInsert(const WCHAR *name, int image) //-------------------------------------------------------- { - TV_INSERTSTRUCTW tvis; DWORD dwId = 0; switch(image) { @@ -1805,20 +1762,13 @@ dwId = 4; break; } - tvis.hParent = (!IsSampleBrowser()) ? m_hInsLib : TVI_ROOT; - tvis.hInsertAfter = TVI_LAST; - tvis.item.mask = TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_TEXT; - tvis.item.hItem = 0; - tvis.item.state = 0; - tvis.item.stateMask = 0; - tvis.item.pszText = const_cast<WCHAR *>(name); - tvis.item.cchTextMax = 0; - tvis.item.iImage = image; - tvis.item.iSelectedImage = image; - tvis.item.cChildren = 0; - tvis.item.lParam = (LPARAM)dwId; - - ::SendMessage(m_hWnd, TVM_INSERTITEMW, 0, (LPARAM)&tvis); + InsertItem(TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_TEXT, + name, + image, image, + 0, 0, + (LPARAM)dwId, + (!IsSampleBrowser()) ? m_hInsLib : TVI_ROOT, + TVI_LAST); } @@ -1838,12 +1788,9 @@ lParam2 &= 0x7FFFFFFF; if ((lParam1 & 0xFF00FFFF) == (lParam2 & 0xFF00FFFF)) { - /*UINT iDls = (lParam1 >> 24) & 0xFF; - if ((iDls < CTrackApp::gpDLSBanks.size()) && (CTrackApp::gpDLSBanks[iDls]))*/ if(pDLSBank) { - //CDLSBank *pDLSBank = CTrackApp::gpDLSBanks[iDls]; - DLSINSTRUMENT *pDlsIns = reinterpret_cast<CDLSBank *>(pDLSBank)->GetInstrument(lParam1 & 0xFFFF); + const DLSINSTRUMENT *pDlsIns = reinterpret_cast<CDLSBank *>(pDLSBank)->GetInstrument(lParam1 & 0xFFFF); lParam1 = (lParam1 >> 16) & 0xFF; lParam2 = (lParam2 >> 16) & 0xFF; if ((pDlsIns) && (lParam1 < (LONG)pDlsIns->nRegions) && (lParam2 < (LONG)pDlsIns->nRegions)) @@ -3283,17 +3230,12 @@ void CModTree::OnSoundBankProperties() //------------------------------------ { - HTREEITEM hItem = GetSelectedItem(); - - const ModItem modItem = GetModItem(hItem); - - if (modItem.type == MODITEM_DLSBANK_FOLDER) + const ModItem modItem = GetModItem(GetSelectedItem()); + if(modItem.type == MODITEM_DLSBANK_FOLDER + && modItem.val1 < CTrackApp::gpDLSBanks.size() && CTrackApp::gpDLSBanks[modItem.val1]) { - if ((modItem.val1 < CTrackApp::gpDLSBanks.size()) && (CTrackApp::gpDLSBanks[modItem.val1])) - { - CSoundBankProperties dlg(CTrackApp::gpDLSBanks[modItem.val1], this); - dlg.DoModal(); - } + CSoundBankProperties dlg(CTrackApp::gpDLSBanks[modItem.val1], this); + dlg.DoModal(); } } Modified: trunk/OpenMPT/mptrack/View_tre.h =================================================================== --- trunk/OpenMPT/mptrack/View_tre.h 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/mptrack/View_tre.h 2013-11-10 22:22:01 UTC (rev 3186) @@ -36,7 +36,7 @@ std::bitset<MAX_SAMPLES> samplesPlaying; std::bitset<MAX_INSTRUMENTS> instrumentsPlaying; - + ModTreeDocInfo(const CSoundFile &sndFile) { pModDoc = sndFile.GetpModDoc(); @@ -70,9 +70,11 @@ }; -//============================== -class CModTree: public CTreeCtrl -//============================== +#include "CTreeCtrl.h" + +//=============================== +class CModTree: public CTreeCtrlW +//=============================== { protected: @@ -166,7 +168,6 @@ UINT m_nDocNdx, m_nDragDocNdx; HTREEITEM m_hItemDrag, m_hItemDrop; HTREEITEM m_hInsLib, m_hMidiLib; - HTREEITEM m_tiMidiGrp[17]; HTREEITEM m_tiMidi[128]; HTREEITEM m_tiPerc[128]; std::vector<HTREEITEM> m_tiDLS; @@ -213,9 +214,6 @@ bool IsSampleBrowser() const { return m_pDataTree == nullptr; } - std::wstring GetItemTextW(HTREEITEM item) const; - void SetItemTextW(HTREEITEM item, const WCHAR *text); - // Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CModTree) Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-11-10 22:22:01 UTC (rev 3186) @@ -893,6 +893,10 @@ > </File> <File + RelativePath=".\CTreeCtrl.h" + > + </File> + <File RelativePath=".\ctrl_com.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-11-10 22:22:01 UTC (rev 3186) @@ -701,6 +701,7 @@ <ClInclude Include="ColourEdit.h" /> <ClInclude Include="CommandSet.h" /> <ClInclude Include="CreditStatic.h" /> + <ClInclude Include="CTreeCtrl.h" /> <ClInclude Include="Ctrl_com.h" /> <ClInclude Include="Ctrl_gen.h" /> <ClInclude Include="Ctrl_ins.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-11-10 19:16:46 UTC (rev 3185) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-11-10 22:22:01 UTC (rev 3186) @@ -951,6 +951,9 @@ <ClInclude Include="..\common\mptPathString.h"> <Filter>Header Files\common</Filter> </ClInclude> + <ClInclude Include="CTreeCtrl.h"> + <Filter>Header Files</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-11 23:33:43
|
Revision: 3189 http://sourceforge.net/p/modplug/code/3189 Author: manxorist Date: 2013-11-11 23:33:33 +0000 (Mon, 11 Nov 2013) Log Message: ----------- [Ref] Use mpt::fstream wrappers around std::fstream for all compilers, thereby enforcing the usage of mpt::PathString. Modified Paths: -------------- trunk/OpenMPT/common/mptFstream.h trunk/OpenMPT/mptrack/CommandSet.cpp trunk/OpenMPT/mptrack/Mod2wave.cpp trunk/OpenMPT/mptrack/Settings.cpp trunk/OpenMPT/mptrack/TuningDialog.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/tuningCollection.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/mptFstream.h =================================================================== --- trunk/OpenMPT/common/mptFstream.h 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/common/mptFstream.h 2013-11-11 23:33:33 UTC (rev 3189) @@ -1,7 +1,7 @@ /* * mptFstream.h * ------------ - * Purpose: A wrapper around std::fstream, fixing VS2008 charset conversion braindamage. + * Purpose: A wrapper around std::fstream, fixing VS2008 charset conversion braindamage, and enforcing usage of mpt::PathString. * Notes : You should only ever use these wrappers instead of plain std::fstream classes. * Authors: OpenMPT Devs * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. @@ -11,9 +11,8 @@ #include <fstream> -#if MPT_COMPILER_MSVC && MPT_MSVC_BEFORE(2010,0) #include "../common/mptString.h" -#endif +#include "../common/mptPathString.h" namespace mpt { @@ -24,168 +23,160 @@ // This is totally wrong for Win32 GUI applications because the C locale does not necessarily match the current windows ANSI codepage (CP_ACP). // Work around this insanity by using our own string conversions for the std::fstream filenames. +#define MPT_FSTREAM_DO_CONVERSIONS + +#endif + +#ifdef MPT_FSTREAM_DO_CONVERSIONS +#define MPT_FSTREAM_OPEN(filename, mode) detail::fstream_open<Tbase>(*this, (filename), (mode)) +#else +#define MPT_FSTREAM_OPEN(filename, mode) Tbase::open((filename), (mode)) +#endif + +namespace detail +{ + +template<typename Tbase> +inline void fstream_open(Tbase & base, const mpt::PathString & filename, std::ios_base::openmode mode) +{ + base.open(filename.AsNative().c_str(), mode); +} + +#ifdef MPT_FSTREAM_DO_CONVERSIONS + +template<typename Tbase> +inline void fstream_open(Tbase & base, const std::wstring & filename, std::ios_base::openmode mode) +{ + base.open(filename.c_str(), mode); +} + +template<typename Tbase> +inline void fstream_open(Tbase & base, const wchar_t * filename, std::ios_base::openmode mode) +{ + base.open(filename, mode); +} + +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); +} + +template<typename Tbase> +inline void fstream_open(Tbase & base, const char * filename, std::ios_base::openmode mode) +{ + detail::fstream_open<Tbase>(base, filename ? std::string(filename) : std::string(), mode); +} + +#endif + +} // namespace detail + class fstream : public std::fstream { private: - void mptopen(const std::wstring & filename, std::ios_base::openmode mode) - { - std::fstream::open(filename.c_str(), mode); - } - void mptopen(const std::string & filename, std::ios_base::openmode mode) - { - mptopen(mpt::String::Decode(filename, mpt::CharsetLocale).c_str(), mode); - } - void mptopen(const char * filename, std::ios_base::openmode mode) - { - mptopen(filename ? std::string(filename) : std::string(), mode); - } + typedef std::fstream Tbase; public: fstream() {} - fstream(const char * filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) + fstream(const mpt::PathString & filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { - mptopen(filename, mode); + detail::fstream_open<Tbase>(*this, filename, mode); } - fstream(const std::string & filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) + void open(const mpt::PathString & filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { - mptopen(filename, mode); + detail::fstream_open<Tbase>(*this, filename, mode); } - fstream(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) + MPT_DEPRECATED_PATH void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename, mode); } - fstream(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) + MPT_DEPRECATED_PATH void open(const std::string & filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename.c_str(), mode); } - void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) +#if defined(WIN32) + MPT_DEPRECATED_PATH void open(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename, mode); } - void open(const std::string & filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) + MPT_DEPRECATED_PATH void open(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename.c_str(), mode); } - void open(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) - { - mptopen(filename, mode); - } - void open(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out) - { - mptopen(filename, mode); - } +#endif }; class ifstream : public std::ifstream { private: - void mptopen(const std::wstring & filename, std::ios_base::openmode mode) - { - std::ifstream::open(filename.c_str(), mode); - } - void mptopen(const std::string & filename, std::ios_base::openmode mode) - { - mptopen(mpt::String::Decode(filename, mpt::CharsetLocale).c_str(), mode); - } - void mptopen(const char * filename, std::ios_base::openmode mode) - { - mptopen(filename ? std::string(filename) : std::string(), mode); - } + typedef std::ifstream Tbase; public: ifstream() {} - ifstream(const char * filename, std::ios_base::openmode mode = std::ios_base::in) + ifstream(const mpt::PathString & filename, std::ios_base::openmode mode = std::ios_base::in) { - mptopen(filename, mode); + detail::fstream_open<Tbase>(*this, filename, mode); } - ifstream(const std::string & filename, std::ios_base::openmode mode = std::ios_base::in) + void open(const mpt::PathString & filename, std::ios_base::openmode mode = std::ios_base::in) { - mptopen(filename, mode); + detail::fstream_open<Tbase>(*this, filename, mode); } - ifstream(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::in) + MPT_DEPRECATED_PATH void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename, mode); } - ifstream(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::in) + MPT_DEPRECATED_PATH void open(const std::string & filename, std::ios_base::openmode mode = std::ios_base::in) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename.c_str(), mode); } - void open(const char * filename, std::ios_base::openmode mode = std::ios_base::in) +#if defined(WIN32) + MPT_DEPRECATED_PATH void open(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::in) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename, mode); } - void open(const std::string & filename, std::ios_base::openmode mode = std::ios_base::in) + MPT_DEPRECATED_PATH void open(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::in) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename.c_str(), mode); } - void open(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::in) - { - mptopen(filename, mode); - } - void open(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::in) - { - mptopen(filename, mode); - } +#endif }; class ofstream : public std::ofstream { private: - void mptopen(const std::wstring & filename, std::ios_base::openmode mode) - { - std::ofstream::open(filename.c_str(), mode); - } - void mptopen(const std::string & filename, std::ios_base::openmode mode) - { - mptopen(mpt::String::Decode(filename, mpt::CharsetLocale).c_str(), mode); - } - void mptopen(const char * filename, std::ios_base::openmode mode) - { - mptopen(filename ? std::string(filename) : std::string(), mode); - } + typedef std::ofstream Tbase; public: ofstream() {} - ofstream(const char * filename, std::ios_base::openmode mode = std::ios_base::out) + ofstream(const mpt::PathString & filename, std::ios_base::openmode mode = std::ios_base::out) { - mptopen(filename, mode); + detail::fstream_open<Tbase>(*this, filename, mode); } - ofstream(const std::string & filename, std::ios_base::openmode mode = std::ios_base::out) + void open(const mpt::PathString & filename, std::ios_base::openmode mode = std::ios_base::out) { - mptopen(filename, mode); + detail::fstream_open<Tbase>(*this, filename, mode); } - ofstream(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::out) + MPT_DEPRECATED_PATH void open(const char * filename, std::ios_base::openmode mode = std::ios_base::out) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename, mode); } - ofstream(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::out) + MPT_DEPRECATED_PATH void open(const std::string & filename, std::ios_base::openmode mode = std::ios_base::out) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename.c_str(), mode); } - void open(const char * filename, std::ios_base::openmode mode = std::ios_base::out) +#if defined(WIN32) + MPT_DEPRECATED_PATH void open(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::out) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename, mode); } - void open(const std::string & filename, std::ios_base::openmode mode = std::ios_base::out) + MPT_DEPRECATED_PATH void open(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::out) { - mptopen(filename, mode); + MPT_FSTREAM_OPEN(filename.c_str(), mode); } - void open(const wchar_t * filename, std::ios_base::openmode mode = std::ios_base::out) - { - mptopen(filename, mode); - } - void open(const std::wstring & filename, std::ios_base::openmode mode = std::ios_base::out) - { - mptopen(filename, mode); - } +#endif }; -#else +#undef MPT_FSTREAM_OPEN -typedef std::fstream fstream; -typedef std::ifstream ifstream; -typedef std::ofstream ofstream; - -#endif - } // namespace mpt Modified: trunk/OpenMPT/mptrack/CommandSet.cpp =================================================================== --- trunk/OpenMPT/mptrack/CommandSet.cpp 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/mptrack/CommandSet.cpp 2013-11-11 23:33:33 UTC (rev 3189) @@ -1679,7 +1679,7 @@ bool CCommandSet::LoadFile(const mpt::PathString &filename) //--------------------------------------------------------- { - mpt::ifstream fin(filename.AsNative().c_str()); + mpt::ifstream fin(filename); if (fin.fail()) { Reporting::Warning(L"Can't open keybindings file " + filename.ToWide() + L" for reading. Default keybindings will be used."); Modified: trunk/OpenMPT/mptrack/Mod2wave.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mod2wave.cpp 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/mptrack/Mod2wave.cpp 2013-11-11 23:33:33 UTC (rev 3189) @@ -879,10 +879,10 @@ mpt::fstream normalizeFile; if(m_Settings.Normalize) { - normalizeFile.open(normalizeFileName.AsNative().c_str(), std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc); + normalizeFile.open(normalizeFileName, std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc); } - mpt::ofstream fileStream(m_lpszFileName.AsNative().c_str(), std::ios::binary | std::ios::trunc); + mpt::ofstream fileStream(m_lpszFileName, std::ios::binary | std::ios::trunc); if(!fileStream) { Modified: trunk/OpenMPT/mptrack/Settings.cpp =================================================================== --- trunk/OpenMPT/mptrack/Settings.cpp 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/mptrack/Settings.cpp 2013-11-11 23:33:33 UTC (rev 3189) @@ -434,7 +434,7 @@ static std::vector<char> ReadFile(const mpt::PathString &filename) { - mpt::ifstream s(filename.AsNative().c_str(), std::ios::binary); + mpt::ifstream s(filename, std::ios::binary); std::vector<char> result; while(s) { @@ -449,7 +449,7 @@ static void WriteFileUTF16LE(const mpt::PathString &filename, const std::wstring &str) { STATIC_ASSERT(sizeof(wchar_t) == 2); - mpt::ofstream inifile(filename.AsNative().c_str(), std::ios::binary | std::ios::trunc); + mpt::ofstream inifile(filename, std::ios::binary | std::ios::trunc); const uint8 UTF16LE_BOM[] = { 0xff, 0xfe }; inifile.write(reinterpret_cast<const char*>(UTF16LE_BOM), 2); inifile.write(reinterpret_cast<const char*>(str.c_str()), str.length() * sizeof(std::wstring::value_type)); Modified: trunk/OpenMPT/mptrack/TuningDialog.cpp =================================================================== --- trunk/OpenMPT/mptrack/TuningDialog.cpp 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/mptrack/TuningDialog.cpp 2013-11-11 23:33:33 UTC (rev 3189) @@ -643,7 +643,7 @@ bool failure = true; - mpt::ofstream fout(dlg.GetFirstFile().AsNative().c_str(), std::ios::binary); + mpt::ofstream fout(dlg.GetFirstFile(), std::ios::binary); if(filterIndex == 0) { @@ -702,7 +702,7 @@ if (bIsTun) { - mpt::ifstream fin(files[counter].AsNative().c_str(), std::ios::binary); + mpt::ifstream fin(files[counter], std::ios::binary); pT = CTuningRTI::DeserializeOLD(fin); if(pT == 0) {fin.clear(); fin.seekg(0); pT = CTuningRTI::Deserialize(fin);} @@ -1467,7 +1467,7 @@ CTuningDialog::EnSclImport CTuningDialog::ImportScl(const mpt::PathString &filename, LPCTSTR pszName) //--------------------------------------------------------------------------------------------------- { - mpt::ifstream iStrm(filename.AsNative().c_str(), std::ios::in | std::ios::binary); + mpt::ifstream iStrm(filename, std::ios::in | std::ios::binary); if(!iStrm) { return enSclImportFailUnableToOpenFile; Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-11 23:33:33 UTC (rev 3189) @@ -1609,7 +1609,7 @@ bool bank = (dlg.GetExtension() == MPT_PATHSTRING("fxb")); - mpt::fstream f(dlg.GetFirstFile().AsNative().c_str(), std::ios::out | std::ios::trunc | std::ios::binary); + mpt::fstream f(dlg.GetFirstFile(), std::ios::out | std::ios::trunc | std::ios::binary); if(f.good() && VSTPresets::SaveFile(f, *this, bank)) { return true; Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-11-11 23:33:33 UTC (rev 3189) @@ -1629,7 +1629,7 @@ // Using std::ios::in | std::ios::out | std::ios::ate prevents truncation and sets the file pointer to the end of the so-far saved file, // but it also allows reading, which does no harm but is not what we actually really want here. // That's a very broken interface. - mpt::ofstream fout(filename.AsNative().c_str(), std::ios::binary | std::ios::ate | std::ios::in); + mpt::ofstream fout(filename, std::ios::binary | std::ios::ate | std::ios::in); #endif const uint32 MPTStartPos = (uint32)fout.tellp(); Modified: trunk/OpenMPT/soundlib/tuningCollection.cpp =================================================================== --- trunk/OpenMPT/soundlib/tuningCollection.cpp 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/soundlib/tuningCollection.cpp 2013-11-11 23:33:33 UTC (rev 3189) @@ -124,7 +124,7 @@ { if(m_SavefilePath.empty()) return SERIALIZATION_FAILURE; - mpt::ofstream fout(m_SavefilePath.AsNative().c_str(), std::ios::binary); + mpt::ofstream fout(m_SavefilePath, std::ios::binary); if(!fout.good()) return SERIALIZATION_FAILURE; @@ -139,7 +139,7 @@ { if(m_SavefilePath.empty()) return SERIALIZATION_FAILURE; - mpt::ifstream fin(m_SavefilePath.AsNative().c_str(), std::ios::binary); + mpt::ifstream fin(m_SavefilePath, std::ios::binary); if(!fin.good()) return SERIALIZATION_FAILURE; Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-11 16:00:18 UTC (rev 3188) +++ trunk/OpenMPT/test/test.cpp 2013-11-11 23:33:33 UTC (rev 3189) @@ -1472,7 +1472,7 @@ static TSoundFileContainer CreateSoundFileContainer(const mpt::PathString &filename) { - mpt::ifstream stream(filename.AsNative().c_str(), std::ios::binary); + mpt::ifstream stream(filename, std::ios::binary); FileReader file(&stream); std::shared_ptr<CSoundFile> pSndFile(new CSoundFile()); pSndFile->Create(file, CSoundFile::loadCompleteModule); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-12 15:50:38
|
Revision: 3191 http://sourceforge.net/p/modplug/code/3191 Author: manxorist Date: 2013-11-12 15:50:28 +0000 (Tue, 12 Nov 2013) Log Message: ----------- [Fix] Do not return uninitialized data from MptVersion::ToNum. Modified Paths: -------------- trunk/OpenMPT/common/version.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/version.cpp =================================================================== --- trunk/OpenMPT/common/version.cpp 2013-11-12 00:42:40 UTC (rev 3190) +++ trunk/OpenMPT/common/version.cpp 2013-11-12 15:50:28 UTC (rev 3191) @@ -90,7 +90,10 @@ VersionNum ToNum(const std::string &s_) { const char *s = s_.c_str(); - unsigned int v1, v2, v3, v4; + unsigned int v1 = 0; + unsigned int v2 = 0; + unsigned int v3 = 0; + unsigned int v4 = 0; sscanf(s, "%x.%x.%x.%x", &v1, &v2, &v3, &v4); return ((v1 << 24) | (v2 << 16) | (v3 << 8) | v4); } Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-12 00:42:40 UTC (rev 3190) +++ trunk/OpenMPT/test/test.cpp 2013-11-12 15:50:28 UTC (rev 3191) @@ -343,6 +343,9 @@ VERIFY_EQUAL( MptVersion::ToStr(MptVersion::ToNum(MptVersion::str)), MptVersion::str ); VERIFY_EQUAL( MptVersion::ToStr(18285096), "1.17.02.28" ); VERIFY_EQUAL( MptVersion::ToNum("1.17.02.28"), 18285096 ); + VERIFY_EQUAL( MptVersion::ToNum("1.fe.02.28"), 0x01fe0228 ); + VERIFY_EQUAL( MptVersion::ToNum("01.fe.02.28"), 0x01fe0228 ); + VERIFY_EQUAL( MptVersion::ToNum("1.22"), 0x01220000 ); VERIFY_EQUAL( MptVersion::ToNum(MptVersion::str), MptVersion::num ); VERIFY_EQUAL( MptVersion::ToStr(MptVersion::num), MptVersion::str ); VERIFY_EQUAL( MptVersion::RemoveBuildNumber(MAKE_VERSION_NUMERIC(1,19,02,00)), MAKE_VERSION_NUMERIC(1,19,02,00)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-11-12 20:54:23
|
Revision: 3198 http://sourceforge.net/p/modplug/code/3198 Author: saga-games Date: 2013-11-12 20:54:13 +0000 (Tue, 12 Nov 2013) Log Message: ----------- [Ref] Moved some code from Vstplug.cpp to DmoToVst.cpp and PluginManager.cpp to make this monster slightly less bulky. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/mptrack/Vstplug.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp Added Paths: ----------- trunk/OpenMPT/soundlib/plugins/DmoToVst.cpp trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2013-11-12 20:26:19 UTC (rev 3197) +++ trunk/OpenMPT/common/misc_util.cpp 2013-11-12 20:54:13 UTC (rev 3198) @@ -131,3 +131,43 @@ #endif // ENABLE_ASM + + +#ifdef MODPLUG_TRACKER + +namespace Util +{ + std::wstring CLSIDToString(CLSID clsid) + //------------------------------------- + { + std::wstring str; + LPOLESTR tmp = nullptr; + StringFromCLSID(clsid, &tmp); + if(tmp) + { + str = tmp; + CoTaskMemFree(tmp); + tmp = nullptr; + } + return str; + } + + + bool StringToCLSID(const std::wstring &str, CLSID &clsid) + //------------------------------------------------------- + { + std::vector<OLECHAR> tmp(str.c_str(), str.c_str() + str.length() + 1); + return CLSIDFromString(&tmp[0], &clsid) == S_OK; + } + + + bool IsCLSID(const std::wstring &str) + //----------------------------------- + { + CLSID clsid = CLSID(); + std::vector<OLECHAR> tmp(str.c_str(), str.c_str() + str.length() + 1); + return CLSIDFromString(&tmp[0], &clsid) == S_OK; + } +} // namespace Util + +#endif // MODPLUG_TRACKER Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-11-12 20:26:19 UTC (rev 3197) +++ trunk/OpenMPT/common/misc_util.h 2013-11-12 20:54:13 UTC (rev 3198) @@ -510,3 +510,14 @@ } #endif // ENABLE_ASM + +#ifdef MODPLUG_TRACKER + +namespace Util +{ + std::wstring CLSIDToString(CLSID clsid); + bool StringToCLSID(const std::wstring &str, CLSID &clsid); + bool IsCLSID(const std::wstring &str); +} // namespace Util + +#endif // MODPLUG_TRACKER \ No newline at end of file Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-12 20:26:19 UTC (rev 3197) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-11-12 20:54:13 UTC (rev 3198) @@ -1,7 +1,7 @@ /* * vstplug.cpp * ----------- - * Purpose: Plugin handling (loading and processing plugins) + * Purpose: Plugin handling / processing * Notes : (currently none) * Authors: OpenMPT Devs * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. @@ -9,642 +9,26 @@ #include "stdafx.h" -#include <uuids.h> -#include <dmoreg.h> -#include <shlwapi.h> -#include <medparam.h> -#include "mainfrm.h" -#include "vstplug.h" +#include "Mainfrm.h" +#include "Vstplug.h" #include "VstPresets.h" -#include "moddoc.h" -#include "Sndfile.h" -#include "AbstractVstEditor.h" //rewbs.defaultPlugGUI -#include "VstEditor.h" //rewbs.defaultPlugGUI -#include "defaultvsteditor.h" //rewbs.defaultPlugGUI +#include "Moddoc.h" +#include "../soundlib/Sndfile.h" +#include "AbstractVstEditor.h" +#include "VstEditor.h" +#include "DefaultVstEditor.h" #include "../soundlib/MIDIEvents.h" -#include "../common/version.h" -#include "midimappingdialog.h" +#include "MIDIMappingDialog.h" #include "../common/StringFixer.h" #include "MemoryMappedFile.h" #include "../soundlib/FileReader.h" -#include "../soundlib/plugins/JBridge.h" #include "FileDialog.h" #include "../common/mptFstream.h" -#ifdef VST_USE_ALTERNATIVE_MAGIC //Pelya's plugin ID fix. Breaks fx presets, so let's avoid it for now. -#include "../zlib/zlib.h" //For CRC32 calculation (to detect plugins with same UID) -#endif // VST_USE_ALTERNATIVE_MAGIC #ifndef NO_VST -char CVstPluginManager::s_szHostProductString[64] = "OpenMPT"; -char CVstPluginManager::s_szHostVendorString[64] = "OpenMPT project"; -VstIntPtr CVstPluginManager::s_nHostVendorVersion = MptVersion::num; - //#define VST_LOG -#define DMO_LOG -AEffect *DmoToVst(VSTPluginLib *pLib); - -#ifdef VST_USE_ALTERNATIVE_MAGIC -UINT32 CalculateCRC32fromFilename(const char *s) -//---------------------------------------------- -{ - char fn[_MAX_PATH]; - mpt::String::Copy(fn, s); - int f; - for(f = 0; fn[f] != 0; f++) fn[f] = toupper(fn[f]); - return LittleEndian(crc32(0, (BYTE *)fn, f)); - -} -#endif // VST_USE_ALTERNATIVE_MAGIC - - -static HRESULT CLSIDFromWString(const std::wstring &str, CLSID *clsid) -//-------------------------------------------------------------------- -{ - std::vector<OLECHAR> tmp(str.c_str(), str.c_str() + str.length() + 1); - return CLSIDFromString(&tmp[0], clsid); -} - - -VstIntPtr VSTCALLBACK CVstPluginManager::MasterCallBack(AEffect *effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void *ptr, float opt) -//---------------------------------------------------------------------------------------------------------------------------------------------- -{ - CVstPluginManager *that = theApp.GetPluginManager(); - if (that) - { - return that->VstCallback(effect, opcode, index, value, ptr, opt); - } - return 0; -} - - -bool CVstPluginManager::CreateMixPluginProc(SNDMIXPLUGIN &mixPlugin, CSoundFile &sndFile) -//--------------------------------------------------------------------------------------- -{ - CVstPluginManager *that = theApp.GetPluginManager(); - if(that) - { - return that->CreateMixPlugin(mixPlugin, sndFile); - } - return false; -} - - -CVstPluginManager::CVstPluginManager() -//------------------------------------ -{ - m_pVstHead = nullptr; - //m_bNeedIdle = FALSE; //rewbs.VSTCompliance - now member of plugin class - CSoundFile::gpMixPluginCreateProc = CreateMixPluginProc; - EnumerateDirectXDMOs(); -} - - -CVstPluginManager::~CVstPluginManager() -//------------------------------------- -{ - CSoundFile::gpMixPluginCreateProc = nullptr; - while (m_pVstHead) - { - 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) - { - p->pPluginsList->Release(); - } - delete p; - } -} - - -bool CVstPluginManager::IsValidPlugin(const VSTPluginLib *pLib) -//------------------------------------------------------------- -{ - VSTPluginLib *p = m_pVstHead; - while (p) - { - if (p == pLib) return true; - p = p->pNext; - } - return false; -} - - -void CVstPluginManager::EnumerateDirectXDMOs() -//-------------------------------------------- -{ - HKEY hkEnum; - WCHAR keyname[128]; - LONG cr; - DWORD index; - - cr = RegOpenKey(HKEY_LOCAL_MACHINE, "software\\classes\\DirectShow\\MediaObjects\\Categories\\f3602b3f-0592-48df-a4cd-674721e7ebeb", &hkEnum); - index = 0; - while (cr == ERROR_SUCCESS) - { - if ((cr = RegEnumKeyW(hkEnum, index, keyname, CountOf(keyname))) == ERROR_SUCCESS) - { - CLSID clsid; - std::wstring formattedKey = std::wstring(L"{") + std::wstring(keyname) + std::wstring(L"}"); - if(CLSIDFromWString(formattedKey, &clsid) == S_OK) - { - HKEY hksub; - formattedKey = std::wstring(L"software\\classes\\DirectShow\\MediaObjects\\") + std::wstring(keyname); - if (RegOpenKeyW(HKEY_LOCAL_MACHINE, formattedKey.c_str(), &hksub) == ERROR_SUCCESS) - { - WCHAR name[64]; - DWORD datatype = REG_SZ; - DWORD datasize = sizeof(name); - - if(ERROR_SUCCESS == RegQueryValueExW(hksub, nullptr, 0, &datatype, (LPBYTE)name, &datasize)) - { - StringFromGUID2(clsid, keyname, 100); - - VSTPluginLib *p = new VSTPluginLib(mpt::PathString::FromWide(keyname), mpt::PathString::FromWide(name)); - p->pNext = m_pVstHead; - p->pluginId1 = kDmoMagic; - p->pluginId2 = clsid.Data1; - p->category = VSTPluginLib::catDMO; - #ifdef DMO_LOG - Log("Found \"%s\" clsid=%s\n", p->libraryName.AsNative().c_str(), p->dllPath.AsNative().c_str()); - #endif - if (m_pVstHead) m_pVstHead->pPrev = p; - m_pVstHead = p; - } - RegCloseKey(hksub); - } - } - } - index++; - } - if (hkEnum) RegCloseKey(hkEnum); -} - - -void CVstPluginManager::LoadPlugin(const mpt::PathString &pluginPath, AEffect *&effect, HINSTANCE &library) -//--------------------------------------------------------------------------------------------------------- -{ - library = nullptr; - effect = nullptr; - - try - { - library = LoadLibraryW(pluginPath.ToWide().c_str()); - - if(library == nullptr) - { - DWORD error = GetLastError(); - -#ifdef _DEBUG - if(error != ERROR_MOD_NOT_FOUND) // "File not found errors" are annoying. - { - TCHAR szBuf[256]; - wsprintf(szBuf, "Warning: encountered problem when loading plugin dll. Error %x: %s", error, GetErrorMessage(error).c_str()); - Reporting::Error(szBuf, "DEBUG: Error when loading plugin dll"); - } -#endif //_DEBUG - - if(error == ERROR_MOD_NOT_FOUND) - { - // No point in trying with JBride, either... - return; - } - } - } catch(...) - { - CVstPluginManager::ReportPlugException("Exception caught in LoadLibrary (%s)", pluginPath.ToLocale().c_str()); - } - - if(library != nullptr && library != INVALID_HANDLE_VALUE) - { - // Try loading the VST plugin. - PVSTPLUGENTRY pMainProc = (PVSTPLUGENTRY)GetProcAddress(library, "VSTPluginMain"); - if(pMainProc == nullptr) - { - pMainProc = (PVSTPLUGENTRY)GetProcAddress(library, "main"); - } - - if(pMainProc != nullptr) - { - effect = pMainProc(MasterCallBack); - } else - { -#ifdef VST_LOG - Log("Entry point not found! (handle=%08X)\n", library); -#endif // VST_LOG - } - } - - if(effect == nullptr) - { - // Try loading the plugin using JBridge instead. - FreeLibrary(library); - library = nullptr; - effect = JBridge::LoadBridgedPlugin(MasterCallBack, pluginPath); - } -} - - -// Extract instrument and category information from plugin. -void GetPluginInformation(AEffect *effect, VSTPluginLib &library) -//--------------------------------------------------------------- -{ - library.category = static_cast<VSTPluginLib::PluginCategory>(effect->dispatcher(effect, effGetPlugCategory, 0, 0, nullptr, 0.0f)); - library.isInstrument = ((effect->flags & effFlagsIsSynth) || !effect->numInputs); - - if(library.isInstrument) - { - library.category = VSTPluginLib::catSynth; - } else if(library.category >= VSTPluginLib::numCategories) - { - library.category = VSTPluginLib::catUnknown; - } -} - - -// -// PluginCache format: -// LibraryName = ID100000ID200000 -// ID100000ID200000 = FullDllPath -// ID100000ID200000.Flags = Plugin Flags (isInstrument + category). - -VSTPluginLib *CVstPluginManager::AddPlugin(const mpt::PathString &dllPath, bool fromCache, const bool checkFileExistence, CString *const errStr) -//---------------------------------------------------------------------------------------------------------------------------------------------- -{ - const mpt::PathString fileName = dllPath.GetFileName(); - - if(checkFileExistence && (PathFileExistsW(dllPath.AsNative().c_str()) == FALSE)) - { - if(errStr) - { - *errStr += "\nUnable to find "; - *errStr += dllPath.ToCString(); - } - } - - VSTPluginLib *pDup = m_pVstHead; - while(pDup != nullptr) - { - if(!dllPath.CompareNoCase(dllPath, pDup->dllPath)) return pDup; - pDup = pDup->pNext; - } - // Look if the plugin info is stored in the PluginCache - if(fromCache) - { - const char *cacheSection = "PluginCache"; - SettingsContainer & cacheFile = theApp.GetPluginCache(); - - std::string IDs = cacheFile.Read<std::string>(cacheSection, fileName.ToLocale(), ""); - - if(IDs.length() >= 16) - { - // Get path from cache file - mpt::PathString realPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING("")); - realPath = theApp.RelativePathToAbsolute(realPath); - - if(!realPath.empty() && !dllPath.CompareNoCase(realPath, dllPath)) - { - VSTPluginLib *p = new (std::nothrow) VSTPluginLib(dllPath, fileName); - if(p == nullptr) - { - return nullptr; - } - p->pNext = m_pVstHead; - if (m_pVstHead) m_pVstHead->pPrev = p; - m_pVstHead = p; - - // Extract plugin Ids - for (UINT i=0; i<16; i++) - { - UINT n = IDs[i] - '0'; - if (n > 9) n = IDs[i] + 10 - 'A'; - n &= 0x0f; - if (i < 8) - { - p->pluginId1 = (p->pluginId1 << 4) | n; - } else - { - p->pluginId2 = (p->pluginId2 << 4) | n; - } - } - - std::string flagKey = mpt::String::Format("%s.Flags", IDs.c_str()); - p->DecodeCacheFlags(cacheFile.Read<int32>(cacheSection, flagKey, 0)); - - #ifdef VST_USE_ALTERNATIVE_MAGIC - if( p->pluginId1 == kEffectMagic ) - { - p->pluginId1 = CalculateCRC32fromFilename(p->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); - #endif // VST_LOG - return p; - } else - { - #ifdef VST_LOG - Log("Plugin \"%s\" mismatch in PluginCache: \"%s\" [%s]=\"%s\"\n", s, dllPath, (LPCTSTR)IDs, (LPCTSTR)strFullPath); - #endif // VST_LOG - } - } - } - - // If this key contains a file name on program launch, a plugin previously crashed OpenMPT. - theApp.GetSettings().Write<mpt::PathString>("VST Plugins", "FailedPlugin", dllPath); - - AEffect *pEffect; - HINSTANCE hLib; - bool validPlug = false; - - VSTPluginLib *p = new (std::nothrow) VSTPluginLib(dllPath, fileName); - if(p == nullptr) - { - return nullptr; - } - p->pNext = m_pVstHead; - - try - { - LoadPlugin(dllPath, pEffect, hLib); - - if(pEffect != nullptr && pEffect->magic == kEffectMagic && pEffect->dispatcher != nullptr) - { - 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 -#else - p->pluginId1 = pEffect->magic; -#endif // VST_USE_ALTERNATIVE_MAGIC - p->pluginId2 = pEffect->uniqueID; - - GetPluginInformation(pEffect, *p); - -#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, - pEffect->numInputs, pEffect->numOutputs, - pEffect->numPrograms, pEffect->numParams, - pEffect->flags, pEffect->realQualities, pEffect->offQualities); -#endif // VST_LOG - - pEffect->dispatcher(pEffect, effClose, 0, 0, 0, 0); - - validPlug = true; - } - - FreeLibrary(hLib); - } catch(...) - { - CVstPluginManager::ReportPlugException("Exception while trying to load plugin \"%s\"!\n", p->libraryName); - } - - // Now it should be safe to assume that this plugin loaded properly. :) - theApp.GetSettings().Write<std::string>("VST Plugins", "FailedPlugin", ""); - - // If OK, write the information in PluginCache - if(validPlug) - { - const std::string cacheSection = "PluginCache"; - SettingsContainer & cacheFile = theApp.GetPluginCache(); - std::string IDs = mpt::String::Format("%08X%08X", p->pluginId1, p->pluginId2); - std::string flagsKey = mpt::String::Format("%s.Flags", IDs); - - mpt::PathString writePath = dllPath; - if(theApp.IsPortableMode()) - { - theApp.AbsolutePathToRelative(writePath); - } - - 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<int32>(cacheSection, flagsKey, p->EncodeCacheFlags()); - } else - { - delete p; - } - - return (validPlug ? m_pVstHead : nullptr); -} - - -bool CVstPluginManager::RemovePlugin(VSTPluginLib *pFactory) -//---------------------------------------------------------- -{ - VSTPluginLib *p = m_pVstHead; - - while (p) - { - if (p == 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) - { - p->pPluginsList->Release(); - } - delete p; - } catch (...) - { - CVstPluginManager::ReportPlugException("Exception while trying to release plugin \"%s\"!\n", pFactory->libraryName); - } - - return true; - } - p = p->pNext; - } - return false; -} - - -bool CVstPluginManager::CreateMixPlugin(SNDMIXPLUGIN &mixPlugin, CSoundFile &sndFile) -//----------------------------------------------------------------------------------- -{ - UINT nMatch = 0; - VSTPluginLib *pFound = nullptr; - - VSTPluginLib *p = m_pVstHead; - - while(p) - { - bool b1 = false, b2 = false; - if((p->pluginId1 == mixPlugin.Info.dwPluginId1) - && (p->pluginId2 == mixPlugin.Info.dwPluginId2)) - { - b1 = true; - } - if(!mpt::strnicmp(p->libraryName.ToLocale().c_str(), mixPlugin.GetLibraryName(), 64)) - { - b2 = true; - } - if((b1) && (b2)) - { - nMatch = 3; - pFound = p; - } else - if((b1) && (nMatch < 2)) - { - nMatch = 2; - pFound = p; - } else - if((b2) && (nMatch < 1)) - { - nMatch = 1; - pFound = p; - } - p = p->pNext; - } - - if(mixPlugin.Info.dwPluginId1 == kDmoMagic) - { - if (!pFound) return FALSE; - AEffect *pEffect = DmoToVst(pFound); - if ((pEffect) && (pEffect->dispatcher) && (pEffect->magic == kDmoMagic)) - { - bool result = false; - CVstPlugin *pVstPlug = new (std::nothrow) CVstPlugin(NULL, *pFound, mixPlugin, *pEffect, sndFile); - if(pVstPlug) - { - result = true; - } - return result; - } - } - - if((!pFound) && strcmp(mixPlugin.GetLibraryName(), "")) - { - // Try finding the plugin DLL in the plugin directory instead. - mpt::PathString fullPath; - fullPath = TrackerDirectories::Instance().GetDefaultDirectory(DIR_PLUGINS); - if(fullPath.empty()) - { - fullPath = theApp.GetAppDirPath() + MPT_PATHSTRING("Plugins\\"); - } - if(!fullPath.HasTrailingSlash()) - { - fullPath += MPT_PATHSTRING("\\"); - } - fullPath += mpt::PathString::FromLocale(mixPlugin.GetLibraryName()) + MPT_PATHSTRING(".dll"); - - pFound = AddPlugin(fullPath); - if(!pFound) - { - std::string cacheSection = "PluginCache"; - SettingsContainer & cacheFile = theApp.GetPluginCache(); - std::string IDs = cacheFile.Read<std::string>(cacheSection, mixPlugin.GetLibraryName(), ""); - if (IDs.length() >= 16) - { - fullPath = cacheFile.Read<mpt::PathString>(cacheSection, IDs, MPT_PATHSTRING("")); - if(!fullPath.empty()) pFound = AddPlugin(fullPath); - } - } - } - - if (pFound) - { - - AEffect *pEffect = nullptr; - HINSTANCE hLibrary = nullptr; - bool validPlugin = false; - - try - { - LoadPlugin(pFound->dllPath, pEffect, hLibrary); - - if(pEffect != nullptr && pEffect->dispatcher != nullptr && pEffect->magic == kEffectMagic) - { - validPlugin = true; - - const bool oldIsInstrument = pFound->isInstrument; - const VSTPluginLib::PluginCategory oldCategory = pFound->category; - - GetPluginInformation(pEffect, *pFound); - - if(oldIsInstrument != pFound->isInstrument || oldCategory != pFound->category) - { - // Update cached information - const std::string cacheSection = "PluginCache"; - SettingsContainer & cacheFile = theApp.GetPluginCache(); - std::string flagsKey = mpt::String::Format("%08X%08X.Flags", pFound->pluginId1, pFound->pluginId2); - cacheFile.Write<int32>(cacheSection, flagsKey, pFound->EncodeCacheFlags()); - } - - CVstPlugin *pVstPlug = new (std::nothrow) CVstPlugin(hLibrary, *pFound, mixPlugin, *pEffect, sndFile); - if(pVstPlug == nullptr) - { - validPlugin = false; - } - } - - if(!validPlugin) - { - FreeLibrary(hLibrary); - } - } catch(...) - { - CVstPluginManager::ReportPlugException("Exception while trying to create plugin \"%s\"!\n", pFound->libraryName); - } - - return validPlugin; - } else - { - // "plug not found" notification code MOVED to CSoundFile::Create - #ifdef VST_LOG - Log("Unknown plugin\n"); - #endif - } - return false; -} - - -void CVstPluginManager::OnIdle() -//------------------------------ -{ - VSTPluginLib *pFactory = m_pVstHead; - - while (pFactory) - { - CVstPlugin *p = pFactory->pPluginsList; - while (p) - { - //rewbs. VSTCompliance: A specific plug has requested indefinite periodic processing time. - if (p->m_bNeedIdle) - { - if (!(p->Dispatch(effIdle, 0, 0, nullptr, 0.0f))) - p->m_bNeedIdle=false; - } - //We need to update all open editors - if ((p->m_pEditor) && (p->m_pEditor->m_hWnd)) - { - p->m_pEditor->UpdateParamDisplays(); - } - //end rewbs. VSTCompliance: - - p = p->m_pNext; - } - pFactory = pFactory->pNext; - } - -} - -//rewbs.VSTCompliance: Added support for lots of opcodes VstIntPtr CVstPluginManager::VstCallback(AEffect *effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void *ptr, float /*opt*/) //----------------------------------------------------------------------------------------------------------------------------------- { @@ -1053,7 +437,6 @@ return 0; } -//end rewbs. VSTCompliance: // Helper function for file selection dialog stuff. @@ -1229,27 +612,6 @@ } -void CVstPluginManager::ReportPlugException(LPCSTR format,...) -//------------------------------------------------------------ -{ - CHAR cBuf[1024]; - va_list va; - va_start(va, format); - wvsprintf(cBuf, format, va); - Reporting::Notification(cBuf); -#ifdef VST_LOG - Log(cBuf); -#endif - - //Stop song - TODO: figure out why this causes a kernel hang from IASIO->release(); -/* END_CRITICAL(); - CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); - if (pMainFrm) pMainFrm->StopMod(); -*/ - va_end(va); -} - - ////////////////////////////////////////////////////////////////////////////// // // CVstPlugin @@ -1275,7 +637,7 @@ m_MixState.pOutBufferL = mixBuffer.GetInputBuffer(0); m_MixState.pOutBufferR = mixBuffer.GetInputBuffer(1); - m_bSongPlaying = false; //rewbs.VSTCompliance + m_bSongPlaying = false; m_bPlugResumed = false; m_nSampleRate = uint32_max; @@ -1490,6 +852,12 @@ } +#ifdef MODPLUG_TRACKER +CModDoc *CVstPlugin::GetModDoc() { return m_SndFile.GetpModDoc(); } +const CModDoc *CVstPlugin::GetModDoc() const { return m_SndFile.GetpModDoc(); } +#endif // MODPLUG_TRACKER + + void CVstPlugin::GetPluginType(LPSTR pszType) //------------------------------------------- { @@ -1556,7 +924,6 @@ param[p - min] = GetParameter(p); return true; - } @@ -1816,7 +1183,7 @@ CString CVstPlugin::GetParamPropertyString(VstInt32 param, VstInt32 opcode) //------------------------------------------------------------------------- { - CHAR s[MAX(kVstMaxParamStrLen + 1, 64)]; // Increased to 64 bytes since 32 bytes doesn't seem to suffice for all plugs. Kind of ridiculous if you consider that kVstMaxParamStrLen = 8... + char s[MAX(kVstMaxParamStrLen + 1, 64)]; // Increased to 64 bytes since 32 bytes doesn't seem to suffice for all plugs. Kind of ridiculous if you consider that kVstMaxParamStrLen = 8... s[0] = '\0'; if(m_Effect.numParams > 0 && param < m_Effect.numParams) @@ -2561,13 +1928,13 @@ //--------------------------------------------------------------------------------------------- { note -= NOTE_MIN; - VSTInstrChannel *pMidiCh = &m_MidiCh[midiChn & 0x0f]; + VSTInstrChannel &chn = m_MidiCh[midiChn & 0x0f]; - if (!(pMidiCh->noteOnMap[note][sourceTrackerChn])) + if(!chn.noteOnMap[note][sourceTrackerChn]) return false; - pMidiCh->noteOnMap[note][sourceTrackerChn]--; - pMidiCh->noteOnMap[note][destTrackerChn]++; + chn.noteOnMap[note][sourceTrackerChn]--; + chn.noteOnMap[note][destTrackerChn]++; return true; } //end rewbs.introVST @@ -2959,541 +2326,6 @@ } - -////////////////////////////////////////////////////////////////////////////////////////////////// -// -// DirectX Media Object support -// - -//============ -class CDmo2Vst -//============ -{ -protected: - IMediaObject *m_pMediaObject; - IMediaObjectInPlace *m_pMediaProcess; - IMediaParamInfo *m_pParamInfo; - IMediaParams *m_pMediaParams; - ULONG m_nSamplesPerSec; - AEffect m_Effect; - REFERENCE_TIME m_DataTime; - int16 *m_pMixBuffer; - int16 m_MixBuffer[MIXBUFFERSIZE * 2 + 16]; // 16-bit Stereo interleaved - -public: - CDmo2Vst(IMediaObject *pMO, IMediaObjectInPlace *pMOIP, DWORD uid); - ~CDmo2Vst(); - AEffect *GetEffect() { return &m_Effect; } - VstIntPtr Dispatcher(VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt); - void SetParameter(VstInt32 index, float parameter); - float GetParameter(VstInt32 index); - void Process(float * const *inputs, float **outputs, int samples); - -public: - static VstIntPtr VSTCALLBACK DmoDispatcher(AEffect *effect, VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt); - static void VSTCALLBACK DmoSetParameter(AEffect *effect, VstInt32 index, float parameter); - static float VSTCALLBACK DmoGetParameter(AEffect *effect, VstInt32 index); - static void VSTCALLBACK DmoProcess(AEffect *effect, float **inputs, float **outputs, VstInt32 sampleframes); - -protected: - // Stream conversion functions - void InterleaveFloatToInt16(const float *inLeft, const float *inRight, int nsamples); - void DeinterleaveInt16ToFloat(float *outLeft, float *outRight, int nsamples) const; -#ifdef ENABLE_SSE - void SSEInterleaveFloatToInt16(const float *inLeft, const float *inRight, int nsamples); - void SSEDeinterleaveInt16ToFloat(float *outLeft, float *outRight, int nsamples) const; -#endif // ENABLE_SSE -}; - - -CDmo2Vst::CDmo2Vst(IMediaObject *pMO, IMediaObjectInPlace *pMOIP, DWORD uid) -//-------------------------------------------------------------------------- -{ - m_pMediaObject = pMO; - m_pMediaProcess = pMOIP; - m_pParamInfo = nullptr; - m_pMediaParams = nullptr; - MemsetZero(m_Effect); - m_Effect.magic = kDmoMagic; - m_Effect.numPrograms = 0; - m_Effect.numParams = 0; - m_Effect.numInputs = 2; - m_Effect.numOutputs = 2; - m_Effect.flags = 0; // see constants - m_Effect.ioRatio = 1.0f; - m_Effect.object = this; - m_Effect.uniqueID = uid; - m_Effect.version = 2; - m_nSamplesPerSec = 44100; - m_DataTime = 0; - if (FAILED(m_pMediaObject->QueryInterface(IID_IMediaParamInfo, (void **)&m_pParamInfo))) m_pParamInfo = nullptr; - if (m_pParamInfo) - { - DWORD dwParamCount = 0; - m_pParamInfo->GetParamCount(&dwParamCount); - m_Effect.numParams = dwParamCount; - } - if (FAILED(m_pMediaObject->QueryInterface(IID_IMediaParams, (void **)&m_pMediaParams))) m_pMediaParams = nullptr; - m_pMixBuffer = (int16 *)((((intptr_t)m_MixBuffer) + 15) & ~15); - // Callbacks - m_Effect.dispatcher = DmoDispatcher; - m_Effect.setParameter = DmoSetParameter; - m_Effect.getParameter = DmoGetParameter; - m_Effect.process = DmoProcess; - m_Effect.processReplacing = nullptr; -} - - -CDmo2Vst::~CDmo2Vst() -//------------------- -{ - if (m_pMediaParams) - { - m_pMediaParams->Release(); - m_pMediaParams = nullptr; - } - if (m_pParamInfo) - { - m_pParamInfo->Release(); - m_pParamInfo = nullptr; - } - if (m_pMediaProcess) - { - m_pMediaProcess->Release(); - m_pMediaProcess = nullptr; - } - if (m_pMediaObject) - { - m_pMediaObject->Release(); - m_pMediaObject = nullptr; - } -} - - -VstIntPtr CDmo2Vst::DmoDispatcher(AEffect *effect, VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt) -//------------------------------------------------------------------------------------------------------------------------ -{ - if (effect) - { - CDmo2Vst *that = (CDmo2Vst *)effect->object; - if (that) return that->Dispatcher(opCode, index, value, ptr, opt); - } - return 0; -} - - -void CDmo2Vst::DmoSetParameter(AEffect *effect, VstInt32 index, float parameter) -//------------------------------------------------------------------------------ -{ - if (effect) - { - CDmo2Vst *that = (CDmo2Vst *)effect->object; - if (that) that->SetParameter(index, parameter); - } -} - - -float CDmo2Vst::DmoGetParameter(AEffect *effect, VstInt32 index) -//---------------------------------------------------------- -{ - if (effect) - { - CDmo2Vst *that = (CDmo2Vst *)effect->object; - if (that) return that->GetParameter(index); - } - return 0; -} - - -void CDmo2Vst::DmoProcess(AEffect *effect, float **inputs, float **outputs, VstInt32 sampleframes) -//------------------------------------------------------------------------------------------------ -{ - if (effect) - { - CDmo2Vst *that = (CDmo2Vst *)effect->object; - if (that) that->Process(inputs, outputs, sampleframes); - } -} - - -VstIntPtr CDmo2Vst::Dispatcher(VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt) -//---------------------------------------------------------------------------------------------------- -{ - switch(opCode) - { - case effOpen: - break; - - case effClose: - m_Effect.object = nullptr; - delete this; - return 0; - - case effGetParamName: - case effGetParamLabel: - case effGetParamDisplay: - if ((index < m_Effect.numParams) && (m_pParamInfo)) - { - MP_PARAMINFO mpi; - LPSTR pszName = (LPSTR)ptr; - - mpi.mpType = MPT_INT; - mpi.szUnitText[0] = 0; - mpi.szLabel[0] = 0; - pszName[0] = 0; - if (m_pParamInfo->GetParamInfo(index, &mpi) == S_OK) - { - if (opCode == effGetParamDisplay) - { - MP_DATA md; - - if ((m_pMediaParams) && (m_pMediaParams->GetParam(index, &md) == S_OK)) - { - switch(mpi.mpType) - { - case MPT_FLOAT: - { - int nValue = (int)(md * 100.0f + 0.5f); - bool bNeg = false; - if (nValue < 0) { bNeg = true; nValue = -nValue; } - wsprintf(pszName, (bNeg) ? "-%d.%02d" : "%d.%02d", nValue/100, nValue%100); - } - break; - - case MPT_BOOL: - strcpy(pszName, ((int)md) ? "Yes" : "No"); - break; - - case MPT_ENUM: - { - WCHAR *text = nullptr; - m_pParamInfo->GetParamText(index, &text); - - const int nValue = (int)(md * (mpi.mpdMaxValue - mpi.mpdMinValue) + 0.5f); - // Always skip first two strings (param name, unit name) - for(int i = 0; i < nValue + 2; i++) - { - text += wcslen(text) + 1; - } - WideCharToMultiByte(CP_ACP, 0, text, -1, pszName, 32, nullptr, nullptr); - } - break; - - case MPT_INT: - default: - wsprintf(pszName, "%d", (int)md); - break; - } - } - } else - { - WideCharToMultiByte(CP_ACP, 0, (opCode == effGetParamName) ? mpi.szLabel : mpi.szUnitText, -1, pszName, 32, nullptr, nullptr); - } - } - } - break; - - case effCanBeAutomated: - return (index < m_Effect.numParams); - - case effSetSampleRate: - m_nSamplesPerSec = (int)opt; - { - - m_Effect.initialDelay = 0; - REFERENCE_TIME time; // Unit 100-nanoseconds - if(m_pMediaProcess->GetLatency(&time) == S_OK) - { - m_Effect.initialDelay = static_cast<VstInt32>(time * m_nSamplesPerSec / (10 * 1000 * 1000)); - } - } - break; - - case effMainsChanged: - if (value) - { - DMO_MEDIA_TYPE mt; - WAVEFORMATEX wfx; - - mt.majortype = MEDIATYPE_Audio; - mt.subtype = MEDIASUBTYPE_PCM; - mt.bFixedSizeSamples = TRUE; - mt.bTemporalCompression = FALSE; - mt.formattype = FORMAT_WaveFormatEx; - mt.pUnk = nullptr; - mt.pbFormat = (LPBYTE)&wfx; - mt.cbFormat = sizeof(WAVEFORMATEX); - mt.lSampleSize = 2 * sizeof(int16); - wfx.wFormatTag = WAVE_FORMAT_PCM; - wfx.nChannels = 2; - wfx.nSamplesPerSec = m_nSamplesPerSec; - wfx.wBitsPerSample = sizeof(int16) * 8; - wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8); - wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; - wfx.cbSize = 0; - if (FAILED(m_pMediaObject->SetInputType(0, &mt, 0)) - || FAILED(m_pMediaObject->SetOutputType(0, &mt, 0))) - { - #ifdef DMO_LOG - Log("DMO: Failed to set I/O media type\n"); - #endif - return -1; - } - } else - { - m_pMediaObject->Flush(); - m_pMediaObject->SetInputType(0, nullptr, DMO_SET_TYPEF_CLEAR); - m_pMediaObject->SetOutputType(0, nullptr, DMO_SET_TYPEF_CLEAR); - m_DataTime = 0; - } - break; - } - return 0; -} - - -void CDmo2Vst::SetParameter(VstInt32 index, float fValue) -//------------------------------------------------------- -{ - MP_PARAMINFO mpi; - - if ((index < m_Effect.numParams) && (m_pParamInfo) && (m_pMediaParams)) - { - MemsetZero(mpi); - if (m_pParamInfo->GetParamInfo(index, &mpi) == S_OK) - { - float fMin = mpi.mpdMinValue; - float fMax = mpi.mpdMaxValue; - - if (mpi.mpType == MPT_BOOL) - { - fMin = 0; - fMax = 1; - fValue = (fValue > 0.5f) ? 1.0f : 0.0f; - } - if (fMax > fMin) fValue *= (fMax - fMin); - fValue += fMin; - if (fValue < fMin) fValue = fMin; - if (fValue > fMax) fValue = fMax; - if (mpi.mpType != MPT_FLOAT) fValue = (float)(int)fValue; - m_pMediaParams->SetParam(index, fValue); - } - } -} - - -float CDmo2Vst::GetParameter(VstInt32 index) -//------------------------------------------ -{ - if ((index < m_Effect.numParams) && (m_pParamInfo) && (m_pMediaParams)) - { - MP_PARAMINFO mpi; - MP_DATA md; - - MemsetZero(mpi); - md = 0; - if (m_pParamInfo->GetParamInfo(index, &mpi) == S_OK - && m_pMediaParams->GetParam(index, &md) == S_OK) - { - float fValue, fMin, fMax, fDefault; - - fValue = md; - fMin = mpi.mpdMinValue; - fMax = mpi.mpdMaxValue; - fDefault = mpi.mpdNeutralValue; - if (mpi.mpType == MPT_BOOL) - { - fMin = 0; - fMax = 1; - } - fValue -= fMin; - if (fMax > fMin) fValue /= (fMax - fMin); - return fValue; - } - } - return 0; -} - - -static const float _f2si = 32768.0f; -static const float _si2f = 1.0f / 32768.0f; - -// Interleave two float streams into one int16 stereo stream. -void CDmo2Vst::InterleaveFloatToInt16(const float *inLeft, const float *inRight, int samples) -//------------------------------------------------------------------------------------------- -{ - int16 *outBuf = m_pMixBuffer; - for(int i = samples; i != 0; i--) - { - *(outBuf++) = static_cast<int16>(Clamp(*(inLeft++) * _f2si, static_cast<float>(int16_min), static_cast<float>(int16_max))); - *(outBuf++) = static_cast<int16>(Clamp(*(inRight++) * _f2si, static_cast<float>(int16_min), static_cast<float>(int16_max))); - } -} - - -// Deinterleave an int16 stereo stream into two float streams. -void CDmo2Vst::DeinterleaveInt16ToFloat(float *outLeft, float *outRight, int samples) const -//----------------------------------------------------------------------------------------- -{ - const int16 *inBuf = m_pMixBuffer; - for(int i = samples; i != 0; i--) - { - *outLeft++ += _si2f * static_cast<float>(*inBuf++); - *outRight++ += _si2f * static_cast<float>(*inBuf++); - } -} - - -#ifdef ENABLE_SSE -// Interleave two float streams into one int16 stereo stream using SSE magic. -void CDmo2Vst::SSEInterleaveFloatToInt16(const float *inLeft, const float *inRight, int samples) -//---------------------------------------------------------------------------------------------- -{ - int16 *outBuf = m_pMixBuffer; - _asm - { - mov eax, inLeft - mov edx, inRight - mov ebx, outBuf - mov ecx, samples - movss xmm2, _f2si - xorps xmm0, xmm0 - xorps xmm1, xmm1 - shufps xmm2, xmm2, 0x00 - pxor mm0, mm0 - inc ecx - shr ecx, 1 -mainloop: - movlps xmm0, [eax] - movlps xmm1, [edx] - mulps xmm0, xmm2 - mulps xmm1, xmm2 - add ebx, 8 - cvtps2pi mm0, xmm0 // mm0 = [ x2l | x1l ] - add eax, 8 - cvtps2pi mm1, xmm1 // mm1 = [ x2r | x1r ] - add edx, 8 - packssdw mm0, mm1 // mm0 = [x2r|x1r|x2l|x1l] - pshufw mm0, mm0, 0xD8 - dec ecx - movq [ebx-8], mm0 - jnz mainloop - emms - } -} - - -// Deinterleave an int16 stereo stream into two float streams using SSE magic. -void CDmo2Vst::SSEDeinterleaveInt16ToFloat(float *outLeft, float *outRight, int samples) const -//-------------------------------------------------------------------------------------------- -{ - const int16 *inBuf = m_pMixBuffer; - _asm { - mov ebx, inBuf - mov eax, outLeft - mov edx, outRight - mov ecx, samples - movss xmm7, _si2f - inc ecx - shr ecx, 1 - shufps xmm7, xmm7, 0x00 - xorps xmm0, xmm0 - xorps xmm1, xmm1 - xorps xmm2, xmm2 -mainloop: - movq mm0, [ebx] // mm0 = [x2r|x2l|x1r|x1l] - add ebx, 8 - pxor mm1, mm1 - pxor mm2, mm2 - punpcklwd mm1, mm0 // mm1 = [x1r|0|x1l|0] - punpckhwd mm2, mm0 // mm2 = [x2r|0|x2l|0] - psrad mm1, 16 // mm1 = [x1r|x1l] - movlps xmm2, [eax] - psrad mm2, 16 // mm2 = [x2r|x2l] - cvtpi2ps xmm0, mm1 // xmm0 = [ ? | ? |x1r|x1l] - dec ecx - cvtpi2ps xmm1, mm2 // xmm1 = [ ? | ? |x2r|x2l] - movhps xmm2, [edx] // xmm2 = [y2r|y1r|y2l|y1l] - movlhps xmm0, xmm1 // xmm0 = [x2r|x2l|x1r|x1l] - shufps xmm0, xmm0, 0xD8 - lea eax, [eax+8] - mulps xmm0, xmm7 - addps xmm0, xmm2 - lea edx, [edx+8] - movlps [eax-8], xmm0 - movhps [edx-8], xmm0 - jnz mainloop - emms - } -} - -#endif // ENABLE_SSE - - -void CDmo2Vst::Process(float * const *inputs, float **outputs, int samples) -//------------------------------------------------------------------------- -{ - if(m_pMixBuffer == nullptr || samples <= 0) - { - return; - } - -#ifdef ENABLE_SSE - if(GetProcSupport() & PROCSUPPORT_SSE) - { - SSEInterleaveFloatToInt16(inputs[0], inputs[1], samples); - m_pMediaProcess->Process(samples * 2 * sizeof(int16), reinterpret_cast<BYTE *>(m_pMixBuffer), m_DataTime, DMO_INPLACE_NORMAL); - SSEDeinterleaveInt16ToFloat(outputs[0], outputs[1], samples); - } else -#endif // ENABLE_SSE - { - InterleaveFloatToInt16(inputs[0], inputs[1], samples); - m_pMediaProcess->Process(samples * 2 * sizeof(int16), reinterpret_cast<BYTE *>(m_pMixBuffer), m_DataTime, DMO_INPLACE_NORMAL); - DeinterleaveInt16ToFloat(outputs[0], outputs[1], samples); - } - - m_DataTime += Util::muldiv(samples, 10000000, m_nSamplesPerSec); -} - - -AEffect *DmoToVst(VSTPluginLib *pLib) -//----------------------------------- -{ - CLSID clsid; - - if (CLSIDFromWString(pLib->dllPath.ToWide(), &clsid) == S_OK) - { - IMediaObject *pMO = nullptr; - IMediaObjectInPlace *pMOIP = nullptr; - if ((CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, IID_IMediaObject, (VOID **)&pMO) == S_OK) && (pMO)) - { - if (pMO->QueryInterface(IID_IMediaObjectInPlace, (void **)&pMOIP) != S_OK) pMOIP = nullptr; - } else pMO = nullptr; - if ((pMO) && (pMOIP)) - { - DWORD dwInputs, dwOutputs; - - dwInputs = dwOutputs = 0; - pMO->GetStreamCount(&dwInputs, &dwOutputs); - if (dwInputs == 1 && dwOutputs == 1) - { - CDmo2Vst *p = new CDmo2Vst(pMO, pMOIP, clsid.Data1); - return (p) ? p->GetEffect() : nullptr; - } - #ifdef DMO_LOG - Log("%s: Unable to use this DMO\n", pLib->libraryName); - #endif - } - #ifdef DMO_LOG - else Log("%s: Failed to get IMediaObject & IMediaObjectInPlace interfaces\n", pLib->libraryName); - #endif - if (pMO) pMO->Release(); - if (pMOIP) pMOIP->Release(); - } - return nullptr; -} - - #endif // NO_VST Modified: trunk/OpenMPT/mptrack/Vstplug.h =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.h 2013-11-12 20:26:19 UTC (rev 3197) +++ trunk/OpenMPT/mptrack/Vstplug.h 2013-11-12 20:54:13 UTC (rev 3198) @@ -17,9 +17,8 @@ #include "../soundlib/Snd_defs.h" #include "../soundlib/plugins/PluginMixBuffer.h" +#include "../soundlib/plugins/PlugInterface.h" -#include "../common/StringFixer.h" - //#define kBuzzMagic 'Buzz' #define kDmoMagic 'DXMO' @@ -188,8 +187,8 @@ bool GetParams(float* param, VstInt32 min, VstInt32 max); bool RandomizeParams(PlugParamIndex minParam = 0, PlugParamIndex maxParam = 0); #ifdef MODPLUG_TRACKER - inline CModDoc *GetModDoc() { return m_SndFile.GetpModDoc(); } - inline const CModDoc *GetModDoc() const { return m_SndFile.GetpModDoc(); } + forceinline CModDoc *GetModDoc(); + forceinline const CModDoc *GetModDoc() const; #endif // MODPLUG_TRACKER inline CSoundFile &GetSoundFile() { return m_SndFile; } inline const CSoundFile &GetSoundFile() const { return m_SndFile; } @@ -340,14 +339,14 @@ protected: void EnumerateDirectXDMOs(); - void LoadPlugin(const mpt::PathString &pluginPath, AEffect *&effect, HINSTANCE &library); + AEffect *LoadPlugin(const mpt::PathString &pluginPath, HINSTANCE &library); protected: VstIntPtr VstCallback(AEffect *effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void *ptr, float opt); VstIntPtr VstFileSelector(bool destructor, VstFileSelect *fileSel, const AEffect *effect); static VstIntPtr VSTCALLBACK MasterCallBack(AEffect *effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void *ptr, float opt); static bool CreateMixPluginProc(SNDMIXPLUGIN &, CSoundFile &); - VstTimeInfo timeInfo; //rewbs.VSTcompliance + VstTimeInfo timeInfo; public: static char s_szHostProductString[64]; Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-11-12 20:26:19 UTC (rev 3197) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-11-12 20:54:13 UTC (rev 3198) @@ -339,10 +339,18 @@ > </File> <File + RelativePath="..\soundlib\plugins\DmoToVst.cpp" + > + </File> + <File RelativePath="..\soundlib\plugins\JBridge.cpp" > </File> <File + RelativePath="..\soundlib\plugins\PluginManager.cpp" + > + </File> + <File RelativePath=".\mainbar.cpp" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-11-12 20:26:19 UTC (rev 3197) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-11-12 20:54:13 UTC (rev 3198) @@ -476,7 +476,9 @@ <ClCompile Include="..\soundlib\mod_specifications.cpp" /> <ClCompile Include="..\soundlib\pattern.cpp" /> <ClCompile Include="..\soundlib\patternContainer.cpp" /> + <ClCompile Include="..\soundlib\plugins\DmoToVst.cpp" /> <ClCompile Include="..\soundlib\plugins\JBridge.cpp" /> + <ClCompile Include="..\soundlib\plugins\PluginManager.cpp" /> <ClCompile Include="..\soundlib\RowVisitor.cpp" /> <ClCompile Include="..\soundlib\S3MTools.cpp" /> <ClCompile Include="..\soundlib\SampleFormats.cpp" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-11-12 20:26:19 UTC (rev 3197) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-11-12 20:54:13 UTC (rev 3198) @@ -493,6 +493,12 @@ <ClCompile Include="..\common\mptPathString.cpp"> <Filter>Source Files\common</Filter> </ClCompile> + <ClCompile Include="..\soundlib\plugins\PluginManager.cpp"> + <Filter>Source Files\soundlib\plugins</Filter> + </ClCompile> + <ClCompile Include="..\soundlib\plugins\DmoToVst.cpp"> + <Filter>Source Files\soundlib\plugins</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\soundlib\Loaders.h"> Modified: trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-12 20:26:19 UTC (rev 3197) +++ trunk/OpenMPT/sounddev/SoundDeviceASIO.cpp 2013-11-12 20:54:13 UTC (rev 3198) @@ -44,43 +44,9 @@ static int g_asio_startcount = 0; -static std::wstring CLSIDToString(CLSID clsid) -//-------------------------------------------- +std::vector<SoundDeviceInfo> CASIODevice::EnumerateDevices() +//---------------------------------------------------------- { - std::wstring str; - LPOLESTR tmp = nullptr; - StringFromCLSID(clsid, &tmp); - if(tmp) - { - str = tmp; - CoTaskMemFree(tmp); - tmp = nullptr; - } - return str; -} - - -static CLSID StringToCLSID(const std::wstring &str) -//------------------------------------------------- -{ - CLSID clsid = CLSID(); - std::vector<OLECHAR> tmp(str.c_str(), str.c_str() + str.length() + 1); - CLSIDFromString(&tmp[0], &clsid); - return clsid; -} - - -static bool IsCLSID(const std::wstring &str) -{ - CLSID clsid = CLSID(); - std::vector<OLECHAR> tmp(str.c_str(), str.c_str() + str.length() + 1); - return CLSIDFromString(&tmp[0], &clsid) == S_OK; -} - - -std::vector<SoundDeviceInfo> CASIODevice::EnumerateDevices() -//----------------------------------------------------------- -{ std::vector<SoundDeviceInfo> devices; LONG cr; @@ -128,7 +94,7 @@ if(ERROR_SUCCESS == RegQueryValueExW(hksub, L"CLSID", 0, &datatype, (LPBYTE)idBuf, &datasize)) { const std::wstring internalID = idBuf; - if(IsCLSID(internalID)) + if(Util::IsCLSID(internalID)) { #ifdef ASIO_LOG Log(" clsid=\"%s\"\n", mpt::String::Encode(idBuf, mpt::CharsetLocale).c_str()); @@ -463,7 +429,8 @@ return; } - CLSID clsid = StringToCLSID(GetDeviceInternalID()); + CLSID clsid; + Util::StringToCLSID(GetDeviceInternalID(), clsid); if (CoCreateInstance(clsid,0,CLSCTX_INPROC_SERVER, clsid, (void **)&m_pAsioDrv) == S_OK) { m_pAsioDrv->init((void *)m_Settings.hWnd); Added: trunk/OpenMPT/soundlib/plugins/DmoToVst.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/DmoToVst.cpp (rev 0) +++ trunk/OpenMPT/soundlib/plugins/DmoToVst.cpp 2013-11-12 20:54:13 UTC (rev 3198) @@ -0,0 +1,554 @@ +/* + * DmoToVst.cpp + * ------------ + * Purpose: DirectX Media Object to VST plugin adapter class. + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + + +#include "stdafx.h" + +#ifndef NO_VST +#include <uuids.h> +#include <dmoreg.h> +#include <medparam.h> +#include "../../mptrack/Vstplug.h" +#include "../Snd_defs.h" +#include "../../common/misc_util.h" + +#define DMO_LOG + + +//============ +class CDmo2Vst +//============ +{ +protected: + IMediaObject *m_pMediaObject; + IMediaObjectInPlace *m_pMediaProcess; + IMediaParamInfo *m_pParamInfo; + IMediaParams *m_pMediaParams; + ULONG m_nSamplesPerSec; + AEffect m_Effect; + REFERENCE_TIME m_DataTime; + int16 *m_pMixBuffer; + int16 m_MixBuffer[MIXBUFFERSIZE * 2 + 16]; // 16-bit Stereo interleaved + +public: + CDmo2Vst(IMediaObject *pMO, IMediaObjectInPlace *pMOIP, DWORD uid); + ~CDmo2Vst(); + AEffect *GetEffect() { return &m_Effect; } + VstIntPtr Dispatcher(VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt); + void SetParameter(VstInt32 index, float parameter); + float GetParameter(VstInt32 index); + void Process(float * const *inputs, float **outputs, int samples); + +public: + static VstIntPtr VSTCALLBACK DmoDispatcher(AEffect *effect, VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt); + static void VSTCALLBACK DmoSetParameter(AEffect *effect, VstInt32 index, float parameter); + static float VSTCALLBACK DmoGetParameter(AEffect *effect, VstInt32 index); + static void VSTCALLBACK DmoProcess(AEffect *effect, float **inputs, float **outputs, VstInt32 sampleframes); + +protected: + // Stream conversion functions + void InterleaveFloatToInt16(const float *inLeft, const float *inRight, int nsamples); + void DeinterleaveInt16ToFloat(float *outLeft, float *outRight, int nsamples) const; +#ifdef ENABLE_SSE + void SSEInterleaveFloatToInt16(const float *inLeft, const float *inRight, int nsamples); + void SSEDeinterleaveInt16ToFloat(float *outLeft, float *outRight, int nsamples) const; +#endif // ENABLE_SSE +}; + + +CDmo2Vst::CDmo2Vst(IMediaObject *pMO, IMediaObjectInPlace *pMOIP, DWORD uid) +//-------------------------------------------------------------------------- +{ + m_pMediaObject = pMO; + m_pMediaProcess = pMOIP; + m_pParamInfo = nullptr; + m_pMediaParams = nullptr; + + MemsetZero(m_Effect); + m_Effect.magic = kDmoMagic; + m_Effect.numPrograms = 0; + m_Effect.numParams = 0; + m_Effect.numInputs = 2; + m_Effect.numOutputs = 2; + m_Effect.flags = 0; // see constants + m_Effect.ioRatio = 1.0f; + m_Effect.object = this; + m_Effect.uniqueID = uid; + m_Effect.version = 2; + + m_nSamplesPerSec = 44100; + m_DataTime = 0; + if (FAILED(m_pMediaObject->QueryInterface(IID_IMediaParamInfo, (void **)&m_pParamInfo))) m_pParamInfo = nullptr; + if (m_pParamInfo) + { + DWORD dwParamCount = 0; + m_pParamInfo->GetParamCount(&dwParamCount); + m_Effect.numParams = dwParamCount; + } + if (FAILED(m_pMediaObject->QueryInterface(IID_IMediaParams, (void **)&m_pMediaParams))) m_pMediaParams = nullptr; + m_pMixBuffer = (int16 *)((((intptr_t)m_MixBuffer) + 15) & ~15); + // Callbacks + m_Effect.dispatcher = DmoDispatcher; + m_Effect.setParameter = DmoSetParameter; + m_Effect.getParameter = DmoGetParameter; + m_Effect.process = DmoProcess; + m_Effect.processReplacing = nullptr; +} + + +CDmo2Vst::~CDmo2Vst() +//------------------- +{ + if (m_pMediaParams) + { + m_pMediaParams->Release(); + m_pMediaParams = nullptr; + } + if (m_pParamInfo) + { + m_pParamInfo->Release(); + m_pParamInfo = nullptr; + } + if (m_pMediaProcess) + { + m_pMediaProcess->Release(); + m_pMediaProcess = nullptr; + } + if (m_pMediaObject) + { + m_pMediaObject->Release(); + m_pMediaObject = nullptr; + } +} + + +VstIntPtr CDmo2Vst::DmoDispatcher(AEffect *effect, VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt) +//------------------------------------------------------------------------------------------------------------------------ +{ + if (effect) + { + CDmo2Vst *that = (CDmo2Vst *)effect->object; + if (that) return that->Dispatcher(opCode, index, value, ptr, opt); + } + return 0; +} + + +void CDmo2Vst::DmoSetParameter(AEffect *effect, VstInt32 index, float parameter) +//------------------------------------------------------------------------------ +{ + if (effect) + { + CDmo2Vst *that = (CDmo2Vst *)effect->object; + if (that) that->SetParameter(index, parameter); + } +} + + +float CDmo2Vst::DmoGetParameter(AEffect *effect, VstInt32 index) +//---------------------------------------------------------- +{ + if (effect) + { + CDmo2Vst *that = (CDmo2Vst *)effect->object; + if (that) return that->GetParameter(index); + } + return 0; +} + + +void CDmo2Vst::DmoProcess(AEffect *effect, float **inputs, float **outputs, VstInt32 sampleframes) +//------------------------------------------------------------------------------------------------ +{ + if (effect) + { + CDmo2Vst *that = (CDmo2Vst *)effect->object; + if (that) that->Process(inputs, outputs, sampleframes); + } +} + + +VstIntPtr CDmo2Vst::Dispatcher(VstInt32 opCode, VstInt32 index, VstIntPtr value, void *ptr, float opt) +//---------------------------------------------------------------------------------------------------- +{ + switch(opCode) + { + case effOpen: + break; + + case effClose: + m_Effect.object = nullptr; + delete this; + return 0; + + case effGetParamName: + case effGetParamLabel: + case effGetParamDisplay: + if ((index < m_Effect.numParams) && (m_pParamInfo)) + { + MP_PARAMINFO mpi; + char *pszName = (char *)ptr; + + mpi.mpType = MPT_INT; + mpi.szUnitText[0] = 0; + mpi.szLabel[0] = 0; + pszName[0] = 0; + if (m_pParamInfo->GetParamInfo(index, &mpi) == S_OK) + { + if (opCode == effGetParamDisplay) + { + MP_DATA md; + + if ((m_pMediaParams) && (m_pMediaParams->GetParam(index, &md) == S_OK)) + { + switch(mpi.mpType) + { + case MPT_FLOAT: + { + int nValue = (int)(md * 100.0f + 0.5f); + bool bNeg = false; + if (nValue < 0) { bNeg = true; nValue = -nValue; } + wsprintf(pszName, (bNeg) ? "-%d.%02d" : "%d.%02d", nValue/100, nValue%100); + } + break; + + case MPT_BOOL: + strcpy(pszName, ((int)md) ? "Yes" : "No"); + break; + + case MPT_ENUM: + { + WCHAR *text = nullptr; + m_pParamInfo->GetParamText(index, &text); + + const int nValue = (int)(md * (mpi.mpdMaxValue - mpi.mpdMinValue) + 0.5f); + // Always skip first two strings (param name, unit name) + for(int i = 0; i < nValue + 2; i++) + { + text += wcslen(text) + 1; + } + WideCharToMultiByte(CP_ACP, 0, text, -1, pszName, 32, nullptr, nullptr); + } + break; + + case MPT_INT: + default: + wsprintf(pszName, "%d", (int)md); + break; + } + } + } else + { + WideCharToMultiByte(CP_ACP, 0, (opCode == effGetParamName) ? mpi.szLabel : mpi.szUnitText, -1, pszName, 32, nullptr, nullptr); + } + } + } + break; + + case effCanBeAutomated: + return (index < m_Effect.numParams); + + case effSetSampleRate: + m_nSamplesPerSec = (int)opt; + { + + m_Effect.initialDelay = 0; + REFERENCE_TIME time; // Unit 100-nanoseconds + if(m_pMediaProcess->GetLatency(&time) == S_OK) + { + m_Effect.initialDelay = static_cast<VstInt32>(time * m_nSamplesPerSec / (10 * 1000 * 1000)); + } + } + break; + + case effMainsChanged: + if (value) + { + DMO_MEDIA_TYPE mt; + WAVEFORMATEX wfx; + + mt.majortype = MEDIATYPE_Audio; + mt.subtype = MEDIASUBTYPE_PCM; + mt.bFixedSizeSamples = TRUE; + mt.bTemporalCompression = FALSE; + mt.formattype = FORMAT_WaveFormatEx; + mt.pUnk = nullptr; + mt.pbFormat = (LPBYTE)&wfx; + mt.cbFormat = sizeof(WAVEFORMATEX); + mt.lSampleSize = 2 * sizeof(int16); + wfx.wFormatTag = WAVE_FORMAT_PCM; + wfx.nChannels = 2; + wfx.nSamplesPerSec = m_nSamplesPerSec; + wfx.wBitsPerSample = sizeof(int16) * 8; + wfx.nBlockAlign = wfx.nChannels * (wfx.wBitsPerSample / 8); + wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; + wfx.cbSize = 0; + if (FAILED(m_pMediaObject->SetInputType(0, &mt, 0)) + || FAILED(m_pMediaObject->SetOutputType(0, &mt, 0))) + { +#ifdef DMO_LOG + Log("DMO: Failed to set I/O media type\n"); +#endif + return -1; + } + } else + { + m_pMediaObject->Flush(); + m_pMediaObject->SetInputType(0, nullptr, DMO_SET_TYPEF_CLEAR); + m_pMediaObject->SetOutputType(0, nullptr, DMO_SET_TYPEF_CLEAR); + m_DataTime = 0; + } + break; + } + return 0; +} + + +void CDmo2Vst::SetParameter(VstInt32 index, float fValue) +//------------------------------------------------------- +{ + MP_PARAMINFO mpi; + + if ((index < m_Effect.numParams) && (m_pParamInfo) && (m_pMediaParams)) + { + MemsetZero(mpi); + if (m_pParamInfo->GetParamInfo(index, &mpi) == S_OK) + { + float fMin = mpi.mpdMinValue; + float fMax = mpi.mpdMaxValue; + + if (mpi.mpType == MPT_BOOL) + { + fMin = 0; + fMax = 1; + fValue = (fValue > 0.5f) ? 1.0f : 0.0f; + } + if (fMax > fMin) fValue *= (fMax - fMin); + fValue += fMin; + if (fValue < fMin) fValue = fMin; + if (fValue > fMax) fValue = fMax; + if (mpi.mpType != MPT_FLOAT) fValue = (float)(int)fValue; + m_pMediaParams->SetParam(index, fValue); + } + } +} + + +float CDmo2Vst::GetParameter(VstInt32 index) +//------------------------------------------ +{ + if ((index < m_Effect.numParams) && (m_pParamInfo) && (m_pMediaParams)) + { + MP_PARAMINFO mpi; + MP_DATA md; + + MemsetZero(mpi); + md = 0; + if (m_pParamInfo->GetParamInfo(index, &mpi) == S_OK + && m_pMediaParams->GetParam(index, &md) == S_OK) + { + float fValue, fMin, fMax, fDefault; + + fValue = md; + fMin = mpi.mpdMinValue; + fMax = mpi.mpdMaxValue; + fDefault = mpi.mpdNeutralValue; + if (mpi.mpType == MPT_BOOL) + { + fMin = 0; + fMax = 1; + } + fValue -= fMin; + if (fMax > fMin) fValue /= (fMax - fMin); + return fValue; + } + } + return 0; +} + + +static const float _f2si = 32768.0f; +static const float _si2f = 1.0f / 32768.0f; + +// Interleave two float streams into one int16 stereo stream. +void CDmo2Vst::InterleaveFloatToInt16(const float *inLeft, const float *inRight, int samples) +//------------------------------------------------------------------------------------------- +{ + int16 *outBuf = m_pMixBuffer; + for(int i = samples; i != 0; i--) + { + *(outBuf++) = static_cast<int16>(Clamp(*(inLeft++) * _f2si, static_cast<float>(int16_min), static_cast<float>(int16_max))); + *(outBuf++) = static_cast<int16>(Clamp(*(inRight++) * _f2si, static_cast<float>(int16_min), static_cast<float>(int16_max))); + } +} + + +// Deinterleave an int16 stereo stream into two float streams. +void CDmo2Vst::DeinterleaveInt16ToFloat(float *outLeft, float *outRight, int samples) const +//----------------------------------------------------------------------------------------- +{ + const int16 *inBuf = m_pMixBuffer; + for(int i = samples; i != 0; i--) + { + *outLeft++ += _si2f * static_cast<float>(*inBuf++); + *outRight++ += _si2f * static_cast<float>(*inBuf++); + } +} + + +#ifdef ENABLE_SSE +// Interleave two float streams into one int16 stereo stream using SSE magic. +void CDmo2Vst::SSEInterleaveFloatToInt16(const float *inLeft, const float *inRight, int samples) +//---------------------------------------------------------------------------------------------- +{ + int16 *outBuf = m_pMixBuffer; + _asm + { + mov eax, inLeft + mov edx, inRight + mov ebx, outBuf + mov ecx, samples + movss xmm2, _f2si + xorps xmm0, xmm0 + xorps xmm1, xmm1 + shufps xmm2, xmm2, 0x00 + pxor mm0, mm0 + inc ecx + shr ecx, 1 +mainloop: + movlps xmm0, [eax] + movlps xmm1, [edx] + mulps xmm0, xmm2 + mulps xmm1, xmm2 + add ebx, 8 + cvtps2pi mm0, xmm0 // mm0 = [ x2l | x1l ] + add eax, 8 + cvtps2pi mm1, xmm1 // mm1 = [ x2r | x1r ] + add edx, 8 + packssdw mm0, mm1 // mm0 = [x2r|x1r|x2l|x1l] + pshufw mm0, mm0, 0xD8 + dec ecx + movq [ebx-8], mm0 + jnz mainloop + emms + } +} + + +// Deinterleave an int16 stereo stream into two float streams using SSE magic. +void CDmo2Vst::SSEDeinterleaveInt16ToFloat(float *outLeft, float *outRight, int samples) const +//-------------------------------------------------------------------------------------------- +{ + const int16 *inBuf = m_pMixBuffer; + _asm { + mov ebx, inBuf + mov eax, outLeft + mov edx, outRight + mov ecx, samples + movss xmm7, _si2f + inc ecx + shr ecx, 1 + shufps xmm7, xmm7, 0x00 + xorps xmm0, xmm0 + xorps xmm1, xmm1 + xorps xmm2, xmm2 +mainloop: + movq mm0, [ebx] // mm0 = [x2r|x2l|x1r|x1l] + add ebx, 8 + pxor mm1, mm1 + pxor mm2, mm2 + punpcklwd mm1, mm0 // mm1 = [x1r|0|x1l|0] + punpckhwd mm2, mm0 // mm2 = [x2r|0|x2l|0] + psrad mm1, 16 // mm1 = [x1r|x1l] + movlps xmm2, [eax] + psrad mm2, 16 // mm2 = [x2r|x2l] + cvtpi2ps xmm0, mm1 // xmm0 = [ ? | ? |x1r|x1l] + dec ecx + cvtpi2ps xmm1, mm2 // xmm1 = [ ? | ? |x2r|x2l] + movhps xmm2, [edx] // xmm2 = [y2r|y1r|y2l|y1l] + movlhps xmm0, xmm1 // xmm0 = [x2r|x2l|x1r|x1l] + shufps xmm0, xmm0, 0xD8 + lea eax, [eax+8] + mulps xmm0, xmm7 + addps xmm0, xmm2 + lea edx, [edx+8] + movlps [eax-8], xmm0 + movhps [edx-8], xmm0 + jnz mainloop + emms + } +} + +#endif // ENABLE_SSE + + +void CDmo2Vst::Process(float * const *inputs, float **outputs, int samples) +//------------------------------------------------------------------------- +{ + if(m_pMixBuffer == nullptr || samples <= 0) + { + return; + } + +#ifdef ENABLE_SSE + if(GetProcSupport() & PROCSUPPORT_SSE) + { + SSEInterleaveFloatToInt16(inputs[0], inputs[1], samples); + m_pMediaProcess->Process(samples * 2 * sizeof(int16), reinterpret_cast<BYTE *>(m_pMixBuffer), m_DataTime, DMO_INPLACE_NORMAL); + SSEDeinterleaveInt16ToFloat(outputs[0], outputs[1], samples); + } else +#endif // ENABLE_SSE + { + InterleaveFloatToInt16(inputs[0], inputs[1], samples); + m_pMediaProcess->Process(samples * 2 * sizeof(int16), reinterpret_cast<BYTE *>(m_pMixBuffer), m_DataTime, DMO_INPLACE_NORMAL); + DeinterleaveInt16ToFloat(outputs[0], outputs[1], samples); + } + + m_DataTime += Util::muldiv(samples, 10000000, m_nSamplesPerSec); +} + + +// The actual adapter function. +AEffect *DmoToVst(VSTPluginLib &lib) +//---------------------------------- +{ + CLSID clsid; + if (Util::StringToCLSID(lib.dllPath.ToWide(), clsid)) + { + IMediaObject *pMO = nullptr; + IMediaObjectInPlace *pMOIP = nullptr; + if ((CoCreateInstance(clsid, nullptr, CLSCTX_INPROC_SERVER, IID_IMediaObject, (VOID **)&pMO) == S_OK) && (pMO)) + { + if (pMO->Q... [truncated message content] |
From: <sag...@us...> - 2013-11-12 21:18:08
|
Revision: 3199 http://sourceforge.net/p/modplug/code/3199 Author: saga-games Date: 2013-11-12 21:17:57 +0000 (Tue, 12 Nov 2013) Log Message: ----------- [New] Instrument library is now refreshed automatically when there are changes in the folder (e.g. adding new files) [Ref] Added mpt::thread to unify thread creation code. [Fix] DMO plugins broke in previous revision. Modified Paths: -------------- trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/UpdateCheck.cpp trunk/OpenMPT/mptrack/UpdateCheck.h trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/mptrack/View_tre.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters trunk/OpenMPT/soundlib/plugins/PluginManager.cpp Added Paths: ----------- trunk/OpenMPT/common/thread.h Added: trunk/OpenMPT/common/thread.h =================================================================== --- trunk/OpenMPT/common/thread.h (rev 0) +++ trunk/OpenMPT/common/thread.h 2013-11-12 21:17:57 UTC (rev 3199) @@ -0,0 +1,61 @@ +/* + * thread.h + * -------- + * Purpose: Helper class for running threads, with a more or less platform-independent interface. + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + +#pragma once + +namespace mpt +{ + +// Default WinAPI thread +class thread +{ +protected: + HANDLE threadHandle; + +public: + + enum Priority + { + lowest = THREAD_PRIORITY_LOWEST, + lower = THREAD_PRIORITY_BELOW_NORMAL, + normal = THREAD_PRIORITY_NORMAL, + high = THREAD_PRIORITY_ABOVE_NORMAL, + highest = THREAD_PRIORITY_HIGHEST + }; + + operator HANDLE& () { return threadHandle; } + operator bool () { return threadHandle != nullptr; } + + thread() : threadHandle(nullptr) { } + thread(LPTHREAD_START_ROUTINE function, void *userData = nullptr, Priority priority = normal) + { + DWORD dummy; // For Win9x + threadHandle = CreateThread(NULL, 0, function, userData, 0, &dummy); + SetThreadPriority(threadHandle, priority); + } +}; + + +// Thread that operates on a member function +template<typename T, void (T::*Fun)()> +class thread_member : public thread +{ +protected: + static DWORD WINAPI wrapperFunc(LPVOID param) + { + (static_cast<T *>(param)->*Fun)(); + return 0; + } + +public: + + thread_member(T *instance, Priority priority = normal) : thread(wrapperFunc, instance, priority) { } +}; + +} // namespace mpt Modified: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/common/versionNumber.h 2013-11-12 21:17:57 UTC (rev 3199) @@ -17,7 +17,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 22 #define VER_MINOR 06 -#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/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-11-12 21:17:57 UTC (rev 3199) @@ -2504,8 +2504,7 @@ void CMainFrame::OnInternetUpdate() //--------------------------------- { - CUpdateCheck *updateCheck = CUpdateCheck::Create(false); - updateCheck->DoUpdateCheck(); + CUpdateCheck::DoUpdateCheck(false); } Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-11-12 21:17:57 UTC (rev 3199) @@ -898,10 +898,9 @@ m_dwTimeStarted = timeGetTime(); m_bInitialized = TRUE; - if (CUpdateCheck::GetUpdateCheckPeriod() != 0) + if(CUpdateCheck::GetUpdateCheckPeriod() != 0) { - CUpdateCheck *updateCheck = CUpdateCheck::Create(true); - updateCheck->DoUpdateCheck(); + CUpdateCheck::DoUpdateCheck(true); } // Open settings if the previous execution was with an earlier version. Modified: trunk/OpenMPT/mptrack/UpdateCheck.cpp =================================================================== --- trunk/OpenMPT/mptrack/UpdateCheck.cpp 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/UpdateCheck.cpp 2013-11-12 21:17:57 UTC (rev 3199) @@ -18,11 +18,7 @@ #include "Mainfrm.h" #include "Moptions.h" -#ifdef _DEBUG -#define new DEBUG_NEW -#endif - const CString CUpdateCheck::defaultUpdateURL = "http://update.openmpt.org/check/$VERSION/$GUID"; // Static configuration variables @@ -33,55 +29,31 @@ bool CUpdateCheck::showUpdateHint = true; -CUpdateCheck::CUpdateCheck(const bool autoUpdate) +// Start update check +void CUpdateCheck::DoUpdateCheck(bool autoUpdate) //----------------------------------------------- { - isAutoUpdate = autoUpdate; - threadHandle = NULL; -} - - -CUpdateCheck::~CUpdateCheck() -//--------------------------- -{ - if(threadHandle != NULL) + CUpdateCheck *that = new (std::nothrow) CUpdateCheck(autoUpdate); + if(that != nullptr) { - CloseHandle(threadHandle); + that->threadHandle = mpt::thread_member<CUpdateCheck, &CUpdateCheck::UpdateThread>(that, autoUpdate ? mpt::thread::lower : mpt::thread::normal); } } -// Start update check -void CUpdateCheck::DoUpdateCheck() -//-------------------------------- -{ - internetHandle = NULL; - connectionHandle = NULL; - - DWORD dummy; // For Win9x - threadHandle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&CUpdateCheck::UpdateThread, (LPVOID)this, 0, &dummy); - if(isAutoUpdate) - { - SetThreadPriority(threadHandle, THREAD_PRIORITY_BELOW_NORMAL); - } -} - - // Run update check (independent thread) -DWORD WINAPI CUpdateCheck::UpdateThread(LPVOID param) -//--------------------------------------------------- +void CUpdateCheck::UpdateThread() +//------------------------------- { - CUpdateCheck *caller = (CUpdateCheck *)param; - const time_t now = time(nullptr); - if(caller->isAutoUpdate) + if(isAutoUpdate) { // Do we actually need to run the update check right now? if(CUpdateCheck::updateCheckPeriod == 0 || difftime(now, CUpdateCheck::lastUpdateCheck) < (double)(CUpdateCheck::updateCheckPeriod * 86400)) { - caller->Terminate(); - return 0; + Terminate(); + return; } // Never ran update checks before, so we notify the user of automatic update checks. @@ -93,8 +65,8 @@ if(Reporting::Confirm(msg, "OpenMPT Internet Update") == cnfNo) { CUpdateCheck::lastUpdateCheck = now; - caller->Terminate(); - return 0; + Terminate(); + return; } } @@ -108,57 +80,57 @@ updateURL.Replace("$GUID", GetSendGUID() ? TrackerSettings::Instance().gcsInstallGUID.Get() : "anonymous"); // Establish a connection. - caller->internetHandle = InternetOpen(userAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); - if(caller->internetHandle == NULL) + internetHandle = InternetOpen(userAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); + if(internetHandle == NULL) { - caller->Die("Could not start update check:\n", GetLastError()); - return 0; + Die("Could not start update check:\n", GetLastError()); + return; } - caller->connectionHandle = InternetOpenUrl(caller->internetHandle, updateURL, NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_UI, 0); - if(caller->connectionHandle == NULL) + connectionHandle = InternetOpenUrl(internetHandle, updateURL, NULL, 0, INTERNET_FLAG_RELOAD | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_UI, 0); + if(connectionHandle == NULL) { - caller->Die("Could not establish connection:\n", GetLastError()); - return 0; + Die("Could not establish connection:\n", GetLastError()); + return; } // Retrieve HTTP status code. DWORD statusCodeHTTP = 0; DWORD length = sizeof(statusCodeHTTP); - if(HttpQueryInfo(caller->connectionHandle, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, (LPVOID)&statusCodeHTTP, &length, NULL) == FALSE) + if(HttpQueryInfo(connectionHandle, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, (LPVOID)&statusCodeHTTP, &length, NULL) == FALSE) { - caller->Die("Could not retrieve HTTP header information:\n", GetLastError()); - return 0; + Die("Could not retrieve HTTP header information:\n", GetLastError()); + return; } if(statusCodeHTTP >= 400) { CString error; error.Format("Version information could not be found on the server (HTTP status code %d). Maybe your version of OpenMPT is too old!", statusCodeHTTP); - caller->Die(error); - return 0; + Die(error); + return; } // Download data. CString resultData = ""; char *downloadBuffer = new char[DOWNLOAD_BUFFER_SIZE]; - DWORD availableSize, bytesRead; + DWORD availableSize, bytesRead; do { // Query number of available bytes to download - if(InternetQueryDataAvailable(caller->connectionHandle, &availableSize, 0, NULL) == FALSE) + if(InternetQueryDataAvailable(connectionHandle, &availableSize, 0, NULL) == FALSE) { delete[] downloadBuffer; - caller->Die("Error while downloading update information data:\n", GetLastError()); - return 0; + Die("Error while downloading update information data:\n", GetLastError()); + return; } LimitMax(availableSize, (DWORD)DOWNLOAD_BUFFER_SIZE); // Put downloaded bytes into our buffer - if(InternetReadFile(caller->connectionHandle, downloadBuffer, availableSize, &bytesRead) == FALSE) + if(InternetReadFile(connectionHandle, downloadBuffer, availableSize, &bytesRead) == FALSE) { delete[] downloadBuffer; - caller->Die("Error while downloading update information data:\n", GetLastError()); - return 0; + Die("Error while downloading update information data:\n", GetLastError()); + return; } resultData.Append(downloadBuffer, availableSize); @@ -170,7 +142,7 @@ // Now, evaluate the downloaded data. if(!resultData.CompareNoCase("noupdate")) { - if(!caller->isAutoUpdate) + if(!isAutoUpdate) { Reporting::Information("You already have the latest version of OpenMPT installed.", "OpenMPT Internet Update"); } @@ -187,8 +159,8 @@ case 0: if(token.CompareNoCase("update") != 0) { - caller->Die("Could not understand server response. Maybe your version of OpenMPT is too old!"); - return 0; + Die("Could not understand server response. Maybe your version of OpenMPT is too old!"); + return; } break; case 1: @@ -211,15 +183,14 @@ } } else { - caller->Die("Could not understand server response. Maybe your version of OpenMPT is too old!"); - return 0; + Die("Could not understand server response. Maybe your version of OpenMPT is too old!"); + return; } } CUpdateCheck::lastUpdateCheck = now; - caller->Terminate(); - return 0; + Terminate(); } @@ -241,7 +212,7 @@ { if(!isAutoUpdate) { - LPVOID lpMsgBuf; + void *lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, GetModuleHandle(TEXT("wininet.dll")), errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL); @@ -256,17 +227,16 @@ void CUpdateCheck::Terminate() //---------------------------- { - if(connectionHandle != NULL) + if(connectionHandle != nullptr) { InternetCloseHandle(connectionHandle); - connectionHandle = NULL; + connectionHandle = nullptr; } - if(internetHandle != NULL) + if(internetHandle != nullptr) { InternetCloseHandle(internetHandle); - internetHandle = NULL; + internetHandle = nullptr; } - threadHandle = NULL; // If we got here, the thread asked for termination, so don't use CloseHandle() delete this; } Modified: trunk/OpenMPT/mptrack/UpdateCheck.h =================================================================== --- trunk/OpenMPT/mptrack/UpdateCheck.h 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/UpdateCheck.h 2013-11-12 21:17:57 UTC (rev 3199) @@ -14,8 +14,8 @@ #include <time.h> #include "resource.h" +#include "../common/thread.h" - #define DOWNLOAD_BUFFER_SIZE 256 //================ @@ -26,9 +26,7 @@ static const CString defaultUpdateURL; - // Force creation via "new" as we're using "delete this". - static CUpdateCheck *Create(bool autoUpdate) { return new CUpdateCheck(autoUpdate); }; - void DoUpdateCheck(); + static void DoUpdateCheck(bool autoUpdate); static time_t GetLastUpdateCheck() { return lastUpdateCheck; }; static int GetUpdateCheckPeriod() { return updateCheckPeriod; }; @@ -50,13 +48,13 @@ bool isAutoUpdate; // Are we running an automatic update check? // Runtime resource handles - HANDLE threadHandle; + mpt::thread threadHandle; HINTERNET internetHandle, connectionHandle; - CUpdateCheck(const bool showErrors); - ~CUpdateCheck(); + // Force creation via "new" as we're using "delete this". Use CUpdateCheck::DoUpdateCheck to create an object. + CUpdateCheck::CUpdateCheck(bool autoUpdate) : internetHandle(nullptr), connectionHandle(nullptr), isAutoUpdate(autoUpdate) { } - static DWORD WINAPI UpdateThread(LPVOID param); + void UpdateThread(); void Die(CString errorMessage); void Die(CString errorMessage, DWORD errorCode); void Terminate(); Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-12 21:17:57 UTC (rev 3199) @@ -116,13 +116,20 @@ CModTree::CModTree(CModTree *pDataTree) : m_pDataTree(pDataTree), m_hDropWnd(nullptr), + m_hWatchDir(nullptr), m_dwStatus(0), m_nDocNdx(0), m_nDragDocNdx(0), m_hItemDrag(nullptr), m_hItemDrop(nullptr), m_hInsLib(nullptr), m_hMidiLib(nullptr), m_bShowAllFiles(false), doLabelEdit(false) -//------------------------------------- +//-------------------------------------------- { + if(m_pDataTree != nullptr) + { + // Set up instrument library monitoring thread + m_hWatchDirKillThread = CreateEvent(NULL, FALSE, FALSE, NULL); + watchDirThread = mpt::thread_member<CModTree, &CModTree::MonitorInstrumentLibrary>(this, mpt::thread::lowest); + } MemsetZero(m_tiMidi); MemsetZero(m_tiPerc); } @@ -143,6 +150,12 @@ delete m_SongFile; m_SongFile = nullptr; } + + if(m_pDataTree != nullptr) + { + SetEvent(m_hWatchDirKillThread); + WaitForSingleObject(watchDirThread, INFINITE); + } } @@ -423,7 +436,7 @@ for(UINT iMidi = 0; iMidi < 128; iMidi++) { DWORD dwImage = IMAGE_NOINSTRUMENT; - s = StringifyW(iMidi) + L": " + mpt::String::Decode(szMidiProgramNames[iMidi], mpt::CharsetUTF8); + s = StringifyW(iMidi) + L": " + mpt::String::Decode(szMidiProgramNames[iMidi], mpt::CharsetUS_ASCII); const LPARAM param = (MODITEM_MIDIINSTRUMENT << MIDILIB_SHIFT) | iMidi; if(!midiLib.MidiMap[iMidi].empty()) { @@ -457,7 +470,7 @@ for (UINT iPerc=24; iPerc<=84; iPerc++) { DWORD dwImage = IMAGE_NOSAMPLE; - s = mpt::String::Decode(szDefaultNoteNames[iPerc], mpt::CharsetUTF8) + L": " + mpt::String::Decode(szMidiPercussionNames[iPerc - 24], mpt::CharsetUTF8); + s = mpt::String::Decode(szDefaultNoteNames[iPerc], mpt::CharsetUS_ASCII) + L": " + mpt::String::Decode(szMidiPercussionNames[iPerc - 24], mpt::CharsetUS_ASCII); const LPARAM param = (MODITEM_MIDIPERCUSSION << MIDILIB_SHIFT) | iPerc; if(!midiLib.MidiMap[iPerc | 0x80].empty()) { @@ -650,7 +663,7 @@ void CModTree::UpdateView(ModTreeDocInfo *pInfo, DWORD lHint) //---------------------------------------------------------- { - CHAR s[256], stmp[256]; + TCHAR s[256], stmp[256]; TV_ITEM tvi; const DWORD hintFlagPart = HintFlagPart(lHint); if ((pInfo == nullptr) || (pInfo->pModDoc == nullptr) || IsSampleBrowser()) return; @@ -670,9 +683,9 @@ if (!pInfo->hSong) { pInfo->hSong = InsertItem(s, TVI_ROOT, TVI_FIRST); - pInfo->hOrders = InsertItem("Sequence", IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); - pInfo->hPatterns = InsertItem("Patterns", IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); - pInfo->hSamples = InsertItem("Samples", IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); + pInfo->hOrders = InsertItem(_T("Sequence"), IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); + pInfo->hPatterns = InsertItem(_T("Patterns"), IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); + pInfo->hSamples = InsertItem(_T("Samples"), IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); } if (hintFlagPart & (HINT_MODGENERAL|HINT_MODTYPE)) { @@ -682,7 +695,7 @@ tvi.cchTextMax = CountOf(stmp); tvi.iImage = tvi.iSelectedImage = IMAGE_FOLDER; GetItem(&tvi); - if ((strcmp(s, stmp)) || (tvi.iImage != IMAGE_FOLDER)) + if(tvi.iImage != IMAGE_FOLDER || strcmp(s, stmp)) { tvi.mask |= TVIF_TEXT | TVIF_HANDLE | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; tvi.hItem = pInfo->hSong; @@ -694,7 +707,7 @@ } if (sndFile.GetModSpecifications().instrumentsMax > 0) { - if (!pInfo->hInstruments) pInfo->hInstruments = InsertItem("Instruments", IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); + if (!pInfo->hInstruments) pInfo->hInstruments = InsertItem(_T("Instruments"), IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); } else { if (pInfo->hInstruments) @@ -704,7 +717,7 @@ pInfo->hInstruments = NULL; } } - if (!pInfo->hComments) pInfo->hComments = InsertItem("Comments", IMAGE_COMMENTS, IMAGE_COMMENTS, pInfo->hSong, TVI_LAST); + if (!pInfo->hComments) pInfo->hComments = InsertItem(_T("Comments"), IMAGE_COMMENTS, IMAGE_COMMENTS, pInfo->hSong, TVI_LAST); // Add effects if (hintFlagPart & (HINT_MODGENERAL|HINT_MODTYPE|HINT_MODCHANNELS|HINT_MIXPLUGINS)) { @@ -717,7 +730,7 @@ { if (!pInfo->hEffects) { - pInfo->hEffects = InsertItem("Plugins", IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); + pInfo->hEffects = InsertItem(_T("Plugins"), IMAGE_FOLDER, IMAGE_FOLDER, pInfo->hSong, TVI_LAST); } wsprintf(s, "FX%u: %s", iFx + 1, plugin.GetName()); int nImage = IMAGE_NOPLUGIN; @@ -781,12 +794,12 @@ // Adjust caption of the "Sequence" node (if only one sequence exists, it should be labeled with the sequence name) if(((hintFlagPart & HINT_SEQNAMES) && sndFile.Order.GetNumSequences() == 1) || adjustParentNode) { - CString sSeqName = sndFile.Order.GetSequence(0).m_sName; - if(sSeqName.IsEmpty() || sndFile.Order.GetNumSequences() > 1) - sSeqName = "Sequence"; + CString seqName = sndFile.Order.GetSequence(0).m_sName; + if(seqName.IsEmpty() || sndFile.Order.GetNumSequences() > 1) + seqName = _T("Sequence"); else - sSeqName = "Sequence: " + sSeqName; - SetItem(pInfo->hOrders, TVIF_TEXT, sSeqName, 0, 0, 0, 0, 0); + seqName = _T("Sequence: ") + seqName; + SetItem(pInfo->hOrders, TVIF_TEXT, seqName, 0, 0, 0, 0, 0); } // go through all sequences @@ -874,7 +887,7 @@ tvi.pszText = stmp; tvi.cchTextMax = CountOf(stmp); GetItem(&tvi); - if ((strcmp(s, stmp)) || (tvi.state != state)) + if(tvi.state != state || strcmp(s, stmp)) SetItem(pInfo->tiOrders[nSeq][iOrd], TVIF_TEXT | TVIF_STATE | TVIF_PARAM, s, 0, 0, state, TVIS_BOLD, param); } else { @@ -967,7 +980,7 @@ tvi.cchTextMax = CountOf(stmp); tvi.iImage = tvi.iSelectedImage = nImage; GetItem(&tvi); - if ((strcmp(s, stmp)) || (tvi.iImage != nImage)) + if(tvi.iImage != nImage || strcmp(s, stmp)) { SetItem(hChild, TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE, s, nImage, nImage, 0, 0, 0); } @@ -1024,7 +1037,7 @@ tvi.cchTextMax = CountOf(stmp); tvi.iImage = tvi.iSelectedImage = nImage; GetItem(&tvi); - if ((strcmp(s, stmp)) || (tvi.iImage != nImage)) + if(tvi.iImage != nImage || strcmp(s, stmp)) SetItem(hChild, TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE, s, nImage, nImage, 0, 0, 0); } SetItemData(hChild, nIns); @@ -1383,7 +1396,7 @@ } -BOOL CModTree::DeleteTreeItem(HTREEITEM hItem) +void CModTree::DeleteTreeItem(HTREEITEM hItem) //-------------------------------------------- { const ModItem modItem = GetModItem(hItem); @@ -1392,21 +1405,23 @@ ModTreeDocInfo *pInfo = (m_nDocNdx < DocInfo.size() ? DocInfo[m_nDocNdx] : nullptr); CModDoc *pModDoc = (pInfo) ? pInfo->pModDoc : nullptr; + if(modItem.IsSongItem() && pModDoc == nullptr) + { + return; + } + switch(modItem.type) { case MODITEM_SEQUENCE: - if (pModDoc) - { - wsprintf(s, _T("Remove sequence %u?"), modItemID); - if(Reporting::Confirm(s, false, true) == cnfNo) break; - pModDoc->GetrSoundFile().Order.RemoveSequence((SEQUENCEINDEX)(modItemID)); - pModDoc->UpdateAllViews(NULL, HINT_MODSEQUENCE, NULL); - } + wsprintf(s, _T("Remove sequence %u?"), modItemID); + if(Reporting::Confirm(s, false, true) == cnfNo) break; + pModDoc->GetrSoundFile().Order.RemoveSequence((SEQUENCEINDEX)(modItemID)); + pModDoc->UpdateAllViews(NULL, HINT_MODSEQUENCE, NULL); break; case MODITEM_ORDER: // might be slightly annoying to ask for confirmation here, and it's rather easy to restore the orderlist anyway. - if ((pModDoc) && (pModDoc->RemoveOrder((SEQUENCEINDEX)(modItem.val2), (ORDERINDEX)(modItem.val1)))) + if(pModDoc->RemoveOrder((SEQUENCEINDEX)(modItem.val2), (ORDERINDEX)(modItem.val1))) { pModDoc->UpdateAllViews(NULL, HINT_MODSEQUENCE, NULL); } @@ -1414,8 +1429,7 @@ case MODITEM_PATTERN: wsprintf(s, _T("Remove pattern %u?"), modItemID); - if (pModDoc == nullptr || Reporting::Confirm(s, false, true) == cnfNo) break; - if (pModDoc->RemovePattern((PATTERNINDEX)modItemID)) + if(Reporting::Confirm(s, false, true) == cnfYes && pModDoc->RemovePattern((PATTERNINDEX)modItemID)) { pModDoc->UpdateAllViews(NULL, (UINT(modItemID) << HINT_SHIFT_PAT) | HINT_PATTERNDATA|HINT_PATNAMES); } @@ -1423,7 +1437,7 @@ case MODITEM_SAMPLE: wsprintf(s, _T("Remove sample %u?"), modItemID); - if (pModDoc == nullptr || Reporting::Confirm(s, false, true) == cnfNo) break; + if(Reporting::Confirm(s, false, true) == cnfNo) break; pModDoc->GetSampleUndo().PrepareUndo((SAMPLEINDEX)modItemID, sundo_replace); if (pModDoc->RemoveSample((SAMPLEINDEX)modItemID)) { @@ -1433,8 +1447,7 @@ case MODITEM_INSTRUMENT: wsprintf(s, _T("Remove instrument %u?"), modItemID); - if (pModDoc == nullptr || Reporting::Confirm(s, false, true) == cnfNo) break; - if (pModDoc->RemoveInstrument((INSTRUMENTINDEX)modItemID)) + if(Reporting::Confirm(s, false, true) == cnfYes && pModDoc->RemoveInstrument((INSTRUMENTINDEX)modItemID)) { pModDoc->UpdateAllViews(NULL, (UINT(modItemID) << HINT_SHIFT_INS) | HINT_MODTYPE|HINT_ENVELOPE|HINT_INSTRUMENT); } @@ -1470,7 +1483,6 @@ } break; } - return TRUE; } @@ -1558,6 +1570,7 @@ //------------------------------------ { if (!m_hInsLib) return; + SetRedraw(FALSE); if(!m_szSongName.empty() && IsSampleBrowser() && m_SongFile) { @@ -1729,6 +1742,7 @@ FindClose(hFind); } } + // Sort items TV_SORTCB tvs; tvs.hParent = (!IsSampleBrowser()) ? m_hInsLib : TVI_ROOT; @@ -1737,9 +1751,35 @@ SortChildren(tvs.hParent); SortChildrenCB(&tvs); SetRedraw(TRUE); + + if(m_hWatchDir == nullptr) + { + m_hWatchDir = FindFirstChangeNotificationW(m_szInstrLibPath.AsNative().c_str(), FALSE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME); + } } +// Monitor changes in the instrument library folder. +void CModTree::MonitorInstrumentLibrary() +//--------------------------------------- +{ + DWORD result; + do + { + const HANDLE waitHandles[] = { m_hWatchDirKillThread, m_hWatchDir }; + result = WaitForMultipleObjects(m_hWatchDir != nullptr ? 2 : 1, waitHandles, FALSE, 1000); + if(result == WAIT_OBJECT_0 + 1 && m_hWatchDir == waitHandles[1]) + { + FindNextChangeNotification(m_hWatchDir); + RefreshInstrumentLibrary(); + } else if(result == WAIT_FAILED) + { + Sleep(100); + } + } while(result != WAIT_OBJECT_0); +} + + // Insert sample browser item. void CModTree::ModTreeInsert(const WCHAR *name, int image) //-------------------------------------------------------- @@ -1859,7 +1899,12 @@ if(!ok) { std::wstring s = L"Unable to browse to \"" + dir.AsNative() + L"\""; - Reporting::Error(s); + Reporting::Error(s, L"Instrument Library"); + } else + { + HANDLE watchDir = m_hWatchDir; + m_hWatchDir = nullptr; + FindCloseChangeNotification(watchDir); } } @@ -3023,7 +3068,7 @@ if(pSndFile && modItem.val1) { - FileDialog dlg = OpenFileDialog() + FileDialog dlg = SaveFileDialog() .ExtensionFilter("All files(*.*)|*.*||"); if(!dlg.Show()) return; Modified: trunk/OpenMPT/mptrack/View_tre.h =================================================================== --- trunk/OpenMPT/mptrack/View_tre.h 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/View_tre.h 2013-11-12 21:17:57 UTC (rev 3199) @@ -71,6 +71,7 @@ #include "CTreeCtrl.h" +#include "../common/thread.h" //=============================== class CModTree: public CTreeCtrlW @@ -163,6 +164,9 @@ CModTreeDropTarget m_DropTarget; CModTree *m_pDataTree; // Pointer to instrument browser (lower part of tree view) - if it's a nullptr, this object is the instrument browser itself. HWND m_hDropWnd; + volatile HANDLE m_hWatchDir; + HANDLE m_hWatchDirKillThread; + mpt::thread watchDirThread; ModItem m_itemDrag; DWORD m_dwStatus; UINT m_nDocNdx, m_nDragDocNdx; @@ -191,11 +195,12 @@ void RefreshInstrumentLibrary(); void EmptyInstrumentLibrary(); void FillInstrumentLibrary(); + void MonitorInstrumentLibrary(); ModItem GetModItem(HTREEITEM hItem); BOOL SetMidiInstrument(UINT nIns, const mpt::PathString &fileName); BOOL SetMidiPercussion(UINT nPerc, const mpt::PathString &fileName); BOOL ExecuteItem(HTREEITEM hItem); - BOOL DeleteTreeItem(HTREEITEM hItem); + void DeleteTreeItem(HTREEITEM hItem); BOOL PlayItem(HTREEITEM hItem, ModCommand::NOTE nParam); BOOL OpenTreeItem(HTREEITEM hItem); BOOL OpenMidiInstrument(DWORD dwItem); Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-11-12 21:17:57 UTC (rev 3199) @@ -1257,6 +1257,10 @@ > </File> <File + RelativePath="..\common\thread.h" + > + </File> + <File RelativePath="..\common\typedefs.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-11-12 21:17:57 UTC (rev 3199) @@ -634,6 +634,7 @@ <ClInclude Include="..\common\serialization_utils.h" /> <ClInclude Include="..\common\StringFixer.h" /> <ClInclude Include="..\common\svn_version_default\svn_version.h" /> + <ClInclude Include="..\common\thread.h" /> <ClInclude Include="..\common\typedefs.h" /> <ClInclude Include="..\common\version.h" /> <ClInclude Include="..\common\versionNumber.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-11-12 21:17:57 UTC (rev 3199) @@ -960,6 +960,9 @@ <ClInclude Include="CTreeCtrl.h"> <Filter>Header Files</Filter> </ClInclude> + <ClInclude Include="..\common\thread.h"> + <Filter>Header Files\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> Modified: trunk/OpenMPT/soundlib/plugins/PluginManager.cpp =================================================================== --- trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-12 20:54:13 UTC (rev 3198) +++ trunk/OpenMPT/soundlib/plugins/PluginManager.cpp 2013-11-12 21:17:57 UTC (rev 3199) @@ -118,18 +118,16 @@ { HKEY hkEnum; WCHAR keyname[128]; - LONG cr; - DWORD index; - cr = RegOpenKey(HKEY_LOCAL_MACHINE, "software\\classes\\DirectShow\\MediaObjects\\Categories\\f3602b3f-0592-48df-a4cd-674721e7ebeb", &hkEnum); - index = 0; + LONG cr = RegOpenKey(HKEY_LOCAL_MACHINE, "software\\classes\\DirectShow\\MediaObjects\\Categories\\f3602b3f-0592-48df-a4cd-674721e7ebeb", &hkEnum); + DWORD index = 0; while (cr == ERROR_SUCCESS) { if ((cr = RegEnumKeyW(hkEnum, index, keyname, CountOf(keyname))) == ERROR_SUCCESS) { CLSID clsid; std::wstring formattedKey = std::wstring(L"{") + std::wstring(keyname) + std::wstring(L"}"); - if(Util::StringToCLSID(formattedKey, clsid) == S_OK) + if(Util::StringToCLSID(formattedKey, clsid)) { HKEY hksub; formattedKey = std::wstring(L"software\\classes\\DirectShow\\MediaObjects\\") + std::wstring(keyname); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-12 21:25:45
|
Revision: 3200 http://sourceforge.net/p/modplug/code/3200 Author: manxorist Date: 2013-11-12 21:25:39 +0000 (Tue, 12 Nov 2013) Log Message: ----------- [Ref] Add thread.h to libopenmpt project. Everything in common/ should be in there for consistency. [Fix] Guard windows code with #ifdef WIN32. Modified Paths: -------------- trunk/OpenMPT/common/thread.h trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters Modified: trunk/OpenMPT/common/thread.h =================================================================== --- trunk/OpenMPT/common/thread.h 2013-11-12 21:17:57 UTC (rev 3199) +++ trunk/OpenMPT/common/thread.h 2013-11-12 21:25:39 UTC (rev 3200) @@ -12,6 +12,8 @@ namespace mpt { +#if defined(WIN32) + // Default WinAPI thread class thread { @@ -58,4 +60,10 @@ thread_member(T *instance, Priority priority = normal) : thread(wrapperFunc, instance, priority) { } }; +#else // !WIN32 + +#error "thread.h is unimplemented on non-WIN32" + +#endif // !WIN32 + } // namespace mpt Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-11-12 21:17:57 UTC (rev 3199) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-11-12 21:25:39 UTC (rev 3200) @@ -425,6 +425,7 @@ <ClInclude Include="..\common\StringFixer.h" /> <ClInclude Include="..\common\svn_version_default\svn_version.h" /> <ClInclude Include="..\common\svn_version_subwcrev\svn_version.template.h" /> + <ClInclude Include="..\common\thread.h" /> <ClInclude Include="..\common\typedefs.h" /> <ClInclude Include="..\common\version.h" /> <ClInclude Include="..\common\versionNumber.h" /> Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-11-12 21:17:57 UTC (rev 3199) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-11-12 21:25:39 UTC (rev 3200) @@ -260,6 +260,9 @@ <ClInclude Include="..\common\mptPathString.h"> <Filter>Header Files\common</Filter> </ClInclude> + <ClInclude Include="..\common\thread.h"> + <Filter>Header Files\common</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <ClCompile Include="..\common\AudioCriticalSection.cpp"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-12 21:39:51
|
Revision: 3201 http://sourceforge.net/p/modplug/code/3201 Author: manxorist Date: 2013-11-12 21:39:43 +0000 (Tue, 12 Nov 2013) Log Message: ----------- [Var] Merge include/readme.txt into README. [Var] Correct some outdated information and path names in README. [Var] Add some basic documentation about building libopenmpt and openmpt123. Modified Paths: -------------- trunk/OpenMPT/README Removed Paths: ------------- trunk/OpenMPT/include/readme.txt Modified: trunk/OpenMPT/README =================================================================== --- trunk/OpenMPT/README 2013-11-12 21:25:39 UTC (rev 3200) +++ trunk/OpenMPT/README 2013-11-12 21:39:43 UTC (rev 3201) @@ -1,38 +1,101 @@ -How to compile the code: -- Visual Studio 2008/2010 is required. Express versions won't work as they don't - include MFC. -- The VST 2.4 and ASIO SDKs are needed for compiling with VST and ASIO support. +How to compile OpenMPT: + +- Visual Studio 2008/2010 is required. Express versions won't work as they + don't include MFC. +- The VST 2.4 and ASIO SDKs are needed for compiling with VST and ASIO + support. If you don't want this, uncomment #define NO_VST and #define NO_ASIO in the - file StdAfx.h. Have a look at include/readme.txt to find out which exact files - you need and where you can get them. If you need further help with the VST and - ASIO SDKs, get in touch with the main developers. -- You need the DirectX SDK to enable DirectSound output. If you don't want this, - uncomment #define NO_DSOUND in the file StdAfx.h. + file common/BuildSettings.h. + - ASIO: + If you don't use #define NO_ASIO, you will need to put the ASIO SDK in the + "include/ASIOSDK2" folder. The top level directory of the SDK is already + named "ASIOSDK2", so simply move that directory in the include folder. + Please visit http://www.steinberg.net/en/company/developer.html + to download the SDK. + - VST: + If you don't use #define NO_VST, you will need to put the VST 2.4 SDK in + the "include/vstsdk2.4" folder. + Please visit http://www.steinberg.net/en/company/developer.html + to download the SDK. + If you need further help with the VST and ASIO SDKs, get in touch with the + main developers. +- You need the DirectX SDK to enable DirectSound output. If you don't want + this, uncomment #define NO_DSOUND in the file common/BuildSettings.h. - To compile the project, open mptrack/MPTRACK_08.SLN (if you're using VS2008) or mptrack/MPTRACK_10.SLN (VS2010) and hit the compile button! :) +How to compile libopenmpt and openmpt123: + +- Visual Studio 2010 (express version should work, but this is not tested): + - The libopenmpt solution is in libopenmpt/libopenmpt.sln. + You will need the Winamp 5 SDK and the xmplay SDK if you want to compile + the plugins for these 2 players: + - Winamp 5 SDK: + To build libopenmpt as a winamp input plugin, copy the headers in + Winamp/ from WA5.55_SDK.exe to include/winamp/. + Please visit http://wiki.winamp.com/wiki/Plug-in_Developer to download + the SDK. + Use #define NO_WINAMP in common/BuildSettings.h to disable. + - xmplay SDK: + To build libopenmpt with xmplay input plugin support, copy the contents + of xmpin.zip into include/xmplay/. + Please get in touch with un4seen developments at + http://www.un4seen.com/ to obtain the SDK. + Use #define NO_XMPLAY in common/BuildSettings.h to disable. + - The openmpt123 solution is in openmpt123/openmpt123.sln. +- Makefile + The makefile resides in openmpt123/Makefile. You should cd into openmpt123 + for using it. + The makefile supports different build environments and targets via HOST= and + CONFIG= parameters directly to the make invocation. + Use 'make CONFIG=$newconfig clean' when switching between different configs + because the makefile cleans only intermediates and target that are active + for the current config and no configuration state is kept around across + invocations. + - mingw-w64 (on windows): + The required version should be at least 4.4. Only 4.6 and up are tested. + - cd openmpt123 ; mingw32-make HOST=windows CONFIG=mingw64-win32 + - cd openmpt123 ; mingw32-make HOST=windows CONFIG=mingw64-win64 + depending on whether you want win32 or win64 builds. + - mingw-w64 (on unix): + The required version should be at least 4.4. Only 4.6 and up are tested. + - cd openmpt123 ; make CONFIG=mingw64-win32 + - cd openmpt123 ; make CONFIG=mingw64-win64 + depending on whether you want win32 or win64 builds. + - gcc or clang (on unix, including Mac OS X with MacPorts): + The minimum required compiler versions are: + - gcc 4.4 + - clang 3.0 + The Makefile requires pkg-config for native unix builds. + For sound output in openmpt123, PortAudio or SDL is required. + openmpt123 can optionally use libflac, libwavpack and libsndfile to render + PCM files to disk. + When using gcc, you should simply do: + - cd openmpt123 ; make + When using clang, it is recommended to do: + - cd openmpt123 ; make CONFIG=llvm + The Makefile supports some customizations. You might want to read the top + which should get you some possible make settings, like e.g. make DYNLINK=0 + or similar. Cross compiling or different compiler would best be implemented + via new Makefile.config.* files. + + + Coding conventions (see below for an example): -* Functions / methods are "underlined" (The "//------" comment, see below for an - example what it should look like). +* Functions / methods are "underlined" (The "//------" comment, see below for + an example what it should look like). * Place curly braces at the beginning of the line, not at the end * Generally make use of the custom index types like SAMPLEINDEX or ORDERINDEX when referring to samples, orders, etc. * When changing playback behaviour, make sure that you use the function -* CSoundFile::IsCompatibleMode() so that modules made with previous versions of - MPT still sound correct (if the change is extremely small, this might be + CSoundFile::IsCompatibleMode() so that modules made with previous versions + of MPT still sound correct (if the change is extremely small, this might be unnecessary) * CamelCase function and variable names are preferred. -* When checking the module type, use something like - if(GetType() & MOD_TYPE_XXX) - instead of - if(GetType() == MOD_TYPE_XXX) - as it could be theoretically possible that two mod types are set (currently - this doesn't happen, but in the future this might actually be used as a code - feature :) Code example: @@ -71,4 +134,4 @@ rule, the more recent the code is, the cleaner it is), though the UI code is tightly integrated with the implementation (this could make it somewhat more difficult to implement such things as a skin-based UI - but hey, if it was easy, -I probably would have done it already :). \ No newline at end of file +I probably would have done it already :). Deleted: trunk/OpenMPT/include/readme.txt =================================================================== --- trunk/OpenMPT/include/readme.txt 2013-11-12 21:25:39 UTC (rev 3200) +++ trunk/OpenMPT/include/readme.txt 2013-11-12 21:39:43 UTC (rev 3201) @@ -1,31 +0,0 @@ -What files do I need to compile OpenMPT? - -VST 2.4 SDK -=========== -If you don't use #define NO_VST, you will need to put the VST 2.4 SDK in the -"vstsdk2.4" folder. The top level directory of the SDK is already named -"vstsdk2.4", so simply move that directory in the include folder. - -Please visit http://www.steinberg.net/en/company/developer.html -to download the SDK. - -ASIO SDK -======== -If you don't use #define NO_ASIO, you will need to put the ASIO SDK in the -"ASIOSDK2" folder. The top level directory of the SDK is already named -"ASIOSDK2", so simply move that directory in the include folder. - -Please visit http://www.steinberg.net/en/company/developer.html -to download the SDK. - -Winamp5 SDK -=========== -To build libopenmpt as a winamp input plugin, copy the headers in Winamp/ -from WA5.55_SDK.exe to include/winamp/. -Use #define NO_WINAMP in common/BuildSettings.h to disable. - -xmplay input SDK -================ -To build libopenmpt with xmplay input plugin support, copy the contents of -xmpin.zip into include/xmplay/. -Use #define NO_XMPLAY in common/BuildSettings.h to disable. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-12 23:02:13
|
Revision: 3203 http://sourceforge.net/p/modplug/code/3203 Author: manxorist Date: 2013-11-12 23:02:01 +0000 (Tue, 12 Nov 2013) Log Message: ----------- [Fix] For ConvertStrTo, force the istringstream to classic() locale to make it independent of any global c or c++ locale set by the host program (in case of libopenmpt). [Fix] Replace all scanf-like calls as well as ato[i|f] and strto[l|f] with either a classic()-locale based istringstream solution or just simply locale-independent ConvertStrTo<T>() to make libopenmpt behaviour independent of the global c/c++ locale. [Fix] Replace almost all printf-like calls in soundlib/ with our own type-safe and locale-independent formatting. Debug logging via the global Log() function is still based on sprintf though. [Ref] Formatting and number parsing are both based on c++ iostreams. However, the interface header is independent of <sstream> and <locale> to improve compile times and cleanly separate the implementation detail (i.e. do not catch up custom type formatting via ostream::operator<<). This also avoids binary code bloat which could be caused by ostream::operator<< inlining. [Ref] Add some small documentation snippets to mptString.h. [Var] Documentation for the custom formatting library (also included in common/mptString.h): 1. ToString() and ToWString() mimic the semantics of c++11 std::to_string() and std::to_wstring(). There is an important difference though. The c++11 versions are specified in terms of sprintf formatting which in turn depend on the current C locale. This renders these functions unusable in a library context because the current C locale is set by the library-using application and could be anything. There is no way a library can get reliable semantics out of these functions. It is thus better to just avoid them. ToString() and ToWString() are based on iostream internally, but the the locale of the stream is forced to std::locale::classic(), which results in "C" ASCII locale behavior. 2. The full suite of printf-like or iostream like number formatting is generally not required. Instead, a sane subset functionality is provided here. For convenience, mpt::Format().ParsePrintf(const char *).ToString(float) allows formatting a single floating point value with a standard printf-like format string. This itself relies on iostream with classic() locale internally and is thus current locale agnostic. When formatting integers, it is recommended to use mpt::fmt::dec or mpt::fmt::hex. Appending a template argument '<n>' sets the width, the same way as '%nd' would do. Appending a '0' to the function name causes zero-filling as print-like '%0nd' would do. Spelling 'HEX' in upper-case generates upper-case hex digits. If these are not known at compile-time, a more verbose FormatVal(int, format) can be used. 3. mpt::String::Print(format, ...) provides simplified and type-safe message and localization string formatting. The only specifier allowed is '%' followed by a single digit n. It references to n-th parameter after the format string (1-based). This mimics the behaviour of QString::arg() in QT4/5 or MFC AfxFormatString2(). C printf-like functions offer similar functionality with a '%n$TYPE' syntax. In .NET, the syntax is '{n}'. This is useful to support localization strings that can change the parameter ordering. 4. Every function is available for std::string and std::wstring. std::string makes no assumption about the encoding, which basically means, it should work for any 7-bit or 8-bit encoding, including for example ASCII, UTF8 or the current locale encoding. std::string std::wstring mpt::ToString mpt::ToWString mpt::FormatVal mpt::FormatValW mpt::fmt mpt::wfmt mpt::String::Print mpt::String::PrintW 5. All functionality here delegates real work outside of the header file so that <sstream> and <locale> do not need to be included when using this functionality. Advantages: - Avoids binary code bloat when too much of iostream operator << gets inlined at every usage site. - Faster compile times because <sstream> and <locale> (2 very complex headers) are not included everywhere. Disadvantages: - Slightly more c++ code is required for delegating work. - As the header does not use iostreams, custom types need to overload mpt::ToString and mpt::ToWstring instead of iostream operator << to allow for custom type formatting. - std::string and std::wstring are returned from somewhat deep cascades of helper functions. Where possible, code is written in such a way that return-value-optimization (RVO) or named-return-value-optimization (NRVO) should be able to eliminate almost all these copies. This should not be a problem for any decent modern compiler (and even less so for a c++11 compiler where move-semantics will kick in if RVO/NRVO fails). Modified Paths: -------------- trunk/OpenMPT/common/Profiler.cpp trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/common/mptString.cpp trunk/OpenMPT/common/mptString.h trunk/OpenMPT/common/stdafx.h trunk/OpenMPT/common/typedefs.cpp trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/common/version.cpp trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/Settings.cpp trunk/OpenMPT/soundlib/Load_ams.cpp trunk/OpenMPT/soundlib/Load_dbm.cpp trunk/OpenMPT/soundlib/Load_digi.cpp trunk/OpenMPT/soundlib/Load_gdm.cpp trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Load_med.cpp trunk/OpenMPT/soundlib/Load_mtm.cpp trunk/OpenMPT/soundlib/Load_psm.cpp trunk/OpenMPT/soundlib/Load_ptm.cpp trunk/OpenMPT/soundlib/Load_s3m.cpp trunk/OpenMPT/soundlib/Load_stm.cpp trunk/OpenMPT/soundlib/Load_umx.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/ModSequence.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/common/Profiler.cpp =================================================================== --- trunk/OpenMPT/common/Profiler.cpp 2013-11-12 21:56:31 UTC (rev 3202) +++ trunk/OpenMPT/common/Profiler.cpp 2013-11-12 23:02:01 UTC (rev 3203) @@ -110,7 +110,7 @@ case Profiler::Audio: cat = "Audio"; break; case Profiler::Notify: cat = "Notify"; break; } - ret += cat + " " + std::string(stats.profile.Name) + ": " + mpt::String::Format("%6.3f", (stats.usage * 100.0)) + "%\r\n"; + ret += cat + " " + std::string(stats.profile.Name) + ": " + mpt::Format("%6.3f").ToString(stats.usage * 100.0) + "%\r\n"; } } ret += "\r\n"; Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2013-11-12 21:56:31 UTC (rev 3202) +++ trunk/OpenMPT/common/misc_util.cpp 2013-11-12 23:02:01 UTC (rev 3203) @@ -11,7 +11,75 @@ #include "stdafx.h" #include "misc_util.h" +#include <locale> +#include <sstream> +#include <string> + +template<typename T> +inline T ConvertStrToHelper(const std::string &str) +{ + std::istringstream i(str); + i.imbue(std::locale::classic()); + T x; + if(!(i >> x)) + { + return T(); + } + return x; +} +template<> inline bool ConvertStrToHelper(const std::string &str) { return ConvertStrToHelper<int>(str)?true:false; } +template<> inline signed char ConvertStrToHelper(const std::string &str) { return static_cast<signed char>(ConvertStrToHelper<signed int>(str)); } +template<> inline unsigned char ConvertStrToHelper(const std::string &str) { return static_cast<unsigned char>(ConvertStrToHelper<unsigned int>(str)); } + +template<typename T> +inline T ConvertStrToHelper(const std::wstring &str) +{ + std::wistringstream i(str); + i.imbue(std::locale::classic()); + T x; + if(!(i >> x)) + { + return T(); + } + return x; +} +template<> inline bool ConvertStrToHelper(const std::wstring &str) { return ConvertStrToHelper<int>(str)?true:false; } +template<> inline signed char ConvertStrToHelper(const std::wstring &str) { return static_cast<signed char>(ConvertStrToHelper<signed int>(str)); } +template<> inline unsigned char ConvertStrToHelper(const std::wstring &str) { return static_cast<unsigned char>(ConvertStrToHelper<unsigned int>(str)); } + +bool ConvertStrToBool(const std::string &str) { return ConvertStrToHelper<bool>(str); } +signed char ConvertStrToSignedChar(const std::string &str) { return ConvertStrToHelper<signed char>(str); } +unsigned char ConvertStrToUnsignedChar(const std::string &str) { return ConvertStrToHelper<unsigned char>(str); } +signed short ConvertStrToSignedShort(const std::string &str) { return ConvertStrToHelper<signed short>(str); } +unsigned short ConvertStrToUnsignedShort(const std::string &str) { return ConvertStrToHelper<unsigned short>(str); } +signed int ConvertStrToSignedInt(const std::string &str) { return ConvertStrToHelper<signed int>(str); } +unsigned int ConvertStrToUnsignedInt(const std::string &str) { return ConvertStrToHelper<unsigned int>(str); } +signed long ConvertStrToSignedLong(const std::string &str) { return ConvertStrToHelper<signed long>(str); } +unsigned long ConvertStrToUnsignedLong(const std::string &str) { return ConvertStrToHelper<unsigned long>(str); } +signed long long ConvertStrToSignedLongLong(const std::string &str) { return ConvertStrToHelper<signed long long>(str); } +unsigned long long ConvertStrToUnsignedLongLong(const std::string &str) { return ConvertStrToHelper<unsigned long long>(str); } +float ConvertStrToFloat(const std::string &str) { return ConvertStrToHelper<float>(str); } +double ConvertStrToDouble(const std::string &str) { return ConvertStrToHelper<double>(str); } +long double ConvertStrToLongDouble(const std::string &str) { return ConvertStrToHelper<long double>(str); } + +bool ConvertStrToBool(const std::wstring &str) { return ConvertStrToHelper<bool>(str); } +signed char ConvertStrToSignedChar(const std::wstring &str) { return ConvertStrToHelper<signed char>(str); } +unsigned char ConvertStrToUnsignedChar(const std::wstring &str) { return ConvertStrToHelper<unsigned char>(str); } +signed short ConvertStrToSignedShort(const std::wstring &str) { return ConvertStrToHelper<signed short>(str); } +unsigned short ConvertStrToUnsignedShort(const std::wstring &str) { return ConvertStrToHelper<unsigned short>(str); } +signed int ConvertStrToSignedInt(const std::wstring &str) { return ConvertStrToHelper<signed int>(str); } +unsigned int ConvertStrToUnsignedInt(const std::wstring &str) { return ConvertStrToHelper<unsigned int>(str); } +signed long ConvertStrToSignedLong(const std::wstring &str) { return ConvertStrToHelper<signed long>(str); } +unsigned long ConvertStrToUnsignedLong(const std::wstring &str) { return ConvertStrToHelper<unsigned long>(str); } +signed long long ConvertStrToSignedLongLong(const std::wstring &str) { return ConvertStrToHelper<signed long long>(str); } +unsigned long long ConvertStrToUnsignedLongLong(const std::wstring &str) { return ConvertStrToHelper<unsigned long long>(str); } +float ConvertStrToFloat(const std::wstring &str) { return ConvertStrToHelper<float>(str); } +double ConvertStrToDouble(const std::wstring &str) { return ConvertStrToHelper<double>(str); } +long double ConvertStrToLongDouble(const std::wstring &str) { return ConvertStrToHelper<long double>(str); } + + + #if defined(ENABLE_ASM) Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-11-12 21:56:31 UTC (rev 3202) +++ trunk/OpenMPT/common/misc_util.h 2013-11-12 23:02:01 UTC (rev 3203) @@ -11,7 +11,6 @@ #pragma once #include <limits> -#include <sstream> #include <string> #include <cmath> @@ -25,79 +24,89 @@ #include <type_traits> #endif -//Convert object(typically number) to string -template<class T> -inline std::string Stringify(const T& x) -//-------------------------------------- -{ - std::ostringstream o; - if(!(o << x)) return "FAILURE"; - else return o.str(); -} +bool ConvertStrToBool(const std::string &str); +signed char ConvertStrToSignedChar(const std::string &str); +unsigned char ConvertStrToUnsignedChar(const std::string &str); +signed short ConvertStrToSignedShort(const std::string &str); +unsigned short ConvertStrToUnsignedShort(const std::string &str); +signed int ConvertStrToSignedInt(const std::string &str); +unsigned int ConvertStrToUnsignedInt(const std::string &str); +signed long ConvertStrToSignedLong(const std::string &str); +unsigned long ConvertStrToUnsignedLong(const std::string &str); +signed long long ConvertStrToSignedLongLong(const std::string &str); +unsigned long long ConvertStrToUnsignedLongLong(const std::string &str); +float ConvertStrToFloat(const std::string &str); +double ConvertStrToDouble(const std::string &str); +long double ConvertStrToLongDouble(const std::string &str); -template<> inline std::string Stringify(const signed char& x) { return Stringify((signed int)x); } -template<> inline std::string Stringify(const unsigned char& x) { return Stringify((unsigned int)x); } +template<typename T> inline T ConvertStrTo(const std::string &str); // not defined, generates compiler error for non-specialized types +template<> inline bool ConvertStrTo(const std::string &str) { return ConvertStrToBool(str); } +template<> inline signed char ConvertStrTo(const std::string &str) { return ConvertStrToSignedChar(str); } +template<> inline unsigned char ConvertStrTo(const std::string &str) { return ConvertStrToUnsignedChar(str); } +template<> inline signed short ConvertStrTo(const std::string &str) { return ConvertStrToSignedShort(str); } +template<> inline unsigned short ConvertStrTo(const std::string &str) { return ConvertStrToUnsignedShort(str); } +template<> inline signed int ConvertStrTo(const std::string &str) { return ConvertStrToSignedInt(str); } +template<> inline unsigned int ConvertStrTo(const std::string &str) { return ConvertStrToUnsignedInt(str); } +template<> inline signed long ConvertStrTo(const std::string &str) { return ConvertStrToSignedLong(str); } +template<> inline unsigned long ConvertStrTo(const std::string &str) { return ConvertStrToUnsignedLong(str); } +template<> inline signed long long ConvertStrTo(const std::string &str) { return ConvertStrToSignedLongLong(str); } +template<> inline unsigned long long ConvertStrTo(const std::string &str) { return ConvertStrToUnsignedLongLong(str); } +template<> inline float ConvertStrTo(const std::string &str) { return ConvertStrToFloat(str); } +template<> inline double ConvertStrTo(const std::string &str) { return ConvertStrToDouble(str); } +template<> inline long double ConvertStrTo(const std::string &str) { return ConvertStrToLongDouble(str); } -template<class T> -inline std::wstring StringifyW(const T& x) -//---------------------------------------- -{ - std::wostringstream o; - if(!(o << x)) return L"FAILURE"; - else return o.str(); -} +bool ConvertStrToBool(const std::wstring &str); +signed char ConvertStrToSignedChar(const std::wstring &str); +unsigned char ConvertStrToUnsignedChar(const std::wstring &str); +signed short ConvertStrToSignedShort(const std::wstring &str); +unsigned short ConvertStrToUnsignedShort(const std::wstring &str); +signed int ConvertStrToSignedInt(const std::wstring &str); +unsigned int ConvertStrToUnsignedInt(const std::wstring &str); +signed long ConvertStrToSignedLong(const std::wstring &str); +unsigned long ConvertStrToUnsignedLong(const std::wstring &str); +signed long long ConvertStrToSignedLongLong(const std::wstring &str); +unsigned long long ConvertStrToUnsignedLongLong(const std::wstring &str); +float ConvertStrToFloat(const std::wstring &str); +double ConvertStrToDouble(const std::wstring &str); +long double ConvertStrToLongDouble(const std::wstring &str); -template<> inline std::wstring StringifyW(const signed char& x) { return StringifyW((signed int)x); } -template<> inline std::wstring StringifyW(const unsigned char& x) { return StringifyW((unsigned int)x); } +template<typename T> inline T ConvertStrTo(const std::wstring &str); // not defined, generates compiler error for non-specialized types +template<> inline bool ConvertStrTo(const std::wstring &str) { return ConvertStrToBool(str); } +template<> inline signed char ConvertStrTo(const std::wstring &str) { return ConvertStrToSignedChar(str); } +template<> inline unsigned char ConvertStrTo(const std::wstring &str) { return ConvertStrToUnsignedChar(str); } +template<> inline signed short ConvertStrTo(const std::wstring &str) { return ConvertStrToSignedShort(str); } +template<> inline unsigned short ConvertStrTo(const std::wstring &str) { return ConvertStrToUnsignedShort(str); } +template<> inline signed int ConvertStrTo(const std::wstring &str) { return ConvertStrToSignedInt(str); } +template<> inline unsigned int ConvertStrTo(const std::wstring &str) { return ConvertStrToUnsignedInt(str); } +template<> inline signed long ConvertStrTo(const std::wstring &str) { return ConvertStrToSignedLong(str); } +template<> inline unsigned long ConvertStrTo(const std::wstring &str) { return ConvertStrToUnsignedLong(str); } +template<> inline signed long long ConvertStrTo(const std::wstring &str) { return ConvertStrToSignedLongLong(str); } +template<> inline unsigned long long ConvertStrTo(const std::wstring &str) { return ConvertStrToUnsignedLongLong(str); } +template<> inline float ConvertStrTo(const std::wstring &str) { return ConvertStrToFloat(str); } +template<> inline double ConvertStrTo(const std::wstring &str) { return ConvertStrToDouble(str); } +template<> inline long double ConvertStrTo(const std::wstring &str) { return ConvertStrToLongDouble(str); } -//Convert string to number. -template<class T> +template<typename T> inline T ConvertStrTo(const char *str) -//------------------------------------ { - #ifdef HAS_TYPE_TRAITS - static_assert(std::is_const<T>::value == false && std::is_volatile<T>::value == false, "Const and volatile types are not handled correctly."); - #endif - if(std::numeric_limits<T>::is_integer) - return static_cast<T>(atoi(str)); - else - return static_cast<T>(atof(str)); + if(!str) + { + return T(); + } + return ConvertStrTo<T>(std::string(str)); } -template<class T> -inline T ConvertStrTo(const std::string &str) -//------------------------------------------- +template<typename T> +inline T ConvertStrTo(const wchar_t *str) { - return ConvertStrTo<T>(str.c_str()); + if(!str) + { + return T(); + } + return ConvertStrTo<T>(std::wstring(str)); } -#if MPT_COMPILER_MSVC -#define cxx11_strtoll _strtoi64 -#define cxx11_strtoull _strtoui64 -#else -#define cxx11_strtoll std::strtoll -#define cxx11_strtoull std::strtoull -#endif -template<> inline bool ConvertStrTo(const char *str) {return std::strtol(str, nullptr, 10) ? true : false;} -template<> inline signed char ConvertStrTo(const char *str) {return (signed char)std::strtol(str, nullptr, 10);} -template<> inline signed short ConvertStrTo(const char *str) {return (signed short)std::strtol(str, nullptr, 10);} -template<> inline signed int ConvertStrTo(const char *str) {return (signed int)std::strtol(str, nullptr, 10);} -template<> inline signed long ConvertStrTo(const char *str) {return std::strtol(str, nullptr, 10);} -template<> inline signed long long ConvertStrTo(const char *str) {return cxx11_strtoll(str, nullptr, 10);} -template<> inline unsigned char ConvertStrTo(const char *str) {return (unsigned char)std::strtoul(str, nullptr, 10);} -template<> inline unsigned short ConvertStrTo(const char *str) {return (unsigned short)std::strtoul(str, nullptr, 10);} -template<> inline unsigned int ConvertStrTo(const char *str) {return (unsigned int)std::strtoul(str, nullptr, 10);} -template<> inline unsigned long ConvertStrTo(const char *str) {return std::strtoul(str, nullptr, 10);} -template<> inline unsigned long long ConvertStrTo(const char *str) {return cxx11_strtoull(str, nullptr, 10);} -template<class T> -inline T ConvertStrTo(const std::wstring &str) -//-------------------------------------------- -{ - return ConvertStrTo<T>(mpt::String::Encode(str, mpt::CharsetLocale)); -} - - // Memset given object to zero. template <class T> inline void MemsetZero(T &a) Modified: trunk/OpenMPT/common/mptString.cpp =================================================================== --- trunk/OpenMPT/common/mptString.cpp 2013-11-12 21:56:31 UTC (rev 3202) +++ trunk/OpenMPT/common/mptString.cpp 2013-11-12 23:02:01 UTC (rev 3203) @@ -1,8 +1,8 @@ /* * mptString.cpp * ------------- - * Purpose: A wrapper around std::string implemeting the CString. - * Notes : Should be removed somewhen in the future when all uses of CString have been converted to std::string. + * Purpose: MFC compatibility classes, small string-related utilities, number and message formatting. + * Notes : Currently none. * Authors: OpenMPT Devs * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. */ @@ -10,8 +10,13 @@ #include "stdafx.h" #include "mptString.h" +#include <iomanip> +#include <locale> +#include <sstream> +#include <string> #include <stdexcept> #include <vector> + #include <cstdarg> #if !defined(WIN32) @@ -22,6 +27,8 @@ namespace mpt { namespace String { +#ifdef MODPLUG_TRACKER + std::string Format(const char *format, ...) { #if MPT_COMPILER_MSVC @@ -48,7 +55,9 @@ #endif } +#endif + #if defined(WIN32) static UINT CharsetToCodepage(Charset charset) { @@ -294,3 +303,332 @@ } } // namespace mpt::String + + +namespace mpt +{ + + +template<typename Tstream, typename T> inline void SaneInsert(Tstream & s, const T & x) { s << x; } +// do the right thing for signed/unsigned char and bool +template<typename Tstream> void SaneInsert(Tstream & s, const bool & x) { s << static_cast<int>(x); } +template<typename Tstream> void SaneInsert(Tstream & s, const signed char & x) { s << static_cast<signed int>(x); } +template<typename Tstream> void SaneInsert(Tstream & s, const unsigned char & x) { s << static_cast<unsigned int>(x); } + +template<typename T> +inline std::string ToStringHelper(const T & x) +{ + std::ostringstream o; + o.imbue(std::locale::classic()); + SaneInsert(o, x); + return o.str(); +} + +template<typename T> +inline std::wstring ToWStringHelper(const T & x) +{ + std::wostringstream o; + o.imbue(std::locale::classic()); + SaneInsert(o, x); + return o.str(); +} + +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 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); } +std::string ToString(const signed short & x) { return ToStringHelper(x); } +std::string ToString(const unsigned short & x) { return ToStringHelper(x); } +std::string ToString(const signed int & x) { return ToStringHelper(x); } +std::string ToString(const unsigned int & x) { return ToStringHelper(x); } +std::string ToString(const signed long & x) { return ToStringHelper(x); } +std::string ToString(const unsigned long & x) { return ToStringHelper(x); } +std::string ToString(const signed long long & x) { return ToStringHelper(x); } +std::string ToString(const unsigned long long & x) { return ToStringHelper(x); } +std::string ToString(const float & x) { return ToStringHelper(x); } +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 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); } +std::wstring ToWString(const unsigned char & x) { return ToWStringHelper(x); } +std::wstring ToWString(const signed short & x) { return ToWStringHelper(x); } +std::wstring ToWString(const unsigned short & x) { return ToWStringHelper(x); } +std::wstring ToWString(const signed int & x) { return ToWStringHelper(x); } +std::wstring ToWString(const unsigned int & x) { return ToWStringHelper(x); } +std::wstring ToWString(const signed long & x) { return ToWStringHelper(x); } +std::wstring ToWString(const unsigned long & x) { return ToWStringHelper(x); } +std::wstring ToWString(const signed long long & x) { return ToWStringHelper(x); } +std::wstring ToWString(const unsigned long long & x) { return ToWStringHelper(x); } +std::wstring ToWString(const float & x) { return ToWStringHelper(x); } +std::wstring ToWString(const double & x) { return ToWStringHelper(x); } +std::wstring ToWString(const long double & x) { return ToWStringHelper(x); } + + +#if defined(MPT_FMT) + + +template<typename Tostream> +inline void ApplyFormat(Tostream & o, const Format & format) +{ + FormatFlags f = format.GetFlags(); + std::size_t width = format.GetWidth(); + int precision = format.GetPrecision(); + if(precision != -1 && width != 0 && !(f & fmt::NotaFix) && !(f & fmt::NotaSci)) + { + // fixup: + // precision behaves differently from .# + // avoid default format when precision and width are set + f &= ~fmt::NotaNrm; + f |= fmt::NotaFix; + } + if(f & fmt::BaseDec) { o << std::dec; } + else if(f & fmt::BaseHex) { o << std::hex; } + if(f & fmt::NotaNrm ) { /*nothing*/ } + else if(f & fmt::NotaFix ) { o << std::setiosflags(std::ios::fixed); } + else if(f & fmt::NotaSci ) { o << std::setiosflags(std::ios::scientific); } + if(f & fmt::CaseLow) { o << std::nouppercase; } + else if(f & fmt::CaseUpp) { o << std::uppercase; } + if(f & fmt::FillOff) { /* nothing */ } + else if(f & fmt::FillNul) { o << std::setw(width) << std::setfill(typename Tostream::char_type('0')); } + else if(f & fmt::FillSpc) { o << std::setw(width) << std::setfill(typename Tostream::char_type(' ')); } + if(precision != -1) { o << std::setprecision(precision); } +} + + +template<typename T> +inline std::string FormatValHelper(const T & x, const Format & f) +{ + std::ostringstream o; + o.imbue(std::locale::classic()); + ApplyFormat(o, f); + SaneInsert(o, x); + return o.str(); +} + +template<typename T> +inline std::wstring FormatValWHelper(const T & x, const Format & f) +{ + std::wostringstream o; + o.imbue(std::locale::classic()); + ApplyFormat(o, f); + SaneInsert(o, x); + return o.str(); +} + +// Parses a useful subset of standard sprintf syntax for specifying floating point formatting. +template<typename Tchar> +inline Format ParseFormatStringFloat(const Tchar * str) +{ + ASSERT(str); + FormatFlags f = FormatFlags(); + std::size_t width = 0; + int precision = -1; + if(!str) + { + return Format(); + } + const Tchar * p = str; + while(*p && *p != Tchar('%')) + { + ++p; + } + ++p; + while(*p && (*p == Tchar(' ') || *p == Tchar('0'))) + { + if(*p == Tchar(' ')) f |= mpt::fmt::FillSpc; + if(*p == Tchar('0')) f |= mpt::fmt::FillNul; + ++p; + } + if(!(f & mpt::fmt::FillSpc) && !(f & mpt::fmt::FillNul)) + { + f |= mpt::fmt::FillOff; + } + while(*p && (Tchar('0') <= *p && *p <= Tchar('9'))) + { + if(f & mpt::fmt::FillOff) + { + f &= ~mpt::fmt::FillOff; + f |= mpt::fmt::FillSpc; + } + width *= 10; + width += *p - Tchar('0'); + ++p; + } + if(*p && *p == Tchar('.')) + { + ++p; + precision = 0; + while(*p && (Tchar('0') <= *p && *p <= Tchar('9'))) + { + precision *= 10; + precision += *p - Tchar('0'); + ++p; + } + } + if(*p && (*p == Tchar('g') || *p == Tchar('G') || *p == Tchar('f') || *p == Tchar('F') || *p == Tchar('e') || *p == Tchar('E'))) + { + if(*p == Tchar('g')) f |= mpt::fmt::NotaNrm | mpt::fmt::CaseLow; + if(*p == Tchar('G')) f |= mpt::fmt::NotaNrm | mpt::fmt::CaseUpp; + if(*p == Tchar('f')) f |= mpt::fmt::NotaFix | mpt::fmt::CaseLow; + if(*p == Tchar('F')) f |= mpt::fmt::NotaFix | mpt::fmt::CaseUpp; + if(*p == Tchar('e')) f |= mpt::fmt::NotaSci | mpt::fmt::CaseLow; + if(*p == Tchar('E')) f |= mpt::fmt::NotaSci | mpt::fmt::CaseUpp; + ++p; + } + return Format().SetFlags(f).SetWidth(width).SetPrecision(precision); +} + +Format & Format::ParsePrintf(const char * format) +{ + *this = ParseFormatStringFloat(format); + return *this; +} +Format & Format::ParsePrintf(const wchar_t * format) +{ + *this = ParseFormatStringFloat(format); + return *this; +} +Format & Format::ParsePrintf(const std::string & format) +{ + *this = ParseFormatStringFloat(format.c_str()); + return *this; +} +Format & Format::ParsePrintf(const std::wstring & format) +{ + *this = ParseFormatStringFloat(format.c_str()); + return *this; +} + + +std::string FormatVal(const char & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const wchar_t & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const bool & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const signed char & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const unsigned char & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const signed short & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const unsigned short & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const signed int & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const unsigned int & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const signed long & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const unsigned long & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const signed long long & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const unsigned long long & x, const Format & f) { return FormatValHelper(x, f); } + +std::string FormatVal(const float & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const double & x, const Format & f) { return FormatValHelper(x, f); } +std::string FormatVal(const long double & x, const Format & f) { return FormatValHelper(x, f); } + +std::wstring FormatValW(const char & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const wchar_t & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const bool & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const signed char & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const unsigned char & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const signed short & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const unsigned short & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const signed int & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const unsigned int & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const signed long & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const unsigned long & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const signed long long & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const unsigned long long & x, const Format & f) { return FormatValWHelper(x, f); } + +std::wstring FormatValW(const float & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const double & x, const Format & f) { return FormatValWHelper(x, f); } +std::wstring FormatValW(const long double & x, const Format & f) { return FormatValWHelper(x, f); } + + +#endif // MPT_FMT + + +namespace String +{ + + +namespace detail +{ + +template<typename Tstring> +Tstring PrintImplTemplate(const Tstring & format + , const Tstring & x1 + , const Tstring & x2 + , const Tstring & x3 + , const Tstring & x4 + , const Tstring & x5 + , const Tstring & x6 + , const Tstring & x7 + , const Tstring & x8 + ) +{ + Tstring result; + const std::size_t len = format.length(); + for(std::size_t pos = 0; pos != len; ++pos) + { + typename Tstring::value_type c = format[pos]; + if(pos + 1 != len && c == '%') + { + pos++; + c = format[pos]; + if('1' <= c && c <= '9') + { + const std::size_t n = c - '0'; + switch(n) + { + case 1: result.append(x1); break; + case 2: result.append(x2); break; + case 3: result.append(x3); break; + case 4: result.append(x4); break; + case 5: result.append(x5); break; + case 6: result.append(x6); break; + case 7: result.append(x7); break; + case 8: result.append(x8); break; + } + continue; + } else if(c != '%') + { + result.append(1, '%'); + } + } + result.append(1, c); + } + return result; +} + +std::string PrintImpl(const std::string & format + , const std::string & x1 + , const std::string & x2 + , const std::string & x3 + , const std::string & x4 + , const std::string & x5 + , const std::string & x6 + , const std::string & x7 + , const std::string & x8 + ) +{ + return PrintImplTemplate<std::string>(format, x1,x2,x3,x4,x5,x6,x7,x8); +} + +std::wstring PrintImplW(const std::wstring & format + , const std::wstring & x1 + , const std::wstring & x2 + , const std::wstring & x3 + , const std::wstring & x4 + , const std::wstring & x5 + , const std::wstring & x6 + , const std::wstring & x7 + , const std::wstring & x8 + ) +{ + return PrintImplTemplate<std::wstring>(format, x1,x2,x3,x4,x5,x6,x7,x8); +} + +} // namespace detail + + +} // namespace String + + +} // namespace mpt Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-11-12 21:56:31 UTC (rev 3202) +++ trunk/OpenMPT/common/mptString.h 2013-11-12 23:02:01 UTC (rev 3203) @@ -1,8 +1,8 @@ /* * mptString.h * ---------- - * Purpose: A wrapper around std::string implemeting the CString interface. - * Notes : Should be removed somewhen in the future when all uses of CString have been converted to std::string. + * Purpose: MFC compatibility classes, small string-related utilities, number and message formatting. + * Notes : Currently none. * Authors: OpenMPT Devs * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. */ @@ -10,7 +10,12 @@ #pragma once +#include <limits> #include <string> +#if defined(HAS_TYPE_TRAITS) +#include <type_traits> +#endif + #include <cstdio> #include <cstring> #include <stdio.h> @@ -18,13 +23,7 @@ #include <strings.h> // for strcasecmp #endif -#if MPT_COMPILER_GCC || MPT_COMPILER_CLANG -#define MPT_PRINTF_FUNC(formatstringindex,varargsindex) __attribute__((format(printf, formatstringindex, varargsindex))) -#else -#define MPT_PRINTF_FUNC(formatstringindex,varargsindex) -#endif - namespace mpt { @@ -51,7 +50,15 @@ { +#ifdef MODPLUG_TRACKER +// There are 4 reasons why this is not available for library code: +// 1. printf-like functionality is not type-safe. +// 2. There are portability problems with char/wchar_t and the semantics of %s/%ls/%S . +// 3. There are portability problems with specifying format for 64bit integers. +// 4. Formatting of floating point values depends on the currently set C locale. +// A library is not allowed to mock with that and thus cannot influence the behavior in this case. std::string MPT_PRINTF_FUNC(1,2) Format(const char * format, ...); +#endif // Remove whitespace at start of string @@ -147,11 +154,11 @@ enum Charset { - CharsetLocale, + CharsetLocale, // CP_ACP on windows, current C locale otherwise CharsetUTF8, - CharsetUS_ASCII, + CharsetUS_ASCII, // strictly 7-bit ASCII CharsetISO8859_1, CharsetISO8859_15, @@ -164,14 +171,30 @@ 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); + +// 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); +// 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); #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 @@ -179,3 +202,841 @@ } // namespace String } // namespace mpt + + + + + +// The following section demands a rationale. +// 1. ToString() and ToWString() mimic the semantics of c++11 std::to_string() and std::to_wstring(). +// There is an important difference though. The c++11 versions are specified in terms of sprintf formatting which in turn +// depend on the current C locale. This renders these functions unusable in a library context because the current +// C locale is set by the library-using application and could be anything. There is no way a library can get reliable semantics +// out of these functions. It is thus better to just avoid them. +// ToString() and ToWString() are based on iostream internally, but the the locale of the stream is forced to std::locale::classic(), +// which results in "C" ASCII locale behavior. +// 2. The full suite of printf-like or iostream like number formatting is generally not required. Instead, a sane subset functionality +// is provided here. +// For convenience, mpt::Format().ParsePrintf(const char *).ToString(float) allows formatting a single floating point value with a +// standard printf-like format string. This itself relies on iostream with classic() locale internally and is thus current locale +// agnostic. +// When formatting integers, it is recommended to use mpt::fmt::dec or mpt::fmt::hex. Appending a template argument '<n>' sets the width, +// the same way as '%nd' would do. Appending a '0' to the function name causes zero-filling as print-like '%0nd' would do. Spelling 'HEX' +// in upper-case generates upper-case hex digits. If these are not known at compile-time, a more verbose FormatVal(int, format) can be +// used. +// 3. mpt::String::Print(format, ...) provides simplified and type-safe message and localization string formatting. +// The only specifier allowed is '%' followed by a single digit n. It references to n-th parameter after the format string (1-based). +// This mimics the behaviour of QString::arg() in QT4/5 or MFC AfxFormatString2(). C printf-like functions offer similar functionality +// with a '%n$TYPE' syntax. In .NET, the syntax is '{n}'. This is useful to support localization strings that can change the parameter +// ordering. +// 4. Every function is available for std::string and std::wstring. std::string makes no assumption about the encoding, which basically means, +// it should work for any 7-bit or 8-bit encoding, including for example ASCII, UTF8 or the current locale encoding. +// std::string std::wstring +// mpt::ToString mpt::ToWString +// mpt::FormatVal mpt::FormatValW +// mpt::fmt mpt::wfmt +// mpt::String::Print mpt::String::PrintW +// 5. All functionality here delegates real work outside of the header file so that <sstream> and <locale> do not need to be included when +// using this functionality. +// Advantages: +// - Avoids binary code bloat when too much of iostream operator << gets inlined at every usage site. +// - Faster compile times because <sstream> and <locale> (2 very complex headers) are not included everywhere. +// Disadvantages: +// - Slightly more c++ code is required for delegating work. +// - As the header does not use iostreams, custom types need to overload mpt::ToString and mpt::ToWstring instead of iostream +// operator << to allow for custom type formatting. +// - std::string and std::wstring are returned from somewhat deep cascades of helper functions. Where possible, code is written in such +// a way that return-value-optimization (RVO) or named-return-value-optimization (NRVO) should be able to eliminate almost all these +// copies. This should not be a problem for any decent modern compiler (and even less so for a c++11 compiler where move-semantics +// will kick in if RVO/NRVO fails). + +namespace mpt +{ + +// ToString() converts various built-in types to a well-defined, locale-independent string representation. +// This is also used as a type-tunnel pattern for mpt::String::Print. +// Custom types that need to be converted to strings are encouraged to overload ToString() and ToWString(). + +static inline std::string ToString(const std::string & x) { return x; } +static inline std::string ToString(const char * const & x) { return x; } +MPT_DEPRECATED std::string ToString(const char & x); // deprecated to catch potential API mis-use, use std::string(1, x) instead +MPT_DEPRECATED std::string ToString(const wchar_t & x); // deprecated to catch potential API mis-use, use std::wstring(1, x) instead +std::string ToString(const bool & x); +std::string ToString(const signed char & x); +std::string ToString(const unsigned char & x); +std::string ToString(const signed short & x); +std::string ToString(const unsigned short & x); +std::string ToString(const signed int & x); +std::string ToString(const unsigned int & x); +std::string ToString(const signed long & x); +std::string ToString(const unsigned long & x); +std::string ToString(const signed long long & x); +std::string ToString(const unsigned long long & x); +std::string ToString(const float & x); +std::string ToString(const double & x); +std::string ToString(const long double & x); + +static inline std::wstring ToWString(const std::wstring & x) { return x; } +static inline std::wstring ToWString(const wchar_t * const & x) { return x; } +MPT_DEPRECATED std::wstring ToWString(const char & x); // deprecated to catch potential API mis-use, use std::string(1, x) instead +MPT_DEPRECATED std::wstring ToWString(const wchar_t & x); // deprecated to catch potential API mis-use, use std::wstring(1, x) instead +std::wstring ToWString(const bool & x); +std::wstring ToWString(const signed char & x); +std::wstring ToWString(const unsigned char & x); +std::wstring ToWString(const signed short & x); +std::wstring ToWString(const unsigned short & x); +std::wstring ToWString(const signed int & x); +std::wstring ToWString(const unsigned int & x); +std::wstring ToWString(const signed long & x); +std::wstring ToWString(const unsigned long & x); +std::wstring ToWString(const signed long long & x); +std::wstring ToWString(const unsigned long long & x); +std::wstring ToWString(const float & x); +std::wstring ToWString(const double & x); +std::wstring ToWString(const long double & x); + +#define MPT_FMT + +#if defined(MPT_FMT) + +namespace fmt +{ + +enum FormatFlagsEnum +{ + BaseDec = 0x0001, // base 10 (integers only) + BaseHex = 0x0002, // base 16 (integers only) + CaseLow = 0x0010, // lower case hex digits + CaseUpp = 0x0020, // upper case hex digits + FillOff = 0x0100, // do not fill up width + FillSpc = 0x0200, // fill up width with spaces + FillNul = 0x0400, // fill up width with zeros + NotaNrm = 0x1000, // float: normal/default notation + NotaFix = 0x2000, // float: fixed point notation + NotaSci = 0x4000, // float: scientific notation +}; + +} // namespace fmt + +typedef unsigned int FormatFlags; + +STATIC_ASSERT(sizeof(FormatFlags) >= sizeof(fmt::FormatFlagsEnum)); + +class Format; + +MPT_DEPRECATED std::string FormatVal(const char & x, const Format & f); // deprecated to catch potential API mis-use, use std::string(1, x) instead +MPT_DEPRECATED std::string FormatVal(const wchar_t & x, const Format & f); // deprecated to catch potential API mis-use, use std::wstring(1, x) instead +std::string FormatVal(const bool & x, const Format & f); +std::string FormatVal(const signed char & x, const Format & f); +std::string FormatVal(const unsigned char & x, const Format & f); +std::string FormatVal(const signed short & x, const Format & f); +std::string FormatVal(const unsigned short & x, const Format & f); +std::string FormatVal(const signed int & x, const Format & f); +std::string FormatVal(const unsigned int & x, const Format & f); +std::string FormatVal(const signed long & x, const Format & f); +std::string FormatVal(const unsigned long & x, const Format & f); +std::string FormatVal(const signed long long & x, const Format & f); +std::string FormatVal(const unsigned long long & x, const Format & f); + +std::string FormatVal(const float & x, const Format & f); +std::string FormatVal(const double & x, const Format & f); +std::string FormatVal(const long double & x, const Format & f); + +MPT_DEPRECATED std::wstring FormatValW(const char & x, const Format & f); // deprecated to catch potential API mis-use, use std::string(1, x) instead +MPT_DEPRECATED std::wstring FormatValW(const wchar_t & x, const Format & f); // deprecated to catch potential API mis-use, use std::wstring(1, x) instead +std::wstring FormatValW(const bool & x, const Format & f); +std::wstring FormatValW(const signed char & x, const Format & f); +std::wstring FormatValW(const unsigned char & x, const Format & f); +std::wstring FormatValW(const signed short & x, const Format & f); +std::wstring FormatValW(const unsigned short & x, const Format & f); +std::wstring FormatValW(const signed int & x, const Format & f); +std::wstring FormatValW(const unsigned int & x, const Format & f); +std::wstring FormatValW(const signed long & x, const Format & f); +std::wstring FormatValW(const unsigned long & x, const Format & f); +std::wstring FormatValW(const signed long long & x, const Format & f); +std::wstring FormatValW(const unsigned long long & x, const Format & f); + +std::wstring FormatValW(const float & x, const Format & f); +std::wstring FormatValW(const double & x, const Format & f); +std::wstring FormatValW(const long double & x, const Format & f); + +class Format +{ +private: + FormatFlags flags; + std::size_t width; + int precision; +public: + Format() : flags(0), width(0), precision(-1) {} + FormatFlags GetFlags() const { return flags; } + std::size_t GetWidth() const { return width; } + int GetPrecision() const { return precision; } + Format & SetFlags(FormatFlags f) { flags = f; return *this; } + Format & SetWidth(std::size_t w) { width = w; return *this; } + Format & SetPrecision(int p) { precision = p; return *this; } +public: + // short-hand construction + explicit Format(FormatFlags f, std::size_t w = 0, int p = -1) : flags(f), width(w), precision(p) {} + explicit Format(const char * format) : flags(0), width(0), precision(-1) { ParsePrintf(format); } + explicit Format(const wchar_t * format) : flags(0), width(0), precision(-1) { ParsePrintf(format); } + explicit Format(const std::string & format) : flags(0), width(0), precision(-1) { ParsePrintf(format); } + explicit Format(const std::wstring & format) : flags(0), width(0), precision(-1) { ParsePrintf(format); } +public: + // only for floating point formats + Format & ParsePrintf(const char * format); + Format & ParsePrintf(const wchar_t * format); + Format & ParsePrintf(const std::string & format); + Format & ParsePrintf(const std::wstring & format); +public: + Format & BaseDec() { flags &= ~(fmt::BaseDec|fmt::BaseHex); flags |= fmt::BaseDec; return *this; } + Format & BaseHex() { flags &= ~(fmt::BaseDec|fmt::BaseHex); flags |= fmt::BaseHex; return *this; } + Format & CaseLow() { flags &= ~(fmt::CaseLow|fmt::CaseUpp); flags |= fmt::CaseLow; return *this; } + Format & CaseUpp() { flags &= ~(fmt::CaseLow|fmt::CaseUpp); flags |= fmt::CaseUpp; return *this; } + Format & FillOff() { flags &= ~(fmt::FillOff|fmt::FillSpc|fmt::FillNul); flags |= fmt::FillOff; return *this; } + Format & FillSpc() { flags &= ~(fmt::FillOff|fmt::FillSpc|fmt::FillNul); flags |= fmt::FillSpc; return *this; } + Format & FillNul() { flags &= ~(fmt::FillOff|fmt::FillSpc|fmt::FillNul); flags |= fmt::FillNul; return *this; } + Format & NotaNrm() { flags &= ~(fmt::NotaNrm|fmt::NotaFix|fmt::NotaSci); flags |= fmt::NotaNrm; return *this; } + Format & NotaFix() { flags &= ~(fmt::NotaNrm|fmt::NotaFix|fmt::NotaSci); flags |= fmt::NotaFix; return *this; } + Format & NotaSci() { flags &= ~(fmt::NotaNrm|fmt::NotaFix|fmt::NotaSci); flags |= fmt::NotaSci; return *this; } + Format & Width(std::size_t w) { width = w; return *this; } + Format & Prec(int p) { precision = p; return *this; } +public: + Format & Dec() { return BaseDec(); } + Format & Hex() { return BaseHex(); } + Format & Low() { return CaseLow(); } + Format & Upp() { return CaseUpp(); } + Format & Off() { return FillOff(); } + Format & Spc() { return FillSpc(); } + Format & Nul() { return FillNul(); } + Format & Nrm() { return NotaNrm(); } + Format & Fix() { return NotaFix(); } + Format & Sci() { return NotaSci(); } +public: + Format & Decimal() { return BaseDec(); } + Format & Hexadecimal() { return BaseHex(); } + Format & Lower() { return CaseLow(); } + Format & Upper() { return CaseUpp(); } + Format & FillNone() { return FillOff(); } + Format & FillSpace() { return FillSpc(); } + Format & FillZero() { return FillNul(); } + Format & FloatNormal() { return NotaNrm(); } + Format & FloatFixed() { return NotaFix(); } + Format & FloatScientific() { return NotaSci(); } + Format & Precision(int p) { return Prec(p); } + template<typename T> + inline std::string ToString(const T & x) const + { + return FormatVal(x, *this); + } + template<typename T> + inline std::wstring ToWString(const T & x) const + { + return FormatValW(x, *this); + } +}; + +namespace fmt +{ + +template<typename T> +inline std::string dec(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseDec().FillOff()); +} +template<int width, typename T> +inline std::string dec(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseDec().FillSpc().Width(width)); +} +template<int width, typename T> +inline std::string dec0(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseDec().FillNul().Width(width)); +} + +template<typename T> +inline std::string hex(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseHex().CaseLow().FillOff()); +} +template<typename T> +inline std::string HEX(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseHex().CaseUpp().FillOff()); +} +template<int width, typename T> +inline std::string hex(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseHex().CaseLow().FillSpc().Width(width)); +} +template<int width, typename T> +inline std::string HEX(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseHex().CaseUpp().FillSpc().Width(width)); +} +template<int width, typename T> +inline std::string hex0(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseHex().CaseLow().FillNul().Width(width)); +} +template<int width, typename T> +inline std::string HEX0(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatVal(x, Format().BaseHex().CaseUpp().FillNul().Width(width)); +} + +template<typename T> +inline std::string flt(const T& x, std::size_t width = 0, int precision = -1) +{ + #if defined(HAS_TYPE_TRAITS) + STATIC_ASSERT(std::is_floating_point<T>::value); + #endif + if(width == 0) + { + return FormatVal(x, Format().NotaNrm().FillOff().Precision(precision)); + } else + { + return FormatVal(x, Format().NotaNrm().FillSpc().Width(width).Precision(precision)); + } +} +template<typename T> +inline std::string fix(const T& x, std::size_t width = 0, int precision = -1) +{ + #if defined(HAS_TYPE_TRAITS) + STATIC_ASSERT(std::is_floating_point<T>::value); + #endif + if(width == 0) + { + return FormatVal(x, Format().NotaFix().FillOff().Precision(precision)); + } else + { + return FormatVal(x, Format().NotaFix().FillSpc().Width(width).Precision(precision)); + } +} +template<typename T> +inline std::string sci(const T& x, std::size_t width = 0, int precision = -1) +{ + #if defined(HAS_TYPE_TRAITS) + STATIC_ASSERT(std::is_floating_point<T>::value); + #endif + if(width == 0) + { + return FormatVal(x, Format().NotaSci().FillOff().Precision(precision)); + } else + { + return FormatVal(x, Format().NotaSci().FillSpc().Width(width).Precision(precision)); + } +} + +} // namespace fmt + +namespace wfmt +{ + +template<typename T> +inline std::wstring dec(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseDec().FillOff()); +} +template<int width, typename T> +inline std::wstring dec(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseDec().FillSpc().Width(width)); +} +template<int width, typename T> +inline std::wstring dec0(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseDec().FillNul().Width(width)); +} + +template<typename T> +inline std::wstring hex(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseHex().CaseLow().FillOff()); +} +template<typename T> +inline std::wstring HEX(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseHex().CaseUpp().FillOff()); +} +template<int width, typename T> +inline std::wstring hex(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseHex().CaseLow().FillSpc().Width(width)); +} +template<int width, typename T> +inline std::wstring HEX(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseHex().CaseUpp().FillSpc().Width(width)); +} +template<int width, typename T> +inline std::wstring hex0(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseHex().CaseLow().FillNul().Width(width)); +} +template<int width, typename T> +inline std::wstring HEX0(const T& x) +{ + STATIC_ASSERT(std::numeric_limits<T>::is_integer); + return FormatValW(x, Format().BaseHex().CaseUpp().FillNul().Width(width)); +} + +template<typename T> +inline std::wstring flt(const T& x, std::size_t width = 0, int precision = -1) +{ + #if defined(HAS_TYPE_TRAITS) + STATIC_ASSERT(std::is_floating_point<T>::value); + #endif + if(width == 0) + { + return FormatValW(x, Format().NotaNrm().FillOff().Precision(precision)); + } else + { + return FormatValW(x, Format().NotaNrm().FillSpc().Width(width).Precision(precision)); + } +} +template<typename T> +inline std::wstring fix(const T& x, std::size_t width = 0, int precision = -1) +{ + #if defined(HAS_TYPE_TRAITS) + STATIC_ASSERT(std::is_floating_point<T>::value); + #endif + if(width == 0) + { + return FormatValW(x, Format().NotaFix().FillOff().Precision(precision)); + } else + { + return FormatValW(x, Format().NotaFix().FillSpc().Width(width).Precision(precision)); + } +} +template<typename T> +inline std::wstring sci(const T& x, std::size_t width = 0, int precision = -1) +{ + #if defined(HAS_TYPE_TRAITS) + STATIC_ASSERT(std::is_floating_point<T>::value); + #endif + if(width == 0) + { + return FormatValW(x, Format().NotaSci().FillOff().Precision(precision)); + } else + { + return FormatValW(x, Format().NotaSci().FillSpc().Width(width).Precision(precision)); + } +} + +} // namespace wfmt + +#endif // MPT_FMT + +} // namespace mpt + +#define Stringify(x) mpt::ToString(x) +#define StringifyW(x) mpt::ToWString(x) + +namespace mpt { namespace String { + +namespace detail +{ + +std::string PrintImpl(const std::string & format + , const std::string & x1 = std::string() + , const std::string & x2 = std::string() + , const std::string & x3 = std::string() + , const std::string & x4 = std::string() + , const std::string & x5 = std::string() + , const std::string & x6 = std::string() + , const std::string & x7 = std::string() + , const std::string & x8 = std::string() + ); + +std::wstring PrintImplW(const std::wstring & format + , const std::wstring & x1 = std::wstring() + , const std::wstring & x2 = std::wstring() + , const std::wstring & x3 = std::wstring() + , const std::wstring & x4 = std::wstring() + , const std::wstring & x5 = std::wstring() + , const std::wstring & x6 = std::wstring() + , const std::wstring & x7 = std::wstring() + , const std::wstring & x8 = std::wstring() + ); + +} // namespace detail + +template< + typename T1 +> +std::string Print(const std::string & format + , const T1& x1 +) +{ + return detail::PrintImpl(format + , ToString(x1) + ); +} + +template< + typename T1, + typename T2 +> +std::string Print(const std::string & format + , const T1& x1 + , const T2& x2 +) +{ + return detail::PrintImpl(format + , ToString(x1) + , ToString(x2) + ); +} + +template< + typename T1, + typename T2, + typename T3 +> +std::string Print(const std::string & format + , const T1& x1 + , const T2& x2 + , const T3& x3 +) +{ + return detail::PrintImpl(format + , ToString(x1) + , ToString(x2) + , ToString(x3) + ); +} + +template< + typename T1, + typename T2, + typename T3, + typename T4 +> +std::string Print(const std::string & format + , const T1& x1 + , const T2& x2 + , const T3& x3 + , const T4& x4 +) +{ + return detail::PrintImpl(format + , ToString(x1) + , ToString(x2) + , ToString(x3) + , ToString(x4) + ); +} + +template< + typename T1, + typename T2, + typename T3, + typename T4, + typename T5 +> +std::string Print(const std::string & format + , const T1& x1 + , const T2& x2 + , const T3& x3 + , const T4& x4 + , const T5& x5 +) +{ + return detail::PrintImpl(format + , ToString(x1) + , ToString(x2) + , ToString(x3) + , ToString(x4) + , ToString(x5) + ); +} + +template< + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6 +> +std::string Print(const std::string & format + , const T1& x1 + , const T2& x2 + , const T3& x3 + , const T4& x4 + , const T5& x5 + , const T6& x6 +) +{ + return detail::PrintImpl(format + , ToString(x1) + , ToString(x2) + , ToString(x3) + , ToString(x4) + , ToString(x5) + , ToString(x6) + ); +} + +template< + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7 +> +std::string Print(const std::string & format + , const T1& x1 + , const T2& x2 + , const T3& x3 + , const T4& x4 + , const T5& x5 + , const T6& x6 + , const T7& x7 +) +{ + return detail::PrintImpl(format + , ToString(x1) + , ToString(x2) + , ToString(x3) + , ToString(x4) + , ToString(x5) + , ToString(x6) + , ToString(x7) + ); +} + +template< + typename T1, + typename T2, + typename T3, + typename T4, + typename T5, + typename T6, + typename T7, + typename T8 +> +std::string Print(const std::string & format + , const T1& x1 + , const T2& x2 + , const T3& x3 + , const T4& x4 + , const T5& x5 + , const T6& x6 + , const T7& x7 + , const T8& x8 +) +{ + return detail::PrintImpl(format + , ToString(x1) + , ToString(x2) + , ToString(x3) + , ToString(x4) + , ToString(x5) + , ToString(x6) + , ToString(x7) + , ToString(x8) + ); +} + +template< + typename T1 +> +std::wstring PrintW(const std::wstring & fo... [truncated message content] |
From: <man...@us...> - 2013-11-13 17:45:13
|
Revision: 3205 http://sourceforge.net/p/modplug/code/3205 Author: manxorist Date: 2013-11-13 17:45:06 +0000 (Wed, 13 Nov 2013) Log Message: ----------- [Ref] Replace the second-last occurence of mpt::string. Modified Paths: -------------- trunk/OpenMPT/mptrack/PatternClipboard.cpp trunk/OpenMPT/mptrack/PatternEditorDialogs.cpp trunk/OpenMPT/soundlib/pattern.h Modified: trunk/OpenMPT/mptrack/PatternClipboard.cpp =================================================================== --- trunk/OpenMPT/mptrack/PatternClipboard.cpp 2013-11-12 23:13:18 UTC (rev 3204) +++ trunk/OpenMPT/mptrack/PatternClipboard.cpp 2013-11-13 17:45:06 UTC (rev 3205) @@ -88,7 +88,7 @@ patList[pattern] = insertedPats++; patternData.AppendFormat("Rows: %u\r\n", sndFile.Patterns[pattern].GetNumRows()); - CString name = sndFile.Patterns[pattern].GetName(); + CString name = sndFile.Patterns[pattern].GetName().c_str(); if(!name.IsEmpty()) { patternData.Append("Name: " + name + "\r\n"); Modified: trunk/OpenMPT/mptrack/PatternEditorDialogs.cpp =================================================================== --- trunk/OpenMPT/mptrack/PatternEditorDialogs.cpp 2013-11-12 23:13:18 UTC (rev 3204) +++ trunk/OpenMPT/mptrack/PatternEditorDialogs.cpp 2013-11-13 17:45:06 UTC (rev 3205) @@ -479,7 +479,7 @@ SetDlgItemText(IDC_TEXT1, s); // Window title - const CString patternName = sndFile.Patterns[m_nPattern].GetName(); + const CString patternName = sndFile.Patterns[m_nPattern].GetName().c_str(); wsprintf(s, "Pattern Properties for Pattern #%d", m_nPattern); if(!patternName.IsEmpty()) { Modified: trunk/OpenMPT/soundlib/pattern.h =================================================================== --- trunk/OpenMPT/soundlib/pattern.h 2013-11-12 23:13:18 UTC (rev 3204) +++ trunk/OpenMPT/soundlib/pattern.h 2013-11-13 17:45:06 UTC (rev 3205) @@ -103,7 +103,7 @@ return GetName(buffer, bufferSize); } bool GetName(char *buffer, size_t maxChars) const; - mpt::string GetName() const { return m_PatternName; }; + std::string GetName() const { return m_PatternName; }; // Double number of rows bool Expand(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-11-13 18:05:30
|
Revision: 3206 http://sourceforge.net/p/modplug/code/3206 Author: manxorist Date: 2013-11-13 18:05:18 +0000 (Wed, 13 Nov 2013) Log Message: ----------- [Ref] Replace last occurence of mpt::string with std::string. Modified Paths: -------------- trunk/OpenMPT/mptrack/Ctrl_pat.cpp trunk/OpenMPT/mptrack/Ctrl_seq.cpp trunk/OpenMPT/mptrack/View_tre.cpp trunk/OpenMPT/soundlib/ModSequence.cpp trunk/OpenMPT/soundlib/ModSequence.h trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/mptrack/Ctrl_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_pat.cpp 2013-11-13 17:45:06 UTC (rev 3205) +++ trunk/OpenMPT/mptrack/Ctrl_pat.cpp 2013-11-13 18:05:18 UTC (rev 3206) @@ -192,7 +192,7 @@ m_SpinSequence.SetRange(0, m_sndFile.Order.GetNumSequences() - 1); m_SpinSequence.SetPos(m_sndFile.Order.GetCurrentSequenceIndex()); - SetDlgItemText(IDC_EDIT_SEQUENCE_NAME, m_sndFile.Order.m_sName); + SetDlgItemText(IDC_EDIT_SEQUENCE_NAME, m_sndFile.Order.GetName().c_str()); m_OrderList.SetFocus(); @@ -243,7 +243,7 @@ if(dwHintMask & HINT_MODSEQUENCE) { - SetDlgItemText(IDC_EDIT_SEQUENCE_NAME, m_sndFile.Order.m_sName); + SetDlgItemText(IDC_EDIT_SEQUENCE_NAME, m_sndFile.Order.GetName().c_str()); } if(dwHintMask & (HINT_MODSEQUENCE|HINT_MODTYPE)) { @@ -1093,9 +1093,9 @@ { CString str; GetDlgItemText(IDC_EDIT_SEQUENCE_NAME, str); - if (str != m_sndFile.Order.m_sName) + if(str != m_sndFile.Order.GetName().c_str()) { - m_sndFile.Order.m_sName = str.GetString(); + m_sndFile.Order.SetName(str.GetString()); m_modDoc.SetModified(); m_modDoc.UpdateAllViews(NULL, (m_sndFile.Order.GetCurrentSequenceIndex() << HINT_SHIFT_SEQUENCE) | HINT_SEQNAMES, this); } Modified: trunk/OpenMPT/mptrack/Ctrl_seq.cpp =================================================================== --- trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2013-11-13 17:45:06 UTC (rev 3205) +++ trunk/OpenMPT/mptrack/Ctrl_seq.cpp 2013-11-13 18:05:18 UTC (rev 3206) @@ -1008,10 +1008,10 @@ for(SEQUENCEINDEX i = 0; i < numSequences; i++) { CString str; - if(sndFile.Order.GetSequence(i).m_sName.empty()) + if(sndFile.Order.GetSequence(i).GetName().empty()) str.Format(TEXT("Sequence %u"), i); else - str.Format(TEXT("%u: %s"), i, (LPCTSTR)sndFile.Order.GetSequence(i).m_sName); + str.Format(TEXT("%u: %s"), i, sndFile.Order.GetSequence(i).GetName().c_str()); const UINT flags = (sndFile.Order.GetCurrentSequenceIndex() == i) ? MF_STRING|MF_CHECKED : MF_STRING; AppendMenu(menuSequence, flags, ID_SEQUENCE_ITEM + i, str); } @@ -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.m_sName, mpt::CharsetLocale) + L"?"; + std::wstring str = L"Delete sequence " + StringifyW(sndFile.Order.GetCurrentSequenceIndex()) + L": " + mpt::String::Decode(sndFile.Order.GetName(), mpt::CharsetLocale) + L"?"; if (Reporting::Confirm(str) == cnfYes) sndFile.Order.RemoveSequence(); else Modified: trunk/OpenMPT/mptrack/View_tre.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-13 17:45:06 UTC (rev 3205) +++ trunk/OpenMPT/mptrack/View_tre.cpp 2013-11-13 18:05:18 UTC (rev 3206) @@ -794,7 +794,7 @@ // Adjust caption of the "Sequence" node (if only one sequence exists, it should be labeled with the sequence name) if(((hintFlagPart & HINT_SEQNAMES) && sndFile.Order.GetNumSequences() == 1) || adjustParentNode) { - CString seqName = sndFile.Order.GetSequence(0).m_sName; + CString seqName = sndFile.Order.GetSequence(0).GetName().c_str(); if(seqName.IsEmpty() || sndFile.Order.GetNumSequences() > 1) seqName = _T("Sequence"); else @@ -809,10 +809,10 @@ { // more than one sequence -> add folder CString sSeqName; - if(sndFile.Order.GetSequence(nSeq).m_sName.empty()) + if(sndFile.Order.GetSequence(nSeq).GetName().empty()) sSeqName.Format("Sequence %u", nSeq); else - sSeqName.Format("%u: %s", nSeq, (LPCTSTR)sndFile.Order.GetSequence(nSeq).m_sName); + sSeqName.Format("%u: %s", nSeq, sndFile.Order.GetSequence(nSeq).GetName().c_str()); UINT state = (nSeq == sndFile.Order.GetCurrentSequenceIndex()) ? TVIS_BOLD : 0; @@ -3430,7 +3430,7 @@ case MODITEM_SEQUENCE: if(modItem.val1 < sndFile.Order.GetNumSequences()) { - text = sndFile.Order.GetSequence(static_cast<SEQUENCEINDEX>(modItem.val1)).m_sName; + text = sndFile.Order.GetSequence(static_cast<SEQUENCEINDEX>(modItem.val1)).GetName(); doLabelEdit = true; } break; @@ -3523,9 +3523,9 @@ case MODITEM_HDR_ORDERS: case MODITEM_SEQUENCE: - if(modItem.val1 < sndFile.Order.GetNumSequences() && sndFile.Order.GetSequence(static_cast<SEQUENCEINDEX>(modItem.val1)).m_sName != info->item.pszText) + if(modItem.val1 < sndFile.Order.GetNumSequences() && sndFile.Order.GetSequence(static_cast<SEQUENCEINDEX>(modItem.val1)).GetName() != info->item.pszText) { - sndFile.Order.GetSequence(static_cast<SEQUENCEINDEX>(modItem.val1)).m_sName = info->item.pszText; + sndFile.Order.GetSequence(static_cast<SEQUENCEINDEX>(modItem.val1)).SetName(info->item.pszText); modDoc->SetModified(); modDoc->UpdateAllViews(NULL, HINT_SEQNAMES | HINT_MODSEQUENCE | ((modItem.val1) << HINT_SHIFT_SEQUENCE), NULL); } Modified: trunk/OpenMPT/soundlib/ModSequence.cpp =================================================================== --- trunk/OpenMPT/soundlib/ModSequence.cpp 2013-11-13 17:45:06 UTC (rev 3205) +++ trunk/OpenMPT/soundlib/ModSequence.cpp 2013-11-13 18:05:18 UTC (rev 3206) @@ -669,6 +669,20 @@ #endif // MODPLUG_TRACKER +void ModSequence::SetName(const std::string &newName) +//--------------------------------------------------- +{ + m_sName = newName; +} + + +std::string ModSequence::GetName() const +//-------------------------------------- +{ + return m_sName; +} + + ///////////////////////////////////// // Read/Write ///////////////////////////////////// Modified: trunk/OpenMPT/soundlib/ModSequence.h =================================================================== --- trunk/OpenMPT/soundlib/ModSequence.h 2013-11-13 17:45:06 UTC (rev 3205) +++ trunk/OpenMPT/soundlib/ModSequence.h 2013-11-13 18:05:18 UTC (rev 3206) @@ -115,16 +115,20 @@ bool IsPositionLocked(ORDERINDEX position); #endif // MODPLUG_TRACKER + // Sequence name setter + void SetName(const std::string &newName); + + // Sequence name getter + std::string GetName() const; - protected: iterator begin() {return m_pArray;} const_iterator begin() const {return m_pArray;} iterator end() {return m_pArray + m_nSize;} const_iterator end() const {return m_pArray + m_nSize;} -public: - mpt::string m_sName; // Sequence name. +protected: + std::string m_sName; // Sequence name. protected: CSoundFile &m_sndFile; // Pointer to associated CSoundFile. Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-11-13 17:45:06 UTC (rev 3205) +++ trunk/OpenMPT/test/test.cpp 2013-11-13 18:05:18 UTC (rev 3206) @@ -1278,13 +1278,13 @@ VERIFY_EQUAL_NONCONT(sndFile.Order.GetNumSequences(), 2); VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(0).GetLengthTailTrimmed(), 3); - VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(0).m_sName, "First Sequence"); + VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(0).GetName(), "First Sequence"); VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(0)[0], sndFile.Order.GetIgnoreIndex()); VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(0)[1], 0); VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(0)[2], sndFile.Order.GetIgnoreIndex()); VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(1).GetLengthTailTrimmed(), 2); - VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(1).m_sName, "Second Sequence"); + VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(1).GetName(), "Second Sequence"); VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(1)[0], 1); VERIFY_EQUAL_NONCONT(sndFile.Order.GetSequence(1)[1], 2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |