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/convert.h"
22 #include "pbd/error.h"
24 #include "ardour/gain_control.h"
25 #include "ardour/session.h"
26 #include "ardour/record_enable_control.h"
27 #include "ardour/route.h"
28 #include "ardour/audio_track.h"
29 #include "ardour/meter.h"
30 #include "ardour/amp.h"
31 #include "control_protocol/control_protocol.h"
33 using namespace ARDOUR;
37 Signal0<void> ControlProtocol::ZoomToSession;
38 Signal0<void> ControlProtocol::ZoomOut;
39 Signal0<void> ControlProtocol::ZoomIn;
40 Signal0<void> ControlProtocol::Enter;
41 Signal0<void> ControlProtocol::Undo;
42 Signal0<void> ControlProtocol::Redo;
43 Signal1<void,float> ControlProtocol::ScrollTimeline;
44 Signal1<void,uint32_t> ControlProtocol::GotoView;
45 Signal0<void> ControlProtocol::CloseDialog;
46 PBD::Signal0<void> ControlProtocol::VerticalZoomInAll;
47 PBD::Signal0<void> ControlProtocol::VerticalZoomOutAll;
48 PBD::Signal0<void> ControlProtocol::VerticalZoomInSelected;
49 PBD::Signal0<void> ControlProtocol::VerticalZoomOutSelected;
50 PBD::Signal0<void> ControlProtocol::StepTracksDown;
51 PBD::Signal0<void> ControlProtocol::StepTracksUp;
53 PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::AddStripableToSelection;
54 PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::SetStripableSelection;
55 PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::ToggleStripableSelection;
56 PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::RemoveStripableFromSelection;
57 PBD::Signal0<void> ControlProtocol::ClearStripableSelection;
59 Glib::Threads::Mutex ControlProtocol::special_stripable_mutex;
60 boost::weak_ptr<Stripable> ControlProtocol::_first_selected_stripable;
61 boost::weak_ptr<Stripable> ControlProtocol::_leftmost_mixer_stripable;
62 StripableNotificationList ControlProtocol::_last_selected;
64 const std::string ControlProtocol::state_node_name ("Protocol");
66 ControlProtocol::ControlProtocol (Session& s, string str)
73 ControlProtocol::~ControlProtocol ()
78 ControlProtocol::set_active (bool yn)
85 ControlProtocol::next_track (uint32_t initial_id)
87 // STRIPABLE route_table[0] = _session->get_nth_stripable (++initial_id, RemoteControlID::Route);
91 ControlProtocol::prev_track (uint32_t initial_id)
96 // STRIPABLE route_table[0] = _session->get_nth_stripable (--initial_id, RemoteControlID::Route);
100 ControlProtocol::set_route_table_size (uint32_t size)
102 while (route_table.size() < size) {
103 route_table.push_back (boost::shared_ptr<Route> ((Route*) 0));
108 ControlProtocol::set_route_table (uint32_t table_index, boost::shared_ptr<ARDOUR::Route> r)
110 if (table_index >= route_table.size()) {
114 route_table[table_index] = r;
116 // XXX SHAREDPTR need to handle r->GoingAway
120 ControlProtocol::set_route_table (uint32_t table_index, uint32_t remote_control_id)
123 boost::shared_ptr<Route> r = session->route_by_remote_id (remote_control_id);
129 set_route_table (table_index, r);
135 ControlProtocol::route_set_rec_enable (uint32_t table_index, bool yn)
137 if (table_index > route_table.size()) {
141 boost::shared_ptr<Route> r = route_table[table_index];
143 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
146 at->rec_enable_control()->set_value (1.0, Controllable::UseGroup);
151 ControlProtocol::route_get_rec_enable (uint32_t table_index)
153 if (table_index > route_table.size()) {
157 boost::shared_ptr<Route> r = route_table[table_index];
159 boost::shared_ptr<AudioTrack> at = boost::dynamic_pointer_cast<AudioTrack>(r);
162 return at->rec_enable_control()->get_value();
170 ControlProtocol::route_get_gain (uint32_t table_index)
172 if (table_index > route_table.size()) {
176 boost::shared_ptr<Route> r = route_table[table_index];
182 return r->gain_control()->get_value();
186 ControlProtocol::route_set_gain (uint32_t table_index, float gain)
188 if (table_index > route_table.size()) {
192 boost::shared_ptr<Route> r = route_table[table_index];
195 r->gain_control()->set_value (gain, Controllable::UseGroup);
200 ControlProtocol::route_get_effective_gain (uint32_t table_index)
202 if (table_index > route_table.size()) {
206 boost::shared_ptr<Route> r = route_table[table_index];
212 return r->amp()->gain_control()->get_value();
217 ControlProtocol::route_get_peak_input_power (uint32_t table_index, uint32_t which_input)
219 if (table_index > route_table.size()) {
223 boost::shared_ptr<Route> r = route_table[table_index];
229 return r->peak_meter()->meter_level (which_input, MeterPeak);
233 ControlProtocol::route_get_muted (uint32_t table_index)
235 if (table_index > route_table.size()) {
239 boost::shared_ptr<Route> r = route_table[table_index];
245 return r->mute_control()->muted ();
249 ControlProtocol::route_set_muted (uint32_t table_index, bool yn)
251 if (table_index > route_table.size()) {
255 boost::shared_ptr<Route> r = route_table[table_index];
258 r->mute_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup);
264 ControlProtocol::route_get_soloed (uint32_t table_index)
266 if (table_index > route_table.size()) {
270 boost::shared_ptr<Route> r = route_table[table_index];
280 ControlProtocol::route_set_soloed (uint32_t table_index, bool yn)
282 if (table_index > route_table.size()) {
286 boost::shared_ptr<Route> r = route_table[table_index];
289 r->solo_control()->set_value (yn ? 1.0 : 0.0, Controllable::UseGroup); // XXX does not propagate
290 //_session->set_control (r->solo_control(), yn ? 1.0 : 0.0, Controllable::UseGroup); // << correct way, needs a session ptr
295 ControlProtocol:: route_get_name (uint32_t table_index)
297 if (table_index > route_table.size()) {
301 boost::shared_ptr<Route> r = route_table[table_index];
310 list<boost::shared_ptr<Bundle> >
311 ControlProtocol::bundles ()
313 return list<boost::shared_ptr<Bundle> > ();
317 ControlProtocol::get_state ()
319 XMLNode* node = new XMLNode (state_node_name);
321 node->set_property ("name", _name);
322 node->set_property ("feedback", get_feedback());
328 ControlProtocol::set_state (XMLNode const & node, int /* version */)
331 if (node.get_property ("feedback", feedback)) {
332 set_feedback (feedback);
338 boost::shared_ptr<Stripable>
339 ControlProtocol::first_selected_stripable ()
341 Glib::Threads::Mutex::Lock lm (special_stripable_mutex);
342 return _first_selected_stripable.lock();
345 boost::shared_ptr<Stripable>
346 ControlProtocol::leftmost_mixer_stripable ()
348 Glib::Threads::Mutex::Lock lm (special_stripable_mutex);
349 return _leftmost_mixer_stripable.lock();
353 ControlProtocol::set_leftmost_mixer_stripable (boost::shared_ptr<Stripable> s)
355 Glib::Threads::Mutex::Lock lm (special_stripable_mutex);
356 _leftmost_mixer_stripable = s;
360 ControlProtocol::set_first_selected_stripable (boost::shared_ptr<Stripable> s)
362 Glib::Threads::Mutex::Lock lm (special_stripable_mutex);
363 _first_selected_stripable = s;
367 ControlProtocol::notify_stripable_selection_changed (StripableNotificationListPtr sp)
369 bool had_selection = !_last_selected.empty();
371 _last_selected = *sp;
374 Glib::Threads::Mutex::Lock lm (special_stripable_mutex);
376 if (!_last_selected.empty()) {
377 if (!had_selection) {
378 _first_selected_stripable = _last_selected.front().lock();
381 _first_selected_stripable = boost::weak_ptr<Stripable>();