From acd176eda23d21ff8abd100b3df4e862d3342def Mon Sep 17 00:00:00 2001 From: Paul Giblock Date: Tue, 26 Aug 2008 05:36:26 +0000 Subject: [PATCH] Basic controller deletion support git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1491 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 15 +++++++++++ include/automatable_model.h | 2 +- include/controller.h | 3 --- include/controller_connection.h | 3 +++ include/controller_rack_view.h | 5 +--- include/controller_view.h | 6 ++--- src/core/automatable_model.cpp | 16 ++++++++++++ src/core/controller.cpp | 2 +- src/core/controller_connection.cpp | 24 ++++++++++++----- src/gui/widgets/controller_rack_view.cpp | 22 +++++++--------- src/gui/widgets/controller_view.cpp | 33 +++++++++++++++++++++--- 11 files changed, 95 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 761310b63..cf90f3a6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2008-08-26 Paul Giblock + + * include/controller_connection.h: + * include/controller.h: + * include/controller_rack_view.h: + * include/automatable_model.h: + * include/controller_view.h: + * src/gui/widgets/controller_rack_view.cpp: + * src/gui/widgets/controller_view.cpp: + * src/core/automatable_model.cpp: + * src/core/controller_connection.cpp: + * src/core/controller.cpp: + Add basic support for delete. The controller dialogs probably leak, and + peakController isn't handled yet. + 2008-08-24 Tobias Doerffel * CMakeLists.txt: diff --git a/include/automatable_model.h b/include/automatable_model.h index 979e990c1..605698466 100644 --- a/include/automatable_model.h +++ b/include/automatable_model.h @@ -219,7 +219,7 @@ public slots: virtual void reset( void ); virtual void copyValue( void ); virtual void pasteValue( void ); - + void unlinkControllerConnection( void ); protected: virtual void redoStep( journalEntry & _je ); diff --git a/include/controller.h b/include/controller.h index 7b13f25b2..985c14a16 100644 --- a/include/controller.h +++ b/include/controller.h @@ -149,9 +149,6 @@ signals: // The value changed while the mixer isn't running (i.e: MIDI CC) void valueChanged( void ); - // Allow all attached models to unlink - void destroying( void ); - friend class controllerDialog; } ; diff --git a/include/controller_connection.h b/include/controller_connection.h index e3ff751e6..98618560b 100644 --- a/include/controller_connection.h +++ b/include/controller_connection.h @@ -82,6 +82,9 @@ public: virtual void loadSettings( const QDomElement & _this ); virtual QString nodeName( void ) const; +public slots: + void deleteConnection( void ); + protected: //virtual controllerDialog * createDialog( QWidget * _parent ); controller * m_controller; diff --git a/include/controller_rack_view.h b/include/controller_rack_view.h index c5cfd866d..4ee9c86c4 100644 --- a/include/controller_rack_view.h +++ b/include/controller_rack_view.h @@ -49,16 +49,13 @@ public: public slots: - //void moveUp( effectView * _view ); - //void moveDown( effectView * _view ); - //void deletePlugin( effectView * _view ); + void deleteController( controllerView * _view ); private slots: virtual void update( void ); void addController( void ); - private: /*virtual void modelChanged( void ); diff --git a/include/controller_view.h b/include/controller_view.h index 57e00a6e9..8fac4f9bd 100644 --- a/include/controller_view.h +++ b/include/controller_view.h @@ -59,15 +59,13 @@ public: public slots: void editControls( void ); - //void deletePlugin( void ); + void deleteController( void ); //void displayHelp( void ); void closeControls( void ); signals: - //void moveUp( effectView * _plugin ); - //void moveDown( effectView * _plugin ); - //void deletePlugin( effectView * _plugin ); + void deleteController( controllerView * _view ); protected: diff --git a/src/core/automatable_model.cpp b/src/core/automatable_model.cpp index a743873b3..8212788e2 100644 --- a/src/core/automatable_model.cpp +++ b/src/core/automatable_model.cpp @@ -413,6 +413,9 @@ void automatableModel::setControllerConnection( controllerConnection * _c ) QObject::connect( m_controllerConnection, SIGNAL( valueChanged() ), this, SIGNAL( dataChanged() ) ); + QObject::connect( m_controllerConnection, + SIGNAL( destroyed() ), + this, SLOT( unlinkControllerConnection() ) ); emit dataChanged(); } } @@ -420,6 +423,19 @@ void automatableModel::setControllerConnection( controllerConnection * _c ) +void automatableModel::unlinkControllerConnection( void ) +{ + if( m_controllerConnection ) + { + m_controllerConnection->disconnect( this ); + } + + m_controllerConnection = NULL; +} + + + + void automatableModel::setInitValue( const float _value ) { m_initValue = _value; diff --git a/src/core/controller.cpp b/src/core/controller.cpp index a95765b37..5ac52aaff 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -74,7 +74,7 @@ controller::~controller() engine::getSong()->removeController( this ); } - // TODO: Remove connections + // Remove connections by destroyed signal } diff --git a/src/core/controller_connection.cpp b/src/core/controller_connection.cpp index e6367c16b..813ae62c0 100644 --- a/src/core/controller_connection.cpp +++ b/src/core/controller_connection.cpp @@ -97,22 +97,29 @@ void controllerConnection::setController( controller * _controller ) if( !_controller ) { - m_controller = controller::create( controller::DummyController, NULL ); + m_controller = controller::create( controller::DummyController, NULL ); } else { m_controller = _controller; } - m_controllerId = -1; + m_controllerId = -1; - if( _controller->type() != controller::DummyController ) + if( _controller->type() != controller::DummyController ) { - QObject::connect( _controller, SIGNAL( valueChanged() ), - this, SIGNAL( valueChanged() ) ); - } + QObject::connect( _controller, SIGNAL( valueChanged() ), + this, SIGNAL( valueChanged() ) ); + } m_ownsController = ( _controller->type() == controller::MidiController ); + + // If we don't own the controller, allow deletion of controller + // to delete the connection + if( !m_ownsController ) { + QObject::connect( _controller, SIGNAL( destroyed() ), + this, SLOT( deleteConnection() ) ); + } } @@ -194,7 +201,10 @@ void controllerConnection::loadSettings( const QDomElement & _this ) } - +void controllerConnection::deleteConnection( void ) +{ + delete this; +} QString controllerConnection::nodeName( void ) const { diff --git a/src/gui/widgets/controller_rack_view.cpp b/src/gui/widgets/controller_rack_view.cpp index ec557b036..425b84368 100644 --- a/src/gui/widgets/controller_rack_view.cpp +++ b/src/gui/widgets/controller_rack_view.cpp @@ -149,23 +149,16 @@ void controllerRackView::moveDown( effectView * _view ) }*/ -/* - -void controllerRackView::deletePlugin( effectView * _view ) +void controllerRackView::deleteController( controllerView * _view ) { - effect * e = _view->getEffect(); - m_effectViews.erase( qFind( m_effectViews.begin(), m_effectViews.end(), - _view ) ); + controller * c = _view->getController(); + m_controllerViews.erase( qFind( m_controllerViews.begin(), + m_controllerViews.end(), _view ) ); delete _view; - fxChain()->m_effects.erase( qFind( fxChain()->m_effects.begin(), - fxChain()->m_effects.end(), - e ) ); - delete e; + delete c; update(); - } -*/ @@ -188,6 +181,11 @@ void controllerRackView::update( void ) for( i = 0; i < s->m_controllers.size(); ++i ) { controllerView * v = new controllerView( s->m_controllers[i], w ); + + connect( v, SIGNAL( deleteController( controllerView * ) ), + this, SLOT( deleteController( controllerView * ) ), + Qt::QueuedConnection ); + m_controllerViews.append( v ); v->move( 0, i*32 ); v->show(); diff --git a/src/gui/widgets/controller_view.cpp b/src/gui/widgets/controller_view.cpp index 49657bd52..b8746fabf 100644 --- a/src/gui/widgets/controller_view.cpp +++ b/src/gui/widgets/controller_view.cpp @@ -124,15 +124,13 @@ void controllerView::closeControls( void ) } - - -void controllerView::contextMenuEvent( QContextMenuEvent * ) +void controllerView::deleteController() { + emit( deleteController( this ) ); } - void controllerView::paintEvent( QPaintEvent * ) { QPainter p( this ); @@ -178,6 +176,33 @@ void controllerView::modelChanged( void ) } + +void controllerView::contextMenuEvent( QContextMenuEvent * ) +{ + QPointer contextMenu = new captionMenu( + getModel()->displayName() ); + /* + contextMenu->addAction( embed::getIconPixmap( "arp_up" ), + tr( "Move &up" ), + this, SLOT( moveUp() ) ); + contextMenu->addAction( embed::getIconPixmap( "arp_down" ), + tr( "Move &down" ), + this, SLOT( moveDown() ) ); + contextMenu->addSeparator(); + */ + contextMenu->addAction( embed::getIconPixmap( "cancel" ), + tr( "&Remove this plugin" ), + this, SLOT( deleteController() ) ); + contextMenu->addSeparator(); + contextMenu->addAction( embed::getIconPixmap( "help" ), + tr( "&Help" ), + this, SLOT( displayHelp() ) ); + contextMenu->exec( QCursor::pos() ); + delete contextMenu; +} + + + #include "moc_controller_view.cxx" #endif