2013-07-25 12:36:54 -04:00
|
|
|
/*
|
2019-08-02 22:11:41 -04:00
|
|
|
* Copyright (C) 2013-2015 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2018 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-07-25 12:36:54 -04:00
|
|
|
|
2013-09-09 15:17:29 -04:00
|
|
|
#include <string>
|
|
|
|
#include <list>
|
2013-07-25 22:40:21 -04:00
|
|
|
#include <math.h>
|
2013-07-25 12:36:54 -04:00
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2013-07-30 17:48:57 -04:00
|
|
|
#include <glibmm/timer.h>
|
2013-09-09 21:23:12 -04:00
|
|
|
#include <glibmm/spawn.h>
|
2013-07-30 17:48:57 -04:00
|
|
|
|
|
|
|
#include "pbd/error.h"
|
|
|
|
|
2013-07-25 12:36:54 -04:00
|
|
|
#include "ardour/audioengine.h"
|
2019-11-15 17:14:54 -05:00
|
|
|
#include "ardour/debug.h"
|
2013-08-09 12:15:37 -04:00
|
|
|
#include "ardour/session.h"
|
2013-07-25 12:36:54 -04:00
|
|
|
#include "ardour/types.h"
|
2013-08-09 12:15:37 -04:00
|
|
|
|
2013-09-07 11:03:57 -04:00
|
|
|
#include "jack_audiobackend.h"
|
|
|
|
#include "jack_connection.h"
|
|
|
|
#include "jack_utils.h"
|
2013-10-08 14:02:03 -04:00
|
|
|
#include "jack_session.h"
|
2013-07-23 22:14:52 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2013-07-30 17:48:57 -04:00
|
|
|
|
2013-07-25 12:36:54 -04:00
|
|
|
using namespace ARDOUR;
|
2013-07-30 17:48:57 -04:00
|
|
|
using namespace PBD;
|
2013-07-25 12:36:54 -04:00
|
|
|
using std::string;
|
2013-07-30 17:48:57 -04:00
|
|
|
using std::vector;
|
2013-07-25 12:36:54 -04:00
|
|
|
|
2013-08-14 06:30:09 -04:00
|
|
|
|
2013-07-30 17:48:57 -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; }
|
2023-09-14 08:59:29 -04:00
|
|
|
// #define JACK_SERVER_CALL(expr) { std::cerr << "JACK SERVER CALL: " << DEBUG_THREAD_SELF << '/' << pthread_name() << ' ' << #expr << std::endl; Glib::Threads::Mutex::Lock lm (server_call_mutex); expr; }
|
2023-09-13 11:20:41 -04:00
|
|
|
#define JACK_SERVER_CALL(expr) { Glib::Threads::Mutex::Lock lm (server_call_mutex); expr; }
|
2013-07-25 22:40:21 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
JACKAudioBackend::JACKAudioBackend (AudioEngine& e, AudioBackendInfo& info, std::shared_ptr<JackConnection> jc)
|
2014-05-01 09:14:25 -04:00
|
|
|
: AudioBackend (e, info)
|
2013-07-31 19:47:20 -04:00
|
|
|
, _jack_connection (jc)
|
2013-07-30 17:48:57 -04:00
|
|
|
, _running (false)
|
|
|
|
, _freewheeling (false)
|
2013-07-25 12:36:54 -04:00
|
|
|
, _target_sample_rate (48000)
|
|
|
|
, _target_buffer_size (1024)
|
2015-12-05 07:56:18 -05:00
|
|
|
, _target_num_periods (2)
|
2013-07-25 12:36:54 -04:00
|
|
|
, _target_interleaved (false)
|
2013-09-17 21:09:13 -04:00
|
|
|
, _target_input_channels (0)
|
|
|
|
, _target_output_channels (0)
|
2013-07-25 12:36:54 -04:00
|
|
|
, _target_systemic_input_latency (0)
|
|
|
|
, _target_systemic_output_latency (0)
|
2013-08-08 16:31:08 -04:00
|
|
|
, _current_sample_rate (0)
|
|
|
|
, _current_buffer_size (0)
|
2020-04-08 21:56:33 -04:00
|
|
|
, _jack_ports (new JackPorts)
|
2013-10-08 14:02:03 -04:00
|
|
|
, _session (0)
|
2013-07-25 12:36:54 -04:00
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
_jack_connection->Connected.connect_same_thread (jack_connection_connection, boost::bind (&JACKAudioBackend::when_connected_to_jack, this));
|
2013-08-07 22:22:11 -04:00
|
|
|
_jack_connection->Disconnected.connect_same_thread (disconnect_connection, boost::bind (&JACKAudioBackend::disconnected, this, _1));
|
2013-07-25 12:36:54 -04:00
|
|
|
}
|
|
|
|
|
2013-08-01 18:49:40 -04:00
|
|
|
JACKAudioBackend::~JACKAudioBackend()
|
|
|
|
{
|
2020-04-08 21:56:33 -04:00
|
|
|
{
|
|
|
|
RCUWriter<JackPorts> writer (_jack_ports);
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<JackPorts> jp = writer.get_copy ();
|
2020-04-08 21:56:33 -04:00
|
|
|
jp->clear ();
|
|
|
|
}
|
|
|
|
|
|
|
|
_jack_ports.flush ();
|
2013-08-01 18:49:40 -04:00
|
|
|
}
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
string
|
2015-10-04 14:51:05 -04:00
|
|
|
JACKAudioBackend::name() const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
|
|
|
return X_("JACK");
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::private_handle() const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
return _jack_connection->jack();
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend::available() const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
return (private_handle() != 0);
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::is_realtime () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack,false);
|
2013-07-25 22:40:21 -04:00
|
|
|
return jack_is_realtime (_priv_jack);
|
|
|
|
}
|
|
|
|
|
2013-08-04 14:03:19 -04:00
|
|
|
bool
|
|
|
|
JACKAudioBackend::requires_driver_selection() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<string>
|
|
|
|
JACKAudioBackend::enumerate_drivers () const
|
|
|
|
{
|
2013-08-05 13:19:23 -04:00
|
|
|
vector<string> currently_available;
|
|
|
|
get_jack_audio_driver_names (currently_available);
|
|
|
|
return currently_available;
|
2013-08-04 14:03:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::set_driver (const std::string& name)
|
|
|
|
{
|
|
|
|
_target_driver = name;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-05 13:19:23 -04:00
|
|
|
vector<AudioBackend::DeviceStatus>
|
2013-07-25 22:40:21 -04:00
|
|
|
JACKAudioBackend::enumerate_devices () const
|
|
|
|
{
|
2013-08-05 13:19:23 -04:00
|
|
|
vector<string> currently_available = get_jack_device_names_for_audio_driver (_target_driver);
|
|
|
|
vector<DeviceStatus> statuses;
|
|
|
|
|
|
|
|
if (all_devices.find (_target_driver) == all_devices.end()) {
|
|
|
|
all_devices.insert (make_pair (_target_driver, std::set<string>()));
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* store every device we've found, by driver name.
|
2013-08-05 13:19:23 -04:00
|
|
|
*
|
|
|
|
* This is so we do not confuse ALSA, FFADO, netjack etc. devices
|
|
|
|
* with each other.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DeviceList& all (all_devices[_target_driver]);
|
|
|
|
|
|
|
|
for (vector<string>::const_iterator d = currently_available.begin(); d != currently_available.end(); ++d) {
|
|
|
|
all.insert (*d);
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-05 13:19:23 -04:00
|
|
|
for (DeviceList::const_iterator d = all.begin(); d != all.end(); ++d) {
|
|
|
|
if (find (currently_available.begin(), currently_available.end(), *d) == currently_available.end()) {
|
|
|
|
statuses.push_back (DeviceStatus (*d, false));
|
|
|
|
} else {
|
|
|
|
statuses.push_back (DeviceStatus (*d, false));
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-05 13:19:23 -04:00
|
|
|
return statuses;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
vector<float>
|
2013-11-27 17:41:54 -05:00
|
|
|
JACKAudioBackend::available_sample_rates (const string& device) const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
|
|
|
vector<float> f;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-11-27 17:41:54 -05:00
|
|
|
if (device == _target_device && available()) {
|
2013-07-30 17:48:57 -04:00
|
|
|
f.push_back (sample_rate());
|
2013-07-25 22:40:21 -04:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* if JACK is not already running, just list a bunch of reasonable
|
2013-07-25 22:40:21 -04:00
|
|
|
values and let the future sort it all out.
|
|
|
|
*/
|
|
|
|
|
|
|
|
f.push_back (8000.0);
|
|
|
|
f.push_back (16000.0);
|
|
|
|
f.push_back (24000.0);
|
|
|
|
f.push_back (32000.0);
|
|
|
|
f.push_back (44100.0);
|
|
|
|
f.push_back (48000.0);
|
|
|
|
f.push_back (88200.0);
|
|
|
|
f.push_back (96000.0);
|
|
|
|
f.push_back (192000.0);
|
|
|
|
f.push_back (384000.0);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<uint32_t>
|
2013-11-27 17:41:54 -05:00
|
|
|
JACKAudioBackend::available_buffer_sizes (const string& device) const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
|
|
|
vector<uint32_t> s;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-11-27 17:41:54 -05:00
|
|
|
if (device == _target_device && available()) {
|
2013-07-30 17:48:57 -04:00
|
|
|
s.push_back (buffer_size());
|
2013-07-25 22:40:21 -04:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
s.push_back (8);
|
|
|
|
s.push_back (16);
|
|
|
|
s.push_back (32);
|
|
|
|
s.push_back (64);
|
|
|
|
s.push_back (128);
|
|
|
|
s.push_back (256);
|
|
|
|
s.push_back (512);
|
|
|
|
s.push_back (1024);
|
|
|
|
s.push_back (2048);
|
|
|
|
s.push_back (4096);
|
|
|
|
s.push_back (8192);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2015-12-05 07:56:18 -05:00
|
|
|
std::vector<uint32_t>
|
2020-04-28 11:56:17 -04:00
|
|
|
JACKAudioBackend::available_period_sizes (const std::string& driver, const std::string&) const
|
2015-12-05 07:56:18 -05:00
|
|
|
{
|
|
|
|
vector<uint32_t> s;
|
|
|
|
if (ARDOUR::get_jack_audio_driver_supports_setting_period_count (driver)) {
|
|
|
|
s.push_back (2);
|
|
|
|
s.push_back (3);
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
uint32_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::available_input_channel_count (const string& /*device*/) const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
|
|
|
return 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::available_output_channel_count (const string& /*device*/) const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
|
|
|
return 128;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -- parameter setting -- */
|
|
|
|
|
2013-07-25 12:36:54 -04:00
|
|
|
int
|
|
|
|
JACKAudioBackend::set_device_name (const string& dev)
|
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
if (available()) {
|
2013-07-25 22:40:21 -04:00
|
|
|
/* need to stop and restart JACK for this to work, at present */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-25 12:36:54 -04:00
|
|
|
_target_device = dev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
int
|
|
|
|
JACKAudioBackend::set_sample_rate (float sr)
|
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
if (!available()) {
|
2013-07-30 17:48:57 -04:00
|
|
|
_target_sample_rate = sr;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-25 22:40:21 -04:00
|
|
|
|
2013-08-05 12:51:51 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
if (sr == jack_get_sample_rate (_priv_jack)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
return -1;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
2015-12-05 07:56:18 -05:00
|
|
|
int
|
|
|
|
JACKAudioBackend::set_peridod_size (uint32_t nperiods)
|
|
|
|
{
|
|
|
|
if (!available()) {
|
|
|
|
_target_num_periods = nperiods;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
int
|
|
|
|
JACKAudioBackend::set_buffer_size (uint32_t nframes)
|
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
if (!available()) {
|
2013-07-30 17:48:57 -04:00
|
|
|
_target_buffer_size = nframes;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-05 12:51:51 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
if (nframes == jack_get_buffer_size (_priv_jack)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jack_set_buffer_size (_priv_jack, nframes);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::set_interleaved (bool yn)
|
|
|
|
{
|
|
|
|
/* as far as JACK clients are concerned, the hardware is always
|
|
|
|
* non-interleaved
|
|
|
|
*/
|
|
|
|
if (!yn) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::set_input_channels (uint32_t cnt)
|
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
if (available()) {
|
2013-09-17 21:09:13 -04:00
|
|
|
if (cnt != 0) {
|
|
|
|
/* can't set a real value for this while JACK runs */
|
|
|
|
return -1;
|
|
|
|
}
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_target_input_channels = cnt;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
return 0;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::set_output_channels (uint32_t cnt)
|
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
if (available()) {
|
2013-09-17 21:09:13 -04:00
|
|
|
if (cnt != 0) {
|
|
|
|
/* can't set a real value for this while JACK runs */
|
|
|
|
return -1;
|
|
|
|
}
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
_target_output_channels = cnt;
|
2013-07-30 17:48:57 -04:00
|
|
|
|
|
|
|
return 0;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::set_systemic_input_latency (uint32_t l)
|
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
if (available()) {
|
2013-09-17 21:09:13 -04:00
|
|
|
/* can't do this while JACK runs */
|
2013-07-25 22:40:21 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
_target_systemic_input_latency = l;
|
2013-07-30 17:48:57 -04:00
|
|
|
|
|
|
|
return 0;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::set_systemic_output_latency (uint32_t l)
|
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
if (available()) {
|
2013-09-17 21:09:13 -04:00
|
|
|
/* can't do this while JACK runs */
|
2013-07-25 22:40:21 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
_target_systemic_output_latency = l;
|
2013-07-30 17:48:57 -04:00
|
|
|
|
|
|
|
return 0;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --- Parameter retrieval --- */
|
|
|
|
|
|
|
|
std::string
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::device_name () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-09-17 21:09:13 -04:00
|
|
|
if (!_jack_connection->in_control()) {
|
|
|
|
return "???"; // JACK has no way (as of fall 2013) to return
|
|
|
|
// the device name
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2013-09-09 15:17:29 -04:00
|
|
|
|
|
|
|
return _target_device;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
2013-09-17 21:09:13 -04:00
|
|
|
std::string
|
|
|
|
JACKAudioBackend::driver_name() const
|
|
|
|
{
|
|
|
|
if (!_jack_connection->in_control()) {
|
|
|
|
return "???"; // JACK has no way (as of fall 2013) to return
|
|
|
|
// the driver name
|
|
|
|
}
|
|
|
|
|
|
|
|
return _target_driver;
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
float
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::sample_rate () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-09-17 21:09:13 -04:00
|
|
|
if (!_jack_connection->in_control()) {
|
|
|
|
if (available()) {
|
|
|
|
return _current_sample_rate;
|
|
|
|
} else {
|
2015-06-14 12:10:31 -04:00
|
|
|
return _jack_connection->probed_sample_rate ();
|
2013-09-17 21:09:13 -04:00
|
|
|
}
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
return _target_sample_rate;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::buffer_size () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-09-17 21:09:13 -04:00
|
|
|
if (!_jack_connection->in_control()) {
|
|
|
|
if (available()) {
|
|
|
|
return _current_buffer_size;
|
|
|
|
} else {
|
2015-06-14 12:10:31 -04:00
|
|
|
return _jack_connection->probed_buffer_size ();
|
2013-09-17 21:09:13 -04:00
|
|
|
}
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
return _target_buffer_size;
|
|
|
|
}
|
|
|
|
|
2015-12-05 07:56:18 -05:00
|
|
|
uint32_t
|
|
|
|
JACKAudioBackend::period_size () const
|
|
|
|
{
|
|
|
|
return _target_num_periods;
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
bool
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::interleaved () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-10 16:18:00 -04:00
|
|
|
string
|
|
|
|
JACKAudioBackend::midi_option () const
|
|
|
|
{
|
|
|
|
return _target_midi_option;
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
uint32_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::input_channels () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-09-17 21:09:13 -04:00
|
|
|
if (!_jack_connection->in_control()) {
|
|
|
|
if (available()) {
|
|
|
|
return n_physical (JackPortIsInput).n_audio();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (available()) {
|
|
|
|
return n_physical (JackPortIsInput).n_audio();
|
|
|
|
} else {
|
|
|
|
return _target_input_channels;
|
|
|
|
}
|
|
|
|
}
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::output_channels () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-09-17 21:09:13 -04:00
|
|
|
if (!_jack_connection->in_control()) {
|
|
|
|
if (available()) {
|
|
|
|
return n_physical (JackPortIsOutput).n_audio();
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (available()) {
|
|
|
|
return n_physical (JackPortIsOutput).n_audio();
|
|
|
|
} else {
|
|
|
|
return _target_output_channels;
|
|
|
|
}
|
|
|
|
}
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::systemic_input_latency () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-08-08 16:31:08 -04:00
|
|
|
return _target_systemic_output_latency;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::systemic_output_latency () const
|
2013-07-25 22:40:21 -04:00
|
|
|
{
|
2013-08-08 16:31:08 -04:00
|
|
|
return _target_systemic_output_latency;
|
2013-07-25 22:40:21 -04:00
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
size_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::raw_buffer_size(DataType t)
|
|
|
|
{
|
|
|
|
std::map<DataType,size_t>::const_iterator s = _raw_buffer_sizes.find(t);
|
|
|
|
return (s != _raw_buffer_sizes.end()) ? s->second : 0;
|
|
|
|
}
|
|
|
|
|
2013-08-03 11:57:56 -04:00
|
|
|
void
|
2013-10-12 10:03:15 -04:00
|
|
|
JACKAudioBackend::setup_jack_startup_command (bool for_latency_measurement)
|
2013-08-03 11:57:56 -04:00
|
|
|
{
|
2013-08-03 16:37:10 -04:00
|
|
|
/* first we map the parameters that have been set onto a
|
|
|
|
* JackCommandLineOptions object.
|
2013-08-03 11:57:56 -04:00
|
|
|
*/
|
2013-08-03 16:37:10 -04:00
|
|
|
|
|
|
|
JackCommandLineOptions options;
|
|
|
|
|
2013-08-05 12:51:51 -04:00
|
|
|
get_jack_default_server_path (options.server_path);
|
|
|
|
options.driver = _target_driver;
|
2013-08-03 16:37:10 -04:00
|
|
|
options.samplerate = _target_sample_rate;
|
|
|
|
options.period_size = _target_buffer_size;
|
2015-12-05 07:56:18 -05:00
|
|
|
options.num_periods = _target_num_periods;
|
2013-08-03 16:37:10 -04:00
|
|
|
options.input_device = _target_device;
|
|
|
|
options.output_device = _target_device;
|
2015-10-03 02:22:19 -04:00
|
|
|
if (for_latency_measurement) {
|
|
|
|
options.input_latency = 0;
|
|
|
|
options.output_latency = 0;
|
|
|
|
} else {
|
|
|
|
options.input_latency = _target_systemic_input_latency;
|
|
|
|
options.output_latency = _target_systemic_output_latency;
|
|
|
|
}
|
2013-09-06 17:21:23 -04:00
|
|
|
options.input_channels = _target_input_channels;
|
|
|
|
options.output_channels = _target_output_channels;
|
2013-08-03 16:37:10 -04:00
|
|
|
if (_target_sample_format == FormatInt16) {
|
|
|
|
options.force16_bit = _target_sample_format;
|
|
|
|
}
|
2013-08-05 12:51:51 -04:00
|
|
|
options.realtime = true;
|
|
|
|
options.ports_max = 2048;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-10-10 12:59:11 -04:00
|
|
|
ARDOUR::set_midi_option (options, _target_midi_option);
|
|
|
|
|
2013-08-03 16:37:10 -04:00
|
|
|
/* this must always be true for any server instance we start ourselves
|
|
|
|
*/
|
|
|
|
|
|
|
|
options.temporary = true;
|
|
|
|
|
|
|
|
string cmdline;
|
|
|
|
|
2015-10-03 02:22:19 -04:00
|
|
|
if (!get_jack_command_line_string (options, cmdline)) {
|
2013-09-13 10:19:01 -04:00
|
|
|
/* error, somehow - we will still try to start JACK
|
|
|
|
* automatically but it will be without our preferred options
|
|
|
|
*/
|
2013-10-23 11:10:36 -04:00
|
|
|
std::cerr << "get_jack_command_line_string () failed: using default settings." << std::endl;
|
2013-08-09 18:35:07 -04:00
|
|
|
return;
|
2013-08-03 16:37:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "JACK command line will be: " << cmdline << std::endl;
|
|
|
|
|
2013-08-09 18:11:04 -04:00
|
|
|
write_jack_config_file (get_jack_server_user_config_file_path(), cmdline);
|
2013-08-03 11:57:56 -04:00
|
|
|
}
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
/* ---- BASIC STATE CONTROL API: start/stop/pause/freewheel --- */
|
|
|
|
|
2013-07-23 22:14:52 -04:00
|
|
|
int
|
2013-10-12 10:03:15 -04:00
|
|
|
JACKAudioBackend::_start (bool for_latency_measurement)
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-09-13 11:21:43 -04:00
|
|
|
if (!available()) {
|
2013-08-03 11:57:56 -04:00
|
|
|
|
2013-09-25 22:56:28 -04:00
|
|
|
if (_jack_connection->in_control()) {
|
2015-10-04 14:51:05 -04:00
|
|
|
/* we will be starting JACK, so set up the
|
2013-09-25 22:56:28 -04:00
|
|
|
command that JACK will use when it (auto-)starts
|
|
|
|
*/
|
2013-10-12 10:03:15 -04:00
|
|
|
setup_jack_startup_command (for_latency_measurement);
|
2013-08-03 11:57:56 -04:00
|
|
|
}
|
2013-08-03 16:37:10 -04:00
|
|
|
|
2013-08-08 16:31:08 -04:00
|
|
|
if (_jack_connection->open ()) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-07-30 17:48:57 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2013-07-24 19:29:45 -04:00
|
|
|
|
2013-08-08 16:31:08 -04:00
|
|
|
/* get the buffer size and sample rates established */
|
|
|
|
|
|
|
|
jack_sample_rate_callback (jack_get_sample_rate (_priv_jack));
|
|
|
|
jack_bufsize_callback (jack_get_buffer_size (_priv_jack));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* Now that we have buffer size and sample rate established, the engine
|
2013-08-08 16:31:08 -04:00
|
|
|
can go ahead and do its stuff
|
|
|
|
*/
|
2013-11-27 15:24:24 -05:00
|
|
|
|
|
|
|
if (engine.reestablish_ports ()) {
|
|
|
|
error << _("Could not re-establish ports after connecting to JACK") << endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-08 16:31:08 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
if (!jack_port_type_get_buffer_size) {
|
2013-08-08 16:31:08 -04:00
|
|
|
warning << _("This version of JACK is old - you should upgrade to a newer version that supports jack_port_type_get_buffer_size()") << endmsg;
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
set_jack_callbacks ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
if (jack_activate (_priv_jack) == 0) {
|
|
|
|
_running = true;
|
|
|
|
} else {
|
|
|
|
// error << _("cannot activate JACK client") << endmsg;
|
|
|
|
}
|
2013-08-08 16:31:08 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
engine.reconnect_ports ();
|
|
|
|
|
|
|
|
return 0;
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::stop ()
|
|
|
|
{
|
2014-06-04 10:58:53 -04:00
|
|
|
_running = false; // no 'engine halted message'.
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
_jack_connection->close ();
|
2013-07-23 22:14:52 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
_current_buffer_size = 0;
|
|
|
|
_current_sample_rate = 0;
|
2013-07-23 22:14:52 -04:00
|
|
|
|
|
|
|
_raw_buffer_sizes.clear();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::freewheel (bool onoff)
|
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2013-07-23 22:14:52 -04:00
|
|
|
|
|
|
|
if (onoff == _freewheeling) {
|
|
|
|
/* already doing what has been asked for */
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-07-23 22:14:52 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-09-13 11:20:41 -04:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
JACK_SERVER_CALL (ret = jack_set_freewheel (_priv_jack, onoff));
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2013-10-12 11:07:57 -04:00
|
|
|
_freewheeling = onoff;
|
2013-07-30 17:48:57 -04:00
|
|
|
return 0;
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
return -1;
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --- TRANSPORT STATE MANAGEMENT --- */
|
|
|
|
|
|
|
|
void
|
2013-07-24 08:36:04 -04:00
|
|
|
JACKAudioBackend::transport_stop ()
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER (_priv_jack);
|
2013-07-23 22:14:52 -04:00
|
|
|
jack_transport_stop (_priv_jack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-24 08:36:04 -04:00
|
|
|
JACKAudioBackend::transport_start ()
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER (_priv_jack);
|
2013-07-23 22:14:52 -04:00
|
|
|
jack_transport_start (_priv_jack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-09-18 12:39:17 -04:00
|
|
|
JACKAudioBackend::transport_locate (samplepos_t where)
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER (_priv_jack);
|
2013-07-23 22:14:52 -04:00
|
|
|
jack_transport_locate (_priv_jack, where);
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
|
|
|
JACKAudioBackend::transport_sample () const
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, 0);
|
2013-07-23 22:14:52 -04:00
|
|
|
return jack_get_current_transport_frame (_priv_jack);
|
|
|
|
}
|
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
TransportState
|
|
|
|
JACKAudioBackend::transport_state () const
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, ((TransportState) JackTransportStopped));
|
2013-07-23 22:14:52 -04:00
|
|
|
jack_position_t pos;
|
|
|
|
return (TransportState) jack_transport_query (_priv_jack, &pos);
|
|
|
|
}
|
|
|
|
|
2013-07-24 08:36:04 -04:00
|
|
|
int
|
|
|
|
JACKAudioBackend::set_time_master (bool yn)
|
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2013-07-24 08:36:04 -04:00
|
|
|
if (yn) {
|
2023-09-13 11:20:41 -04:00
|
|
|
JACK_SERVER_CALL (return jack_set_timebase_callback (_priv_jack, 0, _jack_timebase_callback, this));
|
2013-07-24 08:36:04 -04:00
|
|
|
} else {
|
2023-09-13 11:20:41 -04:00
|
|
|
JACK_SERVER_CALL (return jack_release_timebase (_priv_jack));
|
2013-07-24 08:36:04 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* process-time */
|
|
|
|
|
|
|
|
bool
|
|
|
|
JACKAudioBackend::get_sync_offset (pframes_t& offset) const
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifdef HAVE_JACK_VIDEO_SUPPORT
|
|
|
|
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, false);
|
2013-07-24 08:36:04 -04:00
|
|
|
|
|
|
|
jack_position_t pos;
|
|
|
|
|
|
|
|
if (_priv_jack) {
|
|
|
|
(void) jack_transport_query (_priv_jack, &pos);
|
|
|
|
|
|
|
|
if (pos.valid & JackVideoFrameOffset) {
|
|
|
|
offset = pos.video_offset;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* keep gcc happy */
|
|
|
|
offset = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::sample_time ()
|
2013-07-24 08:36:04 -04:00
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, 0);
|
|
|
|
return jack_frame_time (_priv_jack);
|
2013-07-24 08:36:04 -04:00
|
|
|
}
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplepos_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::sample_time_at_cycle_start ()
|
2013-07-24 08:36:04 -04:00
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, 0);
|
|
|
|
return jack_last_frame_time (_priv_jack);
|
2013-07-24 08:36:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
pframes_t
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::samples_since_cycle_start ()
|
2013-07-24 08:36:04 -04:00
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, 0);
|
|
|
|
return jack_frames_since_cycle_start (_priv_jack);
|
2013-07-24 08:36:04 -04:00
|
|
|
}
|
2013-07-23 22:14:52 -04:00
|
|
|
|
|
|
|
/* JACK Callbacks */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ardour_jack_error (const char* msg)
|
|
|
|
{
|
|
|
|
error << "JACK: " << msg << endmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JACKAudioBackend::set_jack_callbacks ()
|
|
|
|
{
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER (_priv_jack);
|
2013-07-23 22:14:52 -04:00
|
|
|
|
2023-04-21 13:46:56 -04:00
|
|
|
/* no need to set the thread_init_callback because we use the
|
|
|
|
* non-callback API, and run the thread init callback in our own code.
|
|
|
|
*/
|
2013-07-30 17:48:57 -04:00
|
|
|
|
2023-09-13 11:20:41 -04:00
|
|
|
JACK_SERVER_CALL (jack_set_process_thread (_priv_jack, _process_thread, this));
|
|
|
|
JACK_SERVER_CALL (jack_set_sample_rate_callback (_priv_jack, _sample_rate_callback, this));
|
|
|
|
JACK_SERVER_CALL (jack_set_buffer_size_callback (_priv_jack, _bufsize_callback, this));
|
|
|
|
JACK_SERVER_CALL (jack_set_xrun_callback (_priv_jack, _xrun_callback, this));
|
|
|
|
JACK_SERVER_CALL (jack_set_sync_callback (_priv_jack, _jack_sync_callback, this));
|
|
|
|
JACK_SERVER_CALL (jack_set_freewheel_callback (_priv_jack, _freewheel_callback, this));
|
2013-07-23 22:14:52 -04:00
|
|
|
|
|
|
|
#ifdef HAVE_JACK_SESSION
|
2023-09-13 11:20:41 -04:00
|
|
|
if (jack_set_session_callback) {
|
|
|
|
JACK_SERVER_CALL (jack_set_session_callback (_priv_jack, _session_callback, this));
|
|
|
|
}
|
2013-07-23 22:14:52 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (jack_set_latency_callback) {
|
2023-09-13 11:20:41 -04:00
|
|
|
JACK_SERVER_CALL (jack_set_latency_callback (_priv_jack, _latency_callback, this));
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
jack_set_error_function (ardour_jack_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JACKAudioBackend::_jack_timebase_callback (jack_transport_state_t state, pframes_t nframes,
|
|
|
|
jack_position_t* pos, int new_position, void *arg)
|
|
|
|
{
|
2023-09-14 08:59:29 -04:00
|
|
|
DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose ("%1/%2 jack timebase callback\n", DEBUG_THREAD_SELF, pthread_name()));
|
2013-07-30 17:48:57 -04:00
|
|
|
static_cast<JACKAudioBackend*> (arg)->jack_timebase_callback (state, nframes, pos, new_position);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-08-09 12:15:37 -04:00
|
|
|
JACKAudioBackend::jack_timebase_callback (jack_transport_state_t state, pframes_t nframes,
|
|
|
|
jack_position_t* pos, int new_position)
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-08-09 12:15:37 -04:00
|
|
|
ARDOUR::Session* session = engine.session();
|
2013-07-30 17:48:57 -04:00
|
|
|
|
2013-08-09 12:15:37 -04:00
|
|
|
if (session) {
|
2013-10-08 14:02:03 -04:00
|
|
|
JACKSession jsession (session);
|
|
|
|
jsession.timebase_callback (state, nframes, pos, new_position);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::_jack_sync_callback (jack_transport_state_t state, jack_position_t* pos, void* arg)
|
|
|
|
{
|
2023-09-14 08:59:29 -04:00
|
|
|
DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose ("%1/%2 jack sync callback\n", DEBUG_THREAD_SELF, pthread_name()));
|
2013-07-30 17:48:57 -04:00
|
|
|
return static_cast<JACKAudioBackend*> (arg)->jack_sync_callback (state, pos);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::jack_sync_callback (jack_transport_state_t state, jack_position_t* pos)
|
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
TransportState tstate;
|
2013-12-09 11:54:34 -05:00
|
|
|
bool tstate_valid = true;
|
2013-07-30 17:48:57 -04:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case JackTransportRolling:
|
|
|
|
tstate = TransportRolling;
|
|
|
|
break;
|
|
|
|
case JackTransportLooping:
|
|
|
|
tstate = TransportLooping;
|
|
|
|
break;
|
|
|
|
case JackTransportStarting:
|
|
|
|
tstate = TransportStarting;
|
|
|
|
break;
|
2013-11-04 21:32:41 -05:00
|
|
|
case JackTransportStopped:
|
|
|
|
tstate = TransportStopped;
|
|
|
|
break;
|
2013-12-09 11:54:34 -05:00
|
|
|
default:
|
|
|
|
// ignore "unofficial" states like JackTransportNetStarting (jackd2)
|
|
|
|
tstate_valid = false;
|
|
|
|
break;
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
2013-12-09 11:54:34 -05:00
|
|
|
if (tstate_valid) {
|
|
|
|
return engine.sync_callback (tstate, pos->frame);
|
|
|
|
}
|
2013-07-30 17:48:57 -04:00
|
|
|
|
2013-07-23 22:14:52 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::_xrun_callback (void *arg)
|
|
|
|
{
|
2023-09-14 08:59:29 -04:00
|
|
|
DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose ("%1/%2 jack sync callback\n", DEBUG_THREAD_SELF, pthread_name()));
|
2023-09-13 11:20:41 -04:00
|
|
|
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend* jab = static_cast<JACKAudioBackend*> (arg);
|
|
|
|
if (jab->available()) {
|
|
|
|
jab->engine.Xrun (); /* EMIT SIGNAL */
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JACKAudioBackend::_session_callback (jack_session_event_t *event, void *arg)
|
|
|
|
{
|
2023-09-14 08:59:29 -04:00
|
|
|
DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose ("%1/%2 jack session callback\n", DEBUG_THREAD_SELF, pthread_name()));
|
2023-09-13 11:20:41 -04:00
|
|
|
|
2013-09-13 11:21:43 -04:00
|
|
|
JACKAudioBackend* jab = static_cast<JACKAudioBackend*> (arg);
|
|
|
|
ARDOUR::Session* session = jab->engine.session();
|
2013-08-09 12:15:37 -04:00
|
|
|
|
|
|
|
if (session) {
|
2013-10-08 14:02:03 -04:00
|
|
|
JACKSession jsession (session);
|
|
|
|
jsession.session_event (event);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JACKAudioBackend::_freewheel_callback (int onoff, void *arg)
|
|
|
|
{
|
2023-09-14 08:59:29 -04:00
|
|
|
DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose ("%1/%2 jack freewheel callback\n", DEBUG_THREAD_SELF, pthread_name()));
|
2013-07-30 17:48:57 -04:00
|
|
|
static_cast<JACKAudioBackend*>(arg)->freewheel_callback (onoff);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JACKAudioBackend::freewheel_callback (int onoff)
|
|
|
|
{
|
|
|
|
_freewheeling = onoff;
|
2013-07-30 17:48:57 -04:00
|
|
|
engine.freewheel_callback (onoff);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JACKAudioBackend::_latency_callback (jack_latency_callback_mode_t mode, void* arg)
|
|
|
|
{
|
2023-09-14 08:59:29 -04:00
|
|
|
DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose ("%1/%2 jack latency callback\n", DEBUG_THREAD_SELF, pthread_name()));
|
2013-07-30 17:48:57 -04:00
|
|
|
return static_cast<JACKAudioBackend*> (arg)->jack_latency_callback (mode);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
2013-07-24 08:36:04 -04:00
|
|
|
int
|
2013-10-02 05:40:48 -04:00
|
|
|
JACKAudioBackend::create_process_thread (boost::function<void()> f)
|
2013-07-24 08:36:04 -04:00
|
|
|
{
|
2013-09-14 16:17:49 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
2013-08-14 06:30:09 -04:00
|
|
|
|
|
|
|
jack_native_thread_t thread_id;
|
2013-10-02 05:40:48 -04:00
|
|
|
ThreadData* td = new ThreadData (this, f, thread_stack_size());
|
2013-07-24 08:36:04 -04:00
|
|
|
|
2013-08-14 06:30:09 -04:00
|
|
|
if (jack_client_create_thread (_priv_jack, &thread_id, jack_client_real_time_priority (_priv_jack),
|
2013-07-24 08:36:04 -04:00
|
|
|
jack_is_realtime (_priv_jack), _start_process_thread, td)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-10-02 05:40:48 -04:00
|
|
|
_jack_threads.push_back(thread_id);
|
2013-08-14 06:30:09 -04:00
|
|
|
return 0;
|
2013-07-24 08:36:04 -04:00
|
|
|
}
|
|
|
|
|
2013-09-12 11:29:47 -04:00
|
|
|
int
|
2013-10-02 05:40:48 -04:00
|
|
|
JACKAudioBackend::join_process_threads ()
|
2013-09-12 11:29:47 -04:00
|
|
|
{
|
2022-10-20 01:34:26 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
|
|
|
|
|
2013-08-14 06:30:09 -04:00
|
|
|
int ret = 0;
|
|
|
|
|
2023-09-13 11:20:41 -04:00
|
|
|
for (auto & thread : _jack_threads) {
|
2013-10-02 05:40:48 -04:00
|
|
|
|
2015-07-04 03:52:04 -04:00
|
|
|
#if defined(USING_JACK2_EXPANSION_OF_JACK_API) || defined __jack_systemdeps_h__
|
2015-01-29 19:25:54 -05:00
|
|
|
// jack_client is not used by JACK2's implementation
|
|
|
|
// also jack_client_close() leaves threads active
|
2023-09-13 11:20:41 -04:00
|
|
|
if (jack_client_stop_thread (_priv_jack, thread) != 0)
|
2013-08-14 06:30:09 -04:00
|
|
|
#else
|
2013-10-02 05:40:48 -04:00
|
|
|
void* status;
|
2023-09-13 11:20:41 -04:00
|
|
|
if (pthread_join (thread, &status) != 0)
|
2013-08-14 06:30:09 -04:00
|
|
|
#endif
|
2015-01-29 19:25:54 -05:00
|
|
|
{
|
2013-10-02 05:40:48 -04:00
|
|
|
error << "AudioEngine: cannot stop process thread" << endmsg;
|
|
|
|
ret += -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_jack_threads.clear();
|
|
|
|
|
2013-08-14 06:30:09 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JACKAudioBackend::in_process_thread ()
|
|
|
|
{
|
2015-07-04 05:49:44 -04:00
|
|
|
#if defined COMPILER_MINGW && (!defined PTW32_VERSION || defined __jack_systemdeps_h__)
|
2014-10-22 17:02:15 -04:00
|
|
|
if (_main_thread == GetCurrentThread()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else // pthreads
|
|
|
|
if (pthread_equal (_main_thread, pthread_self()) != 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-09-13 11:20:41 -04:00
|
|
|
for (auto & thread : _jack_threads) {
|
2013-10-03 05:38:58 -04:00
|
|
|
|
2015-07-04 05:49:44 -04:00
|
|
|
#if defined COMPILER_MINGW && (!defined PTW32_VERSION || defined __jack_systemdeps_h__)
|
2023-09-13 11:20:41 -04:00
|
|
|
if (thread == GetCurrentThread()) {
|
2013-10-03 05:38:58 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#else // pthreads
|
2023-09-14 11:44:51 -04:00
|
|
|
if (pthread_equal (thread, pthread_self()) != 0) {
|
2013-10-03 05:38:58 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2013-08-14 06:30:09 -04:00
|
|
|
|
|
|
|
return false;
|
2013-09-12 11:29:47 -04:00
|
|
|
}
|
|
|
|
|
2013-10-02 05:40:48 -04:00
|
|
|
uint32_t
|
|
|
|
JACKAudioBackend::process_thread_count ()
|
|
|
|
{
|
|
|
|
return _jack_threads.size();
|
|
|
|
}
|
|
|
|
|
2018-10-10 19:36:10 -04:00
|
|
|
int
|
|
|
|
JACKAudioBackend::client_real_time_priority ()
|
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, 0);
|
|
|
|
return jack_client_real_time_priority (_priv_jack);
|
|
|
|
}
|
|
|
|
|
2013-07-24 08:36:04 -04:00
|
|
|
void*
|
|
|
|
JACKAudioBackend::_start_process_thread (void* arg)
|
|
|
|
{
|
|
|
|
ThreadData* td = reinterpret_cast<ThreadData*> (arg);
|
|
|
|
boost::function<void()> f = td->f;
|
|
|
|
delete td;
|
|
|
|
|
|
|
|
f ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-23 22:14:52 -04:00
|
|
|
void*
|
|
|
|
JACKAudioBackend::_process_thread (void *arg)
|
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
return static_cast<JACKAudioBackend*> (arg)->process_thread ();
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
|
|
|
JACKAudioBackend::process_thread ()
|
|
|
|
{
|
|
|
|
/* JACK doesn't do this for us when we use the wait API
|
|
|
|
*/
|
|
|
|
|
2015-07-04 05:49:44 -04:00
|
|
|
#if defined COMPILER_MINGW && (!defined PTW32_VERSION || defined __jack_systemdeps_h__)
|
2014-10-22 17:57:55 -04:00
|
|
|
_main_thread = GetCurrentThread();
|
|
|
|
#else
|
2014-10-22 17:02:15 -04:00
|
|
|
_main_thread = pthread_self ();
|
2014-10-22 17:57:55 -04:00
|
|
|
#endif
|
|
|
|
|
2014-10-22 17:02:15 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
AudioEngine::thread_init_callback (this);
|
2013-07-23 22:14:52 -04:00
|
|
|
|
|
|
|
while (1) {
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET(_priv_jack,0);
|
2021-06-12 11:20:28 -04:00
|
|
|
dsp_stats[AudioBackend::DeviceWait].start ();
|
2013-07-23 22:14:52 -04:00
|
|
|
pframes_t nframes = jack_cycle_wait (_priv_jack);
|
2021-06-12 11:20:28 -04:00
|
|
|
dsp_stats[AudioBackend::DeviceWait].update ();
|
2021-06-13 13:11:03 -04:00
|
|
|
dsp_stats[RunLoop].start();
|
|
|
|
|
2013-07-24 19:29:45 -04:00
|
|
|
if (engine.process_callback (nframes)) {
|
2013-07-23 22:14:52 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
jack_cycle_signal (_priv_jack, 0);
|
2021-06-13 13:11:03 -04:00
|
|
|
dsp_stats[AudioBackend::RunLoop].update ();
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::_sample_rate_callback (pframes_t nframes, void *arg)
|
|
|
|
{
|
2023-09-14 08:59:29 -04:00
|
|
|
DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose ("%1/%2 jack sample rate callback\n", DEBUG_THREAD_SELF, pthread_name()));
|
2013-07-30 17:48:57 -04:00
|
|
|
return static_cast<JACKAudioBackend*> (arg)->jack_sample_rate_callback (nframes);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::jack_sample_rate_callback (pframes_t nframes)
|
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
_current_sample_rate = nframes;
|
|
|
|
return engine.sample_rate_change (nframes);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
JACKAudioBackend::jack_latency_callback (jack_latency_callback_mode_t mode)
|
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
engine.latency_callback (mode == JackPlaybackLatency);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::_bufsize_callback (pframes_t nframes, void *arg)
|
|
|
|
{
|
2023-09-14 08:59:29 -04:00
|
|
|
DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose ("%1/%2 jack buffer size callback\n", DEBUG_THREAD_SELF, pthread_name()));
|
2013-07-30 17:48:57 -04:00
|
|
|
return static_cast<JACKAudioBackend*> (arg)->jack_bufsize_callback (nframes);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::jack_bufsize_callback (pframes_t nframes)
|
|
|
|
{
|
|
|
|
/* if the size has not changed, this should be a no-op */
|
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
if (nframes == _current_buffer_size) {
|
2013-07-23 22:14:52 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-29 23:41:41 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, 1);
|
2013-07-23 22:14:52 -04:00
|
|
|
|
2013-07-25 22:40:21 -04:00
|
|
|
_current_buffer_size = nframes;
|
2013-07-23 22:14:52 -04:00
|
|
|
|
|
|
|
if (jack_port_type_get_buffer_size) {
|
|
|
|
_raw_buffer_sizes[DataType::AUDIO] = jack_port_type_get_buffer_size (_priv_jack, JACK_DEFAULT_AUDIO_TYPE);
|
|
|
|
_raw_buffer_sizes[DataType::MIDI] = jack_port_type_get_buffer_size (_priv_jack, JACK_DEFAULT_MIDI_TYPE);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Old version of JACK.
|
|
|
|
|
|
|
|
These crude guesses, see below where we try to get the right answers.
|
|
|
|
|
|
|
|
Note that our guess for MIDI deliberatey tries to overestimate
|
|
|
|
by a little. It would be nicer if we could get the actual
|
|
|
|
size from a port, but we have to use this estimate in the
|
|
|
|
event that there are no MIDI ports currently. If there are
|
|
|
|
the value will be adjusted below.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_raw_buffer_sizes[DataType::AUDIO] = nframes * sizeof (Sample);
|
|
|
|
_raw_buffer_sizes[DataType::MIDI] = nframes * 4 - (nframes/2);
|
|
|
|
}
|
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
engine.buffer_size_change (nframes);
|
2013-07-23 22:14:52 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-07-30 17:48:57 -04:00
|
|
|
JACKAudioBackend::disconnected (const char* why)
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
bool was_running = _running;
|
2013-07-23 22:14:52 -04:00
|
|
|
|
2013-07-30 17:48:57 -04:00
|
|
|
_running = false;
|
|
|
|
_current_buffer_size = 0;
|
|
|
|
_current_sample_rate = 0;
|
2013-07-23 22:14:52 -04:00
|
|
|
|
|
|
|
if (was_running) {
|
2013-07-30 17:48:57 -04:00
|
|
|
engine.halted_callback (why); /* EMIT SIGNAL */
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
|
|
|
}
|
2013-09-19 15:03:20 -04:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
float
|
|
|
|
JACKAudioBackend::dsp_load() const
|
2013-07-23 22:14:52 -04:00
|
|
|
{
|
2013-07-30 17:48:57 -04:00
|
|
|
GET_PRIVATE_JACK_POINTER_RET(_priv_jack,0);
|
|
|
|
return jack_cpu_load (_priv_jack);
|
2013-07-23 22:14:52 -04:00
|
|
|
}
|
2013-08-01 14:43:12 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
JACKAudioBackend::update_latencies ()
|
|
|
|
{
|
|
|
|
GET_PRIVATE_JACK_POINTER (_priv_jack);
|
2023-09-13 11:20:41 -04:00
|
|
|
JACK_SERVER_CALL (jack_recompute_total_latencies (_priv_jack));
|
2013-08-01 14:43:12 -04:00
|
|
|
}
|
2013-08-01 18:49:40 -04:00
|
|
|
|
|
|
|
ChanCount
|
|
|
|
JACKAudioBackend::n_physical (unsigned long flags) const
|
|
|
|
{
|
|
|
|
ChanCount c;
|
|
|
|
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, c);
|
|
|
|
|
|
|
|
const char ** ports = jack_get_ports (_priv_jack, NULL, NULL, JackPortIsPhysical | flags);
|
|
|
|
|
|
|
|
if (ports) {
|
|
|
|
for (uint32_t i = 0; ports[i]; ++i) {
|
|
|
|
if (!strstr (ports[i], "Midi-Through")) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<JackPort> jp (new JackPort (jack_port_by_name (_priv_jack, ports[i])));
|
2020-04-07 12:18:16 -04:00
|
|
|
DataType t = port_data_type (jp);
|
2013-09-13 11:21:43 -04:00
|
|
|
if (t != DataType::NIL) {
|
|
|
|
c.set (t, c.get (t) + 1);
|
|
|
|
}
|
2013-08-01 18:49:40 -04:00
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-01 18:49:40 -04:00
|
|
|
jack_free (ports);
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
2013-09-09 13:27:48 -04:00
|
|
|
|
|
|
|
bool
|
|
|
|
JACKAudioBackend::can_change_sample_rate_when_running () const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
JACKAudioBackend::can_change_buffer_size_when_running () const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-09 15:17:29 -04:00
|
|
|
|
|
|
|
string
|
|
|
|
JACKAudioBackend::control_app_name () const
|
|
|
|
{
|
2013-09-09 21:23:12 -04:00
|
|
|
/* Since JACK/ALSA really don't provide particularly integrated support
|
|
|
|
for the idea of a control app to be used to control a device,
|
|
|
|
allow the user to take some control themselves if necessary.
|
|
|
|
*/
|
2013-09-09 15:17:29 -04:00
|
|
|
|
2013-09-09 21:23:12 -04:00
|
|
|
const char* env_value = g_getenv ("ARDOUR_DEVICE_CONTROL_APP");
|
|
|
|
string appname;
|
2013-09-09 15:17:29 -04:00
|
|
|
|
2013-09-09 21:23:12 -04:00
|
|
|
if (!env_value) {
|
|
|
|
if (_target_driver.empty() || _target_device.empty()) {
|
|
|
|
return appname;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-09-09 21:23:12 -04:00
|
|
|
if (_target_driver == "ALSA") {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-09-09 21:23:12 -04:00
|
|
|
if (_target_device == "Hammerfall DSP") {
|
|
|
|
appname = "hdspconf";
|
|
|
|
} else if (_target_device == "M Audio Delta 1010") {
|
2013-09-09 21:35:47 -04:00
|
|
|
appname = "mudita24";
|
2014-01-06 11:35:46 -05:00
|
|
|
} else if (_target_device == "M2496") {
|
|
|
|
appname = "mudita24";
|
2013-09-09 21:23:12 -04:00
|
|
|
}
|
2013-09-09 17:10:33 -04:00
|
|
|
}
|
2013-09-09 21:23:12 -04:00
|
|
|
} else {
|
|
|
|
appname = env_value;
|
2013-09-09 15:17:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return appname;
|
|
|
|
}
|
|
|
|
|
2013-09-09 21:23:12 -04:00
|
|
|
void
|
|
|
|
JACKAudioBackend::launch_control_app ()
|
|
|
|
{
|
|
|
|
string appname = control_app_name();
|
|
|
|
|
|
|
|
if (appname.empty()) {
|
|
|
|
error << string_compose (_("There is no control application for the device \"%1\""), _target_device) << endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<string> args;
|
|
|
|
args.push_back (appname);
|
|
|
|
Glib::spawn_async ("", args, Glib::SPAWN_SEARCH_PATH);
|
|
|
|
}
|
2013-10-10 12:59:11 -04:00
|
|
|
|
|
|
|
vector<string>
|
|
|
|
JACKAudioBackend::enumerate_midi_options () const
|
|
|
|
{
|
|
|
|
return ARDOUR::enumerate_midi_options ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::set_midi_option (const string& opt)
|
|
|
|
{
|
|
|
|
_target_midi_option = opt;
|
|
|
|
return 0;
|
|
|
|
}
|
2013-10-21 16:24:24 -04:00
|
|
|
|
|
|
|
bool
|
2017-09-18 12:39:17 -04:00
|
|
|
JACKAudioBackend::speed_and_position (double& speed, samplepos_t& position)
|
2013-10-21 16:24:24 -04:00
|
|
|
{
|
|
|
|
jack_position_t pos;
|
|
|
|
jack_transport_state_t state;
|
|
|
|
bool starting;
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* this won't be called if the port engine in use is not JACK, so we do
|
2013-10-21 16:24:24 -04:00
|
|
|
not have to worry about the type of PortEngine::private_handle()
|
|
|
|
*/
|
|
|
|
|
|
|
|
speed = 0;
|
|
|
|
position = 0;
|
|
|
|
|
|
|
|
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, true);
|
|
|
|
|
|
|
|
state = jack_transport_query (_priv_jack, &pos);
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case JackTransportStopped:
|
|
|
|
speed = 0;
|
|
|
|
starting = false;
|
|
|
|
break;
|
|
|
|
case JackTransportRolling:
|
|
|
|
speed = 1.0;
|
|
|
|
starting = false;
|
|
|
|
break;
|
|
|
|
case JackTransportLooping:
|
|
|
|
speed = 1.0;
|
|
|
|
starting = false;
|
|
|
|
break;
|
|
|
|
case JackTransportStarting:
|
|
|
|
starting = true;
|
|
|
|
// don't adjust speed here, just leave it as it was
|
|
|
|
break;
|
|
|
|
default:
|
2014-03-22 21:26:37 -04:00
|
|
|
starting = true; // jack2: JackTransportNetStarting
|
2013-10-21 16:24:24 -04:00
|
|
|
std::cerr << "WARNING: Unknown JACK transport state: " << state << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
position = pos.frame;
|
2019-11-15 17:14:54 -05:00
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::Slave, string_compose ("JACK transport: speed %1 position %2 starting %3\n", speed, position, starting));
|
|
|
|
|
2013-10-21 16:24:24 -04:00
|
|
|
return starting;
|
|
|
|
}
|
2014-09-30 20:35:31 -04:00
|
|
|
|
|
|
|
int
|
|
|
|
JACKAudioBackend::reset_device ()
|
|
|
|
{
|
|
|
|
/* XXX need to figure out what this means for JACK
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
}
|