Browse Source

Attempt to cope with failure to create JACK clients and ports.

tags/non-daw-v1.1.0
Jonathan Moore Liles 15 years ago
parent
commit
13b3ddc301
8 changed files with 93 additions and 17 deletions
  1. +10
    -1
      Mixer/Chain.C
  2. +7
    -0
      Mixer/Controller_Module.C
  3. +20
    -0
      Mixer/JACK_Module.C
  4. +2
    -0
      Mixer/JACK_Module.H
  5. +13
    -0
      Timeline/Control_Sequence.C
  6. +10
    -0
      Timeline/Engine/Track.C
  7. +26
    -14
      nonlib/JACK/Port.C
  8. +5
    -2
      nonlib/JACK/Port.H

+ 10
- 1
Mixer/Chain.C View File

@@ -414,7 +414,16 @@ Chain::name ( const char *name )


engine()->buffer_size_callback( &Chain::buffer_size, this ); engine()->buffer_size_callback( &Chain::buffer_size, this );


engine()->init( ename );
const char *jack_name = engine()->init( ename );

if ( ! jack_name )
{
_engine = NULL;

fl_alert( "Could not create JACK client. Perhaps the sound device already in use. In any event, now I'll die." );
exit( 1 );
return;
}
} }
else else
{ {


+ 7
- 0
Mixer/Controller_Module.C View File

@@ -25,6 +25,7 @@


#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/Fl_Box.H> #include <FL/Fl_Box.H>
#include <FL/fl_ask.H>
#include <FL/Fl_Counter.H> #include <FL/Fl_Counter.H>
#include <FL/Fl_Menu_Item.H> #include <FL/Fl_Menu_Item.H>
#include <FL/Fl_Menu_Button.H> #include <FL/Fl_Menu_Button.H>
@@ -159,6 +160,12 @@ Controller_Module::mode ( Mode m )


JACK::Port po( chain()->engine(), JACK::Port::Input, p->name(), 0, "CV" ); JACK::Port po( chain()->engine(), JACK::Port::Input, p->name(), 0, "CV" );


if ( ! po.activate() )
{
fl_alert( "Could not activate JACK port \"%s\"", po.name() );
return;
}

if ( po.valid() ) if ( po.valid() )
{ {
jack_input.push_back( po ); jack_input.push_back( po );


+ 20
- 0
Mixer/JACK_Module.C View File

@@ -21,6 +21,8 @@


#include <string.h> #include <string.h>


#include <FL/fl_ask.H>

#include "dsp.h" #include "dsp.h"


#include "Engine/Engine.H" #include "Engine/Engine.H"
@@ -91,6 +93,12 @@ JACK_Module::configure_inputs ( int n )
{ {
JACK::Port po( chain()->engine(), JACK::Port::Output, i ); JACK::Port po( chain()->engine(), JACK::Port::Output, i );


if ( ! po.activate() )
{
jack_port_activation_error( &po );
return false;
}

if ( po.valid() ) if ( po.valid() )
{ {
add_port( Port( this, Port::INPUT, Port::AUDIO ) ); add_port( Port( this, Port::INPUT, Port::AUDIO ) );
@@ -114,6 +122,12 @@ JACK_Module::configure_inputs ( int n )
return true; return true;
} }


void
JACK_Module::jack_port_activation_error ( JACK::Port *p )
{
fl_alert( "Could not activate JACK port \"%s\"", p->name() );
}

bool bool
JACK_Module::configure_outputs ( int n ) JACK_Module::configure_outputs ( int n )
{ {
@@ -125,6 +139,12 @@ JACK_Module::configure_outputs ( int n )
{ {
JACK::Port po( chain()->engine(), JACK::Port::Input, i ); JACK::Port po( chain()->engine(), JACK::Port::Input, i );


if ( ! po.activate() )
{
jack_port_activation_error( &po );
return false;
}

if ( po.valid() ) if ( po.valid() )
{ {
add_port( Port( this, Port::OUTPUT, Port::AUDIO ) ); add_port( Port( this, Port::OUTPUT, Port::AUDIO ) );


+ 2
- 0
Mixer/JACK_Module.H View File

@@ -29,6 +29,8 @@ class JACK_Module : public Module
std::vector<JACK::Port> jack_input; std::vector<JACK::Port> jack_input;
std::vector<JACK::Port> jack_output; std::vector<JACK::Port> jack_output;


static void jack_port_activation_error ( JACK::Port *p );

public: public:


JACK_Module ( ); JACK_Module ( );


+ 13
- 0
Timeline/Control_Sequence.C View File

@@ -17,6 +17,9 @@
/* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
/*******************************************************************************/ /*******************************************************************************/


#include "const.h"
#include "debug.h"

#include <FL/fl_ask.H> #include <FL/fl_ask.H>


#include "Control_Sequence.H" #include "Control_Sequence.H"
@@ -43,6 +46,11 @@ Control_Sequence::Control_Sequence ( Track *track ) : Sequence( 0 )


_output = new JACK::Port( engine, JACK::Port::Output, track->name(), track->ncontrols(), "cv" ); _output = new JACK::Port( engine, JACK::Port::Output, track->name(), track->ncontrols(), "cv" );


if ( ! _output->activate() )
{
FATAL( "could not create JACK port" );
}

if ( track ) if ( track )
track->add( this ); track->add( this );


@@ -112,6 +120,11 @@ Control_Sequence::set ( Log_Entry &e )


_output = new JACK::Port( engine, JACK::Port::Output, t->name(), t->ncontrols(), "cv" ); _output = new JACK::Port( engine, JACK::Port::Output, t->name(), t->ncontrols(), "cv" );


if ( ! _output->activate() )
{
FATAL( "could not create JACK port" );
}

t->add( this ); t->add( this );
} }
else if ( ! strcmp( ":name", s ) ) else if ( ! strcmp( ":name", s ) )


+ 10
- 0
Timeline/Engine/Track.C View File

@@ -79,6 +79,11 @@ Track::configure_outputs ( int n )
{ {
JACK::Port p( engine, JACK::Port::Output, name(), i ); JACK::Port p( engine, JACK::Port::Output, name(), i );


if ( !p.activate() )
{
FATAL( "could not created output port!");
}

if ( p.valid() ) if ( p.valid() )
output.push_back( p ); output.push_back( p );
else else
@@ -126,6 +131,11 @@ Track::configure_inputs ( int n )
{ {
JACK::Port p( engine, JACK::Port::Input, name(), i ); JACK::Port p( engine, JACK::Port::Input, name(), i );


if ( !p.activate() )
{
FATAL( "could not created output port!");
}

if ( p.valid() ) if ( p.valid() )
input.push_back( p ); input.push_back( p );
else else


+ 26
- 14
nonlib/JACK/Port.C View File

@@ -42,6 +42,7 @@ namespace JACK
_freezer = rhs._freezer; _freezer = rhs._freezer;
_client = rhs._client; _client = rhs._client;
_port = rhs._port; _port = rhs._port;
_direction = rhs._direction;
_name = strdup( rhs._name ); _name = strdup( rhs._name );


_client->port_added( this ); _client->port_added( this );
@@ -54,6 +55,7 @@ namespace JACK
_client = client; _client = client;
_port = port; _port = port;
_name = strdup( jack_port_name( port ) ); _name = strdup( jack_port_name( port ) );
_direction = jack_port_flags( _port ) == JackPortIsOutput ? Output : Input;
} }


Port::Port ( JACK::Client *client, const char *name, type_e dir ) Port::Port ( JACK::Client *client, const char *name, type_e dir )
@@ -61,7 +63,9 @@ namespace JACK
_name = NULL; _name = NULL;
_freezer = NULL; _freezer = NULL;
_client = client; _client = client;
activate( name, dir );
_direction = dir;

_name = strdup( name );
} }


Port::Port ( JACK::Client *client, type_e dir, const char *base, int n, const char *type ) Port::Port ( JACK::Client *client, type_e dir, const char *base, int n, const char *type )
@@ -70,9 +74,8 @@ namespace JACK
_freezer = NULL; _freezer = NULL;
_client = client; _client = client;


const char *name = name_for_port( dir, base, n, type );

activate( name, dir );
_name = strdup( name_for_port( dir, base, n, type ) );
_direction = dir;
} }


Port::Port ( JACK::Client *client, type_e dir, int n, const char *type ) Port::Port ( JACK::Client *client, type_e dir, int n, const char *type )
@@ -81,9 +84,9 @@ namespace JACK
_freezer = NULL; _freezer = NULL;
_client = client; _client = client;


const char *name = name_for_port( dir, NULL, n, type );
_name = strdup( name_for_port( dir, NULL, n, type ) );
_direction = dir;


activate( name, dir );
} }


Port::~Port ( ) Port::~Port ( )
@@ -141,16 +144,29 @@ namespace JACK
return pname; return pname;
} }


void
bool
Port::activate ( const char *name, type_e dir ) Port::activate ( const char *name, type_e dir )
{ {
_name = strdup( name ); _name = strdup( name );
_direction = dir;

return activate();
}

bool
Port::activate ( void )
{
_port = jack_port_register( _client->jack_client(), _name, _port = jack_port_register( _client->jack_client(), _name,
JACK_DEFAULT_AUDIO_TYPE, JACK_DEFAULT_AUDIO_TYPE,
dir == Output ? JackPortIsOutput : JackPortIsInput,
_direction == Output ? JackPortIsOutput : JackPortIsInput,
0 ); 0 );


if ( ! _port )
return false;

_client->port_added( this ); _client->port_added( this );

return true;
} }


/** returns the sum of latency of all ports between this one and a /** returns the sum of latency of all ports between this one and a
@@ -239,10 +255,7 @@ namespace JACK
Port::type_e Port::type_e
Port::type ( void ) const Port::type ( void ) const
{ {
if ( _freezer )
return _freezer->direction;
else
return jack_port_flags( _port ) == JackPortIsOutput ? Output : Input;
return _direction;
} }


/** Restore the connections returned by connections() */ /** Restore the connections returned by connections() */
@@ -295,7 +308,6 @@ namespace JACK
freeze_state *f = new freeze_state(); freeze_state *f = new freeze_state();


f->connections = connections(); f->connections = connections();
f->direction = type();
f->name = strdup( name() ); f->name = strdup( name() );


_freezer = f; _freezer = f;
@@ -304,7 +316,7 @@ namespace JACK
void void
Port::thaw ( void ) Port::thaw ( void )
{ {
activate( name(), _freezer->direction );
activate();


connections( _freezer->connections ); connections( _freezer->connections );




+ 5
- 2
nonlib/JACK/Port.H View File

@@ -67,7 +67,7 @@ namespace JACK
nframes_t latency ( void ) const; nframes_t latency ( void ) const;
void latency ( nframes_t frames ); void latency ( nframes_t frames );


void activate ( const char *name, type_e dir );
bool activate ( void );
void shutdown ( void ); void shutdown ( void );
void write ( sample_t *buf, nframes_t nframes ); void write ( sample_t *buf, nframes_t nframes );
void read ( sample_t *buf, nframes_t nframes ); void read ( sample_t *buf, nframes_t nframes );
@@ -82,12 +82,15 @@ namespace JACK


private: private:


type_e _direction;

bool activate ( const char *name, type_e dir );

/* holds all we need to know about a jack port to recreate it on a /* holds all we need to know about a jack port to recreate it on a
new client */ new client */
struct freeze_state struct freeze_state
{ {
const char **connections; const char **connections;
type_e direction;
char *name; char *name;


freeze_state ( ) freeze_state ( )


Loading…
Cancel
Save