enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / audio_time_axis.cc
1 /*
2     Copyright (C) 2000-2006 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 <cstdlib>
21 #include <cmath>
22 #include <cassert>
23
24 #include <algorithm>
25 #include <string>
26 #include <vector>
27
28 #include <sigc++/bind.h>
29
30 #include "pbd/error.h"
31 #include "pbd/stl_delete.h"
32 #include "pbd/memento_command.h"
33
34 #include "gtkmm2ext/gtk_ui.h"
35 #include "gtkmm2ext/selector.h"
36 #include "gtkmm2ext/bindable_button.h"
37 #include "gtkmm2ext/utils.h"
38
39 #include "ardour/event_type_map.h"
40 #include "ardour/pannable.h"
41 #include "ardour/panner.h"
42 #include "ardour/panner_shell.h"
43
44 #include "ardour_button.h"
45 #include "audio_time_axis.h"
46 #include "automation_line.h"
47 #include "enums.h"
48 #include "gui_thread.h"
49 #include "automation_time_axis.h"
50 #include "keyboard.h"
51 #include "playlist_selector.h"
52 #include "prompter.h"
53 #include "public_editor.h"
54 #include "audio_region_view.h"
55 #include "audio_streamview.h"
56 #include "utils.h"
57
58 #include "pbd/i18n.h"
59
60 using namespace std;
61 using namespace ARDOUR;
62 using namespace ARDOUR_UI_UTILS;
63 using namespace PBD;
64 using namespace Gtk;
65 using namespace Editing;
66
67 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, ArdourCanvas::Canvas& canvas)
68         : SessionHandlePtr (sess)
69         , RouteTimeAxisView(ed, sess, canvas)
70 {
71 }
72
73 void
74 AudioTimeAxisView::set_route (boost::shared_ptr<Route> rt)
75 {
76         _route = rt;
77
78         /* RouteTimeAxisView::set_route() sets up some things in the View,
79            so it must be created before RouteTimeAxis::set_route() is
80            called.
81         */
82         _view = new AudioStreamView (*this);
83
84         RouteTimeAxisView::set_route (rt);
85
86         _view->apply_color (gdk_color_to_rgba (color()), StreamView::RegionColor);
87
88         // Make sure things are sane...
89         assert(!is_track() || is_audio_track());
90
91         subplugin_menu.set_name ("ArdourContextMenu");
92
93         ignore_toggle = false;
94
95         if (is_audio_track()) {
96                 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
97                 time_axis_frame.set_name ("AudioTrackControlsBaseUnselected");
98         } else { // bus
99                 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
100                 time_axis_frame.set_name ("AudioBusControlsBaseUnselected");
101         }
102
103         /* if set_state above didn't create a gain automation child, we need to make one */
104         if (automation_child (GainAutomation) == 0) {
105                 create_automation_child (GainAutomation, false);
106         }
107
108         if (automation_child (TrimAutomation) == 0) {
109                 create_automation_child (TrimAutomation, false);
110         }
111
112         /* if set_state above didn't create a mute automation child, we need to make one */
113         if (automation_child (MuteAutomation) == 0) {
114                 create_automation_child (MuteAutomation, false);
115         }
116
117         if (_route->panner_shell()) {
118                 _route->panner_shell()->Changed.connect (*this, invalidator (*this),
119                                                          boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
120         }
121
122         /* map current state of the route */
123
124         processors_changed (RouteProcessorChange ());
125         reset_processor_automation_curves ();
126         ensure_pan_views (false);
127         update_control_names ();
128
129         if (is_audio_track()) {
130
131                 /* ask for notifications of any new RegionViews */
132                 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
133
134                 if (!_editor.have_idled()) {
135                         /* first idle will do what we need */
136                 } else {
137                         first_idle ();
138                 }
139
140         } else {
141                 post_construct ();
142         }
143 }
144
145 AudioTimeAxisView::~AudioTimeAxisView ()
146 {
147 }
148
149 void
150 AudioTimeAxisView::first_idle ()
151 {
152         _view->attach ();
153         post_construct ();
154 }
155
156 AudioStreamView*
157 AudioTimeAxisView::audio_view()
158 {
159         return dynamic_cast<AudioStreamView*>(_view);
160 }
161
162 guint32
163 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
164 {
165         set_gui_property ("visible", true);
166         return TimeAxisView::show_at (y, nth, parent);
167 }
168
169 void
170 AudioTimeAxisView::hide ()
171 {
172         set_gui_property ("visible", false);
173         TimeAxisView::hide ();
174 }
175
176 void
177 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
178 {
179         if (param.type() == NullAutomation) {
180                 return;
181         }
182
183         AutomationTracks::iterator existing = _automation_tracks.find (param);
184
185         if (existing != _automation_tracks.end()) {
186
187                 /* automation track created because we had existing data for
188                  * the processor, but visibility may need to be controlled
189                  * since it will have been set visible by default.
190                  */
191
192                 existing->second->set_marked_for_display (show);
193
194                 if (!no_redraw) {
195                         request_redraw ();
196                 }
197
198                 return;
199         }
200
201         if (param.type() == GainAutomation) {
202
203                 create_gain_automation_child (param, show);
204
205         } else if (param.type() == TrimAutomation) {
206
207                 create_trim_automation_child (param, show);
208
209         } else if (param.type() == PanWidthAutomation ||
210                    param.type() == PanElevationAutomation ||
211                    param.type() == PanAzimuthAutomation) {
212
213                 ensure_pan_views (show);
214
215         } else if (param.type() == PluginAutomation) {
216
217                 /* handled elsewhere */
218
219         } else if (param.type() == MuteAutomation) {
220
221                 create_mute_automation_child (param, show);
222
223
224         } else {
225                 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
226         }
227 }
228
229 void
230 AudioTimeAxisView::show_all_automation (bool apply_to_selection)
231 {
232         if (apply_to_selection) {
233                 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_all_automation, _1, false));
234         } else {
235
236                 no_redraw = true;
237
238                 RouteTimeAxisView::show_all_automation ();
239
240                 no_redraw = false;
241                 request_redraw ();
242         }
243 }
244
245 void
246 AudioTimeAxisView::show_existing_automation (bool apply_to_selection)
247 {
248         if (apply_to_selection) {
249                 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_existing_automation, _1, false));
250         } else {
251                 no_redraw = true;
252
253                 RouteTimeAxisView::show_existing_automation ();
254
255                 no_redraw = false;
256
257                 request_redraw ();
258         }
259 }
260
261 void
262 AudioTimeAxisView::hide_all_automation (bool apply_to_selection)
263 {
264         if (apply_to_selection) {
265                 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::hide_all_automation, _1, false));
266         } else {
267                 no_redraw = true;
268
269                 RouteTimeAxisView::hide_all_automation();
270
271                 no_redraw = false;
272                 request_redraw ();
273         }
274 }
275
276 void
277 AudioTimeAxisView::route_active_changed ()
278 {
279         update_control_names ();
280 }
281
282
283 /**
284  *    Set up the names of the controls so that they are coloured
285  *    correctly depending on whether this route is inactive or
286  *    selected.
287  */
288
289 void
290 AudioTimeAxisView::update_control_names ()
291 {
292         if (is_audio_track()) {
293                 if (_route->active()) {
294                         controls_base_selected_name = "AudioTrackControlsBaseSelected";
295                         controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
296                 } else {
297                         controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
298                         controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
299                 }
300         } else {
301                 if (_route->active()) {
302                         controls_base_selected_name = "BusControlsBaseSelected";
303                         controls_base_unselected_name = "BusControlsBaseUnselected";
304                 } else {
305                         controls_base_selected_name = "BusControlsBaseInactiveSelected";
306                         controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
307                 }
308         }
309
310         if (selected()) {
311                 controls_ebox.set_name (controls_base_selected_name);
312                 time_axis_frame.set_name (controls_base_selected_name);
313         } else {
314                 controls_ebox.set_name (controls_base_unselected_name);
315                 time_axis_frame.set_name (controls_base_unselected_name);
316         }
317 }
318
319 void
320 AudioTimeAxisView::build_automation_action_menu (bool for_selection)
321 {
322         RouteTimeAxisView::build_automation_action_menu (for_selection);
323 }