2 * Copyright (C) 2017 Ben Loftis <ben@harrisonconsoles.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32 #include <boost/shared_array.hpp>
33 #include <glibmm/miscutils.h>
35 #include "midi++/types.h"
36 #include "midi++/port.h"
37 #include "pbd/pthread_utils.h"
38 #include "pbd/error.h"
39 #include "pbd/memento_command.h"
40 #include "pbd/convert.h"
42 #include "ardour/audio_track.h"
43 #include "ardour/automation_control.h"
44 #include "ardour/async_midi_port.h"
45 #include "ardour/dB.h"
46 #include "ardour/debug.h"
47 #include "ardour/location.h"
48 #include "ardour/meter.h"
49 #include "ardour/midi_track.h"
50 #include "ardour/panner.h"
51 #include "ardour/panner_shell.h"
52 #include "ardour/profile.h"
53 #include "ardour/record_enable_control.h"
54 #include "ardour/route.h"
55 #include "ardour/route_group.h"
56 #include "ardour/session.h"
57 #include "ardour/tempo.h"
58 #include "ardour/track.h"
59 #include "ardour/types.h"
60 #include "ardour/audioengine.h"
61 #include "ardour/vca_manager.h"
63 #include "us2400_control_protocol.h"
65 #include "midi_byte_array.h"
66 #include "us2400_control_exception.h"
67 #include "device_profile.h"
68 #include "surface_port.h"
71 #include "control_group.h"
77 using namespace ARDOUR;
81 using namespace ArdourSurface;
82 using namespace US2400;
86 #include "pbd/abstract_ui.cc" // instantiate template
88 const int US2400Protocol::MODIFIER_OPTION = 0x1;
89 const int US2400Protocol::MODIFIER_CONTROL = 0x2;
90 const int US2400Protocol::MODIFIER_SHIFT = 0x4;
91 const int US2400Protocol::MODIFIER_CMDALT = 0x8;
92 const int US2400Protocol::MODIFIER_ZOOM = 0x10;
93 const int US2400Protocol::MODIFIER_SCRUB = 0x20;
94 const int US2400Protocol::MODIFIER_MARKER = 0x40;
95 const int US2400Protocol::MODIFIER_DROP = 0x80; //US2400 Drop as a modifier for In/out
96 const int US2400Protocol::MAIN_MODIFIER_MASK = (US2400Protocol::MODIFIER_OPTION|
97 US2400Protocol::MODIFIER_CONTROL|
98 US2400Protocol::MODIFIER_SHIFT|
99 US2400Protocol::MODIFIER_CMDALT);
101 US2400Protocol* US2400Protocol::_instance = 0;
103 bool US2400Protocol::probe()
108 US2400Protocol::US2400Protocol (Session& session)
109 : ControlProtocol (session, X_("Tascam US-2400"))
110 , AbstractUI<US2400ControlUIRequest> (name())
111 , _current_initial_bank (0)
113 , _timecode_type (ARDOUR::AnyTime::BBT)
115 , _scrub_mode (false)
117 , _subview_mode (None)
118 , _modifier_state (0)
119 , _metering_active (true)
120 , _initialized (false)
121 , configuration_state (0)
123 , marker_modifier_consumed_by_button (false)
124 , nudge_modifier_consumed_by_button (false)
126 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::US2400Protocol\n");
128 // DeviceInfo::reload_device_info ();
129 DeviceProfile::reload_device_profiles ();
131 for (int i = 0; i < 9; i++) {
135 PresentationInfo::Change.connect (gui_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_presentation_info_changed, this, _1), this);
142 US2400Protocol::~US2400Protocol()
144 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::~US2400Protocol init\n");
146 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
150 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::~US2400Protocol drop_connections ()\n");
153 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::~US2400Protocol tear_down_gui ()\n");
156 delete configuration_state;
158 /* stop event loop */
159 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::~US2400Protocol BaseUI::quit ()\n");
163 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::~US2400Protocol close()\n");
166 catch (exception & e) {
167 cout << "~US2400Protocol caught " << e.what() << endl;
170 cout << "~US2400Protocol caught unknown" << endl;
175 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::~US2400Protocol done\n");
179 US2400Protocol::thread_init ()
181 pthread_set_name (event_loop_name().c_str());
183 PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
184 ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
186 set_thread_priority ();
189 // go to the previous track.
191 US2400Protocol::prev_track()
193 if (_current_initial_bank >= 1) {
194 switch_banks (_current_initial_bank - 1);
198 // go to the next track.
200 US2400Protocol::next_track()
202 Sorted sorted = get_sorted_stripables();
203 if (_current_initial_bank + n_strips() < sorted.size()) {
204 switch_banks (_current_initial_bank + 1);
209 US2400Protocol::stripable_is_locked_to_strip (boost::shared_ptr<Stripable> r) const
211 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
212 if ((*si)->stripable_is_locked_to_strip (r)) {
219 // predicate for sort call in get_sorted_stripables
220 struct StripableByPresentationOrder
222 bool operator () (const boost::shared_ptr<Stripable> & a, const boost::shared_ptr<Stripable> & b) const
224 return a->presentation_info().order() < b->presentation_info().order();
227 bool operator () (const Stripable & a, const Stripable & b) const
229 return a.presentation_info().order() < b.presentation_info().order();
232 bool operator () (const Stripable * a, const Stripable * b) const
234 return a->presentation_info().order() < b->presentation_info().order();
238 US2400Protocol::Sorted
239 US2400Protocol::get_sorted_stripables()
243 // fetch all stripables
244 StripableList stripables;
246 session->get_stripables (stripables);
248 // sort in presentation order, and exclude master, control and hidden stripables
249 // and any stripables that are already set.
251 for (StripableList::iterator it = stripables.begin(); it != stripables.end(); ++it) {
253 boost::shared_ptr<Stripable> s = *it;
255 if (s->presentation_info().special()) {
259 /* don't include locked routes */
261 if (stripable_is_locked_to_strip (s)) {
265 switch (_view_mode) {
268 if (!s->presentation_info().hidden() && !s->mixbus()) {
270 if (!s->presentation_info().hidden()) {
272 sorted.push_back (s);
278 sorted.push_back (s);
282 if (!is_track(s) && !s->presentation_info().hidden()) {
283 sorted.push_back (s);
290 sort (sorted.begin(), sorted.end(), StripableByPresentationOrder());
295 US2400Protocol::refresh_current_bank()
297 switch_banks (_current_initial_bank, true);
301 US2400Protocol::n_strips (bool with_locked_strips) const
303 uint32_t strip_count = 0;
305 for (Surfaces::const_iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
306 strip_count += (*si)->n_strips (with_locked_strips);
313 US2400Protocol::switch_banks (uint32_t initial, bool force)
315 DEBUG_TRACE (DEBUG::US2400, string_compose ("switch banking to start at %1 force ? %2 current = %3\n", initial, force, _current_initial_bank));
317 if (initial == _current_initial_bank && !force) {
318 /* everything is as it should be */
322 Sorted sorted = get_sorted_stripables();
323 uint32_t strip_cnt = n_strips (false); // do not include locked strips
326 if (initial >= sorted.size() && !force) {
327 DEBUG_TRACE (DEBUG::US2400, string_compose ("bank target %1 exceeds route range %2\n",
328 _current_initial_bank, sorted.size()));
329 /* too high, we can't get there */
333 if (sorted.size() <= strip_cnt && _current_initial_bank == 0 && !force) {
334 /* no banking - not enough stripables to fill all strips and we're
335 * not at the first one.
337 DEBUG_TRACE (DEBUG::US2400, string_compose ("less routes (%1) than strips (%2) and we're at the end already (%3)\n",
338 sorted.size(), strip_cnt, _current_initial_bank));
342 _current_initial_bank = initial;
344 // Map current bank of stripables onto each surface(+strip)
346 if (_current_initial_bank < sorted.size()) {
348 DEBUG_TRACE (DEBUG::US2400, string_compose ("switch to %1, %2, available stripables %3 on %4 surfaces\n",
349 _current_initial_bank, strip_cnt, sorted.size(),
352 // link stripables to strips
354 Sorted::iterator r = sorted.begin() + _current_initial_bank;
356 for (Surfaces::iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
357 vector<boost::shared_ptr<Stripable> > stripables;
360 DEBUG_TRACE (DEBUG::US2400, string_compose ("surface has %1 unlocked strips\n", (*si)->n_strips (false)));
362 for (; r != sorted.end() && added < (*si)->n_strips (false); ++r, ++added) {
363 stripables.push_back (*r);
366 DEBUG_TRACE (DEBUG::US2400, string_compose ("give surface #%1 %2 stripables\n", (*si)->number(), stripables.size()));
368 (*si)->map_stripables (stripables);
372 /* all strips need to be reset */
373 DEBUG_TRACE (DEBUG::US2400, string_compose ("clear all strips, bank target %1 is outside route range %2\n",
374 _current_initial_bank, sorted.size()));
375 for (Surfaces::iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
376 vector<boost::shared_ptr<Stripable> > stripables;
377 /* pass in an empty stripables list, so that all strips will be reset */
378 (*si)->map_stripables (stripables);
383 /* current bank has not been saved */
384 session->set_dirty();
390 US2400Protocol::set_active (bool yn)
392 DEBUG_TRACE (DEBUG::US2400, string_compose("US2400Protocol::set_active init with yn: '%1'\n", yn));
394 if (yn == active()) {
400 /* start event loop */
404 connect_session_signals ();
406 if (!_device_info.name().empty()) {
407 set_device (_device_info.name(), true);
410 /* set up periodic task for timecode display and metering and automation
413 Glib::RefPtr<Glib::TimeoutSource> periodic_timeout = Glib::TimeoutSource::create (10); // milliseconds
414 periodic_connection = periodic_timeout->connect (sigc::mem_fun (*this, &US2400Protocol::periodic));
415 periodic_timeout->attach (main_loop()->get_context());
417 /* periodic task used to update strip displays */
419 Glib::RefPtr<Glib::TimeoutSource> redisplay_timeout = Glib::TimeoutSource::create (10); // milliseconds
420 redisplay_connection = redisplay_timeout->connect (sigc::mem_fun (*this, &US2400Protocol::redisplay));
421 redisplay_timeout->attach (main_loop()->get_context());
430 ControlProtocol::set_active (yn);
432 DEBUG_TRACE (DEBUG::US2400, string_compose("US2400Protocol::set_active done with yn: '%1'\n", yn));
438 US2400Protocol::hui_heartbeat ()
440 Glib::Threads::Mutex::Lock lm (surfaces_lock);
442 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
443 (*s)->hui_heartbeat ();
450 US2400Protocol::periodic ()
460 ARDOUR::microseconds_t now_usecs = ARDOUR::get_microseconds ();
463 Glib::Threads::Mutex::Lock lm (surfaces_lock);
465 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
466 (*s)->periodic (now_usecs);
474 US2400Protocol::redisplay ()
480 US2400Protocol::update_timecode_beats_led()
485 US2400Protocol::update_global_button (int id, LedState ls)
487 boost::shared_ptr<Surface> surface;
490 Glib::Threads::Mutex::Lock lm (surfaces_lock);
492 if (surfaces.empty()) {
496 if (!_device_info.has_global_controls()) {
499 // surface needs to be master surface
500 surface = _master_surface;
503 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (id);
504 if (x != surface->controls_by_device_independent_id.end()) {
505 Button * button = dynamic_cast<Button*> (x->second);
506 surface->write (button->set_state (ls));
508 DEBUG_TRACE (DEBUG::US2400, string_compose ("Button %1 not found\n", id));
513 US2400Protocol::update_global_led (int id, LedState ls)
515 Glib::Threads::Mutex::Lock lm (surfaces_lock);
517 if (surfaces.empty()) {
521 if (!_device_info.has_global_controls()) {
524 boost::shared_ptr<Surface> surface = _master_surface;
526 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (id);
528 if (x != surface->controls_by_device_independent_id.end()) {
529 Led * led = dynamic_cast<Led*> (x->second);
530 DEBUG_TRACE (DEBUG::US2400, "Writing LedState\n");
531 surface->write (led->set_state (ls));
533 DEBUG_TRACE (DEBUG::US2400, string_compose ("Led %1 not found\n", id));
538 US2400Protocol::device_ready ()
540 DEBUG_TRACE (DEBUG::US2400, string_compose ("device ready init (active=%1)\n", active()));
542 //this gets called every time a new surface appears; we have to do this to reset the banking etc
543 //particularly when the user is setting it up the first time; we can't guarantee the order that they will be connected
547 set_subview_mode (US2400Protocol::None, first_selected_stripable());
550 // send messages to surface to set controls to correct values
552 US2400Protocol::update_surfaces()
554 DEBUG_TRACE (DEBUG::US2400, string_compose ("US2400Protocol::update_surfaces() init (active=%1)\n", active()));
559 // do the initial bank switch to connect signals
560 // _current_initial_bank is initialised by set_state
561 (void) switch_banks (_current_initial_bank, true);
563 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::update_surfaces() finished\n");
567 US2400Protocol::initialize()
570 Glib::Threads::Mutex::Lock lm (surfaces_lock);
572 if (surfaces.empty()) {
576 if (!_master_surface->active ()) {
582 update_global_button (Button::Send, on);
583 update_global_button (Button::Send, off);
585 update_global_button (Button::Scrub, on);
586 update_global_button (Button::Scrub, off);
588 notify_solo_active_changed(false);
590 update_global_button (Button::Pan, off);
591 update_global_button (Button::Pan, on);
593 update_global_button (Button::Flip, on);
594 update_global_button (Button::Flip, off);
596 update_global_button (Button::MstrSelect, on);
597 update_global_button (Button::MstrSelect, off);
599 notify_transport_state_changed();
605 US2400Protocol::connect_session_signals()
607 // receive routes added
608 session->RouteAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_routes_added, this, _1), this);
609 // receive VCAs added
610 session->vca_manager().VCAAdded.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_vca_added, this, _1), this);
612 // receive record state toggled
613 session->RecordStateChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_record_state_changed, this), this);
614 // receive transport state changed
615 session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_transport_state_changed, this), this);
616 session->TransportLooped.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_loop_state_changed, this), this);
617 // receive punch-in and punch-out
618 Config->ParameterChanged.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_parameter_changed, this, _1), this);
619 session->config.ParameterChanged.connect (session_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_parameter_changed, this, _1), this);
620 // receive rude solo changed
621 session->SoloActive.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::notify_solo_active_changed, this, _1), this);
623 // make sure remote id changed signals reach here
624 // see also notify_stripable_added
625 Sorted sorted = get_sorted_stripables();
629 US2400Protocol::set_profile (const string& profile_name)
631 map<string,DeviceProfile>::iterator d = DeviceProfile::device_profiles.find (profile_name);
633 if (d == DeviceProfile::device_profiles.end()) {
634 _device_profile = DeviceProfile (profile_name);
638 _device_profile = d->second;
642 US2400Protocol::set_device_info (const string& device_name)
648 US2400Protocol::set_device (const string& device_name, bool force)
650 if (device_name == device_info().name() && !force) {
651 /* already using that device, nothing to do */
654 /* get state from the current setup, and make sure it is stored in
655 the configuration_states node so that if we switch back to this device,
656 we will have its state available.
660 Glib::Threads::Mutex::Lock lm (surfaces_lock);
661 if (!surfaces.empty()) {
662 update_configuration_state ();
666 if (set_device_info (device_name)) {
671 port_connection.disconnect ();
672 hui_connection.disconnect ();
674 if (_device_info.device_type() == DeviceInfo::HUI) {
675 Glib::RefPtr<Glib::TimeoutSource> hui_timeout = Glib::TimeoutSource::create (1000); // milliseconds
676 hui_connection = hui_timeout->connect (sigc::mem_fun (*this, &US2400Protocol::hui_heartbeat));
677 hui_timeout->attach (main_loop()->get_context());
680 /* notice that the handler for this will execute in our event
681 loop, not in the thread where the
682 PortConnectedOrDisconnected signal is emitted.
684 ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connection, MISSING_INVALIDATOR, boost::bind (&US2400Protocol::connection_handler, this, _1, _2, _3, _4, _5), this);
686 if (create_surfaces ()) {
696 US2400Protocol::create_surfaces ()
699 surface_type_t stype = st_mcu; // type not yet determined
701 DEBUG_TRACE (DEBUG::US2400, string_compose ("Create %1 surfaces for %2\n", 1 + _device_info.extenders(), _device_info.name()));
703 _input_bundle.reset (new ARDOUR::Bundle (_("US2400 Control In"), true));
704 _output_bundle.reset (new ARDOUR::Bundle (_("US2400 Control Out"), false));
706 for (uint32_t n = 0; n < 1 + _device_info.extenders(); ++n) {
707 bool is_master = false;
709 if (n == _device_info.master_position()) {
713 device_name = string_compose (X_("US-2400 Control %1"), n+1);
715 DEBUG_TRACE (DEBUG::US2400, string_compose ("Port Name for surface %1 is %2\n", n, device_name));
717 boost::shared_ptr<Surface> surface;
722 stype = st_ext; //ch8..16
724 stype = st_ext; //ch17..24
726 stype = st_joy; //joystick
728 stype = st_knb; //chan knobs ???
731 surface.reset (new Surface (*this, device_name, n, stype));
737 _master_surface = surface;
740 if (configuration_state) {
741 XMLNode* this_device = 0;
742 XMLNodeList const& devices = configuration_state->children();
743 for (XMLNodeList::const_iterator d = devices.begin(); d != devices.end(); ++d) {
744 XMLProperty const * prop = (*d)->property (X_("name"));
745 if (prop && prop->value() == _device_info.name()) {
751 XMLNode* snode = this_device->child (X_("Surfaces"));
753 surface->set_state (*snode, state_version);
759 Glib::Threads::Mutex::Lock lm (surfaces_lock);
760 surfaces.push_back (surface);
763 if ( n <=3 ) { //ports 5&6 are not really used by us2400
765 _input_bundle->add_channel (
766 surface->port().input_port().name(),
767 ARDOUR::DataType::MIDI,
768 session->engine().make_port_name_non_relative (surface->port().input_port().name())
771 _output_bundle->add_channel (
772 surface->port().output_port().name(),
773 ARDOUR::DataType::MIDI,
774 session->engine().make_port_name_non_relative (surface->port().output_port().name())
778 MIDI::Port& input_port (surface->port().input_port());
779 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*> (&input_port);
783 /* async MIDI port */
785 asp->xthread().set_receive_handler (sigc::bind (sigc::mem_fun (this, &US2400Protocol::midi_input_handler), &input_port));
786 asp->xthread().attach (main_loop()->get_context());
791 Glib::Threads::Mutex::Lock lm (surfaces_lock);
792 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
793 (*s)->port().reconnect ();
796 session->BundleAddedOrRemoved ();
798 assert (_master_surface);
804 US2400Protocol::close()
806 port_connection.disconnect ();
807 session_connections.drop_connections ();
808 stripable_connections.drop_connections ();
809 periodic_connection.disconnect ();
814 /** Ensure that the configuration_state XML node contains an up-to-date
815 * copy of the state node the current device. If configuration_state already
816 * contains a state node for the device, it will deleted and replaced.
819 US2400Protocol::update_configuration_state ()
821 /* CALLER MUST HOLD SURFACES LOCK */
823 if (!configuration_state) {
824 configuration_state = new XMLNode (X_("Configurations"));
827 XMLNode* devnode = new XMLNode (X_("Configuration"));
828 devnode->set_property (X_("name"), _device_info.name());
830 configuration_state->remove_nodes_and_delete (X_("name"), _device_info.name());
831 configuration_state->add_child_nocopy (*devnode);
833 XMLNode* snode = new XMLNode (X_("Surfaces"));
835 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
836 snode->add_child_nocopy ((*s)->get_state());
839 devnode->add_child_nocopy (*snode);
843 US2400Protocol::get_state()
845 XMLNode& node (ControlProtocol::get_state());
847 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::get_state init\n");
850 node.set_property (X_("bank"), _current_initial_bank);
852 node.set_property (X_("device-profile"), _device_profile.name());
853 node.set_property (X_("device-name"), _device_info.name());
856 Glib::Threads::Mutex::Lock lm (surfaces_lock);
857 update_configuration_state ();
860 /* force a copy of the _surfaces_state node, because we want to retain ownership */
861 node.add_child_copy (*configuration_state);
863 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::get_state done\n");
869 US2400Protocol::profile_exists (string const & name) const
871 return DeviceProfile::device_profiles.find (name) != DeviceProfile::device_profiles.end();
875 US2400Protocol::set_state (const XMLNode & node, int version)
877 DEBUG_TRACE (DEBUG::US2400, string_compose ("US2400Protocol::set_state: active %1\n", active()));
879 if (ControlProtocol::set_state (node, version)) {
884 // fetch current bank
885 node.get_property (X_("bank"), bank);
887 std::string device_name;
888 if (node.get_property (X_("device-name"), device_name)) {
889 set_device_info (device_name);
892 std::string device_profile_name;
893 if (node.get_property (X_("device-profile"), device_profile_name)) {
894 if (device_profile_name.empty()) {
895 string default_profile_name;
897 /* start by looking for a user-edited profile for the current device name */
899 default_profile_name = DeviceProfile::name_when_edited (_device_info.name());
901 if (!profile_exists (default_profile_name)) {
903 /* no user-edited profile for this device name, so try the user-edited default profile */
905 default_profile_name = DeviceProfile::name_when_edited (DeviceProfile::default_profile_name);
907 if (!profile_exists (default_profile_name)) {
909 /* no user-edited version, so just try the device name */
911 default_profile_name = _device_info.name();
913 if (!profile_exists (default_profile_name)) {
915 /* no generic device specific profile, just try the fixed default */
916 default_profile_name = DeviceProfile::default_profile_name;
921 set_profile (default_profile_name);
924 if (profile_exists (device_profile_name)) {
925 set_profile (device_profile_name);
927 set_profile (DeviceProfile::default_profile_name);
932 XMLNode* dnode = node.child (X_("Configurations"));
934 delete configuration_state;
935 configuration_state = 0;
938 configuration_state = new XMLNode (*dnode);
939 state_version = version;
942 (void) switch_banks (bank, true);
944 DEBUG_TRACE (DEBUG::US2400, "US2400Protocol::set_state done\n");
949 ///////////////////////////////////////////
951 ///////////////////////////////////////////
953 void US2400Protocol::notify_parameter_changed (std::string const & p)
958 US2400Protocol::notify_stripable_removed ()
960 Glib::Threads::Mutex::Lock lm (surfaces_lock);
961 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
962 (*s)->master_monitor_may_have_changed ();
967 US2400Protocol::notify_vca_added (ARDOUR::VCAList& vl)
969 refresh_current_bank ();
972 // RouteList is the set of Routes that have just been added
974 US2400Protocol::notify_routes_added (ARDOUR::RouteList & rl)
977 Glib::Threads::Mutex::Lock lm (surfaces_lock);
979 if (surfaces.empty()) {
984 /* special case: single route, and it is the monitor or master out */
986 if (rl.size() == 1 && (rl.front()->is_monitor() || rl.front()->is_master())) {
987 Glib::Threads::Mutex::Lock lm (surfaces_lock);
988 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
989 (*s)->master_monitor_may_have_changed ();
993 // currently assigned banks are less than the full set of
994 // strips, so activate the new strip now.
996 refresh_current_bank();
998 // otherwise route added, but current bank needs no updating
1002 US2400Protocol::notify_solo_active_changed (bool active)
1004 boost::shared_ptr<Surface> surface;
1007 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1009 if (surfaces.empty()) {
1013 surface = _master_surface;
1016 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (Led::RudeSolo);
1017 if (x != surface->controls_by_device_independent_id.end()) {
1018 Led* rude_solo = dynamic_cast<Led*> (x->second);
1020 surface->write (rude_solo->set_state (active ? flashing : off));
1026 US2400Protocol::notify_presentation_info_changed (PBD::PropertyChange const & what_changed)
1028 PBD::PropertyChange order_or_hidden;
1030 order_or_hidden.add (Properties::hidden);
1031 order_or_hidden.add (Properties::order);
1033 if (!what_changed.contains (order_or_hidden)) {
1038 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1040 if (surfaces.empty()) {
1045 refresh_current_bank();
1048 ///////////////////////////////////////////
1049 // Transport signals
1050 ///////////////////////////////////////////
1053 US2400Protocol::notify_loop_state_changed()
1058 US2400Protocol::notify_transport_state_changed()
1060 if (!_device_info.has_global_controls()) {
1064 // switch various play and stop buttons on / off
1065 update_global_button (Button::Play, session->transport_speed() == 1.0);
1066 update_global_button (Button::Stop, session->transport_stopped_or_stopping ());
1067 update_global_button (Button::Rewind, session->transport_speed() < 0.0);
1068 update_global_button (Button::Ffwd, session->transport_speed() > 1.0);
1070 // sometimes a return to start leaves time code at old time
1071 _timecode_last = string (10, ' ');
1073 notify_metering_state_changed ();
1077 US2400Protocol::notify_metering_state_changed()
1079 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1081 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1082 (*s)->notify_metering_state_changed ();
1087 US2400Protocol::notify_record_state_changed ()
1089 if (!_device_info.has_global_controls()) {
1093 boost::shared_ptr<Surface> surface;
1096 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1097 if (surfaces.empty()) {
1100 surface = _master_surface;
1103 /* rec is a tristate */
1105 map<int,Control*>::iterator x = surface->controls_by_device_independent_id.find (Button::Record);
1106 if (x != surface->controls_by_device_independent_id.end()) {
1107 Button * rec = dynamic_cast<Button*> (x->second);
1111 switch (session->record_status()) {
1112 case Session::Disabled:
1113 DEBUG_TRACE (DEBUG::US2400, "record state changed to disabled, LED off\n");
1116 case Session::Recording:
1117 DEBUG_TRACE (DEBUG::US2400, "record state changed to recording, LED on\n");
1120 case Session::Enabled:
1121 DEBUG_TRACE (DEBUG::US2400, "record state changed to enabled, LED flashing\n");
1126 surface->write (rec->set_state (ls));
1131 list<boost::shared_ptr<ARDOUR::Bundle> >
1132 US2400Protocol::bundles ()
1134 list<boost::shared_ptr<ARDOUR::Bundle> > b;
1136 if (_input_bundle) {
1137 b.push_back (_input_bundle);
1138 b.push_back (_output_bundle);
1145 US2400Protocol::do_request (US2400ControlUIRequest* req)
1147 DEBUG_TRACE (DEBUG::US2400, string_compose ("doing request type %1\n", req->type));
1148 if (req->type == CallSlot) {
1150 call_slot (MISSING_INVALIDATOR, req->the_slot);
1152 } else if (req->type == Quit) {
1159 US2400Protocol::stop ()
1167 US2400Protocol::update_led (Surface& surface, Button& button, US2400::LedState ls)
1170 surface.port().write (button.set_state (ls));
1175 US2400Protocol::build_button_map ()
1177 /* this maps our device-independent button codes to the methods that handle them.
1180 #define DEFINE_BUTTON_HANDLER(b,p,r) button_map.insert (pair<Button::ID,ButtonHandlers> ((b), ButtonHandlers ((p),(r))));
1182 DEFINE_BUTTON_HANDLER (Button::Solo, &US2400Protocol::clearsolo_press, &US2400Protocol::clearsolo_release); // ClearSolo button == Option+Solo lands here.
1184 DEFINE_BUTTON_HANDLER (Button::Send, &US2400Protocol::send_press, &US2400Protocol::send_release);
1185 DEFINE_BUTTON_HANDLER (Button::Pan, &US2400Protocol::pan_press, &US2400Protocol::pan_release);
1186 DEFINE_BUTTON_HANDLER (Button::Left, &US2400Protocol::left_press, &US2400Protocol::left_release);
1187 DEFINE_BUTTON_HANDLER (Button::Right, &US2400Protocol::right_press, &US2400Protocol::right_release);
1188 DEFINE_BUTTON_HANDLER (Button::Flip, &US2400Protocol::flip_press, &US2400Protocol::flip_release);
1189 DEFINE_BUTTON_HANDLER (Button::MstrSelect, &US2400Protocol::mstr_press, &US2400Protocol::mstr_release);
1190 // DEFINE_BUTTON_HANDLER (Button::F1, &US2400Protocol::F1_press, &US2400Protocol::F1_release);
1191 // DEFINE_BUTTON_HANDLER (Button::F2, &US2400Protocol::F2_press, &US2400Protocol::F2_release);
1192 // DEFINE_BUTTON_HANDLER (Button::F3, &US2400Protocol::F3_press, &US2400Protocol::F3_release);
1193 // DEFINE_BUTTON_HANDLER (Button::F4, &US2400Protocol::F4_press, &US2400Protocol::F4_release);
1194 // DEFINE_BUTTON_HANDLER (Button::F5, &US2400Protocol::F5_press, &US2400Protocol::F5_release);
1195 // DEFINE_BUTTON_HANDLER (Button::F6, &US2400Protocol::F6_press, &US2400Protocol::F6_release);
1196 DEFINE_BUTTON_HANDLER (Button::Shift, &US2400Protocol::shift_press, &US2400Protocol::shift_release);
1197 DEFINE_BUTTON_HANDLER (Button::Option, &US2400Protocol::option_press, &US2400Protocol::option_release);
1198 DEFINE_BUTTON_HANDLER (Button::Drop, &US2400Protocol::drop_press, &US2400Protocol::drop_release);
1199 DEFINE_BUTTON_HANDLER (Button::Rewind, &US2400Protocol::rewind_press, &US2400Protocol::rewind_release);
1200 DEFINE_BUTTON_HANDLER (Button::Ffwd, &US2400Protocol::ffwd_press, &US2400Protocol::ffwd_release);
1201 DEFINE_BUTTON_HANDLER (Button::Stop, &US2400Protocol::stop_press, &US2400Protocol::stop_release);
1202 DEFINE_BUTTON_HANDLER (Button::Play, &US2400Protocol::play_press, &US2400Protocol::play_release);
1203 DEFINE_BUTTON_HANDLER (Button::Record, &US2400Protocol::record_press, &US2400Protocol::record_release);
1204 DEFINE_BUTTON_HANDLER (Button::Scrub, &US2400Protocol::scrub_press, &US2400Protocol::scrub_release);
1205 DEFINE_BUTTON_HANDLER (Button::MasterFaderTouch, &US2400Protocol::master_fader_touch_press, &US2400Protocol::master_fader_touch_release);
1209 US2400Protocol::handle_button_event (Surface& surface, Button& button, ButtonState bs)
1211 Button::ID button_id = button.bid();
1213 if (bs != press && bs != release) {
1214 update_led (surface, button, none);
1218 DEBUG_TRACE (DEBUG::US2400, string_compose ("Handling %1 for button %2 (%3)\n", (bs == press ? "press" : "release"), button.id(),
1219 Button::id_to_name (button.bid())));
1221 /* check profile first */
1223 string action = _device_profile.get_button_action (button.bid(), _modifier_state);
1225 DEBUG_TRACE (DEBUG::US2400, string_compose ("device profile returned [%1] for that button\n", action));
1227 if (!action.empty()) {
1229 if (action.find ('/') != string::npos) { /* good chance that this is really an action */
1231 DEBUG_TRACE (DEBUG::US2400, string_compose ("Looked up action for button %1 with modifier %2, got [%3]\n",
1232 button.bid(), _modifier_state, action));
1234 /* if there is a bound action for this button, and this is a press event,
1235 carry out the action. If its a release event, do nothing since we
1236 don't bind to them at all but don't want any other handling to
1240 update_led (surface, button, on);
1241 DEBUG_TRACE (DEBUG::US2400, string_compose ("executing action %1\n", action));
1242 access_action (action);
1244 update_led (surface, button, off);
1250 /* "action" is more likely to be a button name. We use this to
1251 * allow remapping buttons to different (builtin) functionality
1252 * associated with an existing button. This is similar to the
1253 * way that (for example) Nuendo moves the "Shift" function to
1254 * the "Enter" key of the MCU Pro.
1257 int bid = Button::name_to_id (action);
1260 DEBUG_TRACE (DEBUG::US2400, string_compose ("apparent button name %1 not found\n", action));
1264 button_id = (Button::ID) bid;
1265 DEBUG_TRACE (DEBUG::US2400, 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)));
1269 /* Now that we have the correct (maybe remapped) button ID, do these
1273 /* lookup using the device-INDEPENDENT button ID */
1275 DEBUG_TRACE (DEBUG::US2400, string_compose ("now looking up button ID %1\n", button_id));
1277 ButtonMap::iterator b = button_map.find (button_id);
1279 if (b != button_map.end()) {
1281 ButtonHandlers& bh (b->second);
1283 DEBUG_TRACE (DEBUG::US2400, string_compose ("button found in map, now invoking %1\n", (bs == press ? "press" : "release")));
1287 surface.write (button.set_state ((this->*(bh.press)) (button)));
1290 surface.write (button.set_state ((this->*(bh.release)) (button)));
1296 DEBUG_TRACE (DEBUG::US2400, string_compose ("no button handlers for button ID %1 (device ID %2)\n",
1297 button.bid(), button.id()));
1298 error << string_compose ("no button handlers for button ID %1 (device ID %2)\n",
1299 button.bid(), button.id()) << endmsg;
1304 US2400Protocol::midi_input_handler (IOCondition ioc, MIDI::Port* port)
1307 DEBUG_TRACE (DEBUG::US2400, "MIDI port closed\n");
1313 // DEBUG_TRACE (DEBUG::US2400, string_compose ("something happend on %1\n", port->name()));
1315 /* Devices using regular JACK MIDI ports will need to have
1316 the x-thread FIFO drained to avoid burning endless CPU.
1319 AsyncMIDIPort* asp = dynamic_cast<AsyncMIDIPort*>(port);
1324 // DEBUG_TRACE (DEBUG::US2400, string_compose ("data available on %1\n", port->name()));
1325 samplepos_t now = session->engine().sample_time();
1333 US2400Protocol::clear_ports ()
1335 if (_input_bundle) {
1336 _input_bundle->remove_channels ();
1337 _output_bundle->remove_channels ();
1342 US2400Protocol::notify_subview_stripable_deleted ()
1344 /* return to global/mixer view */
1345 _subview_stripable.reset ();
1346 set_view_mode (Mixer);
1350 US2400Protocol::subview_mode_would_be_ok (SubViewMode mode, boost::shared_ptr<Stripable> r)
1367 US2400Protocol::redisplay_subview_mode ()
1369 Surfaces copy; /* can't hold surfaces lock while calling Strip::subview_mode_changed */
1372 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1376 for (Surfaces::iterator s = copy.begin(); s != copy.end(); ++s) {
1377 (*s)->subview_mode_changed ();
1380 /* don't call this again from a timeout */
1385 US2400Protocol::set_subview_mode (SubViewMode sm, boost::shared_ptr<Stripable> r)
1387 if (!subview_mode_would_be_ok (sm, r)) {
1389 DEBUG_TRACE (DEBUG::US2400, "subview mode not OK\n");
1393 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1395 if (!surfaces.empty()) {
1401 msg = _("no track view possible");
1411 boost::shared_ptr<Stripable> old_stripable = _subview_stripable;
1414 _subview_stripable = r;
1416 if (_subview_stripable != old_stripable) {
1417 subview_stripable_connections.drop_connections ();
1419 /* Catch the current subview stripable going away */
1420 if (_subview_stripable) {
1421 _subview_stripable->DropReferences.connect (subview_stripable_connections, MISSING_INVALIDATOR,
1422 boost::bind (&US2400Protocol::notify_subview_stripable_deleted, this),
1427 redisplay_subview_mode ();
1429 /* turn buttons related to vpot mode on or off as required */
1431 switch (_subview_mode) {
1432 case US2400Protocol::None:
1433 update_global_button (Button::Send, off);
1434 update_global_button (Button::Pan, on);
1436 case US2400Protocol::TrackView:
1437 update_global_button (Button::Send, off);
1438 update_global_button (Button::Pan, off);
1446 US2400Protocol::set_view_mode (ViewMode m)
1448 ViewMode old_view_mode = _view_mode;
1451 _last_bank[old_view_mode] = _current_initial_bank;
1453 if (switch_banks(_last_bank[m], true)) {
1454 _view_mode = old_view_mode;
1458 /* leave subview mode, whatever it was */
1459 set_subview_mode (None, boost::shared_ptr<Stripable>());
1463 US2400Protocol::display_view_mode ()
1469 US2400Protocol::set_master_on_surface_strip (uint32_t surface, uint32_t strip_number)
1471 force_special_stripable_to_strip (session->master_out(), surface, strip_number);
1475 US2400Protocol::set_monitor_on_surface_strip (uint32_t surface, uint32_t strip_number)
1477 force_special_stripable_to_strip (session->monitor_out(), surface, strip_number);
1481 US2400Protocol::force_special_stripable_to_strip (boost::shared_ptr<Stripable> r, uint32_t surface, uint32_t strip_number)
1487 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1489 for (Surfaces::iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1490 if ((*s)->number() == surface) {
1491 Strip* strip = (*s)->nth_strip (strip_number);
1493 strip->set_stripable (session->master_out());
1494 strip->lock_controls ();
1501 US2400Protocol::check_fader_automation_state ()
1506 US2400Protocol::update_fader_automation_state ()
1511 US2400Protocol::transport_sample() const
1513 return session->transport_sample();
1517 US2400Protocol::add_down_select_button (int surface, int strip)
1519 _down_select_buttons.insert ((surface<<8)|(strip&0xf));
1523 US2400Protocol::remove_down_select_button (int surface, int strip)
1525 DownButtonList::iterator x = find (_down_select_buttons.begin(), _down_select_buttons.end(), (uint32_t) (surface<<8)|(strip&0xf));
1526 DEBUG_TRACE (DEBUG::US2400, string_compose ("removing surface %1 strip %2 from down select buttons\n", surface, strip));
1527 if (x != _down_select_buttons.end()) {
1528 _down_select_buttons.erase (x);
1530 DEBUG_TRACE (DEBUG::US2400, string_compose ("surface %1 strip %2 not found in down select buttons\n",
1536 US2400Protocol::select_range (uint32_t pressed)
1538 StripableList stripables;
1540 pull_stripable_range (_down_select_buttons, stripables, pressed);
1542 DEBUG_TRACE (DEBUG::US2400, string_compose ("select range: found %1 stripables, first = %2\n", stripables.size(),
1543 (stripables.empty() ? "null" : stripables.front()->name())));
1545 if (stripables.empty()) {
1549 if (stripables.size() == 1 && ControlProtocol::last_selected().size() == 1 && stripables.front()->is_selected()) {
1550 /* cancel selection for one and only selected stripable */
1551 ToggleStripableSelection (stripables.front());
1553 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
1555 if (main_modifier_state() == MODIFIER_SHIFT) {
1556 ToggleStripableSelection (*s);
1558 if (s == stripables.begin()) {
1559 SetStripableSelection (*s);
1561 AddStripableToSelection (*s);
1569 US2400Protocol::add_down_button (AutomationType a, int surface, int strip)
1571 DownButtonMap::iterator m = _down_buttons.find (a);
1573 if (m == _down_buttons.end()) {
1574 _down_buttons[a] = DownButtonList();
1577 _down_buttons[a].insert ((surface<<8)|(strip&0xf));
1581 US2400Protocol::remove_down_button (AutomationType a, int surface, int strip)
1583 DownButtonMap::iterator m = _down_buttons.find (a);
1585 DEBUG_TRACE (DEBUG::US2400, string_compose ("removing surface %1 strip %2 from down buttons for %3\n", surface, strip, (int) a));
1587 if (m == _down_buttons.end()) {
1591 DownButtonList& l (m->second);
1592 DownButtonList::iterator x = find (l.begin(), l.end(), (surface<<8)|(strip&0xf));
1597 DEBUG_TRACE (DEBUG::US2400, string_compose ("surface %1 strip %2 not found in down buttons for %3\n",
1598 surface, strip, (int) a));
1602 US2400Protocol::ControlList
1603 US2400Protocol::down_controls (AutomationType p, uint32_t pressed)
1605 ControlList controls;
1606 StripableList stripables;
1608 DownButtonMap::iterator m = _down_buttons.find (p);
1610 if (m == _down_buttons.end()) {
1614 DEBUG_TRACE (DEBUG::US2400, string_compose ("looking for down buttons for %1, got %2\n",
1615 p, m->second.size()));
1617 pull_stripable_range (m->second, stripables, pressed);
1620 case GainAutomation:
1621 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
1622 controls.push_back ((*s)->gain_control());
1625 case SoloAutomation:
1626 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
1627 controls.push_back ((*s)->solo_control());
1630 case MuteAutomation:
1631 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
1632 controls.push_back ((*s)->mute_control());
1635 case RecEnableAutomation:
1636 for (StripableList::iterator s = stripables.begin(); s != stripables.end(); ++s) {
1637 boost::shared_ptr<AutomationControl> ac = (*s)->rec_enable_control();
1639 controls.push_back (ac);
1651 struct ButtonRangeSorter {
1652 bool operator() (const uint32_t& a, const uint32_t& b) {
1653 return (a>>8) < (b>>8) // a.surface < b.surface
1655 ((a>>8) == (b>>8) && (a&0xf) < (b&0xf)); // a.surface == b.surface && a.strip < b.strip
1660 US2400Protocol::pull_stripable_range (DownButtonList& down, StripableList& selected, uint32_t pressed)
1662 ButtonRangeSorter cmp;
1668 list<uint32_t> ldown;
1669 ldown.insert (ldown.end(), down.begin(), down.end());
1672 uint32_t first = ldown.front();
1673 uint32_t last = ldown.back ();
1675 uint32_t first_surface = first>>8;
1676 uint32_t first_strip = first&0xf;
1678 uint32_t last_surface = last>>8;
1679 uint32_t last_strip = last&0xf;
1681 DEBUG_TRACE (DEBUG::US2400, string_compose ("PRR %5 in list %1.%2 - %3.%4\n", first_surface, first_strip, last_surface, last_strip,
1684 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1686 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1688 if ((*s)->number() >= first_surface && (*s)->number() <= last_surface) {
1693 if ((*s)->number() == first_surface) {
1699 if ((*s)->number() == last_surface) {
1703 ls = (*s)->n_strips ();
1706 DEBUG_TRACE (DEBUG::US2400, string_compose ("adding strips for surface %1 (%2 .. %3)\n",
1707 (*s)->number(), fs, ls));
1709 for (uint32_t n = fs; n < ls; ++n) {
1710 Strip* strip = (*s)->nth_strip (n);
1711 boost::shared_ptr<Stripable> r = strip->stripable();
1713 if (global_index_locked (*strip) == pressed) {
1714 selected.push_front (r);
1716 selected.push_back (r);
1726 US2400Protocol::clear_surfaces ()
1731 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1732 _master_surface.reset ();
1738 US2400Protocol::set_touch_sensitivity (int sensitivity)
1740 sensitivity = min (9, sensitivity);
1741 sensitivity = max (0, sensitivity);
1743 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1745 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1746 (*s)->set_touch_sensitivity (sensitivity);
1751 US2400Protocol::recalibrate_faders ()
1753 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1755 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1756 (*s)->recalibrate_faders ();
1761 US2400Protocol::toggle_backlight ()
1763 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1765 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1766 (*s)->toggle_backlight ();
1770 boost::shared_ptr<Surface>
1771 US2400Protocol::get_surface_by_raw_pointer (void* ptr) const
1773 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1775 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1776 if ((*s).get() == (Surface*) ptr) {
1781 return boost::shared_ptr<Surface> ();
1784 boost::shared_ptr<Surface>
1785 US2400Protocol::nth_surface (uint32_t n) const
1787 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1789 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s, --n) {
1795 return boost::shared_ptr<Surface> ();
1799 US2400Protocol::connection_handler (boost::weak_ptr<ARDOUR::Port> wp1, std::string name1, boost::weak_ptr<ARDOUR::Port> wp2, std::string name2, bool yn)
1803 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1807 for (Surfaces::const_iterator s = scopy.begin(); s != scopy.end(); ++s) {
1808 if ((*s)->connection_handler (wp1, name1, wp2, name2, yn)) {
1809 ConnectionChange (*s);
1816 US2400Protocol::is_track (boost::shared_ptr<Stripable> r) const
1818 return boost::dynamic_pointer_cast<Track>(r) != 0;
1822 US2400Protocol::is_audio_track (boost::shared_ptr<Stripable> r) const
1824 return boost::dynamic_pointer_cast<AudioTrack>(r) != 0;
1828 US2400Protocol::is_midi_track (boost::shared_ptr<Stripable> r) const
1830 return boost::dynamic_pointer_cast<MidiTrack>(r) != 0;
1834 US2400Protocol::is_mapped (boost::shared_ptr<Stripable> r) const
1836 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1838 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1839 if ((*s)->stripable_is_mapped (r)) {
1848 US2400Protocol::stripable_selection_changed ()
1850 //this function is called after the stripable selection is "stable", so this is the place to check surface selection state
1851 for (Surfaces::iterator si = surfaces.begin(); si != surfaces.end(); ++si) {
1852 (*si)->update_strip_selection ();
1855 //first check for the dedicated Master strip
1856 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
1857 if (s && s->is_master()) {
1858 update_global_button(Button::MstrSelect, on); //NOTE: surface does not respond to this
1860 update_global_button(Button::MstrSelect, off);
1862 //not the master; now check for other strips ( this will only allow a selection if the strip is mapped on our surface )
1863 s = first_selected_stripable ();
1867 check_fader_automation_state ();
1869 /* It is possible that first_selected_route() may return null if we
1870 * are no longer displaying/mapping that route. In that case,
1871 * we will exit subview mode. If first_selected_route() is
1872 * null, and subview mode is not None, then the first call to
1873 * set_subview_mode() will fail, and we will reset to None.
1876 if (set_subview_mode (TrackView, s)) {
1877 set_subview_mode (None, boost::shared_ptr<Stripable>());
1881 set_subview_mode (None, boost::shared_ptr<Stripable>());
1884 boost::shared_ptr<Stripable>
1885 US2400Protocol::first_selected_stripable () const
1887 boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
1890 /* check it is on one of our surfaces */
1892 if (is_mapped (s)) {
1896 /* stripable is not mapped. thus, the currently selected stripable is
1897 * not on the surfaces, and so from our perspective, there is
1898 * no currently selected stripable.
1904 return s; /* may be null */
1907 boost::shared_ptr<Stripable>
1908 US2400Protocol::subview_stripable () const
1910 return _subview_stripable;
1914 US2400Protocol::global_index (Strip& strip)
1916 Glib::Threads::Mutex::Lock lm (surfaces_lock);
1917 return global_index_locked (strip);
1921 US2400Protocol::global_index_locked (Strip& strip)
1923 uint32_t global = 0;
1925 for (Surfaces::const_iterator s = surfaces.begin(); s != surfaces.end(); ++s) {
1926 if ((*s).get() == strip.surface()) {
1927 return global + strip.index();
1929 global += (*s)->n_strips ();
1936 US2400Protocol::request_factory (uint32_t num_requests)
1938 /* AbstractUI<T>::request_buffer_factory() is a template method only
1939 instantiated in this source module. To provide something visible for
1940 use in the interface/descriptor, we have this static method that is
1943 return request_buffer_factory (num_requests);
1947 US2400Protocol::set_automation_state (AutoState as)
1949 boost::shared_ptr<Stripable> r = first_selected_stripable ();
1955 boost::shared_ptr<AutomationControl> ac = r->gain_control();
1961 ac->set_automation_state (as);