From ad9a3ae1039d326ad70250ebf912347018bfa63b Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 14 Apr 2024 19:37:09 +0200 Subject: [PATCH] Fix region-gain envelope auto-enable when dragging When using freehand drawing of automation, the line itself is not notified (no ::start_drag(), ::end_drag() calls). This adds a end_draw() call which allows the AutomatioLine to perform additional actions. --- gtk2_ardour/automation_line.h | 1 + gtk2_ardour/mergeable_line.cc | 2 ++ gtk2_ardour/region_gain_line.cc | 34 +++++++++++++++++++++++++++++++++ gtk2_ardour/region_gain_line.h | 3 +++ 4 files changed, 40 insertions(+) diff --git a/gtk2_ardour/automation_line.h b/gtk2_ardour/automation_line.h index 8aac3799f2..efa557851b 100644 --- a/gtk2_ardour/automation_line.h +++ b/gtk2_ardour/automation_line.h @@ -94,6 +94,7 @@ public: virtual void start_drag_multiple (std::list, float, XMLNode *); virtual std::pair drag_motion (Temporal::timecnt_t const &, float, bool, bool with_push, uint32_t& final_index); virtual void end_drag (bool with_push, uint32_t final_index); + virtual void end_draw_merge () {} ControlPoint* nth (uint32_t); ControlPoint const * nth (uint32_t) const; diff --git a/gtk2_ardour/mergeable_line.cc b/gtk2_ardour/mergeable_line.cc index d554b05133..6a39644ac7 100644 --- a/gtk2_ardour/mergeable_line.cc +++ b/gtk2_ardour/mergeable_line.cc @@ -103,6 +103,8 @@ MergeableLine::merge_drawn_line (Editor& e, Session& s, Evoral::ControlList::Ord e.begin_reversible_command (_("draw automation")); s.add_command (new MementoCommand (*list.get (), &before, &after)); + _line->end_draw_merge (); + _line->get_selectables (earliest, latest, 0.0, 1.0, results); e.get_selection ().set (results); diff --git a/gtk2_ardour/region_gain_line.cc b/gtk2_ardour/region_gain_line.cc index cc7bff9b4b..14830e95f9 100644 --- a/gtk2_ardour/region_gain_line.cc +++ b/gtk2_ardour/region_gain_line.cc @@ -77,6 +77,28 @@ AudioRegionGainLine::start_drag_single (ControlPoint* cp, double x, float fracti } } +void +AudioRegionGainLine::start_drag_line (uint32_t i1, uint32_t i2, float fraction) +{ + AutomationLine::start_drag_line (i1, i2, fraction); + + if (!rv.audio_region()->envelope_active()) { + trackview.session()->add_command(new MementoCommand(*(rv.audio_region().get()), &rv.audio_region()->get_state(), 0)); + rv.audio_region()->set_envelope_active(false); + } +} + +void +AudioRegionGainLine::start_drag_multiple (list cp, float fraction, XMLNode* state) +{ + AutomationLine::start_drag_multiple (cp, fraction, state); + + if (!rv.audio_region()->envelope_active()) { + trackview.session()->add_command(new MementoCommand(*(rv.audio_region().get()), &rv.audio_region()->get_state(), 0)); + rv.audio_region()->set_envelope_active(false); + } +} + // This is an extended copy from AutomationList void AudioRegionGainLine::remove_point (ControlPoint& cp) @@ -109,6 +131,18 @@ AudioRegionGainLine::end_drag (bool with_push, uint32_t final_index) AutomationLine::end_drag (with_push, final_index); } +void +AudioRegionGainLine::end_draw_merge () +{ + if (!rv.audio_region()->envelope_active()) { + XMLNode& before = rv.audio_region()->get_state(); + rv.audio_region()->set_envelope_active(true); + trackview.session()->add_command(new MementoCommand(*(rv.audio_region().get()), &before, &rv.audio_region()->get_state())); + } + + AutomationLine::end_draw_merge (); +} + void AudioRegionGainLine::region_changed (const PropertyChange& what_changed) { diff --git a/gtk2_ardour/region_gain_line.h b/gtk2_ardour/region_gain_line.h index 2959357f61..9a2daccb91 100644 --- a/gtk2_ardour/region_gain_line.h +++ b/gtk2_ardour/region_gain_line.h @@ -45,7 +45,10 @@ public: Temporal::timepos_t get_origin() const; void start_drag_single (ControlPoint*, double, float); + void start_drag_line (uint32_t, uint32_t, float); + void start_drag_multiple (std::list, float, XMLNode*); void end_drag (bool with_push, uint32_t final_index); + void end_draw_merge (); void remove_point (ControlPoint&); AudioRegionView& region_view () { return rv; }