Merged with trunk R708
[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 #include "canvas_impl.h"
30
31 #include "i18n.h"
32
33 using namespace ARDOUR;
34 using namespace PBD;
35 using namespace Gtk;
36
37 PanAutomationTimeAxisView::PanAutomationTimeAxisView (Session& s, boost::shared_ptr<Route> r, PublicEditor& e, 
38                                                       TimeAxisView& parent, Canvas& canvas, std::string n)
39
40         : AxisView (s),
41           AutomationTimeAxisView (s, r, e, parent, canvas, n, X_("pan"), "")
42 {
43         multiline_selector.set_name ("PanAutomationLineSelector");
44         
45         controls_table.attach (multiline_selector, 1, 5, 1, 2, Gtk::FILL | Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
46 }
47
48 PanAutomationTimeAxisView::~PanAutomationTimeAxisView ()
49 {
50 }
51
52 void
53 PanAutomationTimeAxisView::add_automation_event (ArdourCanvas::Item* item, GdkEvent* event, jack_nframes_t when, double y)
54 {
55         if (lines.empty()) {
56                 /* no data, possibly caused by no outputs/inputs */
57                 return;
58         }
59
60         int line_index = 0;
61
62         if (lines.size() > 1) {
63                 line_index = multiline_selector.get_active_row_number();
64
65                 if (line_index < 0 || line_index >= (int)lines.size()) {
66                         Gtkmm2ext::PopUp* msg = new Gtkmm2ext::PopUp (Gtk::WIN_POS_MOUSE, 5000, true);
67                 
68                         msg->set_text (_("You need to select which line to edit"));
69                         msg->touch ();
70
71                         return;
72                 }
73         }
74
75         double x = 0;
76
77         canvas_display->w2i (x, y);
78
79         /* compute vertical fractional position */
80
81         y = 1.0 - (y / height);
82
83         /* map using line */
84
85         lines.front()->view_to_model_y (y);
86
87         AutomationList& alist (lines[line_index]->the_list());
88
89         _session.begin_reversible_command (_("add pan automation event"));
90         _session.add_undo (alist.get_memento());
91         alist.add (when, y);
92         _session.add_redo_no_execute (alist.get_memento());
93         _session.commit_reversible_command ();
94         _session.set_dirty ();
95 }
96
97 void
98 PanAutomationTimeAxisView::clear_lines ()
99 {
100         AutomationTimeAxisView::clear_lines();
101         multiline_selector.clear();
102 }
103
104 void
105 PanAutomationTimeAxisView::add_line (AutomationLine& line)
106 {
107         char buf[32];
108         snprintf(buf,32,"Line %ld",lines.size()+1);
109         multiline_selector.append_text(buf);
110
111         if (lines.empty()) {
112                 multiline_selector.set_active(0);
113         }
114
115         if (lines.size() + 1 > 1) {
116                 multiline_selector.show();
117         }
118
119         AutomationTimeAxisView::add_line(line);
120 }
121
122 void
123 PanAutomationTimeAxisView::set_height (TimeAxisView::TrackHeight th)
124 {
125         AutomationTimeAxisView::set_height(th);
126
127         switch (th) {
128                 case Largest:
129                 case Large:
130                 case Larger:
131                 case Normal:
132                         multiline_selector.show();
133                         break;
134
135                 default:
136                         multiline_selector.hide();
137         }
138 }
139
140 void
141 PanAutomationTimeAxisView::set_automation_state (AutoState state)
142 {
143         if (!ignore_state_request) {
144                 route->panner().set_automation_state (state);
145         }
146 }