add Stripable analogs for Route signals and methods in ControlProtocol
[ardour.git] / libs / surfaces / control_protocol / control_protocol.cc
1 /*
2     Copyright (C) 2006 Paul Davis
3
4     This program is free software; you can redistribute it
5     and/or modify it under the terms of the GNU Lesser
6     General Public License as published by the Free Software
7     Foundation; either version 2 of the License, or (at your
8     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
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #include "pbd/error.h"
22
23 #include "ardour/gain_control.h"
24 #include "ardour/session.h"
25 #include "ardour/route.h"
26 #include "ardour/audio_track.h"
27 #include "ardour/meter.h"
28 #include "ardour/amp.h"
29 #include "control_protocol/control_protocol.h"
30
31 using namespace ARDOUR;
32 using namespace std;
33 using namespace PBD;
34
35 Signal0<void>       ControlProtocol::ZoomToSession;
36 Signal0<void>       ControlProtocol::ZoomOut;
37 Signal0<void>       ControlProtocol::ZoomIn;
38 Signal0<void>       ControlProtocol::Enter;
39 Signal0<void>       ControlProtocol::Undo;
40 Signal0<void>       ControlProtocol::Redo;
41 Signal1<void,float> ControlProtocol::ScrollTimeline;
42 Signal1<void,uint32_t> ControlProtocol::GotoView;
43 Signal0<void> ControlProtocol::CloseDialog;
44 PBD::Signal0<void> ControlProtocol::VerticalZoomInAll;
45 PBD::Signal0<void> ControlProtocol::VerticalZoomOutAll;
46 PBD::Signal0<void> ControlProtocol::VerticalZoomInSelected;
47 PBD::Signal0<void> ControlProtocol::VerticalZoomOutSelected;
48 PBD::Signal1<void,RouteNotificationListPtr> ControlProtocol::TrackSelectionChanged;
49 PBD::Signal0<void>          ControlProtocol::StepTracksDown;
50 PBD::Signal0<void>          ControlProtocol::StepTracksUp;
51
52 PBD::Signal1<void,uint64_t> ControlProtocol::AddRouteToSelection;
53 PBD::Signal1<void,uint64_t> ControlProtocol::SetRouteSelection;
54 PBD::Signal1<void,uint64_t> ControlProtocol::ToggleRouteSelection;
55 PBD::Signal1<void,uint64_t> ControlProtocol::RemoveRouteFromSelection;
56 PBD::Signal0<void>          ControlProtocol::ClearRouteSelection;
57
58 PBD::Signal1<void,StripableNotificationListPtr> ControlProtocol::StripableSelectionChanged;
59 PBD::Signal1<void,uint64_t> ControlProtocol::AddStripableToSelection;
60 PBD::Signal1<void,uint64_t> ControlProtocol::SetStripableSelection;
61 PBD::Signal1<void,uint64_t> ControlProtocol::ToggleStripableSelection;
62 PBD::Signal1<void,uint64_t> ControlProtocol::RemoveStripableFromSelection;
63 PBD::Signal0<void>          ControlProtocol::ClearStripableSelection;
64
65
66 const std::string ControlProtocol::state_node_name ("Protocol");
67
68 ControlProtocol::ControlProtocol (Session& s, string str)
69         : BasicUI (s)
70         , _name (str)
71         , _active (false)
72 {
73 }
74
75 ControlProtocol::~ControlProtocol ()
76 {
77 }
78
79 int
80 ControlProtocol::set_active (bool yn)
81 {
82         _active = yn;
83         return 0;
84 }
85
86 void
87 ControlProtocol::next_track (uint32_t initial_id)
88 {
89         // STRIPABLE route_table[0] = _session->get_nth_stripable (++initial_id, RemoteControlID::Route);
90 }
91
92 void
93 ControlProtocol::prev_track (uint32_t initial_id)
94 {
95         if (!initial_id) {
96                 return;
97         }
98         // STRIPABLE route_table[0] = _session->get_nth_stripable (--initial_id, RemoteControlID::Route);
99 }
100
101 void
102 ControlProtocol::set_route_table_size (uint32_t size)
103 {
104         while (route_table.size() < size) {
105                 route_table.push_back (boost::shared_ptr<Route> ((Route*) 0));
106         }
107 }
108
109 void
110 ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR::Route> r)
111 {
112         if (table_index >= route_table.size()) {
113                 return;
114         }
115
116         route_table[table_index] = r;
117
118         // XXX SHAREDPTR need to handle r->GoingAway
119 }
120
121 bool
122 ControlProtocol::set_route_table (uint32_t table_index, uint32_t remote_control_id)
123 {
124 #if 0 // STRIPABLE
125         boost::shared_ptr<Route> r = session->route_by_remote_id (remote_control_id);
126
127         if (!r) {
128                 return false;
129         }
130
131         set_route_table (table_index, r);
132 #endif
133         return true;
134 }
135
136 void
137 ControlProtocol::route_set_rec_enable (uint32_t table_index, bool yn)
138 {
139         if (table_index > route_table.size()) {
140                 return;
141         }
142
143         boost::shared_ptr<Route> r = route_table[table_index];
144
145         boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
146
147         if (at) {
148                 at->rec_enable_control()->set_value (1.0, Controllable::UseGroup);
149         }
150 }
151
152 bool
153 ControlProtocol::route_get_rec_enable (uint32_t table_index)
154 {
155         if (table_index > route_table.size()) {
156                 return false;
157         }
158
159         boost::shared_ptr<Route> r = route_table[table_index];
160
161         boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
162
163         if (at) {
164                 return at->rec_enable_control()->get_value();
165         }
166
167         return false;
168 }
169
170
171 float
172 ControlProtocol::route_get_gain (uint32_t table_index)
173 {
174         if (table_index > route_table.size()) {
175                 return 0.0f;
176         }
177
178         boost::shared_ptr<Route> r = route_table[table_index];
179
180         if (r == 0) {
181                 return 0.0f;
182         }
183
184         return r->gain_control()->get_value();
185 }
186
187 void
188 ControlProtocol::route_set_gain (uint32_t table_index, float gain)
189 {
190         if (table_index > route_table.size()) {
191                 return;
192         }
193
194         boost::shared_ptr<Route> r = route_table[table_index];
195
196         if (r != 0) {
197                 r->gain_control()->set_value (gain, Controllable::UseGroup);
198         }
199 }
200
201 float
202 ControlProtocol::route_get_effective_gain (uint32_t table_index)
203 {
204         if (table_index > route_table.size()) {
205                 return 0.0f;
206         }
207
208         boost::shared_ptr<Route> r = route_table[table_index];
209
210         if (r == 0) {
211                 return 0.0f;
212         }
213
214         return r->amp()->gain_control()->get_value();
215 }
216
217
218 float
219 ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t which_input)
220 {
221         if (table_index > route_table.size()) {
222                 return 0.0f;
223         }
224
225         boost::shared_ptr<Route> r = route_table[table_index];
226
227         if (r == 0) {
228                 return 0.0f;
229         }
230
231         return r->peak_meter()->meter_level (which_input, MeterPeak);
232 }
233
234 bool
235 ControlProtocol::route_get_muted (uint32_t table_index)
236 {
237         if (table_index > route_table.size()) {
238                 return false;
239         }
240
241         boost::shared_ptr<Route> r = route_table[table_index];
242
243         if (r == 0) {
244                 return false;
245         }
246
247         return r->mute_control()->muted ();
248 }
249
250 void
251 ControlProtocol::route_set_muted (uint32_t table_index, bool yn)
252 {
253         if (table_index > route_table.size()) {
254                 return;
255         }
256
257         boost::shared_ptr<Route> r = route_table[table_index];
258
259         if (r != 0) {
260                 r->mute_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup);
261         }
262 }
263
264
265 bool
266 ControlProtocol::route_get_soloed (uint32_t table_index)
267 {
268         if (table_index > route_table.size()) {
269                 return false;
270         }
271
272         boost::shared_ptr<Route> r = route_table[table_index];
273
274         if (r == 0) {
275                 return false;
276         }
277
278         return r->soloed ();
279 }
280
281 void
282 ControlProtocol::route_set_soloed (uint32_t table_index, bool yn)
283 {
284         if (table_index > route_table.size()) {
285                 return;
286         }
287
288         boost::shared_ptr<Route> r = route_table[table_index];
289
290         if (r != 0) {
291                 r->solo_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup);
292         }
293 }
294
295 string
296 ControlProtocol:: route_get_name (uint32_t table_index)
297 {
298         if (table_index > route_table.size()) {
299                 return "";
300         }
301
302         boost::shared_ptr<Route> r = route_table[table_index];
303
304         if (r == 0) {
305                 return "";
306         }
307
308         return r->name();
309 }
310
311 list<boost::shared_ptr<Bundle> >
312 ControlProtocol::bundles ()
313 {
314         return list<boost::shared_ptr<Bundle> > ();
315 }
316
317 XMLNode&
318 ControlProtocol::get_state ()
319 {
320         XMLNode* node = new XMLNode (state_node_name);
321
322         node->add_property ("name", _name);
323         node->add_property ("feedback", get_feedback() ? "yes" : "no");
324
325         return *node;
326 }
327
328 int
329 ControlProtocol::set_state (XMLNode const & node, int /* version */)
330 {
331         const XMLProperty* prop;
332
333         if ((prop = node.property ("feedback")) != 0) {
334                 set_feedback (string_is_affirmative (prop->value()));
335         }
336
337         return 0;
338 }