Mixer: Rearrange so that each mixer strip runs as its own JACK client.
This commit is contained in:
parent
82e1c50b8f
commit
a971175c8e
|
@ -79,7 +79,6 @@
|
|||
|
||||
|
||||
|
||||
std::vector <Module::Port> Chain::port;
|
||||
std::list <Chain*> Chain::chain;
|
||||
|
||||
|
||||
|
@ -126,6 +125,10 @@ Chain::set ( Log_Entry &e )
|
|||
Chain::Chain ( ) : Fl_Group( 0, 0, 100, 100, "")
|
||||
|
||||
{
|
||||
_engine = new Engine( &Chain::process, this );
|
||||
|
||||
engine()->init( "Non-Mixer" );
|
||||
|
||||
int X = 0;
|
||||
int Y = 0;
|
||||
int W = 100;
|
||||
|
@ -192,8 +195,19 @@ Chain::Chain ( ) : Fl_Group( 0, 0, 100, 100, "")
|
|||
|
||||
Chain::~Chain ( )
|
||||
{
|
||||
DMESSAGE( "Destroying chain" );
|
||||
|
||||
chain.remove( this );
|
||||
|
||||
log_destroy();
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -313,7 +327,7 @@ Chain::configure_ports ( void )
|
|||
/* int old_outs = outs(); */
|
||||
int nouts = 0;
|
||||
|
||||
engine->lock();
|
||||
engine()->lock();
|
||||
|
||||
for ( int i = 0; i < modules(); ++i )
|
||||
{
|
||||
|
@ -333,18 +347,18 @@ Chain::configure_ports ( void )
|
|||
|
||||
DMESSAGE( "required_buffers = %i", req_buffers );
|
||||
|
||||
if ( port.size() < req_buffers )
|
||||
if ( scratch_port.size() < req_buffers )
|
||||
{
|
||||
for ( unsigned int i = port.size(); i--; )
|
||||
delete[] (sample_t*)port[i].buffer();
|
||||
port.clear();
|
||||
for ( unsigned int i = scratch_port.size(); i--; )
|
||||
delete[] (sample_t*)scratch_port[i].buffer();
|
||||
scratch_port.clear();
|
||||
|
||||
for ( unsigned int i = 0; i < req_buffers; ++i )
|
||||
{
|
||||
Module::Port p( NULL, Module::Port::OUTPUT, Module::Port::AUDIO );
|
||||
p.connect_to( new sample_t[engine->nframes()] );
|
||||
buffer_fill_with_silence( (sample_t*)p.buffer(), engine->nframes() );
|
||||
port.push_back( p );
|
||||
p.connect_to( new sample_t[engine()->nframes()] );
|
||||
buffer_fill_with_silence( (sample_t*)p.buffer(), engine()->nframes() );
|
||||
scratch_port.push_back( p );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -359,7 +373,7 @@ Chain::configure_ports ( void )
|
|||
(*i)->build_process_queue();
|
||||
}
|
||||
|
||||
engine->unlock();
|
||||
engine()->unlock();
|
||||
|
||||
parent()->redraw();
|
||||
}
|
||||
|
@ -445,7 +459,7 @@ bool
|
|||
Chain::insert ( Module *m, Module *n )
|
||||
{
|
||||
|
||||
engine->lock();
|
||||
engine()->lock();
|
||||
|
||||
if ( !m )
|
||||
{
|
||||
|
@ -505,13 +519,13 @@ Chain::insert ( Module *m, Module *n )
|
|||
|
||||
configure_ports();
|
||||
|
||||
engine->unlock();
|
||||
engine()->unlock();
|
||||
|
||||
return true;
|
||||
|
||||
err:
|
||||
|
||||
engine->unlock();
|
||||
engine()->unlock();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -520,11 +534,11 @@ err:
|
|||
void
|
||||
Chain::add_control ( Module *m )
|
||||
{
|
||||
engine->lock();
|
||||
engine()->lock();
|
||||
|
||||
controls_pack->add( m );
|
||||
|
||||
engine->unlock();
|
||||
engine()->unlock();
|
||||
|
||||
controls_pack->redraw();
|
||||
}
|
||||
|
@ -608,11 +622,11 @@ Chain::build_process_queue ( void )
|
|||
Module *m = module( i );
|
||||
for ( unsigned int j = 0; j < m->audio_input.size(); ++j )
|
||||
{
|
||||
m->audio_input[j].connect_to( &port[j] );
|
||||
m->audio_input[j].connect_to( &scratch_port[j] );
|
||||
}
|
||||
for ( unsigned int j = 0; j < m->audio_output.size(); ++j )
|
||||
{
|
||||
m->audio_output[j].connect_to( &port[j] );
|
||||
m->audio_output[j].connect_to( &scratch_port[j] );
|
||||
}
|
||||
|
||||
m->handle_port_connection_change();
|
||||
|
@ -730,6 +744,13 @@ Chain::strip ( Mixer_Strip * ms )
|
|||
_strip = ms;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Chain::process ( nframes_t nframes, void *v )
|
||||
{
|
||||
((Chain*)v)->process( nframes );
|
||||
}
|
||||
|
||||
void
|
||||
Chain::process ( nframes_t nframes )
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
class Mixer_Strip;
|
||||
class Fl_Flowpack;
|
||||
class Fl_Flip_Button;
|
||||
class Engine;
|
||||
|
||||
class Chain : public Fl_Group, public Loggable {
|
||||
|
||||
|
@ -66,9 +67,14 @@ class Chain : public Fl_Group, public Loggable {
|
|||
void build_process_queue ( void );
|
||||
void add_to_process_queue ( Module *m );
|
||||
|
||||
static std::vector <Module::Port> port;
|
||||
std::vector <Module::Port> scratch_port;
|
||||
static std::list <Chain*> chain;
|
||||
|
||||
Engine *_engine;
|
||||
|
||||
static void process ( nframes_t, void * );
|
||||
void process ( nframes_t );
|
||||
|
||||
protected:
|
||||
|
||||
void get ( Log_Entry &e ) const;
|
||||
|
@ -119,9 +125,9 @@ public:
|
|||
|
||||
Fl_Callback * configure_outputs_callback ( void ) const { return _configure_outputs_callback; }
|
||||
|
||||
void process ( nframes_t );
|
||||
|
||||
void log_children ( void );
|
||||
|
||||
Engine *engine ( void ) const { return _engine; }
|
||||
|
||||
LOG_CREATE_FUNC( Chain );
|
||||
};
|
||||
|
|
|
@ -164,19 +164,19 @@ Controller_Module::connect_to ( Port *p )
|
|||
|
||||
if( mode() == CV )
|
||||
{
|
||||
engine->lock();
|
||||
{
|
||||
chain()->engine()->lock();
|
||||
|
||||
char name[256];
|
||||
snprintf( name, sizeof( name ), "%s-CV", p->name() );
|
||||
|
||||
JACK::Port po( engine->client(), JACK::Port::Input, chain()->name(), 0, name );
|
||||
JACK::Port po( chain()->engine()->client(), JACK::Port::Input, chain()->name(), 0, name );
|
||||
|
||||
if ( po.valid() )
|
||||
{
|
||||
jack_input.push_back( po );
|
||||
}
|
||||
}
|
||||
engine->unlock();
|
||||
|
||||
chain()->engine()->unlock();
|
||||
}
|
||||
|
||||
Fl_Widget *w;
|
||||
|
@ -302,7 +302,7 @@ Controller_Module::process ( void )
|
|||
|
||||
if ( mode() == CV )
|
||||
{
|
||||
f = *((float*)jack_input[0].buffer( engine->nframes() ));
|
||||
f = *((float*)jack_input[0].buffer( chain()->engine()->nframes() ));
|
||||
|
||||
const Port *p = control_output[0].connected_port();
|
||||
|
||||
|
|
|
@ -30,8 +30,10 @@
|
|||
|
||||
|
||||
|
||||
Engine::Engine ( ) : _thread( "RT" )
|
||||
Engine::Engine ( void (*process_callback)(nframes_t nframes, void *), void *user_data ) : _thread( "RT" )
|
||||
{
|
||||
_process_callback = process_callback;
|
||||
_user_data = user_data;
|
||||
_buffers_dropped = 0;
|
||||
}
|
||||
|
||||
|
@ -120,12 +122,7 @@ Engine::process ( nframes_t nframes )
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* handle chicken/egg problem */
|
||||
if ( mixer )
|
||||
/* this will initiate the process() call graph for the various
|
||||
* number and types of tracks, which will in turn send data out
|
||||
* the appropriate ports. */
|
||||
mixer->process( nframes );
|
||||
_process_callback(nframes, _user_data);
|
||||
|
||||
unlock();
|
||||
}
|
||||
|
|
|
@ -34,6 +34,9 @@ class Engine : public JACK::Client, public Mutex
|
|||
int _buffers_dropped; /* buffers dropped because of locking */
|
||||
/* int _buffers_dropped; /\* buffers dropped because of locking *\/ */
|
||||
|
||||
void ( * _process_callback ) ( nframes_t, void * );
|
||||
void *_user_data;
|
||||
|
||||
void shutdown ( void );
|
||||
int process ( nframes_t nframes );
|
||||
int sync ( jack_transport_state_t state, jack_position_t *pos );
|
||||
|
@ -56,11 +59,9 @@ private:
|
|||
|
||||
public:
|
||||
|
||||
Engine ( );
|
||||
Engine ( void (*process_callback) (nframes_t, void *), void *user_data );
|
||||
~Engine ( );
|
||||
|
||||
int dropped ( void ) const { return _buffers_dropped; }
|
||||
|
||||
};
|
||||
|
||||
extern Engine * engine;
|
||||
|
|
|
@ -86,7 +86,7 @@ JACK_Module::configure_inputs ( int n )
|
|||
{
|
||||
for ( int i = on; i < n; ++i )
|
||||
{
|
||||
JACK::Port po( engine->client(), JACK::Port::Output, chain()->name(), i );
|
||||
JACK::Port po( chain()->engine()->client(), JACK::Port::Output, chain()->name(), i );
|
||||
|
||||
if ( po.valid() )
|
||||
{
|
||||
|
@ -120,7 +120,7 @@ JACK_Module::configure_outputs ( int n )
|
|||
{
|
||||
for ( int i = on; i < n; ++i )
|
||||
{
|
||||
JACK::Port po( engine->client(), JACK::Port::Input, chain()->name(), i );
|
||||
JACK::Port po( chain()->engine()->client(), JACK::Port::Input, chain()->name(), i );
|
||||
|
||||
if ( po.valid() )
|
||||
{
|
||||
|
|
|
@ -140,7 +140,7 @@ Mixer::Mixer ( int X, int Y, int W, int H, const char *L ) :
|
|||
Mixer::~Mixer ( )
|
||||
{
|
||||
/* FIXME: teardown */
|
||||
|
||||
DMESSAGE( "Destroying mixer" );
|
||||
}
|
||||
|
||||
void Mixer::resize ( int X, int Y, int W, int H )
|
||||
|
@ -156,16 +156,9 @@ void Mixer::add ( Mixer_Strip *ms )
|
|||
{
|
||||
MESSAGE( "Add mixer strip \"%s\"", ms->name() );
|
||||
|
||||
engine->lock();
|
||||
|
||||
mixer_strips->add( ms );
|
||||
// mixer_strips->insert( *ms, 0 );
|
||||
|
||||
engine->unlock();
|
||||
|
||||
scroll->redraw();
|
||||
|
||||
// redraw();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -180,13 +173,9 @@ Mixer::quit ( void )
|
|||
void
|
||||
Mixer::insert ( Mixer_Strip *ms, Mixer_Strip *before )
|
||||
{
|
||||
engine->lock();
|
||||
|
||||
mixer_strips->remove( ms );
|
||||
mixer_strips->insert( *ms, before );
|
||||
|
||||
engine->unlock();
|
||||
|
||||
scroll->redraw();
|
||||
}
|
||||
void
|
||||
|
@ -219,12 +208,8 @@ void Mixer::remove ( Mixer_Strip *ms )
|
|||
{
|
||||
MESSAGE( "Remove mixer strip \"%s\"", ms->name() );
|
||||
|
||||
engine->lock();
|
||||
|
||||
mixer_strips->remove( ms );
|
||||
|
||||
engine->unlock();
|
||||
|
||||
delete ms;
|
||||
|
||||
parent()->redraw();
|
||||
|
@ -247,17 +232,6 @@ void Mixer::update ( void )
|
|||
// redraw();
|
||||
}
|
||||
|
||||
void
|
||||
Mixer::process ( unsigned int nframes )
|
||||
{
|
||||
THREAD_ASSERT( RT );
|
||||
|
||||
for ( int i = mixer_strips->children(); i--; )
|
||||
{
|
||||
((Mixer_Strip*)mixer_strips->child( i ))->process( nframes );
|
||||
}
|
||||
}
|
||||
|
||||
/** retrun a pointer to the track named /name/, or NULL if no track is named /name/ */
|
||||
Mixer_Strip *
|
||||
Mixer::track_by_name ( const char *name )
|
||||
|
@ -299,13 +273,7 @@ Mixer::snapshot ( void )
|
|||
void
|
||||
Mixer::new_strip ( void )
|
||||
{
|
||||
engine->lock();
|
||||
|
||||
add( new Mixer_Strip( get_unique_track_name( "Unnamed" ), 1 ) );
|
||||
|
||||
engine->unlock();
|
||||
|
||||
// scroll->size( mixer_strips->w(), scroll->h() );
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -175,6 +175,7 @@ Mixer_Strip::Mixer_Strip() : Fl_Group( 0, 0, 120, 600 )
|
|||
|
||||
Mixer_Strip::~Mixer_Strip ( )
|
||||
{
|
||||
DMESSAGE( "Destroying mixer strip" );
|
||||
log_destroy();
|
||||
}
|
||||
|
||||
|
@ -274,15 +275,6 @@ Mixer_Strip::handle_module_added ( Module *m )
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Mixer_Strip::process ( nframes_t nframes )
|
||||
{
|
||||
THREAD_ASSERT( RT );
|
||||
|
||||
_chain->process( nframes );
|
||||
}
|
||||
|
||||
/* update GUI with values from RT thread */
|
||||
void
|
||||
Mixer_Strip::update ( void )
|
||||
|
|
|
@ -67,8 +67,6 @@ public:
|
|||
|
||||
LOG_CREATE_FUNC( Mixer_Strip );
|
||||
|
||||
void process ( unsigned int nframes );
|
||||
|
||||
static void configure_outputs ( Fl_Widget *o, void *v );
|
||||
void configure_outputs ( void );
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "Engine/Engine.H"
|
||||
#include "Chain.H"
|
||||
|
||||
|
||||
|
||||
|
@ -331,7 +332,7 @@ Plugin_Module::plugin_instances ( unsigned int n )
|
|||
|
||||
DMESSAGE( "Instantiating plugin..." );
|
||||
|
||||
if ( ! (h = _idata->descriptor->instantiate( _idata->descriptor, engine->sample_rate() ) ) )
|
||||
if ( ! (h = _idata->descriptor->instantiate( _idata->descriptor, chain()->engine()->sample_rate() ) ) )
|
||||
{
|
||||
WARNING( "Failed to instantiate plugin" );
|
||||
return false;
|
||||
|
@ -457,7 +458,7 @@ Plugin_Module::load ( unsigned long id )
|
|||
Min=_idata->descriptor->PortRangeHints[Port].LowerBound;
|
||||
if (LADSPA_IS_HINT_SAMPLE_RATE(HintDesc))
|
||||
{
|
||||
Min*=engine->sample_rate();
|
||||
Min*=chain()->engine()->sample_rate();
|
||||
}
|
||||
}
|
||||
if (LADSPA_IS_HINT_BOUNDED_ABOVE(HintDesc))
|
||||
|
@ -465,7 +466,7 @@ Plugin_Module::load ( unsigned long id )
|
|||
Max=_idata->descriptor->PortRangeHints[Port].UpperBound;
|
||||
if (LADSPA_IS_HINT_SAMPLE_RATE(HintDesc))
|
||||
{
|
||||
Max*=engine->sample_rate();
|
||||
Max*=chain()->engine()->sample_rate();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -533,7 +534,7 @@ Plugin_Module::load ( unsigned long id )
|
|||
}
|
||||
}
|
||||
if (LADSPA_IS_HINT_SAMPLE_RATE(HintDesc)) {
|
||||
Default *= engine->sample_rate();
|
||||
Default *= chain()->engine()->sample_rate();
|
||||
}
|
||||
if (LADSPA_IS_HINT_INTEGER(HintDesc)) {
|
||||
if ( p.hints.ranged &&
|
||||
|
|
15
Mixer/main.C
15
Mixer/main.C
|
@ -31,12 +31,10 @@
|
|||
#include "DPM.H"
|
||||
|
||||
#include "Mixer.H"
|
||||
#include "Engine/Engine.H"
|
||||
#include "util/Thread.H"
|
||||
#include "util/debug.h"
|
||||
#include "Project.H"
|
||||
|
||||
Engine *engine;
|
||||
Mixer *mixer;
|
||||
|
||||
Fl_Single_Window *main_window;
|
||||
|
@ -98,12 +96,6 @@ main ( int argc, char **argv )
|
|||
/* Fl::foreground( 0xFF, 0xFF, 0xFF ); */
|
||||
/* Fl::background( 0x10, 0x10, 0x10 ); */
|
||||
|
||||
MESSAGE( "Initializing JACK" );
|
||||
|
||||
engine = new Engine();
|
||||
|
||||
engine->init( "Non-Mixer" );
|
||||
|
||||
{
|
||||
Fl_Single_Window *o = main_window = new Fl_Single_Window( 1024, 768, "Mixer" );
|
||||
{
|
||||
|
@ -117,8 +109,6 @@ main ( int argc, char **argv )
|
|||
}
|
||||
|
||||
{
|
||||
engine->lock();
|
||||
|
||||
if ( argc > 1 )
|
||||
{
|
||||
/* char name[1024]; */
|
||||
|
@ -137,13 +127,12 @@ main ( int argc, char **argv )
|
|||
{
|
||||
WARNING( "Running without a project--nothing will be saved." );
|
||||
}
|
||||
|
||||
engine->unlock();
|
||||
}
|
||||
|
||||
Fl::run();
|
||||
|
||||
delete engine;
|
||||
delete main_window;
|
||||
main_window = NULL;
|
||||
|
||||
MESSAGE( "Your fun is over" );
|
||||
|
||||
|
|
Loading…
Reference in New Issue