Skip to content

Commit

Permalink
AudioEngine: do not reset() m_fSongSizeInTicks
Browse files Browse the repository at this point in the history
every time the `reset()` function was called in `AudioEngineTests` the song size had to be reapplied.

I think conceptionally it is more elegant _not_ reset the song size in `reset()`. This way it does not reset to its initial state after startup but just resets its transport state. Association with the current song and Hydrogen session still remains
  • Loading branch information
theGreatWhiteShark committed Oct 31, 2024
1 parent 68a2d74 commit bf6f33b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 29 deletions.
17 changes: 9 additions & 8 deletions src/core/AudioEngine/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ void AudioEngine::reset( bool bWithJackBroadcast ) {
m_nLoopsDone = 0;
m_bLookaheadApplied = false;

m_fSongSizeInTicks = MAX_NOTES;
setNextBpm( 120 );

m_pTransportPosition->reset();
Expand Down Expand Up @@ -1258,15 +1257,14 @@ void AudioEngine::handleSelectedPattern() {
}

void AudioEngine::handleSongModeChanged() {
reset( true );

const auto pSong = Hydrogen::get_instance()->getSong();
if ( pSong == nullptr ) {
AE_ERRORLOG( "no song set" );
return;
}

m_fSongSizeInTicks = pSong->lengthInTicks();
reset( true );
setNextBpm( pSong->getBpm() );
}

Expand Down Expand Up @@ -1702,17 +1700,19 @@ void AudioEngine::setSong( std::shared_ptr<Song> pNewSong )
setupLadspaFX();
}

// Reset (among other things) the transport position. This causes
// the locate() call below to update the playing patterns.
reset( false );
float fNextBpm;
if ( pNewSong != nullptr ) {
setNextBpm( pNewSong->getBpm() );
fNextBpm = pNewSong->getBpm();
m_fSongSizeInTicks = static_cast<double>( pNewSong->lengthInTicks() );
}
else {
setNextBpm( MIN_BPM );
fNextBpm = MIN_BPM;
m_fSongSizeInTicks = MAX_NOTES;
}
// Reset (among other things) the transport position. This causes
// the locate() call below to update the playing patterns.
reset( false );
setNextBpm( fNextBpm );

pHydrogen->renameJackPorts( pNewSong );

Expand Down Expand Up @@ -1745,6 +1745,7 @@ void AudioEngine::prepare() {

m_pSampler->stopPlayingNotes();
reset();
m_fSongSizeInTicks = MAX_NOTES;

setState( State::Prepared );
}
Expand Down
21 changes: 0 additions & 21 deletions src/core/AudioEngine/AudioEngineTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ void AudioEngineTests::testTransportProcessing() {
// For this call the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

// Check consistency of updated frames, ticks, and queuing
// position while using a random buffer size (e.g. like PulseAudio
Expand Down Expand Up @@ -170,7 +169,6 @@ void AudioEngineTests::testTransportProcessing() {
}

pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

pAE->setState( AudioEngine::State::Ready );
pAE->unlock();
Expand Down Expand Up @@ -209,8 +207,6 @@ void AudioEngineTests::testTransportProcessing() {
}

pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

pAE->setState( AudioEngine::State::Ready );
pAE->unlock();

Expand Down Expand Up @@ -332,7 +328,6 @@ void AudioEngineTests::testTransportProcessingTimeline() {
// For this call the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

// Check consistency of updated frames, ticks, and queuing
// position while using a random buffer size (e.g. like PulseAudio
Expand Down Expand Up @@ -383,7 +378,6 @@ void AudioEngineTests::testTransportProcessingTimeline() {
// "classical" bpm change".

pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
resetVariables();

float fBpm;
Expand Down Expand Up @@ -448,7 +442,6 @@ void AudioEngineTests::testLoopMode() {
// For this call the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

// Check consistency of updated frames, ticks, and queuing
// position while using a random buffer size (e.g. like PulseAudio
Expand Down Expand Up @@ -659,7 +652,6 @@ void AudioEngineTests::testTransportRelocation() {
// For this call the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

// Check consistency of updated frames and ticks while relocating
// transport.
Expand Down Expand Up @@ -697,7 +689,6 @@ void AudioEngineTests::testTransportRelocation() {
}

pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
pAE->setState( AudioEngine::State::Ready );
pAE->unlock();
}
Expand All @@ -712,7 +703,6 @@ void AudioEngineTests::testSongSizeChange() {
pAE->lock( RIGHT_HERE );
pAE->setState( AudioEngine::State::Testing );
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
pAE->setState( AudioEngine::State::Ready );
pAE->unlock();

Expand Down Expand Up @@ -773,7 +763,6 @@ void AudioEngineTests::testSongSizeChangeInLoopMode() {
// For this call the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

const uint32_t nFrames = 500;
const double fInitialSongSize = pAE->m_fSongSizeInTicks;
Expand Down Expand Up @@ -861,7 +850,6 @@ void AudioEngineTests::testNoteEnqueuing() {
// For this call the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

// Check consistency of updated frames and ticks while using a
// random buffer size (e.g. like PulseAudio does).
Expand Down Expand Up @@ -1075,7 +1063,6 @@ void AudioEngineTests::testNoteEnqueuing() {
pAE->lock( RIGHT_HERE );
pAE->setState( AudioEngine::State::Testing );
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

nLoops = 1;

Expand Down Expand Up @@ -1147,7 +1134,6 @@ void AudioEngineTests::testNoteEnqueuingTimeline() {
// For reset() the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
AudioEngineTests::resetSampler( __PRETTY_FUNCTION__ );

uint32_t nFrames;
Expand Down Expand Up @@ -1246,7 +1232,6 @@ void AudioEngineTests::testHumanization() {
// For reset() the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

// Rolls playback from beginning to the end of the song and
// captures all notes added to the Sampler.
Expand Down Expand Up @@ -2013,7 +1998,6 @@ void AudioEngineTests::resetSampler( const QString& sContext ) {
}

pAE->reset( false );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
}

void AudioEngineTests::testUpdateTransportPosition() {
Expand All @@ -2023,7 +2007,6 @@ void AudioEngineTests::testUpdateTransportPosition() {

pAE->lock( RIGHT_HERE );
pAE->reset( true );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();

// Check whether the transport positions in the audio engine are untouched
// by updateTransportPosition.
Expand Down Expand Up @@ -2081,7 +2064,6 @@ void AudioEngineTests::testTransportProcessingJack() {

pAE->lock( RIGHT_HERE );
pAE->reset( true );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
pAE->unlock();

auto pDriver = startJackAudioDriver();
Expand Down Expand Up @@ -2133,7 +2115,6 @@ void AudioEngineTests::testTransportProcessingJack() {
pAE->stopPlayback();
}
pAE->reset( true );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
pAE->unlock();

if ( pHydrogen->getJackTimebaseState() == JackAudioDriver::Timebase::Listener &&
Expand All @@ -2159,7 +2140,6 @@ void AudioEngineTests::testTransportRelocationJack() {
// For this call the AudioEngine still needs to be in state
// Playing or Ready.
pAE->reset( true );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
pAE->unlock();

auto pDriver = startJackAudioDriver();
Expand Down Expand Up @@ -2391,7 +2371,6 @@ void AudioEngineTests::testTransportRelocationJack() {
JackAudioDriver::m_nIntegrationLastRelocationFrame = -1;
#endif
pAE->reset( true );
pAE->m_fSongSizeInTicks = pSong->lengthInTicks();
pAE->unlock();

stopJackAudioDriver();
Expand Down

0 comments on commit bf6f33b

Please sign in to comment.