Mixer: Allow controller modules to be removed.

This commit is contained in:
Jonathan Moore Liles 2012-05-20 15:08:38 -07:00
parent ac30a5a4e2
commit 363f2f04bc
5 changed files with 71 additions and 8 deletions

View File

@ -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. */

View File

@ -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 );

View File

@ -91,6 +91,17 @@ Controller_Module::handle_chain_name_changed()
// change_osc_path( generate_osc_path() );
}
void
Controller_Module::disconnect ( void )
{
for ( std::vector<Module::Port>::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();
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 */
@ -499,6 +522,7 @@ Controller_Module::menu ( void )
{ "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 },
{ "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 */
/**********/

View File

@ -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 );

View File

@ -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 );
};