add class controllerConnection to model link between models and controllers

git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1023 0778d3d1-df1d-0410-868b-ea421aaaa00d
This commit is contained in:
Paul Giblock
2008-05-26 06:16:49 +00:00
parent f3168bac1b
commit 79905590da
10 changed files with 334 additions and 19 deletions

View File

@@ -45,9 +45,11 @@ QVector<controller *> controller::s_controllers;
controller::controller( ControllerTypes _type, model * _parent ) :
model( _parent ),
journallingObject(),
m_type( _type )
{
s_controllers.append( this );
if( _type != DummyController )
s_controllers.append( this );
}
@@ -60,6 +62,8 @@ controller::~controller()
{
engine::getSong()->removeController( this );
}
// TODO: Remove connections
}

View File

@@ -0,0 +1,159 @@
#ifndef SINGLE_SOURCE_COMPILE
/*
* controller_connection.cpp - implementation of class controller connection
* which handles the link between automatableModels and controllers
*
* Copyright (c) 2008 Paul Giblock <drfaygo/at/gmail.com>
*
* This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
*/
#include <Qt/QtXml>
#include <QtCore/QObject>
#include <QtCore/QVector>
#include "song.h"
#include "engine.h"
#include "mixer.h"
#include "controller_connection.h"
controllerConnectionVector controllerConnection::s_connections;
controller * controllerConnection::s_dummyController = NULL;
controllerConnection::controllerConnection( controller * _controller ) :
m_controllerId( -1 )
{
setController( _controller );
s_connections.append( this );
}
controllerConnection::controllerConnection( int _controllerId ) :
m_controller( dummyController() ),
m_controllerId( _controllerId )
{
s_connections.append( this );
}
controllerConnection::~controllerConnection()
{
s_connections.remove( s_connections.indexOf( this ) );
}
void controllerConnection::setController( int _controllerId )
{
}
void controllerConnection::setController( controller * _controller )
{
m_controller = _controller;
m_controllerId = -1;
if( _controller->type() != controller::DummyController ) {
QObject::connect( _controller, SIGNAL( valueChanged() ),
this, SIGNAL( valueChanged() ) );
}
}
void controllerConnection::finalizeConnections( void )
{
for( int i = 0; i < s_connections.size(); ++i )
{
controllerConnection * c = s_connections[i];
if ( !c->isFinalized() )
{
c->setController( engine::getSong()->controllers().at( c->m_controllerId ) );
}
}
}
void controllerConnection::saveSettings( QDomDocument & _doc, QDomElement & _this )
{
if( engine::getSong() ) {
int id = engine::getSong()->controllers().indexOf( m_controller );
_this.setAttribute( "id", id );
}
}
void controllerConnection::loadSettings( const QDomElement & _this )
{
if( _this.attribute( "id" ).toInt() >= 0 )
{
m_controllerId = _this.attribute( "id" ).toInt();
m_controller = dummyController();
}
else
{
qWarning( "controller index invalid\n" );
m_controllerId = -1;
m_controller = dummyController();
}
}
controller * controllerConnection::dummyController()
{
if( s_dummyController == NULL )
{
s_dummyController = new controller( controller::DummyController, NULL );
}
return s_dummyController;
}
QString controllerConnection::nodeName( void ) const
{
return( "connection" );
}
/*
controllerDialog * controller::createDialog( QWidget * _parent )
{
controllerDialog * d = new controllerDialog( this, _parent );
return d;
}
*/
#include "controller_connection.moc"
#endif

View File

@@ -49,6 +49,7 @@
#include "bb_track_container.h"
#include "config_mgr.h"
#include "controller_rack_view.h"
#include "controller_connection.h"
#include "embed.h"
#include "envelope_and_lfo_parameters.h"
#include "export_project_dialog.h"
@@ -727,12 +728,6 @@ void song::clearProject( void )
{
delete m_controllers.last();
}
/* if( engine::getControllerRackView() )
{
engine::getControllerRackView()->update();
}*/
emit dataChanged();
engine::getProjectJournal()->clearInvalidJournallingObjects();
engine::getProjectJournal()->clearJournal();
@@ -906,6 +901,10 @@ void FASTCALL song::loadProject( const QString & _file_name )
node = node.nextSibling();
}
// Connect controller links to their controllers
// now that everything is loaded
controllerConnection::finalizeConnections();
configManager::inst()->addRecentlyOpenedProject( _file_name );
engine::getProjectJournal()->setJournalling( TRUE );

View File

@@ -56,6 +56,7 @@
#include "text_float.h"
#include "song.h"
#include "controller_connection_dialog.h"
#include "controller_connection.h"
float knob::s_copiedValue = 0.0f;
@@ -737,7 +738,8 @@ void knob::connectToController( void )
if (d->chosenController() != NULL )
{
model()->setController( d->chosenController() );
model()->setControllerConnection(
new controllerConnection( d->chosenController() ) );
}
delete d;
@@ -747,7 +749,7 @@ void knob::connectToController( void )
void knob::friendlyUpdate( void )
{
if( model()->getController() == NULL || controller::runningFrames() % (256*4) == 0 )
if( model()->getControllerConnection() == NULL || controller::runningFrames() % (256*4) == 0 )
{
update();
}