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:
@@ -26,13 +26,14 @@
|
||||
#define LMMS_INSTRUMENT_PLAY_HANDLE_H
|
||||
|
||||
#include "PlayHandle.h"
|
||||
#include "Instrument.h"
|
||||
#include "NotePlayHandle.h"
|
||||
#include "lmms_export.h"
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
|
||||
class Instrument;
|
||||
class InstrumentTrack;
|
||||
|
||||
class LMMS_EXPORT InstrumentPlayHandle : public PlayHandle
|
||||
{
|
||||
public:
|
||||
@@ -40,46 +41,17 @@ public:
|
||||
|
||||
~InstrumentPlayHandle() override = default;
|
||||
|
||||
|
||||
void play( sampleFrame * _working_buffer ) override
|
||||
{
|
||||
// ensure that all our nph's have been processed first
|
||||
ConstNotePlayHandleList nphv = NotePlayHandle::nphsOfInstrumentTrack( m_instrument->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 );
|
||||
}
|
||||
void play( sampleFrame * _working_buffer ) override;
|
||||
|
||||
bool isFinished() const override
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isFromTrack( const Track* _track ) const override
|
||||
{
|
||||
return m_instrument->isFromTrack( _track );
|
||||
}
|
||||
|
||||
bool isFromTrack( const Track* _track ) const override;
|
||||
|
||||
private:
|
||||
Instrument* m_instrument;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user