From: <sv...@op...> - 2024-12-02 20:10:59
|
Author: sagamusix Date: Mon Dec 2 21:10:52 2024 New Revision: 22453 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22453 Log: [Fix] When rows per beat are unset, avoid reporting infinity for BPM or fractional PPQ position. Assume a default of 4 rows per beat instead. Modified: trunk/OpenMPT/mptrack/ColorConfigDlg.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/soundlib/PlayState.cpp trunk/OpenMPT/soundlib/Snd_defs.h trunk/OpenMPT/soundlib/Snd_fx.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/mptrack/ColorConfigDlg.cpp ============================================================================== --- trunk/OpenMPT/mptrack/ColorConfigDlg.cpp Mon Dec 2 20:12:42 2024 (r22452) +++ trunk/OpenMPT/mptrack/ColorConfigDlg.cpp Mon Dec 2 21:10:52 2024 (r22453) @@ -193,8 +193,8 @@ SetDlgItemInt(IDC_PRIMARYHILITE, TrackerSettings::Instance().m_nRowHighlightMeasures); SetDlgItemInt(IDC_SECONDARYHILITE, TrackerSettings::Instance().m_nRowHighlightBeats); - m_spinRowsPerMeasure.SetRange32(0, int32_max); - m_spinRowsPerBeat.SetRange32(0, int32_max); + m_spinRowsPerMeasure.SetRange32(0, MAX_ROWS_PER_MEASURE); + m_spinRowsPerBeat.SetRange32(0, MAX_ROWS_PER_BEAT); patternFont = TrackerSettings::Instance().patternFont; m_ComboFont.SetRedraw(FALSE); Modified: trunk/OpenMPT/mptrack/Moddoc.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp Mon Dec 2 20:12:42 2024 (r22452) +++ trunk/OpenMPT/mptrack/Moddoc.cpp Mon Dec 2 21:10:52 2024 (r22453) @@ -2406,13 +2406,14 @@ } m_SndFile.RecalculateSamplesPerTick(); const double bpm = m_SndFile.GetCurrentBPM(); + const ROWINDEX rowsPerBeat = m_SndFile.m_PlayState.m_nCurrentRowsPerBeat ? m_SndFile.m_PlayState.m_nCurrentRowsPerBeat : DEFAULT_ROWS_PER_BEAT; CString s; switch(m_SndFile.m_nTempoMode) { case TempoMode::Alternative: s.Format(_T("Using alternative tempo interpretation.\n\nAssuming:\n. %.8g ticks per second\n. %u ticks per row\n. %u rows per beat\nthe tempo is approximately: %.8g BPM"), - m_SndFile.m_PlayState.m_nMusicTempo.ToDouble(), m_SndFile.m_PlayState.m_nMusicSpeed, m_SndFile.m_PlayState.m_nCurrentRowsPerBeat, bpm); + m_SndFile.m_PlayState.m_nMusicTempo.ToDouble(), m_SndFile.m_PlayState.m_nMusicSpeed, rowsPerBeat, bpm); break; case TempoMode::Modern: @@ -2422,7 +2423,7 @@ case TempoMode::Classic: default: s.Format(_T("Using standard tempo interpretation.\n\nAssuming:\n. A mod tempo (tick duration factor) of %.8g\n. %u ticks per row\n. %u rows per beat\nthe tempo is approximately: %.8g BPM"), - m_SndFile.m_PlayState.m_nMusicTempo.ToDouble(), m_SndFile.m_PlayState.m_nMusicSpeed, m_SndFile.m_PlayState.m_nCurrentRowsPerBeat, bpm); + m_SndFile.m_PlayState.m_nMusicTempo.ToDouble(), m_SndFile.m_PlayState.m_nMusicSpeed, rowsPerBeat, bpm); break; } Modified: trunk/OpenMPT/soundlib/PlayState.cpp ============================================================================== --- trunk/OpenMPT/soundlib/PlayState.cpp Mon Dec 2 20:12:42 2024 (r22452) +++ trunk/OpenMPT/soundlib/PlayState.cpp Mon Dec 2 21:10:52 2024 (r22453) @@ -50,8 +50,8 @@ void PlayState::UpdatePPQ(bool patternTransition) noexcept { - ROWINDEX rpm = m_nCurrentRowsPerMeasure ? m_nCurrentRowsPerMeasure : 4; - ROWINDEX rpb = m_nCurrentRowsPerBeat ? m_nCurrentRowsPerBeat : 1; + ROWINDEX rpm = m_nCurrentRowsPerMeasure ? m_nCurrentRowsPerMeasure : DEFAULT_ROWS_PER_MEASURE; + ROWINDEX rpb = m_nCurrentRowsPerBeat ? m_nCurrentRowsPerBeat : DEFAULT_ROWS_PER_BEAT; if(m_lTotalSampleCount > 0 && (patternTransition || !(m_nRow % rpm))) { // Pattern end = end of measure, so round up PPQ to the next full measure Modified: trunk/OpenMPT/soundlib/Snd_defs.h ============================================================================== --- trunk/OpenMPT/soundlib/Snd_defs.h Mon Dec 2 20:12:42 2024 (r22452) +++ trunk/OpenMPT/soundlib/Snd_defs.h Mon Dec 2 21:10:52 2024 (r22453) @@ -43,8 +43,12 @@ inline constexpr SmpLength MAX_SAMPLE_LENGTH = 0x10000000; // Sample length in frames. Sample size in bytes can be more than this (= 256 MB). +inline constexpr ROWINDEX MAX_ROWS_PER_MEASURE = 65536; +inline constexpr ROWINDEX MAX_ROWS_PER_BEAT = 65536; +inline constexpr ROWINDEX DEFAULT_ROWS_PER_BEAT = 4; +inline constexpr ROWINDEX DEFAULT_ROWS_PER_MEASURE = 16; + inline constexpr ROWINDEX MAX_PATTERN_ROWS = 4096; -inline constexpr ROWINDEX MAX_ROWS_PER_BEAT = 65536; inline constexpr ORDERINDEX MAX_ORDERS = ORDERINDEX_MAX + 1; inline constexpr PATTERNINDEX MAX_PATTERNS = 4000; inline constexpr SAMPLEINDEX MAX_SAMPLES = 4000; Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp Mon Dec 2 20:12:42 2024 (r22452) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp Mon Dec 2 21:10:52 2024 (r22453) @@ -1072,7 +1072,8 @@ const uint32 rowDuration = tickDuration * numTicks; memory.elapsedTime += static_cast<double>(rowDuration) / static_cast<double>(m_MixerSettings.gdwMixingFreq); playState.m_lTotalSampleCount += rowDuration; - playState.m_ppqPosFract += 1.0 / playState.m_nCurrentRowsPerBeat; + const ROWINDEX rowsPerBeat = playState.m_nCurrentRowsPerBeat ? playState.m_nCurrentRowsPerBeat : DEFAULT_ROWS_PER_BEAT; + playState.m_ppqPosFract += 1.0 / rowsPerBeat; if(adjustSamplePos) { Modified: trunk/OpenMPT/soundlib/Sndfile.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp Mon Dec 2 20:12:42 2024 (r22452) +++ trunk/OpenMPT/soundlib/Sndfile.cpp Mon Dec 2 21:10:52 2024 (r22453) @@ -131,11 +131,11 @@ #ifdef MODPLUG_TRACKER m_bChannelMuteTogglePending.reset(); - m_nDefaultRowsPerBeat = m_PlayState.m_nCurrentRowsPerBeat = (TrackerSettings::Instance().m_nRowHighlightBeats) ? TrackerSettings::Instance().m_nRowHighlightBeats : 4; + m_nDefaultRowsPerBeat = m_PlayState.m_nCurrentRowsPerBeat = (TrackerSettings::Instance().m_nRowHighlightBeats) ? TrackerSettings::Instance().m_nRowHighlightBeats : DEFAULT_ROWS_PER_BEAT; m_nDefaultRowsPerMeasure = m_PlayState.m_nCurrentRowsPerMeasure = (TrackerSettings::Instance().m_nRowHighlightMeasures >= m_nDefaultRowsPerBeat) ? TrackerSettings::Instance().m_nRowHighlightMeasures : m_nDefaultRowsPerBeat * 4; #else - m_nDefaultRowsPerBeat = m_PlayState.m_nCurrentRowsPerBeat = 4; - m_nDefaultRowsPerMeasure = m_PlayState.m_nCurrentRowsPerMeasure = 16; + m_nDefaultRowsPerBeat = m_PlayState.m_nCurrentRowsPerBeat = DEFAULT_ROWS_PER_BEAT; + m_nDefaultRowsPerMeasure = m_PlayState.m_nCurrentRowsPerMeasure = DEFAULT_ROWS_PER_MEASURE; #endif // MODPLUG_TRACKER MemsetZero(Instruments); @@ -897,11 +897,12 @@ bpm = m_PlayState.m_nMusicTempo.ToDouble(); } else { - //with other modes, we calculate it: - double ticksPerBeat = m_PlayState.m_nMusicSpeed * m_PlayState.m_nCurrentRowsPerBeat; //ticks/beat = ticks/row * rows/beat - double samplesPerBeat = m_PlayState.m_nSamplesPerTick * ticksPerBeat; //samps/beat = samps/tick * ticks/beat - bpm = m_MixerSettings.gdwMixingFreq / samplesPerBeat * 60; //beats/sec = samps/sec / samps/beat - } //beats/min = beats/sec * 60 + // With other modes, we calculate it: + ROWINDEX rowsPerBeat = m_PlayState.m_nCurrentRowsPerBeat ? m_PlayState.m_nCurrentRowsPerBeat : DEFAULT_ROWS_PER_BEAT; + double ticksPerBeat = m_PlayState.m_nMusicSpeed * rowsPerBeat; // Ticks/beat = ticks/row * rows/beat + double samplesPerBeat = m_PlayState.m_nSamplesPerTick * ticksPerBeat; // Samps/beat = samps/tick * ticks/beat + bpm = m_MixerSettings.gdwMixingFreq / samplesPerBeat * 60; // Beats/sec = samps/sec / samps/beat + } // Beats/min = beats/sec * 60 return bpm; } Modified: trunk/OpenMPT/soundlib/Sndmix.cpp ============================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp Mon Dec 2 20:12:42 2024 (r22452) +++ trunk/OpenMPT/soundlib/Sndmix.cpp Mon Dec 2 21:10:52 2024 (r22453) @@ -356,8 +356,9 @@ countToRender -= countChunk; m_PlayState.m_nBufferCount -= countChunk; m_PlayState.m_lTotalSampleCount += countChunk; + const ROWINDEX rowsPerBeat = m_PlayState.m_nCurrentRowsPerBeat ? m_PlayState.m_nCurrentRowsPerBeat : DEFAULT_ROWS_PER_BEAT; if(!m_PlayState.m_nBufferCount && !m_PlayState.m_flags[SONG_PAUSED]) - m_PlayState.m_ppqPosFract += 1.0 / (m_PlayState.m_nCurrentRowsPerBeat * m_PlayState.TicksOnRow()); + m_PlayState.m_ppqPosFract += 1.0 / (rowsPerBeat * m_PlayState.TicksOnRow()); #ifdef MODPLUG_TRACKER if(IsRenderingToDisc()) |