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.
This commit is contained in:
Robin Gareus 2020-10-18 03:10:19 +02:00
parent 9b382fe1c5
commit 84bf97aa49
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
4 changed files with 43 additions and 63 deletions

View File

@ -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

View File

@ -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<void> ControlProtocol::VerticalZoomOutSelected;
PBD::Signal0<void> ControlProtocol::StepTracksDown;
PBD::Signal0<void> ControlProtocol::StepTracksUp;
PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::AddStripableToSelection;
PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::SetStripableSelection;
PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::ToggleStripableSelection;
PBD::Signal1<void,boost::shared_ptr<ARDOUR::Stripable> > ControlProtocol::RemoveStripableFromSelection;
PBD::Signal0<void> ControlProtocol::ClearStripableSelection;
Glib::Threads::Mutex ControlProtocol::special_stripable_mutex;
boost::weak_ptr<Stripable> ControlProtocol::_first_selected_stripable;
boost::weak_ptr<Stripable> 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<Stripable>
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<Stripable>
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<Stripable> s)
ControlProtocol::AddStripableToSelection (boost::shared_ptr<ARDOUR::Stripable> s)
{
Glib::Threads::Mutex::Lock lm (special_stripable_mutex);
_leftmost_mixer_stripable = s;
session->selection().add (s, boost::shared_ptr<AutomationControl>());
}
void
ControlProtocol::set_first_selected_stripable (boost::shared_ptr<Stripable> s)
ControlProtocol::SetStripableSelection (boost::shared_ptr<ARDOUR::Stripable> 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<ARDOUR::Stripable> s)
{
session->selection().toggle (s, boost::shared_ptr<AutomationControl>());
}
void
ControlProtocol::RemoveStripableFromSelection (boost::shared_ptr<ARDOUR::Stripable> s)
{
session->selection().remove (s, boost::shared_ptr<AutomationControl>());
}
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<Stripable>();
}
}
}

View File

@ -82,17 +82,13 @@ public:
static PBD::Signal0<void> StepTracksDown;
static PBD::Signal0<void> StepTracksUp;
static PBD::Signal1<void, boost::shared_ptr<ARDOUR::Stripable> > AddStripableToSelection;
static PBD::Signal1<void, boost::shared_ptr<ARDOUR::Stripable> > SetStripableSelection;
static PBD::Signal1<void, boost::shared_ptr<ARDOUR::Stripable> > ToggleStripableSelection;
static PBD::Signal1<void, boost::shared_ptr<ARDOUR::Stripable> > RemoveStripableFromSelection;
static PBD::Signal0<void> ClearStripableSelection;
void AddStripableToSelection (boost::shared_ptr<ARDOUR::Stripable>);
void SetStripableSelection (boost::shared_ptr<ARDOUR::Stripable>);
void ToggleStripableSelection (boost::shared_ptr<ARDOUR::Stripable>);
void RemoveStripableFromSelection (boost::shared_ptr<ARDOUR::Stripable>);
void ClearStripableSelection ();
static boost::shared_ptr<ARDOUR::Stripable> first_selected_stripable ();
static void set_first_selected_stripable (boost::shared_ptr<ARDOUR::Stripable>);
static boost::shared_ptr<ARDOUR::Stripable> leftmost_mixer_stripable ();
static void set_leftmost_mixer_stripable (boost::shared_ptr<ARDOUR::Stripable>);
boost::shared_ptr<ARDOUR::Stripable> 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<ARDOUR::Stripable> _leftmost_mixer_stripable;
static boost::weak_ptr<ARDOUR::Stripable> _first_selected_stripable;
static StripableNotificationList _last_selected;
static PBD::ScopedConnection selection_connection;
static bool selection_connected;

View File

@ -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<Stripable> s = ControlProtocol::first_selected_stripable();
boost::shared_ptr<Stripable> s = session.selection().first_selected_stripable();
if (s) {
boost::shared_ptr<AutomationControl> ac = s->mute_control();
if (ac) {
@ -399,7 +400,7 @@ MixLayout::button_mute ()
void
MixLayout::button_solo ()
{
boost::shared_ptr<Stripable> s = ControlProtocol::first_selected_stripable();
boost::shared_ptr<Stripable> s = session.selection().first_selected_stripable();
if (s) {
boost::shared_ptr<AutomationControl> 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<AutomationControl>());
}
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<AutomationControl>());
}
} 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<AutomationControl>());
}
}
} 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<AutomationControl>());
}
}
@ -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<AutomationControl>());
switch_bank (bank_start+1);
if (stripable[7]) {
ControlProtocol::SetStripableSelection (stripable[7]);
session.selection().set (stripable[7], boost::shared_ptr<AutomationControl>());
}
} 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<AutomationControl>());
}
}
}