2 /*******************************************************************************/
3 /* Copyright (C) 2009 Jonathan Moore Liles */
5 /* This program is free software; you can redistribute it and/or modify it */
6 /* under the terms of the GNU General Public License as published by the */
7 /* Free Software Foundation; either version 2 of the License, or (at your */
8 /* option) any later version. */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
12 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for */
15 /* You should have received a copy of the GNU General Public License along */
16 /* with This program; see the file COPYING. If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /*******************************************************************************/
24 #include <FL/fl_ask.H>
28 #include "Engine/Engine.H"
31 #include "JACK_Module.H"
35 JACK_Module::JACK_Module ( )
36 : Module ( 50, 24, name() )
38 /* FIXME: how do Controls find out that a connected value has changed? How does this work in ladspa? */
40 Port p( this, Port::INPUT, Port::CONTROL, "Inputs" );
41 p.hints.type = Port::Hints::INTEGER;
44 p.hints.ranged = true;
46 p.connect_to( new float );
47 p.control_value_no_callback( 0 );
53 Port p( this, Port::INPUT, Port::CONTROL, "Outputs" );
54 p.hints.type = Port::Hints::INTEGER;
57 p.hints.ranged = true;
59 p.connect_to( new float );
60 p.control_value_no_callback( 0 );
70 JACK_Module::~JACK_Module ( )
73 configure_inputs( 0 );
74 configure_outputs( 0 );
80 JACK_Module::can_support_inputs ( int )
82 return audio_output.size();
86 JACK_Module::configure_inputs ( int n )
88 int on = audio_input.size();
92 for ( int i = on; i < n; ++i )
94 JACK::Port po( chain()->engine(), JACK::Port::Output, i );
96 if ( ! po.activate() )
98 jack_port_activation_error( &po );
104 add_port( Port( this, Port::INPUT, Port::AUDIO ) );
105 jack_output.push_back( po );
111 for ( int i = on; i > n; --i )
113 audio_input.back().disconnect();
114 audio_input.pop_back();
115 jack_output.back().shutdown();
116 jack_output.pop_back();
120 control_input[0].control_value_no_callback( n );
126 JACK_Module::jack_port_activation_error ( JACK::Port *p )
128 fl_alert( "Could not activate JACK port \"%s\"", p->name() );
132 JACK_Module::configure_outputs ( int n )
134 int on = audio_output.size();
138 for ( int i = on; i < n; ++i )
140 JACK::Port po( chain()->engine(), JACK::Port::Input, i );
142 if ( ! po.activate() )
144 jack_port_activation_error( &po );
150 add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
151 jack_input.push_back( po );
157 for ( int i = on; i > n; --i )
159 audio_output.back().disconnect();
160 audio_output.pop_back();
161 jack_input.back().shutdown();
162 jack_input.pop_back();
166 control_input[1].control_value_no_callback( n );
172 JACK_Module::initialize ( void )
178 JACK_Module::handle_control_changed ( Port *p )
182 if ( 0 == strcmp( p->name(), "Inputs" ) )
184 DMESSAGE( "Adjusting number of inputs (JACK outputs)" );
185 configure_inputs( p->control_value() );
187 chain()->configure_ports();
189 else if ( 0 == strcmp( p->name(), "Outputs" ) )
191 DMESSAGE( "Adjusting number of outputs (JACK inputs)" );
195 configure_outputs( p->control_value() );
197 else if ( chain()->can_configure_outputs( this, p->control_value() ) )
199 configure_outputs( p->control_value() );
200 chain()->configure_ports();
204 p->connected_port()->control_value( noutputs() );
210 JACK_Module::handle_chain_name_changed ( void )
212 for ( unsigned int i = 0; i < jack_output.size(); ++i )
213 jack_output[ i ].name( NULL, i );
215 for ( unsigned int i = 0; i < jack_input.size(); ++i )
216 jack_input[ i ].name( NULL, i );
218 Module::handle_chain_name_changed();
228 JACK_Module::process ( nframes_t nframes )
230 for ( unsigned int i = 0; i < audio_input.size(); ++i )
231 if ( audio_input[i].connected() )
232 buffer_copy( (sample_t*)jack_output[i].buffer( nframes ), (sample_t*)audio_input[i].buffer(), nframes );
234 for ( unsigned int i = 0; i < audio_output.size(); ++i )
235 if ( audio_output[i].connected() )
236 buffer_copy( (sample_t*)audio_output[i].buffer(), (sample_t*)jack_input[i].buffer( nframes ), nframes );