From e637da4b77601fb2d17602e3cf3869b91e9ab860 Mon Sep 17 00:00:00 2001 From: Jonathan Moore Liles Date: Mon, 28 Apr 2008 11:19:25 -0500 Subject: [PATCH] Attempt to create control output ports properly. --- Timeline/Control_Sequence.C | 6 +++-- Timeline/Control_Sequence.H | 6 +++-- Timeline/Port.C | 53 ++++++++++++++++++++++++++++++++----- Timeline/Port.H | 6 +++++ Timeline/Track.C | 34 ++++++++++++------------ Timeline/Track.H | 2 ++ 6 files changed, 80 insertions(+), 27 deletions(-) diff --git a/Timeline/Control_Sequence.C b/Timeline/Control_Sequence.C index 12befc3..6b1f71c 100644 --- a/Timeline/Control_Sequence.C +++ b/Timeline/Control_Sequence.C @@ -27,7 +27,7 @@ bool Control_Sequence::draw_with_gradient = true; bool Control_Sequence::draw_with_polygon = true; bool Control_Sequence::draw_with_grid = true; -Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0 ), output( "foo", Port::Output ) +Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0 ) { init(); @@ -36,6 +36,8 @@ Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0, 0, 0, 0 ), ou if ( track ) track->add( this ); +// output.activate( track->name(), + log_create(); } @@ -335,7 +337,7 @@ Control_Sequence::play ( sample_t *buf, nframes_t frame, nframes_t nframes ) nframes_t Control_Sequence::process ( nframes_t nframes ) { - void *buf = output.buffer( nframes ); + void *buf = _output->buffer( nframes ); return play( (sample_t*)buf, transport->frame, nframes ); } diff --git a/Timeline/Control_Sequence.H b/Timeline/Control_Sequence.H index e38f441..22df5d3 100644 --- a/Timeline/Control_Sequence.H +++ b/Timeline/Control_Sequence.H @@ -26,11 +26,12 @@ class Control_Sequence : public Sequence { + Port *_output; + bool _highlighted; void init ( void ); - Port output; protected: @@ -38,7 +39,7 @@ protected: virtual void get ( Log_Entry &e ) const; void set ( Log_Entry &e ); - Control_Sequence ( ) : Sequence( 0, 0, 0, 1 ), output( "foo", Port::Output ) + Control_Sequence ( ) : Sequence( 0, 0, 0, 1 ) { init(); } @@ -65,6 +66,7 @@ public: /* Engine */ + void output ( Port *p ) { _output = p; } nframes_t play ( sample_t *buf, nframes_t frame, nframes_t nframes ); nframes_t process ( nframes_t nframes ); diff --git a/Timeline/Port.C b/Timeline/Port.C index bfdf98b..93b9b9a 100644 --- a/Timeline/Port.C +++ b/Timeline/Port.C @@ -23,6 +23,8 @@ #include "Engine.H" +#include // sprintf + /* nframes is the number of frames to buffer */ Port::Port ( jack_port_t *port ) { @@ -32,14 +34,37 @@ Port::Port ( jack_port_t *port ) Port::Port ( const char *name, type_e dir ) { - _name = name; - - _port = jack_port_register( engine->client(), _name, - JACK_DEFAULT_AUDIO_TYPE, - dir == Output ? JackPortIsOutput : JackPortIsInput, - 0 ); + activate( name, dir ); } +static const char * +name_for_port ( Port::type_e dir, const char *base, int n, const char *type ) +{ + static char pname[256]; + + const char *dir_s = dir == Port::Output ? "out" : "in"; + + if ( type ) + snprintf( pname, sizeof( pname ), "%s/%s-%s-%d", base, type, dir_s, n + 1 ); + else + snprintf( pname, sizeof( pname ), "%s/%s-%d", base, dir_s, n + 1 ); + + return pname; +} + +Port::Port ( type_e dir, const char *base, int n, const char *type ) +{ + const char *name = name_for_port( dir, base, n, type ); + + activate( name, dir ); +} + +/* Port::Port ( ) */ +/* { */ +/* _name = NULL; */ +/* _port = NULL; */ +/* } */ + Port::~Port ( ) { @@ -48,6 +73,16 @@ Port::~Port ( ) } +void +Port::activate ( const char *name, type_e dir ) +{ + _name = name; + _port = jack_port_register( engine->client(), _name, + JACK_DEFAULT_AUDIO_TYPE, + dir == Output ? JackPortIsOutput : JackPortIsInput, + 0 ); +} + void Port::shutdown ( void ) { @@ -64,6 +99,12 @@ Port::name ( const char *name ) return 0 == jack_port_set_name( _port, name ); } +bool +Port::name ( const char *base, int n, const char *type ) +{ + return name( name_for_port( this->type(), base, n, type ) ); +} + void Port::write ( sample_t *buf, nframes_t nframes ) { diff --git a/Timeline/Port.H b/Timeline/Port.H index ca5ea34..31519a9 100644 --- a/Timeline/Port.H +++ b/Timeline/Port.H @@ -34,6 +34,9 @@ public: Port ( jack_port_t *port ); Port ( const char *name, type_e dir ); + Port ( type_e dir, const char *base, int n, const char *type=0 ); + +// Port ( ); ~Port ( ); /* Port ( const Port & rhs ) */ @@ -51,7 +54,10 @@ public: } const char * name ( void ) const { return _name; } bool name ( const char *name ); + bool name ( const char *base, int n, const char *type=0 ); + + void activate ( const char *name, type_e dir ); void shutdown ( void ); void write ( sample_t *buf, nframes_t nframes ); void read ( sample_t *buf, nframes_t nframes ); diff --git a/Timeline/Track.C b/Timeline/Track.C index fdf3e38..a997cbe 100644 --- a/Timeline/Track.C +++ b/Timeline/Track.C @@ -357,6 +357,10 @@ Track::add ( Control_Sequence *t ) control->add( t ); + control_out.push_back( Port( Port::Output, name(), control_out.size(), "cv" ) ); + + t->output( &control_out.back() ); + resize(); } @@ -498,27 +502,23 @@ Track::handle ( int m ) /* Engine */ /**********/ -const char * -Track::name_for_port ( Port::type_e type, int n ) -{ - static char pname[256]; - - snprintf( pname, sizeof( pname ), "%s/%s-%d", - name(), - type == Port::Output ? "out" : "in", - n + 1 ); - - return pname; -} - void Track::update_port_names ( void ) { for ( int i = 0; i < output.size(); ++i ) - output[ i ].name( name_for_port( output[ i ].type(), i ) ); + output[ i ].name( name(), i ); for ( int i = 0; i < input.size(); ++i ) - input[ i ].name( name_for_port( input[ i ].type(), i ) ); + input[ i ].name( name(), i ); + + for ( int i = 0; i < control_out.size(); ++i ) + control_out[ i ].name( name(), i, "cv" ); + + +/* /\* tell any attached control sequences to do the same *\/ */ +/* for ( int i = control->children(); i-- ) */ +/* ((Control_Sequence*)control->child( i ))->update_port_names(); */ + } bool @@ -541,7 +541,7 @@ Track::configure_outputs ( int n ) { for ( int i = on; i < n; ++i ) { - Port p( strdup( name_for_port( Port::Output, i ) ), Port::Output ); + Port p( Port::Output, name(), i ); if ( p.valid() ) output.push_back( p ); @@ -586,7 +586,7 @@ Track::configure_inputs ( int n ) { for ( int i = on; i < n; ++i ) { - Port p( strdup( name_for_port( Port::Input, i ) ), Port::Input ); + Port p( Port::Input, name(), i ); if ( p.valid() ) input.push_back( p ); diff --git a/Timeline/Track.H b/Timeline/Track.H index 8686dd5..3ba5f02 100644 --- a/Timeline/Track.H +++ b/Timeline/Track.H @@ -109,6 +109,8 @@ public: vector input; /* input ports... */ vector output; /* output ports... */ + vector control_out; /* control ports... */ + Playback_DS *playback_ds; Record_DS *record_ds;