587a42f3e5b450201538bec2eee6ea4ac0b8d12c
[ardour.git] / gtk2_ardour / pan_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 #include <ardour/panner.h>
24
25 #include <gtkmm2ext/popup.h>
26
27 #include "pan_automation_time_axis.h"
28 #include "automation_line.h"
29
30 #include "i18n.h"
31
32 using namespace ARDOUR;
33 using namespace Gtk;
34
35 PanAutomationTimeAxisView::PanAutomationTimeAxisView (Session& s, Route& r, PublicEditor& e, TimeAxisView& parent, Widget* p, std::string n)
36
37         : AxisView (s),
38           AutomationTimeAxisView (s, r, e, parent, p, n, X_("pan"), "")
39 {
40 }
41
42 PanAutomationTimeAxisView::~PanAutomationTimeAxisView ()
43 {
44 }
45
46 void
47 PanAutomationTimeAxisView::add_automation_event (GtkCanvasItem* item, GdkEvent* event, jack_nframes_t when, double y)
48 {
49         if (lines.empty()) {
50                 /* no data, possibly caused by no outputs/inputs */
51                 return;
52         }
53
54         if (lines.size() > 1) {
55
56                 Gtkmm2ext::PopUp* msg = new Gtkmm2ext::PopUp (Gtk::WIN_POS_MOUSE, 5000, true);
57                 
58                 msg->set_text (_("You can't graphically edit panning of more than stream"));
59                 msg->touch ();
60                 
61                 return;
62         }
63
64         double x = 0;
65
66         gtk_canvas_item_w2i (canvas_display, &x, &y);
67
68         /* compute vertical fractional position */
69
70         y = 1.0 - (y / height);
71
72         /* map using line */
73
74         lines.front()->view_to_model_y (y);
75
76         AutomationList& alist (lines.front()->the_list());
77
78         _session.begin_reversible_command (_("add pan automation event"));
79         _session.add_undo (alist.get_memento());
80         alist.add (when, y);
81         _session.add_undo (alist.get_memento());
82         _session.commit_reversible_command ();
83         _session.set_dirty ();
84 }
85
86 void
87 PanAutomationTimeAxisView::set_automation_state (AutoState state)
88 {
89         if (!ignore_state_request) {
90                 route.panner().set_automation_state (state);
91         }
92 }