From fc0e68d7b23da73606dc109b9925cfd341794403 Mon Sep 17 00:00:00 2001 From: Paul Giblock Date: Mon, 2 Jun 2008 22:26:39 +0000 Subject: [PATCH] Update default context menu for controllers git-svn-id: https://lmms.svn.sf.net/svnroot/lmms/trunk/lmms@1058 0778d3d1-df1d-0410-868b-ea421aaaa00d --- ChangeLog | 16 ++++ Makefile.am | 1 + include/automatable_model_view.h | 23 +++++- include/knob.h | 1 - include/midi_controller.h | 2 + src/core/midi/midi_controller.cpp | 5 +- src/gui/automatable_model_view.cpp | 113 ++++++++++++++++++++++++++++- src/gui/widgets/knob.cpp | 37 +--------- 8 files changed, 155 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3c48788d8..1ac6ada49 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,22 @@ * src/gui/main_window.cpp: Support loading of sf2 files from the sidebar sample browser + * include/knob.h: + * include/automatable_model_view.h: + * src/gui/automatable_model_view.cpp: + * src/gui/widgets/knob.cpp: + * Makefile.am: + - move context menu stuff to automatableModelView + - add automatableModelViewSlots for slots we may wish to call from AMV + + * include/midi_controller.h: + code style + + * src/core/midi/midi_controller.cpp: + name midiControllers after their channel/controller + + + 2008-06-02 Tobias Doerffel * src/core/mixer.cpp: diff --git a/Makefile.am b/Makefile.am index ba8ac198f..520bd98e5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,6 +51,7 @@ man1_MANS = lmms.1 lmms_MOC = \ ./about_dialog.moc \ ./automatable_model.moc \ + ./automatable_model_view.moc \ ./automatable_button.moc \ ./automatable_slider.moc \ ./automation_editor.moc \ diff --git a/include/automatable_model_view.h b/include/automatable_model_view.h index a94c245d9..5cc7894cb 100644 --- a/include/automatable_model_view.h +++ b/include/automatable_model_view.h @@ -81,18 +81,37 @@ public: } - protected: void addDefaultActions( QMenu * _menu ); - QString m_description; QString m_unit; +} ; + + + + +class automatableModelViewSlots : public QObject +{ + Q_OBJECT +public: + automatableModelViewSlots( + automatableModelView * _amv, + QObject * _parent ); + +public slots: + void execConnectionDialog( void ); + void removeConnection( void ); + +protected: + automatableModelView * amv; } ; + + #define generateTypedModelView(type) \ class EXPORT type##ModelView : public automatableModelView \ {\ diff --git a/include/knob.h b/include/knob.h index 32421e297..efaeaec8a 100644 --- a/include/knob.h +++ b/include/knob.h @@ -100,7 +100,6 @@ public: public slots: virtual void enterValue( void ); void connectToMidiDevice( void ); - void connectToController( void ); void displayHelp( void ); void friendlyUpdate( void ); diff --git a/include/midi_controller.h b/include/midi_controller.h index ce3b4e62b..34785afde 100644 --- a/include/midi_controller.h +++ b/include/midi_controller.h @@ -49,6 +49,8 @@ public: return "MIDI Controller"; } + + virtual void processInEvent( const midiEvent & _me, const midiTime & _time, bool _lock = TRUE ); diff --git a/src/core/midi/midi_controller.cpp b/src/core/midi/midi_controller.cpp index a2efc8990..cca192a61 100644 --- a/src/core/midi/midi_controller.cpp +++ b/src/core/midi/midi_controller.cpp @@ -79,6 +79,9 @@ float midiController::value( int _offset ) void midiController::updateMidiPort( void ) { m_midiPort->setInputChannel( m_midiChannel.value() - 1 ); + setName( QString("MIDI ch%1 ctrl%2"). + arg( m_midiChannel.value() ). + arg( m_midiController.value() ) ); } @@ -95,7 +98,7 @@ void midiController::processInEvent( const midiEvent & _me, bytes = _me.m_data.m_bytes; controllerNum = _me.m_data.m_bytes[0] & 0x7F; - if( m_midiController.value() == controllerNum + 1 && + if( m_midiController.value() == controllerNum + 1 && ( m_midiChannel.value() == _me.m_channel + 1 || m_midiChannel.value() == 0 ) ) { diff --git a/src/gui/automatable_model_view.cpp b/src/gui/automatable_model_view.cpp index b8fdb7b45..5be1b4967 100644 --- a/src/gui/automatable_model_view.cpp +++ b/src/gui/automatable_model_view.cpp @@ -28,13 +28,20 @@ #include "automatable_model_view.h" #include "automation_pattern.h" +#include "controller_connection_dialog.h" +#include "controller_connection.h" #include "embed.h" + + void automatableModelView::addDefaultActions( QMenu * _menu ) { automatableModel * _model = modelUntyped(); + automatableModelViewSlots * amvSlots = + new automatableModelViewSlots( this, _menu ); + _menu->addAction( embed::getIconPixmap( "reload" ), automatableModel::tr( "&Reset (%1%2)" ). arg( _model->displayValue( @@ -66,10 +73,108 @@ void automatableModelView::addDefaultActions( QMenu * _menu ) _menu->addSeparator(); } - _menu->addAction( embed::getIconPixmap( "controller" ), - automatableModel::tr( "Connect to controller..." ), - dynamic_cast( this ), - SLOT( connectToController() ) ); + QString controllerTxt; + if( _model->getControllerConnection() ) + { + controller * cont = _model->getControllerConnection()->getController(); + if( cont ) + { + controllerTxt = automatableModel::tr("Connected to %1"). + arg( cont->name() ); + } + else + { + controllerTxt = automatableModel::tr("Connected to controller"); + } + + QMenu * contMenu = _menu->addMenu( embed::getIconPixmap( "controller" ), + controllerTxt ); + + contMenu->addAction( embed::getIconPixmap( "controller" ), + automatableModel::tr("Edit connection..."), + amvSlots, + SLOT( execConnectionDialog() ) ); + contMenu->addAction( embed::getIconPixmap( "cancel" ), + automatableModel::tr("Remove connection"), + amvSlots, + SLOT( removeConnection() ) ); + } + else + { + _menu->addAction( embed::getIconPixmap( "controller" ), + automatableModel::tr("Connect to controller..."), + amvSlots, + SLOT( execConnectionDialog() ) ); + } } + + +automatableModelViewSlots::automatableModelViewSlots( + automatableModelView * _amv, + QObject * _parent ) : + QObject(), + amv( _amv ) +{ + QObject::connect( _parent, SIGNAL( destroyed() ), + this, SLOT( deleteLater() ), + Qt::QueuedConnection ); +} + + + + +void automatableModelViewSlots::execConnectionDialog( void ) +{ + // TODO[pg]: Display a dialog with list of controllers currently in the song + // in addition to any system MIDI controllers + automatableModel * m = amv->modelUntyped(); + + controllerConnectionDialog * d = new controllerConnectionDialog( + (QWidget*)engine::getMainWindow(), + m->getControllerConnection() ); + + d->exec(); + + // Actually chose something + if (d->chosenController() != NULL ) + { + // Update + if( m->getControllerConnection() ) + { + m->getControllerConnection()-> + setController( d->chosenController() ); + } + // New + else + { + m->setControllerConnection( + new controllerConnection( d->chosenController() ) ); + } + } + // no controller, so delete existing connection + else + { + removeConnection(); + } + + delete d; +} + + + + +void automatableModelViewSlots::removeConnection( void ) +{ + automatableModel * m = amv->modelUntyped(); + + if( m->getControllerConnection() ) + { + delete m->getControllerConnection(); + m->setControllerConnection( NULL ); + } +} + + +#include "automatable_model_view.moc" diff --git a/src/gui/widgets/knob.cpp b/src/gui/widgets/knob.cpp index de4720ca6..8672b4479 100644 --- a/src/gui/widgets/knob.cpp +++ b/src/gui/widgets/knob.cpp @@ -54,8 +54,6 @@ #include "templates.h" #include "text_float.h" #include "song.h" -#include "controller_connection_dialog.h" -#include "controller_connection.h" textFloat * knob::s_textFloat = NULL; @@ -686,39 +684,6 @@ void knob::connectToMidiDevice( void ) } -void knob::connectToController( void ) -{ - // TODO[pg]: Display a dialog with list of controllers currently in the song - // in addition to any system MIDI controllers - - controllerConnectionDialog * d = new controllerConnectionDialog( - engine::getMainWindow(), - model()->getControllerConnection() ); - - d->exec(); - - if (d->chosenController() != NULL ) - { - if( model()->getControllerConnection() ) - { - model()->getControllerConnection()-> - setController( d->chosenController() ); - } - else - { - model()->setControllerConnection( - new controllerConnection( d->chosenController() ) ); - } - } - else if( model()->getControllerConnection() ) - { - delete model()->getControllerConnection(); - model()->setControllerConnection( NULL ); - } - - delete d; - -} void knob::friendlyUpdate( void ) @@ -730,6 +695,8 @@ void knob::friendlyUpdate( void ) } + + void knob::doConnections( void ) { if( model() != NULL )