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" );
}
strip()->handle_module_removed( m );
modules_pack->remove( m );
configure_ports();

View File

@ -1,4 +1,3 @@
/*******************************************************************************/
/* Copyright (C) 2009 Jonathan Moore Liles */
/* */
@ -36,6 +35,7 @@
#include "FL/Fl_Arc_Dial.H"
#include "FL/Fl_Labelpad_Group.H"
#include "FL/Fl_Value_SliderX.H"
#include "Panner.H"
#include "FL/test_press.H"
#include "FL/menu_popup.H"
@ -193,11 +193,105 @@ Controller_Module::mode ( 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
Controller_Module::connect_to ( Port *p )
{
control_output[0].connect_to( p );
clear();
Fl_Widget *w;
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 );
flg->set_visible_focus();
size( flg->w(), flg->h() );
flg->position( x(), y() );
add( flg );
}
else
{
/* HACK: hide label */
w->labeltype( FL_NO_LABEL );
w->resize( x(), y(), this->w(), h() );
add( w );
resizable( w );
}
}
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 );
/* init_sizes(); */
}
}
@ -315,8 +397,8 @@ Controller_Module::update_cb ( void )
{
Fl::repeat_timeout( CONTROL_UPDATE_FREQ, update_cb, this );
if ( control && control_output[0].connected() )
control->value(control_value);
/* if ( control && control_output[0].connected() ) */
/* handle_control_changed( NULL ); */
}
void
@ -330,12 +412,26 @@ Controller_Module::cb_handle ( Fl_Widget *w )
{
control_value = ((Fl_Valuator*)w)->value();
if ( control_output[0].connected() )
{
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() );
}
}
@ -391,22 +487,43 @@ Controller_Module::handle ( int m )
{
case FL_PUSH:
{
if ( test_press( FL_BUTTON3 ) )
{
/* context menu */
menu_popup( &menu() );
if ( test_press( FL_BUTTON3 ) )
{
/* context menu */
menu_popup( &menu() );
return 1;
}
else
return Fl_Group::handle( m );
return 1;
}
else
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 */
@ -417,7 +534,13 @@ Controller_Module::process ( nframes_t nframes )
{
THREAD_ASSERT( RT );
if ( control_output[0].connected() )
if ( control_output.size() > 1 )
{
/* this is a spatializer controller... */
return;
}
if ( control_output[0].connected() )
{
float f = control_value;
@ -443,6 +566,6 @@ Controller_Module::process ( nframes_t nframes )
*((float*)control_output[0].buffer()) = f;
control_value = f;
control_value = f;
}
}

View File

@ -61,12 +61,16 @@ public:
static void cb_handle ( Fl_Widget *w, void *v );
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 );
bool connect_spatializer_to ( Module *m );
void handle_control_changed ( Port *p );
LOG_CREATE_FUNC( Controller_Module );
void resize ( int, int, int, int );
void process ( nframes_t nframes );
void draw ( void )

View File

@ -209,17 +209,23 @@ Mixer_Strip::chain ( Chain *c )
void Mixer_Strip::cb_handle(Fl_Widget* o) {
// parent()->parent()->damage( FL_DAMAGE_ALL, x(), y(), w(), h() );
DMESSAGE( "Callback for %s", o->label() );
if ( o == tab_button )
{
if ( tab_button->value() == 0 )
{
fader_tab->resize( tab_group->x(), tab_group->y(), tab_group->w(), tab_group->h() );
fader_tab->show();
signal_tab->hide();
tab_group->resizable( fader_tab );
}
else
{
signal_tab->resize( tab_group->x(), tab_group->y(), tab_group->w(), tab_group->h() );
signal_tab->show();
fader_tab->hide();
tab_group->resizable( signal_tab );
}
}
@ -236,13 +242,13 @@ void Mixer_Strip::cb_handle(Fl_Widget* o) {
name( name_field->value() );
else if ( o == width_button )
{
if ( ((Fl_Button*)o)->value() )
if ( width_button->value() )
size( 220, h() );
else
size( 96, h() );
if ( parent() )
parent()->parent()->redraw();
if ( parent() )
parent()->parent()->redraw();
}
}
@ -305,6 +311,26 @@ Mixer_Strip::handle_module_added ( Module *m )
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 */
@ -330,134 +356,138 @@ Mixer_Strip::init ( )
set_visible_focus();
{ Fl_Pack *o = new Fl_Pack( 2, 2, 114, 100 );
o->type( Fl_Pack::VERTICAL );
o->spacing( 2 );
{
Fl_Sometimes_Input *o = new Fl_Sometimes_Input( 2, 2, 144, 24 );
name_field = o;
{ Fl_Scalepack *o = new Fl_Scalepack( 2, 2, 116, 595 );
o->type( FL_VERTICAL );
o->spacing( 2 );
o->color( color() );
o->up_box( FL_ROUNDED_BOX );
o->box( FL_ROUNDED_BOX );
o->labeltype( FL_NO_LABEL );
o->labelcolor( FL_GRAY0 );
o->textcolor( FL_FOREGROUND_COLOR );
o->value( name() );
o->callback( cb_handle, (void*)this );
{ Fl_Pack *o = new Fl_Pack( 2, 2, 114, 100 );
o->type( Fl_Pack::VERTICAL );
o->spacing( 2 );
{
Fl_Sometimes_Input *o = new Fl_Sometimes_Input( 2, 2, 144, 24 );
name_field = o;
}
{ Fl_Scalepack *o = new Fl_Scalepack( 7, 143, 110, 25 );
o->type( Fl_Pack::HORIZONTAL );
{ Fl_Button* o = left_button = new Fl_Button(7, 143, 35, 25, "@<-");
o->tooltip( "Move left" );
o->type(0);
o->labelsize(10);
o->when( FL_WHEN_RELEASE );
o->callback( ((Fl_Callback*)cb_handle), this );
} // Fl_Button* o
o->color( color() );
o->up_box( FL_ROUNDED_BOX );
o->box( FL_ROUNDED_BOX );
o->labeltype( FL_NO_LABEL );
o->labelcolor( FL_GRAY0 );
o->textcolor( FL_FOREGROUND_COLOR );
o->value( name() );
o->callback( cb_handle, (void*)this );
{ Fl_Button* o = close_button = new Fl_Button(7, 143, 35, 25, "X");
o->tooltip( "Remove strip" );
o->type(0);
o->labeltype( FL_EMBOSSED_LABEL );
o->color( FL_LIGHT1 );
o->selection_color( FL_RED );
o->labelsize(10);
o->when( FL_WHEN_RELEASE );
o->callback( ((Fl_Callback*)cb_handle), this );
} // Fl_Button* o
{ Fl_Button* o = right_button = new Fl_Button(7, 143, 35, 25, "@->");
o->tooltip( "Move right" );
o->type(0);
o->labelsize(10);
o->when( FL_WHEN_RELEASE );
o->callback( ((Fl_Callback*)cb_handle), this );
} // Fl_Button* o
o->end();
} // Fl_Group* o
{ Fl_Flip_Button* o = width_button = new Fl_Flip_Button(61, 183, 45, 22, "narrow/wide");
o->type(1);
o->labelsize(14);
o->callback( ((Fl_Callback*)cb_handle), this );
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();
}
Fl_Pack *fader_pack;
{ Fl_Group *o = fader_tab = new Fl_Group( 7, 115, 105, 330, "Fader" );
o->box( FL_NO_BOX );
o->labeltype( FL_NO_LABEL );
{ Fl_Pack* o = fader_pack = new Fl_Pack(7, 116, 103, 330 );
o->spacing( 20 );
o->type( Fl_Pack::HORIZONTAL );
{ Controller_Module *o = gain_controller = new Controller_Module( true );
o->pad( false );
o->size( 33, 0 );
}
{ Meter_Indicator_Module *o = meter_indicator = new Meter_Indicator_Module( true );
o->pad( false );
o->size( 58, 0 );
{ Fl_Scalepack *o = new Fl_Scalepack( 7, 143, 110, 25 );
o->type( Fl_Pack::HORIZONTAL );
{ Fl_Button* o = left_button = new Fl_Button(7, 143, 35, 25, "@<-");
o->tooltip( "Move left" );
o->type(0);
o->labelsize(10);
o->when( FL_WHEN_RELEASE );
o->callback( ((Fl_Callback*)cb_handle), this );
} // Fl_Button* o
{ Fl_Button* o = close_button = new Fl_Button(7, 143, 35, 25, "X");
o->tooltip( "Remove strip" );
o->type(0);
o->labeltype( FL_EMBOSSED_LABEL );
o->color( FL_LIGHT1 );
o->selection_color( FL_RED );
o->labelsize(10);
o->when( FL_WHEN_RELEASE );
o->callback( ((Fl_Callback*)cb_handle), this );
} // Fl_Button* o
{ Fl_Button* o = right_button = new Fl_Button(7, 143, 35, 25, "@->");
o->tooltip( "Move right" );
o->type(0);
o->labelsize(10);
o->when( FL_WHEN_RELEASE );
o->callback( ((Fl_Callback*)cb_handle), this );
} // Fl_Button* o
o->end();
} // 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");
o->type(1);
o->labelsize( 14 );
o->callback( ((Fl_Callback*)cb_handle), this );
o->when(FL_WHEN_RELEASE);
}
o->end();
}
/* { Fl_Scalepack *o = new Fl_Scalepack( 2, 103, 114, 490 ); */
/* o->type( FL_VERTICAL ); */
// 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->labeltype( FL_NO_LABEL );
{ Fl_Scalepack* o = new Fl_Scalepack(2, 116, 105, 330 );
// o->box( FL_BORDER_BOX );
// o->color( FL_RED );
o->spacing( 20 );
o->type( Fl_Scalepack::HORIZONTAL );
{ Controller_Module *o = gain_controller = new Controller_Module( true );
o->pad( false );
o->size( 33, 100 );
}
{ Meter_Indicator_Module *o = meter_indicator = new Meter_Indicator_Module( true );
o->pad( false );
o->size( 38, 100 );
Fl_Group::current()->resizable(o);
}
o->end();
Fl_Group::current()->resizable(o);
} // Fl_Group* o
o->end();
Fl_Group::current()->resizable(o);
}
{ Fl_Group *o = signal_tab = new Fl_Group( 2, 116, 105, 330 );
o->box( FL_NO_BOX );
o->labeltype( FL_NO_LABEL );
o->hide();
o->end();
}
o->end();
Fl_Group::current()->resizable(o);
} // Fl_Group* o
o->end();
Fl_Group::current()->resizable(o);
}
{ Fl_Group *o = signal_tab = new Fl_Group( 7, 115, 105, 330 );
o->box( FL_NO_BOX );
o->labeltype( FL_NO_LABEL );
o->hide();
o->end();
}
{ Fl_Pack *o = panner_pack = new Fl_Pack( 2, 443, 114, 40 );
o->spacing( 2 );
o->type( Fl_Pack::VERTICAL );
o->box( FL_NO_BOX );
{ Fl_Box *o = new Fl_Box( 0, 0, 100, 24 );
o->align( (Fl_Align)(FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE) );
o->labelsize( 10 );
o->label( "Spatialization" );
}
{ 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 );
o->align( (Fl_Align)(FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE) );
o->labelsize( 10 );
o->label( "Inputs" );
}
{
Controller_Module *m = jack_input_controller = new Controller_Module( true );
m->labeltype( FL_NO_LABEL );
m->chain( _chain );
m->pad( false );
// m->connect_to( &_chain->module( 0 )->control_input[1] );
m->size( 33, 24 );
Fl_Group::current()->resizable( o );
}
/* { Fl_Pack *o = panner_pack = new Fl_Pack( 2, 465, 114, 40 ); */
/* o->spacing( 2 ); */
/* 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->labelsize( 10 );
// o->label( "Spatialization" );
}
{ Controller_Module *o = spatialization_controller = new Controller_Module( true );
o->hide();
o->pad( false );
o->size( 100, 100 );
}
{ Fl_Box *o = new Fl_Box( 0, 0, 100, 12 );
o->align( (Fl_Align)(FL_ALIGN_BOTTOM | FL_ALIGN_INSIDE) );
o->labelsize( 10 );
o->label( "Inputs" );
}
{
Controller_Module *m = jack_input_controller = new Controller_Module( true );
m->labeltype( FL_NO_LABEL );
m->chain( _chain );
m->pad( false );
m->size( 33, 24 );
}
/* o->end(); */
/* } */
o->end();
}
@ -467,6 +497,8 @@ Mixer_Strip::init ( )
size( 96, h() );
redraw();
// _chain->configure_ports();
}
@ -476,8 +508,9 @@ Mixer_Strip::draw ( void )
if ( !fl_not_clipped( x(), y(), w(), h() ) )
return;
/* don't bother drawing anything else, all we're doing is drawing the focus. */
if ( damage() != FL_DAMAGE_USER1 )
/* don't bother drawing anything else, all we're doing is drawing the focus. */
if ( damage() & FL_DAMAGE_ALL ||
damage() & FL_DAMAGE_CHILD )
Fl_Group::draw();
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
return menu().test_shortcut() != 0;
break;
}
break;
case FL_PUSH:
{
take_focus();
int r = 0;
if ( Fl::event_button1() )
{
take_focus();
r = 1;
}
if ( Fl_Group::handle( m ) )
return 1;
if ( test_press( FL_BUTTON3 ) )
else if ( test_press( FL_BUTTON3 ) )
{
menu_popup( &menu() );
return 1;
}
return 0;
else
return r;
break;
}
case FL_FOCUS:
damage( FL_DAMAGE_USER1 );

View File

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

View File

@ -281,7 +281,7 @@ Module_Parameter_Editor::make_controls ( void )
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->color(FL_GRAY0);
o->selection_color(FL_BACKGROUND_COLOR);
@ -289,7 +289,7 @@ Module_Parameter_Editor::make_controls ( void )
o->labelfont(0);
o->labelcolor(FL_FOREGROUND_COLOR);
o->align(FL_ALIGN_TOP);
o->when(FL_WHEN_RELEASE);
o->when(FL_WHEN_CHANGED);
o->label( "Spatialization" );
o->align(FL_ALIGN_TOP);
@ -370,5 +370,8 @@ void
Module_Parameter_Editor::set_value (int i, float 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;
redraw();
return 0;
return 1;
}
else if ( Fl::event_button1() && ( drag = event_point() ) )
return 1;
else
return 0;
case FL_RELEASE:
drag = NULL;
do_callback();
redraw();
return 1;
if ( Fl::event_button1() && drag )
{
drag = NULL;
do_callback();
redraw();
return 1;
}
else
return 0;
case FL_MOUSEWHEEL:
{
/* TODO: place point on opposite face of sphere */
}
case FL_DRAG:
{
if ( ! drag )
return 0;
float X = Fl::event_x() - x();
float Y = Fl::event_y() - y();
@ -312,7 +320,10 @@ Panner::handle ( int m )
/* if ( _outs < 3 ) */
/* drag->angle( (float)(X / (tw / 2)) - 1.0f, 0.0f ); */
/* 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();