Mixer pane can be collapsed again, some cleanup, give up and go back to 'Off' for...
[ardour.git] / libs / ardour / control_protocol.cc
1 /*
2     Copyright (C) 2006 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     $Id$
19 */
20
21 #include <ardour/control_protocol.h>
22 #include <ardour/session.h>
23 #include <ardour/route.h>
24 #include <ardour/audio_track.h>
25
26 using namespace ARDOUR;
27 using namespace std;
28
29 sigc::signal<void> ControlProtocol::ZoomToSession;
30 sigc::signal<void> ControlProtocol::ZoomOut;
31 sigc::signal<void> ControlProtocol::ZoomIn;
32 sigc::signal<void> ControlProtocol::Enter;
33 sigc::signal<void,float> ControlProtocol::ScrollTimeline;
34
35 ControlProtocol::ControlProtocol (Session& s, string str)
36         : BasicUI (s),
37           _name (str)
38 {
39         _active = false;
40 }
41
42 ControlProtocol::~ControlProtocol ()
43 {
44 }
45
46 void
47 ControlProtocol::next_track (uint32_t initial_id)
48 {
49         uint32_t limit = session->nroutes();
50         Route* cr = route_table[0];
51         uint32_t id;
52
53         if (cr) {
54                 id = cr->remote_control_id ();
55         } else {
56                 id = 0;
57         }
58
59         if (id == limit) {
60                 id = 0;
61         } else {
62                 id++;
63         }
64
65         while (id < limit) {
66                 if ((cr = session->route_by_remote_id (id)) != 0) {
67                         break;
68                 }
69                 id++;
70         }
71
72         if (id == limit) {
73                 id = 0;
74                 while (id != initial_id) {
75                         if ((cr = session->route_by_remote_id (id)) != 0) {
76                                 break;
77                         }
78                         id++;
79                 }
80         }
81
82         route_table[0] = cr;
83 }
84
85 void
86 ControlProtocol::prev_track (uint32_t initial_id)
87 {
88         uint32_t limit = session->nroutes() - 1;
89         Route* cr = route_table[0];
90         uint32_t id;
91
92         if (cr) {
93                 id = cr->remote_control_id ();
94         } else {
95                 id = 0;
96         }
97
98         if (id == 0) {
99                 id = session->nroutes() - 1;
100         } else {
101                 id--;
102         }
103
104         while (id >= 0) {
105                 if ((cr = session->route_by_remote_id (id)) != 0) {
106                         break;
107                 }
108                 id--;
109         }
110
111         if (id < 0) {
112                 id = limit;
113                 while (id > initial_id) {
114                         if ((cr = session->route_by_remote_id (id)) != 0) {
115                                 break;
116                         }
117                         id--;
118                 }
119         }
120
121         route_table[0] = cr;
122 }
123
124
125 void
126 ControlProtocol::set_route_table_size (uint32_t size)
127 {
128         while (route_table.size() < size) {
129                 route_table.push_back (0);
130         }
131 }
132
133 void
134 ControlProtocol::set_route_table (uint32_t table_index, ARDOUR::Route*)
135 {
136 }
137
138 void
139 ControlProtocol::route_set_rec_enable (uint32_t table_index, bool yn)
140 {
141         if (table_index > route_table.size()) {
142                 return;
143         }
144
145         Route* r = route_table[table_index];
146
147         AudioTrack* at = dynamic_cast<AudioTrack*>(r);
148
149         if (at) {
150                 at->set_record_enable (yn, this);
151         }
152 }
153
154 bool
155 ControlProtocol::route_get_rec_enable (uint32_t table_index)
156 {
157         if (table_index > route_table.size()) {
158                 return false;
159         }
160
161         Route* r = route_table[table_index];
162
163         AudioTrack* at = dynamic_cast<AudioTrack*>(r);
164
165         if (at) {
166                 return at->record_enabled ();
167         }
168
169         return false;
170 }
171
172
173 float
174 ControlProtocol::route_get_gain (uint32_t table_index)
175 {
176         if (table_index > route_table.size()) {
177                 return 0.0f;
178         }
179
180         Route* r = route_table[table_index];
181
182         if (r == 0) {
183                 return 0.0f;
184         }
185
186         return r->gain ();
187 }
188
189 void
190 ControlProtocol::route_set_gain (uint32_t table_index, float gain)
191 {
192         if (table_index > route_table.size()) {
193                 return;
194         }
195
196         Route* r = route_table[table_index];
197         
198         if (r != 0) {
199                 r->set_gain (gain, this);
200         }
201 }
202
203 float
204 ControlProtocol::route_get_effective_gain (uint32_t table_index)
205 {
206         if (table_index > route_table.size()) {
207                 return 0.0f;
208         }
209
210         Route* r = route_table[table_index];
211
212         if (r == 0) {
213                 return 0.0f;
214         }
215
216         return r->effective_gain ();
217 }
218
219
220 float
221 ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t which_input)
222 {
223         if (table_index > route_table.size()) {
224                 return 0.0f;
225         }
226
227         Route* r = route_table[table_index];
228
229         if (r == 0) {
230                 return 0.0f;
231         }
232
233         return r->peak_input_power (which_input);
234 }
235
236
237 bool
238 ControlProtocol::route_get_muted (uint32_t table_index)
239 {
240         if (table_index > route_table.size()) {
241                 return false;
242         }
243
244         Route* r = route_table[table_index];
245
246         if (r == 0) {
247                 return false;
248         }
249
250         return r->muted ();
251 }
252
253 void
254 ControlProtocol::route_set_muted (uint32_t table_index, bool yn)
255 {
256         if (table_index > route_table.size()) {
257                 return;
258         }
259
260         Route* r = route_table[table_index];
261
262         if (r != 0) {
263                 r->set_mute (yn, this);
264         }
265 }
266
267
268 bool
269 ControlProtocol::route_get_soloed (uint32_t table_index)
270 {
271         if (table_index > route_table.size()) {
272                 return false;
273         }
274
275         Route* r = route_table[table_index];
276
277         if (r == 0) {
278                 return false;
279         }
280
281         return r->soloed ();
282 }
283
284 void
285 ControlProtocol::route_set_soloed (uint32_t table_index, bool yn)
286 {
287         if (table_index > route_table.size()) {
288                 return;
289         }
290
291         Route* r = route_table[table_index];
292
293         if (r != 0) {
294                 r->set_solo (yn, this);
295         }
296 }
297
298 string
299 ControlProtocol:: route_get_name (uint32_t table_index)
300 {
301         if (table_index > route_table.size()) {
302                 return "";
303         }
304
305         Route* r = route_table[table_index];
306
307         if (r == 0) {
308                 return "";
309         }
310
311         return r->name();
312 }
313