Large nasty commit in the form of a 5000 line patch chock-full of completely
[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_undo( bind( mem_fun(rv.region, &AudioRegion::set_envelope_active), false) );
51         }
52 }
53
54 // This is an extended copy from AutomationList
55 void
56 AudioRegionGainLine::remove_point (ControlPoint& cp)
57 {
58         ModelRepresentation mr;
59
60         model_representation (cp, mr);
61
62         trackview.editor.current_session()->begin_reversible_command (_("remove control point"));
63         trackview.editor.current_session()->add_undo (get_memento());
64
65         if (!rv.region.envelope_active()) {
66                 trackview.session().add_undo( bind( mem_fun(rv.region, &AudioRegion::set_envelope_active), false) );
67                 trackview.session().add_redo( bind( mem_fun(rv.region, &AudioRegion::set_envelope_active), true) );
68                 rv.region.set_envelope_active(true);
69         }
70
71         alist.erase (mr.start, mr.end);
72
73         trackview.editor.current_session()->add_redo_no_execute (get_memento());
74         trackview.editor.current_session()->commit_reversible_command ();
75         trackview.editor.current_session()->set_dirty ();
76 }
77
78 void
79 AudioRegionGainLine::end_drag (ControlPoint* cp) 
80 {
81         if (!rv.region.envelope_active()) {
82                 trackview.session().add_redo( bind( mem_fun(rv.region, &AudioRegion::set_envelope_active), true) );
83                 rv.region.set_envelope_active(true);
84         }
85         AutomationLine::end_drag(cp);
86 }
87
88
89 // This is a copy from AutomationList
90 UndoAction
91 AudioRegionGainLine::get_memento ()
92 {
93         return alist.get_memento();
94 }