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