fix issues with recording while synced to JACK (non-pure-virtual method added to AudioBackend) and remove pause() from AudioEngine/AudioBackend APIs

This commit is contained in:
Paul Davis 2013-10-21 16:24:24 -04:00
parent f1a6735ca4
commit cfe42bc4ea
7 changed files with 71 additions and 65 deletions

View file

@ -327,20 +327,6 @@ class AudioBackend : public PortEngine {
*/ */
virtual int stop () = 0; 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 /** While remaining connected to the device, and without changing its
* configuration, start (or stop) calling the process_callback() of @param engine * configuration, start (or stop) calling the process_callback() of @param engine
* without waiting for the device. Once process_callback() has returned, it * without waiting for the device. Once process_callback() has returned, it
@ -478,6 +464,21 @@ class AudioBackend : public PortEngine {
virtual void update_latencies () = 0; 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: protected:
AudioEngine& engine; AudioEngine& engine;
}; };

View file

@ -85,7 +85,6 @@ public:
int start (bool for_latency_measurement=false); int start (bool for_latency_measurement=false);
int stop (bool for_latency_measurement=false); int stop (bool for_latency_measurement=false);
int pause ();
int freewheel (bool start_stop); int freewheel (bool start_stop);
float get_cpu_load() const ; float get_cpu_load() const ;
void transport_start (); void transport_start ();

View file

@ -662,23 +662,6 @@ AudioEngine::stop (bool for_latency)
return 0; return 0;
} }
int
AudioEngine::pause ()
{
if (!_backend) {
return 0;
}
if (_backend->pause ()) {
return -1;
}
_running = false;
Stopped(); /* EMIT SIGNAL */
return 0;
}
int int
AudioEngine::freewheel (bool start_stop) AudioEngine::freewheel (bool start_stop)
{ {

View file

@ -21,6 +21,7 @@
#include <cerrno> #include <cerrno>
#include "ardour/audioengine.h" #include "ardour/audioengine.h"
#include "ardour/audio_backend.h"
#include "ardour/slave.h" #include "ardour/slave.h"
using namespace std; using namespace std;
@ -54,26 +55,13 @@ Engine_Slave::ok() const
bool bool
Engine_Slave::speed_and_position (double& sp, framepos_t& position) Engine_Slave::speed_and_position (double& sp, framepos_t& position)
{ {
switch (engine.transport_state()) { boost::shared_ptr<AudioBackend> backend = engine.current_backend();
case TransportStopped:
speed = 0; if (backend) {
_starting = backend->speed_and_position (sp, position);
} else {
_starting = false; _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;
} }
sp = speed;
position = engine.transport_frame();
return true; return true;
} }

View file

@ -581,18 +581,6 @@ JACKAudioBackend::stop ()
return 0; return 0;
} }
int
JACKAudioBackend::pause ()
{
GET_PRIVATE_JACK_POINTER_RET (_priv_jack, -1);
if (_priv_jack) {
jack_deactivate (_priv_jack);
}
return 0;
}
int int
JACKAudioBackend::freewheel (bool onoff) JACKAudioBackend::freewheel (bool onoff)
{ {
@ -1131,3 +1119,46 @@ JACKAudioBackend::set_midi_option (const string& opt)
_target_midi_option = opt; _target_midi_option = opt;
return 0; 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;
}

View file

@ -91,7 +91,6 @@ class JACKAudioBackend : public AudioBackend {
int _start (bool for_latency_measurement); int _start (bool for_latency_measurement);
int stop (); int stop ();
int pause ();
int freewheel (bool); int freewheel (bool);
float cpu_load() const; float cpu_load() const;
@ -183,6 +182,10 @@ class JACKAudioBackend : public AudioBackend {
void* get_buffer (PortHandle, pframes_t); void* get_buffer (PortHandle, pframes_t);
/* transport sync */
bool speed_and_position (double& sp, framepos_t& pos);
private: private:
boost::shared_ptr<JackConnection> _jack_connection; boost::shared_ptr<JackConnection> _jack_connection;
bool _running; bool _running;

View file

@ -23,6 +23,7 @@
#include <glibmm/miscutils.h> #include <glibmm/miscutils.h>
#include <jack/jack.h> #include <jack/jack.h>
#include <jack/transport.h>
#include "ardour/audioengine.h" #include "ardour/audioengine.h"
#include "ardour/filename_extensions.h" #include "ardour/filename_extensions.h"