Prevent cycles in controller connections.

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1440 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Paul Giblock
2008-08-19 02:51:00 +00:00
parent 275a0d30e2
commit faff20a99b
5 changed files with 69 additions and 20 deletions

View File

@@ -1,3 +1,11 @@
2008-08-18 Tobias Doerffel <tobydox/at/users/dot/sourceforge/dot/net>
* 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 <tobydox/at/users/dot/sourceforge/dot/net>
* CMakeLists.txt:

View File

@@ -114,6 +114,8 @@ public slots:
m_name = _new_name;
}
bool hasModel( const model * m );
protected:
// The internal per-controller get-value function

View File

@@ -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<automatableModel*>(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() );

View File

@@ -25,7 +25,6 @@
#include <QtGui/QMenu>
#include <QtGui/QMouseEvent>
#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;
}

View File

@@ -30,6 +30,7 @@
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QScrollArea>
#include <QMessageBox>
#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();
}