X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fsurfaces%2Fmackie%2Fsurface.cc;h=ec8192f91dd33dfbe21f20c47104d81affd237f8;hb=b5dbfc9931bc586fb2b5a50a2493e8c158c99896;hp=4b5a0ef79750877320906dfbb98727dedd365954;hpb=c78426968ffbfd630c401f5acedb2b2b47789dbe;p=ardour.git diff --git a/libs/surfaces/mackie/surface.cc b/libs/surfaces/mackie/surface.cc index 4b5a0ef797..ec8192f91d 100644 --- a/libs/surfaces/mackie/surface.cc +++ b/libs/surfaces/mackie/surface.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Paul Davis + Copyright (C) 2012 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -23,17 +23,25 @@ #include #include +#include + +#include "pbd/stacktrace.h" + #include "midi++/port.h" +#include "ardour/audioengine.h" #include "ardour/automation_control.h" #include "ardour/debug.h" #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" @@ -49,13 +57,17 @@ #include "jog.h" #include "meter.h" -#include "i18n.h" +#include "pbd/i18n.h" + +#ifdef PLATFORM_WINDOWS +#define random() rand() +#endif 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; @@ -84,9 +96,11 @@ Surface::Surface (MackieControlProtocol& mcp, const std::string& device_name, ui , _jog_wheel (0) , _master_fader (0) , _last_master_gain_written (-0.0f) + , connection_state (0) + , input_source (0) { DEBUG_TRACE (DEBUG::MackieControl, "Surface::Surface init\n"); - + try { _port = new SurfacePort (*this); } catch (...) { @@ -110,12 +124,25 @@ Surface::Surface (MackieControlProtocol& mcp, const std::string& device_name, ui } uint32_t n = _mcp.device_info().strip_cnt(); - + if (n) { init_strips (n); 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. + */ + + connection_state |= (InputConnected|OutputConnected); + connected (); + } + connect_to_signals (); DEBUG_TRACE (DEBUG::MackieControl, "Surface::Surface done\n"); @@ -125,42 +152,124 @@ 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"); } +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()); + + if (ni == name1 || ni == name2) { + if (yn) { + connection_state |= InputConnected; + } else { + connection_state &= ~InputConnected; + } + } else if (no == name1 || no == name2) { + if (yn) { + connection_state |= OutputConnected; + } else { + connection_state &= ~OutputConnected; + } + } else { + /* not our ports */ + return false; + } + + if ((connection_state & (InputConnected|OutputConnected)) == (InputConnected|OutputConnected)) { + + /* this will send a device query message, which should + result in a response that will kick off device type + discovery and activation of the surface(s). + + The intended order of events is: + + - each surface sends a device query message + - devices respond with either MCP or LCP response (sysex in both + cases) + - sysex message causes Surface::turn_it_on() which tells the + MCP object that the surface is ready, and sets up strip + displays and binds faders and buttons for that surface + + In the case of LCP, where this is a handshake process that could + fail, the response process to the initial sysex after a device query + will mark the surface inactive, which won't shut anything down + but will stop any writes to the device. + + Note: there are no known cases of the handshake process failing. + + We actually can't initiate this in this callback, so we have + 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; @@ -176,7 +285,7 @@ Surface::set_state (const XMLNode& node, int version) return 0; } -const MidiByteArray& +const MidiByteArray& Surface::sysex_hdr() const { switch (_stype) { @@ -197,11 +306,11 @@ static GlobalControlDefinition mackie_global_controls[] = { { "", 0, Led::factory, "" } }; -void +void Surface::init_controls() { Group* group; - + DEBUG_TRACE (DEBUG::MackieControl, "Surface::init_controls: creating groups\n"); groups["assignment"] = new Group ("assignment"); groups["automation"] = new Group ("automation"); @@ -216,7 +325,7 @@ Surface::init_controls() groups["transport"] = new Group ("transport"); groups["user"] = new Group ("user"); groups["utilities"] = new Group ("utilities"); - + DEBUG_TRACE (DEBUG::MackieControl, "Surface::init_controls: creating jog wheel\n"); if (_mcp.device_info().has_jog_wheel()) { _jog_wheel = new Mackie::JogWheel (_mcp); @@ -239,7 +348,7 @@ Surface::init_controls() } } -void +void Surface::init_strips (uint32_t n) { const map& strip_buttons (_mcp.device_info().strip_buttons()); @@ -247,48 +356,74 @@ Surface::init_strips (uint32_t n) for (uint32_t i = 0; i < n; ++i) { char name[32]; - + snprintf (name, sizeof (name), "strip_%d", (8* _number) + i); Strip* strip = new Strip (*this, name, i, strip_buttons); - + groups[name] = strip; strips.push_back (strip); } } +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 @@ -314,7 +449,7 @@ Surface::master_gain_changed () _last_master_gain_written = normalized_position; } -float +float Surface::scaled_delta (float delta, float current_speed) { /* XXX needs work before use */ @@ -323,7 +458,7 @@ Surface::scaled_delta (float delta, float current_speed) return ((sign * std::pow (delta + 1.0, 2.0)) + current_speed) / 100.0; } -void +void Surface::display_bank_start (uint32_t current_bank) { if (current_bank == 0) { @@ -335,7 +470,7 @@ Surface::display_bank_start (uint32_t current_bank) } } -void +void Surface::blank_jog_ring () { Control* control = controls_by_device_independent_id[Jog::ID]; @@ -354,13 +489,13 @@ Surface::scrub_scaling_factor () const return 100.0; } -void +void Surface::connect_to_signals () { if (!_connected) { - DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface %1 connecting to signals on port %2\n", + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface %1 connecting to signals on port %2\n", number(), _port->input_port().name())); MIDI::Parser* p = _port->input_port().parser(); @@ -380,7 +515,7 @@ Surface::connect_to_signals () } // Master fader p->channel_pitchbend[_mcp.device_info().strip_cnt()].connect_same_thread (*this, boost::bind (&Surface::handle_midi_pitchbend_message, this, _1, _2, _mcp.device_info().strip_cnt())); - + _connected = true; } } @@ -392,25 +527,17 @@ Surface::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb, uin * from the MIDI::Parser conveys the fader ID, which was given by the * channel ID in the status byte. * - * Instead, we have used bind() to supply the fader-within-strip ID + * Instead, we have used bind() to supply the fader-within-strip ID * when we connected to the per-channel pitchbend events. */ DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface::handle_midi_pitchbend_message on port %3, fader = %1 value = %2 (%4)\n", - fader_id, pb, _number, pb/16384.0)); - + fader_id, pb, _number, pb/16384.0)); + if (_mcp.device_info().no_handshake()) { 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) { @@ -429,17 +556,21 @@ Surface::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb, uin } } -void +void Surface::handle_midi_note_on_message (MIDI::Parser &, MIDI::EventTwoBytes* ev) { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface::handle_midi_note_on_message %1 = %2\n", (int) ev->note_number, (int) ev->velocity)); - + if (_mcp.device_info().no_handshake()) { turn_it_on (); } + if (_mcp.device_info().device_type() == DeviceInfo::HUI && ev->note_number == 0 && ev->velocity == 127) { + turn_it_on (); + } + /* fader touch sense is given by "buttons" 0xe..0xe7 and 0xe8 for the - * master. + * master. */ if (ev->note_number >= 0xE0 && ev->note_number <= 0xE8) { @@ -463,6 +594,11 @@ Surface::handle_midi_note_on_message (MIDI::Parser &, MIDI::EventTwoBytes* ev) Button* button = buttons[ev->note_number]; if (button) { + + if (ev->velocity > 64) { + button->pressed (); + } + Strip* strip = dynamic_cast (&button->group()); if (strip) { @@ -474,12 +610,19 @@ Surface::handle_midi_note_on_message (MIDI::Parser &, MIDI::EventTwoBytes* ev) DEBUG_TRACE (DEBUG::MackieControl, string_compose ("global button %1\n", button->id())); _mcp.handle_button_event (*this, *button, ev->velocity > 64 ? press : release); } + + if (ev->velocity <= 64) { + button->released (); + } + } else { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("no button found for %1\n", (int) ev->note_number)); } + + /* button release should reset timer AFTER handler(s) have run */ } -void +void Surface::handle_midi_controller_message (MIDI::Parser &, MIDI::EventTwoBytes* ev) { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("SurfacePort::handle_midi_controller %1 = %2\n", (int) ev->controller_number, (int) ev->value)); @@ -491,7 +634,7 @@ Surface::handle_midi_controller_message (MIDI::Parser &, MIDI::EventTwoBytes* ev Pot* pot = pots[ev->controller_number]; // bit 6 gives the sign - float sign = (ev->value & 0x40) == 0 ? 1.0 : -1.0; + float sign = (ev->value & 0x40) == 0 ? 1.0 : -1.0; // bits 0..5 give the velocity. we interpret this as "ticks // moved before this message was sent" float ticks = (ev->value & 0x3f); @@ -503,12 +646,12 @@ Surface::handle_midi_controller_message (MIDI::Parser &, MIDI::EventTwoBytes* ev } float delta = 0; - if (mcp().modifier_state() == MackieControlProtocol::MODIFIER_CONTROL) { + if (mcp().main_modifier_state() == MackieControlProtocol::MODIFIER_SHIFT) { delta = sign * (ticks / (float) 0xff); } else { delta = sign * (ticks / (float) 0x3f); } - + if (!pot) { if (ev->controller_number == Jog::ID && _jog_wheel) { @@ -524,22 +667,20 @@ Surface::handle_midi_controller_message (MIDI::Parser &, MIDI::EventTwoBytes* ev Strip* strip = dynamic_cast (&pot->group()); if (strip) { strip->handle_pot (*pot, delta); - } + } } -void +void 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 (); } /* always save the device type ID so that our outgoing sysex messages - * are correct + * are correct */ if (_stype == mcu) { @@ -550,62 +691,79 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count switch (bytes[5]) { case 0x01: - /* MCP: Device Ready - LCP: Connection Challenge + if (!_active) { + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("handle_midi_sysex: %1\n", bytes)); + } + /* MCP: Device Ready + LCP: Connection Challenge */ if (bytes[4] == 0x10 || bytes[4] == 0x11) { 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; } } -static MidiByteArray +static MidiByteArray calculate_challenge_response (MidiByteArray::iterator begin, MidiByteArray::iterator end) { MidiByteArray l; back_insert_iterator back (l); copy (begin, end, back); - + MidiByteArray retval; - + // this is how to calculate the response to the challenge. // from the Logic docs. retval << (0x7f & (l[0] + (l[1] ^ 0xa) - l[3])); retval << (0x7f & ( (l[2] >> l[3]) ^ (l[0] + l[3]))); retval << (0x7f & ((l[3] - (l[2] << 2)) ^ (l[0] | l[1]))); retval << (0x7f & (l[1] - l[2] + (0xf0 ^ (l[3] << 4)))); - + return retval; } -// not used right now -MidiByteArray +MidiByteArray Surface::host_connection_query (MidiByteArray & bytes) { MidiByteArray response; - + if (bytes[4] != 0x10 && bytes[4] != 0x11) { /* not a Logic Control device - no response required */ return response; @@ -613,7 +771,7 @@ Surface::host_connection_query (MidiByteArray & bytes) // handle host connection query DEBUG_TRACE (DEBUG::MackieControl, string_compose ("host connection query: %1\n", bytes)); - + if (bytes.size() != 18) { cerr << "expecting 18 bytes, read " << bytes << " from " << _port->input_port().name() << endl; return response; @@ -626,19 +784,18 @@ Surface::host_connection_query (MidiByteArray & bytes) return response; } -// not used right now -MidiByteArray +MidiByteArray Surface::host_connection_confirmation (const MidiByteArray & bytes) { DEBUG_TRACE (DEBUG::MackieControl, string_compose ("host_connection_confirmation: %1\n", bytes)); - + // decode host connection confirmation if (bytes.size() != 14) { ostringstream os; os << "expecting 14 bytes, read " << bytes << " from " << _port->input_port().name(); throw MackieControlException (os.str()); } - + // send version request return MidiByteArray (2, 0x13, 0x00); } @@ -658,14 +815,14 @@ 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 +void Surface::write_sysex (const MidiByteArray & mba) { if (mba.empty()) { @@ -677,7 +834,7 @@ Surface::write_sysex (const MidiByteArray & mba) _port->write (buf); } -void +void Surface::write_sysex (MIDI::byte msg) { MidiByteArray buf; @@ -690,7 +847,7 @@ Surface::n_strips (bool with_locked_strips) const { if (with_locked_strips) { return strips.size(); - } + } uint32_t n = 0; @@ -717,7 +874,7 @@ Surface::zero_all () if (_mcp.device_info().has_timecode_display ()) { display_timecode (string (10, '0'), string (10, ' ')); } - + if (_mcp.device_info().has_two_character_display()) { show_two_char_display (string (2, '0'), string (2, ' ')); } @@ -766,15 +923,15 @@ 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); } } void -Surface::write (const MidiByteArray& data) +Surface::write (const MidiByteArray& data) { if (_active) { _port->write (data); @@ -784,34 +941,33 @@ 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 +static char translate_seven_segment (char achar) { achar = toupper (achar); @@ -831,13 +987,13 @@ Surface::show_two_char_display (const std::string & msg, const std::string & dot if (_stype != mcu || !_mcp.device_info().has_two_character_display() || msg.length() != 2 || dots.length() != 2) { return; } - + MidiByteArray right (3, 0xb0, 0x4b, 0x00); MidiByteArray left (3, 0xb0, 0x4a, 0x00); - + right[2] = translate_seven_segment (msg[0]) + (dots[0] == '.' ? 0x40 : 0x00); left[2] = translate_seven_segment (msg[1]) + (dots[1] == '.' ? 0x40 : 0x00); - + _port->write (right); _port->write (left); } @@ -858,7 +1014,7 @@ Surface::display_timecode (const std::string & timecode, const std::string & las } // if there's no change, send nothing, not even sysex header if (timecode == last_timecode) return; - + // length sanity checking string local_timecode = timecode; @@ -868,10 +1024,10 @@ Surface::display_timecode (const std::string & timecode, const std::string & las } // pad to 10 characters - while (local_timecode.length() < 10) { + while (local_timecode.length() < 10) { local_timecode += " "; } - + // translate characters. // Only the characters that actually changed are sent. int position = 0x3f; @@ -891,12 +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::subview_mode_changed () +{ + for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) { + (*s)->subview_mode_changed (); } } void -Surface::update_view_mode_display () +Surface::update_view_mode_display (bool with_helpful_text) { string text; int id = -1; @@ -908,64 +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::Dynamics: - show_two_char_display ("Dy"); - id = Button::Dyn; - break; - case MackieControlProtocol::EQ: - show_two_char_display ("EQ"); - id = Button::Eq; - 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"); - break; - case MackieControlProtocol::Sends: - show_two_char_display ("Sn"); - id = Button::Send; + id = Button::MidiTracks; + text = _("MIDI Tracks"); break; case MackieControlProtocol::Plugins: - show_two_char_display ("Pl"); + 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 */ - map::iterator x = controls_by_device_independent_id.find (id); + for (vector::iterator i = view_mode_buttons.begin(); i != view_mode_buttons.end(); ++i) { + 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) { - _port->write (button->set_state (on)); + if (x != controls_by_device_independent_id.end()) { + Button* button = dynamic_cast (x->second); + if (button) { + bool onoff; + onoff = (*i) == id; + + _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); } } @@ -991,20 +1172,32 @@ Surface::next_jog_mode () void Surface::set_jog_mode (JogWheel::Mode) { -} +} + +bool +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::route_is_locked_to_strip (boost::shared_ptr r) const +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; } -void +void Surface::notify_metering_state_changed() { for (Strips::const_iterator s = strips.begin(); s != strips.end(); ++s) { @@ -1017,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); } } @@ -1033,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); } } @@ -1048,38 +1237,129 @@ 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); } -} +} void Surface::set_touch_sensitivity (int sensitivity) { /* NOTE: assumed called from GUI code, hence sleep() */ - + /* 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 */ + } + } +} + +void +Surface::hui_heartbeat () +{ + if (!_port) { + return; + } + + MidiByteArray msg (3, MIDI::on, 0x0, 0x0); + _port->write (msg); +} + +void +Surface::connected () +{ + DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Surface %1 now connected, trying to ping device...\n", _name)); - g_usleep (1000); /* milliseconds */ + say_hello (); + + if (_mcp.device_info().no_handshake()) { + 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); + } }