X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fsurfaces%2Fmackie%2Fsurface.cc;h=ec8192f91dd33dfbe21f20c47104d81affd237f8;hb=b5dbfc9931bc586fb2b5a50a2493e8c158c99896;hp=411a4ea47551e7d8e52e3a8da6d4afeccf82d9e7;hpb=6899bd7c158834d3dc795a408ab37b049ada5e72;p=ardour.git diff --git a/libs/surfaces/mackie/surface.cc b/libs/surfaces/mackie/surface.cc index 411a4ea475..ec8192f91d 100644 --- a/libs/surfaces/mackie/surface.cc +++ b/libs/surfaces/mackie/surface.cc @@ -23,6 +23,10 @@ #include #include +#include + +#include "pbd/stacktrace.h" + #include "midi++/port.h" #include "ardour/audioengine.h" @@ -31,10 +35,13 @@ #include "ardour/route.h" #include "ardour/panner.h" #include "ardour/panner_shell.h" +#include "ardour/profile.h" #include "ardour/rc_configuration.h" #include "ardour/session.h" #include "ardour/utils.h" +#include + #include "control_group.h" #include "surface_port.h" #include "surface.h" @@ -50,7 +57,7 @@ #include "jog.h" #include "meter.h" -#include "i18n.h" +#include "pbd/i18n.h" #ifdef PLATFORM_WINDOWS #define random() rand() @@ -58,9 +65,9 @@ using namespace std; using namespace PBD; -using ARDOUR::Route; +using ARDOUR::Stripable; using ARDOUR::Panner; -using ARDOUR::Pannable; +using ARDOUR::Profile; using ARDOUR::AutomationControl; using namespace ArdourSurface; using namespace Mackie; @@ -90,6 +97,7 @@ Surface::Surface (MackieControlProtocol& mcp, const std::string& device_name, ui , _master_fader (0) , _last_master_gain_written (-0.0f) , connection_state (0) + , input_source (0) { DEBUG_TRACE (DEBUG::MackieControl, "Surface::Surface init\n"); @@ -122,10 +130,18 @@ Surface::Surface (MackieControlProtocol& mcp, const std::string& device_name, ui DEBUG_TRACE (DEBUG::MackieControl, "init_strips done\n"); } - /* - */ + if (_mcp.device_info().uses_ipmidi()) { + /* ipMIDI port already exists, we can just assume that we're + * connected. + * + * If the user still hasn't connected the ipMIDI surface and/or + * turned it on, then they have to press "Discover Mackie + * Devices" in the GUI at the right time. + */ - ARDOUR::AudioEngine::instance()->PortConnectedOrDisconnected.connect (port_connection, MISSING_INVALIDATOR, boost::bind (&Surface::connection_handler, this, _1, _2, _3, _4, _5), &_mcp); + connection_state |= (InputConnected|OutputConnected); + connected (); + } connect_to_signals (); @@ -136,27 +152,36 @@ Surface::~Surface () { DEBUG_TRACE (DEBUG::MackieControl, "Surface::~Surface init\n"); - // zero_all (); + if (input_source) { + g_source_destroy (input_source); + input_source = 0; + } - // delete groups + // delete groups (strips) for (Groups::iterator it = groups.begin(); it != groups.end(); ++it) { delete it->second; } - // delete controls + // delete controls (global buttons, master fader etc) for (Controls::iterator it = controls.begin(); it != controls.end(); ++it) { delete *it; } delete _jog_wheel; delete _port; - + // the ports take time to release and we may be rebuilding right away + // in the case of changing devices. + g_usleep (10000); DEBUG_TRACE (DEBUG::MackieControl, "Surface::~Surface done\n"); } -void +bool Surface::connection_handler (boost::weak_ptr, std::string name1, boost::weak_ptr, std::string name2, bool yn) { + if (!_port) { + return false; + } + string ni = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (_port->input_name()); string no = ARDOUR::AudioEngine::instance()->make_port_name_non_relative (_port->output_name()); @@ -172,6 +197,9 @@ Surface::connection_handler (boost::weak_ptr, std::string name1, b } else { connection_state &= ~OutputConnected; } + } else { + /* not our ports */ + return false; } if ((connection_state & (InputConnected|OutputConnected)) == (InputConnected|OutputConnected)) { @@ -200,32 +228,48 @@ Surface::connection_handler (boost::weak_ptr, std::string name1, b to queue it with the MCP event loop. */ + /* XXX this is a horrible hack. Without a short sleep here, + something prevents the device wakeup messages from being + sent and/or the responses from being received. + */ + + g_usleep (100000); connected (); } else { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface %1 disconnected (input or output or both)\n", _name)); _active = false; } + + return true; /* connection status changed */ } XMLNode& Surface::get_state() { - char buf[64]; - snprintf (buf, sizeof (buf), X_("surface-%u"), _number); - XMLNode* node = new XMLNode (buf); - + XMLNode* node = new XMLNode (X_("Surface")); + node->add_property (X_("name"), _name); node->add_child_nocopy (_port->get_state()); - return *node; } int Surface::set_state (const XMLNode& node, int version) { - char buf[64]; - snprintf (buf, sizeof (buf), X_("surface-%u"), _number); - XMLNode* mynode = node.child (buf); + /* Look for a node named after the device we're part of */ + + XMLNodeList const& children = node.children(); + XMLNode* mynode = 0; + + for (XMLNodeList::const_iterator c = children.begin(); c != children.end(); ++c) { + XMLProperty const* prop = (*c)->property (X_("name")); + if (prop) { + if (prop->value() == _name) { + mynode = *c; + break; + } + } + } if (!mynode) { return 0; @@ -322,38 +366,64 @@ Surface::init_strips (uint32_t n) } } +void +Surface::master_monitor_may_have_changed () +{ + if (_number == _mcp.device_info().master_position()) { + setup_master (); + } +} + void Surface::setup_master () { - boost::shared_ptr m; + boost::shared_ptr m; if ((m = _mcp.get_session().monitor_out()) == 0) { m = _mcp.get_session().master_out(); } if (!m) { + if (_master_fader) { + _master_fader->set_control (boost::shared_ptr()); + } + master_connection.disconnect (); return; } - _master_fader = dynamic_cast (Fader::factory (*this, _mcp.device_info().strip_cnt(), "master", *groups["master"])); + if (!_master_fader) { + Groups::iterator group_it; + Group* master_group; + group_it = groups.find("master"); + + if (group_it == groups.end()) { + groups["master"] = master_group = new Group ("master"); + } else { + master_group = group_it->second; + } + + _master_fader = dynamic_cast (Fader::factory (*this, _mcp.device_info().strip_cnt(), "master", *master_group)); + + DeviceInfo device_info = _mcp.device_info(); + GlobalButtonInfo master_button = device_info.get_global_button(Button::MasterFaderTouch); + Button* bb = dynamic_cast (Button::factory ( + *this, + Button::MasterFaderTouch, + master_button.id, + master_button.label, + *(group_it->second) + )); + + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 Master Fader new button BID %2 id %3\n", + number(), Button::MasterFaderTouch, bb->id())); + } else { + master_connection.disconnect (); + } _master_fader->set_control (m->gain_control()); - m->gain_control()->Changed.connect (*this, MISSING_INVALIDATOR, boost::bind (&Surface::master_gain_changed, this), ui_context()); - - Groups::iterator group_it; - group_it = groups.find("master"); - - DeviceInfo device_info = _mcp.device_info(); - GlobalButtonInfo master_button = device_info.get_global_button(Button::MasterFaderTouch); - Button* bb = dynamic_cast (Button::factory ( - *this, - Button::MasterFaderTouch, - master_button.id, - master_button.label, - *(group_it->second) -)); - DEBUG_TRACE (DEBUG::MackieControl, string_compose ("surface %1 Master Fader new button BID %2 id %3\n", - number(), Button::MasterFaderTouch, bb->id())); + m->gain_control()->Changed.connect (master_connection, MISSING_INVALIDATOR, boost::bind (&Surface::master_gain_changed, this), ui_context()); + _last_master_gain_written = FLT_MAX; /* some essentially impossible value */ + master_gain_changed (); } void @@ -468,14 +538,6 @@ Surface::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb, uin turn_it_on (); } - if (_mcp.main_modifier_state() & MackieControlProtocol::MODIFIER_SHIFT) { - /* user is doing a reset to unity gain but device sends a PB - * message in the middle of the touch on/off messages. Ignore - * it. - */ - return; - } - Fader* fader = faders[fader_id]; if (fader) { @@ -584,7 +646,7 @@ Surface::handle_midi_controller_message (MIDI::Parser &, MIDI::EventTwoBytes* ev } float delta = 0; - if (mcp().main_modifier_state() == MackieControlProtocol::MODIFIER_CONTROL) { + if (mcp().main_modifier_state() == MackieControlProtocol::MODIFIER_SHIFT) { delta = sign * (ticks / (float) 0xff); } else { delta = sign * (ticks / (float) 0x3f); @@ -613,8 +675,6 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count { MidiByteArray bytes (count, raw_bytes); - DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handle_midi_sysex: %1\n", bytes)); - if (_mcp.device_info().no_handshake()) { turn_it_on (); } @@ -631,6 +691,9 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count switch (bytes[5]) { case 0x01: + if (!_active) { + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handle_midi_sysex: %1\n", bytes)); + } /* MCP: Device Ready LCP: Connection Challenge */ @@ -638,26 +701,41 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count DEBUG_TRACE (DEBUG::MackieControl, "Logic Control Device connection challenge\n"); write_sysex (host_connection_query (bytes)); } else { - DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Mackie Control Device ready, current status = %1\n", _active)); if (!_active) { - turn_it_on (); + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Mackie Control Device ready, current status = %1\n", _active)); } + turn_it_on (); + } + break; + + case 0x06: + if (!_active) { + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handle_midi_sysex: %1\n", bytes)); } + /* Behringer X-Touch Compact: Device Ready + */ + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Behringer X-Touch Compact ready, current status = %1\n", _active)); + turn_it_on (); break; case 0x03: /* LCP Connection Confirmation */ + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handle_midi_sysex: %1\n", bytes)); DEBUG_TRACE (DEBUG::MackieControl, "Logic Control Device confirms connection, ardour replies\n"); if (bytes[4] == 0x10 || bytes[4] == 0x11) { write_sysex (host_connection_confirmation (bytes)); - _active = true; + turn_it_on (); } break; case 0x04: /* LCP: Confirmation Denied */ + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handle_midi_sysex: %1\n", bytes)); DEBUG_TRACE (DEBUG::MackieControl, "Logic Control Device denies connection\n"); _active = false; break; + default: + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handle_midi_sysex: %1\n", bytes)); + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("unknown device ID byte %1", (int) bytes[5])); error << "MCP: unknown sysex: " << bytes << endmsg; } } @@ -737,11 +815,11 @@ Surface::turn_it_on () (*s)->notify_all (); } - update_view_mode_display (); + update_view_mode_display (false); - if (_mcp.device_info ().has_global_controls ()) { - _mcp.update_global_button (Button::Read, _mcp.metering_active ()); - } +// if (_mcp.device_info ().has_global_controls ()) { +// _mcp.update_global_button (Button::Read, _mcp.metering_active ()); +// } } void @@ -845,10 +923,10 @@ Surface::periodic (uint64_t now_usecs) } void -Surface::redisplay () +Surface::redisplay (ARDOUR::microseconds_t now, bool force) { for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) { - (*s)->redisplay (); + (*s)->redisplay (now, force); } } @@ -863,31 +941,30 @@ Surface::write (const MidiByteArray& data) } void -Surface::map_routes (const vector >& routes) +Surface::map_stripables (const vector >& stripables) { - vector >::const_iterator r; + vector >::const_iterator r; Strips::iterator s = strips.begin(); - DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Mapping %1 routes\n", routes.size())); + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Mapping %1 stripables to %2 strips\n", stripables.size(), strips.size())); - for (r = routes.begin(); r != routes.end() && s != strips.end(); ++s) { + for (r = stripables.begin(); r != stripables.end() && s != strips.end(); ++s) { - /* don't try to assign routes to a locked strip. it won't + /* don't try to assign stripables to a locked strip. it won't use it anyway, but if we do, then we get out of sync with the proposed mapping. */ if (!(*s)->locked()) { - (*s)->set_route (*r); + (*s)->set_stripable (*r); ++r; } } for (; s != strips.end(); ++s) { - (*s)->set_route (boost::shared_ptr()); + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("strip %1 being set to null stripable\n", (*s)->index())); + (*s)->set_stripable (boost::shared_ptr()); } - - } static char @@ -970,20 +1047,20 @@ void Surface::update_flip_mode_display () { for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) { - (*s)->flip_mode_changed (true); + (*s)->flip_mode_changed (); } } - void -Surface::update_potmode () +void +Surface::subview_mode_changed () { for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) { - (*s)->potmode_changed (false); + (*s)->subview_mode_changed (); } } void -Surface::update_view_mode_display () +Surface::update_view_mode_display (bool with_helpful_text) { string text; int id = -1; @@ -995,48 +1072,81 @@ Surface::update_view_mode_display () switch (_mcp.view_mode()) { case MackieControlProtocol::Mixer: show_two_char_display ("Mx"); - //id = Button::Pan; - break; - case MackieControlProtocol::Loop: - show_two_char_display ("LP"); - id = Button::Loop; + id = Button::View; + text = _("Mixer View"); break; case MackieControlProtocol::AudioTracks: show_two_char_display ("AT"); + id = Button::AudioTracks; + text = _("Audio Tracks"); break; case MackieControlProtocol::MidiTracks: show_two_char_display ("MT"); + id = Button::MidiTracks; + text = _("MIDI Tracks"); + break; + case MackieControlProtocol::Plugins: + show_two_char_display ("PL"); + id = Button::Plugin; + text = _("Plugins"); + break; + case MackieControlProtocol::Busses: + show_two_char_display ("BS"); + id = Button::Busses; + if (Profile->get_mixbus()) { + text = _("Mixbusses"); + } else { + text = _("Busses"); + } + break; + case MackieControlProtocol::Auxes: + show_two_char_display ("Au"); + id = Button::Aux; + text = _("Auxes"); + break; + case MackieControlProtocol::Hidden: + show_two_char_display ("HI"); + id = Button::Outputs; + text = _("Hidden Tracks"); + break; + case MackieControlProtocol::Selected: + show_two_char_display ("SE"); + id = Button::User; + text = _("Selected Tracks"); break; default: break; } + vector view_mode_buttons; + view_mode_buttons.push_back (Button::View); + view_mode_buttons.push_back (Button::Busses); + view_mode_buttons.push_back (Button::Plugin); + view_mode_buttons.push_back (Button::AudioTracks); + view_mode_buttons.push_back (Button::MidiTracks); + view_mode_buttons.push_back (Button::Aux); + view_mode_buttons.push_back (Button::Outputs); + view_mode_buttons.push_back (Button::User); + if (id >= 0) { - /* we are attempting to turn a global button/LED on */ + for (vector::iterator i = view_mode_buttons.begin(); i != view_mode_buttons.end(); ++i) { + map::iterator x = controls_by_device_independent_id.find (id); - map::iterator x = controls_by_device_independent_id.find (id); + if (x != controls_by_device_independent_id.end()) { + Button* button = dynamic_cast (x->second); + if (button) { + bool onoff; + onoff = (*i) == id; - if (x != controls_by_device_independent_id.end()) { - Button* button = dynamic_cast (x->second); - if (button) { - _port->write (button->set_state (on)); + _port->write (button->set_state (onoff)); + } } } } - if (!text.empty()) { - for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) { - _port->write ((*s)->display (1, text)); - } - } -} - -void -Surface::gui_selection_changed (const ARDOUR::StrongRouteNotificationList& routes) -{ - for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) { - (*s)->gui_selection_changed (routes); + if (with_helpful_text && !text.empty()) { + display_message_for (text, 1000); } } @@ -1065,13 +1175,25 @@ Surface::set_jog_mode (JogWheel::Mode) } bool -Surface::route_is_locked_to_strip (boost::shared_ptr r) const +Surface::stripable_is_locked_to_strip (boost::shared_ptr stripable) const +{ + for (Strips::const_iterator s = strips.begin(); s != strips.end(); ++s) { + if ((*s)->stripable() == stripable && (*s)->locked()) { + return true; + } + } + return false; +} + +bool +Surface::stripable_is_mapped (boost::shared_ptr stripable) const { for (Strips::const_iterator s = strips.begin(); s != strips.end(); ++s) { - if ((*s)->route() == r && (*s)->locked()) { + if ((*s)->stripable() == stripable) { return true; } } + return false; } @@ -1088,13 +1210,11 @@ Surface::reset () { if (_port) { /* reset msg for Mackie Control */ - MidiByteArray msg (8, MIDI::sysex, 0x00, 0x00, 0x66, 0x14, 0x08, 0x00, MIDI::eox); - _port->write (msg); - msg[4] = 0x15; /* reset Mackie XT */ - _port->write (msg); - msg[4] = 0x10; /* reset Logic Control */ - _port->write (msg); - msg[4] = 0x11; /* reset Logic Control XT */ + MidiByteArray msg; + msg << sysex_hdr(); + msg << 0x08; + msg << 0x00; + msg << MIDI::eox; _port->write (msg); } } @@ -1104,13 +1224,11 @@ Surface::toggle_backlight () { if (_port) { int onoff = random() %2; - MidiByteArray msg (8, MIDI::sysex, 0x00, 0x00, 0x66, 0x14, 0x0a, onoff, MIDI::eox); - _port->write (msg); - msg[4] = 0x15; /* reset Mackie XT */ - _port->write (msg); - msg[4] = 0x10; /* reset Logic Control */ - _port->write (msg); - msg[4] = 0x11; /* reset Logic Control XT */ + MidiByteArray msg; + msg << sysex_hdr (); + msg << 0xa; + msg << (onoff ? 0x1 : 0x0); + msg << MIDI::eox; _port->write (msg); } } @@ -1119,13 +1237,11 @@ void Surface::recalibrate_faders () { if (_port) { - MidiByteArray msg (8, MIDI::sysex, 0x00, 0x00, 0x66, 0x14, 0x09, 0x00, MIDI::eox); - _port->write (msg); - msg[4] = 0x15; /* reset Mackie XT */ - _port->write (msg); - msg[4] = 0x10; /* reset Logic Control */ - _port->write (msg); - msg[4] = 0x11; /* reset Logic Control XT */ + MidiByteArray msg; + msg << sysex_hdr (); + msg << 0x09; + msg << 0x00; + msg << MIDI::eox; _port->write (msg); } } @@ -1138,19 +1254,17 @@ Surface::set_touch_sensitivity (int sensitivity) /* sensitivity already clamped by caller */ if (_port) { - MidiByteArray msg (9, MIDI::sysex, 0x00, 0x00, 0x66, 0x14, 0x0e, 0xff, sensitivity, MIDI::eox); + MidiByteArray msg; + + msg << sysex_hdr (); + msg << 0x0e; + msg << 0xff; /* overwritten for each fader below */ + msg << (sensitivity & 0x7f); + msg << MIDI::eox; for (int fader = 0; fader < 9; ++fader) { msg[6] = fader; - - _port->write (msg); - msg[4] = 0x15; /* reset Mackie XT */ _port->write (msg); - msg[4] = 0x10; /* reset Logic Control */ - _port->write (msg); - msg[4] = 0x11; /* reset Logic Control XT */ - - g_usleep (1000); /* milliseconds */ } } } @@ -1177,3 +1291,75 @@ Surface::connected () turn_it_on (); } } + +MidiByteArray +Surface::display_line (string const& msg, int line_num) +{ + MidiByteArray midi_msg; + midi_msg << sysex_hdr (); + midi_msg << 0x12; + midi_msg << (line_num ? 0x38 : 0x0); /* offsets into char array + * on device that + * correspond to line + * starts + */ + if (msg.empty()) { + + midi_msg.insert (midi_msg.end(), 55, ' '); + + } else { + + /* ascii data to display. @param msg is UTF-8 which is not legal. */ + string ascii = Glib::convert_with_fallback (msg, "UTF-8", "ISO-8859-1", "_"); + string::size_type len = ascii.length(); + + if (len > 55) { + midi_msg << ascii.substr (0, 55); + } else { + midi_msg << ascii; + + for (string::size_type i = len; i < 55; ++i) { + midi_msg << ' '; + } + } + } + + midi_msg << MIDI::eox; + + return midi_msg; +} + +/** display @param msg on the 55x2 screen for @param msecs milliseconds + * + * @param msg is assumed to be UTF-8 encoded, and will be converted + * to ASCII with an underscore as fallback character before being + * sent to the device. + */ +void +Surface::display_message_for (string const& msg, uint64_t msecs) +{ + string::size_type newline; + + if ((newline = msg.find ('\n')) == string::npos) { + + _port->write (display_line (msg, 0)); + _port->write (display_line (string(), 1)); + + } else if (newline == 0) { + + _port->write (display_line (string(), 0)); + _port->write (display_line (msg.substr (1), 1)); + + } else { + + string first_line = msg.substr (0, newline-1); + string second_line = msg.substr (newline+1); + + _port->write (display_line (first_line, 0)); + _port->write (display_line (second_line.substr (0, second_line.find_first_of ('\n')), 1)); + } + + for (Strips::const_iterator s = strips.begin(); s != strips.end(); ++s) { + (*s)->block_screen_display_for (msecs); + } +}