Mixer: Fix jack client rename on strip rename.

This commit is contained in:
Jonathan Moore Liles 2013-07-17 19:27:21 -07:00
parent e95fd10775
commit 932a78c747
6 changed files with 104 additions and 127 deletions

View File

@ -548,18 +548,6 @@ JACK_Module::handle_control_changed ( Port *p )
Module::handle_control_changed( p );
}
void
JACK_Module::handle_chain_name_changed ( void )
{
for ( unsigned int i = 0; i < jack_output.size(); ++i )
jack_output[ i ].name( NULL, i );
for ( unsigned int i = 0; i < jack_input.size(); ++i )
jack_input[ i ].name( NULL, i );
Module::handle_chain_name_changed();
}
int
JACK_Module::handle ( int m )
{

View File

@ -82,7 +82,6 @@ public:
virtual bool configure_outputs ( int n );
virtual void handle_control_changed ( Port *p );
virtual void handle_chain_name_changed ();
LOG_CREATE_FUNC( JACK_Module );

View File

@ -24,6 +24,8 @@
#include "debug.h"
namespace JACK
@ -60,7 +62,16 @@ namespace JACK
int
Client::process ( nframes_t nframes, void *arg )
{
return ((Client*)arg)->process( nframes );
Client *c = (Client*)arg;
if ( ! c->_frozen.trylock() )
return 0;
int r = c->process(nframes);
c->_frozen.unlock();
return r;
}
int
@ -111,7 +122,13 @@ namespace JACK
void
Client::port_connect ( jack_port_id_t a, jack_port_id_t b, int connect, void *arg )
{
Client *c = (Client*)arg;
if (! c->_frozen.trylock() )
return;
((Client*)arg)->port_connect( a, b, connect );
c->_frozen.unlock();
}
int
@ -232,16 +249,22 @@ namespace JACK
* create a client with the new name, and restore our
* connections. Lovely. */
freeze_ports();
jack_deactivate( _client );
jack_client_close( _client );
_client = NULL;
_frozen.lock();
s = init( s );
thaw_ports();
_frozen.unlock();
return s;
}

View File

@ -21,6 +21,7 @@
#include <jack/jack.h>
#include <jack/midiport.h>
#include <Mutex.H>
typedef jack_nframes_t nframes_t;
typedef jack_default_audio_sample_t sample_t;
@ -34,6 +35,8 @@ namespace JACK
{
std::list <JACK::Port*> _active_ports;
Mutex _frozen;
jack_client_t *_client;
// nframes_t _sample_rate;

View File

@ -25,10 +25,13 @@
#include <stdio.h> // sprintf
#include <errno.h>
#include <assert.h>
#include "debug.h"
namespace JACK
{
static const char *name_for_port ( Port::direction_e dir, const char *base, int n, const char *type );
static char *name_for_port ( Port::direction_e dir, const char *base, int n, const char *type );
int
Port::max_name ( void )
@ -39,8 +42,9 @@ namespace JACK
Port::Port ( const Port &rhs )
{
_connections = NULL;
_terminal = rhs._terminal;
_freezer = rhs._freezer;
// _connections = rhs._connections;
_client = rhs._client;
_port = rhs._port;
_direction = rhs._direction;
@ -54,7 +58,7 @@ namespace JACK
Port::Port ( JACK::Client *client, jack_port_t *port )
{
_terminal = 0;
_freezer = NULL;
_connections = NULL;
_client = client;
_port = port;
_name = strdup( jack_port_name( port ) );
@ -64,59 +68,66 @@ namespace JACK
_type = Audio;
if ( strstr( type, "MIDI") )
_type = MIDI;
_client->port_added( this );
}
Port::Port ( JACK::Client *client, const char *name, direction_e dir, type_e type )
{
_port = 0;
_terminal = 0;
_name = NULL;
_freezer = NULL;
_connections = NULL;
_client = client;
_direction = dir;
_type = type;
_name = strdup( name );
_client->port_added( this );
}
Port::Port ( JACK::Client *client, direction_e dir, type_e type, const char *base, int n, const char *subtype )
{
_port = 0;
_terminal = 0;
_name = NULL;
_freezer = NULL;
_connections = NULL;
_client = client;
_name = strdup( name_for_port( dir, base, n, subtype ) );
_name = name_for_port( dir, base, n, subtype );
_direction = dir;
_type = type;
_client->port_added( this );
}
Port::Port ( JACK::Client *client, direction_e dir, type_e type, int n, const char *subtype )
{
_port = 0;
_terminal = 0;
_name = NULL;
_freezer = NULL;
_connections = NULL;
_client = client;
_name = strdup( name_for_port( dir, NULL, n, subtype ) );
_name = name_for_port( dir, NULL, n, subtype );
_direction = dir;
_type = type;
_client->port_added( this );
}
Port::~Port ( )
{
if ( _name )
free( _name );
_client->port_removed( this );
/* if ( _freezer ) */
/* { */
/* delete _freezer; */
/* _freezer = NULL; */
/* } */
/* if ( _port ) */
/* jack_port_unregister( _client, _port ); */
if ( _name )
{
free( _name );
_name = NULL;
}
}
/* sort input before output and then by alpha */
@ -130,45 +141,26 @@ namespace JACK
}
static const char *
static char *
name_for_port ( Port::direction_e dir, const char *base, int n, const char *type )
{
static char pname[ 512 ];
char *pname;
const char *dir_s = dir == Port::Output ? "out" : "in";
pname[0] = '\0';
if ( base )
{
strncpy( pname, base, Port::max_name() );
strcat( pname, "/" );
}
pname[ Port::max_name() - 1 ] = '\0';
int l = strlen( pname );
if ( type )
snprintf( pname + l, sizeof( pname ) - l, "%s-%s-%d", type, dir_s, n + 1 );
asprintf( &pname, "%s-%s%s%s-%d", type, base ? base : "", base ? "/" : "", dir_s, n + 1 );
else
snprintf( pname + l, sizeof( pname ) - l, "%s-%d", dir_s, n + 1 );
asprintf( &pname, "%s%s%s-%d", base ? base : "", base ? "/" : "", dir_s, n + 1 );
return pname;
}
bool
Port::activate ( const char *name, direction_e dir )
{
_name = strdup( name );
_direction = dir;
return activate();
}
bool
Port::activate ( void )
{
/* assert( !_port ); */
int flags = 0;
if ( _direction == Output )
@ -179,16 +171,19 @@ namespace JACK
if ( _terminal )
flags |= JackPortIsTerminal;
DMESSAGE( "Activating port name %s", _name );
_port = jack_port_register( _client->jack_client(), _name,
_type == Audio ? JACK_DEFAULT_AUDIO_TYPE : JACK_DEFAULT_MIDI_TYPE,
flags,
0 );
DMESSAGE( "Port = %p", _port );
if ( ! _port )
return false;
_client->port_added( this );
return true;
}
@ -221,17 +216,28 @@ namespace JACK
void
Port::shutdown ( void )
{
deactivate();
_client->port_removed( this );
}
void
Port::deactivate ( void )
{
if ( _port )
jack_port_unregister( _client->jack_client(), _port );
_client->port_removed( this );
_port = 0;
}
/** rename port */
bool
Port::name ( const char *name )
{
if ( _name )
free( _name );
_name = strdup( name );
return 0 == jack_port_set_name( _port, name );
@ -240,7 +246,10 @@ namespace JACK
bool
Port::name ( const char *base, int n, const char *type )
{
return name( name_for_port( this->direction(), base, n, type ) );
char *s = name_for_port( this->direction(), base, n, type );
bool b = name( s );
free(s);
return b;
}
void
@ -284,32 +293,8 @@ namespace JACK
for ( const char **port_name = port_names; *port_name; ++port_name )
{
const char *src;
const char *dst;
const char *name = jack_port_name( _port );
if ( direction() == Output )
{
src = name;
dst = *port_name;
}
else
{
src = *port_name;
dst = name;
}
if ( int err = jack_connect( _client->jack_client(), src, dst ) )
{
if ( EEXIST == err )
{
/* connection already exists, not a problem */
}
else
{
return false;
}
}
printf( "Attempting to reconnect to %s\n", *port_name );
connect( *port_name );
}
return true;
@ -355,25 +340,30 @@ namespace JACK
void
Port::freeze ( void )
{
if ( _freezer )
delete _freezer;
if ( _connections )
free( _connections );
freeze_state *f = new freeze_state();
// DMESSAGE( "Freezing port %s", _name );
f->connections = connections();
f->name = strdup( name() );
_connections = connections();
_freezer = f;
// deactivate();
}
void
Port::thaw ( void )
{
// DMESSAGE( "Thawing port %s", _name );
activate();
if ( _connections )
{
connections( _connections );
free( _connections );
connections( _freezer->connections );
delete _freezer;
_freezer = NULL;
_connections = NULL;
}
}
}

View File

@ -92,36 +92,10 @@ namespace JACK
type_e _type;
bool _terminal;
bool activate ( const char *name, direction_e dir );
void deactivate ( void );
/* bool activate ( const char *name, direction_e dir ); */
/* holds all we need to know about a jack port to recreate it on a
new client */
struct freeze_state
{
const char **connections;
char *name;
freeze_state ( )
{
connections = NULL;
name = NULL;
}
~freeze_state ( )
{
if ( connections )
{
free( connections );
connections = NULL;
}
if ( name )
{
free( name );
}
}
};
freeze_state *_freezer;
const char **_connections;
};