The cscope and scons front-end makefile.
[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     $Id$
19 */
20
21 #include <cstdlib>
22 #include <cmath>
23 #include <cassert>
24
25 #include <algorithm>
26 #include <string>
27 #include <vector>
28
29 #include <sigc++/bind.h>
30
31 #include <pbd/error.h>
32 #include <pbd/stl_delete.h>
33 #include <pbd/whitespace.h>
34 #include <pbd/memento_command.h>
35
36 #include <gtkmm2ext/gtk_ui.h>
37 #include <gtkmm2ext/selector.h>
38 #include <gtkmm2ext/stop_signal.h>
39 #include <gtkmm2ext/bindable_button.h>
40 #include <gtkmm2ext/utils.h>
41
42 #include <ardour/audioplaylist.h>
43 #include <ardour/audio_diskstream.h>
44 #include <ardour/insert.h>
45 #include <ardour/location.h>
46 #include <ardour/panner.h>
47 #include <ardour/playlist.h>
48 #include <ardour/session.h>
49 #include <ardour/session_playlist.h>
50 #include <ardour/utils.h>
51
52 #include "ardour_ui.h"
53 #include "audio_time_axis.h"
54 #include "automation_gain_line.h"
55 #include "automation_pan_line.h"
56 #include "canvas_impl.h"
57 #include "crossfade_view.h"
58 #include "enums.h"
59 #include "gain_automation_time_axis.h"
60 #include "keyboard.h"
61 #include "pan_automation_time_axis.h"
62 #include "playlist_selector.h"
63 #include "plugin_selector.h"
64 #include "plugin_ui.h"
65 #include "prompter.h"
66 #include "public_editor.h"
67 #include "audio_region_view.h"
68 #include "simplerect.h"
69 #include "audio_streamview.h"
70 #include "utils.h"
71
72 #include <ardour/audio_track.h>
73
74 #include "i18n.h"
75
76 using namespace ARDOUR;
77 using namespace PBD;
78 using namespace Gtk;
79 using namespace Editing;
80
81
82 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
83         : AxisView(sess)
84         , RouteTimeAxisView(ed, sess, rt, canvas)
85 {
86         // Make sure things are sane...
87         assert(!is_track() || is_audio_track());
88
89         subplugin_menu.set_name ("ArdourContextMenu");
90         gain_track = 0;
91         pan_track = 0;
92         waveform_item = 0;
93         pan_automation_item = 0;
94         gain_automation_item = 0;
95
96         _view = new AudioStreamView (*this);
97
98         add_gain_automation_child ();
99         add_pan_automation_child ();
100
101         ignore_toggle = false;
102
103         mute_button->set_active (false);
104         solo_button->set_active (false);
105         
106         if (is_audio_track())
107                 controls_ebox.set_name ("AudioTimeAxisViewControlsBaseUnselected");
108         else // bus
109                 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
110
111         /* map current state of the route */
112
113         redirects_changed (0);
114         reset_redirect_automation_curves ();
115
116         ensure_xml_node ();
117
118         set_state (*xml_node);
119         
120         _route->panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
121
122         if (is_audio_track()) {
123
124                 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
125                 controls_base_selected_name = "AudioTrackControlsBaseSelected";
126                 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
127
128                 /* ask for notifications of any new RegionViews */
129                 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
130                 _view->attach ();
131
132         } else { /* bus */
133
134                 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
135                 controls_base_selected_name = "AudioBusControlsBaseSelected";
136                 controls_base_unselected_name = "AudioBusControlsBaseUnselected";
137         }
138 }
139
140 AudioTimeAxisView::~AudioTimeAxisView ()
141 {
142 }
143
144 AudioStreamView*
145 AudioTimeAxisView::audio_view()
146 {
147         return dynamic_cast<AudioStreamView*>(_view);
148 }
149
150 guint32
151 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
152 {
153         ensure_xml_node ();
154         xml_node->add_property ("shown_editor", "yes");
155                 
156         return TimeAxisView::show_at (y, nth, parent);
157 }
158
159 void
160 AudioTimeAxisView::hide ()
161 {
162         ensure_xml_node ();
163         xml_node->add_property ("shown_editor", "no");
164
165         TimeAxisView::hide ();
166 }
167
168 void
169 AudioTimeAxisView::set_state (const XMLNode& node)
170 {
171         const XMLProperty *prop;
172         
173         TimeAxisView::set_state (node);
174         
175         if ((prop = node.property ("shown_editor")) != 0) {
176                 if (prop->value() == "no") {
177                         _marked_for_display = false;
178                 } else {
179                         _marked_for_display = true;
180                 }
181         } else {
182                 _marked_for_display = true;
183         }
184         
185         XMLNodeList nlist = node.children();
186         XMLNodeConstIterator niter;
187         XMLNode *child_node;
188         
189         
190         show_gain_automation = false;
191         show_pan_automation  = false;
192         
193         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
194                 child_node = *niter;
195
196                 if (child_node->name() == "gain") {
197                         XMLProperty *prop=child_node->property ("shown");
198                         
199                         if (prop != 0) {
200                                 if (prop->value() == "yes") {
201                                         show_gain_automation = true;
202                                 }
203                         }
204                         continue;
205                 }
206                 
207                 if (child_node->name() == "pan") {
208                         XMLProperty *prop=child_node->property ("shown");
209                         
210                         if (prop != 0) {
211                                 if (prop->value() == "yes") {
212                                         show_pan_automation = true;
213                                 }                       
214                         }
215                         continue;
216                 }
217         }
218 }
219
220 void
221 AudioTimeAxisView::build_automation_action_menu ()
222 {
223         using namespace Menu_Helpers;
224
225         RouteTimeAxisView::build_automation_action_menu ();
226
227         MenuList& automation_items = automation_action_menu->items();
228         
229         automation_items.push_back (SeparatorElem());
230
231         automation_items.push_back (CheckMenuElem (_("Fader"), 
232                                                    mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
233         gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
234         gain_automation_item->set_active(show_gain_automation);
235
236         automation_items.push_back (CheckMenuElem (_("Pan"),
237                                                    mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
238         pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
239         pan_automation_item->set_active(show_pan_automation);
240         
241 }
242
243 void
244 AudioTimeAxisView::append_extra_display_menu_items ()
245 {
246         using namespace Menu_Helpers;
247
248         MenuList& items = display_menu->items();
249
250         // crossfade stuff
251         items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
252         items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
253
254         // waveform menu
255         Menu *waveform_menu = manage(new Menu);
256         MenuList& waveform_items = waveform_menu->items();
257         waveform_menu->set_name ("ArdourContextMenu");
258         
259         waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
260         waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
261         ignore_toggle = true;
262         waveform_item->set_active (editor.show_waveforms());
263         ignore_toggle = false;
264
265         RadioMenuItem::Group group;
266
267         waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
268         traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
269
270         waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
271         rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
272
273         items.push_back (MenuElem (_("Waveform"), *waveform_menu));
274 }
275
276 void
277 AudioTimeAxisView::toggle_waveforms ()
278 {
279         AudioStreamView* asv = audio_view();
280         assert(asv);
281
282         if (asv && waveform_item && !ignore_toggle) {
283                 asv->set_show_waveforms (waveform_item->get_active());
284         }
285 }
286
287 void
288 AudioTimeAxisView::set_show_waveforms (bool yn)
289 {
290         AudioStreamView* asv = audio_view();
291         assert(asv);
292
293         if (waveform_item) {
294                 waveform_item->set_active (yn);
295         } else {
296                 asv->set_show_waveforms (yn);
297         }
298 }
299
300 void
301 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
302 {
303         AudioStreamView* asv = audio_view();
304
305         if (asv) {
306                 asv->set_show_waveforms_recording (yn);
307         }
308 }
309
310 void
311 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
312 {
313         AudioStreamView* asv = audio_view();
314
315         if (asv) {
316                 asv->set_waveform_shape (shape);
317         }
318
319         map_frozen ();
320 }       
321
322 void
323 AudioTimeAxisView::add_gain_automation_child ()
324 {
325         XMLProperty* prop;
326         AutomationLine* line;
327
328         gain_track = new GainAutomationTimeAxisView (_session,
329                                                      _route,
330                                                      editor,
331                                                      *this,
332                                                      parent_canvas,
333                                                      _("gain"),
334                                                      _route->gain_automation_curve());
335         
336         line = new AutomationGainLine ("automation gain",
337                                        _session,
338                                        *gain_track,
339                                        *gain_track->canvas_display,
340                                        _route->gain_automation_curve());
341
342         line->set_line_color (color_map[cAutomationLine]);
343         
344
345         gain_track->add_line (*line);
346
347         add_child (gain_track);
348
349         gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
350
351         bool hideit = true;
352         
353         XMLNode* node;
354
355         if ((node = gain_track->get_state_node()) != 0) {
356                 if  ((prop = node->property ("shown")) != 0) {
357                         if (prop->value() == "yes") {
358                                 hideit = false;
359                         }
360                 } 
361         }
362
363         if (hideit) {
364                 gain_track->hide ();
365         }
366 }
367
368 void
369 AudioTimeAxisView::add_pan_automation_child ()
370 {
371         XMLProperty* prop;
372
373         pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
374
375         update_pans ();
376         
377         add_child (pan_track);
378
379         pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
380
381         ensure_xml_node ();
382         bool hideit = true;
383         
384         XMLNode* node;
385
386         if ((node = pan_track->get_state_node()) != 0) {
387                 if ((prop = node->property ("shown")) != 0) {
388                         if (prop->value() == "yes") {
389                                 hideit = false;
390                         }
391                 } 
392         }
393
394         if (hideit) {
395                 pan_track->hide ();
396         }
397 }
398
399 void
400 AudioTimeAxisView::update_pans ()
401 {
402         Panner::iterator p;
403         
404         pan_track->clear_lines ();
405         
406         /* we don't draw lines for "greater than stereo" panning.
407          */
408
409         if (_route->n_outputs() > 2) {
410                 return;
411         }
412
413         for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
414
415                 AutomationLine* line;
416
417                 line = new AutomationPanLine ("automation pan", _session, *pan_track,
418                                               *pan_track->canvas_display, 
419                                               (*p)->automation());
420
421                 if (p == _route->panner().begin()) {
422                         /* first line is a nice orange */
423                         line->set_line_color (color_map[cLeftPanAutomationLine]);
424                 } else {
425                         /* second line is a nice blue */
426                         line->set_line_color (color_map[cRightPanAutomationLine]);
427                 }
428
429                 pan_track->add_line (*line);
430         }
431 }
432                 
433 void
434 AudioTimeAxisView::toggle_gain_track ()
435 {
436
437         bool showit = gain_automation_item->get_active();
438
439         if (showit != gain_track->marked_for_display()) {
440                 if (showit) {
441                         gain_track->set_marked_for_display (true);
442                         gain_track->canvas_display->show();
443                         gain_track->get_state_node()->add_property ("shown", X_("yes"));
444                 } else {
445                         gain_track->set_marked_for_display (false);
446                         gain_track->hide ();
447                         gain_track->get_state_node()->add_property ("shown", X_("no"));
448                 }
449
450                 /* now trigger a redisplay */
451                 
452                 if (!no_redraw) {
453                          _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
454                 }
455         }
456 }
457
458 void
459 AudioTimeAxisView::gain_hidden ()
460 {
461         gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
462
463         if (gain_automation_item && !_hidden) {
464                 gain_automation_item->set_active (false);
465         }
466
467          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
468 }
469
470 void
471 AudioTimeAxisView::toggle_pan_track ()
472 {
473         bool showit = pan_automation_item->get_active();
474
475         if (showit != pan_track->marked_for_display()) {
476                 if (showit) {
477                         pan_track->set_marked_for_display (true);
478                         pan_track->canvas_display->show();
479                         pan_track->get_state_node()->add_property ("shown", X_("yes"));
480                 } else {
481                         pan_track->set_marked_for_display (false);
482                         pan_track->hide ();
483                         pan_track->get_state_node()->add_property ("shown", X_("no"));
484                 }
485
486                 /* now trigger a redisplay */
487                 
488                 if (!no_redraw) {
489                          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
490                 }
491         }
492 }
493
494 void
495 AudioTimeAxisView::pan_hidden ()
496 {
497         pan_track->get_state_node()->add_property ("shown", "no");
498
499         if (pan_automation_item && !_hidden) {
500                 pan_automation_item->set_active (false);
501         }
502
503          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
504 }
505
506 void
507 AudioTimeAxisView::show_all_automation ()
508 {
509         no_redraw = true;
510
511         pan_automation_item->set_active (true);
512         gain_automation_item->set_active (true);
513         
514         RouteTimeAxisView::show_all_automation ();
515
516         no_redraw = false;
517
518          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
519 }
520
521 void
522 AudioTimeAxisView::show_existing_automation ()
523 {
524         no_redraw = true;
525
526         pan_automation_item->set_active (true);
527         gain_automation_item->set_active (true);
528
529         RouteTimeAxisView::show_existing_automation ();
530
531         no_redraw = false;
532
533          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
534 }
535
536 void
537 AudioTimeAxisView::hide_all_automation ()
538 {
539         no_redraw = true;
540
541         pan_automation_item->set_active (false);
542         gain_automation_item->set_active (false);
543
544         RouteTimeAxisView::hide_all_automation();
545
546         no_redraw = false;
547          _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
548 }
549
550 void
551 AudioTimeAxisView::show_all_xfades ()
552 {
553         AudioStreamView* asv = audio_view();
554
555         if (asv) {
556                 asv->show_all_xfades ();
557         }
558 }
559
560 void
561 AudioTimeAxisView::hide_all_xfades ()
562 {
563         AudioStreamView* asv = audio_view();
564         
565         if (asv) {
566                 asv->hide_all_xfades ();
567         }
568 }
569
570 void
571 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
572 {
573         AudioStreamView* asv = audio_view();
574         AudioRegionView* rv;
575
576         if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
577                 asv->hide_xfades_involving (*rv);
578         }
579 }
580
581 void
582 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
583 {
584         AudioStreamView* asv = audio_view();
585         AudioRegionView* rv;
586
587         if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
588                 asv->reveal_xfades_involving (*rv);
589         }
590 }
591
592 void
593 AudioTimeAxisView::route_active_changed ()
594 {
595         RouteTimeAxisView::route_active_changed ();
596
597         if (is_audio_track()) {
598                 if (_route->active()) {
599                         controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
600                         controls_base_selected_name = "AudioTrackControlsBaseSelected";
601                         controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
602                 } else {
603                         controls_ebox.set_name ("AudioTrackControlsBaseInactiveUnselected");
604                         controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
605                         controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
606                 }
607         } else {
608                 if (_route->active()) {
609                         controls_ebox.set_name ("BusControlsBaseUnselected");
610                         controls_base_selected_name = "BusControlsBaseSelected";
611                         controls_base_unselected_name = "BusControlsBaseUnselected";
612                 } else {
613                         controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
614                         controls_base_selected_name = "BusControlsBaseInactiveSelected";
615                         controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
616                 }
617         }
618 }
619
620 XMLNode* 
621 AudioTimeAxisView::get_child_xml_node (const string & childname)
622 {
623         return RouteUI::get_child_xml_node (childname);
624 }
625