From 05c6616e3232c1c29856a11cce0a80a688ca9c50 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 27 Jul 2023 13:29:57 -0600 Subject: [PATCH] ControlGroup: fiddle with API for clarity, and add TrimAutomation special case --- libs/ardour/ardour/control_group.h | 8 ++--- libs/ardour/control_group.cc | 47 +++++++++++++++++------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/libs/ardour/ardour/control_group.h b/libs/ardour/ardour/control_group.h index b7268ad43e..712bb792aa 100644 --- a/libs/ardour/ardour/control_group.h +++ b/libs/ardour/ardour/control_group.h @@ -51,12 +51,12 @@ class LIBARDOUR_API ControlGroup : public std::enable_shared_from_this, bool push = false); int remove_control (std::shared_ptr, bool pop = false); - bool push (std::shared_ptr); - bool pop (std::shared_ptr); + + void pop_all (); ControlList controls () const; - void clear (); + void clear (bool pop = false); void set_active (bool); bool active() const { return _active; } @@ -101,7 +101,7 @@ class LIBARDOUR_API ControlGroup : public std::enable_shared_from_this, double val); diff --git a/libs/ardour/control_group.cc b/libs/ardour/control_group.cc index 3ddb2695e5..5dba24c033 100644 --- a/libs/ardour/control_group.cc +++ b/libs/ardour/control_group.cc @@ -55,7 +55,7 @@ ControlGroup::set_mode (Mode m) } void -ControlGroup::clear () +ControlGroup::clear (bool pop) { /* we're giving up on all members, so we don't care about their * DropReferences signals anymore @@ -77,8 +77,12 @@ ControlGroup::clear () _controls.clear (); - for (std::vector >::iterator c = controls.begin(); c != controls.end(); ++c) { - (*c)->set_group (std::shared_ptr()); + for (auto & c : controls) { + if (pop) { + c->pop_group (); + } else { + c->set_group (std::shared_ptr()); + } } } @@ -217,7 +221,6 @@ void ControlGroup::fill_from_selection (CoreSelection const & sel, Evoral::Parameter const & p) { CoreSelection::StripableAutomationControls stripables; - Evoral::Parameter gain_p (GainAutomation); sel.get_stripables (stripables); @@ -226,41 +229,43 @@ ControlGroup::fill_from_selection (CoreSelection const & sel, Evoral::Parameter * their Amp processor which takes a certain kind of ownership of it. */ - if (p == gain_p) { + switch (p.type()) { + case GainAutomation: for (auto & s : stripables) { std::shared_ptr ac = s.stripable->gain_control (); if (ac) { - push (ac); + add_control (ac, true); } } - } else { + break; + case TrimAutomation: + for (auto & s : stripables) { + std::shared_ptr ac = s.stripable->trim_control (); + if (ac) { + add_control (ac, true); + } + } + break; + default: for (auto & s : stripables) { std::shared_ptr ac = s.stripable->automation_control (p, true); if (ac) { - push (ac); + add_control (ac, true); } } } } -bool -ControlGroup::push (std::shared_ptr c) +void +ControlGroup::pop_all () { - add_control (c, true); - return true; -} - -bool -ControlGroup::pop (std::shared_ptr c) -{ - remove_control (c, true); - return true; + clear (true); } /*---- GAIN CONTROL GROUP -----------*/ -GainControlGroup::GainControlGroup () - : ControlGroup (GainAutomation) +GainControlGroup::GainControlGroup (ARDOUR::AutomationType t) + : ControlGroup (t) { }