Display recorded controller data (fix show all/existing automation).
[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/stop_signal.h>
37 #include <gtkmm2ext/bindable_button.h>
38 #include <gtkmm2ext/utils.h>
39
40 #include <ardour/audioplaylist.h>
41 #include <ardour/audio_diskstream.h>
42 #include <ardour/processor.h>
43 #include <ardour/location.h>
44 #include <ardour/panner.h>
45 #include <ardour/playlist.h>
46 #include <ardour/profile.h>
47 #include <ardour/session.h>
48 #include <ardour/session_playlist.h>
49 #include <ardour/utils.h>
50
51 #include "ardour_ui.h"
52 #include "audio_time_axis.h"
53 #include "automation_line.h"
54 #include "canvas_impl.h"
55 #include "crossfade_view.h"
56 #include "enums.h"
57 #include "automation_time_axis.h"
58 #include "keyboard.h"
59 #include "playlist_selector.h"
60 #include "prompter.h"
61 #include "public_editor.h"
62 #include "audio_region_view.h"
63 #include "simplerect.h"
64 #include "audio_streamview.h"
65 #include "utils.h"
66
67 #include <ardour/audio_track.h>
68
69 #include "i18n.h"
70
71 using namespace ARDOUR;
72 using namespace PBD;
73 using namespace Gtk;
74 using namespace Editing;
75
76 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
77         : AxisView(sess)
78         , RouteTimeAxisView(ed, sess, rt, canvas)
79 {
80         // Make sure things are sane...
81         assert(!is_track() || is_audio_track());
82
83         subplugin_menu.set_name ("ArdourContextMenu");
84         waveform_item = 0;
85
86         _view = new AudioStreamView (*this);
87
88         create_automation_child (GainAutomation, false);
89
90         ignore_toggle = false;
91
92         mute_button->set_active (false);
93         solo_button->set_active (false);
94         
95         if (is_audio_track()) {
96                 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
97         } else { // bus
98                 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
99         }
100
101         ensure_xml_node ();
102
103         set_state (*xml_node);
104         
105         _route->panner().Changed.connect (bind (mem_fun(*this, &AudioTimeAxisView::update_pans), false));
106
107         /* map current state of the route */
108
109         processors_changed ();
110         reset_processor_automation_curves ();
111         update_pans (false);
112         update_control_names ();
113
114         if (is_audio_track()) {
115
116                 /* ask for notifications of any new RegionViews */
117                 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
118
119                 if (!editor.have_idled()) {
120                         /* first idle will do what we need */
121                 } else {
122                         first_idle ();
123                 } 
124
125         } else {
126                 post_construct ();
127         }
128 }
129
130 AudioTimeAxisView::~AudioTimeAxisView ()
131 {
132 }
133
134 void
135 AudioTimeAxisView::first_idle ()
136 {
137         _view->attach ();
138         post_construct ();
139 }
140
141 AudioStreamView*
142 AudioTimeAxisView::audio_view()
143 {
144         return dynamic_cast<AudioStreamView*>(_view);
145 }
146
147 guint32
148 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
149 {
150         ensure_xml_node ();
151         xml_node->add_property ("shown_editor", "yes");
152                 
153         return TimeAxisView::show_at (y, nth, parent);
154 }
155
156 void
157 AudioTimeAxisView::hide ()
158 {
159         ensure_xml_node ();
160         xml_node->add_property ("shown_editor", "no");
161
162         TimeAxisView::hide ();
163 }
164
165
166 void
167 AudioTimeAxisView::append_extra_display_menu_items ()
168 {
169         using namespace Menu_Helpers;
170
171         MenuList& items = display_menu->items();
172
173         // crossfade stuff
174         if (!Profile->get_sae()) {
175                 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
176                 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
177         }
178
179         // waveform menu
180         Menu *waveform_menu = manage(new Menu);
181         MenuList& waveform_items = waveform_menu->items();
182         waveform_menu->set_name ("ArdourContextMenu");
183         
184         waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
185         waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
186         ignore_toggle = true;
187         waveform_item->set_active (editor.show_waveforms());
188         ignore_toggle = false;
189
190         waveform_items.push_back (SeparatorElem());
191         
192         RadioMenuItem::Group group;
193         
194         waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
195         traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
196
197         if (!Profile->get_sae()) {
198                 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
199                 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
200         } else {
201                 rectified_item = 0;
202         }
203
204         waveform_items.push_back (SeparatorElem());
205         
206         RadioMenuItem::Group group2;
207
208         waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
209         linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
210
211         waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
212         logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
213
214         // setting initial item state
215         AudioStreamView* asv = audio_view();
216         if (asv) {
217                 ignore_toggle = true;
218                 if (asv->get_waveform_shape() == Rectified && rectified_item) {
219                         rectified_item->set_active(true);
220                 } else {
221                         traditional_item->set_active(true);
222                 }
223
224                 if (asv->get_waveform_scale() == LogWaveform) 
225                         logscale_item->set_active(true);
226                 else linearscale_item->set_active(true);
227                 ignore_toggle = false;
228         }
229
230         items.push_back (MenuElem (_("Waveform"), *waveform_menu));
231
232 }
233         
234 Gtk::Menu*
235 AudioTimeAxisView::build_mode_menu()
236 {
237         using namespace Menu_Helpers;
238
239         Menu* mode_menu = manage (new Menu);
240         MenuList& items = mode_menu->items();
241         mode_menu->set_name ("ArdourContextMenu");
242
243         RadioMenuItem::Group mode_group;
244         items.push_back (RadioMenuElem (mode_group, _("Normal"),
245                                 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Normal)));
246         normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
247         items.push_back (RadioMenuElem (mode_group, _("Tape"),
248                                 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Destructive)));
249         destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
250
251         switch (track()->mode()) {
252                 case ARDOUR::Destructive:
253                         destructive_track_mode_item->set_active ();
254                         break;
255                 case ARDOUR::Normal:
256                         normal_track_mode_item->set_active ();
257                         break;
258         }
259
260         return mode_menu;
261 }
262
263 void
264 AudioTimeAxisView::toggle_waveforms ()
265 {
266         AudioStreamView* asv = audio_view();
267         assert(asv);
268
269         if (asv && waveform_item && !ignore_toggle) {
270                 asv->set_show_waveforms (waveform_item->get_active());
271         }
272 }
273
274 void
275 AudioTimeAxisView::set_show_waveforms (bool yn)
276 {
277         AudioStreamView* asv = audio_view();
278         assert(asv);
279
280         if (waveform_item) {
281                 waveform_item->set_active (yn);
282         } else {
283                 asv->set_show_waveforms (yn);
284         }
285 }
286
287 void
288 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
289 {
290         AudioStreamView* asv = audio_view();
291
292         if (asv) {
293                 asv->set_show_waveforms_recording (yn);
294         }
295 }
296
297 void
298 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
299 {
300         AudioStreamView* asv = audio_view();
301
302         if (asv && !ignore_toggle) {
303                 asv->set_waveform_shape (shape);
304         }
305
306         map_frozen ();
307 }       
308
309 void
310 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
311 {
312         AudioStreamView* asv = audio_view();
313
314         if (asv && !ignore_toggle) {
315                 asv->set_waveform_scale (scale);
316         }
317
318         map_frozen ();
319 }       
320
321 void
322 AudioTimeAxisView::create_automation_child (Parameter param, bool show)
323 {
324         if (param.type() == GainAutomation) {
325
326                 boost::shared_ptr<AutomationControl> c = _route->gain_control();
327                 if (!c) {
328                         error << "Route has no gain automation, unable to add automation track view." << endmsg;
329                         return;
330                 }
331
332                 boost::shared_ptr<AutomationTimeAxisView> gain_track(new AutomationTimeAxisView (_session,
333                                 _route, _route, c,
334                                 editor,
335                                 *this,
336                                 false,
337                                 parent_canvas,
338                                 _route->describe_parameter(param)));
339
340                 add_automation_child(Parameter(GainAutomation), gain_track, show);
341
342         } else if (param.type() == PanAutomation) {
343
344                 ensure_xml_node ();
345                 update_pans (show);
346
347         } else {
348                 error << "AudioTimeAxisView: unknown automation child " << param.symbol() << endmsg;
349         }
350 }
351
352 void
353 AudioTimeAxisView::update_pans (bool show)
354 {
355         Panner::iterator p;
356
357         uint32_t i = 0;
358         for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
359                 boost::shared_ptr<AutomationControl> pan_control = (*p)->pan_control();
360                 
361                 if (pan_control->parameter().type() == NullAutomation) {
362                         error << "Pan control has NULL automation type!" << endmsg;
363                         continue;
364                 }
365
366                 boost::shared_ptr<AutomationTimeAxisView> pan_track(new AutomationTimeAxisView (_session,
367                                         _route, _route, pan_control, 
368                                         editor,
369                                         *this,
370                                         false,
371                                         parent_canvas,
372                                         _route->describe_parameter(pan_control->parameter())));
373                 add_automation_child(Parameter(PanAutomation, i), pan_track, show);
374                 ++i;
375         }
376 }
377                 
378 void
379 AudioTimeAxisView::show_all_automation ()
380 {
381         no_redraw = true;
382
383         RouteTimeAxisView::show_all_automation ();
384
385         no_redraw = false;
386
387          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
388 }
389
390 void
391 AudioTimeAxisView::show_existing_automation ()
392 {
393         no_redraw = true;
394
395         RouteTimeAxisView::show_existing_automation ();
396
397         no_redraw = false;
398
399          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
400 }
401
402 void
403 AudioTimeAxisView::hide_all_automation ()
404 {
405         no_redraw = true;
406
407         RouteTimeAxisView::hide_all_automation();
408
409         no_redraw = false;
410          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
411 }
412
413 void
414 AudioTimeAxisView::show_all_xfades ()
415 {
416         AudioStreamView* asv = audio_view();
417
418         if (asv) {
419                 asv->show_all_xfades ();
420         }
421 }
422
423 void
424 AudioTimeAxisView::hide_all_xfades ()
425 {
426         AudioStreamView* asv = audio_view();
427         
428         if (asv) {
429                 asv->hide_all_xfades ();
430         }
431 }
432
433 void
434 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
435 {
436         AudioStreamView* asv = audio_view();
437         AudioRegionView* rv;
438
439         if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
440                 asv->hide_xfades_involving (*rv);
441         }
442 }
443
444 void
445 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
446 {
447         AudioStreamView* asv = audio_view();
448         AudioRegionView* rv;
449
450         if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
451                 asv->reveal_xfades_involving (*rv);
452         }
453 }
454
455 void
456 AudioTimeAxisView::route_active_changed ()
457 {
458         RouteTimeAxisView::route_active_changed ();
459         update_control_names ();
460 }
461
462
463 /**
464  *    Set up the names of the controls so that they are coloured
465  *    correctly depending on whether this route is inactive or
466  *    selected.
467  */
468
469 void
470 AudioTimeAxisView::update_control_names ()
471 {
472         if (is_audio_track()) {
473                 if (_route->active()) {
474                         controls_base_selected_name = "AudioTrackControlsBaseSelected";
475                         controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
476                 } else {
477                         controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
478                         controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
479                 }
480         } else {
481                 if (_route->active()) {
482                         controls_base_selected_name = "BusControlsBaseSelected";
483                         controls_base_unselected_name = "BusControlsBaseUnselected";
484                 } else {
485                         controls_base_selected_name = "BusControlsBaseInactiveSelected";
486                         controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
487                 }
488         }
489
490         if (get_selected()) {
491                 controls_ebox.set_name (controls_base_selected_name);
492         } else {
493                 controls_ebox.set_name (controls_base_unselected_name);
494         }
495 }
496