moved OSC into libardour
[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                 at->record_enabled ();
167         }
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         Route* r = route_table[table_index];
179
180         if (r == 0) {
181                 return 0.0f;
182         }
183
184         return r->gain ();
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         Route* r = route_table[table_index];
195         
196         if (r != 0) {
197                 r->set_gain (gain, this);
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         Route* r = route_table[table_index];
209
210         if (r == 0) {
211                 return 0.0f;
212         }
213
214         return r->effective_gain ();
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         Route* r = route_table[table_index];
226
227         if (r == 0) {
228                 return 0.0f;
229         }
230
231         return r->peak_input_power (which_input);
232 }
233
234
235 bool
236 ControlProtocol::route_get_muted (uint32_t table_index)
237 {
238         if (table_index > route_table.size()) {
239                 return false;
240         }
241
242         Route* r = route_table[table_index];
243
244         if (r == 0) {
245                 return false;
246         }
247
248         return r->muted ();
249 }
250
251 void
252 ControlProtocol::route_set_muted (uint32_t table_index, bool yn)
253 {
254         if (table_index > route_table.size()) {
255                 return;
256         }
257
258         Route* r = route_table[table_index];
259
260         if (r != 0) {
261                 r->set_mute (yn, this);
262         }
263 }
264
265
266 bool
267 ControlProtocol::route_get_soloed (uint32_t table_index)
268 {
269         if (table_index > route_table.size()) {
270                 return false;
271         }
272
273         Route* r = route_table[table_index];
274
275         if (r == 0) {
276                 return false;
277         }
278
279         return r->soloed ();
280 }
281
282 void
283 ControlProtocol::route_set_soloed (uint32_t table_index, bool yn)
284 {
285         if (table_index > route_table.size()) {
286                 return;
287         }
288
289         Route* r = route_table[table_index];
290
291         if (r != 0) {
292                 r->set_solo (yn, this);
293         }
294 }
295
296 string
297 ControlProtocol:: route_get_name (uint32_t table_index)
298 {
299         if (table_index > route_table.size()) {
300                 return "";
301         }
302
303         Route* r = route_table[table_index];
304
305         if (r == 0) {
306                 return "";
307         }
308
309         return r->name();
310 }
311