From: <sag...@us...> - 2011-08-31 18:00:21
|
Revision: 1003 http://modplug.svn.sourceforge.net/modplug/?rev=1003&view=rev Author: saga-games Date: 2011-08-31 18:00:14 +0000 (Wed, 31 Aug 2011) Log Message: ----------- [Ref] Some refactoring [Fix] Added critical section when opening param editor (previously, a debug assert could be triggered because updates were sent to the editor before it was painted for the first time) [Mod] OpenMPT: Version is now 1.20.00.14 Modified Paths: -------------- trunk/OpenMPT/mptrack/CleanupSong.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/Modedit.cpp trunk/OpenMPT/mptrack/Undo.cpp trunk/OpenMPT/mptrack/View_pat.cpp trunk/OpenMPT/mptrack/misc_util.h trunk/OpenMPT/mptrack/version.h trunk/OpenMPT/soundlib/pattern.cpp Modified: trunk/OpenMPT/mptrack/CleanupSong.cpp =================================================================== --- trunk/OpenMPT/mptrack/CleanupSong.cpp 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/CleanupSong.cpp 2011-08-31 18:00:14 UTC (rev 1003) @@ -702,7 +702,6 @@ vector<bool> usedmap; INSTRUMENTINDEX swapmap[MAX_INSTRUMENTS]; INSTRUMENTINDEX swapdest[MAX_INSTRUMENTS]; - CHAR s[512]; UINT nRemoved = 0; INSTRUMENTINDEX nSwap, nIndex; bool bReorg = false; @@ -718,7 +717,7 @@ } } else { - ::MessageBox(NULL, "This is an IT project file, so no samples associated with a used instrument will be removed.", "Removing unused instruments", MB_OK | MB_ICONINFORMATION); + ::MessageBox(NULL, "This is an IT project file, so no samples associated with an used instrument will be removed.", "Removing unused instruments", MB_OK | MB_ICONINFORMATION); } BeginWaitCursor(); @@ -734,7 +733,7 @@ // pSndFile->DestroyInstrument(i); pSndFile->DestroyInstrument(i, removeSamples); // -! BEHAVIOUR_CHANGE#0003 - if ((i == pSndFile->GetNumInstruments()) && (i>1)) + if ((i == pSndFile->GetNumInstruments()) && (i >1)) pSndFile->m_nInstruments--; else bReorg = true; @@ -799,6 +798,7 @@ } if (nRemoved) { + CHAR s[64]; wsprintf(s, "%d unused instrument%s removed\n", nRemoved, (nRemoved == 1) ? "" : "s"); m_pModDoc->AddToLog(s); return true; @@ -814,12 +814,12 @@ CSoundFile *pSndFile = m_pModDoc->GetSoundFile(); if(pSndFile == nullptr) return false; - bool usedmap[MAX_MIXPLUGINS]; - memset(usedmap, false, sizeof(usedmap)); + vector<bool> usedmap(MAX_MIXPLUGINS, false); - for (PLUGINDEX nPlug = 0; nPlug < MAX_MIXPLUGINS; nPlug++) { + for (PLUGINDEX nPlug = 0; nPlug < MAX_MIXPLUGINS; nPlug++) + { - //Is the plugin assigned to a channel? + // Is the plugin assigned to a channel? for (CHANNELINDEX nChn = 0; nChn < pSndFile->GetNumChannels(); nChn++) { if (pSndFile->ChnSettings[nChn].nMixPlugin == nPlug + 1) @@ -829,8 +829,8 @@ } } - //Is the plugin used by an instrument? - for (INSTRUMENTINDEX nIns=1; nIns<=pSndFile->GetNumInstruments(); nIns++) + // Is the plugin used by an instrument? + for (INSTRUMENTINDEX nIns = 1; nIns <= pSndFile->GetNumInstruments(); nIns++) { if (pSndFile->Instruments[nIns] && (pSndFile->Instruments[nIns]->nMixPlug == nPlug + 1)) { @@ -839,11 +839,11 @@ } } - //Is the plugin assigned to master? + // Is the plugin assigned to master? if (pSndFile->m_MixPlugins[nPlug].Info.dwInputRouting & MIXPLUG_INPUTF_MASTEREFFECT) usedmap[nPlug] = true; - //all outputs of used plugins count as used + // All outputs of used plugins count as used if (usedmap[nPlug] != false) { if (pSndFile->m_MixPlugins[nPlug].Info.dwOutputRouting & 0x80) @@ -1006,8 +1006,7 @@ bool CModCleanupDlg::RemoveAllPlugins() //------------------------------------- { - bool keepMask[MAX_MIXPLUGINS]; - memset(keepMask, false, sizeof(keepMask)); + vector<bool> keepMask(MAX_MIXPLUGINS, false); m_pModDoc->RemovePlugs(keepMask); return true; } Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2011-08-31 18:00:14 UTC (rev 1003) @@ -975,9 +975,10 @@ void CMainFrame::audioCloseDevice() //--------------------------------- { - CriticalSection cs; if (gpSoundDevice) { + CriticalSection cs; + gpSoundDevice->Reset(); gpSoundDevice->Close(); } Modified: trunk/OpenMPT/mptrack/Mainfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/Mainfrm.h 2011-08-31 18:00:14 UTC (rev 1003) @@ -664,8 +664,8 @@ }; // Critical section handling done in (safe) RAII style. -// Create a CriticalSection object whenever you need exclusive access CSoundFile. -// One object = one lock. +// Create a CriticalSection object whenever you need exclusive access to CSoundFile. +// One object = one lock / critical section. // The critical section is automatically left when the object is destroyed, but // Enter() and Leave() can also be called manually if needed. class CriticalSection Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/Moddoc.h 2011-08-31 18:00:14 UTC (rev 1003) @@ -285,7 +285,7 @@ void CheckUsedChannels(vector<bool> &usedMask, CHANNELINDEX maxRemoveCount = MAX_BASECHANNELS) const; bool ConvertInstrumentsToSamples(); - UINT RemovePlugs(const bool (&keepMask)[MAX_MIXPLUGINS]); + UINT RemovePlugs(const vector<bool> &keepMask); PATTERNINDEX InsertPattern(ORDERINDEX nOrd = ORDERINDEX_INVALID, ROWINDEX nRows = 64); SAMPLEINDEX InsertSample(bool bLimit = false); Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2011-08-31 18:00:14 UTC (rev 1003) @@ -348,17 +348,18 @@ } -UINT CModDoc::RemovePlugs(const bool (&keepMask)[MAX_MIXPLUGINS]) -//--------------------------------------------------------------- +UINT CModDoc::RemovePlugs(const vector<bool> &keepMask) +//----------------------------------------------------- { //Remove all plugins whose keepMask[plugindex] is false. - UINT nRemoved=0; - for (PLUGINDEX nPlug=0; nPlug<MAX_MIXPLUGINS; nPlug++) + UINT nRemoved = 0; + const PLUGINDEX maxPlug = min(MAX_MIXPLUGINS, keepMask.size()); + + for (PLUGINDEX nPlug = 0; nPlug < maxPlug; nPlug++) { SNDMIXPLUGIN* pPlug = &m_SndFile.m_MixPlugins[nPlug]; if (keepMask[nPlug] || !pPlug) { - Log("Keeping mixplug addess (%d): %X\n", nPlug, &(pPlug->pMixPlugin)); continue; } Modified: trunk/OpenMPT/mptrack/Undo.cpp =================================================================== --- trunk/OpenMPT/mptrack/Undo.cpp 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/Undo.cpp 2011-08-31 18:00:14 UTC (rev 1003) @@ -58,7 +58,7 @@ if (firstRow + numRows >= nRows) numRows = nRows - firstRow; if (firstChn + numChns >= pSndFile->GetNumChannels()) numChns = pSndFile->GetNumChannels() - firstChn; - pUndoData = new MODCOMMAND[numChns * numRows]; + pUndoData = CPattern::AllocatePattern(numRows, numChns); if (!pUndoData) return false; const bool bUpdate = !CanUndo(); // update undo status? @@ -210,7 +210,7 @@ bool CPatternUndo::CanUndo() //-------------------------- { - return (UndoBuffer.size() > 0) ? true : false; + return (UndoBuffer.size() > 0); } @@ -291,8 +291,8 @@ SAMPLEUNDOBUFFER sUndo; // Save old sample header - memcpy(&sUndo.OldSample, &pSndFile->Samples[nSmp], sizeof(MODSAMPLE)); - memcpy(sUndo.szOldName, pSndFile->m_szNames[nSmp], sizeof(sUndo.szOldName)); + MemCopy(sUndo.OldSample, pSndFile->Samples[nSmp]); + MemCopy(sUndo.szOldName, pSndFile->m_szNames[nSmp]); sUndo.nChangeType = nChangeType; if(nChangeType == sundo_replace) @@ -426,9 +426,9 @@ } // Restore old sample header - memcpy(&pSndFile->Samples[nSmp], &pUndo->OldSample, sizeof(MODSAMPLE)); + MemCopy(pSndFile->Samples[nSmp], pUndo->OldSample); pSndFile->Samples[nSmp].pSample = pCurrentSample; // select the "correct" old sample - memcpy(pSndFile->m_szNames[nSmp], pUndo->szOldName, sizeof(pUndo->szOldName)); + MemCopy(pSndFile->m_szNames[nSmp], pUndo->szOldName); if(pNewSample != nullptr) { Modified: trunk/OpenMPT/mptrack/View_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_pat.cpp 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/View_pat.cpp 2011-08-31 18:00:14 UTC (rev 1003) @@ -2321,6 +2321,8 @@ else { //Open window & send data + CriticalSection cs; + m_pEffectVis = new CEffectVis(this, row0, row1, nchn, pModDoc, m_nPattern); if (m_pEffectVis) { @@ -2885,10 +2887,10 @@ { CHANNELINDEX firstChannel = GetSelectionStartChan(), lastChannel = GetSelectionEndChan(); ROWINDEX firstRow = GetSelectionStartRow(), lastRow = GetSelectionEndRow(); - firstChannel = CLAMP(firstChannel, 0, pSndFile->GetNumChannels() - 1); - lastChannel = CLAMP(lastChannel, firstChannel, pSndFile->GetNumChannels() - 1); - firstRow = CLAMP(firstRow, 0, pSndFile->Patterns[m_nPattern].GetNumRows() - 1); - lastRow = CLAMP(lastRow, firstRow, pSndFile->Patterns[m_nPattern].GetNumRows() - 1); + Limit(firstChannel, (CHANNELINDEX)0, (CHANNELINDEX)(pSndFile->GetNumChannels() - 1)); + Limit(lastChannel, firstChannel, (CHANNELINDEX)(pSndFile->GetNumChannels() - 1)); + Limit(firstRow, (ROWINDEX)0, pSndFile->Patterns[m_nPattern].GetNumRows() - 1); + Limit(lastRow, firstRow, pSndFile->Patterns[m_nPattern].GetNumRows() - 1); // adjust min/max channel if they're only partly selected (i.e. volume column or effect column (when using .MOD) is not covered) if(CreateCursor(0, firstChannel, useVolCol ? VOL_COLUMN : EFFECT_COLUMN) < (m_dwBeginSel & 0xFFFF)) @@ -3071,7 +3073,8 @@ m_nLastPlayedOrder = nOrd; } - if (nRow < m_nLastPlayedRow) { + if (nRow < m_nLastPlayedRow) + { InvalidateChannelsHeaders(); } m_nLastPlayedRow = nRow; @@ -3092,12 +3095,14 @@ } */ - if (nOrd >= pSndFile->Order.GetLength() || pSndFile->Order[nOrd] != nPat) { + if (nOrd >= pSndFile->Order.GetLength() || pSndFile->Order[nOrd] != nPat) + { //order doesn't correlate with pattern, so mark it as invalid nOrd = 0xFFFF; } - if (m_pEffectVis && m_pEffectVis->m_hWnd) { + if (m_pEffectVis && m_pEffectVis->m_hWnd) + { m_pEffectVis->SetPlayCursor(nPat, nRow); } @@ -4948,7 +4953,7 @@ if (pModDoc->GetSplitKeyboardSettings()->octaveLink && note <= NOTE_MAX) { note += 12 * pModDoc->GetSplitKeyboardSettings()->octaveModifier; - note = CLAMP(note, NOTE_MIN, NOTE_MAX); + Limit(note, NOTE_MIN, NOTE_MAX); } if (pModDoc->GetSplitKeyboardSettings()->splitInstrument) { @@ -4969,27 +4974,34 @@ { CHAR s[512]; bool itemFound; - for (UINT plug=0; plug<=MAX_MIXPLUGINS; plug++) { + for (UINT plug=0; plug<=MAX_MIXPLUGINS; plug++) + { itemFound=false; s[0] = 0; - if (!plug) { + if (!plug) + { strcpy(s, "No plugin"); itemFound=true; - } else { + } else + { PSNDMIXPLUGIN p = &(pSndFile->m_MixPlugins[plug-1]); - if (p->Info.szLibraryName[0]) { + if (p->Info.szLibraryName[0]) + { wsprintf(s, "FX%d: %s", plug, p->Info.szName); itemFound=true; } } - if (itemFound){ - m_nMenuOnChan=nChn+1; - if (plug == pSndFile->ChnSettings[nChn].nMixPlugin) { + if (itemFound) + { + m_nMenuOnChan = nChn + 1; + if (plug == pSndFile->ChnSettings[nChn].nMixPlugin) + { AppendMenu(hMenu, (MF_STRING|MF_CHECKED), ID_PLUGSELECT+plug, s); - } else { + } else + { AppendMenu(hMenu, MF_STRING, ID_PLUGSELECT+plug, s); } } @@ -5006,7 +5018,8 @@ bool bSolo = false, bUnmuteAll = false; bool bSoloPending = false, bUnmuteAllPending = false; // doesn't work perfectly yet - for (CHANNELINDEX i = 0; i < pSndFile->m_nChannels; i++) { + for (CHANNELINDEX i = 0; i < pSndFile->m_nChannels; i++) + { if (i != nChn) { if (!(pSndFile->ChnSettings[i].dwFlags & CHN_MUTE)) bSolo = bSoloPending = true; @@ -5024,8 +5037,7 @@ if (bUnmuteAll) AppendMenu(hMenu, MF_STRING, ID_PATTERN_UNMUTEALL, "Unmute All\t" + ih->GetKeyTextFromCommand(kcChannelUnmuteAll)); AppendMenu(hMenu, - pSndFile->m_bChannelMuteTogglePending[nChn] ? - (MF_STRING|MF_CHECKED) : MF_STRING, + pSndFile->m_bChannelMuteTogglePending[nChn] ? (MF_STRING|MF_CHECKED) : MF_STRING, ID_PATTERN_TRANSITIONMUTE, (pSndFile->ChnSettings[nChn].dwFlags & CHN_MUTE) ? "On transition: Unmute\t" + ih->GetKeyTextFromCommand(kcToggleChanMuteOnPatTransition) : @@ -5052,12 +5064,7 @@ bool CViewPattern::BuildRowInsDelCtxMenu(HMENU hMenu, CInputHandler* ih) //---------------------------------------------------------------------- { - CString label = ""; - if (GetSelectionStartRow() != GetSelectionEndRow()) { - label = "Rows"; - } else { - label = "Row"; - } + const CString label = (GetSelectionStartRow() != GetSelectionEndRow() ? "Rows" : "Row"); AppendMenu(hMenu, MF_STRING, ID_PATTERN_INSERTROW, "Insert " + label + "\t" + ih->GetKeyTextFromCommand(kcInsertRow)); AppendMenu(hMenu, MF_STRING, ID_PATTERN_DELETEROW, "Delete " + label + "\t" + ih->GetKeyTextFromCommand(kcDeleteRows) ); @@ -5241,7 +5248,8 @@ //AppendMenu(hMenu, MF_STRING, ID_RUN_SCRIPT, "Run script"); - if (!greyed || !(CMainFrame::GetSettings().m_dwPatternSetup & PATTERN_OLDCTXMENUSTYLE)) { + if (!greyed || !(CMainFrame::GetSettings().m_dwPatternSetup & PATTERN_OLDCTXMENUSTYLE)) + { AppendMenu(hMenu, MF_STRING|greyed, ID_TRANSPOSE_UP, "Transpose +1\t" + ih->GetKeyTextFromCommand(kcTransposeUp)); AppendMenu(hMenu, MF_STRING|greyed, ID_TRANSPOSE_DOWN, "Transpose -1\t" + ih->GetKeyTextFromCommand(kcTransposeDown)); AppendMenu(hMenu, MF_STRING|greyed, ID_TRANSPOSE_OCTUP, "Transpose +12\t" + ih->GetKeyTextFromCommand(kcTransposeOctUp)); @@ -5257,7 +5265,8 @@ CArray<UINT, UINT> validChans; DWORD greyed = (ListChansWhereColSelected(VOL_COLUMN, validChans)>0)?FALSE:MF_GRAYED; - if (!greyed || !(CMainFrame::GetSettings().m_dwPatternSetup&PATTERN_OLDCTXMENUSTYLE)) { + if (!greyed || !(CMainFrame::GetSettings().m_dwPatternSetup&PATTERN_OLDCTXMENUSTYLE)) + { AppendMenu(hMenu, MF_STRING|greyed, ID_PATTERN_AMPLIFY, "Amplify\t" + ih->GetKeyTextFromCommand(kcPatternAmplify)); return true; } @@ -5450,13 +5459,16 @@ UINT startChan = GetSelectionStartChan(); UINT endChan = GetSelectionEndChan(); - if (GetColTypeFromCursor(m_dwBeginSel) <= colType) { + if (GetColTypeFromCursor(m_dwBeginSel) <= colType) + { chans.Add(startChan); //first selected chan includes this col type } - for (UINT chan=startChan+1; chan<endChan; chan++) { + for (UINT chan=startChan+1; chan<endChan; chan++) + { chans.Add(chan); //All chans between first & last must include this col type } - if ((startChan != endChan) && colType <= GetColTypeFromCursor(m_dwEndSel)) { + if ((startChan != endChan) && colType <= GetColTypeFromCursor(m_dwEndSel)) + { chans.Add(endChan); //last selected chan includes this col type } Modified: trunk/OpenMPT/mptrack/misc_util.h =================================================================== --- trunk/OpenMPT/mptrack/misc_util.h 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/misc_util.h 2011-08-31 18:00:14 UTC (rev 1003) @@ -1,5 +1,6 @@ #ifndef MISC_UTIL_H #define MISC_UTIL_H +#pragma once #include <sstream> #include <string> @@ -41,17 +42,30 @@ // Memset given object to zero. template <class T> -inline void MemsetZero(T& a) -//_------------------------- +inline void MemsetZero(T &a) +//-------------------------- { - #if _HAS_TR1 - static_assert(std::tr1::is_pointer<T>::value == false, "Won't memset pointers."); - static_assert(std::tr1::is_pod<T>::value == true, "Won't memset non-pods."); - #endif +#if _HAS_TR1 + static_assert(std::tr1::is_pointer<T>::value == false, "Won't memset pointers."); + static_assert(std::tr1::is_pod<T>::value == true, "Won't memset non-pods."); +#endif memset(&a, 0, sizeof(T)); } +// Copy given object to other location. +template <class T> +inline void MemCopy(T &destination, T &source) +//-------------------------------------------- +{ +#if _HAS_TR1 + static_assert(std::tr1::is_pointer<T>::value == false, "Won't copy pointers."); + static_assert(std::tr1::is_pod<T>::value == true, "Won't copy non-pods."); +#endif + memcpy(&destination, &source, sizeof(T)); +} + + // Limits 'val' to given range. If 'val' is less than 'lowerLimit', 'val' is set to value 'lowerLimit'. // Similarly if 'val' is greater than 'upperLimit', 'val' is set to value 'upperLimit'. // If 'lowerLimit' > 'upperLimit', 'val' won't be modified. @@ -65,6 +79,18 @@ } +// Like Limit, but returns value +template<class T, class C> +inline T Clamp(T val, const C lowerLimit, const C upperLimit) +//----------------------------------------------------------- +{ + if(lowerLimit > upperLimit) return val; + if(val < lowerLimit) return lowerLimit; + else if(val > upperLimit) return upperLimit; + else return val; +} + + // Like Limit, but with upperlimit only. template<class T, class C> inline void LimitMax(T& val, const C upperLimit) @@ -151,7 +177,7 @@ template <class T> inline const T& Min(const T& a, const T& b) {return (std::min)(a, b);} // Returns maximum value of given integer type. - template <class T> inline T MaxValueOfType(const T&) {static_assert(std::numeric_limits<T>::is_integer == true, "Only interger types are allowed."); return (std::numeric_limits<T>::max)();} + template <class T> inline T MaxValueOfType(const T&) {static_assert(std::numeric_limits<T>::is_integer == true, "Only integer types are allowed."); return (std::numeric_limits<T>::max)();} /// Returns value rounded to nearest integer. inline double Round(const double& val) {return std::floor(val + 0.5);} Modified: trunk/OpenMPT/mptrack/version.h =================================================================== --- trunk/OpenMPT/mptrack/version.h 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/mptrack/version.h 2011-08-31 18:00:14 UTC (rev 1003) @@ -15,7 +15,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 20 #define VER_MINOR 00 -#define VER_MINORMINOR 13 +#define VER_MINORMINOR 14 //Creates version number from version parts that appears in version string. //For example MAKE_VERSION_NUMERIC(1,17,02,28) gives version number of Modified: trunk/OpenMPT/soundlib/pattern.cpp =================================================================== --- trunk/OpenMPT/soundlib/pattern.cpp 2011-08-31 17:51:46 UTC (rev 1002) +++ trunk/OpenMPT/soundlib/pattern.cpp 2011-08-31 18:00:14 UTC (rev 1003) @@ -252,9 +252,15 @@ MODCOMMAND *CPattern::AllocatePattern(ROWINDEX rows, CHANNELINDEX nchns) //---------------------------------------------------------------------- { - MODCOMMAND *p = new MODCOMMAND[rows*nchns]; - if (p) memset(p, 0, rows*nchns*sizeof(MODCOMMAND)); - return p; + try + { + MODCOMMAND *p = new MODCOMMAND[rows*nchns]; + memset(p, 0, rows * nchns * sizeof(MODCOMMAND)); + return p; + } catch (...) + { + return nullptr; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |