From 57d48128ecec768dbe1e2c766437ad96cded0cbc Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 20 Jan 2010 01:43:22 -0600 Subject: [PATCH] Mixer: Scan for plugins in a background thread. --- Mixer/Plugin_Module.C | 47 ++++++++++++++++++++++++++++++++++++++----- Mixer/Plugin_Module.H | 9 ++++++++- Mixer/main.C | 2 ++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Mixer/Plugin_Module.C b/Mixer/Plugin_Module.C index 01660fa..797b304 100644 --- a/Mixer/Plugin_Module.C +++ b/Mixer/Plugin_Module.C @@ -44,6 +44,7 @@ static LADSPAInfo *ladspainfo; +Thread* Plugin_Module::plugin_discover_thread; /* keep this out of the header to avoid spreading ladspa.h dependency */ struct Plugin_Module::ImplementationData @@ -110,7 +111,7 @@ Plugin_Module::set ( Log_Entry &e ) void Plugin_Module::add_plugins_to_menu ( Fl_Menu_Button *menu ) { - Plugin_Module::Plugin_Info *pia = Plugin_Module::discover(); + Plugin_Module::Plugin_Info *pia = Plugin_Module::get_all_plugins(); char path[1024]; for ( Plugin_Module::Plugin_Info *pi = pia; pi->path; ++pi ) @@ -134,7 +135,7 @@ Plugin_Module::pick_plugin ( void ) Fl_Menu_Button *menu = new Fl_Menu_Button( 0, 0, 400, 400 ); menu->type( Fl_Menu_Button::POPUP3 ); - Plugin_Module::Plugin_Info *pia = Plugin_Module::discover(); + Plugin_Module::Plugin_Info *pia = Plugin_Module::get_all_plugins(); for ( Plugin_Module::Plugin_Info *pi = pia; pi->path; ++pi ) { @@ -307,12 +308,43 @@ Plugin_Module::configure_inputs( int n ) return true; } +void * +Plugin_Module::discover_thread ( void * v ) +{ + THREAD_ASSERT( Plugin_Discover ); + + DMESSAGE( "Discovering plugins in the background" ); + + ladspainfo = new LADSPAInfo(); + + return NULL; +} + +/* Spawn a background thread for plugin discovery */ +void +Plugin_Module::spawn_discover_thread ( void ) +{ + if ( plugin_discover_thread ) + { + FATAL( "Plugin discovery thread is already running or has completed" ); + } + + plugin_discover_thread = new Thread( "Plugin_Discover" ); + + plugin_discover_thread->clone( &Plugin_Module::discover_thread, NULL ); +} + /* return a list of available plugins */ Plugin_Module::Plugin_Info * -Plugin_Module::discover ( void ) +Plugin_Module::get_all_plugins ( void ) { if ( !ladspainfo ) - ladspainfo = new LADSPAInfo(); + { + if ( ! plugin_discover_thread ) + ladspainfo = new LADSPAInfo(); + else + plugin_discover_thread->join(); + } std::vector plugins = ladspainfo->GetMenuList(); @@ -396,7 +428,12 @@ bool Plugin_Module::load ( unsigned long id ) { if ( !ladspainfo ) - ladspainfo = new LADSPAInfo(); + { + if ( ! plugin_discover_thread ) + ladspainfo = new LADSPAInfo(); + else + plugin_discover_thread->join(); + } _idata->descriptor = ladspainfo->GetDescriptorByID( id ); diff --git a/Mixer/Plugin_Module.H b/Mixer/Plugin_Module.H index d817a62..a7fafdc 100644 --- a/Mixer/Plugin_Module.H +++ b/Mixer/Plugin_Module.H @@ -23,9 +23,12 @@ #include "Loggable.H" class Fl_Menu_Button; +class Thread; class Plugin_Module : public Module { + static Thread *plugin_discover_thread; + public: struct Plugin_Info @@ -68,7 +71,8 @@ private: int _plugin_outs; bool _crosswire; - static Plugin_Info* discover ( void ); + static void *discover_thread ( void * ); + static Plugin_Info* get_all_plugins ( void ); void set_input_buffer ( int n, void *buf ); @@ -83,8 +87,11 @@ private: void connect_ports ( void ); + public: + static void spawn_discover_thread ( void ); + Plugin_Module ( ); virtual ~Plugin_Module(); diff --git a/Mixer/main.C b/Mixer/main.C index 96bc513..ffe9dad 100644 --- a/Mixer/main.C +++ b/Mixer/main.C @@ -95,6 +95,8 @@ main ( int argc, char **argv ) /* Fl::foreground( 0xFF, 0xFF, 0xFF ); */ /* Fl::background( 0x10, 0x10, 0x10 ); */ + Plugin_Module::spawn_discover_thread(); + Fl_Double_Window *main_window; {