2013-08-01 14:43:12 -04:00
|
|
|
/*
|
2019-08-02 22:11:41 -04:00
|
|
|
* Copyright (C) 2013-2018 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2013-08-01 14:43:12 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-08-03 11:57:56 -04:00
|
|
|
#include "pbd/error.h"
|
2013-08-01 14:43:12 -04:00
|
|
|
|
2013-09-13 11:21:43 -04:00
|
|
|
#include "jack_audiobackend.h"
|
2013-09-07 11:03:57 -04:00
|
|
|
#include "jack_connection.h"
|
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
#include "ardour/port_manager.h"
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2013-08-03 11:57:56 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
using namespace ARDOUR;
|
2013-08-03 11:57:56 -04:00
|
|
|
using namespace PBD;
|
2013-08-01 14:43:12 -04:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2013-07-31 19:47:20 -04:00
|
|
|
#define GET_PRIVATE_JACK_POINTER(localvar) jack_client_t* localvar = _jack_connection->jack(); if (!(localvar)) { return; }
|
|
|
|
#define GET_PRIVATE_JACK_POINTER_RET(localvar,r) jack_client_t* localvar = _jack_connection->jack(); if (!(localvar)) { return r; }
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
ardour_port_flags_to_jack_flags (PortFlags flags)
|
|
|
|
{
|
|
|
|
uint32_t jack_flags = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
if (flags & IsInput) {
|
2013-07-31 19:47:20 -04:00
|
|
|
jack_flags |= JackPortIsInput;
|
|
|
|
}
|
2013-08-01 14:43:12 -04:00
|
|
|
if (flags & IsOutput) {
|
2013-07-31 19:47:20 -04:00
|
|
|
jack_flags |= JackPortIsOutput;
|
|
|
|
}
|
2013-08-01 14:43:12 -04:00
|
|
|
if (flags & IsTerminal) {
|
2013-07-31 19:47:20 -04:00
|
|
|
jack_flags |= JackPortIsTerminal;
|
|
|
|
}
|
|
|
|
if (flags & IsPhysical) {
|
|
|
|
jack_flags |= JackPortIsPhysical;
|
|
|
|
}
|
|
|
|
if (flags & CanMonitor) {
|
|
|
|
jack_flags |= JackPortCanMonitor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jack_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
static DataType
|
|
|
|
jack_port_type_to_ardour_data_type (const char* jack_type)
|
|
|
|
{
|
|
|
|
if (strcmp (jack_type, JACK_DEFAULT_AUDIO_TYPE) == 0) {
|
|
|
|
return DataType::AUDIO;
|
|
|
|
} else if (strcmp (jack_type, JACK_DEFAULT_MIDI_TYPE) == 0) {
|
|
|
|
return DataType::MIDI;
|
|
|
|
}
|
|
|
|
return DataType::NIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
ardour_data_type_to_jack_port_type (DataType d)
|
2013-07-30 17:48:57 -04:00
|
|
|
{
|
2013-07-31 19:47:20 -04:00
|
|
|
switch (d) {
|
|
|
|
case DataType::AUDIO:
|
|
|
|
return JACK_DEFAULT_AUDIO_TYPE;
|
|
|
|
case DataType::MIDI:
|
|
|
|
return JACK_DEFAULT_MIDI_TYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2013-08-03 11:57:56 -04:00
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::when_connected_to_jack ()
|
2013-08-03 11:57:56 -04:00
|
|
|
{
|
|
|
|
/* register callbacks for stuff that is our responsibility */
|
|
|
|
|
|
|
|
jack_client_t* client = _jack_connection->jack();
|
|
|
|
|
|
|
|
if (!client) {
|
|
|
|
/* how could this happen? it could ... */
|
|
|
|
error << _("Already disconnected from JACK before PortEngine could register callbacks") << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
jack_set_port_registration_callback (client, _registration_callback, this);
|
|
|
|
jack_set_port_connect_callback (client, _connect_callback, this);
|
|
|
|
jack_set_graph_order_callback (client, _graph_order_callback, this);
|
|
|
|
}
|
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::set_port_name (PortHandle port, const std::string& name)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
2015-07-02 14:02:00 -04:00
|
|
|
#if HAVE_JACK_PORT_RENAME
|
|
|
|
jack_client_t* client = _jack_connection->jack();
|
|
|
|
if (client) {
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_rename (client, boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr, name.c_str());
|
2015-07-02 14:02:00 -04:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#else
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_set_name (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr, name.c_str());
|
2015-07-02 14:02:00 -04:00
|
|
|
#endif
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
string
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::get_port_name (PortHandle port) const
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_name (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr);
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
2013-07-31 19:47:20 -04:00
|
|
|
|
2018-10-17 14:10:50 -04:00
|
|
|
PortFlags
|
|
|
|
JACKAudioBackend::get_port_flags (PortHandle port) const
|
|
|
|
{
|
2020-04-07 12:18:16 -04:00
|
|
|
return PortFlags (jack_port_flags (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr));
|
2018-10-17 14:10:50 -04:00
|
|
|
}
|
|
|
|
|
2015-03-08 12:26:46 -04:00
|
|
|
int
|
|
|
|
JACKAudioBackend::get_port_property (PortHandle port, const std::string& key, std::string& value, std::string& type) const
|
|
|
|
{
|
2015-04-23 09:29:35 -04:00
|
|
|
#ifdef HAVE_JACK_METADATA // really everyone ought to have this by now.
|
2015-03-08 12:26:46 -04:00
|
|
|
int rv = -1;
|
|
|
|
char *cvalue = NULL;
|
|
|
|
char *ctype = NULL;
|
|
|
|
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_uuid_t uuid = jack_port_uuid (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr);
|
|
|
|
rv = jack_get_property (uuid, key.c_str(), &cvalue, &ctype);
|
2015-03-08 12:26:46 -04:00
|
|
|
|
2016-10-18 16:45:39 -04:00
|
|
|
if (0 == rv && cvalue) {
|
2015-03-08 12:26:46 -04:00
|
|
|
value = cvalue;
|
2016-10-18 16:45:39 -04:00
|
|
|
if (ctype) {
|
|
|
|
type = ctype;
|
|
|
|
}
|
2016-08-19 08:38:22 -04:00
|
|
|
} else {
|
|
|
|
rv = -1;
|
2015-03-08 12:26:46 -04:00
|
|
|
}
|
2016-08-19 08:38:22 -04:00
|
|
|
|
|
|
|
jack_free(cvalue);
|
|
|
|
jack_free(ctype);
|
2015-03-08 12:26:46 -04:00
|
|
|
return rv;
|
2016-04-17 18:35:51 -04:00
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::set_port_property (PortHandle port, const std::string& key, const std::string& value, const std::string& type)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_JACK_METADATA // really everyone ought to have this by now.
|
|
|
|
int rv = -1;
|
|
|
|
jack_client_t* client = _jack_connection->jack();
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_uuid_t uuid = jack_port_uuid (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr);
|
2016-04-17 18:35:51 -04:00
|
|
|
return jack_set_property(client, uuid, key.c_str(), value.c_str(), type.c_str());
|
|
|
|
return rv;
|
2015-03-08 12:26:46 -04:00
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:18:16 -04:00
|
|
|
PortEngine::PortPtr
|
2020-04-07 15:06:49 -04:00
|
|
|
JACKAudioBackend::get_port_by_name (const std::string& name) const
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
2020-04-07 20:54:57 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, PortEngine::PortPtr());
|
2020-04-07 15:06:49 -04:00
|
|
|
jack_port_t * jack_port = jack_port_by_name (_priv_jack, name.c_str());
|
|
|
|
|
|
|
|
if (!jack_port) {
|
|
|
|
return PortEngine::PortPtr();
|
|
|
|
}
|
|
|
|
|
2020-04-08 21:56:33 -04:00
|
|
|
boost::shared_ptr<JackPorts> ports = _jack_ports.reader ();
|
2020-04-07 15:06:49 -04:00
|
|
|
|
2020-04-08 21:56:33 -04:00
|
|
|
JackPorts::const_iterator i = ports->find (jack_port);
|
2020-04-07 15:06:49 -04:00
|
|
|
|
2020-04-08 21:56:33 -04:00
|
|
|
if (i != ports->end()) {
|
2020-04-07 15:06:49 -04:00
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
2020-04-08 21:56:33 -04:00
|
|
|
boost::shared_ptr<JackPort> jp;
|
|
|
|
|
|
|
|
{
|
|
|
|
RCUWriter<JackPorts> writer (_jack_ports);
|
|
|
|
boost::shared_ptr<JackPorts> ports = writer.get_copy();
|
|
|
|
jp.reset (new JackPort (jack_port));
|
|
|
|
ports->insert (std::make_pair (jack_port, jp));
|
|
|
|
}
|
|
|
|
|
|
|
|
_jack_ports.flush ();
|
2020-04-07 15:06:49 -04:00
|
|
|
|
|
|
|
return jp;
|
2013-07-30 17:48:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::_registration_callback (jack_port_id_t /*id*/, int /*reg*/, void* arg)
|
2013-07-30 17:48:57 -04:00
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
static_cast<JACKAudioBackend*> (arg)->manager.registration_callback ();
|
2021-01-13 21:21:59 -05:00
|
|
|
static_cast<JACKAudioBackend*> (arg)->engine.latency_callback (false);
|
|
|
|
static_cast<JACKAudioBackend*> (arg)->engine.latency_callback (true);
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::_graph_order_callback (void *arg)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
return static_cast<JACKAudioBackend*> (arg)->manager.graph_order_callback ();
|
2013-07-30 17:48:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::_connect_callback (jack_port_id_t id_a, jack_port_id_t id_b, int conn, void* arg)
|
2013-07-30 17:48:57 -04:00
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
static_cast<JACKAudioBackend*> (arg)->connect_callback (id_a, id_b, conn);
|
2013-07-30 17:48:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::connect_callback (jack_port_id_t id_a, jack_port_id_t id_b, int conn)
|
2013-07-30 17:48:57 -04:00
|
|
|
{
|
2013-08-01 14:43:12 -04:00
|
|
|
if (manager.port_remove_in_progress()) {
|
2013-07-30 17:48:57 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GET_PRIVATE_JACK_POINTER (_priv_jack);
|
|
|
|
|
2013-07-31 19:47:20 -04:00
|
|
|
jack_port_t* a = jack_port_by_id (_priv_jack, id_a);
|
|
|
|
jack_port_t* b = jack_port_by_id (_priv_jack, id_b);
|
2013-07-30 17:48:57 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
manager.connect_callback (jack_port_name (a), jack_port_name (b), conn == 0 ? false : true);
|
2013-07-30 17:48:57 -04:00
|
|
|
}
|
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
bool
|
2020-04-07 12:18:16 -04:00
|
|
|
JACKAudioBackend::connected (PortHandle p, bool process_callback_safe)
|
2013-07-30 17:48:57 -04:00
|
|
|
{
|
2013-08-01 14:43:12 -04:00
|
|
|
bool ret = false;
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_port_t* port = boost::dynamic_pointer_cast<JackPort>(p)->jack_ptr;
|
2013-09-05 21:39:43 -04:00
|
|
|
const char** ports;
|
|
|
|
|
|
|
|
if (process_callback_safe) {
|
2020-04-07 12:18:16 -04:00
|
|
|
ports = jack_port_get_connections (port);
|
2013-09-05 21:39:43 -04:00
|
|
|
} else {
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
|
2020-04-07 12:18:16 -04:00
|
|
|
ports = jack_port_get_all_connections (_priv_jack, port);
|
2013-09-05 21:39:43 -04:00
|
|
|
}
|
2013-08-01 14:43:12 -04:00
|
|
|
|
|
|
|
if (ports) {
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
jack_free (ports);
|
|
|
|
|
|
|
|
return ret;
|
2013-07-31 19:47:20 -04:00
|
|
|
}
|
2013-07-30 17:48:57 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
bool
|
2020-04-07 12:18:16 -04:00
|
|
|
JACKAudioBackend::connected_to (PortHandle p, const std::string& other, bool process_callback_safe)
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
2013-08-01 14:43:12 -04:00
|
|
|
bool ret = false;
|
2013-09-05 21:39:43 -04:00
|
|
|
const char** ports;
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_port_t* port = boost::dynamic_pointer_cast<JackPort>(p)->jack_ptr;
|
2013-09-05 21:39:43 -04:00
|
|
|
|
|
|
|
if (process_callback_safe) {
|
2020-04-07 12:18:16 -04:00
|
|
|
ports = jack_port_get_connections (port);
|
2013-09-05 21:39:43 -04:00
|
|
|
} else {
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
|
2020-04-07 12:18:16 -04:00
|
|
|
ports = jack_port_get_all_connections (_priv_jack, port);
|
2013-09-05 21:39:43 -04:00
|
|
|
}
|
2013-08-01 14:43:12 -04:00
|
|
|
|
|
|
|
if (ports) {
|
|
|
|
for (int i = 0; ports[i]; ++i) {
|
|
|
|
if (other == ports[i]) {
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jack_free (ports);
|
2013-07-30 17:48:57 -04:00
|
|
|
}
|
2013-07-31 19:47:20 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
return ret;
|
2013-07-30 17:48:57 -04:00
|
|
|
}
|
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
bool
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::physically_connected (PortHandle p, bool process_callback_safe)
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-08-01 14:43:12 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_port_t* port = boost::dynamic_pointer_cast<JackPort>(p)->jack_ptr;
|
2013-07-25 22:40:21 -04:00
|
|
|
|
2013-09-05 21:39:43 -04:00
|
|
|
const char** ports;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-09-05 21:39:43 -04:00
|
|
|
if (process_callback_safe) {
|
|
|
|
ports = jack_port_get_connections ((jack_port_t*)port);
|
|
|
|
} else {
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
|
|
|
|
ports = jack_port_get_all_connections (_priv_jack, (jack_port_t*)port);
|
|
|
|
}
|
2013-07-25 22:40:21 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
if (ports) {
|
|
|
|
for (int i = 0; ports[i]; ++i) {
|
2013-07-25 22:40:21 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
jack_port_t* other = jack_port_by_name (_priv_jack, ports[i]);
|
2013-07-25 22:40:21 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
if (other && (jack_port_flags (other) & JackPortIsPhysical)) {
|
2017-10-30 14:41:42 -04:00
|
|
|
jack_free (ports);
|
2013-07-25 22:40:21 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-08-01 14:43:12 -04:00
|
|
|
jack_free (ports);
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2013-07-30 23:26:46 -04:00
|
|
|
|
2017-10-30 14:41:42 -04:00
|
|
|
bool
|
|
|
|
JACKAudioBackend::externally_connected (PortHandle p, bool process_callback_safe)
|
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_port_t* port = boost::dynamic_pointer_cast<JackPort>(p)->jack_ptr;
|
2017-10-30 14:41:42 -04:00
|
|
|
|
|
|
|
const char** ports;
|
|
|
|
|
|
|
|
if (process_callback_safe) {
|
|
|
|
ports = jack_port_get_connections ((jack_port_t*)port);
|
|
|
|
} else {
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
|
|
|
|
ports = jack_port_get_all_connections (_priv_jack, (jack_port_t*)port);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ports) {
|
|
|
|
for (int i = 0; ports[i]; ++i) {
|
|
|
|
jack_port_t* other = jack_port_by_name (_priv_jack, ports[i]);
|
|
|
|
|
|
|
|
if (other && (jack_port_flags (other) & JackPortIsPhysical)) {
|
|
|
|
jack_free (ports);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (other && !jack_port_is_mine (_priv_jack, other)) {
|
|
|
|
jack_free (ports);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
jack_free (ports);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:49:40 -04:00
|
|
|
int
|
2020-04-07 12:18:16 -04:00
|
|
|
JACKAudioBackend::get_connections (PortHandle p, vector<string>& s, bool process_callback_safe)
|
2013-08-01 18:49:40 -04:00
|
|
|
{
|
2013-09-05 21:39:43 -04:00
|
|
|
const char** ports;
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_port_t* port = boost::dynamic_pointer_cast<JackPort>(p)->jack_ptr;
|
2013-09-05 21:39:43 -04:00
|
|
|
|
|
|
|
if (process_callback_safe) {
|
2020-04-07 12:18:16 -04:00
|
|
|
ports = jack_port_get_connections (port);
|
2013-09-05 21:39:43 -04:00
|
|
|
} else {
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, 0);
|
2020-04-07 12:18:16 -04:00
|
|
|
ports = jack_port_get_all_connections (_priv_jack, port);
|
2013-09-05 21:39:43 -04:00
|
|
|
}
|
2013-08-01 18:49:40 -04:00
|
|
|
|
|
|
|
if (ports) {
|
|
|
|
for (int i = 0; ports[i]; ++i) {
|
|
|
|
s.push_back (ports[i]);
|
|
|
|
}
|
|
|
|
jack_free (ports);
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.size();
|
|
|
|
}
|
|
|
|
|
2013-07-30 23:26:46 -04:00
|
|
|
DataType
|
2020-04-07 12:18:16 -04:00
|
|
|
JACKAudioBackend::port_data_type (PortHandle port) const
|
2013-07-30 23:26:46 -04:00
|
|
|
{
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_type_to_ardour_data_type (jack_port_type (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr));
|
2013-07-31 19:47:20 -04:00
|
|
|
}
|
2013-07-30 23:26:46 -04:00
|
|
|
|
2013-07-31 19:47:20 -04:00
|
|
|
const string&
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::my_name() const
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
2013-08-01 14:43:12 -04:00
|
|
|
return _jack_connection->client_name();
|
2013-07-31 19:47:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2020-04-07 12:18:16 -04:00
|
|
|
JACKAudioBackend::port_is_physical (PortHandle port) const
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
2020-04-07 12:18:16 -04:00
|
|
|
if (!port) {
|
2013-07-31 19:47:20 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_flags (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr) & JackPortIsPhysical;
|
2013-07-31 19:47:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::get_ports (const string& port_name_pattern, DataType type, PortFlags flags, vector<string>& s) const
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
|
|
|
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack,0);
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
const char** ports = jack_get_ports (_priv_jack, port_name_pattern.c_str(),
|
|
|
|
ardour_data_type_to_jack_port_type (type),
|
2013-07-31 19:47:20 -04:00
|
|
|
ardour_port_flags_to_jack_flags (flags));
|
|
|
|
|
|
|
|
if (ports == 0) {
|
2013-08-01 14:43:12 -04:00
|
|
|
return 0;
|
2013-07-30 23:26:46 -04:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:47:20 -04:00
|
|
|
for (uint32_t i = 0; ports[i]; ++i) {
|
|
|
|
s.push_back (ports[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
jack_free (ports);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-07-31 19:47:20 -04:00
|
|
|
return s.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
ChanCount
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::n_physical_inputs () const
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
|
|
|
return n_physical (JackPortIsInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
ChanCount
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::n_physical_outputs () const
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
|
|
|
return n_physical (JackPortIsOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::get_physical (DataType type, unsigned long flags, vector<string>& phy) const
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER (_priv_jack);
|
|
|
|
const char ** ports;
|
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
if ((ports = jack_get_ports (_priv_jack, NULL, ardour_data_type_to_jack_port_type (type), JackPortIsPhysical | flags)) == 0) {
|
2013-07-31 19:47:20 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ports) {
|
|
|
|
for (uint32_t i = 0; ports[i]; ++i) {
|
|
|
|
if (strstr (ports[i], "Midi-Through")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
phy.push_back (ports[i]);
|
|
|
|
}
|
|
|
|
jack_free (ports);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get physical ports for which JackPortIsOutput is set; ie those that correspond to
|
|
|
|
* a physical input connector.
|
|
|
|
*/
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::get_physical_inputs (DataType type, vector<string>& ins)
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
|
|
|
get_physical (type, JackPortIsOutput, ins);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get physical ports for which JackPortIsInput is set; ie those that correspond to
|
|
|
|
* a physical output connector.
|
|
|
|
*/
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::get_physical_outputs (DataType type, vector<string>& outs)
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
|
|
|
get_physical (type, JackPortIsInput, outs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::can_monitor_input () const
|
2013-07-31 19:47:20 -04:00
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack,false);
|
|
|
|
const char ** ports;
|
|
|
|
|
|
|
|
if ((ports = jack_get_ports (_priv_jack, NULL, JACK_DEFAULT_AUDIO_TYPE, JackPortCanMonitor)) == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
jack_free (ports);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-01 18:49:40 -04:00
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::request_input_monitoring (PortHandle port, bool yn)
|
2013-08-01 18:49:40 -04:00
|
|
|
{
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_request_monitor (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr, yn);
|
2013-08-01 18:49:40 -04:00
|
|
|
}
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::ensure_input_monitoring (PortHandle port, bool yn)
|
2013-08-01 18:49:40 -04:00
|
|
|
{
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_ensure_monitor (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr, yn);
|
2013-08-01 18:49:40 -04:00
|
|
|
}
|
|
|
|
bool
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::monitoring_input (PortHandle port)
|
2013-08-01 18:49:40 -04:00
|
|
|
{
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_monitoring_input (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr);
|
2013-08-01 18:49:40 -04:00
|
|
|
}
|
|
|
|
|
2020-04-07 12:18:16 -04:00
|
|
|
PortEngine::PortPtr
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::register_port (const std::string& shortname, ARDOUR::DataType type, ARDOUR::PortFlags flags)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
2020-04-07 20:57:24 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, PortEngine::PortPtr());
|
2020-04-07 15:06:49 -04:00
|
|
|
jack_port_t* jack_port = jack_port_register (_priv_jack, shortname.c_str(),
|
|
|
|
ardour_data_type_to_jack_port_type (type),
|
|
|
|
ardour_port_flags_to_jack_flags (flags),
|
|
|
|
0);
|
|
|
|
if (!jack_port) {
|
2020-04-07 12:18:16 -04:00
|
|
|
return PortEngine::PortPtr();
|
|
|
|
}
|
|
|
|
|
2020-04-08 21:56:33 -04:00
|
|
|
boost::shared_ptr<JackPort> jp;
|
|
|
|
|
|
|
|
{
|
|
|
|
RCUWriter<JackPorts> writer (_jack_ports);
|
|
|
|
boost::shared_ptr<JackPorts> ports = writer.get_copy();
|
|
|
|
|
|
|
|
jp.reset (new JackPort (jack_port));
|
|
|
|
|
|
|
|
ports->insert (std::make_pair (jack_port, jp));
|
|
|
|
}
|
2020-04-07 15:06:49 -04:00
|
|
|
|
2020-04-08 21:56:33 -04:00
|
|
|
_jack_ports.flush();
|
2020-04-07 15:06:49 -04:00
|
|
|
|
|
|
|
return jp;
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::unregister_port (PortHandle port)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER (_priv_jack);
|
2020-04-07 15:06:49 -04:00
|
|
|
boost::shared_ptr<JackPort> jp = boost::dynamic_pointer_cast<JackPort>(port);
|
2020-04-08 21:56:33 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
RCUWriter<JackPorts> writer (_jack_ports);
|
|
|
|
boost::shared_ptr<JackPorts> ports = writer.get_copy();
|
|
|
|
|
|
|
|
ports->erase (jp->jack_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
_jack_ports.flush ();
|
|
|
|
|
2020-04-07 15:06:49 -04:00
|
|
|
(void) jack_port_unregister (_priv_jack, jp->jack_ptr);
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::connect (PortHandle port, const std::string& other)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_connect (_priv_jack, jack_port_name (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr), other.c_str());
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::connect (const std::string& src, const std::string& dst)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-09-05 21:39:43 -04:00
|
|
|
int r = jack_connect (_priv_jack, src.c_str(), dst.c_str());
|
|
|
|
return r;
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::disconnect (PortHandle port, const std::string& other)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_disconnect (_priv_jack, jack_port_name (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr), other.c_str());
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::disconnect (const std::string& src, const std::string& dst)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
|
|
|
return jack_disconnect (_priv_jack, src.c_str(), dst.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::disconnect_all (PortHandle port)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_disconnect (_priv_jack, boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr);
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-08-05 09:04:05 -04:00
|
|
|
JACKAudioBackend::midi_event_get (pframes_t& timestamp, size_t& size, uint8_t const** buf, void* port_buffer, uint32_t event_index)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
jack_midi_event_t ev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((ret = jack_midi_event_get (&ev, port_buffer, event_index)) == 0) {
|
|
|
|
timestamp = ev.time;
|
|
|
|
size = ev.size;
|
|
|
|
*buf = ev.buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
return jack_midi_event_write (port_buffer, timestamp, buffer, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::get_midi_event_count (void* port_buffer)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
return jack_midi_get_event_count (port_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::midi_clear (void* port_buffer)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
jack_midi_clear_buffer (port_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::set_latency_range (PortHandle port, bool for_playback, LatencyRange r)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
jack_latency_range_t range;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-01 14:43:12 -04:00
|
|
|
range.min = r.min;
|
|
|
|
range.max = r.max;
|
|
|
|
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_port_set_latency_range (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr, for_playback ? JackPlaybackLatency : JackCaptureLatency, &range);
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
LatencyRange
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::get_latency_range (PortHandle port, bool for_playback)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
|
|
|
jack_latency_range_t range;
|
|
|
|
LatencyRange ret;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2020-04-07 12:18:16 -04:00
|
|
|
jack_port_get_latency_range (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr, for_playback ? JackPlaybackLatency : JackCaptureLatency, &range);
|
2013-08-01 14:43:12 -04:00
|
|
|
|
|
|
|
ret.min = range.min;
|
|
|
|
ret.max = range.max;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::get_buffer (PortHandle port, pframes_t nframes)
|
2013-08-01 14:43:12 -04:00
|
|
|
{
|
2020-04-07 12:18:16 -04:00
|
|
|
return jack_port_get_buffer (boost::dynamic_pointer_cast<JackPort>(port)->jack_ptr, nframes);
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
2013-08-01 18:49:40 -04:00
|
|
|
|
|
|
|
uint32_t
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::port_name_size() const
|
2013-08-01 18:49:40 -04:00
|
|
|
{
|
|
|
|
return jack_port_name_size ();
|
|
|
|
}
|