From: <sag...@us...> - 2014-02-22 17:49:33
|
Revision: 3751 http://sourceforge.net/p/modplug/code/3751 Author: saga-games Date: 2014-02-22 17:49:24 +0000 (Sat, 22 Feb 2014) Log Message: ----------- [Ref] Small code refactoring in CModDoc/CViewSample Modified Paths: -------------- trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/mptrack/View_smp.cpp Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2014-02-22 16:47:31 UTC (rev 3750) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2014-02-22 17:49:24 UTC (rev 3751) @@ -1883,7 +1883,7 @@ " - Ogg Vorbis libraries\n" " - libmp3lame.dll or Lame_Enc.dll\n" "into OpenMPT's root directory.\n" - "Alternatively, you can install a MP3 ACM codec.", + "Alternatively, you can install an MP3 ACM codec.", "OpenMPT - Export"); } OnFileWaveConvert(nMinOrder, nMaxOrder, encoders); @@ -2033,9 +2033,9 @@ if (pMainFrm->GetModPlaying() == this) { bool isLooping = m_SndFile.m_SongFlags[SONG_PATTERNLOOP]; - UINT nPat = m_SndFile.m_nPattern; - UINT nRow = m_SndFile.m_nRow; - UINT nNextRow = m_SndFile.m_nNextRow; + PATTERNINDEX nPat = m_SndFile.m_nPattern; + ROWINDEX nRow = m_SndFile.m_nRow; + ROWINDEX nNextRow = m_SndFile.m_nNextRow; pMainFrm->PauseMod(); if ((isLooping) && (nPat < m_SndFile.Patterns.Size())) @@ -2258,17 +2258,17 @@ { case tempo_mode_alternative: Message.Format("Using alternative tempo interpretation.\n\nAssuming:\n. %d ticks per second\n. %d ticks per row\n. %d rows per beat\nthe tempo is approximately: %.8g BPM", - m_SndFile.m_nMusicTempo, m_SndFile.m_nMusicSpeed, m_SndFile.m_nCurrentRowsPerBeat, bpm); + m_SndFile.m_nMusicTempo, m_SndFile.m_nMusicSpeed, m_SndFile.m_nCurrentRowsPerBeat, bpm); break; case tempo_mode_modern: - Message.Format("Using modern tempo interpretation.\n\nThe tempo is: %.8g BPM", bpm); + Message.Format("Using modern tempo interpretation.\n\nThe tempo is: %.8g BPM", bpm); break; case tempo_mode_classic: default: Message.Format("Using standard tempo interpretation.\n\nAssuming:\n. A mod tempo (tick duration factor) of %d\n. %d ticks per row\n. %d rows per beat\nthe tempo is approximately: %.8g BPM", - m_SndFile.m_nMusicTempo, m_SndFile.m_nMusicSpeed, m_SndFile.m_nCurrentRowsPerBeat, bpm); + m_SndFile.m_nMusicTempo, m_SndFile.m_nMusicSpeed, m_SndFile.m_nCurrentRowsPerBeat, bpm); break; } @@ -2314,7 +2314,7 @@ pat = patternViewState.nPattern; row = patternViewState.cursor.GetRow(); - ord = patternViewState.nOrder; + ord = patternViewState.nOrder; } else { //patern editor object does not exist (i.e. is not active) - use saved state. @@ -2333,11 +2333,11 @@ } if(pat >= m_SndFile.Patterns.Size()) { - pat=0; + pat = 0; } if(row >= m_SndFile.Patterns[pat].GetNumRows()) { - row=0; + row = 0; } //ensure order correlates with pattern. @@ -2350,7 +2350,6 @@ } } - return followSonghWnd; } @@ -2624,9 +2623,7 @@ mpt::PathString fext; GetPathNameMpt().SplitPath(&drive, &dir, &fname, &fext); - mpt::PathString newPath; - newPath += drive; - newPath += dir; + mpt::PathString newPath = drive + dir; //Catch case where we don't have a filename yet. if(fname.empty()) @@ -2637,14 +2634,12 @@ newPath += fname; } - switch(nNewType) + if(nNewType == MOD_TYPE_IT) { - case MOD_TYPE_XM: newPath += MPT_PATHSTRING(".xm"); break; - case MOD_TYPE_IT: newPath += m_SndFile.m_SongFlags[SONG_ITPROJECT] ? MPT_PATHSTRING(".itp") : MPT_PATHSTRING(".it"); break; - case MOD_TYPE_MPT: newPath += MPT_PATHSTRING(".mptm"); break; - case MOD_TYPE_S3M: newPath += MPT_PATHSTRING(".s3m"); break; - case MOD_TYPE_MOD: newPath += MPT_PATHSTRING(".mod"); break; - default: ASSERT(false); + newPath += m_SndFile.m_SongFlags[SONG_ITPROJECT] ? MPT_PATHSTRING(".itp") : MPT_PATHSTRING(".it"); + } else + { + newPath += MPT_PATHSTRING(".") + mpt::PathString::FromUTF8(CSoundFile::GetModSpecifications(nNewType).fileExtension); } if(nNewType != MOD_TYPE_IT || @@ -2654,31 +2649,29 @@ (!mpt::PathString::CompareNoCase(fext, MPT_PATHSTRING(".itp")) && !m_SndFile.m_SongFlags[SONG_ITPROJECT]) ) ) - ) + ) m_ShowSavedialog = true; //Forcing savedialog to appear after extension change - otherwise //unnotified file overwriting may occur. SetPathName(newPath, FALSE); - } UpdateAllViews(NULL, HINT_MODTYPE); } - -CHANNELINDEX CModDoc::FindAvailableChannel() -//------------------------------------------ +CHANNELINDEX CModDoc::FindAvailableChannel() const +//------------------------------------------------ { CHANNELINDEX nStoppedChannel = CHANNELINDEX_INVALID; // Search for available channel for(CHANNELINDEX j = m_SndFile.m_nChannels; j < MAX_CHANNELS; j++) { - ModChannel *p = &m_SndFile.Chn[j]; - if(!p->nLength) + const ModChannel &chn = m_SndFile.Chn[j]; + if(!chn.nLength) return j; - else if(p->dwFlags[CHN_NOTEFADE]) + else if(chn.dwFlags[CHN_NOTEFADE]) nStoppedChannel = j; } @@ -2690,14 +2683,16 @@ return m_SndFile.m_nChannels; } -void CModDoc::RecordParamChange(int plugSlot, long paramIndex) -//------------------------------------------------------ + +void CModDoc::RecordParamChange(PLUGINDEX plugSlot, PlugParamIndex paramIndex) +//---------------------------------------------------------------------------- { SendMessageToActiveViews(WM_MOD_RECORDPARAM, plugSlot, paramIndex); } -void CModDoc::LearnMacro(int macroToSet, long paramToUse) -//------------------------------------------------------- + +void CModDoc::LearnMacro(int macroToSet, PlugParamIndex paramToUse) +//----------------------------------------------------------------- { if (macroToSet < 0 || macroToSet > NUM_MACROS) { @@ -2737,6 +2732,7 @@ return; } + void CModDoc::SongProperties() //---------------------------- { @@ -2751,7 +2747,7 @@ bShowLog = true; } - CHANNELINDEX nNewChannels = CLAMP(dlg.m_nChannels, m_SndFile.GetModSpecifications().channelsMin, m_SndFile.GetModSpecifications().channelsMax); + CHANNELINDEX nNewChannels = Clamp(dlg.m_nChannels, m_SndFile.GetModSpecifications().channelsMin, m_SndFile.GetModSpecifications().channelsMax); if (nNewChannels != GetNumChannels()) { @@ -2763,7 +2759,6 @@ UpdateAllViews(NULL, HINT_PATTERNDATA | HINT_MODCHANNELS); SetModified(); - } } @@ -2828,6 +2823,7 @@ return displayName; } + void CModDoc::SafeFileClose() //--------------------------- { @@ -2853,7 +2849,7 @@ //---------------------------- { // Song title - mpt::String::FixNullString(m_SndFile.songName); + // std::string, doesn't need to be fixed. // Sample names + filenames for(SAMPLEINDEX nSmp = 1; nSmp <= m_SndFile.GetNumSamples(); nSmp++) @@ -2882,10 +2878,10 @@ m_SndFile.m_MidiCfg.Sanitize(); // Pattern names - // Those are CStrings and don't need to be fixed. + // std::string, doesn't need to be fixed. // Sequence names. - // Those are CStrings and don't need to be fixed. + // std::string, doesn't need to be fixed. } @@ -2905,7 +2901,7 @@ // Generate file name candidate. mpt::PathString sName; - for(size_t i = 0; i<1000; ++i) + for(size_t i = 0; i < 1000; ++i) { sName += MPT_PATHSTRING("newTemplate") + mpt::PathString::FromWide(StringifyW(i)); sName += MPT_PATHSTRING(".") + mpt::PathString::FromUTF8(m_SndFile.GetModSpecifications().fileExtension); Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2014-02-22 16:47:31 UTC (rev 3750) +++ trunk/OpenMPT/mptrack/Moddoc.h 2014-02-22 17:49:24 UTC (rev 3751) @@ -323,8 +323,8 @@ HWND GetEditPosition(ROWINDEX &row, PATTERNINDEX &pat, ORDERINDEX &ord); LRESULT OnCustomKeyMsg(WPARAM, LPARAM); void TogglePluginEditor(UINT m_nCurrentPlugin); - void RecordParamChange(int slot, long param); - void LearnMacro(int macro, long param); + void RecordParamChange(PLUGINDEX slot, PlugParamIndex param); + void LearnMacro(int macro, PlugParamIndex param); void SetElapsedTime(ORDERINDEX nOrd, ROWINDEX nRow); // Global settings to pattern effect conversion @@ -478,7 +478,7 @@ private: void ChangeFileExtension(MODTYPE nNewType); - CHANNELINDEX FindAvailableChannel(); + CHANNELINDEX FindAvailableChannel() const; }; ///////////////////////////////////////////////////////////////////////////// Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2014-02-22 16:47:31 UTC (rev 3750) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2014-02-22 17:49:24 UTC (rev 3751) @@ -42,7 +42,7 @@ // trimming will be done. This is the minimum value for // selection difference, so the minimum length of result // of trimming is nTrimLengthMin + 1. -#define MIN_TRIM_LENGTH 16 +#define MIN_TRIM_LENGTH 4 const UINT cLeftBarButtons[SMP_LEFTBAR_BUTTONS] = { @@ -336,8 +336,7 @@ dMin = dMax; if (nEnd < dMin) dMin = nEnd; if (nEnd > dMax) dMax = nEnd; - } else - if ((nEnd == dMax) && (dMin != nBegin)) + } else if ((nEnd == dMax) && (dMin != nBegin)) { dMax = dMin; if (nBegin < dMin) dMin = nBegin; @@ -1355,8 +1354,8 @@ // Show cursor position as offset effect if no selection is made. if(m_nSample > 0 && m_nSample <= sndFile.GetNumSamples() && x < sndFile.GetSample(m_nSample).nLength) { - const DWORD xLow = (x / 0x100) % 0x100; - const DWORD xHigh = x / 0x10000; + const SmpLength xLow = (x / 0x100) % 0x100; + const SmpLength xHigh = x / 0x10000; const char cOffsetChar = sndFile.GetModSpecifications().GetEffectLetter(CMD_OFFSET); const bool bHasHighOffset = (sndFile.TypeIsS3M_IT_MPT() || (sndFile.GetType() == MOD_TYPE_XM)); @@ -1446,14 +1445,12 @@ //------------------------------------------------- { CModDoc *pModDoc = GetDocument(); - DWORD len; if(m_dwStatus[SMPSTATUS_MOUSEDRAG] || (!pModDoc)) return; CSoundFile &sndFile = pModDoc->GetrSoundFile(); ModSample &sample = sndFile.GetSample(m_nSample); - len = sample.nLength; - if (!len) + if (!sample.nLength) return; m_dwStatus.set(SMPSTATUS_MOUSEDRAG); @@ -1470,7 +1467,7 @@ } else { m_dwBeginDrag = ScreenToSample(point.x); - if (m_dwBeginDrag >= len) m_dwBeginDrag = len-1; + if (m_dwBeginDrag >= sample.nLength) m_dwBeginDrag = sample.nLength - 1; m_dwEndDrag = m_dwBeginDrag; } if (oldsel) SetCurSel(m_dwBeginDrag, m_dwEndDrag); @@ -1517,7 +1514,7 @@ if (pModDoc) { CSoundFile *pSndFile = pModDoc->GetSoundFile(); - DWORD len = pSndFile->GetSample(m_nSample).nLength; + SmpLength len = pSndFile->GetSample(m_nSample).nLength; if (len && !m_dwStatus[SMPSTATUS_DRAWING]) SetCurSel(0, len); } } @@ -1775,8 +1772,7 @@ CModDoc *pModDoc = GetDocument(); if (pModDoc) { - CSoundFile *pSndFile = pModDoc->GetSoundFile(); - DWORD len = pSndFile->GetSample(m_nSample).nLength; + SmpLength len = pModDoc->GetrSoundFile().GetSample(m_nSample).nLength; if (len) SetCurSel(0, len); } } @@ -1819,16 +1815,14 @@ { CModDoc *pModDoc = GetDocument(); DWORD dwUpdateFlags = HINT_SAMPLEINFO | HINT_SAMPLEDATA; - DWORD len; if (!pModDoc) return; CSoundFile &sndFile = pModDoc->GetrSoundFile(); ModSample &sample = sndFile.GetSample(m_nSample); - len = sample.nLength; - if ((!sample.pSample) || (!len)) return; - if (m_dwEndSel > len) m_dwEndSel = len; + if ((!sample.pSample) || (!sample.nLength)) return; + if (m_dwEndSel > sample.nLength) m_dwEndSel = sample.nLength; if ((m_dwBeginSel >= m_dwEndSel) - || (m_dwEndSel - m_dwBeginSel + 4 >= len)) + || (m_dwEndSel - m_dwBeginSel + 4 >= sample.nLength)) { if (Reporting::Confirm("Remove this sample?", "Remove Sample", true) != cnfYes) return; pModDoc->GetSampleUndo().PrepareUndo(m_nSample, sundo_replace, "Delete Sample"); @@ -1842,23 +1836,17 @@ CriticalSection cs; - UINT cutlen = (m_dwEndSel - m_dwBeginSel); - UINT istart = m_dwBeginSel * sample.GetBytesPerSample(); - UINT iend = len * sample.GetBytesPerSample(); - sample.nLength -= cutlen; - cutlen *= sample.GetBytesPerSample(); + const SmpLength selStart = m_dwBeginSel * sample.GetBytesPerSample(); + const SmpLength selEnd = m_dwEndSel * sample.GetBytesPerSample(); + const SmpLength smpEnd = sample.nLength * sample.GetBytesPerSample(); + sample.nLength -= (m_dwEndSel - m_dwBeginSel); - char *p = static_cast<char *>(sample.pSample); - for (UINT i=istart; i<iend; i++) - { - p[i] = (i+cutlen < iend) ? p[i+cutlen] : (char)0; - } - len = sample.nLength; + int8 *p = static_cast<int8 *>(sample.pSample); + memmove(p + selStart, p + selEnd, smpEnd - selEnd); - // adjust loop points - AdjustLoopPoints(sample.nLoopStart, sample.nLoopEnd, len); - AdjustLoopPoints(sample.nSustainStart, sample.nSustainEnd, len); + AdjustLoopPoints(sample.nLoopStart, sample.nLoopEnd, sample.nLength); + AdjustLoopPoints(sample.nSustainStart, sample.nSustainEnd, sample.nLength); if(sample.nLoopEnd == 0) { @@ -2182,7 +2170,7 @@ CriticalSection cs; // Note: Sample is overwritten in-place! Unused data is not deallocated! - int8 *p = (int8 *)sample.pSample; + int8 *p = static_cast<int8 *>(sample.pSample); memmove(p, p + nStart * sample.GetBytesPerSample(), nEnd * sample.GetBytesPerSample()); if (sample.nLoopStart >= nStart) sample.nLoopStart -= nStart; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |