use stringcr_t and gain 1/1000 binary size reduction. not thaat much...
[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
20 AudioRegionGainLine::AudioRegionGainLine (stringcr_t name, Session& s, AudioRegionView& r, ArdourCanvas::Group& parent, Curve& c)
21   : AutomationLine (name, r.get_time_axis_view(), parent, c),
22           session (s),
23           rv (r)
24 {
25         group->raise_to_top ();
26         set_verbose_cursor_uses_gain_mapping (true);
27         terminal_points_can_slide = false;
28 }
29
30 void
31 AudioRegionGainLine::view_to_model_y (double& y)
32 {
33         y = slider_position_to_gain (y);
34         y = max (0.0, y);
35         y = min (2.0, y);
36 }
37
38 void
39 AudioRegionGainLine::model_to_view_y (double& y)
40 {
41         y = gain_to_slider_position (y);
42 }
43
44 void
45 AudioRegionGainLine::start_drag (ControlPoint* cp, float fraction) 
46 {
47         AutomationLine::start_drag(cp,fraction);
48         if (!rv.region.envelope_active()) {
49                 trackview.session().add_undo( bind( mem_fun(rv.region, &AudioRegion::set_envelope_active), false) );
50         }
51 }
52
53 // This is an extended copy from AutomationList
54 void
55 AudioRegionGainLine::remove_point (ControlPoint& cp)
56 {
57         ModelRepresentation mr;
58
59         model_representation (cp, mr);
60
61         trackview.editor.current_session()->begin_reversible_command (_("remove control point"));
62         trackview.editor.current_session()->add_undo (get_memento());
63
64         if (!rv.region.envelope_active()) {
65                 trackview.session().add_undo( bind( mem_fun(rv.region, &AudioRegion::set_envelope_active), false) );
66                 trackview.session().add_redo( bind( mem_fun(rv.region, &AudioRegion::set_envelope_active), true) );
67                 rv.region.set_envelope_active(true);
68         }
69
70         alist.erase (mr.start, mr.end);
71
72         trackview.editor.current_session()->add_redo_no_execute (get_memento());
73         trackview.editor.current_session()->commit_reversible_command ();
74         trackview.editor.current_session()->set_dirty ();
75 }
76
77 void
78 AudioRegionGainLine::end_drag (ControlPoint* cp) 
79 {
80         if (!rv.region.envelope_active()) {
81                 trackview.session().add_redo( bind( mem_fun(rv.region, &AudioRegion::set_envelope_active), true) );
82                 rv.region.set_envelope_active(true);
83         }
84         AutomationLine::end_drag(cp);
85 }
86
87
88 // This is a copy from AutomationList
89 UndoAction
90 AudioRegionGainLine::get_memento ()
91 {
92         return alist.get_memento();
93 }