From fb1ca67e39a203551ca2cc5bc1e2349cdb627775 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 19 Aug 2024 15:22:59 +0200 Subject: [PATCH] RegionFX: add clear-automation action --- gtk2_ardour/region_editor.cc | 44 +++++++++++++++++++++++++++++++++++- gtk2_ardour/region_editor.h | 1 + 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/gtk2_ardour/region_editor.cc b/gtk2_ardour/region_editor.cc index 6fc4f04d38..081261e1d2 100644 --- a/gtk2_ardour/region_editor.cc +++ b/gtk2_ardour/region_editor.cc @@ -671,7 +671,8 @@ RegionEditor::RegionFxBox::fxe_button_press_event (GdkEventButton* ev, RegionFxE if (!ac_items.empty ()) { items.push_back (SeparatorElem ()); - items.push_back (MenuElem ("Automation Enable", *automation_menu)); + items.push_back (MenuElem (_("Automation Enable"), *automation_menu)); + items.push_back (MenuElem (_("Clear All Automation"), sigc::bind (sigc::mem_fun (*this, &RegionFxBox::clear_automation), wfx))); } else { delete automation_menu; } @@ -744,6 +745,47 @@ RegionEditor::RegionFxBox::on_key_press (GdkEventKey* ev) return true; } +void +RegionEditor::RegionFxBox::clear_automation (std::weak_ptr wfx) +{ + std::shared_ptr fx (wfx.lock ()); + if (!fx) { + return; + } + bool in_command = false; + + timepos_t tas ((samplepos_t)_region->length().samples()); + + for (auto const& c : fx->controls ()) { + std::shared_ptr ac = std::dynamic_pointer_cast (c.second); + if (!ac) { + continue; + } + std::shared_ptr alist = ac->alist (); + if (!alist) { + continue; + } + + XMLNode& before (alist->get_state()); + + alist->freeze (); + alist->clear (); + fx->set_default_automation (tas); + alist->thaw (); + alist->set_automation_state (ARDOUR::Off); + + if (!in_command) { + _region->session ().begin_reversible_command (_("Clear region fx automation")); + in_command = true; + } + _region->session ().add_command (new MementoCommand(*alist.get(), &before, &alist->get_state())); + } + + if (in_command) { + _region->session ().commit_reversible_command (); + } +} + void RegionEditor::RegionFxBox::reordered () { diff --git a/gtk2_ardour/region_editor.h b/gtk2_ardour/region_editor.h index 9d7d8676ae..35ea310db9 100644 --- a/gtk2_ardour/region_editor.h +++ b/gtk2_ardour/region_editor.h @@ -108,6 +108,7 @@ private: bool idle_delete_region_fx (std::weak_ptr); void notify_plugin_load_fail (uint32_t cnt = 1); bool on_key_press (GdkEventKey*); + void clear_automation (std::weak_ptr); /* PluginInterestedObject */ bool use_plugins (SelectedPlugins const&);