Browse Source

Use new JACK port_rename API for rename client in single-client

Also some needed cleanup
tags/1.9.7
falkTX 9 years ago
parent
commit
ebf65bcc47
3 changed files with 93 additions and 96 deletions
  1. +74
    -71
      source/backend/engine/CarlaEngineJack.cpp
  2. +1
    -1
      source/jackbridge/JackBridge.hpp
  3. +18
    -24
      source/jackbridge/JackBridge1.cpp

+ 74
- 71
source/backend/engine/CarlaEngineJack.cpp View File

@@ -671,21 +671,32 @@ public:
fEventPorts.removeAll(port);
}

void closeForRename(jack_client_t* const client, const char* const clientName) noexcept
bool renameInSingleClient(const CarlaString& newClientName)
{
const CarlaString clientNamePrefix(newClientName + ":");

return _renamePorts(fAudioPorts, clientNamePrefix) &&
_renamePorts(fCVPorts, clientNamePrefix) &&
_renamePorts(fEventPorts, clientNamePrefix);
}

void closeForRename(jack_client_t* const newClient, const CarlaString& newClientName) noexcept
{
if (fJackClient != nullptr)
{
if (isActive())
{
{
const CarlaString clientNamePrefix(newClientName + ":");

// store current client connections
const CarlaMutexLocker cml(fPreRenameMutex);

fPreRenameConnections.clear();

_savePortsConnections(fAudioPorts, clientName);
_savePortsConnections(fCVPorts, clientName);
_savePortsConnections(fEventPorts, clientName);
_savePortsConnections(fAudioPorts, clientNamePrefix);
_savePortsConnections(fCVPorts, clientNamePrefix);
_savePortsConnections(fEventPorts, clientNamePrefix);
}

try {
@@ -705,7 +716,7 @@ public:
fEventPorts.clear();
_clearPorts();

fJackClient = client;
fJackClient = newClient;
}

private:
@@ -720,11 +731,34 @@ private:
CarlaStringList fPreRenameConnections;

template<typename T>
void _savePortsConnections(const LinkedList<T*>& t, const char* const clientName)
bool _renamePorts(const LinkedList<T*>& t, const CarlaString& clientNamePrefix)
{
CarlaString clientNamePrefix(clientName);
clientNamePrefix += ":";
for (typename LinkedList<T*>::Itenerator it = t.begin2(); it.valid(); it.next())
{
T* const port(it.getValue(nullptr));
CARLA_SAFE_ASSERT_CONTINUE(port != nullptr);
CARLA_SAFE_ASSERT_CONTINUE(port->fJackPort != nullptr);

const char* shortPortName(jackbridge_port_short_name(port->fJackPort));
CARLA_SAFE_ASSERT_CONTINUE(shortPortName != nullptr && shortPortName[0] != '\0');

const char* const oldClientNameSep(std::strstr(shortPortName, ":"));
CARLA_SAFE_ASSERT_CONTINUE(oldClientNameSep != nullptr && oldClientNameSep[0] != '\0' && oldClientNameSep[1] != '\0');

shortPortName += oldClientNameSep-shortPortName + 1;

const CarlaString newPortName(clientNamePrefix + shortPortName);

if (! jackbridge_port_rename(fJackClient, port->fJackPort, newPortName))
return false;
}

return true;
}

template<typename T>
void _savePortsConnections(const LinkedList<T*>& t, const CarlaString& clientNamePrefix)
{
for (typename LinkedList<T*>::Itenerator it = t.begin2(); it.valid(); it.next())
{
T* const port(it.getValue(nullptr));
@@ -1141,47 +1175,48 @@ public:
return nullptr;
}

// single client always re-inits
bool needsReinit = (pData->options.processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT);
bool needsReinit = false;

// rename in multiple client mode
if (pData->options.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
// rename on client client mode, just rename the ports
if (pData->options.processMode == ENGINE_PROCESS_MODE_SINGLE_CLIENT)
{
CarlaEngineJackClient* const client((CarlaEngineJackClient*)plugin->getEngineClient());

#if 0
if (bridge.client_rename_ptr != nullptr)
if (! client->renameInSingleClient(uniqueName))
{
newName = jackbridge_client_rename(client->fClient, newName);
setLastError("Failed to rename some JACK ports, does your JACK version support proper port renaming?");
return nullptr;
}
else
#endif
}
// rename in multiple client mode
else if (pData->options.processMode == ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS)
{
CarlaEngineJackClient* const client((CarlaEngineJackClient*)plugin->getEngineClient());

// we should not be able to do this, jack really needs to allow client rename
if (jack_client_t* const jackClient = jackbridge_client_open(uniqueName, JackNullOption, nullptr))
{
// we should not be able to do this, jack really needs to allow client rename
if (jack_client_t* const jackClient = jackbridge_client_open(uniqueName, JackNullOption, nullptr))
{
// get new client name
uniqueName = jackbridge_get_client_name(jackClient);
// get new client name
uniqueName = jackbridge_get_client_name(jackClient);

// close client
client->closeForRename(jackClient, uniqueName);
// close client
client->closeForRename(jackClient, uniqueName);

// disable plugin
plugin->setEnabled(false);
// disable plugin
plugin->setEnabled(false);

// set new client data
jackbridge_set_thread_init_callback(jackClient, carla_jack_thread_init_callback, nullptr);
jackbridge_set_latency_callback(jackClient, carla_jack_latency_callback_plugin, plugin);
jackbridge_set_process_callback(jackClient, carla_jack_process_callback_plugin, plugin);
jackbridge_on_shutdown(jackClient, carla_jack_shutdown_callback_plugin, plugin);
// set new client data
jackbridge_set_thread_init_callback(jackClient, carla_jack_thread_init_callback, nullptr);
jackbridge_set_latency_callback(jackClient, carla_jack_latency_callback_plugin, plugin);
jackbridge_set_process_callback(jackClient, carla_jack_process_callback_plugin, plugin);
jackbridge_on_shutdown(jackClient, carla_jack_shutdown_callback_plugin, plugin);

needsReinit = true;
}
else
{
setLastError("Failed to create new JACK client");
return nullptr;
}
needsReinit = true;
}
else
{
setLastError("Failed to create new JACK client");
return nullptr;
}
}

@@ -1761,30 +1796,6 @@ protected:
}
}

void handleJackClientRenameCallback(const char* const oldName, const char* const newName)
{
CARLA_SAFE_ASSERT_RETURN(oldName != nullptr && oldName[0] != '\0',);
CARLA_SAFE_ASSERT_RETURN(newName != nullptr && newName[0] != '\0',);

// ignore this if on internal patchbay mode
if (! fExternalPatchbay) return;

for (LinkedList<GroupNameToId>::Itenerator it = fUsedGroups.list.begin2(); it.valid(); it.next())
{
static GroupNameToId groupNameFallback = { 0, { '\0' } };

GroupNameToId& groupNameToId(it.getValue(groupNameFallback));
CARLA_SAFE_ASSERT_CONTINUE(groupNameToId.group != 0);

if (std::strncmp(groupNameToId.name, oldName, STR_MAX) == 0)
{
groupNameToId.rename(newName);
callback(ENGINE_CALLBACK_PATCHBAY_CLIENT_RENAMED, groupNameToId.group, 0, 0, 0.0f, groupNameToId.name);
break;
}
}
}

void handleJackPortRenameCallback(const jack_port_id_t port, const char* const oldFullName, const char* const newFullName)
{
CARLA_SAFE_ASSERT_RETURN(oldFullName != nullptr && oldFullName[0] != '\0',);
@@ -2238,17 +2249,9 @@ private:
handlePtr->handleJackPortConnectCallback(a, b, (connect != 0));
}

static int JACKBRIDGE_API carla_jack_client_rename_callback(const char* oldName, const char* newName, void* arg)
{
handlePtr->handleJackClientRenameCallback(oldName, newName);
return 0;
}

// NOTE: JACK1 returns void, JACK2 returns int
static int JACKBRIDGE_API carla_jack_port_rename_callback(jack_port_id_t port, const char* oldName, const char* newName, void* arg)
static void JACKBRIDGE_API carla_jack_port_rename_callback(jack_port_id_t port, const char* oldName, const char* newName, void* arg)
{
handlePtr->handleJackPortRenameCallback(port, oldName, newName);
return 0;
}
#endif



+ 1
- 1
source/jackbridge/JackBridge.hpp View File

@@ -268,7 +268,7 @@ typedef int (JACKBRIDGE_API *JackSampleRateCallback)(jack_nframes_t nframes, vo
typedef void (JACKBRIDGE_API *JackPortRegistrationCallback)(jack_port_id_t port, int register_, void* arg);
typedef void (JACKBRIDGE_API *JackClientRegistrationCallback)(const char* name, int register_, void* arg);
typedef void (JACKBRIDGE_API *JackPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
typedef int (JACKBRIDGE_API *JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void* arg); // NOTE: returns void in JACK1, int in JACK2
typedef void (JACKBRIDGE_API *JackPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void* arg);
typedef void (JACKBRIDGE_API *JackFreewheelCallback)(int starting, void* arg);
typedef void (JACKBRIDGE_API *JackShutdownCallback)(void* arg);
typedef void (JACKBRIDGE_API *JackInfoShutdownCallback)(jack_status_t code, const char* reason, void* arg);


+ 18
- 24
source/jackbridge/JackBridge1.cpp View File

@@ -35,30 +35,29 @@

extern "C" {

typedef void (JACKSYM_API *JackSymLatencyCallback)(jack_latency_callback_mode_t mode, void* arg);
typedef int (JACKSYM_API *JackSymProcessCallback)(jack_nframes_t nframes, void* arg);
typedef void (JACKSYM_API *JackSymThreadInitCallback)(void* arg);
typedef int (JACKSYM_API *JackSymGraphOrderCallback)(void* arg);
typedef int (JACKSYM_API *JackSymXRunCallback)(void* arg);
typedef int (JACKSYM_API *JackSymBufferSizeCallback)(jack_nframes_t nframes, void* arg);
typedef int (JACKSYM_API *JackSymSampleRateCallback)(jack_nframes_t nframes, void* arg);
typedef void (JACKSYM_API *JackSymPortRegistrationCallback)(jack_port_id_t port, int register_, void* arg);
typedef void (JACKSYM_API *JackSymClientRegistrationCallback)(const char* name, int register_, void* arg);
typedef void (JACKSYM_API *JackSymPortConnectCallback)(jack_port_id_t a, jack_port_id_t b, int connect, void* arg);
typedef int (JACKSYM_API *JackSymPortRenameCallback)(jack_port_id_t port, const char* old_name, const char* new_name, void* arg); // NOTE: returns void in JACK1, int in JACK2
typedef void (JACKSYM_API *JackSymFreewheelCallback)(int starting, void* arg);
typedef void (JACKSYM_API *JackSymShutdownCallback)(void* arg);
typedef void (JACKSYM_API *JackSymInfoShutdownCallback)(jack_status_t code, const char* reason, void* arg);
typedef int (JACKSYM_API *JackSymSyncCallback)(jack_transport_state_t state, jack_position_t* pos, void* arg);
typedef void (JACKSYM_API *JackSymTimebaseCallback)(jack_transport_state_t state, jack_nframes_t nframes, jack_position_t* pos, int new_pos, void* arg);
typedef void (JACKSYM_API *JackSymSessionCallback)(jack_session_event_t* event, void* arg);
typedef void (JACKSYM_API *JackSymPropertyChangeCallback)(jack_uuid_t subject, const char* key, jack_property_change_t change, void* arg);
typedef void (JACKSYM_API *JackSymLatencyCallback)(jack_latency_callback_mode_t, void*);
typedef int (JACKSYM_API *JackSymProcessCallback)(jack_nframes_t, void*);
typedef void (JACKSYM_API *JackSymThreadInitCallback)(void*);
typedef int (JACKSYM_API *JackSymGraphOrderCallback)(void*);
typedef int (JACKSYM_API *JackSymXRunCallback)(void*);
typedef int (JACKSYM_API *JackSymBufferSizeCallback)(jack_nframes_t, void*);
typedef int (JACKSYM_API *JackSymSampleRateCallback)(jack_nframes_t, void*);
typedef void (JACKSYM_API *JackSymPortRegistrationCallback)(jack_port_id_t, int, void*);
typedef void (JACKSYM_API *JackSymClientRegistrationCallback)(const char*, int, void*);
typedef void (JACKSYM_API *JackSymPortConnectCallback)(jack_port_id_t, jack_port_id_t, int, void*);
typedef void (JACKSYM_API *JackSymPortRenameCallback)(jack_port_id_t, const char*, const char*, void*);
typedef void (JACKSYM_API *JackSymFreewheelCallback)(int, void*);
typedef void (JACKSYM_API *JackSymShutdownCallback)(void*);
typedef void (JACKSYM_API *JackSymInfoShutdownCallback)(jack_status_t, const char*, void*);
typedef int (JACKSYM_API *JackSymSyncCallback)(jack_transport_state_t, jack_position_t*, void*);
typedef void (JACKSYM_API *JackSymTimebaseCallback)(jack_transport_state_t, jack_nframes_t, jack_position_t*, int, void*);
typedef void (JACKSYM_API *JackSymSessionCallback)(jack_session_event_t*, void*);
typedef void (JACKSYM_API *JackSymPropertyChangeCallback)(jack_uuid_t, const char*, jack_property_change_t, void*);

typedef void (JACKSYM_API *jacksym_get_version)(int*, int*, int*, int*);
typedef const char* (JACKSYM_API *jacksym_get_version_string)(void);

typedef jack_client_t* (JACKSYM_API *jacksym_client_open)(const char*, jack_options_t, jack_status_t*);
typedef const char* (JACKSYM_API *jacksym_client_rename)(jack_client_t* client, const char* new_name);
typedef int (JACKSYM_API *jacksym_client_close)(jack_client_t*);

typedef int (JACKSYM_API *jacksym_client_name_size)(void);
@@ -182,7 +181,6 @@ struct JackBridge {
jacksym_get_version_string get_version_string_ptr;

jacksym_client_open client_open_ptr;
jacksym_client_rename client_rename_ptr;
jacksym_client_close client_close_ptr;

jacksym_client_name_size client_name_size_ptr;
@@ -299,7 +297,6 @@ struct JackBridge {
get_version_ptr(nullptr),
get_version_string_ptr(nullptr),
client_open_ptr(nullptr),
client_rename_ptr(nullptr),
client_close_ptr(nullptr),
client_name_size_ptr(nullptr),
get_client_name_ptr(nullptr),
@@ -419,7 +416,6 @@ struct JackBridge {
LIB_SYMBOL(get_version_string)

LIB_SYMBOL(client_open)
LIB_SYMBOL(client_rename)
LIB_SYMBOL(client_close)

LIB_SYMBOL(client_name_size)
@@ -1105,8 +1101,6 @@ bool jackbridge_set_port_rename_callback(jack_client_t* client, JackPortRenameCa
#elif defined(JACKBRIDGE_DIRECT)
return (jack_set_port_rename_callback(client, rename_callback, arg) == 0);
#else
if (getBridgeInstance().get_version_string_ptr != nullptr) // don't use this on JACK1
return false;
if (getBridgeInstance().set_port_rename_callback_ptr != nullptr)
{
# ifdef __WINE__


Loading…
Cancel
Save