2 Copyright (C) 2006,2007 John Anderson
3 Copyright (C) 2012 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your 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.
33 #include <boost/shared_array.hpp>
34 #include <glibmm/miscutils.h>
36 #include "midi++/types.h"
37 #include "midi++/port.h"
38 #include "midi++/ipmidi_port.h"
39 #include "pbd/pthread_utils.h"
40 #include "pbd/error.h"
41 #include "pbd/memento_command.h"
42 #include "pbd/convert.h"
44 #include "ardour/audio_track.h"
45 #include "ardour/automation_control.h"
46 #include "ardour/async_midi_port.h"
47 #include "ardour/dB.h"
48 #include "ardour/debug.h"
49 #include "ardour/location.h"
50 #include "ardour/meter.h"
51 #include "ardour/midi_track.h"
52 #include "ardour/panner.h"
53 #include "ardour/panner_shell.h"
54 #include "ardour/profile.h"
55 #include "ardour/record_enable_control.h"
56 #include "ardour/route.h"
57 #include "ardour/route_group.h"
58 #include "ardour/session.h"
59 #include "ardour/tempo.h"
60 #include "ardour/track.h"
61 #include "ardour/types.h"
62 #include "ardour/audioengine.h"
63 #include "ardour/vca_manager.h"
65 #include "mackie_control_protocol.h"
67 #include "midi_byte_array.h"
68 #include "mackie_control_exception.h"
69 #include "device_profile.h"
70 #include "surface_port.h"
73 #include "control_group.h"
79 using namespace ARDOUR;
83 using namespace ArdourSurface;
84 using namespace Mackie;
88 #include "pbd/abstract_ui.cc" // instantiate template
90 const int MackieControlProtocol::MODIFIER_OPTION = 0x1;
91 const int MackieControlProtocol::MODIFIER_CONTROL = 0x2;
92 const int MackieControlProtocol::MODIFIER_SHIFT = 0x4;
93 const int MackieControlProtocol::MODIFIER_CMDALT = 0x8;
94 const int MackieControlProtocol::MODIFIER_ZOOM = 0x10;
95 const int MackieControlProtocol::MODIFIER_SCRUB = 0x20;
96 const int MackieControlProtocol::MODIFIER_MARKER = 0x40;
97 const int MackieControlProtocol::MODIFIER_NUDGE = 0x80;
98 const int MackieControlProtocol::MAIN_MODIFIER_MASK = (MackieControlProtocol::MODIFIER_OPTION|
99 MackieControlProtocol::MODIFIER_CONTROL|
100 MackieControlProtocol::MODIFIER_SHIFT|
101 MackieControlProtocol::MODIFIER_CMDALT);
103 MackieControlProtocol* MackieControlProtocol::_instance = 0;
105 bool MackieControlProtocol::probe()
110 MackieControlProtocol::MackieControlProtocol (Session& session)
111 : ControlProtocol (session, X_("Mackie"))
112 , AbstractUI<MackieControlUIRequest> (name())
113 , _current_initial_bank (0)
115 , _timecode_type (ARDOUR::AnyTime::BBT)
117 , _scrub_mode (false)
118 , _flip_mode (Normal)
120 , _subview_mode (None)
121 , _current_selected_track (-1)
122 , _modifier_state (0)
123 , _ipmidi_base (MIDI::IPMIDIPort::lowest_ipmidi_port_default)
124 , needs_ipmidi_restart (false)
125 , _metering_active (true)
126 , _initialized (false)
127 , configuration_state (0)
129 , marker_modifier_consumed_by_button (false)
130 , nudge_modifier_consumed_by_button (false)
132 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::MackieControlProtocol\n");
134 DeviceInfo::reload_device_info ();
135 DeviceProfile::reload_device_profiles ();
137 for (int i = 0; i < 9; i++) {
141 PresentationInfo::Change.connect (gui_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_presentation_info_changed, this), this);
148 MackieControlProtocol::~MackieControlProtocol()
150 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol init\n");
152 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
156 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol drop_connections ()\n");
159 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol tear_down_gui ()\n");
162 delete configuration_state;
164 /* stop event loop */
165 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol BaseUI::quit ()\n");
169 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol close()\n");
172 catch (exception & e) {
173 cout << "~MackieControlProtocol caught " << e.what() << endl;
176 cout << "~MackieControlProtocol caught unknown" << endl;
181 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::~MackieControlProtocol done\n");
185 MackieControlProtocol::thread_init ()
187 struct sched_param rtparam;
189 pthread_set_name (event_loop_name().c_str());
191 PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
192 ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
194 memset (&rtparam, 0, sizeof (rtparam));
195 rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
197 if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
198 // do we care? not particularly.
203 MackieControlProtocol::ping_devices ()
205 /* should not be called if surfaces are not connected, but will not
206 * malfunction if it is.
209 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
214 // go to the previous track.
216 MackieControlProtocol::prev_track()
218 if (_current_initial_bank >= 1) {
219 switch_banks (_current_initial_bank - 1);
223 // go to the next track.
225 MackieControlProtocol::next_track()
227 Sorted sorted = get_sorted_stripables();
228 if (_current_initial_bank + n_strips() < sorted.size()) {
229 switch_banks (_current_initial_bank + 1);
234 MackieControlProtocol::stripable_is_locked_to_strip (boost::shared_ptr<Stripable> r) const
236 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
237 if ((*si)->stripable_is_locked_to_strip (r)) {
244 // predicate for sort call in get_sorted_stripables
245 struct StripableByPresentationOrder
247 bool operator () (const boost::shared_ptr<Stripable> & a, const boost::shared_ptr<Stripable> & b) const
249 return a->presentation_info().order() < b->presentation_info().order();
252 bool operator () (const Stripable & a, const Stripable & b) const
254 return a.presentation_info().order() < b.presentation_info().order();
257 bool operator () (const Stripable * a, const Stripable * b) const
259 return a->presentation_info().order() < b->presentation_info().order();
263 MackieControlProtocol::Sorted
264 MackieControlProtocol::get_sorted_stripables()
268 // fetch all stripables
269 StripableList stripables;
271 session->get_stripables (stripables);
273 // sort in presentation order, and exclude master, control and hidden stripables
274 // and any stripables that are already set.
276 for (StripableList::iterator it = stripables.begin(); it != stripables.end(); ++it) {
278 boost::shared_ptr<Stripable> s = *it;
280 if (s->presentation_info().special()) {
284 /* don't include locked routes */
286 if (stripable_is_locked_to_strip (s)) {
290 switch (_view_mode) {
292 if (!is_hidden (s)) {
293 sorted.push_back (s);
297 if (is_audio_track(s) && !is_hidden(s)) {
298 sorted.push_back (s);
302 if (Profile->get_mixbus()) {
305 sorted.push_back (s);
309 if (!is_track(s) && !is_hidden(s)) {
310 sorted.push_back (s);
315 if (is_midi_track(s) && !is_hidden(s)) {
316 sorted.push_back (s);
321 case Auxes: // in ardour, for now aux and buss are same. for mixbus, "Busses" are mixbuses, "Auxes" are ardour buses
323 if (!s->mixbus() && !is_track() && !is_hidden(s))
325 if (!is_track(s) && !is_hidden(s))
328 sorted.push_back (s);
331 case Hidden: // Show all the tracks we have hidden
333 // maybe separate groups
334 sorted.push_back (s);
337 case Selected: // For example: a group (this is USER)
338 if (selected(s) && !is_hidden(s)) {
339 sorted.push_back (s);
345 sort (sorted.begin(), sorted.end(), StripableByPresentationOrder());
350 MackieControlProtocol::refresh_current_bank()
352 switch_banks (_current_initial_bank, true);
356 MackieControlProtocol::n_strips (bool with_locked_strips) const
358 uint32_t strip_count = 0;
360 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
361 strip_count += (*si)->n_strips (with_locked_strips);
368 MackieControlProtocol::switch_banks (uint32_t initial, bool force)
370 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch banking to start at %1 force ? %2 current = %3\n", initial, force, _current_initial_bank));
372 if (initial == _current_initial_bank && !force) {
373 /* everything is as it should be */
377 Sorted sorted = get_sorted_stripables();
378 uint32_t strip_cnt = n_strips (false); // do not include locked strips
381 if (initial >= sorted.size() && !force) {
382 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("bank target %1 exceeds route range %2\n",
383 _current_initial_bank, sorted.size()));
384 /* too high, we can't get there */
388 if (sorted.size() <= strip_cnt && _current_initial_bank == 0 && !force) {
389 /* no banking - not enough stripables to fill all strips and we're
390 * not at the first one.
392 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("less routes (%1) than strips (%2) and we're at the end already (%3)\n",
393 sorted.size(), strip_cnt, _current_initial_bank));
397 _current_initial_bank = initial;
398 _current_selected_track = -1;
400 // Map current bank of stripables onto each surface(+strip)
402 if (_current_initial_bank < sorted.size()) {
404 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch to %1, %2, available stripables %3 on %4 surfaces\n",
405 _current_initial_bank, strip_cnt, sorted.size(),
408 // link stripables to strips
410 Sorted::iterator r = sorted.begin() + _current_initial_bank;
412 for (Surfaces::iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
413 vector<boost::shared_ptr<Stripable> > stripables;
416 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface has %1 unlocked strips\n", (*si)->n_strips (false)));
418 for (; r != sorted.end() && added < (*si)->n_strips (false); ++r, ++added) {
419 stripables.push_back (*r);
422 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("give surface %1 stripables\n", stripables.size()));
424 (*si)->map_stripables (stripables);
428 /* all strips need to be reset */
429 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("clear all strips, bank target %1 is outside route range %2\n",
430 _current_initial_bank, sorted.size()));
431 for (Surfaces::iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
432 vector<boost::shared_ptr<Stripable> > stripables;
433 /* pass in an empty stripables list, so that all strips will be reset */
434 (*si)->map_stripables (stripables);
439 /* current bank has not been saved */
440 session->set_dirty();
446 MackieControlProtocol::set_active (bool yn)
448 DEBUG_TRACE (DEBUG::MackieControl, string_compose("MackieControlProtocol::set_active init with yn: '%1'\n", yn));
450 if (yn == active()) {
456 /* start event loop */
460 connect_session_signals ();
462 if (!_device_info.name().empty()) {
463 set_device (_device_info.name(), true);
466 /* set up periodic task for timecode display and metering and automation
469 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (100); // milliseconds
470 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::periodic));
471 periodic_timeout->attach (main_loop()->get_context());
473 /* periodic task used to update strip displays */
475 Glib::RefPtr<Glib::TimeoutSource> redisplay_timeout = Glib::TimeoutSource::create (10); // milliseconds
476 redisplay_connection = redisplay_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::redisplay));
477 redisplay_timeout->attach (main_loop()->get_context());
486 ControlProtocol::set_active (yn);
488 DEBUG_TRACE (DEBUG::MackieControl, string_compose("MackieControlProtocol::set_active done with yn: '%1'\n", yn));
494 MackieControlProtocol::hui_heartbeat ()
496 Glib::Threads::Mutex::Lock lm (surfaces_lock);
498 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
499 (*s)->hui_heartbeat ();
506 MackieControlProtocol::periodic ()
513 /* wait for higher-frequency redisplay() callback to initialize
519 update_timecode_display ();
521 ARDOUR::microseconds_t now_usecs = ARDOUR::get_microseconds ();
524 Glib::Threads::Mutex::Lock lm (surfaces_lock);
526 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
527 (*s)->periodic (now_usecs);
535 MackieControlProtocol::redisplay ()
541 if (needs_ipmidi_restart) {
550 ARDOUR::microseconds_t now = ARDOUR::get_microseconds ();
553 Glib::Threads::Mutex::Lock lm (surfaces_lock);
555 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
556 (*s)->redisplay (now, false);
564 MackieControlProtocol::update_timecode_beats_led()
566 if (!_device_info.has_timecode_display()) {
570 DEBUG_TRACE (DEBUG::MackieControl, string_compose("MackieControlProtocol::update_timecode_beats_led(): %1\n", _timecode_type));
571 switch (_timecode_type) {
572 case ARDOUR::AnyTime::BBT:
573 update_global_led (Led::Beats, on);
574 update_global_led (Led::Timecode, off);
576 case ARDOUR::AnyTime::Timecode:
577 update_global_led (Led::Timecode, on);
578 update_global_led (Led::Beats, off);
582 os << "Unknown Anytime::Type " << _timecode_type;
583 throw runtime_error (os.str());
588 MackieControlProtocol::update_global_button (int id, LedState ls)
590 boost::shared_ptr<Surface> surface;
593 Glib::Threads::Mutex::Lock lm (surfaces_lock);
595 if (surfaces.empty()) {
599 if (!_device_info.has_global_controls()) {
602 // surface needs to be master surface
603 surface = _master_surface;
606 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (id);
607 if (x != surface->controls_by_device_independent_id.end()) {
608 Button * button = dynamic_cast<Button*> (x->second);
609 surface->write (button->set_state (ls));
611 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Button %1 not found\n", id));
616 MackieControlProtocol::update_global_led (int id, LedState ls)
618 Glib::Threads::Mutex::Lock lm (surfaces_lock);
620 if (surfaces.empty()) {
624 if (!_device_info.has_global_controls()) {
627 boost::shared_ptr<Surface> surface = _master_surface;
629 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (id);
631 if (x != surface->controls_by_device_independent_id.end()) {
632 Led * led = dynamic_cast<Led*> (x->second);
633 DEBUG_TRACE (DEBUG::MackieControl, "Writing LedState\n");
634 surface->write (led->set_state (ls));
636 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Led %1 not found\n", id));
641 MackieControlProtocol::device_ready ()
643 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("device ready init (active=%1)\n", active()));
645 set_subview_mode (MackieControlProtocol::None, boost::shared_ptr<Stripable>());
646 set_flip_mode (Normal);
649 // send messages to surface to set controls to correct values
651 MackieControlProtocol::update_surfaces()
653 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::update_surfaces() init (active=%1)\n", active()));
658 // do the initial bank switch to connect signals
659 // _current_initial_bank is initialised by set_state
660 (void) switch_banks (_current_initial_bank, true);
662 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::update_surfaces() finished\n");
666 MackieControlProtocol::initialize()
669 Glib::Threads::Mutex::Lock lm (surfaces_lock);
671 if (surfaces.empty()) {
675 if (!_master_surface->active ()) {
679 // sometimes the jog wheel is a pot
680 if (_device_info.has_jog_wheel()) {
681 _master_surface->blank_jog_ring ();
685 // update global buttons and displays
687 notify_record_state_changed();
688 notify_transport_state_changed();
689 update_timecode_beats_led();
695 MackieControlProtocol::connect_session_signals()
697 // receive routes added
698 session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_routes_added, this, _1), this);
699 // receive VCAs added
700 session->vca_manager().VCAAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_vca_added, this, _1), this);
702 // receive record state toggled
703 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_record_state_changed, this), this);
704 // receive transport state changed
705 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_transport_state_changed, this), this);
706 session->TransportLooped.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_loop_state_changed, this), this);
707 // receive punch-in and punch-out
708 Config->ParameterChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_parameter_changed, this, _1), this);
709 session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_parameter_changed, this, _1), this);
710 // receive rude solo changed
711 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_solo_active_changed, this, _1), this);
713 // make sure remote id changed signals reach here
714 // see also notify_stripable_added
715 Sorted sorted = get_sorted_stripables();
719 MackieControlProtocol::set_profile (const string& profile_name)
721 map<string,DeviceProfile>::iterator d = DeviceProfile::device_profiles.find (profile_name);
723 if (d == DeviceProfile::device_profiles.end()) {
724 _device_profile = DeviceProfile (profile_name);
728 _device_profile = d->second;
732 MackieControlProtocol::set_device_info (const string& device_name)
734 map<string,DeviceInfo>::iterator d = DeviceInfo::device_info.find (device_name);
736 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("new device chosen %1\n", device_name));
738 if (d == DeviceInfo::device_info.end()) {
742 _device_info = d->second;
748 MackieControlProtocol::set_device (const string& device_name, bool force)
750 if (device_name == device_info().name() && !force) {
751 /* already using that device, nothing to do */
754 /* get state from the current setup, and make sure it is stored in
755 the configuration_states node so that if we switch back to this device,
756 we will have its state available.
760 Glib::Threads::Mutex::Lock lm (surfaces_lock);
761 if (!surfaces.empty()) {
762 update_configuration_state ();
766 if (set_device_info (device_name)) {
771 port_connection.disconnect ();
772 hui_connection.disconnect ();
774 if (_device_info.device_type() == DeviceInfo::HUI) {
775 Glib::RefPtr<Glib::TimeoutSource> hui_timeout = Glib::TimeoutSource::create (1000); // milliseconds
776 hui_connection = hui_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::hui_heartbeat));
777 hui_timeout->attach (main_loop()->get_context());
780 if (!_device_info.uses_ipmidi()) {
781 /* notice that the handler for this will execute in our event
782 loop, not in the thread where the
783 PortConnectedOrDisconnected signal is emitted.
785 ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connection, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::connection_handler, this, _1, _2, _3, _4, _5), this);
788 if (create_surfaces ()) {
798 ArdourSurface::ipmidi_input_handler (GIOChannel*, GIOCondition condition, void *data)
800 ArdourSurface::MackieControlProtocol::ipMIDIHandler* ipm = static_cast<ArdourSurface::MackieControlProtocol::ipMIDIHandler*>(data);
801 return ipm->mcp->midi_input_handler (Glib::IOCondition (condition), ipm->port);
805 MackieControlProtocol::create_surfaces ()
808 surface_type_t stype = mcu; // type not yet determined
810 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Create %1 surfaces for %2\n", 1 + _device_info.extenders(), _device_info.name()));
812 if (!_device_info.uses_ipmidi()) {
813 _input_bundle.reset (new ARDOUR::Bundle (_("Mackie Control In"), true));
814 _output_bundle.reset (new ARDOUR::Bundle (_("Mackie Control Out"), false));
816 _input_bundle.reset ();
817 _output_bundle.reset ();
820 for (uint32_t n = 0; n < 1 + _device_info.extenders(); ++n) {
821 bool is_master = false;
823 if (n == _device_info.master_position()) {
825 if (_device_info.extenders() == 0) {
826 device_name = _device_info.name();
828 device_name = X_("mackie control");
834 device_name = string_compose (X_("mackie control ext %1"), n+1);
837 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Port Name for surface %1 is %2\n", n, device_name));
839 boost::shared_ptr<Surface> surface;
847 surface.reset (new Surface (*this, device_name, n, stype));
853 _master_surface = surface;
856 if (configuration_state) {
857 XMLNode* this_device = 0;
858 XMLNodeList const& devices = configuration_state->children();
859 for (XMLNodeList::const_iterator d = devices.begin(); d != devices.end(); ++d) {
860 XMLProperty const * prop = (*d)->property (X_("name"));
861 if (prop && prop->value() == _device_info.name()) {
867 XMLNode* snode = this_device->child (X_("Surfaces"));
869 surface->set_state (*snode, state_version);
875 Glib::Threads::Mutex::Lock lm (surfaces_lock);
876 surfaces.push_back (surface);
879 if (!_device_info.uses_ipmidi()) {
881 _input_bundle->add_channel (
882 surface->port().input_port().name(),
883 ARDOUR::DataType::MIDI,
884 session->engine().make_port_name_non_relative (surface->port().input_port().name())
887 _output_bundle->add_channel (
888 surface->port().output_port().name(),
889 ARDOUR::DataType::MIDI,
890 session->engine().make_port_name_non_relative (surface->port().output_port().name())
894 MIDI::Port& input_port (surface->port().input_port());
895 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*> (&input_port);
899 /* async MIDI port */
901 asp->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &MackieControlProtocol::midi_input_handler), &input_port));
902 asp->xthread().attach (main_loop()->get_context());
906 /* ipMIDI port, no IOSource method at this time */
910 if ((fd = input_port.selectable ()) >= 0) {
912 GIOChannel* ioc = g_io_channel_unix_new (fd);
913 surface->input_source = g_io_create_watch (ioc, GIOCondition (G_IO_IN|G_IO_HUP|G_IO_ERR));
915 /* make surface's input source now hold the
916 * only reference on the IO channel
918 g_io_channel_unref (ioc);
920 /* hack up an object so that in the callback from the event loop
921 we have both the MackieControlProtocol and the input port.
923 If we were using C++ for this stuff we wouldn't need this
924 but a nasty, not-fixable bug in the binding between C
925 and C++ makes it necessary to avoid C++ for the IO
929 ipMIDIHandler* ipm = new ipMIDIHandler (); /* we will leak this sizeof(pointer)*2 sized object */
931 ipm->port = &input_port;
933 g_source_set_callback (surface->input_source, (GSourceFunc) ipmidi_input_handler, ipm, NULL);
934 g_source_attach (surface->input_source, main_loop()->get_context()->gobj());
939 if (!_device_info.uses_ipmidi()) {
940 Glib::Threads::Mutex::Lock lm (surfaces_lock);
941 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
942 (*s)->port().reconnect ();
946 session->BundleAddedOrRemoved ();
948 assert (_master_surface);
954 MackieControlProtocol::close()
956 port_connection.disconnect ();
957 session_connections.drop_connections ();
958 stripable_connections.drop_connections ();
959 periodic_connection.disconnect ();
964 /** Ensure that the configuration_state XML node contains an up-to-date
965 * copy of the state node the current device. If configuration_state already
966 * contains a state node for the device, it will deleted and replaced.
969 MackieControlProtocol::update_configuration_state ()
971 /* CALLER MUST HOLD SURFACES LOCK */
973 if (!configuration_state) {
974 configuration_state = new XMLNode (X_("Configurations"));
977 XMLNode* devnode = new XMLNode (X_("Configuration"));
978 devnode->add_property (X_("name"), _device_info.name());
980 configuration_state->remove_nodes_and_delete (X_("name"), _device_info.name());
981 configuration_state->add_child_nocopy (*devnode);
983 XMLNode* snode = new XMLNode (X_("Surfaces"));
985 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
986 snode->add_child_nocopy ((*s)->get_state());
989 devnode->add_child_nocopy (*snode);
993 MackieControlProtocol::get_state()
995 XMLNode& node (ControlProtocol::get_state());
997 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::get_state init\n");
1001 snprintf (buf, sizeof (buf), "%d", _current_initial_bank);
1002 node.add_property (X_("bank"), buf);
1004 // ipMIDI base port (possibly not used)
1005 snprintf (buf, sizeof (buf), "%d", _ipmidi_base);
1006 node.add_property (X_("ipmidi-base"), buf);
1008 node.add_property (X_("device-profile"), _device_profile.name());
1009 node.add_property (X_("device-name"), _device_info.name());
1012 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1013 update_configuration_state ();
1016 /* force a copy of the _surfaces_state node, because we want to retain ownership */
1017 node.add_child_copy (*configuration_state);
1019 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::get_state done\n");
1025 MackieControlProtocol::profile_exists (string const & name) const
1027 return DeviceProfile::device_profiles.find (name) != DeviceProfile::device_profiles.end();
1031 MackieControlProtocol::set_state (const XMLNode & node, int version)
1033 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("MackieControlProtocol::set_state: active %1\n", active()));
1036 const XMLProperty* prop;
1039 if (ControlProtocol::set_state (node, version)) {
1043 if ((prop = node.property (X_("ipmidi-base"))) != 0) {
1044 set_ipmidi_base (atoi (prop->value()));
1047 // fetch current bank
1048 if ((prop = node.property (X_("bank"))) != 0) {
1049 bank = atoi (prop->value());
1052 if ((prop = node.property (X_("device-name"))) != 0) {
1053 set_device_info (prop->value());
1056 if ((prop = node.property (X_("device-profile"))) != 0) {
1057 if (prop->value().empty()) {
1058 string default_profile_name;
1060 /* start by looking for a user-edited profile for the current device name */
1062 default_profile_name = DeviceProfile::name_when_edited (_device_info.name());
1064 if (!profile_exists (default_profile_name)) {
1066 /* no user-edited profile for this device name, so try the user-edited default profile */
1068 default_profile_name = DeviceProfile::name_when_edited (DeviceProfile::default_profile_name);
1070 if (!profile_exists (default_profile_name)) {
1072 /* no user-edited version, so just try the device name */
1074 default_profile_name = _device_info.name();
1076 if (!profile_exists (default_profile_name)) {
1078 /* no generic device specific profile, just try the fixed default */
1079 default_profile_name = DeviceProfile::default_profile_name;
1084 set_profile (default_profile_name);
1087 if (profile_exists (prop->value())) {
1088 set_profile (prop->value());
1090 set_profile (DeviceProfile::default_profile_name);
1095 XMLNode* dnode = node.child (X_("Configurations"));
1097 delete configuration_state;
1098 configuration_state = 0;
1101 configuration_state = new XMLNode (*dnode);
1102 state_version = version;
1105 (void) switch_banks (bank, true);
1107 DEBUG_TRACE (DEBUG::MackieControl, "MackieControlProtocol::set_state done\n");
1113 MackieControlProtocol::format_bbt_timecode (framepos_t now_frame)
1115 Timecode::BBT_Time bbt_time;
1117 session->bbt_time (now_frame, bbt_time);
1119 // The Mackie protocol spec is built around a BBT time display of
1121 // digits: 888/88/88/888
1122 // semantics: BBB/bb/ss/ttt
1124 // The third field is "subdivisions" which is a concept found in Logic
1125 // but not present in Ardour. Instead Ardour displays a 4 digit tick
1126 // count, which we need to spread across the 5 digits of ss/ttt.
1130 os << setw(3) << setfill('0') << bbt_time.bars;
1131 os << setw(2) << setfill('0') << bbt_time.beats;
1133 os << setw(1) << setfill('0') << bbt_time.ticks / 1000;
1134 os << setw(3) << setfill('0') << bbt_time.ticks % 1000;
1140 MackieControlProtocol::format_timecode_timecode (framepos_t now_frame)
1142 Timecode::Time timecode;
1143 session->timecode_time (now_frame, timecode);
1145 // According to the Logic docs
1146 // digits: 888/88/88/888
1147 // Timecode mode: Hours/Minutes/Seconds/Frames
1149 os << setw(2) << setfill('0') << timecode.hours;
1151 os << setw(2) << setfill('0') << timecode.minutes;
1152 os << setw(2) << setfill('0') << timecode.seconds;
1154 os << setw(2) << setfill('0') << timecode.frames;
1160 MackieControlProtocol::update_timecode_display()
1162 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1164 if (surfaces.empty()) {
1168 boost::shared_ptr<Surface> surface = _master_surface;
1170 if (surface->type() != mcu || !_device_info.has_timecode_display() || !surface->active ()) {
1174 // do assignment here so current_frame is fixed
1175 framepos_t current_frame = session->transport_frame();
1177 // For large jumps in play head possition do full reset
1178 int moved = (current_frame - _frame_last) / session->frame_rate ();
1180 DEBUG_TRACE (DEBUG::MackieControl, "Timecode reset\n");
1181 _timecode_last = string (10, ' ');
1183 _frame_last = current_frame;
1185 switch (_timecode_type) {
1186 case ARDOUR::AnyTime::BBT:
1187 timecode = format_bbt_timecode (current_frame);
1189 case ARDOUR::AnyTime::Timecode:
1190 timecode = format_timecode_timecode (current_frame);
1196 // only write the timecode string to the MCU if it's changed
1197 // since last time. This is to reduce midi bandwidth used.
1198 if (timecode != _timecode_last) {
1199 surface->display_timecode (timecode, _timecode_last);
1200 _timecode_last = timecode;
1204 ///////////////////////////////////////////
1206 ///////////////////////////////////////////
1208 void MackieControlProtocol::notify_parameter_changed (std::string const & p)
1210 if (p == "punch-in") {
1211 update_global_button (Button::Drop, session->config.get_punch_in() ? flashing : off);
1212 } else if (p == "punch-out") {
1213 update_global_button (Button::Replace, session->config.get_punch_out() ? flashing : off);
1214 } else if (p == "clicking") {
1215 update_global_button (Button::Click, Config->get_clicking());
1216 } else if (p == "follow-edits") {
1217 /* we can't respond to this at present, because "follow-edits"
1218 * is a property of the (G)UI configuration object, to which we
1219 * have no access. For now, this means that the lit state of
1220 * this button (if there is one) won't reflect the setting.
1223 //update_global_button (Button::Enter, session->config.get_follow_edits() ? on : off);
1224 } else if (p == "external-sync") {
1225 update_global_button (Button::Cancel, session->config.get_external_sync() ? on : off);
1227 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("parameter changed: %1\n", p));
1232 MackieControlProtocol::notify_stripable_removed ()
1234 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1235 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1236 (*s)->master_monitor_may_have_changed ();
1241 MackieControlProtocol::notify_vca_added (ARDOUR::VCAList& vl)
1243 refresh_current_bank ();
1246 // RouteList is the set of Routes that have just been added
1248 MackieControlProtocol::notify_routes_added (ARDOUR::RouteList & rl)
1251 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1253 if (surfaces.empty()) {
1258 /* special case: single route, and it is the monitor or master out */
1260 if (rl.size() == 1 && (rl.front()->is_monitor() || rl.front()->is_master())) {
1261 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1262 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1263 (*s)->master_monitor_may_have_changed ();
1267 // currently assigned banks are less than the full set of
1268 // strips, so activate the new strip now.
1270 refresh_current_bank();
1272 // otherwise route added, but current bank needs no updating
1276 MackieControlProtocol::notify_solo_active_changed (bool active)
1278 boost::shared_ptr<Surface> surface;
1281 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1283 if (surfaces.empty()) {
1287 surface = _master_surface;
1290 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (Led::RudeSolo);
1291 if (x != surface->controls_by_device_independent_id.end()) {
1292 Led* rude_solo = dynamic_cast<Led*> (x->second);
1294 surface->write (rude_solo->set_state (active ? flashing : off));
1300 MackieControlProtocol::notify_presentation_info_changed ()
1303 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1305 if (surfaces.empty()) {
1310 Sorted sorted = get_sorted_stripables();
1311 uint32_t sz = n_strips();
1313 // if a remote id has been moved off the end, we need to shift
1314 // the current bank backwards.
1316 if (sorted.size() - _current_initial_bank < sz) {
1317 // but don't shift backwards past the zeroth channel
1318 if (sorted.size() < sz) { // avoid unsigned math mistake below
1319 (void) switch_banks(0, true);
1321 (void) switch_banks (max((Sorted::size_type) 0, sorted.size() - sz), true);
1324 // Otherwise just refresh the current bank
1325 refresh_current_bank();
1329 ///////////////////////////////////////////
1330 // Transport signals
1331 ///////////////////////////////////////////
1334 MackieControlProtocol::notify_loop_state_changed()
1336 update_global_button (Button::Loop, session->get_play_loop());
1340 MackieControlProtocol::notify_transport_state_changed()
1342 if (!_device_info.has_global_controls()) {
1346 // switch various play and stop buttons on / off
1347 update_global_button (Button::Loop, session->get_play_loop());
1348 update_global_button (Button::Play, session->transport_speed() == 1.0);
1349 update_global_button (Button::Stop, session->transport_stopped ());
1350 update_global_button (Button::Rewind, session->transport_speed() < 0.0);
1351 update_global_button (Button::Ffwd, session->transport_speed() > 1.0);
1353 // sometimes a return to start leaves time code at old time
1354 _timecode_last = string (10, ' ');
1356 notify_metering_state_changed ();
1360 MackieControlProtocol::notify_metering_state_changed()
1362 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1364 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1365 (*s)->notify_metering_state_changed ();
1370 MackieControlProtocol::notify_record_state_changed ()
1372 if (!_device_info.has_global_controls()) {
1376 boost::shared_ptr<Surface> surface;
1379 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1380 if (surfaces.empty()) {
1383 surface = _master_surface;
1386 /* rec is a tristate */
1388 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (Button::Record);
1389 if (x != surface->controls_by_device_independent_id.end()) {
1390 Button * rec = dynamic_cast<Button*> (x->second);
1394 switch (session->record_status()) {
1395 case Session::Disabled:
1396 DEBUG_TRACE (DEBUG::MackieControl, "record state changed to disabled, LED off\n");
1399 case Session::Recording:
1400 DEBUG_TRACE (DEBUG::MackieControl, "record state changed to recording, LED on\n");
1403 case Session::Enabled:
1404 DEBUG_TRACE (DEBUG::MackieControl, "record state changed to enabled, LED flashing\n");
1409 surface->write (rec->set_state (ls));
1414 list<boost::shared_ptr<ARDOUR::Bundle> >
1415 MackieControlProtocol::bundles ()
1417 list<boost::shared_ptr<ARDOUR::Bundle> > b;
1419 if (_input_bundle) {
1420 b.push_back (_input_bundle);
1421 b.push_back (_output_bundle);
1428 MackieControlProtocol::do_request (MackieControlUIRequest* req)
1430 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("doing request type %1\n", req->type));
1431 if (req->type == CallSlot) {
1433 call_slot (MISSING_INVALIDATOR, req->the_slot);
1435 } else if (req->type == Quit) {
1442 MackieControlProtocol::stop ()
1450 MackieControlProtocol::update_led (Surface& surface, Button& button, Mackie::LedState ls)
1453 surface.port().write (button.set_state (ls));
1458 MackieControlProtocol::build_button_map ()
1460 /* this maps our device-independent button codes to the methods that handle them.
1463 #define DEFINE_BUTTON_HANDLER(b,p,r) button_map.insert (pair<Button::ID,ButtonHandlers> ((b), ButtonHandlers ((p),(r))));
1465 DEFINE_BUTTON_HANDLER (Button::Track, &MackieControlProtocol::track_press, &MackieControlProtocol::track_release);
1466 DEFINE_BUTTON_HANDLER (Button::Send, &MackieControlProtocol::send_press, &MackieControlProtocol::send_release);
1467 DEFINE_BUTTON_HANDLER (Button::Pan, &MackieControlProtocol::pan_press, &MackieControlProtocol::pan_release);
1468 DEFINE_BUTTON_HANDLER (Button::Plugin, &MackieControlProtocol::plugin_press, &MackieControlProtocol::plugin_release);
1469 DEFINE_BUTTON_HANDLER (Button::Eq, &MackieControlProtocol::eq_press, &MackieControlProtocol::eq_release);
1470 DEFINE_BUTTON_HANDLER (Button::Dyn, &MackieControlProtocol::dyn_press, &MackieControlProtocol::dyn_release);
1471 DEFINE_BUTTON_HANDLER (Button::Left, &MackieControlProtocol::left_press, &MackieControlProtocol::left_release);
1472 DEFINE_BUTTON_HANDLER (Button::Right, &MackieControlProtocol::right_press, &MackieControlProtocol::right_release);
1473 DEFINE_BUTTON_HANDLER (Button::ChannelLeft, &MackieControlProtocol::channel_left_press, &MackieControlProtocol::channel_left_release);
1474 DEFINE_BUTTON_HANDLER (Button::ChannelRight, &MackieControlProtocol::channel_right_press, &MackieControlProtocol::channel_right_release);
1475 DEFINE_BUTTON_HANDLER (Button::Flip, &MackieControlProtocol::flip_press, &MackieControlProtocol::flip_release);
1476 DEFINE_BUTTON_HANDLER (Button::View, &MackieControlProtocol::view_press, &MackieControlProtocol::view_release);
1477 DEFINE_BUTTON_HANDLER (Button::NameValue, &MackieControlProtocol::name_value_press, &MackieControlProtocol::name_value_release);
1478 DEFINE_BUTTON_HANDLER (Button::TimecodeBeats, &MackieControlProtocol::timecode_beats_press, &MackieControlProtocol::timecode_beats_release);
1479 DEFINE_BUTTON_HANDLER (Button::F1, &MackieControlProtocol::F1_press, &MackieControlProtocol::F1_release);
1480 DEFINE_BUTTON_HANDLER (Button::F2, &MackieControlProtocol::F2_press, &MackieControlProtocol::F2_release);
1481 DEFINE_BUTTON_HANDLER (Button::F3, &MackieControlProtocol::F3_press, &MackieControlProtocol::F3_release);
1482 DEFINE_BUTTON_HANDLER (Button::F4, &MackieControlProtocol::F4_press, &MackieControlProtocol::F4_release);
1483 DEFINE_BUTTON_HANDLER (Button::F5, &MackieControlProtocol::F5_press, &MackieControlProtocol::F5_release);
1484 DEFINE_BUTTON_HANDLER (Button::F6, &MackieControlProtocol::F6_press, &MackieControlProtocol::F6_release);
1485 DEFINE_BUTTON_HANDLER (Button::F7, &MackieControlProtocol::F7_press, &MackieControlProtocol::F7_release);
1486 DEFINE_BUTTON_HANDLER (Button::F8, &MackieControlProtocol::F8_press, &MackieControlProtocol::F8_release);
1487 DEFINE_BUTTON_HANDLER (Button::MidiTracks, &MackieControlProtocol::miditracks_press, &MackieControlProtocol::miditracks_release);
1488 DEFINE_BUTTON_HANDLER (Button::Inputs, &MackieControlProtocol::inputs_press, &MackieControlProtocol::inputs_release);
1489 DEFINE_BUTTON_HANDLER (Button::AudioTracks, &MackieControlProtocol::audiotracks_press, &MackieControlProtocol::audiotracks_release);
1490 DEFINE_BUTTON_HANDLER (Button::AudioInstruments, &MackieControlProtocol::audioinstruments_press, &MackieControlProtocol::audioinstruments_release);
1491 DEFINE_BUTTON_HANDLER (Button::Aux, &MackieControlProtocol::aux_press, &MackieControlProtocol::aux_release);
1492 DEFINE_BUTTON_HANDLER (Button::Busses, &MackieControlProtocol::busses_press, &MackieControlProtocol::busses_release);
1493 DEFINE_BUTTON_HANDLER (Button::Outputs, &MackieControlProtocol::outputs_press, &MackieControlProtocol::outputs_release);
1494 DEFINE_BUTTON_HANDLER (Button::User, &MackieControlProtocol::user_press, &MackieControlProtocol::user_release);
1495 DEFINE_BUTTON_HANDLER (Button::Shift, &MackieControlProtocol::shift_press, &MackieControlProtocol::shift_release);
1496 DEFINE_BUTTON_HANDLER (Button::Option, &MackieControlProtocol::option_press, &MackieControlProtocol::option_release);
1497 DEFINE_BUTTON_HANDLER (Button::Ctrl, &MackieControlProtocol::control_press, &MackieControlProtocol::control_release);
1498 DEFINE_BUTTON_HANDLER (Button::CmdAlt, &MackieControlProtocol::cmd_alt_press, &MackieControlProtocol::cmd_alt_release);
1499 DEFINE_BUTTON_HANDLER (Button::Read, &MackieControlProtocol::read_press, &MackieControlProtocol::read_release);
1500 DEFINE_BUTTON_HANDLER (Button::Write, &MackieControlProtocol::write_press, &MackieControlProtocol::write_release);
1501 DEFINE_BUTTON_HANDLER (Button::Trim, &MackieControlProtocol::trim_press, &MackieControlProtocol::trim_release);
1502 DEFINE_BUTTON_HANDLER (Button::Touch, &MackieControlProtocol::touch_press, &MackieControlProtocol::touch_release);
1503 DEFINE_BUTTON_HANDLER (Button::Latch, &MackieControlProtocol::latch_press, &MackieControlProtocol::latch_release);
1504 DEFINE_BUTTON_HANDLER (Button::Grp, &MackieControlProtocol::grp_press, &MackieControlProtocol::grp_release);
1505 DEFINE_BUTTON_HANDLER (Button::Save, &MackieControlProtocol::save_press, &MackieControlProtocol::save_release);
1506 DEFINE_BUTTON_HANDLER (Button::Undo, &MackieControlProtocol::undo_press, &MackieControlProtocol::undo_release);
1507 DEFINE_BUTTON_HANDLER (Button::Cancel, &MackieControlProtocol::cancel_press, &MackieControlProtocol::cancel_release);
1508 DEFINE_BUTTON_HANDLER (Button::Enter, &MackieControlProtocol::enter_press, &MackieControlProtocol::enter_release);
1509 DEFINE_BUTTON_HANDLER (Button::Marker, &MackieControlProtocol::marker_press, &MackieControlProtocol::marker_release);
1510 DEFINE_BUTTON_HANDLER (Button::Nudge, &MackieControlProtocol::nudge_press, &MackieControlProtocol::nudge_release);
1511 DEFINE_BUTTON_HANDLER (Button::Loop, &MackieControlProtocol::loop_press, &MackieControlProtocol::loop_release);
1512 DEFINE_BUTTON_HANDLER (Button::Drop, &MackieControlProtocol::drop_press, &MackieControlProtocol::drop_release);
1513 DEFINE_BUTTON_HANDLER (Button::Replace, &MackieControlProtocol::replace_press, &MackieControlProtocol::replace_release);
1514 DEFINE_BUTTON_HANDLER (Button::Click, &MackieControlProtocol::click_press, &MackieControlProtocol::click_release);
1515 DEFINE_BUTTON_HANDLER (Button::ClearSolo, &MackieControlProtocol::clearsolo_press, &MackieControlProtocol::clearsolo_release);
1516 DEFINE_BUTTON_HANDLER (Button::Rewind, &MackieControlProtocol::rewind_press, &MackieControlProtocol::rewind_release);
1517 DEFINE_BUTTON_HANDLER (Button::Ffwd, &MackieControlProtocol::ffwd_press, &MackieControlProtocol::ffwd_release);
1518 DEFINE_BUTTON_HANDLER (Button::Stop, &MackieControlProtocol::stop_press, &MackieControlProtocol::stop_release);
1519 DEFINE_BUTTON_HANDLER (Button::Play, &MackieControlProtocol::play_press, &MackieControlProtocol::play_release);
1520 DEFINE_BUTTON_HANDLER (Button::Record, &MackieControlProtocol::record_press, &MackieControlProtocol::record_release);
1521 DEFINE_BUTTON_HANDLER (Button::CursorUp, &MackieControlProtocol::cursor_up_press, &MackieControlProtocol::cursor_up_release);
1522 DEFINE_BUTTON_HANDLER (Button::CursorDown, &MackieControlProtocol::cursor_down_press, &MackieControlProtocol::cursor_down_release);
1523 DEFINE_BUTTON_HANDLER (Button::CursorLeft, &MackieControlProtocol::cursor_left_press, &MackieControlProtocol::cursor_left_release);
1524 DEFINE_BUTTON_HANDLER (Button::CursorRight, &MackieControlProtocol::cursor_right_press, &MackieControlProtocol::cursor_right_release);
1525 DEFINE_BUTTON_HANDLER (Button::Zoom, &MackieControlProtocol::zoom_press, &MackieControlProtocol::zoom_release);
1526 DEFINE_BUTTON_HANDLER (Button::Scrub, &MackieControlProtocol::scrub_press, &MackieControlProtocol::scrub_release);
1527 DEFINE_BUTTON_HANDLER (Button::UserA, &MackieControlProtocol::user_a_press, &MackieControlProtocol::user_a_release);
1528 DEFINE_BUTTON_HANDLER (Button::UserB, &MackieControlProtocol::user_b_press, &MackieControlProtocol::user_b_release);
1529 DEFINE_BUTTON_HANDLER (Button::MasterFaderTouch, &MackieControlProtocol::master_fader_touch_press, &MackieControlProtocol::master_fader_touch_release);
1533 MackieControlProtocol::handle_button_event (Surface& surface, Button& button, ButtonState bs)
1535 Button::ID button_id = button.bid();
1537 if (bs != press && bs != release) {
1538 update_led (surface, button, none);
1542 if ((button_id != Button::Marker) && (modifier_state() & MODIFIER_MARKER)) {
1543 marker_modifier_consumed_by_button = true;
1546 if ((button_id != Button::Nudge) && (modifier_state() & MODIFIER_NUDGE)) {
1547 nudge_modifier_consumed_by_button = true;
1550 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Handling %1 for button %2 (%3)\n", (bs == press ? "press" : "release"), button.id(),
1551 Button::id_to_name (button.bid())));
1553 /* check profile first */
1555 string action = _device_profile.get_button_action (button.bid(), _modifier_state);
1557 if (!action.empty()) {
1559 if (action.find ('/') != string::npos) { /* good chance that this is really an action */
1561 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Looked up action for button %1 with modifier %2, got [%3]\n",
1562 button.bid(), _modifier_state, action));
1564 /* if there is a bound action for this button, and this is a press event,
1565 carry out the action. If its a release event, do nothing since we
1566 don't bind to them at all but don't want any other handling to
1570 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("executing action %1\n", action));
1571 access_action (action);
1578 /* "action" is more likely to be a button name. We use this to
1579 * allow remapping buttons to different (builtin) functionality
1580 * associated with an existing button. This is similar to the
1581 * way that (for example) Nuendo moves the "Shift" function to
1582 * the "Enter" key of the MCU Pro.
1585 int bid = Button::name_to_id (action);
1588 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("apparent button name %1 not found\n", action));
1592 button_id = (Button::ID) bid;
1593 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handling button %1 as if it was %2 (%3)\n", Button::id_to_name (button.bid()), button_id, Button::id_to_name (button_id)));
1597 /* lookup using the device-INDEPENDENT button ID */
1599 ButtonMap::iterator b = button_map.find (button_id);
1601 if (b != button_map.end()) {
1603 ButtonHandlers& bh (b->second);
1607 surface.write (button.set_state ((this->*(bh.press)) (button)));
1610 surface.write (button.set_state ((this->*(bh.release)) (button)));
1616 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("no button handlers for button ID %1 (device ID %2)\n",
1617 button.bid(), button.id()));
1618 error << string_compose ("no button handlers for button ID %1 (device ID %2)\n",
1619 button.bid(), button.id()) << endmsg;
1624 MackieControlProtocol::midi_input_handler (IOCondition ioc, MIDI::Port* port)
1627 DEBUG_TRACE (DEBUG::MackieControl, "MIDI port closed\n");
1633 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("something happend on %1\n", port->name()));
1635 /* Devices using regular JACK MIDI ports will need to have
1636 the x-thread FIFO drained to avoid burning endless CPU.
1638 Devices using ipMIDI have port->selectable() as the same
1639 file descriptor that data arrives on, so doing this
1640 for them will simply throw all incoming data away.
1643 if (!_device_info.uses_ipmidi()) {
1644 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*>(port);
1650 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("data available on %1\n", port->name()));
1651 framepos_t now = session->engine().sample_time();
1659 MackieControlProtocol::clear_ports ()
1661 if (_input_bundle) {
1662 _input_bundle->remove_channels ();
1663 _output_bundle->remove_channels ();
1668 MackieControlProtocol::notify_subview_stripable_deleted ()
1670 /* return to global/mixer view */
1671 _subview_stripable.reset ();
1672 set_view_mode (Mixer);
1676 MackieControlProtocol::subview_mode_would_be_ok (SubViewMode mode, boost::shared_ptr<Stripable> r)
1684 if (r && r->send_level_controllable (0)) {
1690 if (r && r->eq_band_cnt() > 0) {
1696 if (r && r->comp_enable_controllable()) {
1711 MackieControlProtocol::redisplay_subview_mode ()
1713 Surfaces copy; /* can't hold surfaces lock while calling Strip::subview_mode_changed */
1716 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1720 for (Surfaces::iterator s = copy.begin(); s != copy.end(); ++s) {
1721 (*s)->subview_mode_changed ();
1724 /* don't call this again from a timeout */
1729 MackieControlProtocol::set_subview_mode (SubViewMode sm, boost::shared_ptr<Stripable> r)
1731 if (_flip_mode != Normal) {
1732 set_flip_mode (Normal);
1735 if (!subview_mode_would_be_ok (sm, r)) {
1739 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1741 if (!surfaces.empty()) {
1747 msg = _("no sends for selected track/bus");
1750 msg = _("no EQ in the track/bus");
1753 msg = _("no dynamics in selected track/bus");
1756 msg = _("no track view possible");
1761 surfaces.front()->display_message_for (msg, 1000);
1762 if (_subview_mode != None) {
1763 /* redisplay current subview mode after
1764 that message goes away.
1766 Glib::RefPtr<Glib::TimeoutSource> redisplay_timeout = Glib::TimeoutSource::create (1000); // milliseconds
1767 redisplay_timeout->connect (sigc::mem_fun (*this, &MackieControlProtocol::redisplay_subview_mode));
1768 redisplay_timeout->attach (main_loop()->get_context());
1777 boost::shared_ptr<Stripable> old_stripable = _subview_stripable;
1780 _subview_stripable = r;
1782 if (_subview_stripable != old_stripable) {
1783 subview_stripable_connections.drop_connections ();
1785 /* Catch the current subview stripable going away */
1786 if (_subview_stripable) {
1787 _subview_stripable->DropReferences.connect (subview_stripable_connections, MISSING_INVALIDATOR,
1788 boost::bind (&MackieControlProtocol::notify_subview_stripable_deleted, this),
1793 redisplay_subview_mode ();
1795 /* turn buttons related to vpot mode on or off as required */
1797 switch (_subview_mode) {
1798 case MackieControlProtocol::None:
1799 update_global_button (Button::Send, off);
1800 update_global_button (Button::Plugin, off);
1801 update_global_button (Button::Eq, off);
1802 update_global_button (Button::Dyn, off);
1803 update_global_button (Button::Track, off);
1804 update_global_button (Button::Pan, on);
1806 case MackieControlProtocol::EQ:
1807 update_global_button (Button::Send, off);
1808 update_global_button (Button::Plugin, off);
1809 update_global_button (Button::Eq, on);
1810 update_global_button (Button::Dyn, off);
1811 update_global_button (Button::Track, off);
1812 update_global_button (Button::Pan, off);
1814 case MackieControlProtocol::Dynamics:
1815 update_global_button (Button::Send, off);
1816 update_global_button (Button::Plugin, off);
1817 update_global_button (Button::Eq, off);
1818 update_global_button (Button::Dyn, on);
1819 update_global_button (Button::Track, off);
1820 update_global_button (Button::Pan, off);
1822 case MackieControlProtocol::Sends:
1823 update_global_button (Button::Send, on);
1824 update_global_button (Button::Plugin, off);
1825 update_global_button (Button::Eq, off);
1826 update_global_button (Button::Dyn, off);
1827 update_global_button (Button::Track, off);
1828 update_global_button (Button::Pan, off);
1830 case MackieControlProtocol::TrackView:
1831 update_global_button (Button::Send, off);
1832 update_global_button (Button::Plugin, off);
1833 update_global_button (Button::Eq, off);
1834 update_global_button (Button::Dyn, off);
1835 update_global_button (Button::Track, on);
1836 update_global_button (Button::Pan, off);
1844 MackieControlProtocol::set_view_mode (ViewMode m)
1846 if (_flip_mode != Normal) {
1847 set_flip_mode (Normal);
1849 ViewMode old_view_mode = _view_mode;
1852 _last_bank[old_view_mode] = _current_initial_bank;
1854 if (switch_banks(_last_bank[m], true)) {
1855 _view_mode = old_view_mode;
1859 /* leave subview mode, whatever it was */
1860 set_subview_mode (None, boost::shared_ptr<Stripable>());
1861 display_view_mode ();
1865 MackieControlProtocol::display_view_mode ()
1867 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1869 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1870 (*s)->update_view_mode_display (true);
1875 MackieControlProtocol::set_flip_mode (FlipMode fm)
1878 update_global_button (Button::Flip, off);
1880 update_global_button (Button::Flip, on);
1883 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1887 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1888 (*s)->update_flip_mode_display ();
1893 MackieControlProtocol::set_master_on_surface_strip (uint32_t surface, uint32_t strip_number)
1895 force_special_stripable_to_strip (session->master_out(), surface, strip_number);
1899 MackieControlProtocol::set_monitor_on_surface_strip (uint32_t surface, uint32_t strip_number)
1901 force_special_stripable_to_strip (session->monitor_out(), surface, strip_number);
1905 MackieControlProtocol::force_special_stripable_to_strip (boost::shared_ptr<Stripable> r, uint32_t surface, uint32_t strip_number)
1911 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1913 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1914 if ((*s)->number() == surface) {
1915 Strip* strip = (*s)->nth_strip (strip_number);
1917 strip->set_stripable (session->master_out());
1918 strip->lock_controls ();
1925 MackieControlProtocol::check_fader_automation_state ()
1927 fader_automation_connections.drop_connections ();
1929 boost::shared_ptr<Stripable> r = first_selected_stripable ();
1932 update_global_button (Button::Read, off);
1933 update_global_button (Button::Write, off);
1934 update_global_button (Button::Touch, off);
1935 update_global_button (Button::Trim, off);
1936 update_global_button (Button::Latch, off);
1937 update_global_button (Button::Grp, on);
1941 r->gain_control()->alist()->automation_state_changed.connect (fader_automation_connections,
1942 MISSING_INVALIDATOR,
1943 boost::bind (&MackieControlProtocol::update_fader_automation_state, this),
1946 update_fader_automation_state ();
1950 MackieControlProtocol::update_fader_automation_state ()
1952 boost::shared_ptr<Stripable> r = first_selected_stripable ();
1955 update_global_button (Button::Read, off);
1956 update_global_button (Button::Write, off);
1957 update_global_button (Button::Touch, off);
1958 update_global_button (Button::Trim, off);
1959 update_global_button (Button::Latch, off);
1960 update_global_button (Button::Grp, on);
1964 switch (r->gain_control()->automation_state()) {
1966 update_global_button (Button::Read, off);
1967 update_global_button (Button::Write, off);
1968 update_global_button (Button::Touch, off);
1969 update_global_button (Button::Trim, off);
1970 update_global_button (Button::Latch, off);
1971 update_global_button (Button::Grp, on);
1974 update_global_button (Button::Read, on);
1975 update_global_button (Button::Write, off);
1976 update_global_button (Button::Touch, off);
1977 update_global_button (Button::Trim, off);
1978 update_global_button (Button::Latch, off);
1979 update_global_button (Button::Grp, off);
1982 update_global_button (Button::Read, off);
1983 update_global_button (Button::Write, on);
1984 update_global_button (Button::Touch, off);
1985 update_global_button (Button::Trim, off);
1986 update_global_button (Button::Latch, off);
1987 update_global_button (Button::Grp, off);
1990 update_global_button (Button::Read, off);
1991 update_global_button (Button::Write, off);
1992 update_global_button (Button::Touch, on);
1993 update_global_button (Button::Trim, off);
1994 update_global_button (Button::Latch, off);
1995 update_global_button (Button::Grp, off);
2001 MackieControlProtocol::transport_frame() const
2003 return session->transport_frame();
2007 MackieControlProtocol::add_down_select_button (int surface, int strip)
2009 _down_select_buttons.insert ((surface<<8)|(strip&0xf));
2013 MackieControlProtocol::remove_down_select_button (int surface, int strip)
2015 DownButtonList::iterator x = find (_down_select_buttons.begin(), _down_select_buttons.end(), (uint32_t) (surface<<8)|(strip&0xf));
2016 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("removing surface %1 strip %2 from down select buttons\n", surface, strip));
2017 if (x != _down_select_buttons.end()) {
2018 _down_select_buttons.erase (x);
2020 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 strip %2 not found in down select buttons\n",
2026 MackieControlProtocol::select_range ()
2028 StripableList stripables;
2030 pull_stripable_range (_down_select_buttons, stripables);
2032 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("select range: found %1 stripables\n", stripables.size()));
2034 if (stripables.empty()) {
2038 cerr << "Main modifier state = " << hex << main_modifier_state() << dec << endl;
2040 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
2042 if (main_modifier_state() == MODIFIER_CONTROL) {
2043 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("toggle selection of %1 (%2)\n", (*s)->name(), (*s)->presentation_info().order()));
2044 cerr << "Toggle selection\n";
2045 ToggleStripableSelection ((*s)->presentation_info ().order());
2047 if (s == stripables.begin()) {
2048 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("set selection of %1 (%2)\n", (*s)->name(), (*s)->presentation_info().order()));
2049 SetStripableSelection ((*s)->presentation_info().order());
2051 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("add to selection %1 (%2)\n", (*s)->name(), (*s)->presentation_info().order()));
2052 AddStripableSelection ((*s)->presentation_info().order());
2059 MackieControlProtocol::add_down_button (AutomationType a, int surface, int strip)
2061 DownButtonMap::iterator m = _down_buttons.find (a);
2063 if (m == _down_buttons.end()) {
2064 _down_buttons[a] = DownButtonList();
2067 _down_buttons[a].insert ((surface<<8)|(strip&0xf));
2071 MackieControlProtocol::remove_down_button (AutomationType a, int surface, int strip)
2073 DownButtonMap::iterator m = _down_buttons.find (a);
2075 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("removing surface %1 strip %2 from down buttons for %3\n", surface, strip, (int) a));
2077 if (m == _down_buttons.end()) {
2081 DownButtonList& l (m->second);
2082 DownButtonList::iterator x = find (l.begin(), l.end(), (surface<<8)|(strip&0xf));
2087 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 strip %2 not found in down buttons for %3\n",
2088 surface, strip, (int) a));
2092 MackieControlProtocol::ControlList
2093 MackieControlProtocol::down_controls (AutomationType p)
2095 ControlList controls;
2096 StripableList stripables;
2098 DownButtonMap::iterator m = _down_buttons.find (p);
2100 if (m == _down_buttons.end()) {
2104 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("looking for down buttons for %1, got %2\n",
2105 p, m->second.size()));
2107 pull_stripable_range (m->second, stripables);
2110 case GainAutomation:
2111 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
2112 controls.push_back ((*s)->gain_control());
2115 case SoloAutomation:
2116 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
2117 controls.push_back ((*s)->solo_control());
2120 case MuteAutomation:
2121 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
2122 controls.push_back ((*s)->mute_control());
2125 case RecEnableAutomation:
2126 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
2127 boost::shared_ptr<AutomationControl> ac = (*s)->rec_enable_control();
2129 controls.push_back (ac);
2141 struct ButtonRangeSorter {
2142 bool operator() (const uint32_t& a, const uint32_t& b) {
2143 return (a>>8) < (b>>8) // a.surface < b.surface
2145 ((a>>8) == (b>>8) && (a&0xf) < (b&0xf)); // a.surface == b.surface && a.strip < b.strip
2150 MackieControlProtocol::pull_stripable_range (DownButtonList& down, StripableList& selected)
2152 ButtonRangeSorter cmp;
2158 list<uint32_t> ldown;
2159 ldown.insert (ldown.end(), down.begin(), down.end());
2162 uint32_t first = ldown.front();
2163 uint32_t last = ldown.back ();
2165 uint32_t first_surface = first>>8;
2166 uint32_t first_strip = first&0xf;
2168 uint32_t last_surface = last>>8;
2169 uint32_t last_strip = last&0xf;
2171 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("PRR %5 in list %1.%2 - %3.%4\n", first_surface, first_strip, last_surface, last_strip,
2174 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2176 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2178 if ((*s)->number() >= first_surface && (*s)->number() <= last_surface) {
2183 if ((*s)->number() == first_surface) {
2189 if ((*s)->number() == last_surface) {
2193 ls = (*s)->n_strips ();
2196 DEBUG_TRACE (DEBUG::MackieControl, string_compose ("adding strips for surface %1 (%2 .. %3)\n",
2197 (*s)->number(), fs, ls));
2199 for (uint32_t n = fs; n < ls; ++n) {
2200 boost::shared_ptr<Stripable> r = (*s)->nth_strip (n)->stripable();
2202 selected.push_back (r);
2210 MackieControlProtocol::set_ipmidi_base (int16_t portnum)
2212 /* this will not be saved without a session save, so .. */
2214 session->set_dirty ();
2216 _ipmidi_base = portnum;
2218 /* if the current device uses ipMIDI we need
2222 if (active() && _device_info.uses_ipmidi()) {
2223 needs_ipmidi_restart = true;
2228 MackieControlProtocol::ipmidi_restart ()
2231 if (create_surfaces ()) {
2234 (void) switch_banks (_current_initial_bank, true);
2235 needs_ipmidi_restart = false;
2240 MackieControlProtocol::clear_surfaces ()
2245 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2246 _master_surface.reset ();
2252 MackieControlProtocol::set_touch_sensitivity (int sensitivity)
2254 sensitivity = min (9, sensitivity);
2255 sensitivity = max (0, sensitivity);
2257 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2259 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2260 (*s)->set_touch_sensitivity (sensitivity);
2265 MackieControlProtocol::recalibrate_faders ()
2267 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2269 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2270 (*s)->recalibrate_faders ();
2275 MackieControlProtocol::toggle_backlight ()
2277 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2279 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2280 (*s)->toggle_backlight ();
2284 boost::shared_ptr<Surface>
2285 MackieControlProtocol::get_surface_by_raw_pointer (void* ptr) const
2287 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2289 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2290 if ((*s).get() == (Surface*) ptr) {
2295 return boost::shared_ptr<Surface> ();
2298 boost::shared_ptr<Surface>
2299 MackieControlProtocol::nth_surface (uint32_t n) const
2301 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2303 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s, --n) {
2309 return boost::shared_ptr<Surface> ();
2313 MackieControlProtocol::connection_handler (boost::weak_ptr<ARDOUR::Port> wp1, std::string name1, boost::weak_ptr<ARDOUR::Port> wp2, std::string name2, bool yn)
2317 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2321 for (Surfaces::const_iterator s = scopy.begin(); s != scopy.end(); ++s) {
2322 if ((*s)->connection_handler (wp1, name1, wp2, name2, yn)) {
2323 ConnectionChange (*s);
2330 MackieControlProtocol::is_track (boost::shared_ptr<Stripable> r) const
2332 return boost::dynamic_pointer_cast<Track>(r) != 0;
2336 MackieControlProtocol::is_audio_track (boost::shared_ptr<Stripable> r) const
2338 return boost::dynamic_pointer_cast<AudioTrack>(r) != 0;
2342 MackieControlProtocol::is_midi_track (boost::shared_ptr<Stripable> r) const
2344 return boost::dynamic_pointer_cast<MidiTrack>(r) != 0;
2348 MackieControlProtocol::selected (boost::shared_ptr<Stripable> r) const
2350 const StripableNotificationList* rl = &_last_selected_stripables;
2352 for (ARDOUR::StripableNotificationList::const_iterator i = rl->begin(); i != rl->end(); ++i) {
2353 boost::shared_ptr<ARDOUR::Stripable> rt = (*i).lock();
2362 MackieControlProtocol::is_hidden (boost::shared_ptr<Stripable> r) const
2367 return (r->presentation_info().flags() & PresentationInfo::Hidden);
2371 MackieControlProtocol::is_mapped (boost::shared_ptr<Stripable> r) const
2373 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2375 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2376 if ((*s)->stripable_is_mapped (r)) {
2384 boost::shared_ptr<Stripable>
2385 MackieControlProtocol::first_selected_stripable () const
2387 if (_last_selected_stripables.empty()) {
2388 return boost::shared_ptr<Stripable>();
2391 boost::shared_ptr<Stripable> r = _last_selected_stripables.front().lock();
2394 /* check it is on one of our surfaces */
2396 if (is_mapped (r)) {
2400 /* stripable is not mapped. thus, the currently selected stripable is
2401 * not on the surfaces, and so from our perspective, there is
2402 * no currently selected stripable.
2408 return r; /* may be null */
2411 boost::shared_ptr<Stripable>
2412 MackieControlProtocol::subview_stripable () const
2414 return _subview_stripable;
2418 MackieControlProtocol::global_index (Strip& strip)
2420 Glib::Threads::Mutex::Lock lm (surfaces_lock);
2421 uint32_t global = 0;
2423 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
2424 if ((*s).get() == strip.surface()) {
2425 return global + strip.index();
2427 global += (*s)->n_strips ();
2434 MackieControlProtocol::request_factory (uint32_t num_requests)
2436 /* AbstractUI<T>::request_buffer_factory() is a template method only
2437 instantiated in this source module. To provide something visible for
2438 use in the interface/descriptor, we have this static method that is
2441 return request_buffer_factory (num_requests);
2445 MackieControlProtocol::set_automation_state (AutoState as)
2447 boost::shared_ptr<Stripable> r = first_selected_stripable ();
2453 boost::shared_ptr<AutomationControl> ac = r->gain_control();
2459 ac->set_automation_state (as);