From 8e0a6253121b38b483a9586b0009d439c5498c16 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Sun, 17 Jan 2010 21:59:56 -0600 Subject: [PATCH] Mixer: Allow user to add internal modules as well as plugins to a chain. --- Mixer/Chain.C | 12 +++++++++- Mixer/Module.C | 51 +++++++++++++++++++++++++++++++++++++++++++ Mixer/Module.H | 2 ++ Mixer/Plugin_Module.C | 16 ++++++++++++++ Mixer/Plugin_Module.H | 36 ++++++++++++++++++------------ 5 files changed, 102 insertions(+), 15 deletions(-) diff --git a/Mixer/Chain.C b/Mixer/Chain.C index 4176ca6..a00a7ae 100644 --- a/Mixer/Chain.C +++ b/Mixer/Chain.C @@ -692,9 +692,19 @@ Chain::handle ( int m ) } else if ( test_press( FL_BUTTON1 | FL_SHIFT ) ) { - Module *mod = (Module*)Plugin_Module::pick_plugin(); +// Module *mod = (Module*)Plugin_Module::pick_plugin(); + Module *mod = Module::pick_module(); if ( mod ) { + if ( !strcmp( mod->name(), "JACK" ) ) + { + DMESSAGE( "Special casing JACK module" ); + JACK_Module *jm = (JACK_Module*)mod; + jm->chain( this ); + jm->configure_inputs( m->ninputs() ); + jm->configure_outputs( m->ninputs() ); + } + if ( ! insert( m, mod ) ) fl_alert( "Cannot insert this module at this point in the chain" ); redraw(); diff --git a/Mixer/Module.C b/Mixer/Module.C index fe47364..a3dd69a 100644 --- a/Mixer/Module.C +++ b/Mixer/Module.C @@ -27,6 +27,12 @@ #include "Module_Parameter_Editor.H" #include "Chain.H" +#include "JACK_Module.H" +#include "Gain_Module.H" +#include "Mono_Pan_Module.H" +#include "Meter_Module.H" +#include "Plugin_Module.H" + Module::Module ( int W, int H, const char *L ) : Fl_Group( 0, 0, W, H, L ) @@ -307,6 +313,51 @@ Module::draw_label ( void ) delete[] s; } +#include + +Module * +Module::pick_module ( void ) +{ + Fl_Menu_Button *menu = new Fl_Menu_Button( 0, 0, 400, 400 ); + menu->type( Fl_Menu_Button::POPUP3 ); + +// menu->add( "JACK", 0, 0, (void*)1 ); + menu->add( "Gain", 0, 0, (void*)2 ); + menu->add( "Meter", 0, 0, (void*)3 ); + menu->add( "Mono Pan", 0, 0, (void*)4 ); + + Plugin_Module::add_plugins_to_menu( menu ); + + menu->popup(); + + if ( menu->value() < 0 ) + return NULL; + + void * v = menu->menu()[ menu->value() ].user_data(); + + if ( ! v ) + return NULL; + + switch ( (int)v ) + { + case 1: + return new JACK_Module(); + case 2: + return new Gain_Module(); + case 3: + return new Meter_Module(); + case 4: + return new Mono_Pan_Module(); + } + + Plugin_Module::Plugin_Info *pi = (Plugin_Module::Plugin_Info*)v; + Plugin_Module *m = new Plugin_Module(); + + m->load( pi->id ); + + return m; +} + #include "FL/test_press.H" int diff --git a/Mixer/Module.H b/Mixer/Module.H index d1b4b0c..1bed68f 100644 --- a/Mixer/Module.H +++ b/Mixer/Module.H @@ -310,6 +310,8 @@ public: char *get_parameters ( void ) const; void set_parameters ( const char * ); + static Module * pick_module ( void ); + virtual bool initialize ( void ) { return true; } /* for the given number of inputs, return how many outputs this diff --git a/Mixer/Plugin_Module.C b/Mixer/Plugin_Module.C index 280e992..eca7418 100644 --- a/Mixer/Plugin_Module.C +++ b/Mixer/Plugin_Module.C @@ -107,6 +107,22 @@ Plugin_Module::set ( Log_Entry &e ) #include +void +Plugin_Module::add_plugins_to_menu ( Fl_Menu_Button *menu ) +{ + Plugin_Module::Plugin_Info *pia = Plugin_Module::discover(); + + char path[1024]; + for ( Plugin_Module::Plugin_Info *pi = pia; pi->path; ++pi ) + { + snprintf( path, sizeof( path ), "%s/%s", "Plugin", pi->path ); + + menu->add(path, 0, NULL, pi, 0 ); + } + + delete[] pia; +} + /* allow the user to pick a plugin */ Plugin_Module * Plugin_Module::pick_plugin ( void ) diff --git a/Mixer/Plugin_Module.H b/Mixer/Plugin_Module.H index 2d04040..d817a62 100644 --- a/Mixer/Plugin_Module.H +++ b/Mixer/Plugin_Module.H @@ -22,7 +22,27 @@ #include "Module.H" #include "Loggable.H" -class Plugin_Module : Module { +class Fl_Menu_Button; + +class Plugin_Module : public Module { + +public: + + struct Plugin_Info + { + const char *path; + unsigned long id; + + Plugin_Info ( ) + { + path = 0; + id = 0; + } + }; + + bool load ( unsigned long id ); + +private: void init ( void ); @@ -48,21 +68,8 @@ class Plugin_Module : Module { int _plugin_outs; bool _crosswire; - struct Plugin_Info - { - const char *path; - unsigned long id; - - Plugin_Info ( ) - { - path = 0; - id = 0; - } - }; - static Plugin_Info* discover ( void ); - bool load ( unsigned long id ); void set_input_buffer ( int n, void *buf ); void set_output_buffer ( int n, void *buf ); @@ -82,6 +89,7 @@ public: virtual ~Plugin_Module(); static Plugin_Module * pick_plugin ( void ); + static void add_plugins_to_menu ( Fl_Menu_Button *menu ); int plugin_ins ( void ) const { return _plugin_ins; } int plugin_outs ( void ) const { return _plugin_outs; }