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