From: <sag...@us...> - 2011-02-14 18:33:23
|
Revision: 799 http://modplug.svn.sourceforge.net/modplug/?rev=799&view=rev Author: saga-games Date: 2011-02-14 18:33:16 +0000 (Mon, 14 Feb 2011) Log Message: ----------- [Mod] Pattern Editor: When removing a channel (via context menu) that contains no data in any pattern, no warning is shown anymore. [Ref] Added IsChannelUnued() to CModDoc, refactored CheckUnusedChannels(). Modified Paths: -------------- trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/Modedit.cpp trunk/OpenMPT/mptrack/View_pat.cpp Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2011-02-12 20:40:27 UTC (rev 798) +++ trunk/OpenMPT/mptrack/Moddoc.h 2011-02-14 18:33:16 UTC (rev 799) @@ -340,6 +340,9 @@ // [in] bIncludeIndex: True to include instrument index in front of the instrument name, false otherwise. CString GetPatternViewInstrumentName(UINT nInstr, bool bEmptyInsteadOfNoName = false, bool bIncludeIndex = true) const; + // Check if a given channel contains data. + bool IsChannelUnused(CHANNELINDEX nChn) const; + // protected members protected: CSize m_szOldPatternScrollbarsPos; @@ -347,7 +350,7 @@ BOOL InitializeMod(); void* GetChildFrame(); //rewbs.customKeys - void CheckUnusedChannels(bool mask[MAX_BASECHANNELS], CHANNELINDEX maxRemoveCount = MAX_BASECHANNELS); + void CheckUnusedChannels(bool mask[MAX_BASECHANNELS], CHANNELINDEX maxRemoveCount = MAX_BASECHANNELS) const; // Overrides // ClassWizard generated virtual function overrides Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2011-02-12 20:40:27 UTC (rev 798) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2011-02-14 18:33:16 UTC (rev 799) @@ -197,7 +197,7 @@ { MODCOMMAND::INSTR instr = m.instr, newinstr = 0; MODCOMMAND::NOTE note = m.note, newnote = note; - if((note) && (note <= NOTE_MAX)) + if((note >= NOTE_MIN) && (note <= NOTE_MAX)) note--; else note = NOTE_MIDDLEC - 1; @@ -1231,33 +1231,48 @@ } -void CModDoc::CheckUnusedChannels(bool mask[MAX_BASECHANNELS], CHANNELINDEX maxRemoveCount) -//------------------------------------------------------------------------------------- +// Check which channels contain note data. maxRemoveCount specified how many empty channels are reported at max. +void CModDoc::CheckUnusedChannels(bool mask[MAX_BASECHANNELS], CHANNELINDEX maxRemoveCount) const +//----------------------------------------------------------------------------------------------- { // Checking for unused channels const int nChannels = m_SndFile.GetNumChannels(); for(int iRst = nChannels - 1; iRst >= 0; iRst--) { - mask[iRst] = true; - for (PATTERNINDEX ipat = 0; ipat < m_SndFile.Patterns.Size(); ipat++) if (m_SndFile.Patterns.IsValidPat(ipat)) + mask[iRst] = IsChannelUnused(iRst); + if(mask[iRst]) { - MODCOMMAND *p = m_SndFile.Patterns[ipat] + iRst; - UINT len = m_SndFile.Patterns[ipat].GetNumRows(); - for (UINT idata = 0; idata < len; idata++, p += m_SndFile.m_nChannels) + // Found enough empty channels yet? + if((--maxRemoveCount) == 0) break; + } + } +} + + +// Check if a given channel contains note data. +bool CModDoc::IsChannelUnused(CHANNELINDEX nChn) const +//---------------------------------------------------- +{ + const CHANNELINDEX nChannels = m_SndFile.GetNumChannels(); + if(nChn >= nChannels) + { + return true; + } + for(PATTERNINDEX nPat = 0; nPat < m_SndFile.Patterns.Size(); nPat++) + { + if(m_SndFile.Patterns.IsValidPat(nPat)) + { + const MODCOMMAND *p = m_SndFile.Patterns[nPat] + nChn; + for(ROWINDEX nRow = m_SndFile.Patterns[nPat].GetNumRows(); nRow > 0; nRow--, p += nChannels) { - if (!p->IsEmpty()) + if(!p->IsEmpty()) { - mask[iRst] = false; - break; + return false; } } - if (!mask[iRst]) break; } - if (mask[iRst]) - { - if ((--maxRemoveCount) == 0) break; - } } + return true; } Modified: trunk/OpenMPT/mptrack/View_pat.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_pat.cpp 2011-02-12 20:40:27 UTC (rev 798) +++ trunk/OpenMPT/mptrack/View_pat.cpp 2011-02-14 18:33:16 UTC (rev 799) @@ -2583,7 +2583,7 @@ { CModDoc *pModDoc = GetDocument(); CSoundFile* pSndFile; - if (pModDoc == 0 || (pSndFile = pModDoc->GetSoundFile()) == 0) return; + if (pModDoc == nullptr || (pSndFile = pModDoc->GetSoundFile()) == nullptr) return; if(pSndFile->m_nChannels <= pSndFile->GetModSpecifications().channelsMin) { @@ -2592,9 +2592,11 @@ } CHANNELINDEX nChn = GetChanFromCursor(m_nMenuParam); + const bool isEmpty = pModDoc->IsChannelUnused(nChn); + CString str; - str.Format("Remove channel %d?\nNote: Affects all patterns and no undo", nChn+1); - if(CMainFrame::GetMainFrame()->MessageBox(str , "Remove channel", MB_YESNO | MB_ICONQUESTION) == IDYES) + str.Format("Remove channel %d? This channel still contains note data!\nNote: Operation affects all patterns and has no undo", nChn + 1); + if(isEmpty || CMainFrame::GetMainFrame()->MessageBox(str , "Remove channel", MB_YESNO | MB_ICONQUESTION) == IDYES) { bool chnMask[MAX_BASECHANNELS]; for(CHANNELINDEX i = 0; i < MAX_BASECHANNELS; i++) {chnMask[i] = false;} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |