From 6d7059777bb69f09001469998d9fd6841d85fc4a Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Wed, 8 Feb 2012 19:03:48 -0800 Subject: [PATCH] Mixer: OSC enhancements. Responsd to both exact (range limited) and Control Voltage (0.0-1.0 on */cv) input. --- mixer/src/Controller_Module.C | 73 +++++++++++++++++++++++++---- mixer/src/Controller_Module.H | 5 +- mixer/src/Module_Parameter_Editor.C | 3 ++ mixer/src/main.C | 4 +- 4 files changed, 72 insertions(+), 13 deletions(-) diff --git a/mixer/src/Controller_Module.C b/mixer/src/Controller_Module.C index b4305f0..4953fb0 100644 --- a/mixer/src/Controller_Module.C +++ b/mixer/src/Controller_Module.C @@ -49,7 +49,7 @@ -const float CONTROL_UPDATE_FREQ = 0.1f; +const float CONTROL_UPDATE_FREQ = 0.2f; @@ -127,13 +127,23 @@ Controller_Module::change_osc_path ( char *path ) mixer->osc_endpoint->del_method( _osc_path, "f" ); free( _osc_path ); + free( _osc_path_cv ); _osc_path = NULL; + _osc_path_cv = NULL; } if ( path ) { - mixer->osc_endpoint->add_method( path, "f", &Controller_Module::osc_control_change, this, "value" ); + _osc_path_cv = (char*)malloc( strlen( path ) + 4 ); + _osc_path_cv[0] = 0; + + strcpy( _osc_path_cv, path ); + strcat( _osc_path_cv, "/cv" ); + + mixer->osc_endpoint->add_method( path, "f", &Controller_Module::osc_control_change_exact, this, "value" ); + + mixer->osc_endpoint->add_method( _osc_path_cv, "f", &Controller_Module::osc_control_change_cv, this, "value" ); _osc_path = path; @@ -410,8 +420,10 @@ Controller_Module::connect_to ( Port *p ) { Fl_Arc_Dial *o = new Fl_Arc_Dial( 0, 0, 40, 40, p->name() ); w = o; control = o; + if ( p->hints.ranged ) { + DMESSAGE( "Min: %f, max: %f", p->hints.minimum, p->hints.maximum ); o->minimum( p->hints.minimum ); o->maximum( p->hints.maximum ); } @@ -466,8 +478,8 @@ Controller_Module::update_cb ( void ) { Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this ); -/* if ( control && control_output[0].connected() ) */ -/* handle_control_changed( NULL ); */ + if ( control && control_output.size() > 0 && control_output[0].connected() ) + handle_control_changed( NULL ); } void @@ -581,6 +593,9 @@ Controller_Module::handle_control_changed ( Port * ) if ( contains( Fl::pushed() ) ) return; + if ( control->value() != control_value ) + redraw(); + if ( type() == SPATIALIZATION ) { Panner *pan = (Panner*)control; @@ -592,8 +607,6 @@ Controller_Module::handle_control_changed ( Port * ) { control->value(control_value); } - - redraw(); } /**********/ @@ -641,7 +654,7 @@ Controller_Module::process ( nframes_t nframes ) } int -Controller_Module::osc_control_change ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ) +Controller_Module::osc_control_change_exact ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ) { Controller_Module *c = (Controller_Module*)user_data; @@ -650,11 +663,53 @@ Controller_Module::osc_control_change ( const char *path, const char *types, lo_ OSC_DMSG(); - c->control_value = argv[0]->f; + const Port *p = c->control_output[0].connected_port(); + + float f = argv[0]->f; + + if ( p->hints.ranged ) + { + if ( f > p->hints.maximum ) + f = p->hints.maximum; + else if ( f < p->hints.minimum ) + f = p->hints.minimum; + } + + c->control_value = f; mixer->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, "ok" ); -// OSC_REPLY_OK(); + return 0; +} + +int +Controller_Module::osc_control_change_cv ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ) +{ + Controller_Module *c = (Controller_Module*)user_data; + + if ( c->mode() != OSC ) + return 0; + + OSC_DMSG(); + + const Port *p = c->control_output[0].connected_port(); + + float f = argv[0]->f; + + if (p->hints.ranged ) + { + // scale value to range. + // we assume that CV values are between 0 and 1 + + float scale = p->hints.maximum - p->hints.minimum; + float offset = p->hints.minimum; + + f = ( f * scale ) + offset; + } + + c->control_value = f; + + mixer->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, "ok" ); return 0; } diff --git a/mixer/src/Controller_Module.H b/mixer/src/Controller_Module.H index b76042b..2e30388 100644 --- a/mixer/src/Controller_Module.H +++ b/mixer/src/Controller_Module.H @@ -44,6 +44,7 @@ class Controller_Module : public Module void menu_cb ( const Fl_Menu_ *m ); char *_osc_path; + char *_osc_path_cv; public: @@ -105,8 +106,8 @@ private: char *generate_osc_path ( void ); void change_osc_path ( char *path ); - static int osc_control_change ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ); - + static int osc_control_change_exact ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ); + static int osc_control_change_cv ( const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *user_data ); std::vector jack_input; Mode _mode; diff --git a/mixer/src/Module_Parameter_Editor.C b/mixer/src/Module_Parameter_Editor.C index 734924e..a7911dd 100644 --- a/mixer/src/Module_Parameter_Editor.C +++ b/mixer/src/Module_Parameter_Editor.C @@ -194,8 +194,11 @@ Module_Parameter_Editor::make_controls ( void ) { Fl_Arc_Dial *o = new Fl_Arc_Dial( 0, 0, 50, 50, p->name() ); w = o; + if ( p->hints.ranged ) { + DMESSAGE( "Min: %f, max: %f", p->hints.minimum, p->hints.maximum ); + o->minimum( p->hints.minimum ); o->maximum( p->hints.maximum ); } diff --git a/mixer/src/main.C b/mixer/src/main.C index 138fb2d..d3b01c2 100644 --- a/mixer/src/main.C +++ b/mixer/src/main.C @@ -183,6 +183,8 @@ main ( int argc, char **argv ) break; } + mixer->init_osc( osc_port ); + if ( r >= 1 ) { MESSAGE( "Loading \"%s\"", argv[i] ); @@ -195,8 +197,6 @@ main ( int argc, char **argv ) } - mixer->init_osc( osc_port ); - Fl::run(); delete main_window;