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;
34 Signal0<void> ControlProtocol::ZoomToSession;
35 Signal0<void> ControlProtocol::ZoomOut;
36 Signal0<void> ControlProtocol::ZoomIn;
37 Signal0<void> ControlProtocol::Enter;
38 Signal0<void> ControlProtocol::Undo;
39 Signal0<void> ControlProtocol::Redo;
40 Signal1<void,float> ControlProtocol::ScrollTimeline;
41 Signal1<void,uint32_t> ControlProtocol::SelectByRID;
43 ControlProtocol::ControlProtocol (Session& s, string str, EventLoop* evloop)
48 _own_event_loop = false;
51 _own_event_loop = true;
52 fatal << "programming error: cannot create control protocols without an existing event loop (yet)" << endmsg;
58 session->RouteAdded.connect (*this, MISSING_INVALIDATOR, boost::protect (boost::bind (&ControlProtocol::add_strip, this, _1)), _event_loop);
61 ControlProtocol::~ControlProtocol ()
66 ControlProtocol::add_strip (ARDOUR::RouteList&)
72 ControlProtocol::next_track (uint32_t initial_id)
74 uint32_t limit = session->nroutes();
75 boost::shared_ptr<Route> cr = route_table[0];
79 id = cr->remote_control_id ();
91 if ((cr = session->route_by_remote_id (id)) != 0) {
99 while (id != initial_id) {
100 if ((cr = session->route_by_remote_id (id)) != 0) {
111 ControlProtocol::prev_track (uint32_t initial_id)
113 uint32_t limit = session->nroutes();
114 boost::shared_ptr<Route> cr = route_table[0];
118 id = cr->remote_control_id ();
130 if ((cr = session->route_by_remote_id (id)) != 0) {
138 while (i > initial_id) {
139 if ((cr = session->route_by_remote_id (i)) != 0) {
151 ControlProtocol::set_route_table_size (uint32_t size)
153 while (route_table.size() < size) {
154 route_table.push_back (boost::shared_ptr<Route> ((Route*) 0));
159 ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR::Route> r)
161 if (table_index >= route_table.size()) {
165 route_table[table_index] = r;
167 // XXX SHAREDPTR need to handle r->GoingAway
171 ControlProtocol::set_route_table (uint32_t table_index, uint32_t remote_control_id)
173 boost::shared_ptr<Route> r = session->route_by_remote_id (remote_control_id);
179 set_route_table (table_index, r);
185 ControlProtocol::route_set_rec_enable (uint32_t table_index, bool yn)
187 if (table_index > route_table.size()) {
191 boost::shared_ptr<Route> r = route_table[table_index];
193 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
196 at->set_record_enabled (yn, this);
201 ControlProtocol::route_get_rec_enable (uint32_t table_index)
203 if (table_index > route_table.size()) {
207 boost::shared_ptr<Route> r = route_table[table_index];
209 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
212 return at->record_enabled ();
220 ControlProtocol::route_get_gain (uint32_t table_index)
222 if (table_index > route_table.size()) {
226 boost::shared_ptr<Route> r = route_table[table_index];
232 return r->amp()->gain ();
236 ControlProtocol::route_set_gain (uint32_t table_index, float gain)
238 if (table_index > route_table.size()) {
242 boost::shared_ptr<Route> r = route_table[table_index];
245 r->set_gain (gain, this);
250 ControlProtocol::route_get_effective_gain (uint32_t table_index)
252 if (table_index > route_table.size()) {
256 boost::shared_ptr<Route> r = route_table[table_index];
262 return r->amp()->gain_control()->get_value();
267 ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t which_input)
269 if (table_index > route_table.size()) {
273 boost::shared_ptr<Route> r = route_table[table_index];
279 return r->peak_meter().peak_power (which_input);
284 ControlProtocol::route_get_muted (uint32_t table_index)
286 if (table_index > route_table.size()) {
290 boost::shared_ptr<Route> r = route_table[table_index];
300 ControlProtocol::route_set_muted (uint32_t table_index, bool yn)
302 if (table_index > route_table.size()) {
306 boost::shared_ptr<Route> r = route_table[table_index];
309 r->set_mute (yn, this);
315 ControlProtocol::route_get_soloed (uint32_t table_index)
317 if (table_index > route_table.size()) {
321 boost::shared_ptr<Route> r = route_table[table_index];
331 ControlProtocol::route_set_soloed (uint32_t table_index, bool yn)
333 if (table_index > route_table.size()) {
337 boost::shared_ptr<Route> r = route_table[table_index];
340 r->set_solo (yn, this);
345 ControlProtocol:: route_get_name (uint32_t table_index)
347 if (table_index > route_table.size()) {
351 boost::shared_ptr<Route> r = route_table[table_index];
360 list<boost::shared_ptr<Bundle> >
361 ControlProtocol::bundles ()
363 return list<boost::shared_ptr<Bundle> > ();