From 84bf97aa49995cba8bc8fa6b684064298828aacd Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 18 Oct 2020 03:10:19 +0200 Subject: [PATCH] Update ControlProtocol API, use CoreSelection * replace signal-emission with direct calls to CoreSelecton using BaseUI's session pointer * remove unused leftmost strip API * use CoreSelection for first-selected strip * Accessing CoreSelection does not modify the session (allow access from const callbacks) * replace static calls in P2 surface This removes indirection and dependency on the GUI for managing strip selection. --- libs/ardour/ardour/session.h | 2 +- .../control_protocol/control_protocol.cc | 64 ++++++++----------- .../control_protocol/control_protocol.h | 19 ++---- libs/surfaces/push2/mix.cc | 21 +++--- 4 files changed, 43 insertions(+), 63 deletions(-) diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 956a50eaf4..44e295d3dc 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -317,7 +317,7 @@ public: RouteList get_routelist (bool mixer_order = false, PresentationInfo::Flag fl = PresentationInfo::MixerRoutes) const; - CoreSelection& selection () { return *_selection; } + CoreSelection& selection () const { return *_selection; } /* because the set of Stripables consists of objects managed * independently, in multiple containers within the Session (or objects diff --git a/libs/surfaces/control_protocol/control_protocol.cc b/libs/surfaces/control_protocol/control_protocol.cc index aaf8699fc4..8ee5f286d1 100644 --- a/libs/surfaces/control_protocol/control_protocol.cc +++ b/libs/surfaces/control_protocol/control_protocol.cc @@ -30,6 +30,7 @@ #include "ardour/audio_track.h" #include "ardour/meter.h" #include "ardour/amp.h" +#include "ardour/selection.h" #include "control_protocol/control_protocol.h" using namespace ARDOUR; @@ -52,15 +53,6 @@ PBD::Signal0 ControlProtocol::VerticalZoomOutSelected; PBD::Signal0 ControlProtocol::StepTracksDown; PBD::Signal0 ControlProtocol::StepTracksUp; -PBD::Signal1 > ControlProtocol::AddStripableToSelection; -PBD::Signal1 > ControlProtocol::SetStripableSelection; -PBD::Signal1 > ControlProtocol::ToggleStripableSelection; -PBD::Signal1 > ControlProtocol::RemoveStripableFromSelection; -PBD::Signal0 ControlProtocol::ClearStripableSelection; - -Glib::Threads::Mutex ControlProtocol::special_stripable_mutex; -boost::weak_ptr ControlProtocol::_first_selected_stripable; -boost::weak_ptr ControlProtocol::_leftmost_mixer_stripable; StripableNotificationList ControlProtocol::_last_selected; PBD::ScopedConnection ControlProtocol::selection_connection; bool ControlProtocol::selection_connected = false; @@ -345,49 +337,43 @@ ControlProtocol::set_state (XMLNode const & node, int /* version */) } boost::shared_ptr -ControlProtocol::first_selected_stripable () +ControlProtocol::first_selected_stripable () const { - Glib::Threads::Mutex::Lock lm (special_stripable_mutex); - return _first_selected_stripable.lock(); -} - -boost::shared_ptr -ControlProtocol::leftmost_mixer_stripable () -{ - Glib::Threads::Mutex::Lock lm (special_stripable_mutex); - return _leftmost_mixer_stripable.lock(); + return session->selection().first_selected_stripable (); } void -ControlProtocol::set_leftmost_mixer_stripable (boost::shared_ptr s) +ControlProtocol::AddStripableToSelection (boost::shared_ptr s) { - Glib::Threads::Mutex::Lock lm (special_stripable_mutex); - _leftmost_mixer_stripable = s; + session->selection().add (s, boost::shared_ptr()); } void -ControlProtocol::set_first_selected_stripable (boost::shared_ptr s) +ControlProtocol::SetStripableSelection (boost::shared_ptr s) { - Glib::Threads::Mutex::Lock lm (special_stripable_mutex); - _first_selected_stripable = s; + session->selection().select_stripable_and_maybe_group (s, true, true, 0); +} + +void +ControlProtocol::ToggleStripableSelection (boost::shared_ptr s) +{ + session->selection().toggle (s, boost::shared_ptr()); +} + +void +ControlProtocol::RemoveStripableFromSelection (boost::shared_ptr s) +{ + session->selection().remove (s, boost::shared_ptr()); +} + +void +ControlProtocol::ClearStripableSelection () +{ + session->selection().clear_stripables (); } void ControlProtocol::notify_stripable_selection_changed (StripableNotificationListPtr sp) { - bool had_selection = !_last_selected.empty(); - _last_selected = *sp; - - { - Glib::Threads::Mutex::Lock lm (special_stripable_mutex); - - if (!_last_selected.empty()) { - if (!had_selection) { - _first_selected_stripable = _last_selected.front().lock(); - } - } else { - _first_selected_stripable = boost::weak_ptr(); - } - } } diff --git a/libs/surfaces/control_protocol/control_protocol/control_protocol.h b/libs/surfaces/control_protocol/control_protocol/control_protocol.h index 04f41517ad..fe69d18e53 100644 --- a/libs/surfaces/control_protocol/control_protocol/control_protocol.h +++ b/libs/surfaces/control_protocol/control_protocol/control_protocol.h @@ -82,17 +82,13 @@ public: static PBD::Signal0 StepTracksDown; static PBD::Signal0 StepTracksUp; - static PBD::Signal1 > AddStripableToSelection; - static PBD::Signal1 > SetStripableSelection; - static PBD::Signal1 > ToggleStripableSelection; - static PBD::Signal1 > RemoveStripableFromSelection; - static PBD::Signal0 ClearStripableSelection; + void AddStripableToSelection (boost::shared_ptr); + void SetStripableSelection (boost::shared_ptr); + void ToggleStripableSelection (boost::shared_ptr); + void RemoveStripableFromSelection (boost::shared_ptr); + void ClearStripableSelection (); - static boost::shared_ptr first_selected_stripable (); - static void set_first_selected_stripable (boost::shared_ptr); - - static boost::shared_ptr leftmost_mixer_stripable (); - static void set_leftmost_mixer_stripable (boost::shared_ptr); + boost::shared_ptr first_selected_stripable () const; /* the model here is as follows: @@ -157,9 +153,6 @@ private: bool _active; - static Glib::Threads::Mutex special_stripable_mutex; - static boost::weak_ptr _leftmost_mixer_stripable; - static boost::weak_ptr _first_selected_stripable; static StripableNotificationList _last_selected; static PBD::ScopedConnection selection_connection; static bool selection_connected; diff --git a/libs/surfaces/push2/mix.cc b/libs/surfaces/push2/mix.cc index 1523749789..01feb6b8af 100644 --- a/libs/surfaces/push2/mix.cc +++ b/libs/surfaces/push2/mix.cc @@ -40,6 +40,7 @@ #include "ardour/midiport_manager.h" #include "ardour/midi_track.h" #include "ardour/midi_port.h" +#include "ardour/selection.h" #include "ardour/session.h" #include "ardour/tempo.h" #include "ardour/utils.h" @@ -387,7 +388,7 @@ MixLayout::show_vpot_mode () void MixLayout::button_mute () { - boost::shared_ptr s = ControlProtocol::first_selected_stripable(); + boost::shared_ptr s = session.selection().first_selected_stripable(); if (s) { boost::shared_ptr ac = s->mute_control(); if (ac) { @@ -399,7 +400,7 @@ MixLayout::button_mute () void MixLayout::button_solo () { - boost::shared_ptr s = ControlProtocol::first_selected_stripable(); + boost::shared_ptr s = session.selection().first_selected_stripable(); if (s) { boost::shared_ptr ac = s->solo_control(); if (ac) { @@ -415,7 +416,7 @@ MixLayout::button_lower (uint32_t n) return; } - ControlProtocol::SetStripableSelection (stripable[n]); + session.selection().set (stripable[n], boost::shared_ptr()); } void @@ -686,7 +687,7 @@ MixLayout::button_select_release () /* no visible track selected, select first (if any) */ if (stripable[0]) { - ControlProtocol::SetStripableSelection (stripable[0]); + session.selection().set (stripable[0], boost::shared_ptr()); } } else { @@ -699,10 +700,10 @@ MixLayout::button_select_release () switch banks by one, and select leftmost */ if (bank_start != 0) { - ControlProtocol::ClearStripableSelection (); + session.selection().clear_stripables (); switch_bank (bank_start-1); if (stripable[0]) { - ControlProtocol::SetStripableSelection (stripable[0]); + session.selection().set (stripable[0], boost::shared_ptr()); } } } else { @@ -712,7 +713,7 @@ MixLayout::button_select_release () --n; } if (n >= 0) { - ControlProtocol::SetStripableSelection (stripable[n]); + session.selection().set (stripable[n], boost::shared_ptr()); } } @@ -724,10 +725,10 @@ MixLayout::button_select_release () /* current selected is rightmost ... cancel selection, switch banks by one, and select righmost */ - ControlProtocol::ToggleStripableSelection (stripable[selected]); + session.selection().toggle (stripable[selected], boost::shared_ptr()); switch_bank (bank_start+1); if (stripable[7]) { - ControlProtocol::SetStripableSelection (stripable[7]); + session.selection().set (stripable[7], boost::shared_ptr()); } } else { /* select next, if any */ @@ -737,7 +738,7 @@ MixLayout::button_select_release () } if (n != 8) { - ControlProtocol::SetStripableSelection (stripable[n]); + session.selection().set (stripable[n], boost::shared_ptr()); } } }