From 0b23c871eeb13e2687250065d9a72df7c8a27fae Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Fri, 8 Jan 2021 17:47:03 -0800 Subject: [PATCH] Mixer: Re-transmit the minimum amount of OSC/MIDI feedback messages when strips are rearranged. --- mixer/src/Chain.C | 11 +++++++++-- mixer/src/Chain.H | 5 +++-- mixer/src/Mixer.C | 21 +++++++++++++-------- mixer/src/Mixer.H | 3 ++- mixer/src/Mixer_Strip.C | 11 +++++++++-- mixer/src/Mixer_Strip.H | 3 ++- mixer/src/Module.C | 25 +++++++++++++++---------- mixer/src/Module.H | 10 +++++----- nonlib/OSC/Endpoint.C | 5 +++-- nonlib/OSC/Endpoint.H | 2 +- 10 files changed, 62 insertions(+), 34 deletions(-) diff --git a/mixer/src/Chain.C b/mixer/src/Chain.C index 650c45e..75c2404 100644 --- a/mixer/src/Chain.C +++ b/mixer/src/Chain.C @@ -327,10 +327,17 @@ Chain::remove ( Controller_Module *m ) } void -Chain::send_feedback ( void ) +Chain::send_feedback ( bool force ) { for ( int i = 0; i < modules(); i++ ) - module(i)->send_feedback(); + module(i)->send_feedback( force ); +} + +void +Chain::schedule_feedback ( void ) +{ + for ( int i = 0; i < modules(); i++ ) + module(i)->schedule_feedback(); } /* remove a module from the chain. this isn't guaranteed to succeed, diff --git a/mixer/src/Chain.H b/mixer/src/Chain.H index 4843bb1..4bd3e40 100644 --- a/mixer/src/Chain.H +++ b/mixer/src/Chain.H @@ -100,8 +100,9 @@ public: const char *name ( void ) const { return _name; } void name ( const char *name ); - void send_feedback ( void ); - + void send_feedback ( bool force ); + void schedule_feedback ( void ); + int get_module_instance_number ( Module *m ); void configure_ports ( void ); diff --git a/mixer/src/Mixer.C b/mixer/src/Mixer.C index ffc868f..65c27df 100644 --- a/mixer/src/Mixer.C +++ b/mixer/src/Mixer.C @@ -309,7 +309,7 @@ void Mixer::cb_menu(Fl_Widget* o) { } else if ( !strcmp( picked, "&Remote Control/Send State" ) ) { - send_feedback(); + send_feedback(true); } else if ( ! strcmp( picked, "&Remote Control/Clear All Mappings" ) ) { @@ -804,6 +804,7 @@ Mixer::insert ( Mixer_Strip *ms, Mixer_Strip *before ) // mixer_strips->remove( ms ); mixer_strips->insert( *ms, before ); renumber_strips(); + schedule_feedback(); // scroll->redraw(); } void @@ -852,6 +853,7 @@ void Mixer::remove ( Mixer_Strip *ms ) parent()->redraw(); renumber_strips(); + schedule_feedback(); } @@ -1078,21 +1080,24 @@ Mixer::send_feedback_cb ( void *v ) { Mixer *m = (Mixer*)v; - m->send_feedback(); + m->send_feedback(false); /* just to it once at the start... */ Fl::repeat_timeout( FEEDBACK_UPDATE_FREQ, send_feedback_cb, v ); } -/** unconditionally send feedback to all mapped controls. This is - * useful for updating the state of an external controller. */ void -Mixer::send_feedback ( void ) +Mixer::send_feedback ( bool force ) { for ( int i = 0; i < mixer_strips->children(); i++ ) - { - ((Mixer_Strip*)mixer_strips->child(i))->send_feedback(); - } + ((Mixer_Strip*)mixer_strips->child(i))->send_feedback(force); +} + +void +Mixer::schedule_feedback ( void ) +{ + for ( int i = 0; i < mixer_strips->children(); i++ ) + ((Mixer_Strip*)mixer_strips->child(i))->schedule_feedback(); } diff --git a/mixer/src/Mixer.H b/mixer/src/Mixer.H index 71ec55b..adae55a 100644 --- a/mixer/src/Mixer.H +++ b/mixer/src/Mixer.H @@ -78,7 +78,8 @@ private: void load_translations ( void ); static void send_feedback_cb ( void *v ); - void send_feedback ( void ); + void send_feedback ( bool force ); + void schedule_feedback ( void ); void redraw_windows ( void ); static void handle_dirty ( int, void *v ); diff --git a/mixer/src/Mixer_Strip.C b/mixer/src/Mixer_Strip.C index 998bbcb..2c95b31 100644 --- a/mixer/src/Mixer_Strip.C +++ b/mixer/src/Mixer_Strip.C @@ -1279,10 +1279,17 @@ Mixer_Strip::handle ( int m ) } void -Mixer_Strip::send_feedback ( void ) +Mixer_Strip::send_feedback ( bool force ) { if ( _chain ) - _chain->send_feedback(); + _chain->send_feedback(force); +} + +void +Mixer_Strip::schedule_feedback ( void ) +{ + if ( _chain ) + _chain->schedule_feedback(); } /* called to inform the strip its number has changed. */ diff --git a/mixer/src/Mixer_Strip.H b/mixer/src/Mixer_Strip.H index 28c244b..d1af117 100644 --- a/mixer/src/Mixer_Strip.H +++ b/mixer/src/Mixer_Strip.H @@ -176,7 +176,8 @@ public: // int group ( void ) const; void group ( Group * ); - void send_feedback ( void ); + void send_feedback ( bool force ); + void schedule_feedback ( void ); int number ( void ) const; void number ( int ); static bool import_strip ( const char *filename ); diff --git a/mixer/src/Module.C b/mixer/src/Module.C index 050440a..b1e3b07 100644 --- a/mixer/src/Module.C +++ b/mixer/src/Module.C @@ -169,7 +169,6 @@ Module::init ( void ) _chain = 0; _instances = 1; _bypass = 0; - _pending_feedback = false; _base_label = NULL; _number = -2; /* magic number indicates old instance, before numbering */ @@ -371,7 +370,7 @@ Module::Port::osc_number_path ( void ) void Module::Port::send_feedback ( bool force ) { - if ( !_pending_feedback ) + if ( !force && !_pending_feedback ) return; float f = control_value(); @@ -403,18 +402,17 @@ Module::Port::send_feedback ( bool force ) if ( _scaled_signal ) { - - if ( fabsf( _feedback_value - f ) > (1.0f / 128.0f) ) + /* if ( fabsf( _feedback_value - f ) > (1.0f / 128.0f) ) */ { -/* only send feedback if value has changed significantly since the last time we sent it. */ + /* only send feedback if value has changed significantly since the last time we sent it. */ /* DMESSAGE( "signal value: %f, controL_value: %f", _scaled_signal->value(), f ); */ /* send feedback for by_name signal */ - mixer->osc_endpoint->send_feedback( _scaled_signal->path(), f ); + mixer->osc_endpoint->send_feedback( _scaled_signal->path(), f, force ); /* send feedback for by number signal */ - mixer->osc_endpoint->send_feedback( osc_number_path(), f ); + mixer->osc_endpoint->send_feedback( osc_number_path(), f, force ); - _feedback_value = f; + /* _feedback_value = f; */ _pending_feedback = false; /* _scaled_signal->value( f ); */ @@ -423,10 +421,17 @@ Module::Port::send_feedback ( bool force ) } void -Module::send_feedback ( void ) +Module::schedule_feedback ( void ) { for ( int i = 0; i < ncontrol_inputs(); i++ ) - control_input[i].send_feedback(true); + control_input[i].schedule_feedback(); +} + +void +Module::send_feedback ( bool force ) +{ + for ( int i = 0; i < ncontrol_inputs(); i++ ) + control_input[i].send_feedback(force); } void diff --git a/mixer/src/Module.H b/mixer/src/Module.H index 48bfde0..6a91a0e 100644 --- a/mixer/src/Module.H +++ b/mixer/src/Module.H @@ -48,7 +48,6 @@ class Module : public Fl_Group, public Loggable { int _instances; Chain *_chain; bool _is_default; - bool _pending_feedback; char *_base_label; nframes_t _nframes; @@ -165,7 +164,7 @@ public: _by_number_path = 0; _by_number_number = -1; _jack_port = 0; - _feedback_value = -2; + /* _feedback_value = -2; */ _pending_feedback = false; _feedback_milliseconds = 0; } @@ -184,7 +183,7 @@ public: _by_number_path = 0; _by_number_number = -1; _jack_port = p._jack_port; - _feedback_value = p._feedback_value; + /* _feedback_value = p._feedback_value; */ } virtual ~Port ( ) @@ -382,7 +381,7 @@ public: OSC::Signal *_scaled_signal; OSC::Signal *_unscaled_signal; - float _feedback_value; + /* float _feedback_value; */ bool _pending_feedback; unsigned long long _feedback_milliseconds; @@ -525,7 +524,8 @@ public: bool show_analysis_window ( void ); - void send_feedback ( void ); + void send_feedback ( bool force ); + void schedule_feedback ( void ); virtual bool initialize ( void ) { return true; } /* for the given number of inputs, return how many outputs this diff --git a/nonlib/OSC/Endpoint.C b/nonlib/OSC/Endpoint.C index 6e747c0..b518237 100644 --- a/nonlib/OSC/Endpoint.C +++ b/nonlib/OSC/Endpoint.C @@ -24,6 +24,7 @@ #include #include #include +#include #include "Endpoint.H" @@ -1206,7 +1207,7 @@ namespace OSC /** if there's a translation with a destination of 'path', then send feedback for it */ void - Endpoint::send_feedback ( const char *path, float v ) + Endpoint::send_feedback ( const char *path, float v, bool force ) { for ( std::map::iterator i = _translations.begin(); i != _translations.end(); @@ -1215,7 +1216,7 @@ namespace OSC if ( path && ! strcmp( i->second.path.c_str(), path ) ) { /* found it */ - if ( !i->second.suppress_feedback && i->second.current_value != v ) + if ( !i->second.suppress_feedback && ( force || fabsf(i->second.current_value - v ) > 0.001f )) { const char *spath = i->first.c_str(); diff --git a/nonlib/OSC/Endpoint.H b/nonlib/OSC/Endpoint.H index 28f8e9c..5f60f10 100644 --- a/nonlib/OSC/Endpoint.H +++ b/nonlib/OSC/Endpoint.H @@ -307,7 +307,7 @@ namespace OSC public: - void send_feedback ( const char *path, float v ); + void send_feedback ( const char *path, float v, bool force ); void learn ( const char *path, void (*callback)(void*), void *userdata ); lo_address address ( void )