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

@@ -150,7 +150,7 @@ static const char* host_ui_save_file(NativeHostHandle, bool isDir, const char* t
CarlaInstrument::CarlaInstrument(InstrumentTrack* const instrumentTrack, const Descriptor* const descriptor, const bool isPatchbay)
: Instrument(instrumentTrack, descriptor),
: Instrument(instrumentTrack, descriptor, nullptr, Flag::IsSingleStreamed | Flag::IsMidiBased | Flag::IsNotBendable),
kIsPatchbay(isPatchbay),
fHandle(nullptr),
fDescriptor(isPatchbay ? carla_get_native_patchbay_plugin() : carla_get_native_rack_plugin()),
@@ -343,11 +343,6 @@ intptr_t CarlaInstrument::handleDispatcher(const NativeHostDispatcherOpcode opco
// -------------------------------------------------------------------
Instrument::Flags CarlaInstrument::flags() const
{
return Flag::IsSingleStreamed | Flag::IsMidiBased | Flag::IsNotBendable;
}
QString CarlaInstrument::nodeName() const
{
return descriptor()->name;

View File

@@ -190,7 +190,6 @@ public:
intptr_t handleDispatcher(const NativeHostDispatcherOpcode opcode, const int32_t index, const intptr_t value, void* const ptr, const float opt);
// LMMS functions
Flags flags() const override;
QString nodeName() const override;
void saveSettings(QDomDocument& doc, QDomElement& parent) override;
void loadSettings(const QDomElement& elem) override;

View File

@@ -81,7 +81,7 @@ Plugin::Descriptor PLUGIN_EXPORT gigplayer_plugin_descriptor =
GigInstrument::GigInstrument( InstrumentTrack * _instrument_track ) :
Instrument( _instrument_track, &gigplayer_plugin_descriptor ),
Instrument(_instrument_track, &gigplayer_plugin_descriptor, nullptr, Flag::IsSingleStreamed | Flag::IsNotBendable),
m_instance( nullptr ),
m_instrument( nullptr ),
m_filename( "" ),

View File

@@ -259,11 +259,6 @@ public:
QString nodeName() const override;
Flags flags() const override
{
return Flag::IsSingleStreamed | Flag::IsNotBendable;
}
gui::PluginView* instantiateView( QWidget * _parent ) override;
QString getCurrentPatchName();

View File

@@ -64,7 +64,7 @@ Plugin::Descriptor PLUGIN_EXPORT kicker_plugin_descriptor =
KickerInstrument::KickerInstrument( InstrumentTrack * _instrument_track ) :
Instrument( _instrument_track, &kicker_plugin_descriptor ),
Instrument(_instrument_track, &kicker_plugin_descriptor, nullptr, Flag::IsNotBendable),
m_startFreqModel( 150.0f, 5.0f, 1000.0f, 1.0f, this, tr( "Start frequency" ) ),
m_endFreqModel( 40.0f, 5.0f, 1000.0f, 1.0f, this, tr( "End frequency" ) ),
m_decayModel( 440.0f, 5.0f, 5000.0f, 1.0f, 5000.0f, this, tr( "Length" ) ),

View File

@@ -64,11 +64,6 @@ public:
QString nodeName() const override;
Flags flags() const override
{
return Flag::IsNotBendable;
}
float desiredReleaseTimeMs() const override
{
return 12.f;

View File

@@ -269,7 +269,7 @@ float Lb302Filter3Pole::process(const float& samp)
//
Lb302Synth::Lb302Synth( InstrumentTrack * _instrumentTrack ) :
Instrument( _instrumentTrack, &lb302_plugin_descriptor ),
Instrument(_instrumentTrack, &lb302_plugin_descriptor, nullptr, Flag::IsSingleStreamed),
vcf_cut_knob( 0.75f, 0.0f, 1.5f, 0.005f, this, tr( "VCF Cutoff Frequency" ) ),
vcf_res_knob( 0.75f, 0.0f, 1.25f, 0.005f, this, tr( "VCF Resonance" ) ),
vcf_mod_knob( 0.1f, 0.0f, 1.0f, 0.005f, this, tr( "VCF Envelope Mod" ) ),

View File

@@ -163,11 +163,6 @@ public:
QString nodeName() const override;
Flags flags() const override
{
return Flag::IsSingleStreamed;
}
gui::PluginView* instantiateView( QWidget * _parent ) override;
private:

View File

@@ -73,7 +73,13 @@ Plugin::Descriptor PLUGIN_EXPORT lv2instrument_plugin_descriptor =
Lv2Instrument::Lv2Instrument(InstrumentTrack *instrumentTrackArg,
Descriptor::SubPluginFeatures::Key *key) :
Instrument(instrumentTrackArg, &lv2instrument_plugin_descriptor, key),
Instrument(instrumentTrackArg, &lv2instrument_plugin_descriptor, key,
#ifdef LV2_INSTRUMENT_USE_MIDI
Flag::IsSingleStreamed | Flag::IsMidiBased
#else
Flag::IsSingleStreamed
#endif
),
Lv2ControlBase(this, key->attributes["uri"])
{
clearRunningNotes();

View File

@@ -84,14 +84,6 @@ public:
/*
misc
*/
Flags flags() const override
{
#ifdef LV2_INSTRUMENT_USE_MIDI
return Flag::IsSingleStreamed | Flag::IsMidiBased;
#else
return Flag::IsSingleStreamed;
#endif
}
gui::PluginView* instantiateView(QWidget *parent) override;
private slots:

View File

@@ -95,7 +95,7 @@ QMutex OpulenzInstrument::emulatorMutex;
const auto adlib_opadd = std::array<unsigned int, OPL2_VOICES>{0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12};
OpulenzInstrument::OpulenzInstrument( InstrumentTrack * _instrument_track ) :
Instrument( _instrument_track, &opulenz_plugin_descriptor ),
Instrument(_instrument_track, &opulenz_plugin_descriptor, nullptr, Flag::IsSingleStreamed | Flag::IsMidiBased),
m_patchModel( 0, 0, 127, this, tr( "Patch" ) ),
op1_a_mdl(14.0, 0.0, 15.0, 1.0, this, tr( "Op 1 attack" ) ),
op1_d_mdl(14.0, 0.0, 15.0, 1.0, this, tr( "Op 1 decay" ) ),

View File

@@ -64,11 +64,6 @@ public:
QString nodeName() const override;
gui::PluginView* instantiateView( QWidget * _parent ) override;
Flags flags() const override
{
return Flag::IsSingleStreamed | Flag::IsMidiBased;
}
bool handleMidiEvent( const MidiEvent& event, const TimePos& time, f_cnt_t offset = 0 ) override;
void play( sampleFrame * _working_buffer ) override;

View File

@@ -122,7 +122,7 @@ struct Sf2PluginData
Sf2Instrument::Sf2Instrument( InstrumentTrack * _instrument_track ) :
Instrument( _instrument_track, &sf2player_plugin_descriptor ),
Instrument(_instrument_track, &sf2player_plugin_descriptor, nullptr, Flag::IsSingleStreamed),
m_srcState( nullptr ),
m_synth(nullptr),
m_font( nullptr ),

View File

@@ -80,11 +80,6 @@ public:
QString nodeName() const override;
Flags flags() const override
{
return Flag::IsSingleStreamed;
}
gui::PluginView* instantiateView( QWidget * _parent ) override;
QString getCurrentPatchName();

View File

@@ -152,7 +152,7 @@ private:
VestigeInstrument::VestigeInstrument( InstrumentTrack * _instrument_track ) :
Instrument( _instrument_track, &vestige_plugin_descriptor ),
Instrument(_instrument_track, &vestige_plugin_descriptor, nullptr, Flag::IsSingleStreamed | Flag::IsMidiBased),
m_plugin( nullptr ),
m_pluginMutex(),
m_subWindow( nullptr ),

View File

@@ -70,11 +70,6 @@ public:
virtual void loadFile( const QString & _file );
virtual Flags flags() const
{
return Flag::IsSingleStreamed | Flag::IsMidiBased;
}
virtual bool handleMidiEvent( const MidiEvent& event, const TimePos& time, f_cnt_t offset = 0 );
virtual gui::PluginView* instantiateView( QWidget * _parent );

View File

@@ -97,7 +97,7 @@ private:
};
Vibed::Vibed(InstrumentTrack* instrumentTrack) :
Instrument(instrumentTrack, &vibedstrings_plugin_descriptor)
Instrument(instrumentTrack, &vibedstrings_plugin_descriptor, nullptr, Flag::IsNotBendable)
{
for (int harm = 0; harm < s_stringCount; ++harm)
{

View File

@@ -65,8 +65,6 @@ public:
QString nodeName() const override;
Flags flags() const override { return Flag::IsNotBendable; }
gui::PluginView* instantiateView(QWidget* parent) override;
private:

View File

@@ -103,7 +103,7 @@ bool ZynAddSubFxRemotePlugin::processMessage( const message & _m )
ZynAddSubFxInstrument::ZynAddSubFxInstrument(
InstrumentTrack * _instrumentTrack ) :
Instrument( _instrumentTrack, &zynaddsubfx_plugin_descriptor ),
Instrument(_instrumentTrack, &zynaddsubfx_plugin_descriptor, nullptr, Flag::IsSingleStreamed | Flag::IsMidiBased),
m_hasGUI( false ),
m_plugin( nullptr ),
m_remotePlugin( nullptr ),

View File

@@ -86,11 +86,6 @@ public:
QString nodeName() const override;
Flags flags() const override
{
return Flag::IsSingleStreamed | Flag::IsMidiBased;
}
gui::PluginView* instantiateView( QWidget * _parent ) override;