Merge pull request #6867 from michaelgregorius/RemoveIdenticalCalls
(Re)move identical calls to `InstrumentTrack::processAudioBuffer`
This commit is contained in:
@@ -24,18 +24,57 @@
|
||||
|
||||
|
||||
#include "InstrumentPlayHandle.h"
|
||||
#include "Instrument.h"
|
||||
#include "InstrumentTrack.h"
|
||||
#include "Engine.h"
|
||||
#include "AudioEngine.h"
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
|
||||
|
||||
InstrumentPlayHandle::InstrumentPlayHandle( Instrument * instrument, InstrumentTrack* instrumentTrack ) :
|
||||
PlayHandle( Type::InstrumentPlayHandle ),
|
||||
m_instrument( instrument )
|
||||
InstrumentPlayHandle::InstrumentPlayHandle(Instrument * instrument, InstrumentTrack* instrumentTrack) :
|
||||
PlayHandle(Type::InstrumentPlayHandle),
|
||||
m_instrument(instrument)
|
||||
{
|
||||
setAudioPort( instrumentTrack->audioPort() );
|
||||
setAudioPort(instrumentTrack->audioPort());
|
||||
}
|
||||
|
||||
void InstrumentPlayHandle::play(sampleFrame * working_buffer)
|
||||
{
|
||||
InstrumentTrack * instrumentTrack = m_instrument->instrumentTrack();
|
||||
|
||||
// ensure that all our nph's have been processed first
|
||||
auto nphv = NotePlayHandle::nphsOfInstrumentTrack(instrumentTrack, true);
|
||||
|
||||
bool nphsLeft;
|
||||
do
|
||||
{
|
||||
nphsLeft = false;
|
||||
for (const NotePlayHandle * constNotePlayHandle : nphv)
|
||||
{
|
||||
if (constNotePlayHandle->state() != ThreadableJob::ProcessingState::Done &&
|
||||
!constNotePlayHandle->isFinished())
|
||||
{
|
||||
nphsLeft = true;
|
||||
NotePlayHandle * notePlayHandle = const_cast<NotePlayHandle *>(constNotePlayHandle);
|
||||
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
|
||||
} // namespace lmms
|
||||
|
||||
@@ -570,6 +570,10 @@ f_cnt_t InstrumentTrack::beatLen( NotePlayHandle * _n ) const
|
||||
|
||||
void InstrumentTrack::playNote( NotePlayHandle* n, sampleFrame* workingBuffer )
|
||||
{
|
||||
// Note: under certain circumstances the working buffer is a nullptr.
|
||||
// These cases are triggered in PlayHandle::doProcessing when the play method is called with a nullptr.
|
||||
// TODO: Find out if we can skip processing at a higher level if the buffer is nullptr.
|
||||
|
||||
// arpeggio- and chord-widget has to do its work -> adding sub-notes
|
||||
// for chords/arpeggios
|
||||
m_noteStacking.processNote( n );
|
||||
@@ -579,6 +583,15 @@ void InstrumentTrack::playNote( NotePlayHandle* n, sampleFrame* workingBuffer )
|
||||
{
|
||||
// all is done, so now lets play the note!
|
||||
m_instrument->playNote( n, workingBuffer );
|
||||
|
||||
// This is effectively the same as checking if workingBuffer is not a nullptr.
|
||||
// Calling processAudioBuffer with a nullptr leads to crashes. Hence the check.
|
||||
if (n->usesBuffer())
|
||||
{
|
||||
const fpp_t frames = n->framesLeftForCurrentPeriod();
|
||||
const f_cnt_t offset = n->noteOffset();
|
||||
processAudioBuffer(workingBuffer, frames + offset, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user