Mixer: Listen for OSC messages in a thread instead of polling.

This commit is contained in:
Jonathan Moore Liles 2012-03-13 22:41:54 -07:00
parent c74cd04bab
commit 6673f7057a
3 changed files with 15 additions and 17 deletions

View File

@ -53,8 +53,6 @@
const double STATUS_UPDATE_FREQ = 0.2f; const double STATUS_UPDATE_FREQ = 0.2f;
const double OSC_INTERVAL = 1.0 / 20.0; /* 20 hz */
extern char *user_config_dir; extern char *user_config_dir;
extern char *instance_name; extern char *instance_name;
@ -89,8 +87,11 @@ static int osc_add_strip ( const char *path, const char *, lo_arg **, int , lo_m
{ {
OSC_DMSG(); OSC_DMSG();
Fl::lock();
((Mixer*)(OSC_ENDPOINT())->owner)->command_add_strip(); ((Mixer*)(OSC_ENDPOINT())->owner)->command_add_strip();
Fl::unlock();
OSC_REPLY_OK(); OSC_REPLY_OK();
return 0; return 0;
@ -478,21 +479,11 @@ Mixer::init_osc ( const char *osc_port )
osc_endpoint->add_method( "/non/mixer/add_strip", "", osc_add_strip, osc_endpoint, "" ); osc_endpoint->add_method( "/non/mixer/add_strip", "", osc_add_strip, osc_endpoint, "" );
// osc_endpoint->start(); osc_endpoint->start();
/* poll so we can keep OSC handlers running in the GUI thread and avoid extra sync */
Fl::add_timeout( OSC_INTERVAL, check_osc, this );
return 0; return 0;
} }
void
Mixer::check_osc ( void * v )
{
((Mixer*)v)->osc_endpoint->check();
Fl::repeat_timeout( OSC_INTERVAL, check_osc, v );
}
Mixer::~Mixer ( ) Mixer::~Mixer ( )
{ {

View File

@ -26,6 +26,8 @@
#include <FL/Fl_Pack.H> #include <FL/Fl_Pack.H>
#include "Mixer_Strip.H" #include "Mixer_Strip.H"
#include "Thread.H"
class Fl_Blinker; class Fl_Blinker;
class Fl_Flowpack; class Fl_Flowpack;
class Fl_Menu_Bar; class Fl_Menu_Bar;
@ -98,8 +100,6 @@ public:
Mixer ( int X, int Y, int W, int H, const char *L ); Mixer ( int X, int Y, int W, int H, const char *L );
virtual ~Mixer(); virtual ~Mixer();
static void check_osc ( void * v );
void reply_to_finger ( lo_message msg ); void reply_to_finger ( lo_message msg );
void announce ( const char *nash_url, const char *process_name ); void announce ( const char *nash_url, const char *process_name );

View File

@ -314,6 +314,8 @@ Module::Port::osc_control_change_exact ( float v, void *user_data )
{ {
Module::Port *p = (Module::Port*)user_data; Module::Port *p = (Module::Port*)user_data;
Fl::lock();
float f = v; float f = v;
if ( p->hints.ranged ) if ( p->hints.ranged )
@ -326,6 +328,8 @@ Module::Port::osc_control_change_exact ( float v, void *user_data )
p->control_value( f ); p->control_value( f );
Fl::unlock();
// mixer->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, f ); // mixer->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, f );
return 0; return 0;
@ -338,6 +342,8 @@ Module::Port::osc_control_change_cv ( float v, void *user_data )
float f = v; float f = v;
Fl::lock();
// clamp value to control voltage range. // clamp value to control voltage range.
if ( f > 1.0 ) if ( f > 1.0 )
f = 1.0; f = 1.0;
@ -356,6 +362,7 @@ Module::Port::osc_control_change_cv ( float v, void *user_data )
p->control_value( f ); p->control_value( f );
Fl::unlock();
// mixer->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, f ); // mixer->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, f );
return 0; return 0;