From 27e4b66df7e1f67afb4f9b5d59f92e077248184c Mon Sep 17 00:00:00 2001 From: sletz Date: Sat, 28 Apr 2007 11:59:57 +0000 Subject: Add new jack_port_set_alias, jack_port_unset_alias and jack_port_get_aliases API. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1458 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 4 ++++ common/JackAPI.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++ common/JackGraphManager.cpp | 10 ++++----- common/JackPort.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++ common/JackPort.h | 15 +++++++++---- common/jack.h | 32 ++++++++++++++++++++++++++++ 6 files changed, 153 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ac86944..8ac73b65 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,10 @@ Jackdmp changes log --------------------------- +2007-04-28 Stephane Letz + + * Add new jack_port_set_alias, jack_port_unset_alias and jack_port_get_aliases API. + 2007-04-27 Stephane Letz * Add missing -D__SMP__in OSX project. diff --git a/common/JackAPI.cpp b/common/JackAPI.cpp index 4a29535c..d51664c3 100644 --- a/common/JackAPI.cpp +++ b/common/JackAPI.cpp @@ -114,6 +114,9 @@ extern "C" EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t); EXPORT int jack_recompute_total_latencies (jack_client_t*); EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name); + EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias); + EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias); + EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]); EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff); EXPORT int jack_port_request_monitor_by_name (jack_client_t *client, const char *port_name, int onoff); @@ -431,6 +434,54 @@ EXPORT int jack_port_set_name(jack_port_t* port, const char* name) } } +EXPORT int jack_port_set_alias(jack_port_t* port, const char* name) +{ +#ifdef __CLIENTDEBUG__ + JackLibGlobals::CheckContext(); +#endif + jack_port_id_t myport = (jack_port_id_t)port; + if (!CheckPort(myport)) { + jack_error("jack_port_set_alias called with an incorrect port %ld", myport); + return -1; + } else if (name == NULL) { + jack_error("jack_port_set_alias called with a NULL port name"); + return -1; + } else { + return GetGraphManager()->GetPort(myport)->SetAlias(name); + } +} + +EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name) +{ +#ifdef __CLIENTDEBUG__ + JackLibGlobals::CheckContext(); +#endif + jack_port_id_t myport = (jack_port_id_t)port; + if (!CheckPort(myport)) { + jack_error("jack_port_unset_alias called with an incorrect port %ld", myport); + return -1; + } else if (name == NULL) { + jack_error("jack_port_unset_alias called with a NULL port name"); + return -1; + } else { + return GetGraphManager()->GetPort(myport)->UnsetAlias(name); + } +} + +EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2]) +{ +#ifdef __CLIENTDEBUG__ + JackLibGlobals::CheckContext(); +#endif + jack_port_id_t myport = (jack_port_id_t)port; + if (!CheckPort(myport)) { + jack_error("jack_port_get_aliases called with an incorrect port %ld", myport); + return -1; + } else { + return GetGraphManager()->GetPort(myport)->GetAliases(aliases); + } +} + EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff) { #ifdef __CLIENTDEBUG__ diff --git a/common/JackGraphManager.cpp b/common/JackGraphManager.cpp index 7c0c8dba..381658de 100644 --- a/common/JackGraphManager.cpp +++ b/common/JackGraphManager.cpp @@ -475,9 +475,9 @@ int JackGraphManager::Connect(jack_port_id_t port_src, jack_port_id_t port_dst) if (!in_use_src || !in_use_dst) { if (!in_use_src) - jack_error("JackGraphManager::Connect: port_src not %ld used name = %s", port_src, GetPort(port_src)->fName); + jack_error("JackGraphManager::Connect: port_src = %ld not used name = %s", port_src, GetPort(port_src)->fName); if (!in_use_dst) - jack_error("JackGraphManager::Connect: port_dst not %ld used name = %s", port_dst, GetPort(port_dst)->fName); + jack_error("JackGraphManager::Connect: port_dst = %ld not used name = %s", port_dst, GetPort(port_dst)->fName); res = -1; goto end; } @@ -521,9 +521,9 @@ int JackGraphManager::Disconnect(jack_port_id_t port_src, jack_port_id_t port_ds if (!in_use_src || !in_use_dst) { if (!in_use_src) - jack_error("JackGraphManager::Disconnect: port_src not %ld used name = %s", port_src, GetPort(port_src)->fName); + jack_error("JackGraphManager::Disconnect: port_src = %ld not used name = %s", port_src, GetPort(port_src)->fName); if (!in_use_dst) - jack_error("JackGraphManager::Disconnect: port_src not %ld used name = %s", port_dst, GetPort(port_dst)->fName); + jack_error("JackGraphManager::Disconnect: port_src = %ld not used name = %s", port_dst, GetPort(port_dst)->fName); res = -1; goto end; } @@ -634,7 +634,7 @@ jack_port_id_t JackGraphManager::GetPort(const char* name) { for (int i = 0; i < PORT_NUM; i++) { JackPort* port = GetPort(i); - if (port->IsUsed() && strcmp(port->fName, name) == 0) + if (port->IsUsed() && port->NameEquals(name)) return i; } return NO_PORT; diff --git a/common/JackPort.cpp b/common/JackPort.cpp index c3898e2d..a3d553d0 100644 --- a/common/JackPort.cpp +++ b/common/JackPort.cpp @@ -184,6 +184,56 @@ int JackPort::SetName(const char* new_name) return 0; } +bool JackPort::NameEquals(const char* target) +{ + return (strcmp(fName, target) == 0 + || strcmp(fAlias1, target) == 0 + || strcmp(fAlias2, target) == 0); +} + +int JackPort::GetAliases(char* const aliases[2]) +{ + int cnt = 0; + + if (fAlias1[0] != '\0') { + snprintf(aliases[0], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", fAlias1); + cnt++; + } + + if (fAlias2[0] != '\0') { + snprintf(aliases[1], JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE, "%s", fAlias2); + cnt++; + } + + return cnt; +} + +int JackPort::SetAlias(const char* alias) +{ + if (fAlias1[0] == '\0') { + snprintf(fAlias1, sizeof(fAlias1), "%s", alias); + } else if (fAlias2[0] == '\0') { + snprintf(fAlias2, sizeof(fAlias2), "%s", alias); + } else { + return -1; + } + + return 0; +} + +int JackPort::UnsetAlias(const char* alias) +{ + if (strcmp(fAlias1, alias) == 0) { + fAlias1[0] = '\0'; + } else if (strcmp(fAlias2, alias) == 0) { + fAlias2[0] = '\0'; + } else { + return -1; + } + + return 0; +} + void JackPort::MixBuffer(float* mixbuffer, float* buffer, jack_nframes_t frames) { jack_nframes_t frames_group = frames / 4; diff --git a/common/JackPort.h b/common/JackPort.h index 72021e11..2792c77d 100644 --- a/common/JackPort.h +++ b/common/JackPort.h @@ -42,7 +42,9 @@ class JackPort private: enum JackPortFlags fFlags; - char fName[JACK_PORT_NAME_SIZE + 2]; + char fName[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + char fAlias1[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; + char fAlias2[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE]; int fRefNum; jack_nframes_t fLatency; @@ -53,8 +55,8 @@ class JackPort jack_port_id_t fTied; // Locally tied source port #ifdef WIN32 - //__declspec(align(16)) float fBuffer[BUFFER_SIZE_MAX]; - float fBuffer[BUFFER_SIZE_MAX]; + //__declspec(align(16)) float fBuffer[BUFFER_SIZE_MAX]; + float fBuffer[BUFFER_SIZE_MAX]; #elif __GNUC__ float fBuffer[BUFFER_SIZE_MAX] __attribute__((aligned(16))); #else @@ -75,7 +77,12 @@ class JackPort void Release(); const char* GetName() const; const char* GetShortName() const; - int SetName(const char * name); + int SetName(const char* name); + + int GetAliases(char* const aliases[2]); + int SetAlias(const char* alias); + int UnsetAlias(const char* alias); + bool NameEquals(const char* target); int Flags() const; const char* Type() const; diff --git a/common/jack.h b/common/jack.h index 0789da6c..78467227 100644 --- a/common/jack.h +++ b/common/jack.h @@ -585,6 +585,38 @@ extern "C" */ int jack_port_set_name (jack_port_t *port, const char *port_name); + /** + * Set @a alias as an alias for @a port. May be called at any time. + * If the alias is longer than jack_port_name_size(), it will be truncated. + * + * After a successful call, and until JACK exits or + * @function jack_port_unset_alias() is called, @alias may be + * used as a alternate name for the port. + * + * Ports can have up to two aliases - if both are already + * set, this function will return an error. + * + * @return 0 on success, otherwise a non-zero error code. + */ + int jack_port_set_alias (jack_port_t *port, const char *alias); + + /** + * Remove @a alias as an alias for @a port. May be called at any time. + * + * After a successful call, @a alias can no longer be + * used as a alternate name for the port. + * + * @return 0 on success, otherwise a non-zero error code. + */ + int jack_port_unset_alias (jack_port_t *port, const char *alias); + + /* + * Get any aliases known for @port. + * + * @return the number of aliases discovered for the port + */ + int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]); + /** * If @ref JackPortCanMonitor is set for this @a port, turn input * monitoring on or off. Otherwise, do nothing. -- cgit v1.2.1