diff --git a/libs/ardour/ardour/audio_backend.h b/libs/ardour/ardour/audio_backend.h index 21f050afdd..26ced33885 100644 --- a/libs/ardour/ardour/audio_backend.h +++ b/libs/ardour/ardour/audio_backend.h @@ -327,20 +327,6 @@ class AudioBackend : public PortEngine { */ virtual int stop () = 0; - /** Temporarily cease using the device named in the most recent call to set_parameters(). - * - * If the function is successfully called, no subsequent calls to the - * process_callback() of @param engine will be made after the function - * returns, until start() is called again. - * - * The backend will retain its existing parameter configuration after a successful - * return, and does NOT require any calls to set hardware parameters before it can be - * start()-ed again. - * - * Return zero if successful, 1 if the device is not in use, negative values on error - */ - virtual int pause () = 0; - /** While remaining connected to the device, and without changing its * configuration, start (or stop) calling the process_callback() of @param engine * without waiting for the device. Once process_callback() has returned, it @@ -478,6 +464,21 @@ class AudioBackend : public PortEngine { virtual void update_latencies () = 0; + /** Set @param speed and @param position to the current speed and position + * indicated by some transport sync signal. Return whether the current + * transport state is pending, or finalized. + * + * Derived classes only need implement this if they provide some way to + * sync to a transport sync signal (e.g. Sony 9 Pin) that is not + * handled by Ardour itself (LTC and MTC are both handled by Ardour). + * The canonical example is JACK Transport. + */ + virtual bool speed_and_position (double& speed, framepos_t& position) { + speed = 0.0; + position = 0; + return false; + } + protected: AudioEngine& engine; }; diff --git a/libs/ardour/ardour/audioengine.h b/libs/ardour/ardour/audioengine.h index d5dcbffe2b..7c05f40b82 100644 --- a/libs/ardour/ardour/audioengine.h +++ b/libs/ardour/ardour/audioengine.h @@ -85,7 +85,6 @@ public: int start (bool for_latency_measurement=false); int stop (bool for_latency_measurement=false); - int pause (); int freewheel (bool start_stop); float get_cpu_load() const ; void transport_start (); diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index c2224a8b5e..45b8bbf757 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -662,23 +662,6 @@ AudioEngine::stop (bool for_latency) return 0; } -int -AudioEngine::pause () -{ - if (!_backend) { - return 0; - } - - if (_backend->pause ()) { - return -1; - } - - _running = false; - - Stopped(); /* EMIT SIGNAL */ - return 0; -} - int AudioEngine::freewheel (bool start_stop) { diff --git a/libs/ardour/engine_slave.cc b/libs/ardour/engine_slave.cc index eb55c9ba54..849b7320d3 100644 --- a/libs/ardour/engine_slave.cc +++ b/libs/ardour/engine_slave.cc @@ -21,6 +21,7 @@ #include #include "ardour/audioengine.h" +#include "ardour/audio_backend.h" #include "ardour/slave.h" using namespace std; @@ -54,26 +55,13 @@ Engine_Slave::ok() const bool Engine_Slave::speed_and_position (double& sp, framepos_t& position) { - switch (engine.transport_state()) { - case TransportStopped: - speed = 0; - _starting = false; - break; - case TransportRolling: - speed = 1.0; - _starting = false; - break; - case TransportLooping: - speed = 1.0; - _starting = false; - break; - case TransportStarting: - _starting = true; - // don't adjust speed here, just leave it as it was - break; - } + boost::shared_ptr backend = engine.current_backend(); - sp = speed; - position = engine.transport_frame(); + if (backend) { + _starting = backend->speed_and_position (sp, position); + } else { + _starting = false; + } + return true; } diff --git a/libs/backends/jack/jack_audiobackend.cc b/libs/backends/jack/jack_audiobackend.cc index ff76486bad..7a9b993251 100644 --- a/libs/backends/jack/jack_audiobackend.cc +++ b/libs/backends/jack/jack_audiobackend.cc @@ -581,18 +581,6 @@ JACKAudioBackend::stop () return 0; } -int -JACKAudioBackend::pause () -{ - GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1); - - if (_priv_jack) { - jack_deactivate (_priv_jack); - } - - return 0; -} - int JACKAudioBackend::freewheel (bool onoff) { @@ -1131,3 +1119,46 @@ JACKAudioBackend::set_midi_option (const string& opt) _target_midi_option = opt; return 0; } + +bool +JACKAudioBackend::speed_and_position (double& speed, framepos_t& position) +{ + jack_position_t pos; + jack_transport_state_t state; + bool starting; + + /* this won't be called if the port engine in use is not JACK, so we do + 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: + std::cerr << "WARNING: Unknown JACK transport state: " << state << std::endl; + } + + position = pos.frame; + return starting; +} diff --git a/libs/backends/jack/jack_audiobackend.h b/libs/backends/jack/jack_audiobackend.h index 3c48be5ead..c59ddb5c67 100644 --- a/libs/backends/jack/jack_audiobackend.h +++ b/libs/backends/jack/jack_audiobackend.h @@ -91,7 +91,6 @@ class JACKAudioBackend : public AudioBackend { int _start (bool for_latency_measurement); int stop (); - int pause (); int freewheel (bool); float cpu_load() const; @@ -183,6 +182,10 @@ class JACKAudioBackend : public AudioBackend { void* get_buffer (PortHandle, pframes_t); + /* transport sync */ + + bool speed_and_position (double& sp, framepos_t& pos); + private: boost::shared_ptr _jack_connection; bool _running; diff --git a/libs/backends/jack/jack_session.cc b/libs/backends/jack/jack_session.cc index ca51dafccc..7cd7f6c62b 100644 --- a/libs/backends/jack/jack_session.cc +++ b/libs/backends/jack/jack_session.cc @@ -23,6 +23,7 @@ #include #include +#include #include "ardour/audioengine.h" #include "ardour/filename_extensions.h"