Mixer: Scan for plugins in a background thread.

This commit is contained in:
Jonathan Moore Liles 2010-01-20 01:43:22 -06:00
parent 4d4c913d8d
commit 57d48128ec
3 changed files with 52 additions and 6 deletions

View File

@ -44,6 +44,7 @@
static LADSPAInfo *ladspainfo; static LADSPAInfo *ladspainfo;
Thread* Plugin_Module::plugin_discover_thread;
/* keep this out of the header to avoid spreading ladspa.h dependency */ /* keep this out of the header to avoid spreading ladspa.h dependency */
struct Plugin_Module::ImplementationData struct Plugin_Module::ImplementationData
@ -110,7 +111,7 @@ Plugin_Module::set ( Log_Entry &e )
void void
Plugin_Module::add_plugins_to_menu ( Fl_Menu_Button *menu ) 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]; char path[1024];
for ( Plugin_Module::Plugin_Info *pi = pia; pi->path; ++pi ) 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 ); Fl_Menu_Button *menu = new Fl_Menu_Button( 0, 0, 400, 400 );
menu->type( Fl_Menu_Button::POPUP3 ); 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 ) for ( Plugin_Module::Plugin_Info *pi = pia; pi->path; ++pi )
{ {
@ -307,12 +308,43 @@ Plugin_Module::configure_inputs( int n )
return true; 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 */ /* return a list of available plugins */
Plugin_Module::Plugin_Info * Plugin_Module::Plugin_Info *
Plugin_Module::discover ( void ) Plugin_Module::get_all_plugins ( void )
{ {
if ( !ladspainfo ) if ( !ladspainfo )
{
if ( ! plugin_discover_thread )
ladspainfo = new LADSPAInfo(); ladspainfo = new LADSPAInfo();
else
plugin_discover_thread->join();
}
std::vector<LADSPAInfo::PluginEntry> plugins = ladspainfo->GetMenuList(); std::vector<LADSPAInfo::PluginEntry> plugins = ladspainfo->GetMenuList();
@ -396,7 +428,12 @@ bool
Plugin_Module::load ( unsigned long id ) Plugin_Module::load ( unsigned long id )
{ {
if ( !ladspainfo ) if ( !ladspainfo )
{
if ( ! plugin_discover_thread )
ladspainfo = new LADSPAInfo(); ladspainfo = new LADSPAInfo();
else
plugin_discover_thread->join();
}
_idata->descriptor = ladspainfo->GetDescriptorByID( id ); _idata->descriptor = ladspainfo->GetDescriptorByID( id );

View File

@ -23,9 +23,12 @@
#include "Loggable.H" #include "Loggable.H"
class Fl_Menu_Button; class Fl_Menu_Button;
class Thread;
class Plugin_Module : public Module { class Plugin_Module : public Module {
static Thread *plugin_discover_thread;
public: public:
struct Plugin_Info struct Plugin_Info
@ -68,7 +71,8 @@ private:
int _plugin_outs; int _plugin_outs;
bool _crosswire; 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 ); void set_input_buffer ( int n, void *buf );
@ -83,8 +87,11 @@ private:
void connect_ports ( void ); void connect_ports ( void );
public: public:
static void spawn_discover_thread ( void );
Plugin_Module ( ); Plugin_Module ( );
virtual ~Plugin_Module(); virtual ~Plugin_Module();

View File

@ -95,6 +95,8 @@ main ( int argc, char **argv )
/* Fl::foreground( 0xFF, 0xFF, 0xFF ); */ /* Fl::foreground( 0xFF, 0xFF, 0xFF ); */
/* Fl::background( 0x10, 0x10, 0x10 ); */ /* Fl::background( 0x10, 0x10, 0x10 ); */
Plugin_Module::spawn_discover_thread();
Fl_Double_Window *main_window; Fl_Double_Window *main_window;
{ {