Remove identical calls to InstrumentTrack::processAudioBuffer
Remove identical calls to `InstrumentTrack::processAudioBuffer` which appear in the overridden implementations of `Instrument::play` and `Instrument::playNotes`. Instead the call to `processAudioBuffer` has been moved into `InstrumentPlayHandle::play` and `InstrumentTrack::playNote`. These two methods call the aforementioned methods of `Instrument`. Especially in the case of `InstrumentTrack::playNote` the previous implementation resulted in some unncessary "ping pong" where `InstrumentTrack` called a method on an `Instrument` which then in turn called a method on `InstrumentTrack`. And this was done in almost every instrument.
In `InstrumentTrack::playNote` an additional check was added which only calls `processAudioBuffer` if the buffer is not `nullptr`. The reason is that under certain circumstances `PlayHandle::doProcessing` calls the `play` method by explicitly passing a `nullptr` as the buffer. This behavior was added with commit 7bc97f5d5b. Because it is unknown if this was done for some side effects the code was adjusted so that it behaves identical in this case.
Move the complex implementation for `InstrumentPlayHandle::play` and `InstrumentPlayHandle::isFromTrack` into the cpp file and optimize the includes.
This commit is contained in:
@@ -24,7 +24,10 @@
|
||||
|
||||
|
||||
#include "InstrumentPlayHandle.h"
|
||||
#include "Instrument.h"
|
||||
#include "InstrumentTrack.h"
|
||||
#include "Engine.h"
|
||||
#include "AudioEngine.h"
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
@@ -37,5 +40,41 @@ InstrumentPlayHandle::InstrumentPlayHandle( Instrument * instrument, InstrumentT
|
||||
setAudioPort( instrumentTrack->audioPort() );
|
||||
}
|
||||
|
||||
void InstrumentPlayHandle::play( sampleFrame * _working_buffer )
|
||||
{
|
||||
InstrumentTrack * instrumentTrack = m_instrument->instrumentTrack();
|
||||
|
||||
// ensure that all our nph's have been processed first
|
||||
ConstNotePlayHandleList nphv = NotePlayHandle::nphsOfInstrumentTrack(instrumentTrack, true );
|
||||
|
||||
bool nphsLeft;
|
||||
do
|
||||
{
|
||||
nphsLeft = false;
|
||||
for( const NotePlayHandle * constNotePlayHandle : nphv )
|
||||
{
|
||||
NotePlayHandle * notePlayHandle = const_cast<NotePlayHandle *>( constNotePlayHandle );
|
||||
if( notePlayHandle->state() != ThreadableJob::ProcessingState::Done &&
|
||||
!notePlayHandle->isFinished())
|
||||
{
|
||||
nphsLeft = true;
|
||||
notePlayHandle->process();
|
||||
}
|
||||
}
|
||||
}
|
||||
while( nphsLeft );
|
||||
|
||||
m_instrument->play( _working_buffer );
|
||||
|
||||
// Process the audio buffer that the instrument has just worked on...
|
||||
const fpp_t frames = Engine::audioEngine()->framesPerPeriod();
|
||||
instrumentTrack->processAudioBuffer(_working_buffer, frames, nullptr);
|
||||
}
|
||||
|
||||
bool InstrumentPlayHandle::isFromTrack( const Track* _track ) const
|
||||
{
|
||||
return m_instrument->isFromTrack( _track );
|
||||
}
|
||||
|
||||
|
||||
} // namespace lmms
|
||||
@@ -579,6 +579,13 @@ void InstrumentTrack::playNote( NotePlayHandle* n, sampleFrame* workingBuffer )
|
||||
{
|
||||
// all is done, so now lets play the note!
|
||||
m_instrument->playNote( n, workingBuffer );
|
||||
|
||||
if (workingBuffer != nullptr)
|
||||
{
|
||||
const fpp_t frames = n->framesLeftForCurrentPeriod();
|
||||
const f_cnt_t offset = n->noteOffset();
|
||||
this->processAudioBuffer(workingBuffer, frames + offset, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user