From bbffb98981c1d7196169653e1f3764ee9d3b9ffb Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Mon, 17 Jun 2013 19:26:04 -0700 Subject: [PATCH] Mixer: Consolidate all GUI update timeouts into one to avoid unnecessary X events. --- mixer/src/Chain.C | 16 ++++++++++ mixer/src/Chain.H | 1 + mixer/src/Controller_Module.C | 18 +---------- mixer/src/Controller_Module.H | 5 ++- mixer/src/Meter_Indicator_Module.C | 18 +---------- mixer/src/Meter_Indicator_Module.H | 4 +-- mixer/src/Meter_Module.C | 18 +---------- mixer/src/Meter_Module.H | 5 ++- mixer/src/Mixer.C | 51 ++++++++++++++++++++++++------ mixer/src/Mixer.H | 7 ++++ mixer/src/Mixer_Strip.C | 4 +++ mixer/src/Module.H | 2 ++ 12 files changed, 81 insertions(+), 68 deletions(-) diff --git a/mixer/src/Chain.C b/mixer/src/Chain.C index 31382ba..12514a1 100644 --- a/mixer/src/Chain.C +++ b/mixer/src/Chain.C @@ -873,6 +873,22 @@ Chain::port_connect ( jack_port_id_t a, jack_port_id_t b, int connect ) } } +void +Chain::update ( void ) +{ + for ( int i = 0; i < controls_pack->children(); ++i ) + { + Controller_Module *cm = (Controller_Module*)controls_pack->child( i ); + cm->update(); + } + + for ( int i = 0; i < modules(); i++ ) + { + Module *m = module(i); + m->update(); + } +} + void Chain::update_connection_status ( void *v ) { diff --git a/mixer/src/Chain.H b/mixer/src/Chain.H index 680633a..f0a094d 100644 --- a/mixer/src/Chain.H +++ b/mixer/src/Chain.H @@ -95,6 +95,7 @@ public: Chain ( ); virtual ~Chain ( ); + void update ( void ); void draw ( void ); void resize ( int X, int Y, int W, int H ); diff --git a/mixer/src/Controller_Module.C b/mixer/src/Controller_Module.C index 3a6faa0..cfb7418 100644 --- a/mixer/src/Controller_Module.C +++ b/mixer/src/Controller_Module.C @@ -47,10 +47,6 @@ -const float CONTROL_UPDATE_FREQ = 0.2f; - - - Controller_Module::Controller_Module ( bool is_default ) : Module( is_default, 50, 100, name() ) { // label( "" ); @@ -70,15 +66,11 @@ Controller_Module::Controller_Module ( bool is_default ) : Module( is_default, 5 end(); - Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this ); - log_create(); } Controller_Module::~Controller_Module ( ) { - Fl::remove_timeout( update_cb, this ); - log_destroy(); /* shutdown JACK port, if we have one */ @@ -427,16 +419,8 @@ Controller_Module::connect_to ( Port *p ) } void -Controller_Module::update_cb ( void *v ) +Controller_Module::update ( void ) { - ((Controller_Module*)v)->update_cb(); -} - -void -Controller_Module::update_cb ( void ) -{ - Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this ); - /* we only need this in CV (JACK) mode, because with other forms * of control the change happens in the GUI thread and we know it */ if ( mode() != CV ) diff --git a/mixer/src/Controller_Module.H b/mixer/src/Controller_Module.H index 506d235..9196de3 100644 --- a/mixer/src/Controller_Module.H +++ b/mixer/src/Controller_Module.H @@ -32,9 +32,6 @@ class Fl_Valuator; class Controller_Module : public Module { - static void update_cb ( void *v ); - void update_cb ( void ); - bool _pad; volatile float control_value; @@ -87,6 +84,8 @@ public: LOG_CREATE_FUNC( Controller_Module ); + virtual void update ( void ); + void process ( nframes_t nframes ); void draw ( void ) diff --git a/mixer/src/Meter_Indicator_Module.C b/mixer/src/Meter_Indicator_Module.C index d420812..276afa3 100644 --- a/mixer/src/Meter_Indicator_Module.C +++ b/mixer/src/Meter_Indicator_Module.C @@ -40,10 +40,6 @@ -const float CONTROL_UPDATE_FREQ = 0.1f; - - - Meter_Indicator_Module::Meter_Indicator_Module ( bool is_default ) : Module ( is_default, 50, 100, name() ) { @@ -71,8 +67,6 @@ Meter_Indicator_Module::Meter_Indicator_Module ( bool is_default ) align( (Fl_Align)(FL_ALIGN_CENTER | FL_ALIGN_INSIDE ) ); clear_visible_focus(); - - Fl::add_timeout( CONTROL_UPDATE_FREQ, update_cb, this ); } Meter_Indicator_Module::~Meter_Indicator_Module ( ) @@ -83,8 +77,6 @@ Meter_Indicator_Module::~Meter_Indicator_Module ( ) control_value = NULL; } - Fl::remove_timeout( update_cb, this ); - log_destroy(); } @@ -140,16 +132,8 @@ Meter_Indicator_Module::set ( Log_Entry &e ) void -Meter_Indicator_Module::update_cb ( void *v ) +Meter_Indicator_Module::update ( void ) { - ((Meter_Indicator_Module*)v)->update_cb(); -} - -void -Meter_Indicator_Module::update_cb ( void ) -{ - Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this ); - if ( control_input[0].connected() ) { // A little hack to detect that the connected module's number diff --git a/mixer/src/Meter_Indicator_Module.H b/mixer/src/Meter_Indicator_Module.H index 1d9f44c..960d17c 100644 --- a/mixer/src/Meter_Indicator_Module.H +++ b/mixer/src/Meter_Indicator_Module.H @@ -30,8 +30,6 @@ class Meter_Indicator_Module : public Module { Fl_Scalepack *dpm_pack; - static void update_cb ( void *v ); - void update_cb ( void ); bool _pad; @@ -41,6 +39,8 @@ class Meter_Indicator_Module : public Module public: + virtual void update ( void ); + void disable_context_menu ( bool b ) { _disable_context_menu = b; } void handle_control_changed ( Port *p ); diff --git a/mixer/src/Meter_Module.C b/mixer/src/Meter_Module.C index a792255..6984c91 100644 --- a/mixer/src/Meter_Module.C +++ b/mixer/src/Meter_Module.C @@ -32,10 +32,6 @@ -const float METER_UPDATE_FREQ = 0.2f; - - - Meter_Module::Meter_Module ( ) : Module ( 50, 100, name() ) { @@ -60,8 +56,6 @@ Meter_Module::Meter_Module ( ) add_port( p ); - Fl::add_timeout( METER_UPDATE_FREQ, update_cb, this ); - log_create(); } @@ -70,24 +64,14 @@ Meter_Module::~Meter_Module ( ) if ( control_value ) delete[] control_value; - Fl::remove_timeout( update_cb, this ); - log_destroy(); } void -Meter_Module::update_cb ( void *v ) +Meter_Module::update ( void ) { - ((Meter_Module*)v)->update_cb(); -} - -void -Meter_Module::update_cb ( void ) -{ - Fl::repeat_timeout( METER_UPDATE_FREQ, update_cb, this ); - for ( int i = dpm_pack->children(); i--; ) { ((DPM*)dpm_pack->child( i ))->value( control_value[i] ); diff --git a/mixer/src/Meter_Module.H b/mixer/src/Meter_Module.H index 6fe59fa..2b3e72b 100644 --- a/mixer/src/Meter_Module.H +++ b/mixer/src/Meter_Module.H @@ -29,9 +29,6 @@ class Meter_Module : public Module volatile float *control_value; - static void update_cb ( void *v ); - void update_cb ( void ); - public: Meter_Module ( ); @@ -44,6 +41,8 @@ public: LOG_CREATE_FUNC( Meter_Module ); + virtual void update ( void ); + protected: virtual int handle ( int m ); diff --git a/mixer/src/Mixer.C b/mixer/src/Mixer.C index 4d0d374..69cf253 100644 --- a/mixer/src/Mixer.C +++ b/mixer/src/Mixer.C @@ -48,8 +48,6 @@ #include "OSC/Endpoint.H" #include -const double STATUS_UPDATE_FREQ = 0.2f; - extern char *user_config_dir; extern char *instance_name; @@ -60,12 +58,6 @@ extern char *instance_name; extern NSM_Client *nsm; -/* static void update_cb( void *v ) { */ -/* Fl::repeat_timeout( STATUS_UPDATE_FREQ, update_cb, v ); */ - -/* ((Mixer*)v)->update(); */ -/* } */ - /************************/ @@ -294,6 +286,18 @@ void Mixer::cb_menu(Fl_Widget* o) { { fl_theme_chooser(); } + else if (! strcmp( picked, "&Options/&Display/Update Frequency/15 Hz" ) ) + { + update_frequency( 15.0f ); + } + else if (! strcmp( picked, "&Options/&Display/Update Frequency/30 Hz" ) ) + { + update_frequency( 30.0f ); + } + else if (! strcmp( picked, "&Options/&Display/Update Frequency/60 Hz" ) ) + { + update_frequency( 60.0f ); + } else if ( ! strcmp( picked, "&Help/&About" ) ) { About_Dialog ab( PIXMAP_PATH "/non-mixer/icon-256x256.png" ); @@ -333,6 +337,32 @@ void Mixer::cb_menu(Fl_Widget* o, void* v) { ((Mixer*)(v))->cb_menu(o); } +void Mixer::update_frequency ( float v ) +{ + _update_interval = 1.0f / v; + + Fl::remove_timeout( &Mixer::update_cb ); + Fl::add_timeout( _update_interval, &Mixer::update_cb, this ); +} + +void +Mixer::update_cb ( void *v ) +{ + ((Mixer*)v)->update_cb(); +} + +void +Mixer::update_cb ( void ) +{ + Fl::repeat_timeout( _update_interval, &Mixer::update_cb, this ); + + for ( int i = 0; i < mixer_strips->children(); i++ ) + { + ((Mixer_Strip*)mixer_strips->child(i))->update(); + } +} + + static void progress_cb ( int p, void *v ) { @@ -420,6 +450,9 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) : o->add( "&Mixer/&Import Strip" ); o->add( "&Mixer/Paste", FL_CTRL + 'v', 0, 0 ); o->add( "&View/&Theme", 0, 0, 0 ); + /* o->add( "&Options/&Display/Update Frequency/60 Hz", 0, 0, 0, FL_MENU_RADIO ); */ + /* o->add( "&Options/&Display/Update Frequency/30 Hz", 0, 0, 0, FL_MENU_RADIO); */ + /* o->add( "&Options/&Display/Update Frequency/15 Hz", 0, 0, 0, FL_MENU_RADIO | FL_MENU_VALUE ); */ o->add( "&Help/&Manual" ); o->add( "&Help/&About" ); o->callback( cb_menu, this ); @@ -468,7 +501,7 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) : end(); -// Fl::add_timeout( STATUS_UPDATE_FREQ, update_cb, this ); + update_frequency( 15 ); update_menu(); diff --git a/mixer/src/Mixer.H b/mixer/src/Mixer.H index 3397f30..9e06374 100644 --- a/mixer/src/Mixer.H +++ b/mixer/src/Mixer.H @@ -44,6 +44,8 @@ public: private: + float _update_interval; + int _rows; Fl_Color system_colors[3]; @@ -73,7 +75,12 @@ private: static int osc_non_hello ( const char *, const char *, lo_arg **, int , lo_message msg, void * ); + static void update_cb ( void * ); + void update_cb ( void ); + public: + + void update_frequency ( float f ); virtual int handle ( int m ); diff --git a/mixer/src/Mixer_Strip.C b/mixer/src/Mixer_Strip.C index 7c2c600..6c82f03 100644 --- a/mixer/src/Mixer_Strip.C +++ b/mixer/src/Mixer_Strip.C @@ -361,6 +361,10 @@ void Mixer_Strip::update ( void ) { THREAD_ASSERT( UI ); + + meter_indicator->update(); + gain_controller->update(); + _chain->update(); } void diff --git a/mixer/src/Module.H b/mixer/src/Module.H index d3fb259..8a04959 100644 --- a/mixer/src/Module.H +++ b/mixer/src/Module.H @@ -74,6 +74,8 @@ public: /* true if this module was added by default and not under normal user control */ bool is_default ( void ) const { return _is_default; } void is_default ( bool v ) { _is_default = v; } + + virtual void update ( void ) {} class Port {