various fixes to MidiRegionView selection handling, key handling, drawing of ghost...
[ardour2.git] / libs / surfaces / control_protocol / control_protocol.cc
blob983208343a90309708a1c8e60f840e5863d35ec6
1 /*
2 Copyright (C) 2006 Paul Davis
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.
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.
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.
21 #include "pbd/error.h"
23 #include "ardour/session.h"
24 #include "ardour/route.h"
25 #include "ardour/audio_track.h"
26 #include "ardour/meter.h"
27 #include "ardour/amp.h"
28 #include "control_protocol/control_protocol.h"
30 using namespace ARDOUR;
31 using namespace std;
32 using namespace PBD;
34 Signal0<void> ControlProtocol::ZoomToSession;
35 Signal0<void> ControlProtocol::ZoomOut;
36 Signal0<void> ControlProtocol::ZoomIn;
37 Signal0<void> ControlProtocol::Enter;
38 Signal1<void,float> ControlProtocol::ScrollTimeline;
39 Signal1<void,uint32_t> ControlProtocol::SelectByRID;
41 ControlProtocol::ControlProtocol (Session& s, string str, EventLoop* evloop)
42 : BasicUI (s),
43 _name (str)
45 if (evloop) {
46 _own_event_loop = false;
47 _event_loop = evloop;
48 } else {
49 _own_event_loop = true;
50 fatal << "programming error: cannot create control protocols without an existing event loop (yet)" << endmsg;
51 /*NOTREACHED*/
54 _active = false;
56 session->RouteAdded.connect (*this, MISSING_INVALIDATOR, boost::protect (boost::bind (&ControlProtocol::add_strip, this, _1)), _event_loop);
59 ControlProtocol::~ControlProtocol ()
63 void
64 ControlProtocol::add_strip (ARDOUR::RouteList&)
66 route_list_changed();
69 void
70 ControlProtocol::next_track (uint32_t initial_id)
72 uint32_t limit = session->nroutes();
73 boost::shared_ptr<Route> cr = route_table[0];
74 uint32_t id;
76 if (cr) {
77 id = cr->remote_control_id ();
78 } else {
79 id = 0;
82 if (id == limit) {
83 id = 0;
84 } else {
85 id++;
88 while (id <= limit) {
89 if ((cr = session->route_by_remote_id (id)) != 0) {
90 break;
92 id++;
95 if (id >= limit) {
96 id = 0;
97 while (id != initial_id) {
98 if ((cr = session->route_by_remote_id (id)) != 0) {
99 break;
101 id++;
105 route_table[0] = cr;
108 void
109 ControlProtocol::prev_track (uint32_t initial_id)
111 uint32_t limit = session->nroutes();
112 boost::shared_ptr<Route> cr = route_table[0];
113 int32_t id;
115 if (cr) {
116 id = cr->remote_control_id ();
117 } else {
118 id = 0;
121 if (id == 0) {
122 id = limit;
123 } else {
124 id--;
127 while (id >= 0) {
128 if ((cr = session->route_by_remote_id (id)) != 0) {
129 break;
131 id--;
134 if (id < 0) {
135 uint32_t i = limit;
136 while (i > initial_id) {
137 if ((cr = session->route_by_remote_id (i)) != 0) {
138 break;
140 i--;
144 route_table[0] = cr;
148 void
149 ControlProtocol::set_route_table_size (uint32_t size)
151 while (route_table.size() < size) {
152 route_table.push_back (boost::shared_ptr<Route> ((Route*) 0));
156 void
157 ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR::Route> r)
159 if (table_index >= route_table.size()) {
160 return;
163 route_table[table_index] = r;
165 // XXX SHAREDPTR need to handle r->GoingAway
168 bool
169 ControlProtocol::set_route_table (uint32_t table_index, uint32_t remote_control_id)
171 boost::shared_ptr<Route> r = session->route_by_remote_id (remote_control_id);
173 if (!r) {
174 return false;
177 set_route_table (table_index, r);
179 return true;
182 void
183 ControlProtocol::route_set_rec_enable (uint32_t table_index, bool yn)
185 if (table_index > route_table.size()) {
186 return;
189 boost::shared_ptr<Route> r = route_table[table_index];
191 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
193 if (at) {
194 at->set_record_enabled (yn, this);
198 bool
199 ControlProtocol::route_get_rec_enable (uint32_t table_index)
201 if (table_index > route_table.size()) {
202 return false;
205 boost::shared_ptr<Route> r = route_table[table_index];
207 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
209 if (at) {
210 return at->record_enabled ();
213 return false;
217 float
218 ControlProtocol::route_get_gain (uint32_t table_index)
220 if (table_index > route_table.size()) {
221 return 0.0f;
224 boost::shared_ptr<Route> r = route_table[table_index];
226 if (r == 0) {
227 return 0.0f;
230 return r->amp()->gain ();
233 void
234 ControlProtocol::route_set_gain (uint32_t table_index, float gain)
236 if (table_index > route_table.size()) {
237 return;
240 boost::shared_ptr<Route> r = route_table[table_index];
242 if (r != 0) {
243 r->set_gain (gain, this);
247 float
248 ControlProtocol::route_get_effective_gain (uint32_t table_index)
250 if (table_index > route_table.size()) {
251 return 0.0f;
254 boost::shared_ptr<Route> r = route_table[table_index];
256 if (r == 0) {
257 return 0.0f;
260 return r->amp()->gain_control()->get_value();
264 float
265 ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t which_input)
267 if (table_index > route_table.size()) {
268 return 0.0f;
271 boost::shared_ptr<Route> r = route_table[table_index];
273 if (r == 0) {
274 return 0.0f;
277 return r->peak_meter().peak_power (which_input);
281 bool
282 ControlProtocol::route_get_muted (uint32_t table_index)
284 if (table_index > route_table.size()) {
285 return false;
288 boost::shared_ptr<Route> r = route_table[table_index];
290 if (r == 0) {
291 return false;
294 return r->muted ();
297 void
298 ControlProtocol::route_set_muted (uint32_t table_index, bool yn)
300 if (table_index > route_table.size()) {
301 return;
304 boost::shared_ptr<Route> r = route_table[table_index];
306 if (r != 0) {
307 r->set_mute (yn, this);
312 bool
313 ControlProtocol::route_get_soloed (uint32_t table_index)
315 if (table_index > route_table.size()) {
316 return false;
319 boost::shared_ptr<Route> r = route_table[table_index];
321 if (r == 0) {
322 return false;
325 return r->soloed ();
328 void
329 ControlProtocol::route_set_soloed (uint32_t table_index, bool yn)
331 if (table_index > route_table.size()) {
332 return;
335 boost::shared_ptr<Route> r = route_table[table_index];
337 if (r != 0) {
338 r->set_solo (yn, this);
342 string
343 ControlProtocol:: route_get_name (uint32_t table_index)
345 if (table_index > route_table.size()) {
346 return "";
349 boost::shared_ptr<Route> r = route_table[table_index];
351 if (r == 0) {
352 return "";
355 return r->name();
358 list<boost::shared_ptr<Bundle> >
359 ControlProtocol::bundles ()
361 return list<boost::shared_ptr<Bundle> > ();