changes associated with save/restore of AutomationControl id's
[ardour2.git] / gtk2_ardour / region_gain_line.cc
blob2ad1ee2c7dedac16d1fce7cf427da3f4b8f3e72a
1 /*
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 "region_gain_line.h"
28 #include "audio_region_view.h"
29 #include "utils.h"
31 #include "time_axis_view.h"
32 #include "editor.h"
34 #include "i18n.h"
36 using namespace std;
37 using namespace ARDOUR;
38 using namespace PBD;
40 AudioRegionGainLine::AudioRegionGainLine (const string & name, AudioRegionView& r, ArdourCanvas::Group& parent, boost::shared_ptr<AutomationList> l)
41 : AutomationLine (name, r.get_time_axis_view(), parent, l)
42 , rv (r)
44 // If this isn't true something is horribly wrong, and we'll get catastrophic gain values
45 assert(l->parameter().type() == EnvelopeAutomation);
47 group->raise_to_top ();
48 group->property_y() = 2;
49 set_uses_gain_mapping (true);
50 terminal_points_can_slide = false;
53 void
54 AudioRegionGainLine::start_drag_single (ControlPoint* cp, double x, float fraction)
56 AutomationLine::start_drag_single (cp, x, fraction);
58 // XXX Stateful need to capture automation curve data
60 if (!rv.audio_region()->envelope_active()) {
61 trackview.session()->add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), &rv.audio_region()->get_state(), 0));
62 rv.audio_region()->set_envelope_active(false);
66 // This is an extended copy from AutomationList
67 void
68 AudioRegionGainLine::remove_point (ControlPoint& cp)
70 ModelRepresentation mr;
72 model_representation (cp, mr);
74 trackview.editor().session()->begin_reversible_command (_("remove control point"));
75 XMLNode &before = alist->get_state();
77 if (!rv.audio_region()->envelope_active()) {
78 rv.audio_region()->clear_changes ();
79 rv.audio_region()->set_envelope_active(true);
80 trackview.session()->add_command(new StatefulDiffCommand (rv.audio_region()));
83 alist->erase (mr.start, mr.end);
85 trackview.editor().session()->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
86 trackview.editor().session()->commit_reversible_command ();
87 trackview.editor().session()->set_dirty ();
90 void
91 AudioRegionGainLine::end_drag ()
93 if (!rv.audio_region()->envelope_active()) {
94 rv.audio_region()->set_envelope_active(true);
95 trackview.session()->add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), 0, &rv.audio_region()->get_state()));
98 AutomationLine::end_drag ();