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. */
|
|
|
|
/*******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Group.H>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2010-02-01 07:25:16 +01:00
|
|
|
#include "debug.h"
|
2009-12-25 01:59:39 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2010-02-01 07:25:16 +01:00
|
|
|
#include "Thread.H"
|
2009-12-25 01:59:39 +01:00
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
#include "Loggable.H"
|
2010-01-30 09:35:32 +01:00
|
|
|
#include "JACK/Port.H"
|
2012-02-09 07:38:34 +01:00
|
|
|
#include "OSC/Endpoint.H"
|
2009-12-28 06:25:28 +01:00
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
class Chain;
|
|
|
|
class Module_Parameter_Editor;
|
2010-01-28 05:39:27 +01:00
|
|
|
class Fl_Menu_;
|
|
|
|
class Fl_Menu_Button;
|
|
|
|
class Fl_Button;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
class Module : public Fl_Group, public Loggable {
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
int _ins;
|
|
|
|
int _outs;
|
|
|
|
int _instances;
|
2010-01-30 09:35:32 +01:00
|
|
|
nframes_t _nframes;
|
2009-12-25 01:59:39 +01:00
|
|
|
Chain *_chain;
|
2009-12-28 06:25:28 +01:00
|
|
|
bool _is_default;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
Module_Parameter_Editor *_editor;
|
|
|
|
|
2010-01-14 04:20:40 +01:00
|
|
|
static Module *_copied_module_empty;
|
|
|
|
static char *_copied_module_settings;
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
void init ( void );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
2010-01-28 05:39:27 +01:00
|
|
|
void insert_menu_cb ( const Fl_Menu_ *m );
|
|
|
|
static void insert_menu_cb ( Fl_Widget *w, void *v );
|
|
|
|
|
|
|
|
void menu_cb ( const Fl_Menu_ *m );
|
|
|
|
static void menu_cb ( Fl_Widget *w, void *v );
|
|
|
|
Fl_Menu_Button & menu ( void ) const;
|
|
|
|
|
2010-01-14 04:20:40 +01:00
|
|
|
void copy ( void ) const;
|
|
|
|
void paste_before ( void );
|
|
|
|
|
2013-03-16 01:54:37 +01:00
|
|
|
protected:
|
|
|
|
|
|
|
|
volatile bool _bypass;
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
public:
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
/* true if this module was added by default and not under normal user control */
|
|
|
|
bool is_default ( void ) const { return _is_default; }
|
|
|
|
void is_default ( bool v ) { _is_default = v; }
|
|
|
|
|
2012-02-25 05:23:45 +01:00
|
|
|
virtual bool allows_external_control ( void ) const { return true; }
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
class Port
|
|
|
|
{
|
|
|
|
/* char *type_names[] = { "Audio", "Control" }; */
|
|
|
|
/* char *direction_names[] = { "Input", "Output" }; */
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
void update_connected_port_buffer ( void )
|
|
|
|
{
|
|
|
|
if ( connected() )
|
|
|
|
connected_port()->_buf = _buf;
|
|
|
|
}
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Direction { INPUT, OUTPUT };
|
|
|
|
enum Type { AUDIO, CONTROL };
|
|
|
|
|
|
|
|
/* hints for control ports (specifically control inputs) */
|
|
|
|
struct Hints
|
|
|
|
{
|
|
|
|
enum Type { LINEAR, LOGARITHMIC, BOOLEAN, INTEGER };
|
|
|
|
|
|
|
|
Type type;
|
|
|
|
bool ranged;
|
|
|
|
float minimum;
|
|
|
|
float maximum;
|
|
|
|
float default_value;
|
|
|
|
int dimensions;
|
2012-02-09 07:38:34 +01:00
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
Hints ( )
|
|
|
|
{
|
|
|
|
type = LINEAR;
|
|
|
|
ranged = false;
|
|
|
|
minimum = 0;
|
|
|
|
maximum = 0;
|
|
|
|
default_value = 0.0f;
|
|
|
|
dimensions = 1;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-02-21 09:48:13 +01:00
|
|
|
static int osc_control_change_exact ( float v, void *user_data );
|
|
|
|
static int osc_control_change_cv ( float v, void *user_data );
|
2012-02-09 07:38:34 +01:00
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
Hints hints;
|
|
|
|
|
|
|
|
Port ( Module *module, Direction direction, Type type, const char *name = 0 )
|
|
|
|
{
|
|
|
|
_name = name;
|
|
|
|
_direction = direction;
|
|
|
|
_type = type;
|
|
|
|
_buf = 0;
|
|
|
|
_nframes = 0;
|
|
|
|
_connected = 0;
|
|
|
|
_module = module;
|
2012-02-21 09:48:13 +01:00
|
|
|
_scaled_signal = 0;
|
|
|
|
_unscaled_signal = 0;
|
2009-12-25 01:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Port ( const Port& p )
|
|
|
|
{
|
|
|
|
_name = p._name;
|
|
|
|
_direction = p._direction;
|
|
|
|
_type = p._type;
|
|
|
|
_buf = p._buf;
|
|
|
|
_nframes = p._nframes;
|
|
|
|
_connected = p._connected;
|
|
|
|
_module = p._module;
|
|
|
|
hints = p.hints;
|
2012-02-21 09:48:13 +01:00
|
|
|
_scaled_signal = p._scaled_signal;
|
|
|
|
_unscaled_signal = p._unscaled_signal;
|
2009-12-25 01:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~Port ( )
|
|
|
|
{
|
2012-02-09 07:38:34 +01:00
|
|
|
// change_osc_path( NULL );
|
2009-12-25 01:59:39 +01:00
|
|
|
// disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *name ( void ) const { return _name; }
|
|
|
|
Type type ( void ) const { return _type; }
|
|
|
|
Direction direction ( void ) const { return _direction; }
|
|
|
|
|
|
|
|
Module * module ( void ) const { return _module; }
|
2010-01-30 09:35:32 +01:00
|
|
|
nframes_t nframes ( void ) const { return _nframes; }
|
2009-12-25 01:59:39 +01:00
|
|
|
|
2010-01-30 09:35:32 +01:00
|
|
|
void buffer ( void *buf, nframes_t nframes ) { _buf = buf; _nframes = nframes; };
|
2009-12-25 01:59:39 +01:00
|
|
|
void *buffer ( void ) const { return _buf; }
|
|
|
|
|
2012-02-09 09:19:00 +01:00
|
|
|
const char *osc_path ( )
|
|
|
|
{
|
2012-02-25 05:23:45 +01:00
|
|
|
if ( _scaled_signal )
|
|
|
|
return _scaled_signal->path();
|
|
|
|
else
|
|
|
|
return NULL;
|
2012-02-09 09:19:00 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 07:38:34 +01:00
|
|
|
void update_osc_port ( )
|
|
|
|
{
|
2012-02-26 03:01:46 +01:00
|
|
|
// if ( INPUT == _direction )
|
|
|
|
change_osc_path( generate_osc_path() );
|
2012-02-09 07:38:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void destroy_osc_port ( )
|
|
|
|
{
|
2012-02-24 12:52:57 +01:00
|
|
|
delete _unscaled_signal;
|
|
|
|
delete _scaled_signal;
|
|
|
|
|
|
|
|
_unscaled_signal = _scaled_signal = NULL;
|
2012-02-09 07:38:34 +01:00
|
|
|
}
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
void control_value_no_callback ( float f )
|
|
|
|
{
|
2012-04-25 03:15:26 +02:00
|
|
|
/* can also be called from the OSC thread */
|
|
|
|
ASSERT( Thread::is( "UI" ) || Thread::is( "OSC" ),
|
|
|
|
"Function called from wrong thread! (is %s)", Thread::current()->name() );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
if ( buffer() )
|
|
|
|
{
|
|
|
|
*((float*)buffer()) = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void control_value ( float f )
|
|
|
|
{
|
|
|
|
control_value_no_callback( f );
|
|
|
|
_module->handle_control_changed( this );
|
2012-02-09 07:38:34 +01:00
|
|
|
if ( connected() )
|
|
|
|
connected_port()->_module->handle_control_changed( connected_port() );
|
2009-12-25 01:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
float control_value ( ) const
|
|
|
|
{
|
|
|
|
if ( buffer() )
|
|
|
|
return *((float*)buffer());
|
|
|
|
else
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool connected ( void ) const { return _connected; }
|
2012-02-25 05:23:45 +01:00
|
|
|
bool connected_osc ( void ) const;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
Port *connected_port ( void ) const
|
|
|
|
{
|
|
|
|
return _connected;
|
|
|
|
}
|
|
|
|
|
|
|
|
void connect_to ( Port *to )
|
|
|
|
{
|
|
|
|
_buf = to->_buf;
|
|
|
|
to->_connected = this;
|
|
|
|
_connected = to;
|
|
|
|
}
|
|
|
|
|
|
|
|
void connect_to ( void *buf )
|
|
|
|
{
|
|
|
|
_buf = buf;
|
2009-12-28 06:25:28 +01:00
|
|
|
update_connected_port_buffer();
|
2009-12-25 01:59:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void disconnect ( void )
|
|
|
|
{
|
|
|
|
if ( _connected && _connected != (void*)0x01 )
|
|
|
|
{
|
|
|
|
_connected->_connected = NULL;
|
|
|
|
_connected = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_connected = NULL;
|
|
|
|
|
|
|
|
/* FIXME: do something! */
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2012-02-09 07:38:34 +01:00
|
|
|
char *generate_osc_path ( void );
|
|
|
|
void change_osc_path ( char *path );
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
Port *_connected;
|
|
|
|
Type _type;
|
|
|
|
Direction _direction;
|
|
|
|
const char *_name;
|
|
|
|
void *_buf;
|
2010-01-30 09:35:32 +01:00
|
|
|
nframes_t _nframes;
|
2009-12-25 01:59:39 +01:00
|
|
|
Module *_module;
|
2012-02-09 07:38:34 +01:00
|
|
|
|
2012-02-26 03:01:46 +01:00
|
|
|
|
2012-02-21 09:48:13 +01:00
|
|
|
OSC::Signal *_scaled_signal;
|
|
|
|
OSC::Signal *_unscaled_signal;
|
2012-02-26 03:01:46 +01:00
|
|
|
|
2012-04-17 06:05:34 +02:00
|
|
|
static void handle_signal_connection_state_changed ( OSC::Signal *, void *o );
|
2009-12-25 01:59:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void bbox ( int &X, int &Y, int &W, int &H )
|
|
|
|
{
|
|
|
|
X = x() + 5;
|
|
|
|
Y = y() + 5;
|
|
|
|
W = w() - 10;
|
|
|
|
H = h() - 10;
|
|
|
|
}
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
Module ( int W, int H, const char *L = 0 );
|
|
|
|
Module ( );
|
|
|
|
Module ( bool is_default, int W, int H, const char *L = 0 );
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
virtual ~Module ( );
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
LOG_NAME_FUNC( Module );
|
|
|
|
|
2010-01-30 09:35:32 +01:00
|
|
|
nframes_t nframes ( void ) const { return _nframes; }
|
|
|
|
void resize_buffers ( nframes_t v ) { _nframes = v; }
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
int instances ( void ) const { return _instances; }
|
2009-12-25 20:16:07 +01:00
|
|
|
void instances ( int i ) { _instances = i; }
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
bool is_being_controlled ( void ) const
|
|
|
|
{
|
2010-01-30 09:35:32 +01:00
|
|
|
for ( nframes_t i = control_input.size(); i--; )
|
2009-12-25 01:59:39 +01:00
|
|
|
if ( control_input[i].connected() )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_controlling ( void ) const
|
|
|
|
{
|
2010-01-30 09:35:32 +01:00
|
|
|
for ( nframes_t i = control_output.size(); i--; )
|
2009-12-25 01:59:39 +01:00
|
|
|
if ( control_output[i].connected() )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-25 05:23:45 +01:00
|
|
|
bool
|
|
|
|
is_being_controlled_osc ( void ) const
|
|
|
|
{
|
|
|
|
for ( nframes_t i = control_input.size(); i--; )
|
|
|
|
if ( control_input[i].connected_osc() )
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
virtual const char *name ( void ) const = 0;
|
|
|
|
|
|
|
|
std::vector<Port> audio_input;
|
|
|
|
std::vector<Port> audio_output;
|
|
|
|
std::vector<Port> control_input;
|
|
|
|
std::vector<Port> control_output;
|
|
|
|
|
|
|
|
void add_port ( const Port &p )
|
|
|
|
{
|
|
|
|
if ( p.type() == Port::AUDIO && p.direction() == Port::INPUT )
|
|
|
|
audio_input.push_back( p );
|
|
|
|
else if ( p.type() == Port::AUDIO && p.direction() == Port::OUTPUT )
|
|
|
|
audio_output.push_back( p );
|
|
|
|
else if ( p.type() == Port::CONTROL && p.direction() == Port::INPUT )
|
|
|
|
control_input.push_back( p );
|
|
|
|
else if ( p.type() == Port::CONTROL && p.direction() == Port::OUTPUT )
|
|
|
|
control_output.push_back( p );
|
|
|
|
}
|
|
|
|
|
|
|
|
int noutputs ( void ) const
|
|
|
|
{
|
|
|
|
return audio_output.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ninputs ( void ) const
|
|
|
|
{
|
|
|
|
return audio_input.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ncontrol_inputs ( void ) const
|
|
|
|
{
|
|
|
|
return control_input.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ncontrol_outputs ( void ) const
|
|
|
|
{
|
|
|
|
return control_output.size();
|
|
|
|
}
|
|
|
|
|
2013-03-15 01:31:46 +01:00
|
|
|
virtual bool bypass ( void ) const { return _bypass; }
|
|
|
|
virtual void bypass ( bool v ) { _bypass = v; redraw(); }
|
2009-12-25 01:59:39 +01:00
|
|
|
|
2013-03-15 08:05:23 +01:00
|
|
|
virtual bool bypassable ( void ) const
|
|
|
|
{
|
|
|
|
return ninputs() == noutputs() ||
|
|
|
|
( ninputs() == 1 && noutputs() == 2 );
|
|
|
|
}
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
int control_input_port_index ( Port *p )
|
|
|
|
{
|
2010-01-30 09:35:32 +01:00
|
|
|
for ( nframes_t i = control_input.size(); i--; )
|
2009-12-28 06:25:28 +01:00
|
|
|
if ( &control_input[i] == p )
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int control_output_port_index ( Port *p )
|
|
|
|
{
|
2010-01-30 09:35:32 +01:00
|
|
|
for ( nframes_t i = control_output.size(); i--; )
|
2009-12-28 06:25:28 +01:00
|
|
|
if ( &control_output[i] == p )
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
Chain *chain ( void ) const { return _chain; }
|
2012-07-22 01:31:55 +02:00
|
|
|
void chain ( Chain * v );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
char *get_parameters ( void ) const;
|
|
|
|
void set_parameters ( const char * );
|
2009-12-26 01:22:56 +01:00
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
virtual bool initialize ( void ) { return true; }
|
|
|
|
|
|
|
|
/* for the given number of inputs, return how many outputs this
|
|
|
|
* plugin would have. -1 if this plugin can't support so many
|
|
|
|
* inputs. */
|
|
|
|
virtual int can_support_inputs ( int n ) = 0;
|
|
|
|
/* called by the chain whenever we need to adjust our input
|
|
|
|
* channel configuration, but only if can_support_inputs() returns
|
|
|
|
* true */
|
|
|
|
virtual bool configure_inputs ( int n ) = 0;
|
|
|
|
|
2010-01-30 09:35:32 +01:00
|
|
|
virtual void process ( nframes_t ) = 0;
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
/* called whenever the value of a control port is changed.
|
|
|
|
This can be used to take appropriate action from the GUI thread */
|
2012-02-10 09:28:37 +01:00
|
|
|
virtual void handle_control_changed ( Port * );
|
2009-12-25 01:59:39 +01:00
|
|
|
|
|
|
|
/* called whenever the name of the chain changes (usually because
|
|
|
|
* the name of the mixer strip changed). */
|
2012-02-08 04:44:40 +01:00
|
|
|
virtual void handle_chain_name_changed ();
|
2009-12-25 01:59:39 +01:00
|
|
|
|
2009-12-25 20:16:07 +01:00
|
|
|
virtual void handle_port_connection_change () {}
|
|
|
|
|
2010-01-14 04:20:40 +01:00
|
|
|
#define MODULE_CLONE_FUNC(class) \
|
|
|
|
virtual Module *clone_empty ( void ) const \
|
|
|
|
{ \
|
|
|
|
return new class (); \
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Module *clone_empty ( void ) const { return NULL; }
|
|
|
|
Module *clone ( Chain *dest ) const;
|
|
|
|
Module *clone ( void ) const;
|
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
protected:
|
|
|
|
|
|
|
|
void draw_connections ( void );
|
|
|
|
void draw_label ( void );
|
|
|
|
void draw_box ( void );
|
|
|
|
|
|
|
|
virtual void draw ( void ) { Module::draw_box(); Module::draw_label(); }
|
|
|
|
virtual int handle ( int m );
|
|
|
|
|
2009-12-28 06:25:28 +01:00
|
|
|
virtual void get ( Log_Entry &e ) const;
|
|
|
|
virtual void set ( Log_Entry &e );
|
|
|
|
|
2010-01-28 05:39:27 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
void command_open_parameter_editor();
|
2012-05-21 00:08:38 +02:00
|
|
|
virtual void command_activate ( void );
|
|
|
|
virtual void command_deactivate ( void );
|
|
|
|
virtual void command_remove ( void );
|
2010-01-28 05:39:27 +01:00
|
|
|
|
2009-12-25 01:59:39 +01:00
|
|
|
};
|