diff --git a/include/AutomatableModel.h b/include/AutomatableModel.h index d9dfb86d458..db6216fc4bb 100644 --- a/include/AutomatableModel.h +++ b/include/AutomatableModel.h @@ -151,7 +151,7 @@ class LMMS_EXPORT AutomatableModel : public Model, public JournallingObject { if (m_controllerConnection) { - if (m_controllerConnection->isControllerMidi() && !m_controllerValue) + if (m_controllerConnection->isControllerMidi() && !m_useControllerValue) { return castValue(m_value); } @@ -310,19 +310,15 @@ class LMMS_EXPORT AutomatableModel : public Model, public JournallingObject s_periodCounter = 0; } - bool isControllerValue() + bool useControllerValue() { - return m_controllerValue; - } - void setControllerValue(bool b) - { - m_controllerValue = b; + return m_useControllerValue; } public slots: virtual void reset(); void unlinkControllerConnection(); - void setAndEmitControllerValue(); + void setUseControllerValue(bool b = true); protected: @@ -417,7 +413,7 @@ public slots: // prevent several threads from attempting to write the same vb at the same time QMutex m_valueBufferMutex; - bool m_controllerValue; + bool m_useControllerValue; signals: void initValueChanged( float val ); diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index 4c215d79f1a..d72c9539800 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -54,7 +54,7 @@ AutomatableModel::AutomatableModel( m_valueBuffer( static_cast( Engine::mixer()->framesPerPeriod() ) ), m_lastUpdatedPeriod( -1 ), m_hasSampleExactData(false), - m_controllerValue(true) + m_useControllerValue(true) { m_value = fittedValue( val ); @@ -372,14 +372,8 @@ void AutomatableModel::roundAt( T& value, const T& where ) const void AutomatableModel::setAutomatedValue( const float value ) { - bool emitDataChanged = false; - - if (m_controllerConnection && m_controllerValue && m_controllerConnection->isControllerMidi()) - { - m_controllerValue = false; - emitDataChanged = true; - } - + setUseControllerValue(false); + m_oldValue = m_value; ++m_setValueDepth; const float oldValue = m_value; @@ -401,10 +395,8 @@ void AutomatableModel::setAutomatedValue( const float value ) } } m_valueChanged = true; - emitDataChanged = true; + emit dataChanged(); } - - if (emitDataChanged) {emit dataChanged();} --m_setValueDepth; } @@ -595,7 +587,7 @@ float AutomatableModel::controllerValue( int frameOffset ) const } AutomatableModel* lm = m_linkedModels.first(); - if (lm->controllerConnection() && lm->isControllerValue()) + if (lm->controllerConnection() && lm->useControllerValue()) { return fittedValue( lm->controllerValue( frameOffset ) ); } @@ -618,7 +610,7 @@ ValueBuffer * AutomatableModel::valueBuffer() float val = m_value; // make sure our m_value doesn't change midway ValueBuffer * vb; - if (m_controllerConnection && m_controllerValue && m_controllerConnection->getController()->isSampleExact()) + if (m_controllerConnection && m_useControllerValue && m_controllerConnection->getController()->isSampleExact()) { vb = m_controllerConnection->valueBuffer(); if( vb ) @@ -657,7 +649,7 @@ ValueBuffer * AutomatableModel::valueBuffer() { lm = m_linkedModels.first(); } - if (lm && lm->controllerConnection() && lm->isControllerValue() && + if (lm && lm->controllerConnection() && lm->useControllerValue() && lm->controllerConnection()->getController()->isSampleExact()) { vb = lm->valueBuffer(); @@ -782,10 +774,19 @@ float AutomatableModel::globalAutomationValueAt( const MidiTime& time ) } } -void AutomatableModel::setAndEmitControllerValue() +void AutomatableModel::setUseControllerValue(bool b) { - m_controllerValue = true; - emit dataChanged(); + if (b) + { + m_useControllerValue = true; + emit dataChanged(); + } + else if (m_controllerConnection && m_useControllerValue && m_controllerConnection->isControllerMidi()) + { + m_useControllerValue = false; + emit dataChanged(); + } + } float FloatModel::getRoundedValue() const diff --git a/src/core/ControllerConnection.cpp b/src/core/ControllerConnection.cpp index f4597fea5e3..bec05707983 100644 --- a/src/core/ControllerConnection.cpp +++ b/src/core/ControllerConnection.cpp @@ -125,7 +125,7 @@ void ControllerConnection::setController( Controller * _controller ) { connect(Engine::getSong(), SIGNAL(stopped()), - m_controlledModel, SLOT(setAndEmitControllerValue()), + m_controlledModel, SLOT(setUseControllerValue()), Qt::UniqueConnection); m_ownsController = true; @@ -136,7 +136,7 @@ void ControllerConnection::setController( Controller * _controller ) m_ownsController = false; m_controllerMidi = false; } - m_controlledModel->setControllerValue(true); + m_controlledModel->setUseControllerValue(true); // If we don't own the controller, allow deletion of controller // to delete the connection diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 0f7c1675778..58ce6b0062e 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -477,7 +477,7 @@ void Song::processAutomations(const TrackList &tracklist, MidiTime timeStart, fp am->controllerConnection()->isControllerMidi() && !values.contains(am)) { - am->setAndEmitControllerValue(); + am->setUseControllerValue(true); } } } @@ -490,9 +490,9 @@ void Song::processAutomations(const TrackList &tracklist, MidiTime timeStart, fp { it.key()->setAutomatedValue(it.value()); } - else if (!it.key()->isControllerValue()) + else if (!it.key()->useControllerValue()) { - it.key()->setAndEmitControllerValue(); + it.key()->setUseControllerValue(true); } } } diff --git a/src/gui/AutomatableModelView.cpp b/src/gui/AutomatableModelView.cpp index 59349f915b1..f0d7dc9d5ef 100644 --- a/src/gui/AutomatableModelView.cpp +++ b/src/gui/AutomatableModelView.cpp @@ -269,7 +269,7 @@ void AutomatableModelViewSlots::pasteFromClipboard() void AutomatableModelViewSlots::disconnectStopSignalMidi(AutomatableModel * autmod) { disconnect(Engine::getSong(), SIGNAL(stopped()), - autmod, SLOT(setAndEmitControllerValue())); + autmod, SLOT(setUseControllerValue())); } /// Attempt to parse a float from the clipboard