From: <rel...@us...> - 2009-11-02 21:54:46
|
Revision: 410 http://modplug.svn.sourceforge.net/modplug/?rev=410&view=rev Author: relabsoluness Date: 2009-11-02 21:54:36 +0000 (Mon, 02 Nov 2009) Log Message: ----------- [Fix] Instrument tab: OnMouseMove could cause a crash when moving cursor on Pitch/Filter envelope when not having any instruments. [Ref] Changes to param control note update done on reordering plugs (see rev. 407) [Ref] Minor tweaking (cleaned compiler warnings etc.). Modified Paths: -------------- trunk/OpenMPT/mptrack/Childfrm.h trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/View_gen.cpp trunk/OpenMPT/mptrack/View_gen.h trunk/OpenMPT/mptrack/View_ins.cpp trunk/OpenMPT/mptrack/View_ins.h trunk/OpenMPT/soundlib/ModSequence.h trunk/OpenMPT/soundlib/modcommand.h trunk/OpenMPT/soundlib/patternContainer.h Modified: trunk/OpenMPT/mptrack/Childfrm.h =================================================================== --- trunk/OpenMPT/mptrack/Childfrm.h 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/mptrack/Childfrm.h 2009-11-02 21:54:36 UTC (rev 410) @@ -17,7 +17,7 @@ typedef struct _GENERALVIEWSTATE { DWORD cbStruct; - DWORD nPlugin; + PLUGINDEX nPlugin; DWORD nParam; DWORD nTab; } GENERALVIEWSTATE; Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2009-11-02 21:54:36 UTC (rev 410) @@ -151,7 +151,7 @@ m_SndFile.m_nMixLevels = m_SndFile.GetModSpecifications().defaultMixLevels; m_SndFile.m_pConfig->SetMixLevels(m_SndFile.m_nMixLevels); // ...and the order length - m_SndFile.Order.resize(m_SndFile.GetModSpecifications().ordersMax); + m_SndFile.Order.resize(min(ModSequenceSet::s_nCacheSize, m_SndFile.GetModSpecifications().ordersMax)); theApp.GetDefaultMidiMacro(&m_SndFile.m_MidiCfg); ReinitRecordState(); @@ -281,7 +281,7 @@ if (f.Open(pszMidiMapName, CFile::modeRead)) { - DWORD len = f.GetLength(); + DWORD len = static_cast<DWORD>(f.GetLength()); LPBYTE lpFile; if ((len) && ((lpFile = (LPBYTE)GlobalAllocPtr(GHND, len)) != NULL)) { @@ -831,7 +831,7 @@ pChn->nResonance = 0; pChn->nVolume = 256; pChn->nMasterChn = 0; //remove NNA association - pChn->nNewNote = note; + pChn->nNewNote = static_cast<BYTE>(note); if (nins) { //Set instrument m_SndFile.resetEnvelopes(pChn); @@ -1043,7 +1043,7 @@ //mute any NNA'd channels for (UINT i=m_SndFile.m_nChannels; i<MAX_CHANNELS; i++) { - if (m_SndFile.Chn[i].nMasterChn == nChn+1) { + if (m_SndFile.Chn[i].nMasterChn == nChn + 1u) { if (doMute) { m_SndFile.Chn[i].dwFlags |= muteType; } else { @@ -1432,7 +1432,7 @@ } CDoWaveConvert dwcdlg(&m_SndFile, s, &wsdlg.WaveFormat.Format, wsdlg.m_bNormalize, pMainFrm); - dwcdlg.m_dwFileLimit = wsdlg.m_dwFileLimit; + dwcdlg.m_dwFileLimit = static_cast<DWORD>(wsdlg.m_dwFileLimit); dwcdlg.m_bGivePlugsIdleTime = wsdlg.m_bGivePlugsIdleTime; dwcdlg.m_dwSongLimit = wsdlg.m_dwSongLimit; dwcdlg.m_nMaxPatterns = (wsdlg.m_bSelectPlay) ? wsdlg.m_nMaxOrder - wsdlg.m_nMinOrder + 1 : 0; @@ -2220,7 +2220,7 @@ } } if (gFXInfo[ndx].dwFlags) { - if (refParam > gFXInfo[ndx].dwFlags) { + if (refParam > static_cast<int>(gFXInfo[ndx].dwFlags)) { refParam = gFXInfo[ndx].dwFlags; //used for Zxx macro control: limit to 7F max. } } @@ -2852,6 +2852,7 @@ //rewbs.customKeys void* CModDoc::GetChildFrame() +//---------------------------- { CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); if (!pMainFrm) return 0; Modified: trunk/OpenMPT/mptrack/View_gen.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_gen.cpp 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/mptrack/View_gen.cpp 2009-11-02 21:54:36 UTC (rev 410) @@ -823,7 +823,7 @@ if ((nfx >= 0) && (nfx <= MAX_MIXPLUGINS) && (nChn < pSndFile->m_nChannels) && (pSndFile->ChnSettings[nChn].nMixPlugin != (UINT)nfx)) { - pSndFile->ChnSettings[nChn].nMixPlugin = nfx; + pSndFile->ChnSettings[nChn].nMixPlugin = (PLUGINDEX)nfx; if (pSndFile->m_nType & (MOD_TYPE_XM|MOD_TYPE_IT|MOD_TYPE_MPT)) pModDoc->SetModified(); pModDoc->UpdateAllViews(this, HINT_MODCHANNELS | (m_nActiveTab << HINT_SHIFT_CHNTAB)); } @@ -898,7 +898,7 @@ int nPlugin = m_CbnPlugin.GetCurSel(); if ((pModDoc) && (nPlugin >= 0) && (nPlugin < MAX_MIXPLUGINS)) { - m_nCurrentPlugin = nPlugin; + m_nCurrentPlugin = (PLUGINDEX)nPlugin; pModDoc->UpdateAllViews(NULL, HINT_MIXPLUGINS | HINT_MODCHANNELS | (m_nActiveTab << HINT_SHIFT_CHNTAB)); } // -> CODE#0002 @@ -1314,12 +1314,35 @@ } -bool CViewGlobals::MovePlug(PLUGINDEX src, PLUGINDEX dest) -//-------------------------------------------------------- + +// Functor for adjusting plug indexes in modcommands. Adjusts all instrument column values in +// range [m_nInstrMin, m_nInstrMax] by m_nDiff. +struct PlugIndexModifier +//====================== { + PlugIndexModifier(PLUGINDEX nMin, PLUGINDEX nMax, int nDiff) : + m_nInstrMin(nMin), m_nInstrMax(nMax), m_nDiff(nDiff) {} + void operator()(MODCOMMAND& m) + { + if (m.IsInstrPlug() && m.instr >= m_nInstrMin && m.instr <= m_nInstrMax) + m.instr = (MODCOMMAND::INSTR)((int)m.instr + m_nDiff); + } + int m_nDiff; + MODCOMMAND::INSTR m_nInstrMin; + MODCOMMAND::INSTR m_nInstrMax; +}; + + +bool CViewGlobals::MovePlug(PLUGINDEX src, PLUGINDEX dest, bool bAdjustPat) +//------------------------------------------------------------------------- +{ + if (src == dest) + return false; //AfxMessageBox("Moving %d to %d", src, dest); CModDoc *pModDoc = GetDocument(); CSoundFile* pSndFile = pModDoc->GetSoundFile(); + + BeginWaitCursor(); BEGIN_CRITICAL(); @@ -1363,24 +1386,20 @@ } } - // Update patterns (param control notes) - for (PATTERNINDEX nPat = 0; nPat < pSndFile->Patterns.Size(); nPat++) if (pSndFile->Patterns[nPat]) - { - MODCOMMAND *m = pSndFile->Patterns[nPat]; - for (UINT len = pSndFile->PatternSize[nPat] * pSndFile->m_nChannels; len; m++, len--) - { - if((m->note == NOTE_PC || m->note == NOTE_PCS) && m->instr == src + 1) - m->instr = dest + 1; - } - } + // Update MODCOMMANDs so that they won't be referring to old indexes (e.g. with NOTE_PC). + if (bAdjustPat && pSndFile->GetType() == MOD_TYPE_MPT) + pSndFile->Patterns.ForEachModCommand(PlugIndexModifier(src + 1, src + 1, int(dest) - int(src))); END_CRITICAL(); pModDoc->SetModified(); + EndWaitCursor(); + return true; } + void CViewGlobals::BuildEmptySlotList(CArray<UINT, UINT> &emptySlots) //------------------------------------------------------------------- { @@ -1416,9 +1435,14 @@ //possible mem leak here... } - for (PLUGINDEX nSlot = MAX_MIXPLUGINS-1; nSlot > (PLUGINDEX)m_nCurrentPlugin; nSlot--) { + // Update MODCOMMANDs so that they won't be referring to old indexes (e.g. with NOTE_PC). + if (pSndFile->GetType() == MOD_TYPE_MPT) + pSndFile->Patterns.ForEachModCommand(PlugIndexModifier(m_nCurrentPlugin + 1, MAX_MIXPLUGINS - 1, 1)); + + + for (PLUGINDEX nSlot = MAX_MIXPLUGINS-1; nSlot > m_nCurrentPlugin; nSlot--) { if (pSndFile->m_MixPlugins[nSlot-1].pMixPlugin) { - MovePlug(nSlot-1, nSlot); + MovePlug(nSlot-1, nSlot, NoPatternAdjust); } } Modified: trunk/OpenMPT/mptrack/View_gen.h =================================================================== --- trunk/OpenMPT/mptrack/View_gen.h 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/mptrack/View_gen.h 2009-11-02 21:54:36 UTC (rev 410) @@ -42,6 +42,8 @@ CSpinButtonCtrl m_SpinMixGain; // update#02 // -! NEW_FEATURE#0028 + enum {AdjustPattern = true, NoPatternAdjust = false}; + protected: CViewGlobals():CFormView(IDD_VIEW_GLOBALS) { m_nLockCount = 1; } DECLARE_SERIAL(CViewGlobals) @@ -57,7 +59,7 @@ BOOL IsLocked() const { return (m_nLockCount > 0); } int GetDlgItemIntEx(UINT nID); void BuildEmptySlotList(CArray<UINT, UINT> &emptySlots); - bool MovePlug(PLUGINDEX src, PLUGINDEX dest); + bool MovePlug(PLUGINDEX src, PLUGINDEX dest, bool bAdjustPat = AdjustPattern); public: //{{AFX_VIRTUAL(CViewGlobals) Modified: trunk/OpenMPT/mptrack/View_ins.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_ins.cpp 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/mptrack/View_ins.cpp 2009-11-02 21:54:36 UTC (rev 410) @@ -110,7 +110,7 @@ memset(m_NcButtonState, 0, sizeof(m_NcButtonState)); m_bmpEnvBar.Create(IDB_ENVTOOLBAR, 20, 0, RGB(192,192,192)); memset(m_baPlayingNote, 0, sizeof(bool)*NOTE_MAX); //rewbs.customKeys - m_nPlayingChannel =-1; //rewbs.customKeys + m_nPlayingChannel = UINT_MAX; //rewbs.customKeys //rewbs.envRowGrid m_bGrid=true; m_bGridForceRedraw=false; @@ -152,8 +152,8 @@ } -BOOL CViewInstrument::SetCurrentInstrument(UINT nIns, UINT nEnv) -//-------------------------------------------------------------- +BOOL CViewInstrument::SetCurrentInstrument(INSTRUMENTINDEX nIns, UINT nEnv) +//------------------------------------------------------------------------- { CModDoc *pModDoc = GetDocument(); DWORD dwNotify; @@ -1042,7 +1042,7 @@ } - if (windowResized || m_bGridForceRedraw || (cachedScrollPos != m_GridScrollPos) || (speed != m_GridSpeed)) { + if (windowResized || m_bGridForceRedraw || (cachedScrollPos != m_GridScrollPos) || (speed != (UINT)m_GridSpeed)) { m_GridSpeed = speed; m_GridScrollPos = cachedScrollPos; @@ -1161,7 +1161,7 @@ { maxpoint--; m_dcMemMain.SelectObject(CMainFrame::penEnvelope); - int releaseNode = EnvGetReleaseNode(); + UINT releaseNode = EnvGetReleaseNode(); for (UINT i=0; i<=maxpoint; i++) { int x = (EnvGetTick(i) + 1) * ENV_ZOOM - nScrollPos; @@ -1175,7 +1175,7 @@ } else { m_dcMemMain.MoveTo(x, y); } - if (i==releaseNode) { + if (i == releaseNode) { m_dcMemMain.FrameRect(&rect, CBrush::FromHandle(CMainFrame::brushHighLightRed)); m_dcMemMain.SelectObject(CMainFrame::penEnvelopeHighlight); } else { @@ -1371,7 +1371,7 @@ break; } memset(m_baPlayingNote, 0, sizeof(bool)*NOTE_MAX); //rewbs.instViewNNA - m_nPlayingChannel=-1; //rewbs.instViewNNA + m_nPlayingChannel = UINT_MAX; //rewbs.instViewNNA } } else if ((pnotify->dwType & dwType) && ((pnotify->dwType & 0xFFFF) == m_nInstrument)) @@ -1639,6 +1639,7 @@ CSoundFile *pSndFile = pModDoc->GetSoundFile(); if(pSndFile == nullptr) return; MODINSTRUMENT *pIns = pSndFile->Instruments[m_nInstrument]; + if (pIns == nullptr) return; BOOL bSplitCursor = FALSE; CHAR s[256]; @@ -1991,7 +1992,7 @@ void CViewInstrument::OnEnvToggleReleasNode() //--------------------------------------------------- { - int node = m_nDragItem-1; + UINT node = m_nDragItem-1; CModDoc *pModDoc = GetDocument(); if ((pModDoc) && (node>0) && (node <= EnvGetLastPoint())) @@ -2002,7 +2003,7 @@ if (envelope->nReleaseNode == node) { envelope->nReleaseNode = ENV_RELEASE_NODE_UNSET; } else { - envelope->nReleaseNode = node; + envelope->nReleaseNode = static_cast<BYTE>(node); } pModDoc->SetModified(); @@ -2137,11 +2138,11 @@ MODINSTRUMENT *pIns = pModDoc->GetSoundFile()->Instruments[m_nInstrument]; if ((!pIns) || (!pIns->Keyboard[note-1] && !pIns->nMixPlug)) return; m_baPlayingNote[note] = true; //rewbs.instViewNNA - m_nPlayingChannel= pModDoc->PlayNote(note, m_nInstrument, 0, FALSE); //rewbs.instViewNNA + m_nPlayingChannel = pModDoc->PlayNote(note, m_nInstrument, 0, FALSE); //rewbs.instViewNNA s[0] = 0; if ((note) && (note <= NOTE_MAX)) { - const std::string temp = pModDoc->GetSoundFile()->GetNoteName(note, m_nInstrument); + const std::string temp = pModDoc->GetSoundFile()->GetNoteName(static_cast<int16>(note), m_nInstrument); if(temp.size() >= sizeofS) wsprintf(s, "%s", "..."); else Modified: trunk/OpenMPT/mptrack/View_ins.h =================================================================== --- trunk/OpenMPT/mptrack/View_ins.h 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/mptrack/View_ins.h 2009-11-02 21:54:36 UTC (rev 410) @@ -41,7 +41,7 @@ public: void UpdateScrollSize(); - BOOL SetCurrentInstrument(UINT nIns, UINT m_nEnv=0); + BOOL SetCurrentInstrument(INSTRUMENTINDEX nIns, UINT m_nEnv=0); INSTRUMENTENVELOPE *GetEnvelopePtr() const; UINT EnvGetTick(int nPoint) const; UINT EnvGetValue(int nPoint) const; Modified: trunk/OpenMPT/soundlib/ModSequence.h =================================================================== --- trunk/OpenMPT/soundlib/ModSequence.h 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/soundlib/ModSequence.h 2009-11-02 21:54:36 UTC (rev 410) @@ -140,13 +140,12 @@ ModSequenceSet& operator=(const ModSequence& seq) {ModSequence::operator=(seq); return *this;} + static const ORDERINDEX s_nCacheSize = MAX_ORDERS; private: void CopyCacheToStorage(); void CopyStorageToCache(); - static const ORDERINDEX s_nCacheSize = MAX_ORDERS; - PATTERNINDEX m_Cache[s_nCacheSize]; // Local cache array. std::vector<ModSequence> m_Sequences; // Array of sequences. SEQUENCEINDEX m_nCurrentSeq; // Index of current sequence. Modified: trunk/OpenMPT/soundlib/modcommand.h =================================================================== --- trunk/OpenMPT/soundlib/modcommand.h 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/soundlib/modcommand.h 2009-11-02 21:54:36 UTC (rev 410) @@ -2,6 +2,19 @@ #define MODCOMMAND_H +// Note definitions +#define NOTE_NONE 0 +#define NOTE_MIDDLEC (5*12+1) +#define NOTE_KEYOFF 0xFF //255 +#define NOTE_NOTECUT 0xFE //254 +#define NOTE_FADE 0xFD //253, IT's action for illegal notes - DO NOT SAVE AS 253 as this is IT's internal representation of "no note"! +#define NOTE_PC 0xFC //252, Param Control 'note'. Changes param value on first tick. +#define NOTE_PCS 0xFB //251, Param Control(Smooth) 'note'. Changes param value during the whole row. +#define NOTE_MAX 120 //Defines maximum notevalue(with index starting from 1) as well as maximum number of notes. +#define NOTE_MAX_SPECIAL NOTE_KEYOFF +#define NOTE_MIN_SPECIAL NOTE_PCS + + //============== class MODCOMMAND //============== @@ -21,16 +34,9 @@ // Returns empty modcommand. static MODCOMMAND Empty() {MODCOMMAND m = {0,0,0,0,0,0}; return m;} - inline bool operator==(const MODCOMMAND& mc) const - { - return (memcmp(this, &mc, sizeof(MODCOMMAND)) == 0); - } + bool operator==(const MODCOMMAND& mc) const { return (memcmp(this, &mc, sizeof(MODCOMMAND)) == 0); } + bool operator!=(const MODCOMMAND& mc) const { return !(*this == mc); } - inline bool operator !=(const MODCOMMAND& mc) const - { - return !(*this == mc); - } - void Set(NOTE n, INSTR ins, uint16 volcol, uint16 effectcol) {note = n; instr = ins; SetValueVolCol(volcol); SetValueEffectCol(effectcol);} uint16 GetValueVolCol() const {return GetValueVolCol(volcmd, vol);} @@ -45,8 +51,11 @@ void Clear() {memset(this, 0, sizeof(MODCOMMAND));} // Returns true if modcommand is empty, false otherwise. - inline bool MODCOMMAND::IsEmpty() const {return (*this == Empty());} + bool IsEmpty() const {return (*this == Empty());} + // Returns true if instrument column represents plugin index. + bool IsInstrPlug() const {return note == NOTE_PC || note == NOTE_PCS;} + public: BYTE note; BYTE instr; @@ -60,19 +69,6 @@ typedef MODCOMMAND MODCOMMAND_ORIGINAL; -// Note definitions -#define NOTE_NONE 0 -#define NOTE_MIDDLEC (5*12+1) -#define NOTE_KEYOFF 0xFF //255 -#define NOTE_NOTECUT 0xFE //254 -#define NOTE_FADE 0xFD //253, IT's action for illegal notes - DO NOT SAVE AS 253 as this is IT's internal representation of "no note"! -#define NOTE_PC 0xFC //252, Param Control 'note'. Changes param value on first tick. -#define NOTE_PCS 0xFB //251, Param Control(Smooth) 'note'. Changes param value during the whole row. -#define NOTE_MAX 120 //Defines maximum notevalue(with index starting from 1) as well as maximum number of notes. -#define NOTE_MAX_SPECIAL NOTE_KEYOFF -#define NOTE_MIN_SPECIAL NOTE_PCS - - // Volume Column commands #define VOLCMD_NONE 0 #define VOLCMD_VOLUME 1 Modified: trunk/OpenMPT/soundlib/patternContainer.h =================================================================== --- trunk/OpenMPT/soundlib/patternContainer.h 2009-11-01 16:27:14 UTC (rev 409) +++ trunk/OpenMPT/soundlib/patternContainer.h 2009-11-02 21:54:36 UTC (rev 410) @@ -46,6 +46,13 @@ //'invisible' - the pattern data is cleared but the actual pattern object won't get removed. bool Remove(const PATTERNINDEX index); + // Applies function object for modcommands in patterns in given range. + // Return: Copy of the function object. + template <class Func> + Func ForEachModCommand(PATTERNINDEX nStartPat, PATTERNINDEX nLastPat, Func func); + template <class Func> + Func ForEachModCommand(Func func) {return ForEachModCommand(0, Size() - 1, func);} + PATTERNINDEX Size() const {return static_cast<PATTERNINDEX>(m_Patterns.size());} CSoundFile& GetSoundFile() {return m_rSndFile;} @@ -76,6 +83,18 @@ }; +template <class Func> +Func CPatternContainer::ForEachModCommand(PATTERNINDEX nStartPat, PATTERNINDEX nLastPat, Func func) +//------------------------------------------------------------------------------------------------- +{ + if (nStartPat > nLastPat || nLastPat >= Size()) + return func; + for (PATTERNINDEX nPat = nStartPat; nPat <= nLastPat; nPat++) if (m_Patterns[nPat]) + std::for_each(m_Patterns[nPat].Begin(), m_Patterns[nPat].End(), func); + return func; +} + + const char FileIdPatterns[] = "mptPc"; void ReadModPatterns(std::istream& iStrm, CPatternContainer& patc, const size_t nSize = 0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |