From: <sag...@us...> - 2010-09-07 16:13:16
|
Revision: 702 http://modplug.svn.sourceforge.net/modplug/?rev=702&view=rev Author: saga-games Date: 2010-09-07 16:13:10 +0000 (Tue, 07 Sep 2010) Log Message: ----------- [Imp] Mod Conversion: When converting patterns from a format with instruments to a format without instruments (or when removing all instruments using the cleanup dialog), the instrument note mapping is now also taken care of. [Ref] Refactored the instrument->sample pattern conversion code using ForEachModCommand. Modified Paths: -------------- trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/Modedit.cpp Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2010-09-07 14:37:26 UTC (rev 701) +++ trunk/OpenMPT/mptrack/Moddoc.h 2010-09-07 16:13:10 UTC (rev 702) @@ -221,7 +221,7 @@ bool ChangeModType(MODTYPE wType); bool ChangeNumChannels(UINT nNewChannels, const bool showCancelInRemoveDlg = true); - BOOL ConvertInstrumentsToSamples(); + bool ConvertInstrumentsToSamples(); UINT RemovePlugs(const bool (&keepMask)[MAX_MIXPLUGINS]); PATTERNINDEX InsertPattern(ORDERINDEX nOrd = ORDERINDEX_INVALID, ROWINDEX nRows = 64); Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2010-09-07 14:37:26 UTC (rev 701) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2010-09-07 16:13:10 UTC (rev 702) @@ -182,29 +182,49 @@ } -BOOL CModDoc::ConvertInstrumentsToSamples() -//----------------------------------------- +// Functor for converting instrument numbers to sample numbers in the patterns +struct ConvertInstrumentsToSamplesInPatterns +//========================================== { - if (!m_SndFile.m_nInstruments) return FALSE; - for (UINT i=0; i<m_SndFile.Patterns.Size(); i++) if (m_SndFile.Patterns[i]) + ConvertInstrumentsToSamplesInPatterns(CSoundFile *pSndFile) { - MODCOMMAND *p = m_SndFile.Patterns[i]; - for (UINT j=m_SndFile.m_nChannels*m_SndFile.Patterns[i].GetNumRows(); j; j--, p++) if (p->instr) + this->pSndFile = pSndFile; + } + + void operator()(MODCOMMAND& m) + { + if(m.instr) { - UINT instr = p->instr; - UINT note = p->note; - UINT newins = 0; - if ((note) && (note < 128)) note--; else note = 5*12; - if ((instr < MAX_INSTRUMENTS) && (m_SndFile.Instruments[instr])) + MODCOMMAND::INSTR instr = m.instr, newinstr = 0; + MODCOMMAND::NOTE note = m.note, newnote = note; + if((note) && (note <= NOTE_MAX)) + note--; + else + note = NOTE_MIDDLEC - 1; + + if((instr < MAX_INSTRUMENTS) && (pSndFile->Instruments[instr])) { - MODINSTRUMENT *pIns = m_SndFile.Instruments[instr]; - newins = pIns->Keyboard[note]; - if (newins >= MAX_SAMPLES) newins = 0; + const MODINSTRUMENT *pIns = pSndFile->Instruments[instr]; + newinstr = pIns->Keyboard[note]; + newnote = pIns->NoteMap[note]; + if(newinstr >= MAX_SAMPLES) newinstr = 0; } - p->instr = newins; + m.instr = newinstr; + m.note = newnote; } } - return TRUE; + + CSoundFile *pSndFile; +}; + + +bool CModDoc::ConvertInstrumentsToSamples() +//----------------------------------------- +{ + if (!m_SndFile.GetNumInstruments()) + return false; + m_SndFile.Patterns.ForEachModCommand(ConvertInstrumentsToSamplesInPatterns(&m_SndFile)); + return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |