+
+void
+Surface::notify_metering_state_changed()
+{
+ for (Strips::const_iterator s = strips.begin(); s != strips.end(); ++s) {
+ (*s)->notify_metering_state_changed ();
+ }
+}
+
+void
+Surface::reset ()
+{
+ if (_port) {
+ /* reset msg for Mackie Control */
+ MidiByteArray msg;
+ msg << sysex_hdr();
+ msg << 0x08;
+ msg << 0x00;
+ msg << MIDI::eox;
+ _port->write (msg);
+ }
+}
+
+void
+Surface::toggle_backlight ()
+{
+ if (_port) {
+ int onoff = random() %2;
+ MidiByteArray msg;
+ msg << sysex_hdr ();
+ msg << 0xa;
+ msg << (onoff ? 0x1 : 0x0);
+ msg << MIDI::eox;
+ _port->write (msg);
+ }
+}
+
+void
+Surface::recalibrate_faders ()
+{
+ if (_port) {
+ 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;
+
+ 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);
+ }
+ }
+}
+
+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));
+
+ 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);
+ }
+}