From: <sag...@us...> - 2013-04-21 14:38:15
|
Revision: 1922 http://sourceforge.net/p/modplug/code/1922 Author: saga-games Date: 2013-04-21 14:38:08 +0000 (Sun, 21 Apr 2013) Log Message: ----------- [Ref] Added GetLength mode to seek to given time offset (for libopenmpt). Modified Paths: -------------- trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/soundlib/Snd_fx.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-21 13:32:39 UTC (rev 1921) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2013-04-21 14:38:08 UTC (rev 1922) @@ -1791,7 +1791,7 @@ if(wsdlg.m_bSelectPlay) { m_SndFile.SetCurrentOrder(wsdlg.m_nMinOrder); - m_SndFile.GetLength(eAdjust, wsdlg.m_nMinOrder, 0); // adjust playback variables / visited rows vector + m_SndFile.GetLength(eAdjust, GetLengthTarget(wsdlg.m_nMinOrder, 0)); // adjust playback variables / visited rows vector m_SndFile.m_nCurrentOrder = wsdlg.m_nMinOrder; m_SndFile.m_nMaxOrderPosition = wsdlg.m_nMaxOrder + 1; m_SndFile.SetRepeatCount(0); Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp 2013-04-21 13:32:39 UTC (rev 1921) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2013-04-21 14:38:08 UTC (rev 1922) @@ -94,6 +94,7 @@ }; double elapsedTime; + CSoundFile::samplecount_t renderedSamples; UINT musicSpeed, musicTempo; LONG glbVol; vector<ChnSettings> chnSettings; @@ -111,6 +112,7 @@ void Reset() { elapsedTime = 0.0; + renderedSamples = 0; musicSpeed = sndFile.m_nDefaultSpeed; musicTempo = sndFile.m_nDefaultTempo; glbVol = sndFile.m_nDefaultGlobalVolume; @@ -133,8 +135,8 @@ // [out] lastRow: last parsed row (dito) // [out] endOrder: last order before module loops (UNDEFINED if a target is specified) // [out] endRow: last row before module loops (dito) -GetLengthType CSoundFile::GetLength(enmGetLengthResetMode adjustMode, ORDERINDEX endOrder, ROWINDEX endRow) -//--------------------------------------------------------------------------------------------------------- +GetLengthType CSoundFile::GetLength(enmGetLengthResetMode adjustMode, GetLengthTarget target) +//------------------------------------------------------------------------------------------- { GetLengthType retval; retval.duration = 0.0; @@ -143,7 +145,7 @@ retval.lastRow = retval.endRow = ROWINDEX_INVALID; // Are we trying to reach a certain pattern position? - const bool hasSearchTarget = (endOrder != ORDERINDEX_INVALID && endRow != ROWINDEX_INVALID); + const bool hasSearchTarget = target.mode != GetLengthTarget::NoTarget; ROWINDEX nRow = 0, nNextRow = 0; ROWINDEX nNextPatStartRow = 0; // FT2 E60 bug @@ -154,8 +156,6 @@ // Temporary visited rows vector (so that GetLength() won't interfere with the player code if the module is playing at the same time) RowVisitor visitedRows(*this); - samplecount_t renderedSamples = 0; - for (;;) { UINT rowDelay = 0, tickDelay = 0; @@ -203,7 +203,7 @@ } } // Skip non-existing patterns - if ((nPattern >= Patterns.Size()) || (!Patterns[nPattern])) + if((nPattern >= Patterns.Size()) || (!Patterns[nPattern])) { // If there isn't even a tune, we should probably stop here. if(nCurrentOrder == m_nRestartPos) @@ -223,11 +223,12 @@ continue; } // Should never happen - if (nRow >= Patterns[nPattern].GetNumRows()) + if(nRow >= Patterns[nPattern].GetNumRows()) nRow = 0; - //Check whether target reached. - if(nCurrentOrder == endOrder && nRow == endRow) + // Check whether target was reached. + if((target.mode == GetLengthTarget::SeekPosition && nCurrentOrder == target.pos.order && nRow == target.pos.row) + || (target.mode == GetLengthTarget::SeekSeconds && memory.elapsedTime >= target.time)) { retval.targetReached = true; break; @@ -534,10 +535,10 @@ const UINT rowDuration = tickDuration * (memory.musicSpeed + tickDelay) * MAX(rowDelay, 1); memory.elapsedTime += static_cast<double>(rowDuration) / static_cast<double>(m_MixerSettings.gdwMixingFreq); - renderedSamples += rowDuration; + memory.renderedSamples += rowDuration; } - if(retval.targetReached || endOrder == ORDERINDEX_INVALID || endRow == ROWINDEX_INVALID) + if(retval.targetReached || target.mode == GetLengthTarget::NoTarget) { retval.lastOrder = nCurrentOrder; retval.lastRow = nRow; @@ -547,11 +548,11 @@ // Store final variables if((adjustMode & eAdjust)) { - if(retval.targetReached || endOrder == ORDERINDEX_INVALID || endRow == ROWINDEX_INVALID) + if(retval.targetReached || target.mode == GetLengthTarget::NoTarget) { // Target found, or there is no target (i.e. play whole song)... m_nGlobalVolume = memory.glbVol; - m_lTotalSampleCount = renderedSamples; + m_lTotalSampleCount = memory.renderedSamples; m_bPositionChanged = true; if(IsCompatibleMode(TRK_IMPULSETRACKER | TRK_FASTTRACKER2)) { Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-21 13:32:39 UTC (rev 1921) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-04-21 14:38:08 UTC (rev 1922) @@ -1638,7 +1638,7 @@ double CSoundFile::GetPlaybackTimeAt(ORDERINDEX ord, ROWINDEX row, bool updateVars) //--------------------------------------------------------------------------------- { - const GetLengthType t = GetLength(updateVars ? eAdjust : eNoAdjust, ord, row); + const GetLengthType t = GetLength(updateVars ? eAdjust : eNoAdjust, GetLengthTarget(ord, row)); if(t.targetReached) return t.duration; else return -1; //Given position not found from play sequence. } Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-04-21 13:32:39 UTC (rev 1921) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-04-21 14:38:08 UTC (rev 1922) @@ -92,6 +92,57 @@ }; +// Target seek mode for GetLength() +struct GetLengthTarget +{ + union + { + double time; + struct + { + ROWINDEX row; + ORDERINDEX order; + } pos; + }; + + enum Mode + { + NoTarget, // Don't seek, i.e. return complete module length. + SeekPosition, // Seek to given pattern position. + SeekSeconds, // Seek to given time. + } mode; + + // Don't seek, i.e. return complete module length. + GetLengthTarget() + { + mode = NoTarget; + } + + // Seek to given pattern position if position is valid. + GetLengthTarget(ORDERINDEX order, ROWINDEX row) + { + mode = NoTarget; + if(order != ORDERINDEX_INVALID && row != ROWINDEX_INVALID) + { + mode = SeekPosition; + pos.row = row; + pos.order = order; + } + } + + // Seek to given time if t is valid (i.e. not negative). + GetLengthTarget(double t) + { + mode = NoTarget; + if(t >= 0.0) + { + mode = SeekSeconds; + time = t; + } + } +}; + + // Reset mode for GetLength() enum enmGetLengthResetMode { @@ -400,7 +451,7 @@ //Get modlength in various cases: total length, length to //specific order&row etc. Return value is in seconds. - GetLengthType GetLength(enmGetLengthResetMode adjustMode, ORDERINDEX ord = ORDERINDEX_INVALID, ROWINDEX row = ROWINDEX_INVALID); + GetLengthType GetLength(enmGetLengthResetMode adjustMode, GetLengthTarget target = GetLengthTarget()); void InitializeVisitedRows() { visitedSongRows.Initialize(true); } Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-04-21 13:32:39 UTC (rev 1921) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-04-21 14:38:08 UTC (rev 1922) @@ -177,7 +177,7 @@ UINT CSoundFile::Read(LPVOID lpDestBuffer, UINT count) -//------------------------------------------------------- +//---------------------------------------------------- { LPBYTE lpBuffer = (LPBYTE)lpDestBuffer; LPCONVERTPROC pCvt = nullptr; @@ -436,7 +436,7 @@ m_nMusicSpeed = m_nDefaultSpeed; m_nMusicTempo = m_nDefaultTempo; m_nGlobalVolume = m_nDefaultGlobalVolume; - for (UINT i=0; i<MAX_CHANNELS; i++) + for(CHANNELINDEX i = 0; i < MAX_CHANNELS; i++) { Chn[i].dwFlags.set(CHN_NOTEFADE | CHN_KEYOFF); Chn[i].nFadeOutVol = 0; @@ -546,7 +546,7 @@ } else { // Ok, this is really dirty, but we have to update the visited rows vector... - GetLength(eAdjustOnSuccess, m_nCurrentOrder, m_nRow); + GetLength(eAdjustOnSuccess, GetLengthTarget(m_nCurrentOrder, m_nRow)); } } } @@ -1365,7 +1365,7 @@ else chn.nVibratoPos = (vibpos + chn.nVibratoSpeed) & 0x3F; } - } else if(chn.dwOldFlags & CHN_VIBRATO) + } else if(chn.dwOldFlags[CHN_VIBRATO]) { // Stop MIDI vibrato for plugins: IMixPlugin *plugin = GetChannelInstrumentPlugin(nChn); @@ -1961,7 +1961,7 @@ realvol = (pChn->nRealVolume * kChnMasterVol) >> 8; } - const forcePanningMode panningMode = m_PlayConfig.getForcePanningMode(); + const forcePanningMode panningMode = m_PlayConfig.getForcePanningMode(); if (panningMode == forceSoftPanning || (panningMode == dontForcePanningMode && (m_MixerSettings.MixerFlags & SNDMIX_SOFTPANNING))) { if (pan < 128) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |