Mixer: Auto-connect spatializer controls to spatialization plugins.

This commit is contained in:
Jonathan Moore Liles 2010-02-24 09:05:46 -06:00
parent f770cede45
commit 4a97f3dcb9
7 changed files with 357 additions and 173 deletions

View File

@ -310,6 +310,8 @@ Chain::remove ( Module *m )
fl_alert( "Can't remove module at this point because the resultant chain is invalid" ); fl_alert( "Can't remove module at this point because the resultant chain is invalid" );
} }
strip()->handle_module_removed( m );
modules_pack->remove( m ); modules_pack->remove( m );
configure_ports(); configure_ports();

View File

@ -1,4 +1,3 @@
/*******************************************************************************/ /*******************************************************************************/
/* Copyright (C) 2009 Jonathan Moore Liles */ /* Copyright (C) 2009 Jonathan Moore Liles */
/* */ /* */
@ -36,6 +35,7 @@
#include "FL/Fl_Arc_Dial.H" #include "FL/Fl_Arc_Dial.H"
#include "FL/Fl_Labelpad_Group.H" #include "FL/Fl_Labelpad_Group.H"
#include "FL/Fl_Value_SliderX.H" #include "FL/Fl_Value_SliderX.H"
#include "Panner.H"
#include "FL/test_press.H" #include "FL/test_press.H"
#include "FL/menu_popup.H" #include "FL/menu_popup.H"
@ -193,11 +193,105 @@ Controller_Module::mode ( Mode m )
_mode = m ; _mode = m ;
} }
/** attempt to transform this controller into a spatialization
controller and connect to the given module's spatialization
control inputs. Returns true on success, false if given module
does not accept spatialization inputs. */
bool
Controller_Module::connect_spatializer_to ( Module *m )
{
/* these are for detecting related parameter groups which can be
better represented by a single control */
Port *azimuth_port = NULL;
float azimuth_value = 0.0f;
Port *elevation_port = NULL;
float elevation_value = 0.0f;
for ( unsigned int i = 0; i < m->control_input.size(); ++i )
{
Port *p = &m->control_input[i];
if ( !strcasecmp( "Azimuth", p->name() ) &&
180.0f == p->hints.maximum &&
-180.0f == p->hints.minimum )
{
azimuth_port = p;
azimuth_value = p->control_value();
continue;
}
else if ( !strcasecmp( "Elevation", p->name() ) &&
90.0f == p->hints.maximum &&
-90.0f == p->hints.minimum )
{
elevation_port = p;
elevation_value = p->control_value();
continue;
}
}
if ( ! ( azimuth_port && elevation_port ) )
return false;
control_output.clear();
add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
add_port( Port( this, Port::OUTPUT, Port::CONTROL ) );
control_output[0].connect_to( azimuth_port );
control_output[1].connect_to( elevation_port );
{
clear();
Panner *o = new Panner( 0,0, 100, 100 );
o->box(FL_THIN_UP_BOX);
o->color(FL_GRAY0);
o->selection_color(FL_BACKGROUND_COLOR);
o->labeltype(FL_NORMAL_LABEL);
o->labelfont(0);
o->labelcolor(FL_FOREGROUND_COLOR);
o->align(FL_ALIGN_TOP);
o->when(FL_WHEN_CHANGED);
o->label( "Spatialization" );
o->align(FL_ALIGN_TOP);
o->labelsize( 10 );
// o->callback( cb_panner_value_handle, new callback_data( this, azimuth_port_number, elevation_port_number ) );
o->point( 0 )->azimuth( azimuth_value );
o->point( 0 )->elevation( elevation_value );
o->callback( cb_spatializer_handle, this );
control = (Fl_Valuator*)o;
if ( _pad )
{
Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( o );
flg->position( x(), y() );
flg->set_visible_focus();
size( flg->w(), flg->h() );
add( flg );
}
else
{
o->resize( x(), y(), w(), h() );
add( o );
resizable( o );
init_sizes();
}
return true;
}
}
void void
Controller_Module::connect_to ( Port *p ) Controller_Module::connect_to ( Port *p )
{ {
control_output[0].connect_to( p ); control_output[0].connect_to( p );
clear();
Fl_Widget *w; Fl_Widget *w;
if ( p->hints.type == Module::Port::Hints::BOOLEAN ) if ( p->hints.type == Module::Port::Hints::BOOLEAN )
@ -278,29 +372,17 @@ Controller_Module::connect_to ( Port *p )
Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( w ); Fl_Labelpad_Group *flg = new Fl_Labelpad_Group( w );
flg->set_visible_focus(); flg->set_visible_focus();
size( flg->w(), flg->h() ); size( flg->w(), flg->h() );
flg->position( x(), y() );
add( flg ); add( flg );
} }
else else
{ {
/* HACK: hide label */ /* HACK: hide label */
w->labeltype( FL_NO_LABEL ); w->labeltype( FL_NO_LABEL );
w->resize( x(), y(), this->w(), h() ); w->resize( x(), y(), this->w(), h() );
add( w ); add( w );
resizable( w ); resizable( w );
} /* init_sizes(); */
}
void
Controller_Module::resize ( int X, int Y, int W, int H )
{
Module::resize( X, Y, W, H );
if ( ! _pad && children() )
{
child( 0 )->resize( X, Y, W, H );
} }
} }
@ -315,8 +397,8 @@ Controller_Module::update_cb ( void )
{ {
Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this ); Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
if ( control && control_output[0].connected() ) /* if ( control && control_output[0].connected() ) */
control->value(control_value); /* handle_control_changed( NULL ); */
} }
void void
@ -330,12 +412,26 @@ Controller_Module::cb_handle ( Fl_Widget *w )
{ {
control_value = ((Fl_Valuator*)w)->value(); control_value = ((Fl_Valuator*)w)->value();
if ( control_output[0].connected() ) if ( control_output[0].connected() )
{
control_output[0].control_value( control_value ); control_output[0].control_value( control_value );
Port *p = control_output[0].connected_port(); }
Module *m = p->module();
m->handle_control_changed( p );
void
Controller_Module::cb_spatializer_handle ( Fl_Widget *w, void *v )
{
((Controller_Module*)v)->cb_spatializer_handle( w );
}
void
Controller_Module::cb_spatializer_handle ( Fl_Widget *w )
{
Panner *pan = (Panner*)w;
if ( control_output[0].connected() &&
control_output[1].connected() )
{
control_output[0].connected_port()->control_value( pan->point( 0 )->azimuth() );
control_output[1].connected_port()->control_value( pan->point( 0 )->elevation() );
} }
} }
@ -406,7 +502,28 @@ Controller_Module::handle ( int m )
return Fl_Group::handle( m ); return Fl_Group::handle( m );
} }
void
Controller_Module::handle_control_changed ( Port * )
{
/* ignore changes initiated while mouse is over widget */
if ( contains( Fl::pushed() ) )
return;
if ( control_output.size() > 1 )
{
/* spatializer */
Panner *pan = (Panner*)control;
pan->point( 0 )->azimuth( control_output[0].control_value() );
pan->point( 0 )->elevation( control_output[1].control_value() );
}
else
{
control->value(control_value);
}
redraw();
}
/**********/ /**********/
/* Engine */ /* Engine */
@ -417,6 +534,12 @@ Controller_Module::process ( nframes_t nframes )
{ {
THREAD_ASSERT( RT ); THREAD_ASSERT( RT );
if ( control_output.size() > 1 )
{
/* this is a spatializer controller... */
return;
}
if ( control_output[0].connected() ) if ( control_output[0].connected() )
{ {
float f = control_value; float f = control_value;

View File

@ -61,12 +61,16 @@ public:
static void cb_handle ( Fl_Widget *w, void *v ); static void cb_handle ( Fl_Widget *w, void *v );
void cb_handle ( Fl_Widget *w ); void cb_handle ( Fl_Widget *w );
static void cb_spatializer_handle ( Fl_Widget *w, void *v );
void cb_spatializer_handle ( Fl_Widget *w );
void connect_to ( Port *p ); void connect_to ( Port *p );
bool connect_spatializer_to ( Module *m );
void handle_control_changed ( Port *p );
LOG_CREATE_FUNC( Controller_Module ); LOG_CREATE_FUNC( Controller_Module );
void resize ( int, int, int, int );
void process ( nframes_t nframes ); void process ( nframes_t nframes );
void draw ( void ) void draw ( void )

View File

@ -209,17 +209,23 @@ Mixer_Strip::chain ( Chain *c )
void Mixer_Strip::cb_handle(Fl_Widget* o) { void Mixer_Strip::cb_handle(Fl_Widget* o) {
// parent()->parent()->damage( FL_DAMAGE_ALL, x(), y(), w(), h() ); // parent()->parent()->damage( FL_DAMAGE_ALL, x(), y(), w(), h() );
DMESSAGE( "Callback for %s", o->label() );
if ( o == tab_button ) if ( o == tab_button )
{ {
if ( tab_button->value() == 0 ) if ( tab_button->value() == 0 )
{ {
fader_tab->resize( tab_group->x(), tab_group->y(), tab_group->w(), tab_group->h() );
fader_tab->show(); fader_tab->show();
signal_tab->hide(); signal_tab->hide();
tab_group->resizable( fader_tab );
} }
else else
{ {
signal_tab->resize( tab_group->x(), tab_group->y(), tab_group->w(), tab_group->h() );
signal_tab->show(); signal_tab->show();
fader_tab->hide(); fader_tab->hide();
tab_group->resizable( signal_tab );
} }
} }
@ -236,7 +242,7 @@ void Mixer_Strip::cb_handle(Fl_Widget* o) {
name( name_field->value() ); name( name_field->value() );
else if ( o == width_button ) else if ( o == width_button )
{ {
if ( ((Fl_Button*)o)->value() ) if ( width_button->value() )
size( 220, h() ); size( 220, h() );
else else
size( 96, h() ); size( 96, h() );
@ -305,6 +311,26 @@ Mixer_Strip::handle_module_added ( Module *m )
meter_indicator->connect_to( &m->control_output[0] ); meter_indicator->connect_to( &m->control_output[0] );
} }
} }
else
{
if ( spatialization_controller->connect_spatializer_to( m ) )
{
spatialization_controller->show();
DMESSAGE( "Connected spatializer to module \"%s\"", m->name() );
}
}
}
/* called by the chain to let us know that a module has been removed */
void
Mixer_Strip::handle_module_removed ( Module *m )
{
if ( spatialization_controller->control_output[0].connected_port()->module() == m )
{
spatialization_controller->hide();
DMESSAGE( "Module \"%s\" disconnected from spatialization controller", m->name() );
}
} }
/* update GUI with values from RT thread */ /* update GUI with values from RT thread */
@ -330,6 +356,10 @@ Mixer_Strip::init ( )
set_visible_focus(); set_visible_focus();
{ Fl_Scalepack *o = new Fl_Scalepack( 2, 2, 116, 595 );
o->type( FL_VERTICAL );
o->spacing( 2 );
{ Fl_Pack *o = new Fl_Pack( 2, 2, 114, 100 ); { Fl_Pack *o = new Fl_Pack( 2, 2, 114, 100 );
o->type( Fl_Pack::VERTICAL ); o->type( Fl_Pack::VERTICAL );
o->spacing( 2 ); o->spacing( 2 );
@ -378,38 +408,43 @@ Mixer_Strip::init ( )
o->end(); o->end();
} // Fl_Group* o } // Fl_Group* o
{ Fl_Flip_Button* o = tab_button = new Fl_Flip_Button(61, 183, 45, 22, "fader/signal");
o->type(1);
o->labelsize( 14 );
o->callback( ((Fl_Callback*)cb_handle), this );
o->when(FL_WHEN_RELEASE);
}
{ Fl_Flip_Button* o = width_button = new Fl_Flip_Button(61, 183, 45, 22, "narrow/wide"); { Fl_Flip_Button* o = width_button = new Fl_Flip_Button(61, 183, 45, 22, "narrow/wide");
o->type(1); o->type(1);
o->labelsize( 14 ); o->labelsize( 14 );
o->callback( ((Fl_Callback*)cb_handle), this ); o->callback( ((Fl_Callback*)cb_handle), this );
o->when(FL_WHEN_RELEASE); o->when(FL_WHEN_RELEASE);
} // Fl_Flip_Button* o
{ Fl_Flip_Button* o = tab_button = new Fl_Flip_Button(61, 183, 45, 22, "fader/signal");
o->type(1);
o->labelsize( 14 );
o->callback( cb_handle, this );
o->when(FL_WHEN_RELEASE);
} }
o->end(); o->end();
} }
Fl_Pack *fader_pack; /* { Fl_Scalepack *o = new Fl_Scalepack( 2, 103, 114, 490 ); */
/* o->type( FL_VERTICAL ); */
{ Fl_Group *o = fader_tab = new Fl_Group( 7, 115, 105, 330, "Fader" ); // o->box( FL_FLAT_BOX );
// o->color( FL_BACKGROUND_COLOR );
{ Fl_Group *o = tab_group = new Fl_Group( 2, 116, 105, 330 );
o->box( FL_NO_BOX );
{ Fl_Group *o = fader_tab = new Fl_Group( 2, 116, 105, 330, "Fader" );
o->box( FL_NO_BOX ); o->box( FL_NO_BOX );
o->labeltype( FL_NO_LABEL ); o->labeltype( FL_NO_LABEL );
{ Fl_Pack* o = fader_pack = new Fl_Pack(7, 116, 103, 330 ); { Fl_Scalepack* o = new Fl_Scalepack(2, 116, 105, 330 );
// o->box( FL_BORDER_BOX );
// o->color( FL_RED );
o->spacing( 20 ); o->spacing( 20 );
o->type( Fl_Pack::HORIZONTAL ); o->type( Fl_Scalepack::HORIZONTAL );
{ Controller_Module *o = gain_controller = new Controller_Module( true ); { Controller_Module *o = gain_controller = new Controller_Module( true );
o->pad( false ); o->pad( false );
o->size( 33, 0 ); o->size( 33, 100 );
} }
{ Meter_Indicator_Module *o = meter_indicator = new Meter_Indicator_Module( true ); { Meter_Indicator_Module *o = meter_indicator = new Meter_Indicator_Module( true );
o->pad( false ); o->pad( false );
o->size( 58, 0 ); o->size( 38, 100 );
Fl_Group::current()->resizable(o); Fl_Group::current()->resizable(o);
} }
o->end(); o->end();
Fl_Group::current()->resizable(o); Fl_Group::current()->resizable(o);
@ -417,34 +452,28 @@ Mixer_Strip::init ( )
o->end(); o->end();
Fl_Group::current()->resizable(o); Fl_Group::current()->resizable(o);
} }
{ Fl_Group *o = signal_tab = new Fl_Group( 7, 115, 105, 330 ); { Fl_Group *o = signal_tab = new Fl_Group( 2, 116, 105, 330 );
o->box( FL_NO_BOX ); o->box( FL_NO_BOX );
o->labeltype( FL_NO_LABEL ); o->labeltype( FL_NO_LABEL );
o->hide(); o->hide();
o->end(); o->end();
} }
{ Fl_Pack *o = panner_pack = new Fl_Pack( 2, 443, 114, 40 ); o->end();
o->spacing( 2 ); Fl_Group::current()->resizable( o );
o->type( Fl_Pack::VERTICAL ); }
o->box( FL_NO_BOX ); /* { Fl_Pack *o = panner_pack = new Fl_Pack( 2, 465, 114, 40 ); */
/* o->spacing( 2 ); */
{ Fl_Box *o = new Fl_Box( 0, 0, 100, 24 ); /* o->type( Fl_Pack::VERTICAL ); */
{ Fl_Box *o = new Fl_Box( 0, 0, 100, 12 );
o->align( (Fl_Align)(FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE) ); o->align( (Fl_Align)(FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE) );
o->labelsize( 10 ); o->labelsize( 10 );
o->label( "Spatialization" ); // o->label( "Spatialization" );
}
{ Controller_Module *o = spatialization_controller = new Controller_Module( true );
o->hide();
o->pad( false );
o->size( 100, 100 );
} }
{ Panner* o = new Panner(0, 0, 110, 90);
// o->deactivate();
o->box(FL_THIN_UP_BOX);
o->color(FL_GRAY0);
o->selection_color(FL_BACKGROUND_COLOR);
o->labeltype(FL_NORMAL_LABEL);
o->labelfont(0);
o->labelsize(11);
o->labelcolor(FL_FOREGROUND_COLOR);
o->align(FL_ALIGN_TOP);
o->when(FL_WHEN_RELEASE);
} // Panner* o
{ Fl_Box *o = new Fl_Box( 0, 0, 100, 12 ); { Fl_Box *o = new Fl_Box( 0, 0, 100, 12 );
o->align( (Fl_Align)(FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE) ); o->align( (Fl_Align)(FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE) );
o->labelsize( 10 ); o->labelsize( 10 );
@ -455,9 +484,10 @@ Mixer_Strip::init ( )
m->labeltype( FL_NO_LABEL ); m->labeltype( FL_NO_LABEL );
m->chain( _chain ); m->chain( _chain );
m->pad( false ); m->pad( false );
// m->connect_to( &_chain->module( 0 )->control_input[1] );
m->size( 33, 24 ); m->size( 33, 24 );
} }
/* o->end(); */
/* } */
o->end(); o->end();
} }
@ -467,6 +497,8 @@ Mixer_Strip::init ( )
size( 96, h() ); size( 96, h() );
redraw();
// _chain->configure_ports(); // _chain->configure_ports();
} }
@ -477,7 +509,8 @@ Mixer_Strip::draw ( void )
return; return;
/* don't bother drawing anything else, all we're doing is drawing the focus. */ /* don't bother drawing anything else, all we're doing is drawing the focus. */
if ( damage() != FL_DAMAGE_USER1 ) if ( damage() & FL_DAMAGE_ALL ||
damage() & FL_DAMAGE_CHILD )
Fl_Group::draw(); Fl_Group::draw();
Fl_Group::draw_box( FL_UP_FRAME, x(), y(), w(), h(), Fl::focus() == this ? Fl_Group::selection_color() : FL_BLACK ); Fl_Group::draw_box( FL_UP_FRAME, x(), y(), w(), h(), Fl::focus() == this ? Fl_Group::selection_color() : FL_BLACK );
@ -591,22 +624,27 @@ Mixer_Strip::handle ( int m )
} }
else else
return menu().test_shortcut() != 0; return menu().test_shortcut() != 0;
}
break; break;
}
case FL_PUSH: case FL_PUSH:
{
int r = 0;
if ( Fl::event_button1() )
{ {
take_focus(); take_focus();
r = 1;
}
if ( Fl_Group::handle( m ) ) if ( Fl_Group::handle( m ) )
return 1; return 1;
else if ( test_press( FL_BUTTON3 ) )
if ( test_press( FL_BUTTON3 ) )
{ {
menu_popup( &menu() ); menu_popup( &menu() );
return 1; return 1;
} }
else
return 0; return r;
break;
} }
case FL_FOCUS: case FL_FOCUS:
damage( FL_DAMAGE_USER1 ); damage( FL_DAMAGE_USER1 );

View File

@ -75,6 +75,7 @@ public:
bool configure_ports ( int n ); bool configure_ports ( int n );
void handle_module_added ( Module *m ); void handle_module_added ( Module *m );
void handle_module_removed ( Module *m );
void update ( void ); void update ( void );
@ -96,6 +97,7 @@ private:
Fl_Input *name_field; Fl_Input *name_field;
Fl_Flowpack *controls_pack; Fl_Flowpack *controls_pack;
Fl_Group *tab_group;
Fl_Group *signal_tab; Fl_Group *signal_tab;
Fl_Group *fader_tab; Fl_Group *fader_tab;
Fl_Pack *panner_pack; Fl_Pack *panner_pack;
@ -104,6 +106,7 @@ private:
Controller_Module *gain_controller; Controller_Module *gain_controller;
Controller_Module *jack_input_controller; Controller_Module *jack_input_controller;
Controller_Module *spatialization_controller;
Meter_Indicator_Module *meter_indicator; Meter_Indicator_Module *meter_indicator;
nframes_t nframes; nframes_t nframes;

View File

@ -281,7 +281,7 @@ Module_Parameter_Editor::make_controls ( void )
if ( azimuth_port_number >= 0 && elevation_port_number >= 0 ) if ( azimuth_port_number >= 0 && elevation_port_number >= 0 )
{ {
Panner *o = new Panner( 0,0, 200, 200 ); Panner *o = new Panner( 0,0, 300, 300 );
o->box(FL_THIN_UP_BOX); o->box(FL_THIN_UP_BOX);
o->color(FL_GRAY0); o->color(FL_GRAY0);
o->selection_color(FL_BACKGROUND_COLOR); o->selection_color(FL_BACKGROUND_COLOR);
@ -289,7 +289,7 @@ Module_Parameter_Editor::make_controls ( void )
o->labelfont(0); o->labelfont(0);
o->labelcolor(FL_FOREGROUND_COLOR); o->labelcolor(FL_FOREGROUND_COLOR);
o->align(FL_ALIGN_TOP); o->align(FL_ALIGN_TOP);
o->when(FL_WHEN_RELEASE); o->when(FL_WHEN_CHANGED);
o->label( "Spatialization" ); o->label( "Spatialization" );
o->align(FL_ALIGN_TOP); o->align(FL_ALIGN_TOP);
@ -370,5 +370,8 @@ void
Module_Parameter_Editor::set_value (int i, float value ) Module_Parameter_Editor::set_value (int i, float value )
{ {
_module->control_input[i].control_value( value ); _module->control_input[i].control_value( value );
_module->handle_control_changed( &_module->control_input[i] ); if ( _module->control_input[i].connected() )
_module->control_input[i].connected_port()->module()->handle_control_changed( _module->control_input[i].connected_port() );
// _module->handle_control_changed( &_module->control_input[i] );
} }

View File

@ -286,23 +286,31 @@ Panner::handle ( int m )
{ {
_bypassed = ! _bypassed; _bypassed = ! _bypassed;
redraw(); redraw();
return 0; return 1;
} }
else if ( Fl::event_button1() && ( drag = event_point() ) ) else if ( Fl::event_button1() && ( drag = event_point() ) )
return 1; return 1;
else else
return 0; return 0;
case FL_RELEASE: case FL_RELEASE:
if ( Fl::event_button1() && drag )
{
drag = NULL; drag = NULL;
do_callback(); do_callback();
redraw(); redraw();
return 1; return 1;
}
else
return 0;
case FL_MOUSEWHEEL: case FL_MOUSEWHEEL:
{ {
/* TODO: place point on opposite face of sphere */ /* TODO: place point on opposite face of sphere */
} }
case FL_DRAG: case FL_DRAG:
{ {
if ( ! drag )
return 0;
float X = Fl::event_x() - x(); float X = Fl::event_x() - x();
float Y = Fl::event_y() - y(); float Y = Fl::event_y() - y();
@ -314,6 +322,9 @@ Panner::handle ( int m )
/* else */ /* else */
drag->angle( (float)(X / (tw / 2)) - 1.0f, (float)(Y / (th / 2)) - 1.0f ); drag->angle( (float)(X / (tw / 2)) - 1.0f, (float)(Y / (th / 2)) - 1.0f );
if ( when() & FL_WHEN_CHANGED )
do_callback();
redraw(); redraw();
return 1; return 1;