From ca3a7f3015f2d4284874ae357130f9854f1ca143 Mon Sep 17 00:00:00 2001 From: Colin Wallace Date: Wed, 28 Mar 2018 00:03:10 -0700 Subject: [PATCH] Remove unused method and extraneous state from AutomatableModelView (#4258) * Remove DataType. An AutomatableModel should not need to know what concrete type it is. Use virtual methods and implement them in the derived class instead of testing the type in the base class. * Remove unused method * Remove m_hasLinkedModels We can compute it on-the-fly with very little cost, and doing so simplifies the code. * Remove extra 'public:' Probably a remnant of merging master --- include/AutomatableModel.h | 45 +++++++++++++---------------------- src/core/AutomatableModel.cpp | 39 ++++++++++++++---------------- 2 files changed, 35 insertions(+), 49 deletions(-) diff --git a/include/AutomatableModel.h b/include/AutomatableModel.h index ae9d56951..b04f3da9c 100644 --- a/include/AutomatableModel.h +++ b/include/AutomatableModel.h @@ -77,21 +77,6 @@ public: Decibel }; - enum DataType - { - Float, - Integer, - Bool - } ; - - AutomatableModel( DataType type, - const float val = 0, - const float min = 0, - const float max = 0, - const float step = 0, - Model* parent = NULL, - const QString& displayName = QString(), - bool defaultConstructed = false ); virtual ~AutomatableModel(); @@ -127,7 +112,7 @@ public: template inline T value( int frameOffset = 0 ) const { - if( unlikely( m_hasLinkedModels || m_controllerConnection != NULL ) ) + if( unlikely( hasLinkedModels() || m_controllerConnection != NULL ) ) { return castValue( controllerValue( frameOffset ) ); } @@ -239,11 +224,11 @@ public: return "automatablemodel"; } - QString displayValue( const float val ) const; + virtual QString displayValue( const float val ) const = 0; bool hasLinkedModels() const { - return m_hasLinkedModels; + return !m_linkedModels.empty(); } // a way to track changed values in the model and avoid using signals/slots - useful for speed-critical code. @@ -261,11 +246,6 @@ public: float globalAutomationValueAt( const MidiTime& time ); - bool hasStrictStepSize() const - { - return m_hasStrictStepSize; - } - void setStrictStepSize( const bool b ) { m_hasStrictStepSize = b; @@ -287,6 +267,14 @@ public slots: protected: + AutomatableModel( + const float val = 0, + const float min = 0, + const float max = 0, + const float step = 0, + Model* parent = NULL, + const QString& displayName = QString(), + bool defaultConstructed = false ); //! returns a value which is in range between min() and //! max() and aligned according to the step size (step size 0.05 -> value //! 0.12345 becomes 0.10 etc.). You should always call it at the end after @@ -317,7 +305,6 @@ private: template void roundAt( T &value, const T &where ) const; - DataType m_dataType; ScaleType m_scaleType; //! scale type, linear by default float m_value; float m_initValue; @@ -338,7 +325,6 @@ private: bool m_hasStrictStepSize; AutoModelVector m_linkedModels; - bool m_hasLinkedModels; //! NULL if not appended to controller, otherwise connection info @@ -399,11 +385,12 @@ public: Model * parent = NULL, const QString& displayName = QString(), bool defaultConstructed = false ) : - TypedAutomatableModel( Float, val, min, max, step, parent, displayName, defaultConstructed ) + TypedAutomatableModel( val, min, max, step, parent, displayName, defaultConstructed ) { } float getRoundedValue() const; int getDigitCount() const; + QString displayValue( const float val ) const override; } ; @@ -415,9 +402,10 @@ public: Model* parent = NULL, const QString& displayName = QString(), bool defaultConstructed = false ) : - TypedAutomatableModel( Integer, val, min, max, 1, parent, displayName, defaultConstructed ) + TypedAutomatableModel( val, min, max, 1, parent, displayName, defaultConstructed ) { } + QString displayValue( const float val ) const override; } ; @@ -429,9 +417,10 @@ public: Model* parent = NULL, const QString& displayName = QString(), bool defaultConstructed = false ) : - TypedAutomatableModel( Bool, val, false, true, 1, parent, displayName, defaultConstructed ) + TypedAutomatableModel( val, false, true, 1, parent, displayName, defaultConstructed ) { } + QString displayValue( const float val ) const override; } ; typedef QMap AutomatedValueMap; diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 7c16179fd..425ec59ef 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -35,11 +35,10 @@ long AutomatableModel::s_periodCounter = 0; -AutomatableModel::AutomatableModel( DataType type, +AutomatableModel::AutomatableModel( const float val, const float min, const float max, const float step, Model* parent, const QString & displayName, bool defaultConstructed ) : Model( parent, displayName, defaultConstructed ), - m_dataType( type ), m_scaleType( Linear ), m_minValue( min ), m_maxValue( max ), @@ -49,7 +48,6 @@ AutomatableModel::AutomatableModel( DataType type, m_valueChanged( false ), m_setValueDepth( 0 ), m_hasStrictStepSize( false ), - m_hasLinkedModels( false ), m_controllerConnection( NULL ), m_valueBuffer( static_cast( Engine::mixer()->framesPerPeriod() ) ), m_lastUpdatedPeriod( -1 ), @@ -272,19 +270,6 @@ float AutomatableModel::inverseScaledValue( float value ) const -QString AutomatableModel::displayValue( const float val ) const -{ - switch( m_dataType ) - { - case Float: return QString::number( castValue( scaledValue( val ) ) ); - case Integer: return QString::number( castValue( scaledValue( val ) ) ); - case Bool: return QString::number( castValue( scaledValue( val ) ) ); - } - return "0"; -} - - - //! @todo: this should be moved into a maths header template void roundAt( T& value, const T& where, const T& step_size ) @@ -410,7 +395,6 @@ void AutomatableModel::linkModel( AutomatableModel* model ) if( !m_linkedModels.contains( model ) && model != this ) { m_linkedModels.push_back( model ); - m_hasLinkedModels = true; if( !model->hasLinkedModels() ) { @@ -429,7 +413,6 @@ void AutomatableModel::unlinkModel( AutomatableModel* model ) { m_linkedModels.erase( it ); } - m_hasLinkedModels = !m_linkedModels.isEmpty(); } @@ -461,8 +444,6 @@ void AutomatableModel::unlinkAllModels() { unlinkModels( this, model ); } - - m_hasLinkedModels = false; } @@ -565,7 +546,7 @@ ValueBuffer * AutomatableModel::valueBuffer() } } AutomatableModel* lm = NULL; - if( m_hasLinkedModels ) + if( hasLinkedModels() ) { lm = m_linkedModels.first(); } @@ -712,3 +693,19 @@ int FloatModel::getDigitCount() const return digits; } + + +QString FloatModel::displayValue( const float val ) const +{ + return QString::number( castValue( scaledValue( val ) ) ); +} + +QString IntModel::displayValue( const float val ) const +{ + return QString::number( castValue( scaledValue( val ) ) ); +} + +QString BoolModel::displayValue( const float val ) const +{ + return QString::number( castValue( scaledValue( val ) ) ); +}