diff --git a/src/core/AutomatableModel.cpp b/src/core/AutomatableModel.cpp index e2a088e04dd..0b2a1522bd4 100644 --- a/src/core/AutomatableModel.cpp +++ b/src/core/AutomatableModel.cpp @@ -110,7 +110,8 @@ void AutomatableModel::saveSettings( QDomDocument& doc, QDomElement& element, co element.setAttribute( name, m_value ); } - if( m_controllerConnection ) + if( m_controllerConnection && m_controllerConnection->getController()->type() + != Controller::DummyController ) { QDomElement controllerElement; diff --git a/src/core/ControllerConnection.cpp b/src/core/ControllerConnection.cpp index 280ed709c24..4f04cbc2096 100644 --- a/src/core/ControllerConnection.cpp +++ b/src/core/ControllerConnection.cpp @@ -162,6 +162,11 @@ void ControllerConnection::finalizeConnections() c->setController( Engine::getSong()-> controllers().at( c->m_controllerId ) ); } + else if (c->getController()->type() == Controller::DummyController) + { + delete c; + --i; + } } } @@ -199,7 +204,7 @@ void ControllerConnection::loadSettings( const QDomElement & _this ) } else { - if( _this.attribute( "id" ).toInt() >= 0 ) + if( _this.attribute( "id", "-1" ).toInt() >= 0 ) { m_controllerId = _this.attribute( "id" ).toInt(); } diff --git a/src/core/Song.cpp b/src/core/Song.cpp index 9936585ab98..be0c7dddc70 100644 --- a/src/core/Song.cpp +++ b/src/core/Song.cpp @@ -1122,6 +1122,11 @@ void Song::loadProject( const QString & fileName ) // now that everything is loaded ControllerConnection::finalizeConnections(); + // Remove dummy controllers that was added for correct connections + m_controllers.erase(std::remove_if(m_controllers.begin(), m_controllers.end(), + [](Controller* c){return c->type() == Controller::DummyController;}), + m_controllers.end()); + // resolve all IDs so that autoModels are automated AutomationPattern::resolveAllIDs(); @@ -1289,9 +1294,13 @@ void Song::restoreControllerStates( const QDomElement & element ) while( !node.isNull() && !isCancelled() ) { Controller * c = Controller::create( node.toElement(), this ); - Q_ASSERT( c != NULL ); - - addController( c ); + if (c) {addController(c);} + else + { + // Fix indices to ensure correct connections + m_controllers.append(Controller::create( + Controller::DummyController, this)); + } node = node.nextSibling(); }