2faa63151bf9442a7d0a5dc26eb5444145b6ef6c
[ardour.git] / gtk2_ardour / region_gain_line.cc
1 #include <ardour/curve.h>
2 #include <ardour/audioregion.h>
3
4 #include "region_gain_line.h"
5 #include "regionview.h"
6 #include "utils.h"
7
8 #include "time_axis_view.h"
9 #include "editor.h"
10
11 #include <ardour/session.h>
12
13
14 #include "i18n.h"
15
16
17 using namespace std;
18 using namespace ARDOUR;
19 using namespace PBD;
20
21 AudioRegionGainLine::AudioRegionGainLine (const string & name, Session& s, AudioRegionView& r, ArdourCanvas::Group& parent, Curve& c)
22   : AutomationLine (name, r.get_time_axis_view(), parent, c),
23           session (s),
24           rv (r)
25 {
26         group->raise_to_top ();
27         set_verbose_cursor_uses_gain_mapping (true);
28         terminal_points_can_slide = false;
29 }
30
31 void
32 AudioRegionGainLine::view_to_model_y (double& y)
33 {
34         y = slider_position_to_gain (y);
35         y = max (0.0, y);
36         y = min (2.0, y);
37 }
38
39 void
40 AudioRegionGainLine::model_to_view_y (double& y)
41 {
42         y = gain_to_slider_position (y);
43 }
44
45 void
46 AudioRegionGainLine::start_drag (ControlPoint* cp, float fraction) 
47 {
48         AutomationLine::start_drag(cp,fraction);
49         if (!rv.region.envelope_active()) {
50                 trackview.session().add_command(MementoUndoCommand<AudioRegion>(rv.region, rv.region.get_state()));
51                 rv.region.set_envelope_active(false);
52         }
53 }
54
55 // This is an extended copy from AutomationList
56 void
57 AudioRegionGainLine::remove_point (ControlPoint& cp)
58 {
59         ModelRepresentation mr;
60
61         model_representation (cp, mr);
62
63         trackview.editor.current_session()->begin_reversible_command (_("remove control point"));
64         XMLNode &before = get_state();
65
66         if (!rv.region.envelope_active()) {
67                 XMLNode &before = rv.region.get_state();
68                 rv.region.set_envelope_active(true);
69                 XMLNode &after = rv.region.get_state();
70                 trackview.session().add_command(MementoCommand<AudioRegion>(rv.region, before, after));
71         }
72
73         alist.erase (mr.start, mr.end);
74
75         trackview.editor.current_session()->add_command (MementoCommand<AudioRegionGainLine>(*this, before, get_state()));
76         trackview.editor.current_session()->commit_reversible_command ();
77         trackview.editor.current_session()->set_dirty ();
78 }
79
80 void
81 AudioRegionGainLine::end_drag (ControlPoint* cp) 
82 {
83         if (!rv.region.envelope_active()) {
84                 rv.region.set_envelope_active(true);
85                 trackview.session().add_command(MementoRedoCommand<AudioRegion>(rv.region, rv.region.get_state()));
86         }
87         AutomationLine::end_drag(cp);
88 }
89
90
91 // This is a copy from AutomationList
92 UndoAction
93 AudioRegionGainLine::get_memento ()
94 {
95         return alist.get_memento();
96 }