new transport slave/master implementation, libs/ edition
[ardour.git] / libs / ardour / engine_slave.cc
index 7ac767c3e84565054c99b0527353c9791b31207e..10313705578f5078bd92d7465c88540a10eddf72 100644 (file)
 #include <iostream>
 #include <cerrno>
 
+#include "pbd/i18n.h"
+
 #include "ardour/audioengine.h"
 #include "ardour/audio_backend.h"
-#include "ardour/slave.h"
+#include "ardour/session.h"
+#include "ardour/transport_master.h"
 
 using namespace std;
 using namespace ARDOUR;
 
-Engine_Slave::Engine_Slave (AudioEngine& e)
-       : engine (e)
+Engine_TransportMaster::Engine_TransportMaster (AudioEngine& e)
+       : TransportMaster (Engine, X_("JACK"))
+       , engine (e)
+       , _starting (false)
+{
+       check_backend ();
+}
+
+Engine_TransportMaster::~Engine_TransportMaster ()
 {
-       double x;
-       samplepos_t p;
-       /* call this to initialize things */
-       speed_and_position (x, p);
 }
 
-Engine_Slave::~Engine_Slave ()
+void
+Engine_TransportMaster::init ()
 {
 }
 
+void
+Engine_TransportMaster::check_backend()
+{
+       if (AudioEngine::instance()->current_backend_name() == X_("JACK")) {
+               _connected = true;
+       } else {
+               _connected = false;
+       }
+}
+
 bool
-Engine_Slave::locked() const
+Engine_TransportMaster::locked() const
 {
        return true;
 }
 
 bool
-Engine_Slave::ok() const
+Engine_TransportMaster::ok() const
 {
        return true;
 }
 
+void
+Engine_TransportMaster::pre_process (pframes_t, samplepos_t, boost::optional<samplepos_t>)
+{
+       /* nothing to do */
+}
+
 bool
-Engine_Slave::speed_and_position (double& sp, samplepos_t& position)
+Engine_TransportMaster::speed_and_position (double& sp, samplepos_t& position, samplepos_t /* now */)
 {
        boost::shared_ptr<AudioBackend> backend = engine.current_backend();
 
-       if (backend) {
-               _starting = backend->speed_and_position (sp, position);
-       } else {
-               _starting = false;
+       /* 3rd argument (now) doesn't matter here because we're always being
+        * called synchronously with the engine.
+        */
+
+       if (backend && backend->speed_and_position (sp, position)) {
+               return true;
+       }
+
+       _current_delta = 0;
+
+       return false;
+}
+
+std::string
+Engine_TransportMaster::position_string () const
+{
+       if (_session) {
+               return to_string (_session->audible_sample());
+       }
+
+       return std::string();
+}
+
+std::string
+Engine_TransportMaster::delta_string () const
+{
+       return string ("0");
+}
+
+bool
+Engine_TransportMaster::allow_request (TransportRequestSource src, TransportRequestType type) const
+{
+       if (_session) {
+               if (_session->config.get_jack_time_master()) {
+                       return true;
+               } else {
+                       return false;
+               }
        }
 
        return true;