Add option to limit automatable control parmaters
[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& lp, samplepos_t & when, 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         lp = now;
92         when = now;
93
94         _current_delta = 0;
95
96         return false;
97 }
98
99 std::string
100 Engine_TransportMaster::position_string () const
101 {
102         if (_session) {
103                 return PBD::to_string (_session->audible_sample());
104         }
105
106         return std::string();
107 }
108
109 std::string
110 Engine_TransportMaster::delta_string () const
111 {
112         return string ("0");
113 }
114
115 bool
116 Engine_TransportMaster::allow_request (TransportRequestSource src, TransportRequestType type) const
117 {
118         if (_session) {
119                 if (_session->config.get_jack_time_master()) {
120                         return true;
121                 } else {
122                         return false;
123                 }
124         }
125
126         return true;
127 }
128
129 samplecnt_t
130 Engine_TransportMaster::update_interval () const
131 {
132         return AudioEngine::instance()->samples_per_cycle();
133 }
134