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/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"
32 using namespace ARDOUR;
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;
52 PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::AddStripableToSelection;
53 PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::SetStripableSelection;
54 PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::ToggleStripableSelection;
55 PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::RemoveStripableFromSelection;
56 PBD::Signal0<void> ControlProtocol::ClearStripableSelection;
58 PBD::Signal1<void,StripableNotificationListPtr> ControlProtocol::StripableSelectionChanged;
60 Glib::Threads::Mutex ControlProtocol::first_selected_mutex;
61 boost::weak_ptr<Stripable> ControlProtocol::_first_selected_stripable;
62 StripableNotificationList ControlProtocol::_last_selected;
63 bool ControlProtocol::selection_connected = false;
64 PBD::ScopedConnection ControlProtocol::selection_connection;
66 const std::string ControlProtocol::state_node_name ("Protocol");
68 ControlProtocol::ControlProtocol (Session& s, string str)
73 if (!selection_connected) {
74 /* this is all static, connect it only once (and early), for all ControlProtocols */
76 StripableSelectionChanged.connect_same_thread (selection_connection, boost::bind (&ControlProtocol::stripable_selection_changed, _1));
77 selection_connected = true;
81 ControlProtocol::~ControlProtocol ()
86 ControlProtocol::set_active (bool yn)
93 ControlProtocol::next_track (uint32_t initial_id)
95 // STRIPABLE route_table[0] = _session->get_nth_stripable (++initial_id, RemoteControlID::Route);
99 ControlProtocol::prev_track (uint32_t initial_id)
104 // STRIPABLE route_table[0] = _session->get_nth_stripable (--initial_id, RemoteControlID::Route);
108 ControlProtocol::set_route_table_size (uint32_t size)
110 while (route_table.size() < size) {
111 route_table.push_back (boost::shared_ptr<Route> ((Route*) 0));
116 ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR::Route> r)
118 if (table_index >= route_table.size()) {
122 route_table[table_index] = r;
124 // XXX SHAREDPTR need to handle r->GoingAway
128 ControlProtocol::set_route_table (uint32_t table_index, uint32_t remote_control_id)
131 boost::shared_ptr<Route> r = session->route_by_remote_id (remote_control_id);
137 set_route_table (table_index, r);
143 ControlProtocol::route_set_rec_enable (uint32_t table_index, bool yn)
145 if (table_index > route_table.size()) {
149 boost::shared_ptr<Route> r = route_table[table_index];
151 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
154 at->rec_enable_control()->set_value (1.0, Controllable::UseGroup);
159 ControlProtocol::route_get_rec_enable (uint32_t table_index)
161 if (table_index > route_table.size()) {
165 boost::shared_ptr<Route> r = route_table[table_index];
167 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
170 return at->rec_enable_control()->get_value();
178 ControlProtocol::route_get_gain (uint32_t table_index)
180 if (table_index > route_table.size()) {
184 boost::shared_ptr<Route> r = route_table[table_index];
190 return r->gain_control()->get_value();
194 ControlProtocol::route_set_gain (uint32_t table_index, float gain)
196 if (table_index > route_table.size()) {
200 boost::shared_ptr<Route> r = route_table[table_index];
203 r->gain_control()->set_value (gain, Controllable::UseGroup);
208 ControlProtocol::route_get_effective_gain (uint32_t table_index)
210 if (table_index > route_table.size()) {
214 boost::shared_ptr<Route> r = route_table[table_index];
220 return r->amp()->gain_control()->get_value();
225 ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t which_input)
227 if (table_index > route_table.size()) {
231 boost::shared_ptr<Route> r = route_table[table_index];
237 return r->peak_meter()->meter_level (which_input, MeterPeak);
241 ControlProtocol::route_get_muted (uint32_t table_index)
243 if (table_index > route_table.size()) {
247 boost::shared_ptr<Route> r = route_table[table_index];
253 return r->mute_control()->muted ();
257 ControlProtocol::route_set_muted (uint32_t table_index, bool yn)
259 if (table_index > route_table.size()) {
263 boost::shared_ptr<Route> r = route_table[table_index];
266 r->mute_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup);
272 ControlProtocol::route_get_soloed (uint32_t table_index)
274 if (table_index > route_table.size()) {
278 boost::shared_ptr<Route> r = route_table[table_index];
288 ControlProtocol::route_set_soloed (uint32_t table_index, bool yn)
290 if (table_index > route_table.size()) {
294 boost::shared_ptr<Route> r = route_table[table_index];
297 r->solo_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup);
302 ControlProtocol:: route_get_name (uint32_t table_index)
304 if (table_index > route_table.size()) {
308 boost::shared_ptr<Route> r = route_table[table_index];
317 list<boost::shared_ptr<Bundle> >
318 ControlProtocol::bundles ()
320 return list<boost::shared_ptr<Bundle> > ();
324 ControlProtocol::get_state ()
326 XMLNode* node = new XMLNode (state_node_name);
328 node->add_property ("name", _name);
329 node->add_property ("feedback", get_feedback() ? "yes" : "no");
335 ControlProtocol::set_state (XMLNode const & node, int /* version */)
337 const XMLProperty* prop;
339 if ((prop = node.property ("feedback")) != 0) {
340 set_feedback (string_is_affirmative (prop->value()));
346 boost::shared_ptr<Stripable>
347 ControlProtocol::first_selected_stripable ()
349 Glib::Threads::Mutex::Lock lm (first_selected_mutex);
350 return _first_selected_stripable.lock();
354 ControlProtocol::set_first_selected_stripable (boost::shared_ptr<Stripable> s)
356 Glib::Threads::Mutex::Lock lm (first_selected_mutex);
357 _first_selected_stripable = s;
361 ControlProtocol::stripable_selection_changed (StripableNotificationListPtr sp)
363 bool had_selection = !_last_selected.empty();
365 _last_selected = *sp;
368 Glib::Threads::Mutex::Lock lm (first_selected_mutex);
370 if (!_last_selected.empty()) {
371 if (!had_selection) {
372 _first_selected_stripable = _last_selected.front().lock();
375 _first_selected_stripable = boost::weak_ptr<Stripable>();