2 * Copyright (C) 2005-2016 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
4 * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
5 * Copyright (C) 2006-2014 David Robillard <d@drobilla.net>
6 * Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
7 * Copyright (C) 2014-2015 Nick Mainsbridge <mainsbridge@gmail.com>
8 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "evoral/Curve.h"
26 #include "pbd/memento_command.h"
27 #include "pbd/stateful_diff_command.h"
29 #include "ardour/audioregion.h"
30 #include "ardour/session.h"
32 #include "control_point.h"
33 #include "region_gain_line.h"
34 #include "audio_region_view.h"
36 #include "time_axis_view.h"
38 #include "gui_thread.h"
43 using namespace ARDOUR;
46 AudioRegionGainLine::AudioRegionGainLine (const string & name, AudioRegionView& r, ArdourCanvas::Container& parent, boost::shared_ptr<AutomationList> l)
47 : AutomationLine (name, r.get_time_axis_view(), parent, l, l->parameter())
50 // If this isn't true something is horribly wrong, and we'll get catastrophic gain values
51 assert(l->parameter().type() == EnvelopeAutomation);
53 _time_converter->set_origin_b (rv.region()->position());
55 r.region()->PropertyChanged.connect (_region_changed_connection, invalidator (*this), boost::bind (&AudioRegionGainLine::region_changed, this, _1), gui_context());
57 group->raise_to_top ();
58 group->set_y_position (2);
59 terminal_points_can_slide = false;
63 AudioRegionGainLine::start_drag_single (ControlPoint* cp, double x, float fraction)
65 AutomationLine::start_drag_single (cp, x, fraction);
67 // XXX Stateful need to capture automation curve data
69 if (!rv.audio_region()->envelope_active()) {
70 trackview.session()->add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), &rv.audio_region()->get_state(), 0));
71 rv.audio_region()->set_envelope_active(false);
75 // This is an extended copy from AutomationList
77 AudioRegionGainLine::remove_point (ControlPoint& cp)
79 trackview.editor().begin_reversible_command (_("remove control point"));
80 XMLNode &before = alist->get_state();
82 if (!rv.audio_region()->envelope_active()) {
83 rv.audio_region()->clear_changes ();
84 rv.audio_region()->set_envelope_active(true);
85 trackview.session()->add_command(new StatefulDiffCommand (rv.audio_region()));
88 trackview.editor ().get_selection ().clear_points ();
89 alist->erase (cp.model());
91 trackview.editor().session()->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
92 trackview.editor().commit_reversible_command ();
93 trackview.editor().session()->set_dirty ();
97 AudioRegionGainLine::end_drag (bool with_push, uint32_t final_index)
99 if (!rv.audio_region()->envelope_active()) {
100 rv.audio_region()->set_envelope_active(true);
101 trackview.session()->add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), 0, &rv.audio_region()->get_state()));
104 AutomationLine::end_drag (with_push, final_index);
108 AudioRegionGainLine::region_changed (const PropertyChange& what_changed)
110 PropertyChange interesting_stuff;
112 interesting_stuff.add (ARDOUR::Properties::start);
113 interesting_stuff.add (ARDOUR::Properties::position);
115 if (what_changed.contains (interesting_stuff)) {
116 _time_converter->set_origin_b (rv.region()->position());
119 interesting_stuff.clear ();
120 interesting_stuff.add (ARDOUR::Properties::start);
121 interesting_stuff.add (ARDOUR::Properties::length);
123 if (what_changed.contains (interesting_stuff)) {