Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug introduced by #5657 #5982

Merged
merged 5 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions include/ControllerConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include "JournallingObject.h"
#include "ValueBuffer.h"

class AutomatableModel;
class ControllerConnection;

typedef QVector<ControllerConnection *> ControllerConnectionVector;
Expand All @@ -48,7 +47,7 @@ class LMMS_EXPORT ControllerConnection : public QObject, public JournallingObjec
Q_OBJECT
public:

ControllerConnection(Controller * _controller, AutomatableModel * contmod);
ControllerConnection(Controller * _controller);
ControllerConnection( int _controllerId );

virtual ~ControllerConnection();
Expand Down Expand Up @@ -112,8 +111,6 @@ public slots:

static ControllerConnectionVector s_connections;

AutomatableModel * m_controlledModel;

signals:
// The value changed while the mixer isn't running (i.e: MIDI CC)
void valueChanged();
Expand Down
2 changes: 1 addition & 1 deletion src/core/AutomatableModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void AutomatableModel::loadSettings( const QDomElement& element, const QString&
}
if( thisConnection.isElement() )
{
setControllerConnection(new ControllerConnection((Controller*)NULL, this));
setControllerConnection(new ControllerConnection(nullptr));
m_controllerConnection->loadSettings( thisConnection.toElement() );
//m_controllerConnection->setTargetName( displayName() );
}
Expand Down
11 changes: 2 additions & 9 deletions src/core/ControllerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ ControllerConnectionVector ControllerConnection::s_connections;



ControllerConnection::ControllerConnection(Controller * _controller, AutomatableModel * contmod) :
ControllerConnection::ControllerConnection(Controller * _controller) :
m_controller( NULL ),
m_controllerId( -1 ),
m_ownsController(false),
m_controlledModel(contmod)
m_ownsController(false)
{
if( _controller != NULL )
{
Expand Down Expand Up @@ -124,12 +123,6 @@ void ControllerConnection::setController( Controller * _controller )
m_ownsController =
(_controller->type() == Controller::MidiController);

connect(Engine::getSong(), SIGNAL(stopped()),
m_controlledModel, SLOT(setUseControllerValue()),
Qt::UniqueConnection);

m_controlledModel->setUseControllerValue(true);

// If we don't own the controller, allow deletion of controller
// to delete the connection
if( !m_ownsController ) {
Expand Down
29 changes: 19 additions & 10 deletions src/core/Song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,17 +405,15 @@ void Song::processAutomations(const TrackList &tracklist, TimePos timeStart, fpp
}
}

// Checks if an automated model stopped being automated by automation patterns
// so we can move the control back to any connected controller again
// Moves the control of the models that were processed earlier to their controllers.
// If they get processed again, setAutomatedValue() will move the control back
// to the automation.
if (!m_oldAutomatedValues.isEmpty())
{
for (auto it = m_oldAutomatedValues.begin(); it != m_oldAutomatedValues.end(); it++)
{
AutomatableModel * am = it.key();
if (am->controllerConnection() && !values.contains(am))
{
am->setUseControllerValue(true);
}
am->setUseControllerValue(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setUseControllerValue causes the model to emit its dataChanged signal, so this change means that all automated models will emit that signal twice per buffer (plus an additional third time if their value actually changes). I'm not sure what sort of impact this has, but it may be worth looking at.

}
}
m_oldAutomatedValues = values;
Expand All @@ -427,10 +425,6 @@ void Song::processAutomations(const TrackList &tracklist, TimePos timeStart, fpp
{
it.key()->setAutomatedValue(it.value());
}
else if (!it.key()->useControllerValue())
{
it.key()->setUseControllerValue(true);
}
}
}

Expand Down Expand Up @@ -687,6 +681,18 @@ void Song::stop()
// remove all note-play-handles that are active
Engine::mixer()->clear();

// Moves the control of the models that were processed on the last frame
// back to their controllers.
if (!m_oldAutomatedValues.isEmpty())
{
for (auto it = m_oldAutomatedValues.begin(); it != m_oldAutomatedValues.end(); it++)
{
AutomatableModel * am = it.key();
am->setUseControllerValue(true);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if statement here isn't necessary.

m_oldAutomatedValues.clear();
DomClark marked this conversation as resolved.
Show resolved Hide resolved

m_playMode = Mode_None;

emit stopped();
Expand Down Expand Up @@ -886,6 +892,9 @@ void Song::clearProject()
m_masterPitchModel.reset();
m_timeSigModel.reset();

// Clear the m_oldAutomatedValues AutomatedValueMap
m_oldAutomatedValues.clear();

AutomationPattern::globalAutomationPattern( &m_tempoModel )->clear();
AutomationPattern::globalAutomationPattern( &m_masterVolumeModel )->
clear();
Expand Down
7 changes: 1 addition & 6 deletions src/gui/AutomatableModelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "embed.h"
#include "GuiApplication.h"
#include "MainWindow.h"
#include "Song.h"
#include "StringPairDrag.h"
#include "Clipboard.h"

Expand Down Expand Up @@ -229,7 +228,7 @@ void AutomatableModelViewSlots::execConnectionDialog()
// New
else
{
ControllerConnection* cc = new ControllerConnection(d.chosenController(), m);
ControllerConnection* cc = new ControllerConnection(d.chosenController());
m->setControllerConnection( cc );
//cc->setTargetName( m->displayName() );
}
Expand All @@ -251,12 +250,8 @@ void AutomatableModelViewSlots::removeConnection()

if( m->controllerConnection() )
{
disconnect(Engine::getSong(), SIGNAL(stopped()),
m, SLOT(setUseControllerValue()));

delete m->controllerConnection();
m->setControllerConnection( NULL );
emit m->dataChanged();
}
}

Expand Down