From 1c66bb9d661680fb47098431ce6adeb594f8e2d6 Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Sat, 8 Mar 2014 12:47:42 +0100 Subject: [PATCH] Instrument: introduced flags to replace virtual property getters There'll be more and more flags for instruments. Handling them using virtual and overloaded getter functions doesn't scale well and adds unneccessary overhead. --- include/Instrument.h | 24 ++++++++++++++---------- plugins/opl2/opl2instrument.h | 5 ++++- plugins/sf2_player/sf2_player.h | 6 +++--- plugins/vestige/vestige.h | 4 ++-- plugins/vibed/vibed.h | 5 +++-- plugins/zynaddsubfx/ZynAddSubFx.h | 4 ++-- src/tracks/InstrumentTrack.cpp | 2 +- 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/Instrument.h b/include/Instrument.h index c937cf064..987d1429f 100644 --- a/include/Instrument.h +++ b/include/Instrument.h @@ -44,6 +44,16 @@ class track; class EXPORT Instrument : public Plugin { public: + enum Flag + { + NoFlags = 0x00, + IsSingleStreamed = 0x01, /*! Instrument provides a single audio stream for all notes */ + IsMidiBased = 0x02, /*! Instrument is controlled by MIDI events rather than NotePlayHandles */ + IsNotBendable = 0x04, /*! Instrument can't react to pitch bend changes */ + }; + + Q_DECLARE_FLAGS(Flags, Flag); + Instrument( InstrumentTrack * _instrument_track, const Descriptor * _descriptor ); virtual ~Instrument(); @@ -84,17 +94,9 @@ public: return 0; } - // return false if instrument is not bendable - inline virtual bool isBendable() const + virtual Flags flags() const { - return true; - } - - // return true if instruments reacts to MIDI events passed to - // handleMidiEvent() rather than playNote() & Co - inline virtual bool isMidiBased() const - { - return false; + return NoFlags; } // sub-classes can re-implement this for receiving all incoming @@ -135,4 +137,6 @@ private: } ; +Q_DECLARE_OPERATORS_FOR_FLAGS(Instrument::Flags) + #endif diff --git a/plugins/opl2/opl2instrument.h b/plugins/opl2/opl2instrument.h index 016717b10..e95357807 100644 --- a/plugins/opl2/opl2instrument.h +++ b/plugins/opl2/opl2instrument.h @@ -48,7 +48,10 @@ public: virtual QString nodeName() const; virtual PluginView * instantiateView( QWidget * _parent ); - inline virtual bool isMidiBased() const { return true; } + virtual Flags flags() const + { + return IsSingleStreamed | IsMidiBased; + } virtual bool handleMidiEvent( const MidiEvent& event, const MidiTime& time ); virtual void play( sampleFrame * _working_buffer ); diff --git a/plugins/sf2_player/sf2_player.h b/plugins/sf2_player/sf2_player.h index 4ff8f0cc5..e27aa8a8a 100644 --- a/plugins/sf2_player/sf2_player.h +++ b/plugins/sf2_player/sf2_player.h @@ -2,7 +2,7 @@ * sf2_player.h - a soundfont2 player using fluidSynth * * Copyright (c) 2008 Paul Giblock - * Copyright (c) 2009-2013 Tobias Doerffel + * Copyright (c) 2009-2014 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -77,9 +77,9 @@ public: return 0; } - virtual bool isMidiBased() const + virtual Flags flags() const { - return true; + return IsSingleStreamed | IsMidiBased; } virtual PluginView * instantiateView( QWidget * _parent ); diff --git a/plugins/vestige/vestige.h b/plugins/vestige/vestige.h index b3e670305..b4b063a6a 100644 --- a/plugins/vestige/vestige.h +++ b/plugins/vestige/vestige.h @@ -63,9 +63,9 @@ public: virtual void loadFile( const QString & _file ); - virtual bool isMidiBased( void ) const + virtual Flags flags() const { - return true; + return IsSingleStreamed | IsMidiBased; } virtual bool handleMidiEvent( const MidiEvent& event, const MidiTime& time ); diff --git a/plugins/vibed/vibed.h b/plugins/vibed/vibed.h index b8002ac9c..cb59da15e 100644 --- a/plugins/vibed/vibed.h +++ b/plugins/vibed/vibed.h @@ -52,11 +52,12 @@ public: virtual QString nodeName() const; - inline virtual bool isBendable() const + virtual Flags flags() const { - return( false ); + return IsNotBendable; } + virtual PluginView * instantiateView( QWidget * _parent ); diff --git a/plugins/zynaddsubfx/ZynAddSubFx.h b/plugins/zynaddsubfx/ZynAddSubFx.h index 46230d5bf..cb35b4ce5 100644 --- a/plugins/zynaddsubfx/ZynAddSubFx.h +++ b/plugins/zynaddsubfx/ZynAddSubFx.h @@ -80,9 +80,9 @@ public: virtual QString nodeName() const; - virtual bool isMidiBased() const + virtual Flags flags() const { - return true; + return IsSingleStreamed | IsMidiBased; } virtual PluginView * instantiateView( QWidget * _parent ); diff --git a/src/tracks/InstrumentTrack.cpp b/src/tracks/InstrumentTrack.cpp index d36cf17e3..1e8655996 100644 --- a/src/tracks/InstrumentTrack.cpp +++ b/src/tracks/InstrumentTrack.cpp @@ -1319,7 +1319,7 @@ void InstrumentTrackWindow::modelChanged() m_effectChannelNumber->setModel( &m_track->m_effectChannelModel ); m_pianoView->setModel( &m_track->m_piano ); - if( m_track->instrument() && m_track->instrument()->isBendable() ) + if( m_track->instrument() && m_track->instrument()->flags().testFlag( Instrument::IsNotBendable ) == false ) { m_pitchKnob->setModel( &m_track->m_pitchModel ); m_pitchRangeSpinBox->setModel( &m_track->m_pitchRangeModel );