2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
/* Copyright (C) 2009 Jonathan Moore Liles */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program is free software; you can redistribute it and/or modify it */
|
|
|
|
|
/* under the terms of the GNU General Public License as published by the */
|
|
|
|
|
/* Free Software Foundation; either version 2 of the License, or (at your */
|
|
|
|
|
/* option) any later version. */
|
|
|
|
|
/* */
|
|
|
|
|
/* This program is distributed in the hope that it will be useful, but WITHOUT */
|
|
|
|
|
/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
|
|
|
|
|
/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
|
|
|
|
|
/* more details. */
|
|
|
|
|
/* */
|
|
|
|
|
/* You should have received a copy of the GNU General Public License along */
|
|
|
|
|
/* with This program; see the file COPYING. If not,write to the Free Software */
|
|
|
|
|
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/* Filter chain. This would all be much simpler if we chose not to
|
|
|
|
|
* allow non 1:1 plugins to be mixed in a single chain...
|
|
|
|
|
*
|
|
|
|
|
* Supporting the mixture requires duplicating some inputs (to satisfy
|
|
|
|
|
* stereo input plugins reading mono outputs) and duplicating some
|
|
|
|
|
* plugins (to satisfy mono input plugins reading stereo outputs).
|
|
|
|
|
*
|
|
|
|
|
* Basically, what this means is that the intermediate number of
|
|
|
|
|
* buffers need not have any relation to the starting and ending
|
|
|
|
|
* buffer count. (Picture an ambisonic panner going into an ambisonic
|
|
|
|
|
* decoder (1:6:2).
|
|
|
|
|
*
|
|
|
|
|
* The chain will allocate enough buffers to hold data from the
|
|
|
|
|
* maximum number of channels used by a contained module.
|
|
|
|
|
*
|
|
|
|
|
* The process thread goes as follows:
|
|
|
|
|
*
|
|
|
|
|
* 1. Copy inputs to chain buffers.
|
|
|
|
|
*
|
|
|
|
|
* 2. process() each module in turn (reusing buffers in-place) (inputs
|
|
|
|
|
* will be copied or plugins duplicated as necessary)
|
|
|
|
|
*
|
|
|
|
|
* 3. Copy chain buffers to outputs.
|
|
|
|
|
*
|
|
|
|
|
* For chains where the number of channels never exceeds the maximum
|
|
|
|
|
* of the number of inputs and outputs, the first copy can be
|
|
|
|
|
* optimized out.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-01-17 04:51:14 +01:00
|
|
|
|
#include "const.h"
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
2010-01-17 04:51:14 +01:00
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
#include "Chain.H"
|
|
|
|
|
#include "Module.H"
|
|
|
|
|
#include "Meter_Module.H"
|
|
|
|
|
#include "JACK_Module.H"
|
|
|
|
|
#include "Gain_Module.H"
|
|
|
|
|
#include "Plugin_Module.H"
|
2010-01-14 04:19:12 +01:00
|
|
|
|
#include "Controller_Module.H"
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
#include <Fl/Fl_Box.H>
|
|
|
|
|
#include <FL/Fl_Menu.H>
|
|
|
|
|
#include <FL/fl_ask.H>
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include <FL/Fl_Flip_Button.H>
|
2009-12-25 01:59:39 +01:00
|
|
|
|
#include <FL/Fl_Tabs.H>
|
|
|
|
|
#include "FL/Fl_Flowpack.H"
|
|
|
|
|
#include "FL/Fl_Scroll.H"
|
2010-01-23 05:00:27 +01:00
|
|
|
|
#include "FL/Fl_Packscroller.H"
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
#include "FL/menu_popup.H"
|
|
|
|
|
#include "FL/test_press.H"
|
|
|
|
|
|
2010-02-01 07:25:16 +01:00
|
|
|
|
#include "debug.h"
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include "Engine/Engine.H"
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
#include "Mixer_Strip.H"
|
2009-12-25 20:14:57 +01:00
|
|
|
|
#include <dsp.h>
|
|
|
|
|
|
2010-02-01 05:21:05 +01:00
|
|
|
|
extern char *instance_name;
|
2009-12-28 06:25:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Chain::Chain ( int X, int Y, int W, int H, const char *L ) : */
|
|
|
|
|
/* Fl_Group( X, Y, W, H, L) */
|
|
|
|
|
Chain::Chain ( ) : Fl_Group( 0, 0, 100, 100, "")
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2010-01-18 05:58:05 +01:00
|
|
|
|
_engine = NULL;
|
2010-01-16 09:00:47 +01:00
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
int X = 0;
|
|
|
|
|
int Y = 0;
|
|
|
|
|
int W = 100;
|
|
|
|
|
int H = 100;
|
|
|
|
|
|
|
|
|
|
/* _outs = 1; */
|
|
|
|
|
/* _ins = 1; */
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
_configure_outputs_callback = NULL;
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
_strip = NULL;
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
_name = NULL;
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
labelsize( 10 );
|
|
|
|
|
align( FL_ALIGN_TOP );
|
|
|
|
|
|
2010-01-12 06:23:40 +01:00
|
|
|
|
{ Fl_Flip_Button* o = tab_button = new Fl_Flip_Button( X, Y, W, 16, "chain/controls");
|
|
|
|
|
o->type(1);
|
|
|
|
|
o->labelsize( 12 );
|
|
|
|
|
o->callback( cb_handle, this );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Y += 18;
|
|
|
|
|
H -= 18;
|
|
|
|
|
|
|
|
|
|
{ Fl_Group *o = chain_tab = new Fl_Group( X, Y, W, H, "" );
|
|
|
|
|
o->labeltype( FL_NO_LABEL );
|
|
|
|
|
o->box( FL_FLAT_BOX );
|
2010-02-01 02:14:54 +01:00
|
|
|
|
// o->color( fl_darker( FL_BACKGROUND_COLOR ) );
|
|
|
|
|
// o->color( FL_BACKGROUND_COLOR );
|
2010-01-18 06:28:04 +01:00
|
|
|
|
// o->box( FL_NO_BOX );
|
2010-01-23 05:00:27 +01:00
|
|
|
|
{ Fl_Packscroller *o = new Fl_Packscroller( X, Y, W, H );
|
2010-02-01 02:14:54 +01:00
|
|
|
|
o->color( FL_BACKGROUND_COLOR );
|
2010-01-23 05:00:27 +01:00
|
|
|
|
// o->box( FL_FLAT_BOX );
|
|
|
|
|
o->box( FL_THIN_UP_BOX );
|
2010-01-19 08:47:26 +01:00
|
|
|
|
o->type( Fl_Scroll::VERTICAL );
|
|
|
|
|
{ Fl_Pack *o = modules_pack = new Fl_Pack( X, Y, W, H );
|
|
|
|
|
o->type( Fl_Pack::VERTICAL );
|
|
|
|
|
o->spacing( 10 );
|
|
|
|
|
o->end();
|
|
|
|
|
Fl_Group::current()->resizable( o );
|
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
o->end();
|
|
|
|
|
}
|
2010-01-12 06:23:40 +01:00
|
|
|
|
o->end();
|
|
|
|
|
}
|
|
|
|
|
{ Fl_Group *o = control_tab = new Fl_Group( X, Y, W, H, "" );
|
2010-01-18 06:28:04 +01:00
|
|
|
|
o->box( FL_NO_BOX );
|
2010-01-12 06:23:40 +01:00
|
|
|
|
o->labeltype( FL_NO_LABEL );
|
|
|
|
|
o->hide();
|
|
|
|
|
{ Fl_Scroll *o = new Fl_Scroll( X, Y, W, H );
|
2010-02-01 02:14:54 +01:00
|
|
|
|
o->color( FL_BACKGROUND_COLOR );
|
2010-01-21 07:50:54 +01:00
|
|
|
|
o->box( FL_FLAT_BOX );
|
2010-01-12 06:23:40 +01:00
|
|
|
|
o->type( Fl_Scroll::VERTICAL );
|
|
|
|
|
{ Fl_Flowpack *o = controls_pack = new Fl_Flowpack( X, Y, W, H );
|
|
|
|
|
o->hspacing( 10 );
|
|
|
|
|
o->vspacing( 10 );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
// o->box( FL_FLAT_BOX );
|
|
|
|
|
// o->color( FL_RED );
|
|
|
|
|
o->end();
|
|
|
|
|
Fl_Group::current()->resizable( o );
|
|
|
|
|
}
|
|
|
|
|
o->end();
|
|
|
|
|
Fl_Group::current()->resizable( o );
|
|
|
|
|
}
|
|
|
|
|
o->end();
|
2010-01-12 06:23:40 +01:00
|
|
|
|
o->hide();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
Fl_Group::current()->resizable( o );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end();
|
2009-12-26 05:16:24 +01:00
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
log_create();
|
2009-12-26 05:16:24 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Chain::~Chain ( )
|
|
|
|
|
{
|
2010-01-16 09:00:47 +01:00
|
|
|
|
DMESSAGE( "Destroying chain" );
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
log_destroy();
|
2010-01-16 09:00:47 +01:00
|
|
|
|
|
2010-01-17 04:51:14 +01:00
|
|
|
|
engine()->lock();
|
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
/* if we leave this up to FLTK, it will happen after we've
|
|
|
|
|
already destroyed the engine */
|
|
|
|
|
modules_pack->clear();
|
|
|
|
|
controls_pack->clear();
|
|
|
|
|
|
|
|
|
|
delete _engine;
|
|
|
|
|
_engine = NULL;
|
2009-12-28 06:25:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
void
|
|
|
|
|
Chain::get ( Log_Entry &e ) const
|
|
|
|
|
{
|
|
|
|
|
e.add( ":strip", strip() );
|
|
|
|
|
e.add( ":tab", tab_button->value() ? "controls" : "chain" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Chain::set ( Log_Entry &e )
|
|
|
|
|
{
|
|
|
|
|
for ( int i = 0; i < e.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
const char *s, *v;
|
|
|
|
|
|
|
|
|
|
e.get( i, &s, &v );
|
|
|
|
|
|
|
|
|
|
if ( ! strcmp( s, ":tab" ) )
|
|
|
|
|
{
|
|
|
|
|
tab_button->value( strcmp( v, "controls" ) == 0 );
|
|
|
|
|
tab_button->do_callback();
|
|
|
|
|
}
|
|
|
|
|
else if ( ! strcmp( s, ":strip" ) )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
sscanf( v, "%X", &i );
|
|
|
|
|
Mixer_Strip *t = (Mixer_Strip*)Loggable::find( i );
|
|
|
|
|
|
|
|
|
|
assert( t );
|
|
|
|
|
|
|
|
|
|
t->chain( this );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
void
|
|
|
|
|
Chain::log_children ( void )
|
|
|
|
|
{
|
|
|
|
|
log_create();
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < modules(); ++i )
|
|
|
|
|
{
|
|
|
|
|
module(i)->log_create();
|
|
|
|
|
}
|
2010-01-14 04:19:12 +01:00
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < controls_pack->children(); ++i )
|
|
|
|
|
{
|
|
|
|
|
Controller_Module *cm = (Controller_Module*)controls_pack->child( i );
|
|
|
|
|
|
|
|
|
|
cm->log_create();
|
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Fill this chain with JACK I/O, Gain, and Meter modules. */
|
|
|
|
|
void
|
|
|
|
|
Chain::initialize_with_default ( void )
|
|
|
|
|
{
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
{ JACK_Module *m = new JACK_Module();
|
|
|
|
|
m->is_default( true );
|
|
|
|
|
m->chain( this );
|
|
|
|
|
m->configure_outputs( 1 );
|
|
|
|
|
m->initialize();
|
|
|
|
|
add( m );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{ Module *m = new Gain_Module();
|
|
|
|
|
m->is_default( true );
|
|
|
|
|
m->initialize();
|
|
|
|
|
add( m );
|
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
{ Module *m = new Meter_Module();
|
|
|
|
|
m->is_default( true );
|
|
|
|
|
add( m );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
{ JACK_Module *m = new JACK_Module();
|
|
|
|
|
m->is_default( true );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
m->chain( this );
|
|
|
|
|
m->initialize();
|
2009-12-28 06:25:28 +01:00
|
|
|
|
add( m );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Chain::cb_handle(Fl_Widget* o) {
|
2010-01-17 04:51:14 +01:00
|
|
|
|
if ( o == tab_button )
|
2010-01-12 06:23:40 +01:00
|
|
|
|
{
|
|
|
|
|
Fl_Flip_Button *fb = (Fl_Flip_Button*)o;
|
|
|
|
|
|
|
|
|
|
if ( fb->value() == 0 )
|
|
|
|
|
{
|
|
|
|
|
control_tab->hide();
|
|
|
|
|
chain_tab->show();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
chain_tab->hide();
|
|
|
|
|
control_tab->show();
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Chain::cb_handle(Fl_Widget* o, void* v) {
|
|
|
|
|
((Chain*)(v))->cb_handle(o);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* remove a module from the chain. this isn't guaranteed to succeed,
|
|
|
|
|
* because removing the module might result in an invalid routing */
|
|
|
|
|
void
|
|
|
|
|
Chain::remove ( Module *m )
|
|
|
|
|
{
|
|
|
|
|
int i = modules_pack->find( m );
|
|
|
|
|
|
|
|
|
|
int ins = 0;
|
|
|
|
|
|
|
|
|
|
if ( i != 0 )
|
|
|
|
|
ins = module( i - 1 )->noutputs();
|
|
|
|
|
|
|
|
|
|
if ( ! can_configure_outputs( m, ins ) )
|
|
|
|
|
{
|
|
|
|
|
fl_alert( "Can't remove module at this point because the resultant chain is invalid" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modules_pack->remove( m );
|
|
|
|
|
|
|
|
|
|
configure_ports();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* determine number of output ports, signal if changed. */
|
|
|
|
|
void
|
|
|
|
|
Chain::configure_ports ( void )
|
|
|
|
|
{
|
2009-12-28 06:25:28 +01:00
|
|
|
|
int nouts = 0;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
engine()->lock();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < modules(); ++i )
|
|
|
|
|
{
|
|
|
|
|
module( i )->configure_inputs( nouts );
|
|
|
|
|
nouts = module( i )->noutputs();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-17 04:51:14 +01:00
|
|
|
|
unsigned int req_buffers = required_buffers();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
DMESSAGE( "required_buffers = %i", req_buffers );
|
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
if ( scratch_port.size() < req_buffers )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2010-01-16 09:00:47 +01:00
|
|
|
|
for ( unsigned int i = scratch_port.size(); i--; )
|
|
|
|
|
delete[] (sample_t*)scratch_port[i].buffer();
|
|
|
|
|
scratch_port.clear();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < req_buffers; ++i )
|
|
|
|
|
{
|
|
|
|
|
Module::Port p( NULL, Module::Port::OUTPUT, Module::Port::AUDIO );
|
2010-01-16 09:00:47 +01:00
|
|
|
|
p.connect_to( new sample_t[engine()->nframes()] );
|
|
|
|
|
buffer_fill_with_silence( (sample_t*)p.buffer(), engine()->nframes() );
|
|
|
|
|
scratch_port.push_back( p );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build_process_queue();
|
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
engine()->unlock();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
parent()->redraw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* calculate the minimum number of buffers required to satisfy this chain */
|
|
|
|
|
int
|
|
|
|
|
Chain::required_buffers ( void )
|
|
|
|
|
{
|
|
|
|
|
int buffers = 0;
|
|
|
|
|
int outs = 0;
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < modules(); ++i )
|
|
|
|
|
{
|
|
|
|
|
outs = module( i )->can_support_inputs( outs );
|
|
|
|
|
|
|
|
|
|
if ( outs > buffers )
|
|
|
|
|
buffers = outs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return buffers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* called by a module when it wants to alter the number of its
|
|
|
|
|
* outputs. Also used to test for chain validity when inserting /
|
|
|
|
|
* removing modules */
|
|
|
|
|
bool
|
|
|
|
|
Chain::can_configure_outputs ( Module *m, int n ) const
|
|
|
|
|
{
|
|
|
|
|
/* start at the requesting module */
|
|
|
|
|
|
|
|
|
|
int outs = n;
|
|
|
|
|
|
|
|
|
|
int i = modules_pack->find( m );
|
|
|
|
|
|
|
|
|
|
if ( modules() - 1 == i )
|
|
|
|
|
/* last module */
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
for ( i++ ; i < modules(); ++i )
|
|
|
|
|
{
|
|
|
|
|
outs = module( i )->can_support_inputs( outs );
|
|
|
|
|
|
|
|
|
|
if ( outs < 0 )
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-01 07:23:01 +01:00
|
|
|
|
unsigned int
|
2010-01-31 20:34:18 +01:00
|
|
|
|
Chain::maximum_name_length ( void )
|
|
|
|
|
{
|
2010-02-01 05:21:05 +01:00
|
|
|
|
return JACK::Client::maximum_name_length() - ( strlen( APP_NAME ) + 1 + ( instance_name ? strlen( instance_name ) + 1 : 0 ) );
|
2010-01-31 20:34:18 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
/* rename chain... we have to let our modules know our name has
|
|
|
|
|
* changed so they can take the appropriate action (in particular the
|
|
|
|
|
* JACK module). */
|
|
|
|
|
void
|
|
|
|
|
Chain::name ( const char *name )
|
|
|
|
|
{
|
2010-01-17 01:38:27 +01:00
|
|
|
|
char ename[512];
|
2010-02-01 05:21:05 +01:00
|
|
|
|
snprintf( ename, sizeof(ename), "%s%s%s/%s", APP_NAME, instance_name ? "." : "", instance_name ? instance_name : "", name );
|
2010-01-17 01:38:27 +01:00
|
|
|
|
|
2010-01-18 05:58:05 +01:00
|
|
|
|
if ( ! _engine )
|
|
|
|
|
{
|
|
|
|
|
_engine = new Engine( &Chain::process, this );
|
|
|
|
|
|
2010-01-30 09:35:32 +01:00
|
|
|
|
engine()->buffer_size_callback( &Chain::buffer_size, this );
|
|
|
|
|
|
2010-01-30 17:58:59 +01:00
|
|
|
|
const char *jack_name = engine()->init( ename );
|
|
|
|
|
|
|
|
|
|
if ( ! jack_name )
|
|
|
|
|
{
|
|
|
|
|
_engine = NULL;
|
|
|
|
|
|
|
|
|
|
fl_alert( "Could not create JACK client. Perhaps the sound device already in use. In any event, now I'll die." );
|
|
|
|
|
exit( 1 );
|
|
|
|
|
return;
|
|
|
|
|
}
|
2010-01-18 05:58:05 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
DMESSAGE( "Renaming JACK client from \"%s\" to \"%s\"", _name, ename );
|
|
|
|
|
|
|
|
|
|
_name = engine()->name( ename );
|
|
|
|
|
/* FIXME: discarding the name jack picked is technically wrong! */
|
2010-01-17 01:38:27 +01:00
|
|
|
|
|
2010-01-18 05:58:05 +01:00
|
|
|
|
}
|
2010-01-17 01:38:27 +01:00
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
_name = name;
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < modules(); ++i )
|
|
|
|
|
module( i )->handle_chain_name_changed();
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
bool
|
|
|
|
|
Chain::add ( Module *m )
|
|
|
|
|
{
|
2010-01-21 07:50:12 +01:00
|
|
|
|
/* FIXME: hacky */
|
|
|
|
|
if ( !strcmp( m->name(), "Controller" ) )
|
|
|
|
|
return false;
|
|
|
|
|
else
|
|
|
|
|
return insert( NULL, m );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Chain::add ( Controller_Module *m )
|
|
|
|
|
{
|
|
|
|
|
DMESSAGE( "Adding control" );
|
|
|
|
|
add_control(m);
|
|
|
|
|
return true;
|
2009-12-28 06:25:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
bool
|
|
|
|
|
Chain::insert ( Module *m, Module *n )
|
|
|
|
|
{
|
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
engine()->lock();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
if ( !m )
|
|
|
|
|
{
|
|
|
|
|
if ( modules() == 0 && n->can_support_inputs( 0 ) >= 0 )
|
|
|
|
|
{
|
|
|
|
|
n->configure_inputs( 0 );
|
|
|
|
|
modules_pack->add( n );
|
|
|
|
|
n->chain( this );
|
|
|
|
|
}
|
|
|
|
|
else if ( n->can_support_inputs( module( modules() - 1 )->noutputs() ) >= 0 )
|
|
|
|
|
{
|
|
|
|
|
n->configure_inputs( module( modules() - 1 )->noutputs() );
|
|
|
|
|
modules_pack->add( n );
|
|
|
|
|
n->chain( this );
|
|
|
|
|
}
|
|
|
|
|
else
|
2010-01-18 05:01:37 +01:00
|
|
|
|
{
|
|
|
|
|
DMESSAGE( "Module says it can't support %i inputs", module( modules() - 1 )->noutputs() );
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
goto err;
|
2010-01-18 05:01:37 +01:00
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int i = modules_pack->find( m );
|
|
|
|
|
|
|
|
|
|
if ( 0 == i )
|
|
|
|
|
{
|
|
|
|
|
/* inserting to head of chain*/
|
|
|
|
|
if ( n->can_support_inputs( 0 ) >= 0 )
|
|
|
|
|
n->configure_inputs( 0 );
|
|
|
|
|
else
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if ( n->can_support_inputs( module( i - 1 )->noutputs() ) >= 0 )
|
|
|
|
|
{
|
|
|
|
|
n->configure_inputs( module( i - 1 )->noutputs() );
|
|
|
|
|
|
|
|
|
|
m->configure_inputs( n->noutputs() );
|
|
|
|
|
|
|
|
|
|
for ( int j = i + 1; j < modules(); ++j )
|
|
|
|
|
module( j )->configure_inputs( module( j - 1 )->noutputs() );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
modules_pack->insert( *n, i );
|
|
|
|
|
n->chain( this );
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-18 05:01:37 +01:00
|
|
|
|
DMESSAGE( "Module \"%s\" has %i:%i audio and %i:%i control ports",
|
|
|
|
|
n->name(),
|
2009-12-25 01:59:39 +01:00
|
|
|
|
n->ninputs(),
|
|
|
|
|
n->noutputs(),
|
|
|
|
|
n->ncontrol_inputs(),
|
|
|
|
|
n->ncontrol_outputs() );
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
strip()->handle_module_added( n );
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
configure_ports();
|
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
engine()->unlock();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
|
2010-01-18 05:01:37 +01:00
|
|
|
|
DMESSAGE( "Insert failed" );
|
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
engine()->unlock();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add a control to the control strip. Assumed to already be connected! */
|
|
|
|
|
void
|
2010-01-21 07:50:12 +01:00
|
|
|
|
Chain::add_control ( Controller_Module *m )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2010-01-16 09:00:47 +01:00
|
|
|
|
engine()->lock();
|
2010-01-14 04:19:12 +01:00
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
controls_pack->add( m );
|
2010-01-14 04:19:12 +01:00
|
|
|
|
|
2010-01-24 23:34:57 +01:00
|
|
|
|
configure_ports();
|
|
|
|
|
|
2010-01-16 09:00:47 +01:00
|
|
|
|
engine()->unlock();
|
2010-01-14 04:19:12 +01:00
|
|
|
|
|
|
|
|
|
controls_pack->redraw();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Chain::draw_connections ( Module *m )
|
|
|
|
|
{
|
|
|
|
|
int spacing;
|
|
|
|
|
int offset;
|
|
|
|
|
|
2010-01-23 05:00:27 +01:00
|
|
|
|
int X, Y, W, H;
|
|
|
|
|
|
|
|
|
|
((Fl_Packscroller*)chain_tab->child( 0 ))->bbox( X, Y, W, H );
|
|
|
|
|
|
|
|
|
|
fl_push_clip( X, Y, W, H );
|
2010-01-19 08:47:26 +01:00
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
Fl_Color c =fl_color_average( FL_WHITE, FL_YELLOW, 0.50 );
|
|
|
|
|
fl_color( c );
|
|
|
|
|
|
|
|
|
|
if ( m->ninputs() )
|
|
|
|
|
{
|
|
|
|
|
spacing = w() / m->ninputs();
|
|
|
|
|
offset = spacing / 2;
|
|
|
|
|
|
|
|
|
|
for ( int i = m->ninputs(); i--; )
|
|
|
|
|
fl_rectf( m->x() + offset + ( spacing * i ), m->y() - 5, 2, 5 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fl_color( fl_darker( c ) );
|
|
|
|
|
|
|
|
|
|
if ( m->noutputs() )
|
|
|
|
|
{
|
|
|
|
|
spacing = w() / m->noutputs();
|
|
|
|
|
offset = spacing / 2;
|
|
|
|
|
for ( int i = m->noutputs(); i--; )
|
|
|
|
|
fl_rectf( m->x() + offset + ( spacing * i ), m->y() + m->h(), 2, 5 );
|
|
|
|
|
}
|
2010-01-19 08:47:26 +01:00
|
|
|
|
|
|
|
|
|
fl_pop_clip();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Chain::add_to_process_queue ( Module *m )
|
|
|
|
|
{
|
|
|
|
|
for ( std::list<Module*>::const_iterator i = process_queue.begin(); i != process_queue.end(); ++i )
|
|
|
|
|
if ( m == *i )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
process_queue.push_back( m );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* run any time the internal connection graph might have
|
|
|
|
|
* changed... Tells the process thread what order modules need to be
|
|
|
|
|
* run in. */
|
|
|
|
|
void
|
|
|
|
|
Chain::build_process_queue ( void )
|
|
|
|
|
{
|
|
|
|
|
process_queue.clear();
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < modules(); ++i )
|
|
|
|
|
{
|
|
|
|
|
Module *m = (Module*)module( i );
|
|
|
|
|
|
|
|
|
|
/* controllers */
|
|
|
|
|
for ( unsigned int j = 0; j < m->control_input.size(); ++j )
|
|
|
|
|
{
|
|
|
|
|
if ( m->control_input[j].connected() )
|
|
|
|
|
{
|
|
|
|
|
add_to_process_queue( m->control_input[j].connected_port()->module() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* audio modules */
|
|
|
|
|
add_to_process_queue( m );
|
|
|
|
|
|
|
|
|
|
/* indicators */
|
|
|
|
|
for ( unsigned int j = 0; j < m->control_output.size(); ++j )
|
|
|
|
|
{
|
|
|
|
|
if ( m->control_output[j].connected() )
|
|
|
|
|
{
|
|
|
|
|
add_to_process_queue( m->control_output[j].connected_port()->module() );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* connect all the ports to the buffers */
|
|
|
|
|
for ( int i = 0; i < modules(); ++i )
|
|
|
|
|
{
|
|
|
|
|
Module *m = module( i );
|
|
|
|
|
for ( unsigned int j = 0; j < m->audio_input.size(); ++j )
|
|
|
|
|
{
|
2010-01-16 09:00:47 +01:00
|
|
|
|
m->audio_input[j].connect_to( &scratch_port[j] );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
for ( unsigned int j = 0; j < m->audio_output.size(); ++j )
|
|
|
|
|
{
|
2010-01-16 09:00:47 +01:00
|
|
|
|
m->audio_output[j].connect_to( &scratch_port[j] );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
2009-12-25 20:16:07 +01:00
|
|
|
|
|
|
|
|
|
m->handle_port_connection_change();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
/* DMESSAGE( "Process queue looks like:" ); */
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2010-01-17 04:51:14 +01:00
|
|
|
|
/* for ( std::list<Module*>::const_iterator i = process_queue.begin(); i != process_queue.end(); ++i ) */
|
|
|
|
|
/* { */
|
|
|
|
|
/* const Module* m = *i; */
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
/* if ( m->audio_input.size() || m->audio_output.size() ) */
|
|
|
|
|
/* DMESSAGE( "\t%s", (*i)->name() ); */
|
|
|
|
|
/* else if ( m->control_output.size() ) */
|
|
|
|
|
/* DMESSAGE( "\t%s -->", (*i)->name() ); */
|
|
|
|
|
/* else if ( m->control_input.size() ) */
|
|
|
|
|
/* DMESSAGE( "\t%s <--", (*i)->name() ); */
|
2009-12-26 01:22:56 +01:00
|
|
|
|
|
2010-01-17 04:51:14 +01:00
|
|
|
|
/* { */
|
|
|
|
|
/* char *s = m->get_parameters(); */
|
2009-12-26 01:22:56 +01:00
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
/* DMESSAGE( "(%s)", s ); */
|
2009-12-26 01:22:56 +01:00
|
|
|
|
|
2010-01-17 04:51:14 +01:00
|
|
|
|
/* delete[] s; */
|
|
|
|
|
/* } */
|
|
|
|
|
/* } */
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
void
|
|
|
|
|
Chain::strip ( Mixer_Strip * ms )
|
|
|
|
|
{
|
|
|
|
|
_strip = ms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
void
|
|
|
|
|
Chain::draw ( void )
|
|
|
|
|
{
|
|
|
|
|
Fl_Group::draw();
|
|
|
|
|
|
2010-01-12 06:23:40 +01:00
|
|
|
|
/* if ( 0 == strcmp( "Chain", tabs->value()->label() ) ) */
|
|
|
|
|
if ( chain_tab->visible() )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
for ( int i = 0; i < modules(); ++i )
|
|
|
|
|
draw_connections( module( i ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Chain::resize ( int X, int Y, int W, int H )
|
|
|
|
|
{
|
|
|
|
|
Fl_Group::resize( X, Y, W, H );
|
|
|
|
|
|
|
|
|
|
/* this won't naturally resize because it's inside of an Fl_Scroll... */
|
|
|
|
|
controls_pack->size( W, controls_pack->h() );
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********/
|
|
|
|
|
/* Engine */
|
|
|
|
|
/**********/
|
2010-01-16 09:00:47 +01:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Chain::process ( nframes_t nframes, void *v )
|
|
|
|
|
{
|
|
|
|
|
((Chain*)v)->process( nframes );
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
void
|
|
|
|
|
Chain::process ( nframes_t nframes )
|
|
|
|
|
{
|
|
|
|
|
for ( std::list<Module*>::const_iterator i = process_queue.begin(); i != process_queue.end(); ++i )
|
|
|
|
|
{
|
|
|
|
|
Module *m = *i;
|
|
|
|
|
|
2010-01-28 05:39:27 +01:00
|
|
|
|
if ( ! m->bypass() )
|
2010-01-30 09:35:32 +01:00
|
|
|
|
m->process( nframes );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Chain::buffer_size ( nframes_t nframes, void *v )
|
|
|
|
|
{
|
|
|
|
|
((Chain*)v)->buffer_size( nframes );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Chain::buffer_size ( nframes_t nframes )
|
|
|
|
|
{
|
|
|
|
|
for ( unsigned int i = scratch_port.size(); i--; )
|
|
|
|
|
delete[] (sample_t*)scratch_port[i].buffer();
|
|
|
|
|
scratch_port.clear();
|
|
|
|
|
|
|
|
|
|
configure_ports();
|
|
|
|
|
|
|
|
|
|
for ( int i = 0; i < modules(); ++i )
|
|
|
|
|
{
|
|
|
|
|
Module *m = module(i);
|
|
|
|
|
|
|
|
|
|
m->resize_buffers( nframes );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|