From: <sag...@us...> - 2014-11-08 17:56:55
|
Revision: 4561 http://sourceforge.net/p/modplug/code/4561 Author: saga-games Date: 2014-11-08 17:56:49 +0000 (Sat, 08 Nov 2014) Log Message: ----------- [Imp] Song length estimation reports length for all sub songs in the current order list instead of just the first. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Modedit.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/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2014-11-08 17:21:00 UTC (rev 4560) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2014-11-08 17:56:49 UTC (rev 4561) @@ -691,7 +691,7 @@ double module_impl::get_duration_seconds() const { - return m_sndFile->GetLength( eNoAdjust ).duration; + return m_sndFile->GetLength( eNoAdjust ).back().duration; } void module_impl::select_subsong( std::int32_t subsong ) { if ( subsong < -1 || subsong >= m_sndFile->Order.GetNumSequences() ) { @@ -714,12 +714,12 @@ return m_currentPositionSeconds; } double module_impl::set_position_seconds( double seconds ) { - GetLengthType t = m_sndFile->GetLength( eNoAdjust, GetLengthTarget( seconds ) ); + GetLengthType t = m_sndFile->GetLength( eNoAdjust, GetLengthTarget( seconds ) ).back(); m_sndFile->InitializeVisitedRows(); m_sndFile->m_PlayState.m_nCurrentOrder = t.lastOrder; m_sndFile->SetCurrentOrder( t.lastOrder ); m_sndFile->m_PlayState.m_nNextRow = t.lastRow; - m_currentPositionSeconds = m_sndFile->GetLength( eAdjust, GetLengthTarget( t.lastOrder, t.lastRow ) ).duration; + m_currentPositionSeconds = m_sndFile->GetLength( eAdjust, GetLengthTarget( t.lastOrder, t.lastRow ) ).back().duration; return m_currentPositionSeconds; } double module_impl::set_position_order_row( std::int32_t order, std::int32_t row ) { @@ -738,7 +738,7 @@ m_sndFile->m_PlayState.m_nCurrentOrder = order; m_sndFile->SetCurrentOrder( order ); m_sndFile->m_PlayState.m_nNextRow = row; - m_currentPositionSeconds = m_sndFile->GetLength( eAdjust, GetLengthTarget( order, row ) ).duration; + m_currentPositionSeconds = m_sndFile->GetLength( eAdjust, GetLengthTarget( order, row ) ).back().duration; return m_currentPositionSeconds; } std::vector<std::string> module_impl::get_metadata_keys() const { Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2014-11-08 17:21:00 UTC (rev 4560) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2014-11-08 17:56:49 UTC (rev 4561) @@ -2222,16 +2222,25 @@ void CModDoc::OnEstimateSongLength() //---------------------------------- { - CString s; - double songLength = m_SndFile.GetSongTime(); - if(songLength != std::numeric_limits<double>::infinity()) + CString s = _T("Approximate song length: "); + std::vector<GetLengthType> lengths = m_SndFile.GetLength(eNoAdjust, GetLengthTarget(true)); + for(size_t i = 0; i < lengths.size(); i++) { - songLength = Util::Round(songLength); - s.Format("Approximate song length: %.0fmn%02.0fs", std::floor(songLength / 60.0), fmod(songLength, 60.0)); - } else - { - s = "Song too long!"; + if(lengths.size() > 1) + { + s.AppendFormat(_T("\nSong %u, starting at order %u: "), i, lengths[i].startOrder); + } + double songLength = lengths[i].duration; + if(songLength != std::numeric_limits<double>::infinity()) + { + songLength = Util::Round(songLength); + s.AppendFormat("%.0fmn%02.0fs", std::floor(songLength / 60.0), std::fmod(songLength, 60.0)); + } else + { + s += "Song too long!"; + } } + Reporting::Information(s); } Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2014-11-08 17:21:00 UTC (rev 4560) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2014-11-08 17:56:49 UTC (rev 4561) @@ -1172,10 +1172,13 @@ //--------------------------------- { bool result = false; - GetLengthType length = m_SndFile.GetLength(eNoAdjust); - if(length.endOrder != ORDERINDEX_INVALID && length.endRow != ROWINDEX_INVALID) + std::vector<GetLengthType> length = m_SndFile.GetLength(eNoAdjust, GetLengthTarget(true)); + for(size_t i = 0; i < length.size(); i++) { - result = m_SndFile.Patterns[m_SndFile.Order[length.endOrder]].WriteEffect(EffectWriter(CMD_POSITIONJUMP, m_SndFile.m_nRestartPos).Row(length.endRow).Retry(EffectWriter::rmTryNextRow)); + if(length[i].endOrder != ORDERINDEX_INVALID && length[i].endRow != ROWINDEX_INVALID) + { + result = m_SndFile.Patterns[m_SndFile.Order[length[i].endOrder]].WriteEffect(EffectWriter(CMD_POSITIONJUMP, m_SndFile.m_nRestartPos).Row(length[i].endRow).Retry(EffectWriter::rmTryNextRow)); + } } m_SndFile.m_nRestartPos = 0; return result; Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp 2014-11-08 17:21:00 UTC (rev 4560) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2014-11-08 17:56:49 UTC (rev 4561) @@ -105,14 +105,11 @@ // [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, GetLengthTarget target) -//------------------------------------------------------------------------------------------- +std::vector<GetLengthType> CSoundFile::GetLength(enmGetLengthResetMode adjustMode, GetLengthTarget target) +//------------------------------------------------------------------------------------------------------------ { + std::vector<GetLengthType> results; GetLengthType retval; - retval.duration = 0.0; - retval.targetReached = false; - retval.lastOrder = retval.endOrder = ORDERINDEX_INVALID; - retval.lastRow = retval.endRow = ROWINDEX_INVALID; // Are we trying to reach a certain pattern position? const bool hasSearchTarget = target.mode != GetLengthTarget::NoTarget; @@ -199,7 +196,12 @@ } else { // We haven't found the target row yet, but we found some other unplayed row... continue searching from here. + retval.duration = memory.elapsedTime; + results.push_back(retval); + retval.startRow = nNextRow; + retval.startOrder = nNextOrder; memory.Reset(); + nRow = nNextRow; nCurrentOrder = nNextOrder; nPattern = Order[nCurrentOrder]; @@ -220,6 +222,10 @@ } else { // We haven't found the target row yet, but we found some other unplayed row... continue searching from here. + retval.duration = memory.elapsedTime; + results.push_back(retval); + retval.startRow = nNextRow; + retval.startOrder = nNextOrder; memory.Reset(); continue; } @@ -248,6 +254,10 @@ } else { // We haven't found the target row yet, but we found some other unplayed row... continue searching from here. + retval.duration = memory.elapsedTime; + results.push_back(retval); + retval.startRow = nNextRow; + retval.startOrder = nNextOrder; memory.Reset(); continue; } @@ -814,6 +824,7 @@ retval.lastRow = nRow; } retval.duration = memory.elapsedTime; + results.push_back(retval); // Store final variables if((adjustMode & eAdjust)) @@ -852,7 +863,7 @@ visitedSongRows.Set(visitedRows); } - return retval; + return results; } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2014-11-08 17:21:00 UTC (rev 4560) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2014-11-08 17:56:49 UTC (rev 4561) @@ -1848,7 +1848,7 @@ double CSoundFile::GetPlaybackTimeAt(ORDERINDEX ord, ROWINDEX row, bool updateVars, bool updateSamplePos) //------------------------------------------------------------------------------------------------------- { - const GetLengthType t = GetLength(updateVars ? (updateSamplePos ? eAdjustSamplePositions : eAdjust) : eNoAdjust, GetLengthTarget(ord, row)); + const GetLengthType t = GetLength(updateVars ? (updateSamplePos ? eAdjustSamplePositions : eAdjust) : eNoAdjust, GetLengthTarget(ord, row)).back(); 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 2014-11-08 17:21:00 UTC (rev 4560) +++ trunk/OpenMPT/soundlib/Sndfile.h 2014-11-08 17:56:49 UTC (rev 4561) @@ -97,11 +97,19 @@ struct GetLengthType { double duration; // total time in seconds - ROWINDEX lastRow; // last parsed row (dito) - ROWINDEX endRow; // last row before module loops (dito) + ROWINDEX lastRow; // last parsed row (see lastOrder remark) + ROWINDEX endRow; // last row before module loops (see endOrder remark) + ROWINDEX startRow; // first row of parsed subsong ORDERINDEX lastOrder; // last parsed order (if no target is specified, this is the first order that is parsed twice, i.e. not the *last* played order) ORDERINDEX endOrder; // last order before module loops (UNDEFINED if a target is specified) + ORDERINDEX startOrder; // first order of parsed subsong bool targetReached; // true if the specified order/row combination has been reached while going through the module + + GetLengthType() + : duration(0.0) + , lastRow(ROWINDEX_INVALID), endRow(ROWINDEX_INVALID), startRow(0) + , lastOrder(ORDERINDEX_INVALID), endOrder(ORDERINDEX_INVALID), startOrder(0) + , targetReached(false) { } }; @@ -120,15 +128,16 @@ enum Mode { - NoTarget, // Don't seek, i.e. return complete module length. + NoTarget, // Don't seek, i.e. return complete length of the first subsong. + GetAllSubsongs, // Same as NoTarget (i.e. get complete length), but returns the length of all sub songs SeekPosition, // Seek to given pattern position. SeekSeconds, // Seek to given time. } mode; // Don't seek, i.e. return complete module length. - GetLengthTarget() + GetLengthTarget(bool allSongs = false) { - mode = NoTarget; + mode = allSongs ? GetAllSubsongs : NoTarget; } // Seek to given pattern position if position is valid. @@ -600,13 +609,13 @@ //Get modlength in various cases: total length, length to //specific order&row etc. Return value is in seconds. - GetLengthType GetLength(enmGetLengthResetMode adjustMode, GetLengthTarget target = GetLengthTarget()); + std::vector<GetLengthType> GetLength(enmGetLengthResetMode adjustMode, GetLengthTarget target = GetLengthTarget()); void InitializeVisitedRows() { visitedSongRows.Initialize(true); } public: //Returns song length in seconds. - double GetSongTime() { return GetLength(eNoAdjust).duration; } + double GetSongTime() { return GetLength(eNoAdjust).back().duration; } void RecalculateSamplesPerTick(); double GetRowDuration(UINT tempo, UINT speed) const; Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2014-11-08 17:21:00 UTC (rev 4560) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2014-11-08 17:56:49 UTC (rev 4561) @@ -492,7 +492,7 @@ // Let's check again if this really is the end of the song. // The visited rows vector might have been screwed up while editing... // This is of course not possible during rendering to WAV, so we ignore that case. - GetLengthType t = GetLength(eNoAdjust); + GetLengthType t = GetLength(eNoAdjust).back(); if(IsRenderingToDisc() || (t.lastOrder == m_PlayState.m_nCurrentOrder && t.lastRow == m_PlayState.m_nRow)) #else if(1) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |