Skip to content

Commit

Permalink
improved version of PR LMMS#5657
Browse files Browse the repository at this point in the history
  • Loading branch information
serdnab committed Jan 14, 2021
1 parent e65e12a commit 4c3b5c8
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 33 deletions.
14 changes: 5 additions & 9 deletions include/AutomatableModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(m_value);
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 );
Expand Down
37 changes: 19 additions & 18 deletions src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ AutomatableModel::AutomatableModel(
m_valueBuffer( static_cast<int>( Engine::mixer()->framesPerPeriod() ) ),
m_lastUpdatedPeriod( -1 ),
m_hasSampleExactData(false),
m_controllerValue(true)
m_useControllerValue(true)

{
m_value = fittedValue( val );
Expand Down Expand Up @@ -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;
Expand All @@ -401,10 +395,8 @@ void AutomatableModel::setAutomatedValue( const float value )
}
}
m_valueChanged = true;
emitDataChanged = true;
emit dataChanged();
}

if (emitDataChanged) {emit dataChanged();}
--m_setValueDepth;
}

Expand Down Expand Up @@ -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 ) );
}
Expand All @@ -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 )
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/ControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ void Song::processAutomations(const TrackList &tracklist, MidiTime timeStart, fp
am->controllerConnection()->isControllerMidi() &&
!values.contains(am))
{
am->setAndEmitControllerValue();
am->setUseControllerValue(true);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/AutomatableModelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c3b5c8

Please sign in to comment.