mackie: catch data on what presentation info aspects changed; don't change banks...
[ardour.git] / libs / surfaces / mackie / mackie_control_protocol.cc
index 7a699ca90a812a114709836b88115f70b93e3f0a..2a5d710eafe52d968abe591b808b64f8342d14a4 100644 (file)
@@ -138,7 +138,7 @@ MackieControlProtocol::MackieControlProtocol (Session& session)
                _last_bank[i] = 0;
        }
 
-       PresentationInfo::Change.connect (gui_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_presentation_info_changed, this), this);
+       PresentationInfo::Change.connect (gui_connections, MISSING_INVALIDATOR, boost::bind (&MackieControlProtocol::notify_presentation_info_changed, this, _1), this);
 
        _instance = this;
 
@@ -368,6 +368,7 @@ int
 MackieControlProtocol::switch_banks (uint32_t initial, bool force)
 {
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("switch banking to start at %1 force ? %2 current = %3\n", initial, force, _current_initial_bank));
+       PBD::stacktrace (cerr, 20);
 
        if (initial == _current_initial_bank && !force) {
                /* everything is as it should be */
@@ -1297,8 +1298,17 @@ MackieControlProtocol::notify_solo_active_changed (bool active)
 }
 
 void
-MackieControlProtocol::notify_presentation_info_changed ()
+MackieControlProtocol::notify_presentation_info_changed (PBD::PropertyChange const & what_changed)
 {
+       PBD::PropertyChange order_or_hidden;
+
+       order_or_hidden.add (Properties::hidden);
+       order_or_hidden.add (Properties::order);
+
+       if (!what_changed.contains (order_or_hidden)) {
+               return;
+       }
+
        {
                Glib::Threads::Mutex::Lock lm (surfaces_lock);
 
@@ -1307,23 +1317,7 @@ MackieControlProtocol::notify_presentation_info_changed ()
                }
        }
 
-       Sorted sorted = get_sorted_stripables();
-       uint32_t sz = n_strips();
-
-       // if a remote id has been moved off the end, we need to shift
-       // the current bank backwards.
-
-       if (sorted.size() - _current_initial_bank < sz) {
-               // but don't shift backwards past the zeroth channel
-               if (sorted.size() < sz) {  // avoid unsigned math mistake below
-                       (void) switch_banks(0, true);
-               } else {
-                       (void) switch_banks (max((Sorted::size_type) 0, sorted.size() - sz), true);
-               }
-       } else {
-               // Otherwise just refresh the current bank
-               refresh_current_bank();
-       }
+       refresh_current_bank();
 }
 
 ///////////////////////////////////////////
@@ -1539,14 +1533,6 @@ MackieControlProtocol::handle_button_event (Surface& surface, Button& button, Bu
                return;
        }
 
-       if ((button_id != Button::Marker) && (modifier_state() & MODIFIER_MARKER)) {
-               marker_modifier_consumed_by_button = true;
-       }
-
-       if ((button_id != Button::Nudge) && (modifier_state() & MODIFIER_NUDGE)) {
-               nudge_modifier_consumed_by_button = true;
-       }
-
        DEBUG_TRACE (DEBUG::MackieControl, string_compose ("Handling %1 for button %2 (%3)\n", (bs == press ? "press" : "release"), button.id(),
                                                           Button::id_to_name (button.bid())));
 
@@ -1596,14 +1582,30 @@ MackieControlProtocol::handle_button_event (Surface& surface, Button& button, Bu
                }
        }
 
+       /* Now that we have the correct (maybe remapped) button ID, do these
+        * checks on it.
+        */
+
+       if ((button_id != Button::Marker) && (modifier_state() & MODIFIER_MARKER)) {
+               marker_modifier_consumed_by_button = true;
+       }
+
+       if ((button_id != Button::Nudge) && (modifier_state() & MODIFIER_NUDGE)) {
+               nudge_modifier_consumed_by_button = true;
+       }
+
        /* lookup using the device-INDEPENDENT button ID */
 
+       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("now looking up button ID %1\n", button_id));
+
        ButtonMap::iterator b = button_map.find (button_id);
 
        if (b != button_map.end()) {
 
                ButtonHandlers& bh (b->second);
 
+               DEBUG_TRACE (DEBUG::MackieControl, string_compose ("button found in map, now invoking %1\n", (bs == press ? "press" : "release")));
+
                switch  (bs) {
                case press:
                        surface.write (button.set_state ((this->*(bh.press)) (button)));
@@ -2035,7 +2037,8 @@ MackieControlProtocol::select_range (uint32_t pressed)
 
        pull_stripable_range (_down_select_buttons, stripables, pressed);
 
-       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("select range: found %1 stripables, first = %2\n", stripables.size(), stripables.front()->name()));
+       DEBUG_TRACE (DEBUG::MackieControl, string_compose ("select range: found %1 stripables, first = %2\n", stripables.size(),
+                                                          (stripables.empty() ? "null" : stripables.front()->name())));
 
        if (stripables.empty()) {
                return;