12b7d313a259031fb201340e956cb5a5640baa5c
[ardour.git] / libs / ardour / engine_slave.cc
1 /*
2     Copyright (C) 2004 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <iostream>
21 #include <cerrno>
22
23 #include "ardour/audioengine.h"
24 #include "ardour/audio_backend.h"
25 #include "ardour/session.h"
26 #include "ardour/transport_master.h"
27
28 #include "pbd/i18n.h"
29
30 using namespace std;
31 using namespace ARDOUR;
32
33 Engine_TransportMaster::Engine_TransportMaster (AudioEngine& e)
34         : TransportMaster (Engine, X_("JACK"))
35         , engine (e)
36         , _starting (false)
37 {
38         check_backend ();
39 }
40
41 Engine_TransportMaster::~Engine_TransportMaster ()
42 {
43 }
44
45 void
46 Engine_TransportMaster::init ()
47 {
48 }
49
50 void
51 Engine_TransportMaster::check_backend()
52 {
53         if (AudioEngine::instance()->current_backend_name() == X_("JACK")) {
54                 _connected = true;
55         } else {
56                 _connected = false;
57         }
58 }
59
60 bool
61 Engine_TransportMaster::locked() const
62 {
63         return true;
64 }
65
66 bool
67 Engine_TransportMaster::ok() const
68 {
69         return true;
70 }
71
72 void
73 Engine_TransportMaster::pre_process (pframes_t, samplepos_t, boost::optional<samplepos_t>)
74 {
75         /* nothing to do */
76 }
77
78 bool
79 Engine_TransportMaster::speed_and_position (double& sp, samplepos_t& position, samplepos_t /* now */)
80 {
81         boost::shared_ptr<AudioBackend> backend = engine.current_backend();
82
83         /* 3rd argument (now) doesn't matter here because we're always being
84          * called synchronously with the engine.
85          */
86
87         if (backend && backend->speed_and_position (sp, position)) {
88                 return true;
89         }
90
91         _current_delta = 0;
92
93         return false;
94 }
95
96 std::string
97 Engine_TransportMaster::position_string () const
98 {
99         if (_session) {
100                 return PBD::to_string (_session->audible_sample());
101         }
102
103         return std::string();
104 }
105
106 std::string
107 Engine_TransportMaster::delta_string () const
108 {
109         return string ("0");
110 }
111
112 bool
113 Engine_TransportMaster::allow_request (TransportRequestSource src, TransportRequestType type) const
114 {
115         if (_session) {
116                 if (_session->config.get_jack_time_master()) {
117                         return true;
118                 } else {
119                         return false;
120                 }
121         }
122
123         return true;
124 }