Switched to use libgnomecanvas (not the C++ one).
[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
27 #include "i18n.h"
28
29 using namespace ARDOUR;
30 using namespace Gtk;
31
32 GainAutomationTimeAxisView::GainAutomationTimeAxisView (Session& s, Route& r, PublicEditor& e, TimeAxisView& parent, Widget* p, std::string n, ARDOUR::Curve& c)
33
34         : AxisView (s),
35           AutomationTimeAxisView (s, r, e, parent, p, n, X_("gain"), ""),
36           curve (c)
37         
38 {
39 }
40
41 GainAutomationTimeAxisView::~GainAutomationTimeAxisView ()
42 {
43 }
44
45 void
46 GainAutomationTimeAxisView::add_automation_event (GnomeCanvasItem* item, GdkEvent* event, jack_nframes_t when, double y)
47 {
48         double x = 0;
49
50         gnome_canvas_item_w2i (canvas_display, &x, &y);
51
52         /* compute vertical fractional position */
53
54         y = 1.0 - (y / height);
55
56         /* map using line */
57
58         lines.front()->view_to_model_y (y);
59
60         _session.begin_reversible_command (_("add gain automation event"));
61
62         _session.add_undo (curve.get_memento());
63         curve.add (when, y);
64         _session.add_redo_no_execute (curve.get_memento());
65         _session.commit_reversible_command ();
66         _session.set_dirty ();
67 }
68
69 void
70 GainAutomationTimeAxisView::set_automation_state (AutoState state)
71 {
72         if (!ignore_state_request) {
73                 route.set_gain_automation_state (state);
74         }
75 }