OSC: Fix signal creation notification.

This commit is contained in:
Jonathan Moore Liles 2012-02-26 18:47:07 -08:00
parent 1cdc62416d
commit 2f67b1bee4
4 changed files with 55 additions and 56 deletions

View File

@ -271,15 +271,28 @@ Module::Port::change_osc_path ( char *path )
if ( NULL == _scaled_signal ) if ( NULL == _scaled_signal )
{ {
_scaled_signal = float scaled_default = 0.5f;
mixer->osc_endpoint->add_signal( scaled_path,
OSC::Signal::Input, &Module::Port::osc_control_change_cv, this ); if ( hints.ranged )
{
float scale = hints.maximum - hints.minimum;
float offset = hints.minimum;
scaled_default = ( hints.default_value - offset ) / scale;
}
_scaled_signal = mixer->osc_endpoint->add_signal( scaled_path,
OSC::Signal::Input,
0.0, 1.0, scaled_default,
&Module::Port::osc_control_change_cv, this );
_scaled_signal->signal_connection_state_changed.connect( sigc::mem_fun( this, &Module::Port::handle_signal_connection_state_changed ) ); _scaled_signal->signal_connection_state_changed.connect(
sigc::mem_fun( this, &Module::Port::handle_signal_connection_state_changed ) );
_unscaled_signal =
mixer->osc_endpoint->add_signal( unscaled_path, _unscaled_signal = mixer->osc_endpoint->add_signal( unscaled_path,
OSC::Signal::Input, &Module::Port::osc_control_change_exact, this ); OSC::Signal::Input,
hints.minimum, hints.maximum, hints.default_value,
&Module::Port::osc_control_change_exact, this );
} }
else else
{ {
@ -287,36 +300,11 @@ Module::Port::change_osc_path ( char *path )
_scaled_signal->rename( scaled_path ); _scaled_signal->rename( scaled_path );
_unscaled_signal->rename( unscaled_path ); _unscaled_signal->rename( unscaled_path );
return;
} }
free( unscaled_path ); free( unscaled_path );
/* this was path, it's ok to free because it was malloc()'d in generate_osc_path */
free( scaled_path ); free( scaled_path );
if ( hints.ranged )
{
_unscaled_signal->parameter_limits(
hints.minimum,
hints.maximum,
hints.default_value );
}
float scaled_default = 0.5f;
if ( hints.ranged )
{
float scale = hints.maximum - hints.minimum;
float offset = hints.minimum;
scaled_default = ( hints.default_value - offset ) / scale;
}
_scaled_signal->parameter_limits(
0.0f,
1.0f,
scaled_default );
} }
} }

View File

@ -72,7 +72,6 @@ namespace OSC
{ {
DMESSAGE( "Renaming signal %s to %s", this->path(), path ); DMESSAGE( "Renaming signal %s to %s", this->path(), path );
free( _path ); free( _path );
_path = strdup( path ); _path = strdup( path );
@ -417,9 +416,6 @@ namespace OSC
{ {
Endpoint *ep = (Endpoint*)user_data; Endpoint *ep = (Endpoint*)user_data;
if ( ! argc )
return -1;
Peer *p = ep->find_peer_by_address( lo_message_get_source( msg ) ); Peer *p = ep->find_peer_by_address( lo_message_get_source( msg ) );
if ( ! p ) if ( ! p )
@ -428,20 +424,28 @@ namespace OSC
return 0; return 0;
} }
DMESSAGE( "Peer %s has created signal %s", p->name, &argv[0]->s ); const char *name = &argv[0]->s;
const char *direction = &argv[1]->s;
const int id = argv[2]->i;
const float min = argv[3]->f;
const float max = argv[4]->f;
const float default_value = argv[5]->f;
DMESSAGE( "Peer %s has created signal %s with id %i (%s %f %f %f)", p->name,
name, id, direction, min, max, default_value );
int dir = 0; Signal::Direction dir = Signal::Input;
if ( !strcmp( &argv[1]->s, "in" ) ) if ( !strcmp( direction, "in" ) )
dir = Signal::Input; dir = Signal::Input;
else if ( !strcmp( &argv[1]->s, "out" ) ) else if ( !strcmp( direction, "out" ) )
dir = Signal::Output; dir = Signal::Output;
Signal *s = new Signal( &argv[0]->s, (Signal::Direction)dir ); Signal *s = new Signal( name, dir );
s->_peer = p; s->_peer = p;
s->_id = argv[2]->i; s->_id = id;
s->parameter_limits( argv[3]->f, argv[4]->f, argv[5]->f ); s->parameter_limits( min, max, default_value );
p->_signals.push_back( s ); p->_signals.push_back( s );
@ -650,7 +654,7 @@ namespace OSC
void void
Endpoint::list_peers ( void (*callback) (const char *, const OSC::Signal *, void * ), void *v ) Endpoint::list_peer_signals ( void (*callback) (const char *, const OSC::Signal *, void * ), void *v )
{ {
for ( std::list<Peer*>::iterator i = _peers.begin(); for ( std::list<Peer*>::iterator i = _peers.begin();
i != _peers.end(); i != _peers.end();
@ -916,7 +920,7 @@ namespace OSC
} }
Signal * Signal *
Endpoint::add_signal ( const char *path, Signal::Direction dir, signal_handler handler, void *user_data ) Endpoint::add_signal ( const char *path, Signal::Direction dir, float min, float max, float default_value, signal_handler handler, void *user_data )
{ {
Signal *o = new Signal( path, dir ); Signal *o = new Signal( path, dir );
@ -934,6 +938,9 @@ namespace OSC
lo_server_add_method( _server, path, NULL, osc_sig_handler, o ); lo_server_add_method( _server, path, NULL, osc_sig_handler, o );
} }
o->parameter_limits( min, max, default_value );
/* tell our peers about it */ /* tell our peers about it */
for ( std::list<Peer*>::iterator i = _peers.begin(); for ( std::list<Peer*>::iterator i = _peers.begin();
i != _peers.end(); i != _peers.end();
@ -944,9 +951,9 @@ namespace OSC
o->path(), o->path(),
o->_direction == Signal::Input ? "in" : "out", o->_direction == Signal::Input ? "in" : "out",
o->id(), o->id(),
o->parameter_limits().min, min,
o->parameter_limits().max, max,
o->parameter_limits().default_value default_value
); );
} }

View File

@ -181,14 +181,14 @@ namespace OSC
static Signal *get_peer_signal_by_id ( Peer *p, int signal_id ); static Signal *get_peer_signal_by_id ( Peer *p, int signal_id );
int noutput_connections() { return _outgoing.size(); } int noutput_connections() { return _outgoing.size(); }
bool connected ( void ) { return _outgoing.size() + _incoming.size(); } bool connected ( void ) const { return _outgoing.size() + _incoming.size(); }
char * get_output_connection_peer_name_and_path ( int n ); char * get_output_connection_peer_name_and_path ( int n );
int id ( void ) const { return _id; } int id ( void ) const { return _id; }
Direction direction ( void ) { return _direction; } Direction direction ( void ) const { return _direction; }
void parameter_limits ( float min, float max, float default_value ) void parameter_limits ( float min, float max, float default_value )
{ {
@ -280,7 +280,7 @@ namespace OSC
public: public:
void list_peers ( void (*callback) (const char *, const OSC::Signal *, void * ), void *v ); void list_peer_signals ( void (*callback) (const char *, const OSC::Signal *, void * ), void *v );
int init ( int proto, const char *port = 0 ); int init ( int proto, const char *port = 0 );
Endpoint ( ); Endpoint ( );
@ -298,7 +298,7 @@ namespace OSC
bool connect_signal ( OSC::Signal *s, const char *peer_and_path ); bool connect_signal ( OSC::Signal *s, const char *peer_and_path );
Signal *add_signal ( const char *path, Signal::Direction dir, signal_handler handler, void *user_data ); Signal * add_signal ( const char *path, Signal::Direction dir, float min, float max, float default_value, signal_handler handler, void *user_data );
Method *add_method ( const char *path, const char *typespec, lo_method_handler handler, void *user_data, const char *argument_description ); Method *add_method ( const char *path, const char *typespec, lo_method_handler handler, void *user_data, const char *argument_description );
void del_method ( const char *path, const char *typespec ); void del_method ( const char *path, const char *typespec );
void del_method ( Method* method ); void del_method ( Method* method );

View File

@ -235,7 +235,7 @@ Control_Sequence::mode ( Mode m )
char *path; char *path;
asprintf( &path, "/track/%s/control/%i", track()->name(), track()->ncontrols() ); asprintf( &path, "/track/%s/control/%i", track()->name(), track()->ncontrols() );
_osc_output = timeline->osc->add_signal( path, OSC::Signal::Output, NULL, NULL ); _osc_output = timeline->osc->add_signal( path, OSC::Signal::Output, 0, 1, 0, NULL, NULL );
free( path ); free( path );
@ -531,6 +531,10 @@ Control_Sequence::peer_callback( const char *name, const OSC::Signal *sig )
{ {
char *s; char *s;
/* only show inputs */
if ( sig->direction() != OSC::Signal::Input )
return;
/* only list CV signals for now */ /* only list CV signals for now */
if ( ! ( sig->parameter_limits().min == 0.0 && if ( ! ( sig->parameter_limits().min == 0.0 &&
sig->parameter_limits().max == 1.0 ) ) sig->parameter_limits().max == 1.0 ) )
@ -553,7 +557,7 @@ Control_Sequence::add_osc_peers_to_menu ( Fl_Menu_Button *m, const char *prefix
peer_menu = m; peer_menu = m;
peer_prefix = prefix; peer_prefix = prefix;
timeline->osc->list_peers( &Control_Sequence::peer_callback, this ); timeline->osc->list_peer_signals( &Control_Sequence::peer_callback, this );
} }
int int