From: <sag...@us...> - 2010-03-28 17:21:51
|
Revision: 559 http://modplug.svn.sourceforge.net/modplug/?rev=559&view=rev Author: saga-games Date: 2010-03-28 17:21:44 +0000 (Sun, 28 Mar 2010) Log Message: ----------- [New] INI Settings: When portable mode is enabled, the most common paths in mptrack.ini are now translated to relative paths (if possible). MIDI library, soundfont and plugin paths are not translated to relative paths (yet). [Fix] XM Loader: Some XMs not made with ModPlug were recognized as files made with MPT. [Imp/Ref] It's now possible to link several pattern undo commands together (to undo them in one step). That way, overflow paste now only uses undo step. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Modedit.cpp trunk/OpenMPT/mptrack/Undo.cpp trunk/OpenMPT/mptrack/Undo.h trunk/OpenMPT/soundlib/Load_xm.cpp Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2010-03-28 16:24:23 UTC (rev 558) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2010-03-28 17:21:44 UTC (rev 559) @@ -267,6 +267,11 @@ TCHAR CMainFrame::m_szDefaultDirectory[NUM_DIRS][_MAX_PATH] = {0}; TCHAR CMainFrame::m_szWorkingDirectory[NUM_DIRS][_MAX_PATH] = {0}; TCHAR CMainFrame::m_szKbdFile[_MAX_PATH] = ""; //rewbs.customKeys +// Directory to INI setting translation +const TCHAR CMainFrame::m_szDirectoryToSettingsName[NUM_DIRS][32] = +{ + _T("Songs_Directory"), _T("Samples_Directory"), _T("Instruments_Directory"), _T("Plugins_Directory"), _T("Plugin_Presets_Directory"), _T("Export_Directory"), _T("") +}; CInputHandler *CMainFrame::m_InputHandler = NULL; //rewbs.customKeys @@ -451,19 +456,18 @@ m_nSampleUndoMaxBuffer = max(1, m_nSampleUndoMaxBuffer) << 20; TCHAR szPath[_MAX_PATH] = ""; - GetPrivateProfileString("Paths", "Songs_Directory", GetDefaultDirectory(DIR_MODS), szPath, INIBUFFERSIZE, iniFile); - SetDefaultDirectory(szPath, DIR_MODS); - GetPrivateProfileString("Paths", "Samples_Directory", GetDefaultDirectory(DIR_SAMPLES), szPath, INIBUFFERSIZE, iniFile); - SetDefaultDirectory(szPath, DIR_SAMPLES); - GetPrivateProfileString("Paths", "Instruments_Directory", GetDefaultDirectory(DIR_INSTRUMENTS), szPath, INIBUFFERSIZE, iniFile); - SetDefaultDirectory(szPath, DIR_INSTRUMENTS); - GetPrivateProfileString("Paths", "Plugins_Directory", GetDefaultDirectory(DIR_PLUGINS), szPath, INIBUFFERSIZE, iniFile); - SetDefaultDirectory(szPath, DIR_PLUGINS); - GetPrivateProfileString("Paths", "Plugin_Presets_Directory", GetDefaultDirectory(DIR_PLUGINPRESETS), szPath, INIBUFFERSIZE, iniFile); - SetDefaultDirectory(szPath, DIR_PLUGINPRESETS); - GetPrivateProfileString("Paths", "Export_Directory", GetDefaultDirectory(DIR_EXPORT), szPath, INIBUFFERSIZE, iniFile); - SetDefaultDirectory(szPath, DIR_EXPORT); + for(size_t i = 0; i < NUM_DIRS; i++) + { + if(m_szDirectoryToSettingsName[i][0] == 0) + continue; + + GetPrivateProfileString("Paths", m_szDirectoryToSettingsName[i], GetDefaultDirectory(static_cast<Directory>(i)), szPath, INIBUFFERSIZE, iniFile); + RelativePathToAbsolute(szPath); + SetDefaultDirectory(szPath, static_cast<Directory>(i), false); + + } GetPrivateProfileString("Paths", "Key_Config_File", m_szKbdFile, m_szKbdFile, INIBUFFERSIZE, iniFile); + RelativePathToAbsolute(m_szKbdFile); CSoundFile::m_nXBassDepth = GetPrivateProfileLong("Effects", "XBassDepth", 0, iniFile); CSoundFile::m_nXBassRange = GetPrivateProfileLong("Effects", "XBassRange", 0, iniFile); @@ -980,14 +984,29 @@ WritePrivateProfileDWord("Pattern Editor", "Record", gbPatternRecord, iniFile); WritePrivateProfileDWord("Pattern Editor", "AutoChordWaitTime", gnAutoChordWaitTime, iniFile); - WritePrivateProfileString("Paths", "Songs_Directory", GetDefaultDirectory(DIR_MODS), iniFile); - WritePrivateProfileString("Paths", "Samples_Directory", GetDefaultDirectory(DIR_SAMPLES), iniFile); - WritePrivateProfileString("Paths", "Instruments_Directory", GetDefaultDirectory(DIR_INSTRUMENTS), iniFile); - WritePrivateProfileString("Paths", "Plugins_Directory", GetDefaultDirectory(DIR_PLUGINS), iniFile); - WritePrivateProfileString("Paths", "Plugin_Presets_Directory", GetDefaultDirectory(DIR_PLUGINPRESETS), iniFile); - WritePrivateProfileString("Paths", "Export_Directory", GetDefaultDirectory(DIR_EXPORT), iniFile); - WritePrivateProfileString("Paths", "Key_Config_File", m_szKbdFile, iniFile); + // Write default paths + const bool bConvertPaths = theApp.IsPortableMode(); + TCHAR szPath[_MAX_PATH] = ""; + for(size_t i = 0; i < NUM_DIRS; i++) + { + if(m_szDirectoryToSettingsName[i][0] == 0) + continue; + _tcscpy(szPath, GetDefaultDirectory(static_cast<Directory>(i))); + if(bConvertPaths) + { + AbsolutePathToRelative(szPath); + } + WritePrivateProfileString("Paths", m_szDirectoryToSettingsName[i], szPath, iniFile); + + } + _tcscpy(szPath, m_szKbdFile); + if(bConvertPaths) + { + AbsolutePathToRelative(szPath); + } + WritePrivateProfileString("Paths", "Key_Config_File", szPath, iniFile); + WritePrivateProfileLong("Effects", "XBassDepth", CSoundFile::m_nXBassDepth, iniFile); WritePrivateProfileLong("Effects", "XBassRange", CSoundFile::m_nXBassRange, iniFile); WritePrivateProfileLong("Effects", "ReverbDepth", CSoundFile::m_nReverbDepth, iniFile); @@ -3104,3 +3123,77 @@ { return m_szWorkingDirectory[dir]; } + + +// Convert an absolute path to a path that's relative to OpenMPT's directory. +// Paths are relative to the executable path. +// nLength specifies the maximum number of character that can be written into szPath, +// including the trailing null char. +template <size_t nLength> +void CMainFrame::AbsolutePathToRelative(TCHAR (&szPath)[nLength]) +//--------------------------------------------------------------- +{ + STATIC_ASSERT(nLength >= 3); + + if(_tcslen(szPath) == 0) + return; + + const size_t nStrLength = nLength - 1; // "usable" length, i.e. not including the null char. + TCHAR szExePath[nLength], szTempPath[nLength]; + _tcsncpy(szExePath, theApp.GetAppDirPath(), nStrLength); + SetNullTerminator(szExePath); + + // Path is OpenMPT's directory or a sub directory ("C:\OpenMPT\Somepath" => ".\Somepath") + if(!_tcsncicmp(szExePath, szPath, _tcslen(szExePath))) + { + _tcscpy(szTempPath, _T(".\\")); // ".\" + _tcsncat(szTempPath, &szPath[_tcslen(szExePath)], nStrLength - 2); // "Somepath" + _tcscpy(szPath, szTempPath); + } else + // Path is on the same drive as OpenMPT ("C:\Somepath" => "\Somepath") + if(!_tcsncicmp(szExePath, szPath, 1)) + { + _tcsncpy(szTempPath, &szPath[2], nStrLength); // "\Somepath" + _tcscpy(szPath, szTempPath); + } + SetNullTerminator(szPath); +} + + +// Convert a relative path to an absolute path. +// Paths are relative to the executable path. +// nLength specifies the maximum number of character that can be written into szPath, +// including the trailing null char. +template <size_t nLength> +void CMainFrame::RelativePathToAbsolute(TCHAR (&szPath)[nLength]) +//--------------------------------------------------------------- +{ + STATIC_ASSERT(nLength >= 3); + + if(_tcslen(szPath) == 0) + return; + + const size_t nStrLength = nLength - 1; // "usable" length, i.e. not including the null char. + TCHAR szExePath[nLength], szTempPath[nLength]; + _tcsncpy(szExePath, theApp.GetAppDirPath(), nStrLength); + SetNullTerminator(szExePath); + + // Path is on the same drive as OpenMPT ("\Somepath\" => "C:\Somepath\") + if(!_tcsncicmp(szPath, _T("\\"), 1)) + { + _tcsncpy(szTempPath, szExePath, 2); // "C:" + _tcsncat(szTempPath, szPath, nStrLength - 2); // "\Somepath\" + _tcscpy(szPath, szTempPath); + } else + // Path is OpenMPT's directory or a sub directory (".\Somepath\" => "C:\OpenMPT\Somepath\") + if(!_tcsncicmp(szPath, _T(".\\"), 2)) + { + _tcsncpy(szTempPath, szExePath, nStrLength); // "C:\OpenMPT\" + if(_tcslen(szTempPath) < nStrLength) + { + _tcsncat(szTempPath, &szPath[2], nStrLength - _tcslen(szTempPath)); // "Somepath" + } + _tcscpy(szPath, szTempPath); + } + SetNullTerminator(szPath); +} Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2010-03-28 16:24:23 UTC (rev 558) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2010-03-28 17:21:44 UTC (rev 559) @@ -616,11 +616,19 @@ static LPCTSTR GetWorkingDirectory(Directory dir); static void SetDefaultDirectory(const LPCTSTR szFilenameFrom, Directory dir, bool bStripFilename = false); static LPCTSTR GetDefaultDirectory(Directory dir); + + template <size_t nLength> + static void AbsolutePathToRelative(TCHAR (&szPath)[nLength]); + template <size_t nLength> + static void RelativePathToAbsolute(TCHAR (&szPath)[nLength]); + protected: static void SetDirectory(const LPCTSTR szFilenameFrom, Directory dir, TCHAR (&pDirs)[NUM_DIRS][_MAX_PATH], bool bStripFilename); + // Directory Arrays (default dir + last dir) static TCHAR m_szDefaultDirectory[NUM_DIRS][_MAX_PATH]; static TCHAR m_szWorkingDirectory[NUM_DIRS][_MAX_PATH]; + static const TCHAR m_szDirectoryToSettingsName[NUM_DIRS][32]; // Overrides Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2010-03-28 16:24:23 UTC (rev 558) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2010-03-28 17:21:44 UTC (rev 559) @@ -1204,7 +1204,7 @@ UINT ncol = (dwBeginSel & 0xFFFF) >> 3; UINT col; bool bS3MCommands = false, bOk = false; - bool bPrepareUndo = true; + bool bPrepareUndo = true, bFirstUndo = true; MODTYPE origFormat = MOD_TYPE_IT; UINT len = 0, startLen; @@ -1278,8 +1278,9 @@ // Before changing anything in this pattern, we have to create an undo point. if(bPrepareUndo) { - GetPatternUndo()->PrepareUndo(nPattern, 0, 0, m_SndFile.m_nChannels, m_SndFile.PatternSize[nPattern]); + GetPatternUndo()->PrepareUndo(nPattern, 0, 0, m_SndFile.m_nChannels, m_SndFile.PatternSize[nPattern], !bFirstUndo); bPrepareUndo = false; + bFirstUndo = false; } // ITSyle mixpaste requires that we keep a copy of the thing we are about to paste on Modified: trunk/OpenMPT/mptrack/Undo.cpp =================================================================== --- trunk/OpenMPT/mptrack/Undo.cpp 2010-03-28 16:24:23 UTC (rev 558) +++ trunk/OpenMPT/mptrack/Undo.cpp 2010-03-28 17:21:44 UTC (rev 559) @@ -37,8 +37,9 @@ // - y: first row // - cx: width // - cy: height -bool CPatternUndo::PrepareUndo(PATTERNINDEX pattern, UINT x, UINT y, UINT cx, UINT cy) -//------------------------------------------------------------------------------------ +// - linkToPrevious: Don't create a separate undo step, but link this to the previous undo event. +bool CPatternUndo::PrepareUndo(PATTERNINDEX pattern, UINT x, UINT y, UINT cx, UINT cy, bool linkToPrevious) +//--------------------------------------------------------------------------------------------------------- { if(m_pModDoc == nullptr) return false; CSoundFile *pSndFile = m_pModDoc->GetSoundFile(); @@ -73,6 +74,7 @@ sUndo.cx = cx; sUndo.cy = cy; sUndo.pbuffer = pUndoData; + sUndo.linkToPrevious = linkToPrevious; pPattern += x + y * pSndFile->m_nChannels; for (UINT iy = 0; iy < cy; iy++) { @@ -92,6 +94,15 @@ PATTERNINDEX CPatternUndo::Undo() //------------------------------- { + return Undo(false); +} + + +// Restore an undo point. Returns which pattern has been modified. +// linkedFromPrevious is true if a connected undo even is going to be deleted. +PATTERNINDEX CPatternUndo::Undo(bool linkedFromPrevious) +//------------------------------------------------------ +{ if(m_pModDoc == nullptr) return PATTERNINDEX_INVALID; CSoundFile *pSndFile = m_pModDoc->GetSoundFile(); if(pSndFile == nullptr) return PATTERNINDEX_INVALID; @@ -99,6 +110,7 @@ MODCOMMAND *pUndoData, *pPattern; PATTERNINDEX nPattern; ROWINDEX nRows; + bool linkToPrevious = false; if (CanUndo() == false) return PATTERNINDEX_INVALID; @@ -106,6 +118,9 @@ while(UndoBuffer.back().pattern >= pSndFile->Patterns.Size()) { RemoveLastUndoStep(); + // The command which was connect to this command is no more valid, so don't search for the next command. + if(linkedFromPrevious) + return PATTERNINDEX_INVALID; } // Select most recent undo slot @@ -128,6 +143,7 @@ CSoundFile::FreePattern(oldPattern); } } + linkToPrevious = pUndo->linkToPrevious; pUndoData = pUndo->pbuffer; pPattern = pSndFile->Patterns[nPattern]; if (!pSndFile->Patterns[nPattern]) return PATTERNINDEX_INVALID; @@ -143,7 +159,13 @@ RemoveLastUndoStep(); if (CanUndo() == false) m_pModDoc->UpdateAllViews(NULL, HINT_UNDO); - return nPattern; + if(linkToPrevious) + { + return Undo(true); + } else + { + return nPattern; + } } Modified: trunk/OpenMPT/mptrack/Undo.h =================================================================== --- trunk/OpenMPT/mptrack/Undo.h 2010-03-28 16:24:23 UTC (rev 558) +++ trunk/OpenMPT/mptrack/Undo.h 2010-03-28 17:21:44 UTC (rev 559) @@ -21,6 +21,7 @@ UINT column, row; UINT cx, cy; MODCOMMAND *pbuffer; + bool linkToPrevious; }; //================ @@ -35,23 +36,26 @@ // Pattern undo helper functions void DeleteUndoStep(const UINT nStep); + PATTERNINDEX Undo(bool linkedFromPrevious); public: // Pattern undo functions void ClearUndo(); - bool PrepareUndo(PATTERNINDEX pattern, UINT x, UINT y, UINT cx, UINT cy); + bool PrepareUndo(PATTERNINDEX pattern, UINT x, UINT y, UINT cx, UINT cy, bool linkToPrevious = false); PATTERNINDEX Undo(); bool CanUndo(); void RemoveLastUndoStep(); void SetParent(CModDoc *pModDoc) {m_pModDoc = pModDoc;} - CPatternUndo() { + CPatternUndo() + { UndoBuffer.clear(); m_pModDoc = nullptr; }; - ~CPatternUndo() { + ~CPatternUndo() + { ClearUndo(); }; @@ -112,11 +116,13 @@ void SetParent(CModDoc *pModDoc) {m_pModDoc = pModDoc;} - CSampleUndo() { + CSampleUndo() + { UndoBuffer.clear(); m_pModDoc = nullptr; }; - ~CSampleUndo() { + ~CSampleUndo() + { ClearUndo(); }; Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2010-03-28 16:24:23 UTC (rev 558) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2010-03-28 17:21:44 UTC (rev 559) @@ -664,8 +664,10 @@ // Read mix plugins information if (dwMemPos + 8 < dwMemLength) { + DWORD dwOldPos = dwMemPos; dwMemPos += LoadMixPlugins(lpStream+dwMemPos, dwMemLength-dwMemPos); - bMadeWithModPlug = true; + if(dwMemPos != dwOldPos) + bMadeWithModPlug = true; } // Check various things to find out whether this has been made with MPT. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |