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
This commit is contained in:
Colin Wallace
2018-03-28 00:03:10 -07:00
committed by GitHub
parent 47ab8edef8
commit ca3a7f3015
2 changed files with 35 additions and 49 deletions

View File

@@ -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<class T>
inline T value( int frameOffset = 0 ) const
{
if( unlikely( m_hasLinkedModels || m_controllerConnection != NULL ) )
if( unlikely( hasLinkedModels() || m_controllerConnection != NULL ) )
{
return castValue<T>( 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<class T> 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<AutomatableModel*, float> AutomatedValueMap;

View File

@@ -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<int>( 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<float>( scaledValue( val ) ) );
case Integer: return QString::number( castValue<int>( scaledValue( val ) ) );
case Bool: return QString::number( castValue<bool>( scaledValue( val ) ) );
}
return "0";
}
//! @todo: this should be moved into a maths header
template<class T>
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<float>( scaledValue( val ) ) );
}
QString IntModel::displayValue( const float val ) const
{
return QString::number( castValue<int>( scaledValue( val ) ) );
}
QString BoolModel::displayValue( const float val ) const
{
return QString::number( castValue<bool>( scaledValue( val ) ) );
}