Remove redundant view <-> model value mapping stuff from AudioRegionGainLine.
[ardour.git] / gtk2_ardour / region_gain_line.cc
1 /*
2     Copyright (C) 2000-2007 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #include <ardour/curve.h>
21 #include <ardour/audioregion.h>
22 #include <pbd/memento_command.h>
23
24 #include "region_gain_line.h"
25 #include "audio_region_view.h"
26 #include "utils.h"
27
28 #include "time_axis_view.h"
29 #include "editor.h"
30
31 #include <ardour/session.h>
32
33
34 #include "i18n.h"
35
36
37 using namespace std;
38 using namespace ARDOUR;
39 using namespace PBD;
40
41 AudioRegionGainLine::AudioRegionGainLine (const string & name, Session& s, AudioRegionView& r, ArdourCanvas::Group& parent, boost::shared_ptr<AutomationList> l)
42   : AutomationLine (name, r.get_time_axis_view(), parent, l),
43           session (s),
44           rv (r)
45 {
46         // If this isn't true something is horribly wrong, and we'll get catastrophic gain values
47         assert(l->parameter().type() == EnvelopeAutomation);
48
49         group->raise_to_top ();
50         set_verbose_cursor_uses_gain_mapping (true);
51         terminal_points_can_slide = false;
52 }
53
54 void
55 AudioRegionGainLine::start_drag (ControlPoint* cp, nframes_t x, float fraction) 
56 {
57         AutomationLine::start_drag (cp, x, fraction);
58         if (!rv.audio_region()->envelope_active()) {
59                 trackview.session().add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), &rv.audio_region()->get_state(), 0));
60                 rv.audio_region()->set_envelope_active(false);
61         } 
62 }
63
64 // This is an extended copy from AutomationList
65 void
66 AudioRegionGainLine::remove_point (ControlPoint& cp)
67 {
68         ModelRepresentation mr;
69
70         model_representation (cp, mr);
71
72         trackview.editor.current_session()->begin_reversible_command (_("remove control point"));
73         XMLNode &before = alist->get_state();
74
75         if (!rv.audio_region()->envelope_active()) {
76                 XMLNode &region_before = rv.audio_region()->get_state();
77                 rv.audio_region()->set_envelope_active(true);
78                 XMLNode &region_after = rv.audio_region()->get_state();
79                 trackview.session().add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), &region_before, &region_after));
80         } 
81         
82         alist->erase (mr.start, mr.end);
83
84         trackview.editor.current_session()->add_command (new MementoCommand<AutomationList>(*alist.get(), &before, &alist->get_state()));
85         trackview.editor.current_session()->commit_reversible_command ();
86         trackview.editor.current_session()->set_dirty ();
87 }
88
89 void
90 AudioRegionGainLine::end_drag (ControlPoint* cp) 
91 {
92         if (!rv.audio_region()->envelope_active()) {
93                 rv.audio_region()->set_envelope_active(true);
94                 trackview.session().add_command(new MementoCommand<AudioRegion>(*(rv.audio_region().get()), 0, &rv.audio_region()->get_state()));
95         } 
96
97         AutomationLine::end_drag(cp);
98 }
99