diff --git a/mixer/src/Chain.C b/mixer/src/Chain.C index 1f0b2c4..8a52cc5 100644 --- a/mixer/src/Chain.C +++ b/mixer/src/Chain.C @@ -293,6 +293,25 @@ void Chain::cb_handle(Fl_Widget* o, void* v) { ((Chain*)(v))->cb_handle(o); } +void +Chain::remove ( Controller_Module *m ) +{ + DMESSAGE( "Removing controller module from chain" ); + + engine()->lock(); + + m->disconnect(); + + controls_pack->remove( m ); + modules_pack->remove( m ); + + build_process_queue(); + + engine()->unlock(); + + redraw(); +} + /* remove a module from the chain. this isn't guaranteed to succeed, * because removing the module might result in an invalid routing */ @@ -311,11 +330,15 @@ Chain::remove ( Module *m ) fl_alert( "Can't remove module at this point because the resultant chain is invalid" ); } + engine()->lock(); + strip()->handle_module_removed( m ); modules_pack->remove( m ); configure_ports(); + + engine()->unlock(); } /* determine number of output ports, signal if changed. */ diff --git a/mixer/src/Chain.H b/mixer/src/Chain.H index 783a4a7..1832749 100644 --- a/mixer/src/Chain.H +++ b/mixer/src/Chain.H @@ -101,6 +101,7 @@ public: int modules ( void ) const { return modules_pack->children(); } Module *module ( int n ) const { return (Module*)modules_pack->child( n ); } + void remove ( Controller_Module *m ); void remove ( Module *m ); bool add ( Module *m ); bool add ( Controller_Module *m ); diff --git a/mixer/src/Controller_Module.C b/mixer/src/Controller_Module.C index 2e12764..f6b3b68 100644 --- a/mixer/src/Controller_Module.C +++ b/mixer/src/Controller_Module.C @@ -91,6 +91,17 @@ Controller_Module::handle_chain_name_changed() // change_osc_path( generate_osc_path() ); } +void +Controller_Module::disconnect ( void ) +{ + for ( std::vector::iterator i = control_output.begin(); + i != control_output.end(); + ++i ) + { + (*i).disconnect(); + } +} + void @@ -99,11 +110,21 @@ Controller_Module::get ( Log_Entry &e ) const Module::get( e ); Port *p = control_output[0].connected_port(); - Module *m = p->module(); - e.add( ":module", m ); - e.add( ":port", m->control_input_port_index( p ) ); - e.add( ":mode", mode() ); + if ( !p ) + { + e.add( ":module", "" ); + e.add( ":port", "" ); + e.add( ":mode", "" ); + } + else + { + Module *m = p->module(); + + e.add( ":module", m ); + e.add( ":port", m->control_input_port_index( p ) ); + e.add( ":mode", mode() ); + } } void @@ -485,6 +506,8 @@ Controller_Module::menu_cb ( const Fl_Menu_ *m ) mode( GUI ); else if ( ! strcmp( picked, "Mode/Control Voltage (JACK)" ) ) mode( CV ); + else if ( ! strcmp( picked, "/Remove" ) ) + command_remove(); } /** build the context menu for this control */ @@ -498,7 +521,8 @@ Controller_Module::menu ( void ) { "Mode", 0, 0, 0, FL_SUBMENU }, { "GUI + OSC", 0, 0, 0, FL_MENU_RADIO | ( mode() == GUI ? FL_MENU_VALUE : 0 ) }, { "Control Voltage (JACK)", 0, 0, 0, FL_MENU_RADIO | ( mode() == CV ? FL_MENU_VALUE : 0 ) }, - { 0 }, + { 0 }, + { "Remove", 0, 0, 0, 0 }, { 0 }, }; @@ -569,6 +593,18 @@ Controller_Module::handle_control_changed ( Port *p ) } } +void +Controller_Module::command_remove ( void ) +{ + if ( is_default() ) + fl_alert( "Default modules may not be deleted." ); + else + { + chain()->remove( this ); + Fl::delete_widget( this ); + } +} + /**********/ /* Engine */ /**********/ diff --git a/mixer/src/Controller_Module.H b/mixer/src/Controller_Module.H index 60b2ba1..de29b85 100644 --- a/mixer/src/Controller_Module.H +++ b/mixer/src/Controller_Module.H @@ -78,10 +78,13 @@ public: void connect_to ( Port *p ); bool connect_spatializer_to ( Module *m ); + void disconnect ( void ); void handle_control_changed ( Port *p ); void handle_chain_name_changed ( void ); + virtual void command_remove ( void ); + LOG_CREATE_FUNC( Controller_Module ); void process ( nframes_t nframes ); diff --git a/mixer/src/Module.H b/mixer/src/Module.H index 9241887..2ee4d9c 100644 --- a/mixer/src/Module.H +++ b/mixer/src/Module.H @@ -437,8 +437,8 @@ protected: public: void command_open_parameter_editor(); - void command_activate ( void ); - void command_deactivate ( void ); - void command_remove ( void ); + virtual void command_activate ( void ); + virtual void command_deactivate ( void ); + virtual void command_remove ( void ); };