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. */
|
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include "const.h"
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2010-01-25 03:12:10 +01:00
|
|
|
|
|
2010-01-30 17:58:59 +01:00
|
|
|
|
#include <FL/fl_ask.H>
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include "dsp.h"
|
|
|
|
|
|
|
|
|
|
#include "Engine/Engine.H"
|
2009-12-25 01:59:39 +01:00
|
|
|
|
#include "Chain.H"
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
#include "JACK_Module.H"
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JACK_Module::JACK_Module ( )
|
|
|
|
|
: Module ( 50, 24, name() )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
|
|
|
|
/* FIXME: how do Controls find out that a connected value has changed? How does this work in ladspa? */
|
|
|
|
|
{
|
|
|
|
|
Port p( this, Port::INPUT, Port::CONTROL, "Inputs" );
|
|
|
|
|
p.hints.type = Port::Hints::INTEGER;
|
|
|
|
|
p.hints.minimum = 0;
|
2010-02-27 19:38:45 +01:00
|
|
|
|
p.hints.maximum = 16;
|
2010-01-15 08:53:29 +01:00
|
|
|
|
p.hints.ranged = true;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
p.connect_to( new float );
|
|
|
|
|
p.control_value_no_callback( 0 );
|
|
|
|
|
|
|
|
|
|
add_port( p );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
Port p( this, Port::INPUT, Port::CONTROL, "Outputs" );
|
|
|
|
|
p.hints.type = Port::Hints::INTEGER;
|
|
|
|
|
p.hints.minimum = 0;
|
2010-02-27 19:38:45 +01:00
|
|
|
|
p.hints.maximum = 16;
|
2010-01-15 08:53:29 +01:00
|
|
|
|
p.hints.ranged = true;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
p.connect_to( new float );
|
|
|
|
|
p.control_value_no_callback( 0 );
|
|
|
|
|
|
|
|
|
|
add_port( p );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end();
|
2009-12-28 06:25:28 +01:00
|
|
|
|
|
|
|
|
|
log_create();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
|
JACK_Module::~JACK_Module ( )
|
|
|
|
|
{
|
|
|
|
|
log_destroy();
|
|
|
|
|
configure_inputs( 0 );
|
2010-01-11 07:43:22 +01:00
|
|
|
|
configure_outputs( 0 );
|
2009-12-28 06:25:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
int
|
2010-02-01 07:23:01 +01:00
|
|
|
|
JACK_Module::can_support_inputs ( int )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
|
|
|
|
return audio_output.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
JACK_Module::configure_inputs ( int n )
|
|
|
|
|
{
|
|
|
|
|
int on = audio_input.size();
|
|
|
|
|
|
|
|
|
|
if ( n > on )
|
|
|
|
|
{
|
|
|
|
|
for ( int i = on; i < n; ++i )
|
|
|
|
|
{
|
2010-01-17 01:38:27 +01:00
|
|
|
|
JACK::Port po( chain()->engine(), JACK::Port::Output, i );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2010-01-30 17:58:59 +01:00
|
|
|
|
if ( ! po.activate() )
|
|
|
|
|
{
|
|
|
|
|
jack_port_activation_error( &po );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
if ( po.valid() )
|
|
|
|
|
{
|
|
|
|
|
add_port( Port( this, Port::INPUT, Port::AUDIO ) );
|
|
|
|
|
jack_output.push_back( po );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for ( int i = on; i > n; --i )
|
|
|
|
|
{
|
|
|
|
|
audio_input.back().disconnect();
|
|
|
|
|
audio_input.pop_back();
|
|
|
|
|
jack_output.back().shutdown();
|
|
|
|
|
jack_output.pop_back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
control_input[0].control_value_no_callback( n );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-30 17:58:59 +01:00
|
|
|
|
void
|
|
|
|
|
JACK_Module::jack_port_activation_error ( JACK::Port *p )
|
|
|
|
|
{
|
|
|
|
|
fl_alert( "Could not activate JACK port \"%s\"", p->name() );
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
bool
|
|
|
|
|
JACK_Module::configure_outputs ( int n )
|
|
|
|
|
{
|
|
|
|
|
int on = audio_output.size();
|
|
|
|
|
|
|
|
|
|
if ( n > on )
|
|
|
|
|
{
|
|
|
|
|
for ( int i = on; i < n; ++i )
|
|
|
|
|
{
|
2010-01-17 01:38:27 +01:00
|
|
|
|
JACK::Port po( chain()->engine(), JACK::Port::Input, i );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2010-01-30 17:58:59 +01:00
|
|
|
|
if ( ! po.activate() )
|
|
|
|
|
{
|
|
|
|
|
jack_port_activation_error( &po );
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
if ( po.valid() )
|
|
|
|
|
{
|
|
|
|
|
add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );
|
|
|
|
|
jack_input.push_back( po );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for ( int i = on; i > n; --i )
|
|
|
|
|
{
|
|
|
|
|
audio_output.back().disconnect();
|
|
|
|
|
audio_output.pop_back();
|
|
|
|
|
jack_input.back().shutdown();
|
|
|
|
|
jack_input.pop_back();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
control_input[1].control_value_no_callback( n );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
JACK_Module::initialize ( void )
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
JACK_Module::handle_control_changed ( Port *p )
|
|
|
|
|
{
|
2010-01-15 08:53:29 +01:00
|
|
|
|
THREAD_ASSERT( UI );
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
if ( 0 == strcmp( p->name(), "Inputs" ) )
|
|
|
|
|
{
|
|
|
|
|
DMESSAGE( "Adjusting number of inputs (JACK outputs)" );
|
|
|
|
|
configure_inputs( p->control_value() );
|
2009-12-28 06:25:28 +01:00
|
|
|
|
if ( chain() )
|
|
|
|
|
chain()->configure_ports();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
else if ( 0 == strcmp( p->name(), "Outputs" ) )
|
|
|
|
|
{
|
|
|
|
|
DMESSAGE( "Adjusting number of outputs (JACK inputs)" );
|
2010-01-15 08:53:29 +01:00
|
|
|
|
|
|
|
|
|
if ( ! chain() )
|
|
|
|
|
{
|
|
|
|
|
configure_outputs( p->control_value() );
|
|
|
|
|
}
|
|
|
|
|
else if ( chain()->can_configure_outputs( this, p->control_value() ) )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
|
|
|
|
configure_outputs( p->control_value() );
|
|
|
|
|
chain()->configure_ports();
|
|
|
|
|
}
|
2009-12-28 06:25:28 +01:00
|
|
|
|
else
|
2010-01-15 08:53:29 +01:00
|
|
|
|
{
|
|
|
|
|
p->connected_port()->control_value( noutputs() );
|
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
JACK_Module::handle_chain_name_changed ( void )
|
|
|
|
|
{
|
|
|
|
|
for ( unsigned int i = 0; i < jack_output.size(); ++i )
|
2010-01-17 01:38:27 +01:00
|
|
|
|
jack_output[ i ].name( NULL, i );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < jack_input.size(); ++i )
|
2010-01-17 01:38:27 +01:00
|
|
|
|
jack_input[ i ].name( NULL, i );
|
2012-02-09 01:20:02 +01:00
|
|
|
|
|
|
|
|
|
Module::handle_chain_name_changed();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-25 03:12:10 +01:00
|
|
|
|
/**********/
|
|
|
|
|
/* Engine */
|
|
|
|
|
/**********/
|
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
|
void
|
2010-01-30 09:35:32 +01:00
|
|
|
|
JACK_Module::process ( nframes_t nframes )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
{
|
2010-01-30 09:35:32 +01:00
|
|
|
|
for ( unsigned int i = 0; i < audio_input.size(); ++i )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
if ( audio_input[i].connected() )
|
2010-01-30 09:35:32 +01:00
|
|
|
|
buffer_copy( (sample_t*)jack_output[i].buffer( nframes ), (sample_t*)audio_input[i].buffer(), nframes );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
2010-01-30 09:35:32 +01:00
|
|
|
|
for ( unsigned int i = 0; i < audio_output.size(); ++i )
|
2009-12-25 01:59:39 +01:00
|
|
|
|
if ( audio_output[i].connected() )
|
2010-01-30 09:35:32 +01:00
|
|
|
|
buffer_copy( (sample_t*)audio_output[i].buffer(), (sample_t*)jack_input[i].buffer( nframes ), nframes );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
}
|