add new debug bit for backend callbacks
[ardour.git] / libs / ardour / engine_slave.cc
1 /*
2  * Copyright (C) 2013-2019 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2015-2018 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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 bool
51 Engine_TransportMaster::usable () const
52 {
53         return AudioEngine::instance()->current_backend_name() == X_("JACK");
54 }
55
56 void
57 Engine_TransportMaster::check_backend()
58 {
59         if (AudioEngine::instance()->current_backend_name() == X_("JACK")) {
60                 _connected = true;
61         } else {
62                 _connected = false;
63         }
64 }
65
66 void
67 Engine_TransportMaster::reset (bool)
68 {
69         _starting = false;
70 }
71
72 bool
73 Engine_TransportMaster::locked() const
74 {
75         return true;
76 }
77
78 bool
79 Engine_TransportMaster::ok() const
80 {
81         return true;
82 }
83
84 void
85 Engine_TransportMaster::pre_process (pframes_t, samplepos_t, boost::optional<samplepos_t>)
86 {
87         /* nothing to do */
88 }
89
90 bool
91 Engine_TransportMaster::speed_and_position (double& sp, samplepos_t& position, samplepos_t& lp, samplepos_t & when, samplepos_t now)
92 {
93         boost::shared_ptr<AudioBackend> backend = engine.current_backend();
94
95         /* 3rd argument (now) doesn't matter here because we're always being
96          * called synchronously with the engine.
97          */
98
99         if (backend && backend->speed_and_position (sp, position)) {
100                 return true;
101         }
102
103         lp = now;
104         when = now;
105
106         _current_delta = 0;
107
108         return false;
109 }
110
111 std::string
112 Engine_TransportMaster::position_string () const
113 {
114         if (_session) {
115                 return PBD::to_string (_session->audible_sample());
116         }
117
118         return std::string();
119 }
120
121 std::string
122 Engine_TransportMaster::delta_string () const
123 {
124         return string ("0");
125 }
126
127 bool
128 Engine_TransportMaster::allow_request (TransportRequestSource src, TransportRequestType type) const
129 {
130         if (_session) {
131                 if (_session->config.get_jack_time_master()) {
132                         return true;
133                 } else {
134                         return false;
135                 }
136         }
137
138         return true;
139 }
140
141 samplecnt_t
142 Engine_TransportMaster::update_interval () const
143 {
144         return AudioEngine::instance()->samples_per_cycle();
145 }
146