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