diff --git a/mixer/src/Controller_Module.C b/mixer/src/Controller_Module.C index 01a5199..c3e3a92 100644 --- a/mixer/src/Controller_Module.C +++ b/mixer/src/Controller_Module.C @@ -50,6 +50,9 @@ bool Controller_Module::learn_by_number = false; bool Controller_Module::_learn_mode = false; + +Controller_Module* Controller_Module::_learning_control = NULL; + void @@ -836,10 +839,27 @@ Controller_Module::draw ( void ) if ( learn_mode() ) { - fl_rectf( x(),y(),w(),h(), fl_color_add_alpha( FL_MAGENTA, 50 ) ); + fl_rectf( x(),y(),w(),h(), + fl_color_add_alpha( + this == _learning_control + ? FL_RED + : FL_GREEN, + 60 ) ); } } +void Controller_Module::learning_callback ( void *userdata ) +{ + ((Controller_Module*)userdata)->learning_callback(); +} + +void Controller_Module::learning_callback ( void ) +{ + _learning_control = NULL; + this->redraw(); +} + + int Controller_Module::handle ( int m ) { @@ -852,6 +872,10 @@ Controller_Module::handle ( int m ) { tooltip( "Now learning control. Move the desired control on your controller" ); + _learning_control = this; + + this->redraw(); + //connect_to( &module->control_input[port] ); Port *p = control_output[0].connected_port(); @@ -861,7 +885,7 @@ Controller_Module::handle ( int m ) DMESSAGE( "Will learn %s", path ); - mixer->osc_endpoint->learn( path ); + mixer->osc_endpoint->learn( path, Controller_Module::learning_callback, this ); } return 1; diff --git a/mixer/src/Controller_Module.H b/mixer/src/Controller_Module.H index 83973ba..c466a50 100644 --- a/mixer/src/Controller_Module.H +++ b/mixer/src/Controller_Module.H @@ -47,9 +47,13 @@ class Controller_Module : public Module void add_osc_peers_to_menu ( Fl_Menu_Button *m, const char *prefix ); void add_osc_connections_to_menu ( Fl_Menu_Button *m, const char *prefix ); + static void learning_callback ( void *userdata ); + void learning_callback ( void ); + public: static bool _learn_mode; + static Controller_Module *_learning_control; static bool learn_by_number; static bool learn_mode ( void ) { return _learn_mode; } diff --git a/nonlib/OSC/Endpoint.C b/nonlib/OSC/Endpoint.C index cb8c822..e3c25c5 100644 --- a/nonlib/OSC/Endpoint.C +++ b/nonlib/OSC/Endpoint.C @@ -187,6 +187,7 @@ namespace OSC Endpoint::Endpoint ( ) { _learning_path = NULL; + _learning_callback = NULL; _peer_signal_notification_callback = 0; _peer_signal_notification_userdata = 0; _peer_scan_complete_callback = 0; @@ -685,8 +686,13 @@ namespace OSC DMESSAGE( "Learned translation \"%s\" -> \"%s\"", path, ep->_learning_path ); free(ep->_learning_path); + + ep->_learning_callback(ep->_learning_userdata); + + ep->_learning_userdata = NULL; + ep->_learning_callback = NULL; ep->_learning_path = NULL; - + return 0; } @@ -1066,13 +1072,16 @@ namespace OSC /* prepare to learn a translation for /path/. The next unhandled message to come through will be mapped to /path/ */ void - Endpoint::learn ( const char *path ) + Endpoint::learn ( const char *path, void (*callback)(void*), void *userdata ) { if ( _learning_path ) free( _learning_path ); _learning_path = NULL; + _learning_callback = callback; + _learning_userdata = userdata; + if ( path ) _learning_path = strdup( path ); } diff --git a/nonlib/OSC/Endpoint.H b/nonlib/OSC/Endpoint.H index 4e56960..0360c87 100644 --- a/nonlib/OSC/Endpoint.H +++ b/nonlib/OSC/Endpoint.H @@ -241,6 +241,8 @@ namespace OSC std::list _methods; char *_learning_path; + void (*_learning_callback)(void *); + void *_learning_userdata; class TranslationDestination { @@ -305,7 +307,7 @@ namespace OSC public: void send_feedback ( const char *path, float v ); - void learn ( const char *path ); + void learn ( const char *path, void (*callback)(void*), void *userdata ); lo_address address ( void ) {