diff --git a/ChangeLog b/ChangeLog index 4fb7249fd..2bd6092ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-08-18 Tobias Doerffel + + * include/controller.h: + * src/core/controller.cpp: + * src/gui/automatable_model_view.cpp: + * src/gui/controller_connection_dialog.cpp: + Detect loops before allowing controller-connection + 2008-08-07 Tobias Doerffel * CMakeLists.txt: diff --git a/include/controller.h b/include/controller.h index d7d25fa7c..d022c88be 100644 --- a/include/controller.h +++ b/include/controller.h @@ -114,6 +114,8 @@ public slots: m_name = _new_name; } + bool hasModel( const model * m ); + protected: // The internal per-controller get-value function diff --git a/src/core/controller.cpp b/src/core/controller.cpp index b0e14a6ad..a95765b37 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -190,6 +190,36 @@ controller * controller::create( const QDomElement & _this, model * _parent ) +bool controller::hasModel( const model * m ) +{ + QObjectList chldren = children(); + for( int i = 0; i < chldren.size(); ++i ) + { + QObject * c = chldren.at(i); + automatableModel * am = qobject_cast(c); + if( am != NULL ) + { + if( am == m ) + { + return true; + } + + controllerConnection * cc = am->getControllerConnection(); + if( cc != NULL ) + { + if( cc->getController()->hasModel( m ) ) + { + return true; + } + } + } + } + + return false; +} + + + void controller::saveSettings( QDomDocument & _doc, QDomElement & _this ) { _this.setAttribute( "type", type() ); diff --git a/src/gui/automatable_model_view.cpp b/src/gui/automatable_model_view.cpp index 4ab3dbc12..cf7d6a8c1 100644 --- a/src/gui/automatable_model_view.cpp +++ b/src/gui/automatable_model_view.cpp @@ -25,7 +25,6 @@ #include #include - #include "automatable_model_view.h" #include "automation_pattern.h" #include "controller_connection_dialog.h" @@ -183,32 +182,33 @@ void automatableModelViewSlots::execConnectionDialog( void ) controllerConnectionDialog * d = new controllerConnectionDialog( (QWidget*)engine::getMainWindow(), m ); - d->exec(); - - // Actually chose something - if (d->chosenController() != NULL ) + if( d->exec() == 1) { - // Update - if( m->getControllerConnection() ) + // Actually chose something + if (d->chosenController() != NULL ) { - m->getControllerConnection()-> - setController( d->chosenController() ); + // Update + if( m->getControllerConnection() ) + { + m->getControllerConnection()-> + setController( d->chosenController() ); + } + // New + else + { + controllerConnection * cc = + new controllerConnection( d->chosenController() ); + m->setControllerConnection( cc ); + //cc->setTargetName( m->displayName() ); + + } } - // New + // no controller, so delete existing connection else { - controllerConnection * cc = - new controllerConnection( d->chosenController() ); - m->setControllerConnection( cc ); - //cc->setTargetName( m->displayName() ); - + removeConnection(); } } - // no controller, so delete existing connection - else - { - removeConnection(); - } delete d; } diff --git a/src/gui/controller_connection_dialog.cpp b/src/gui/controller_connection_dialog.cpp index 1b8f16b95..19e6775cb 100644 --- a/src/gui/controller_connection_dialog.cpp +++ b/src/gui/controller_connection_dialog.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include "controller_connection_dialog.h" #include "controller_connection.h" @@ -327,7 +328,15 @@ void controllerConnectionDialog::selectController( void ) m_controller = engine::getSong()->controllers().at( m_userController->model()->value() ); } + + if( m_controller->hasModel( m_targetModel ) ) + { + QMessageBox::warning(this, tr("LMMS"), tr("Cycle Detected.")); + return; + } + } + accept(); }