Mixer: Cleanup OSC value scaling/clamping behavior.

pull/3/head
Jonathan Moore Liles 2012-02-10 00:42:58 -08:00
parent 9ff41fe8fa
commit a11961f9b6
2 changed files with 21 additions and 21 deletions

View File

@ -235,28 +235,25 @@ Module::Port::change_osc_path ( char *path )
if ( _osc_path )
{
mixer->osc_endpoint->del_method( _osc_path, "f" );
mixer->osc_endpoint->del_method( _osc_path_cv, "f" );
mixer->osc_endpoint->del_method( _osc_path_unscaled, "f" );
free( _osc_path );
free( _osc_path_cv );
free( _osc_path_unscaled );
_osc_path = NULL;
_osc_path_cv = NULL;
_osc_path_unscaled = NULL;
}
if ( path )
{
_osc_path_cv = NULL;
asprintf( &_osc_path_cv, "%s/unscaled", path );
mixer->osc_endpoint->add_method( path, "f", &Module::Port::osc_control_change_cv, this, "value" );
mixer->osc_endpoint->add_method( _osc_path_cv, "f", &Module::Port::osc_control_change_exact, this, "value" );
_osc_path_unscaled = NULL;
_osc_path = path;
// tooltip( _osc_path );
asprintf( &_osc_path_unscaled, "%s/unscaled", path );
mixer->osc_endpoint->add_method( _osc_path, "f", &Module::Port::osc_control_change_cv, this, "value" );
mixer->osc_endpoint->add_method( _osc_path_unscaled, "f", &Module::Port::osc_control_change_exact, this, "value" );
}
}
@ -266,8 +263,6 @@ Module::Port::osc_control_change_exact ( const char *path, const char *types, lo
{
Module::Port *p = (Module::Port*)user_data;
OSC_DMSG();
float f = argv[0]->f;
if ( p->hints.ranged )
@ -281,7 +276,7 @@ Module::Port::osc_control_change_exact ( const char *path, const char *types, lo
p->control_value( f );
// mixer->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, "ok" );
mixer->osc_endpoint->send( lo_message_get_source( msg ), path, argv[0]->f );
mixer->osc_endpoint->send( lo_message_get_source( msg ), path, f );
return 0;
}
@ -293,10 +288,15 @@ Module::Port::osc_control_change_cv ( const char *path, const char *types, lo_ar
float f = argv[0]->f;
if (p->hints.ranged )
// clamp value to control voltage range.
if ( f > 1.0 )
f = 1.0;
else if ( f < 0.0 )
f = 0.0;
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;
@ -307,7 +307,7 @@ Module::Port::osc_control_change_cv ( const char *path, const char *types, lo_ar
p->control_value( f );
// mixer->osc_endpoint->send( lo_message_get_source( msg ), "/reply", path, "ok" );
mixer->osc_endpoint->send( lo_message_get_source( msg ), path, argv[0]->f );
mixer->osc_endpoint->send( lo_message_get_source( msg ), path, f );
return 0;
}

View File

@ -125,7 +125,7 @@ public:
_connected = 0;
_module = module;
_osc_path = 0;
_osc_path_cv = 0;
_osc_path_unscaled = 0;
}
Port ( const Port& p )
@ -139,7 +139,7 @@ public:
_module = p._module;
hints = p.hints;
_osc_path = p._osc_path;
_osc_path_cv = p._osc_path;
_osc_path_unscaled = p._osc_path_unscaled;
}
virtual ~Port ( )
@ -247,7 +247,7 @@ public:
Module *_module;
char *_osc_path;
char *_osc_path_cv;
char *_osc_path_unscaled;
};
void bbox ( int &X, int &Y, int &W, int &H )