remove cruft
[ardour.git] / libs / surfaces / mackie / surface.cc
index 954aeebca5529f06a889934828f62bebdaa76b5d..6941c68d29dbf93feedc292f6bfabcf6c87e9033 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <glibmm/convert.h>
 
+#include "pbd/stacktrace.h"
+
 #include "midi++/port.h"
 
 #include "ardour/audioengine.h"
@@ -33,6 +35,7 @@
 #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"
@@ -64,7 +67,7 @@ using namespace std;
 using namespace PBD;
 using ARDOUR::Route;
 using ARDOUR::Panner;
-using ARDOUR::Pannable;
+using ARDOUR::Profile;
 using ARDOUR::AutomationControl;
 using namespace ArdourSurface;
 using namespace Mackie;
@@ -168,7 +171,7 @@ Surface::~Surface ()
        delete _port;
        // the ports take time to release and we may be rebuilding right away
        // in the case of changing devices.
-       g_usleep (100000);
+       g_usleep (10000);
        DEBUG_TRACE (DEBUG::MackieControl, "Surface::~Surface done\n");
 }
 
@@ -363,6 +366,14 @@ 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 ()
 {
@@ -373,28 +384,46 @@ Surface::setup_master ()
        }
 
        if (!m) {
+               if (_master_fader) {
+                       _master_fader->set_control (boost::shared_ptr<AutomationControl>());
+               }
+               master_connection.disconnect ();
                return;
        }
 
-       _master_fader = dynamic_cast<Fader*> (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*> (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*> (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*> (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
@@ -509,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) {
@@ -625,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);
@@ -684,6 +705,13 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count
                }
                break;
 
+       case 0x06:
+               /* 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, "Logic Control Device confirms connection, ardour replies\n");
                if (bytes[4] == 0x10 || bytes[4] == 0x11) {
@@ -696,7 +724,9 @@ Surface::handle_midi_sysex (MIDI::Parser &, MIDI::byte * raw_bytes, size_t count
                DEBUG_TRACE (DEBUG::MackieControl, "Logic Control Device denies connection\n");
                _active = false;
                break;
+
        default:
+               DEBUG_TRACE (DEBUG::MackieControl, string_compose ("unknown device ID byte %1", (int) bytes[5]));
                error << "MCP: unknown sysex: " << bytes << endmsg;
        }
 }
@@ -776,11 +806,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
@@ -884,10 +914,10 @@ Surface::periodic (uint64_t now_usecs)
 }
 
 void
-Surface::redisplay (ARDOUR::microseconds_t now)
+Surface::redisplay (ARDOUR::microseconds_t now, bool force)
 {
        for (Strips::iterator s = strips.begin(); s != strips.end(); ++s) {
-               (*s)->redisplay (now);
+               (*s)->redisplay (now, force);
        }
 }
 
@@ -925,8 +955,6 @@ Surface::map_routes (const vector<boost::shared_ptr<Route> >& routes)
        for (; s != strips.end(); ++s) {
                (*s)->set_route (boost::shared_ptr<Route>());
        }
-
-
 }
 
 static char
@@ -1009,20 +1037,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;
@@ -1034,7 +1062,7 @@ Surface::update_view_mode_display ()
        switch (_mcp.view_mode()) {
        case MackieControlProtocol::Mixer:
                show_two_char_display ("Mx");
-               id = Button::Track;
+               id = Button::View;
                text = _("Mixer View");
                break;
        case MackieControlProtocol::AudioTracks:
@@ -1055,24 +1083,40 @@ Surface::update_view_mode_display ()
        case MackieControlProtocol::Busses:
                show_two_char_display ("BS");
                id = Button::Busses;
-               text = _("Busses");
+               if (Profile->get_mixbus()) {
+                       text = _("Mixbusses");
+               } else {
+                       text = _("Busses");
+               }
                break;
        case MackieControlProtocol::Auxes:
-               show_two_char_display ("AB");
+               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<int> view_mode_buttons;
-       view_mode_buttons.push_back (Button::Track);
+       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) {
 
@@ -1091,7 +1135,7 @@ Surface::update_view_mode_display ()
                }
        }
 
-       if (!text.empty()) {
+       if (with_helpful_text && !text.empty()) {
                display_message_for (text, 1000);
        }
 }
@@ -1139,6 +1183,18 @@ Surface::route_is_locked_to_strip (boost::shared_ptr<Route> r) const
        return false;
 }
 
+bool
+Surface::route_is_mapped (boost::shared_ptr<Route> r) const
+{
+       for (Strips::const_iterator s = strips.begin(); s != strips.end(); ++s) {
+               if ((*s)->route() == r) {
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 void
 Surface::notify_metering_state_changed()
 {