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