Code review changes

Remove whitespace in methods and add it to the parenthesis of some statements. Remove underscores from parameter names. Remove usage of `this` pointer.

Add `auto` keyword to shorten line length in `InstrumentPlayHandle::play`.

Move `const_cast` of `NotePlayHandle` closer to the `process` method as this method is the reason that the cast is needed in the first place. One might also add a version of `nphsOfInstrumentTrack` that returns a non-const result but it seems to be a general problem of a missing clear responsibility so I keep it as is.
This commit is contained in:
Michael Gregorius
2023-09-16 13:35:15 +02:00
parent a6b6565687
commit 73f9f36c9a
3 changed files with 21 additions and 22 deletions

View File

@@ -37,23 +37,22 @@ class InstrumentTrack;
class LMMS_EXPORT InstrumentPlayHandle : public PlayHandle
{
public:
InstrumentPlayHandle( Instrument * instrument, InstrumentTrack* instrumentTrack );
InstrumentPlayHandle(Instrument * instrument, InstrumentTrack* instrumentTrack);
~InstrumentPlayHandle() override = default;
void play( sampleFrame * _working_buffer ) override;
void play(sampleFrame * working_buffer) override;
bool isFinished() const override
{
return false;
}
bool isFromTrack( const Track* _track ) const override;
bool isFromTrack(const Track* track) const override;
private:
Instrument* m_instrument;
} ;
};
} // namespace lmms

View File

@@ -33,48 +33,48 @@ 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 )
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 );
auto nphv = NotePlayHandle::nphsOfInstrumentTrack(instrumentTrack, true);
bool nphsLeft;
do
{
nphsLeft = false;
for( const NotePlayHandle * constNotePlayHandle : nphv )
for (const NotePlayHandle * constNotePlayHandle : nphv)
{
NotePlayHandle * notePlayHandle = const_cast<NotePlayHandle *>( constNotePlayHandle );
if( notePlayHandle->state() != ThreadableJob::ProcessingState::Done &&
!notePlayHandle->isFinished())
if (constNotePlayHandle->state() != ThreadableJob::ProcessingState::Done &&
!constNotePlayHandle->isFinished())
{
nphsLeft = true;
NotePlayHandle * notePlayHandle = const_cast<NotePlayHandle *>(constNotePlayHandle);
notePlayHandle->process();
}
}
}
while( nphsLeft );
while (nphsLeft);
m_instrument->play( _working_buffer );
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);
instrumentTrack->processAudioBuffer(working_buffer, frames, nullptr);
}
bool InstrumentPlayHandle::isFromTrack( const Track* _track ) const
bool InstrumentPlayHandle::isFromTrack(const Track* track) const
{
return m_instrument->isFromTrack( _track );
return m_instrument->isFromTrack(track);
}
} // namespace lmms
} // namespace lmms

View File

@@ -584,7 +584,7 @@ void InstrumentTrack::playNote( NotePlayHandle* n, sampleFrame* workingBuffer )
{
const fpp_t frames = n->framesLeftForCurrentPeriod();
const f_cnt_t offset = n->noteOffset();
this->processAudioBuffer(workingBuffer, frames + offset, n);
processAudioBuffer(workingBuffer, frames + offset, n);
}
}
}