Attempt to create control output ports properly.

This commit is contained in:
Jonathan Moore Liles 2008-04-28 11:19:25 -05:00
parent a77e7a708c
commit e637da4b77
6 changed files with 80 additions and 27 deletions

View File

@ -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 );
}

View File

@ -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 );

View File

@ -23,6 +23,8 @@
#include "Engine.H"
#include <stdio.h> // 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 )
{

View File

@ -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 );

View File

@ -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 );

View File

@ -109,6 +109,8 @@ public:
vector<Port> input; /* input ports... */
vector<Port> output; /* output ports... */
vector<Port> control_out; /* control ports... */
Playback_DS *playback_ds;
Record_DS *record_ds;