Streamline instrument flags (#7227)

## Instrument flags as a property of an instrument
The instruments flags (single streamed, MIDI based, not bendable) are properties of an instrument that do not change over time. Therefore the flags are made a property of the instrument which is initialized at construction time.

Adjust the constructors of all instruments which overrode the `flags` method to pass their flags into the `Instrument` constructor.

## Add helper methods for flags
Add helper methods for the flags. This makes the code more concise and readable and clients do not need to know the technical details on how to evaluate a flag.

## Remove the flags methods
Remove the flags methods to make it an implementation detail on how the flags are managed.
This commit is contained in:
Michael Gregorius
2024-04-27 17:45:55 +02:00
committed by GitHub
parent 6c846684cd
commit 5c0db46a60
26 changed files with 43 additions and 76 deletions

View File

@@ -37,9 +37,11 @@ namespace lmms
Instrument::Instrument(InstrumentTrack * _instrument_track,
const Descriptor * _descriptor,
const Descriptor::SubPluginFeatures::Key *key) :
const Descriptor::SubPluginFeatures::Key *key,
Flags flags) :
Plugin(_descriptor, nullptr/* _instrument_track*/, key),
m_instrumentTrack( _instrument_track )
m_instrumentTrack( _instrument_track ),
m_flags(flags)
{
}

View File

@@ -303,7 +303,7 @@ f_cnt_t InstrumentSoundShaping::releaseFrames() const
f_cnt_t ret_val = m_instrumentTrack->instrument()->desiredReleaseFrames();
if( m_instrumentTrack->instrument()->flags().testFlag( Instrument::Flag::IsSingleStreamed ) )
if (m_instrumentTrack->instrument()->isSingleStreamed())
{
return ret_val;
}

View File

@@ -109,7 +109,7 @@ NotePlayHandle::NotePlayHandle( InstrumentTrack* instrumentTrack,
m_instrumentTrack->midiNoteOn( *this );
}
if(m_instrumentTrack->instrument() && m_instrumentTrack->instrument()->flags() & Instrument::Flag::IsSingleStreamed )
if (m_instrumentTrack->instrument() && m_instrumentTrack->instrument()->isSingleStreamed())
{
setUsesBuffer( false );
}

View File

@@ -350,7 +350,7 @@ void InstrumentTrackWindow::modelChanged()
m_mixerChannelNumber->setModel( &m_track->m_mixerChannelModel );
m_pianoView->setModel( &m_track->m_piano );
if( m_track->instrument() && m_track->instrument()->flags().testFlag( Instrument::Flag::IsNotBendable ) == false )
if (m_track->instrument() && m_track->instrument()->isBendable())
{
m_pitchKnob->setModel( &m_track->m_pitchModel );
m_pitchRangeSpinBox->setModel( &m_track->m_pitchRangeModel );
@@ -368,7 +368,7 @@ void InstrumentTrackWindow::modelChanged()
m_pitchRangeLabel->hide();
}
if (m_track->instrument() && m_track->instrument()->flags().testFlag(Instrument::Flag::IsMidiBased))
if (m_track->instrument() && m_track->instrument()->isMidiBased())
{
m_tuningView->microtunerNotSupportedLabel()->show();
m_tuningView->microtunerGroupBox()->hide();
@@ -462,7 +462,7 @@ void InstrumentTrackWindow::updateInstrumentView()
m_tabWidget->addTab( m_instrumentView, tr( "Plugin" ), "plugin_tab", 0 );
m_tabWidget->setActiveTab( 0 );
m_ssView->setFunctionsHidden( m_track->m_instrument->flags().testFlag( Instrument::Flag::IsSingleStreamed ) );
m_ssView->setFunctionsHidden(m_track->m_instrument->isSingleStreamed());
modelChanged(); // Get the instrument window to refresh
m_track->dataChanged(); // Get the text on the trackButton to change

View File

@@ -233,8 +233,7 @@ void InstrumentTrack::processAudioBuffer( sampleFrame* buf, const fpp_t frames,
// We could do that in all other cases as well but the overhead for silence test is bigger than
// what we potentially save. While playing a note, a NotePlayHandle-driven instrument will produce sound in
// 99 of 100 cases so that test would be a waste of time.
if( m_instrument->flags().testFlag( Instrument::Flag::IsSingleStreamed ) &&
MixHelpers::isSilent( buf, frames ) )
if (m_instrument->isSingleStreamed() && MixHelpers::isSilent(buf, frames))
{
// at least pass one silent buffer to allow
if( m_silentBuffersProcessed )
@@ -263,7 +262,7 @@ void InstrumentTrack::processAudioBuffer( sampleFrame* buf, const fpp_t frames,
// instruments using instrument-play-handles will call this method
// without any knowledge about notes, so they pass NULL for n, which
// is no problem for us since we just bypass the envelopes+LFOs
if( m_instrument->flags().testFlag( Instrument::Flag::IsSingleStreamed ) == false && n != nullptr )
if (!m_instrument->isSingleStreamed() && n != nullptr)
{
const f_cnt_t offset = n->noteOffset();
m_soundShaping.processAudioBuffer( buf + offset, frames - offset, n );