1697adbb9c565dd5bbf07fb75dc4815d8e5477d1
[ardour.git] / gtk2_ardour / gain_automation_time_axis.cc
1 /*
2     Copyright (C) 2003 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     $Id$
19 */
20
21 #include <ardour/curve.h>
22 #include <ardour/route.h>
23
24 #include "gain_automation_time_axis.h"
25 #include "automation_line.h"
26 #include "canvas.h"
27
28 #include "i18n.h"
29
30 using namespace ARDOUR;
31 using namespace PBD;
32 using namespace Gtk;
33
34 GainAutomationTimeAxisView::GainAutomationTimeAxisView (Session& s, Route& r, PublicEditor& e, TimeAxisView& parent, ArdourCanvas::Canvas& canvas, const string & n, ARDOUR::Curve& c)
35
36         : AxisView (s),
37           AutomationTimeAxisView (s, r, e, parent, canvas, n, X_("gain"), ""),
38           curve (c)
39         
40 {
41 }
42
43 GainAutomationTimeAxisView::~GainAutomationTimeAxisView ()
44 {
45 }
46
47 void
48 GainAutomationTimeAxisView::add_automation_event (ArdourCanvas::Item* item, GdkEvent* event, jack_nframes_t when, double y)
49 {
50         double x = 0;
51
52         canvas_display->w2i (x, y);
53
54         /* compute vertical fractional position */
55
56         y = 1.0 - (y / height);
57
58         /* map using line */
59
60         lines.front()->view_to_model_y (y);
61
62         _session.begin_reversible_command (_("add gain automation event"));
63
64         XMLNode &before, &after;
65         before = curve.get_state();
66         curve.add (when, y);
67         after = curve.get_state();
68         _session.add_command(MementoCommand<ARDOUR::Curve>(curve, before, after));
69         _session.commit_reversible_command ();
70         _session.set_dirty ();
71 }
72
73 void
74 GainAutomationTimeAxisView::set_automation_state (AutoState state)
75 {
76         if (!ignore_state_request) {
77                 route.set_gain_automation_state (state);
78         }
79 }