2 Copyright (C) 2000-2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "evoral/Curve.hpp"
21 #include "pbd/memento_command.h"
22 #include "pbd/stateful_diff_command.h"
24 #include "ardour/audioregion.h"
25 #include "ardour/session.h"
27 #include "control_point.h"
28 #include "region_gain_line.h"
29 #include "audio_region_view.h"
31 #include "time_axis_view.h"
33 #include "gui_thread.h"
38 using namespace ARDOUR;
41 AudioRegionGainLine::AudioRegionGainLine (const string & name, AudioRegionView& r, ArdourCanvas::Container& parent, boost::shared_ptr<AutomationList> l)
42 : AutomationLine (name, r.get_time_axis_view(), parent, l, l->parameter())
45 // If this isn't true something is horribly wrong, and we'll get catastrophic gain values
46 assert(l->parameter().type() == EnvelopeAutomation);
48 _time_converter->set_origin_b (rv.region()->position());
50 r.region()->PropertyChanged.connect (_region_changed_connection, invalidator (*this), boost::bind (&AudioRegionGainLine::region_changed, this, _1), gui_context());
52 group->raise_to_top ();
53 group->set_y_position (2);
54 set_uses_gain_mapping (true);
55 terminal_points_can_slide = false;
59 AudioRegionGainLine::start_drag_single (ControlPoint* cp, double x, float fraction)
61 AutomationLine::start_drag_single (cp, x, fraction);
63 // XXX Stateful need to capture automation curve data
65 if (!rv.audio_region()->envelope_active()) {
66 trackview.session()->add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), &rv.audio_region()->get_state(), 0));
67 rv.audio_region()->set_envelope_active(false);
71 // This is an extended copy from AutomationList
73 AudioRegionGainLine::remove_point (ControlPoint& cp)
75 trackview.editor().begin_reversible_command (_("remove control point"));
76 XMLNode &before = alist->get_state();
78 if (!rv.audio_region()->envelope_active()) {
79 rv.audio_region()->clear_changes ();
80 rv.audio_region()->set_envelope_active(true);
81 trackview.session()->add_command(new StatefulDiffCommand (rv.audio_region()));
84 alist->erase (cp.model());
86 trackview.editor().session()->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
87 trackview.editor().commit_reversible_command ();
88 trackview.editor().session()->set_dirty ();
92 AudioRegionGainLine::end_drag (bool with_push, uint32_t final_index)
94 if (!rv.audio_region()->envelope_active()) {
95 rv.audio_region()->set_envelope_active(true);
96 trackview.session()->add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), 0, &rv.audio_region()->get_state()));
99 AutomationLine::end_drag (with_push, final_index);
103 AudioRegionGainLine::region_changed (const PropertyChange& what_changed)
105 PropertyChange interesting_stuff;
107 interesting_stuff.add (ARDOUR::Properties::start);
108 interesting_stuff.add (ARDOUR::Properties::position);
110 if (what_changed.contains (interesting_stuff)) {
111 _time_converter->set_origin_b (rv.region()->position());