2 Copyright (C) 2000-2006 Paul Davis
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.
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.
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.
29 #include <sigc++/bind.h>
31 #include <pbd/error.h>
32 #include <pbd/stl_delete.h>
33 #include <pbd/memento_command.h>
35 #include <gtkmm2ext/gtk_ui.h>
36 #include <gtkmm2ext/selector.h>
37 #include <gtkmm2ext/stop_signal.h>
38 #include <gtkmm2ext/bindable_button.h>
39 #include <gtkmm2ext/utils.h>
41 #include <ardour/audioplaylist.h>
42 #include <ardour/audio_diskstream.h>
43 #include <ardour/insert.h>
44 #include <ardour/location.h>
45 #include <ardour/panner.h>
46 #include <ardour/playlist.h>
47 #include <ardour/session.h>
48 #include <ardour/session_playlist.h>
49 #include <ardour/utils.h>
51 #include "ardour_ui.h"
52 #include "audio_time_axis.h"
53 #include "automation_gain_line.h"
54 #include "automation_pan_line.h"
55 #include "canvas_impl.h"
56 #include "crossfade_view.h"
58 #include "gain_automation_time_axis.h"
60 #include "pan_automation_time_axis.h"
61 #include "playlist_selector.h"
63 #include "public_editor.h"
64 #include "audio_region_view.h"
65 #include "simplerect.h"
66 #include "audio_streamview.h"
69 #include <ardour/audio_track.h>
73 using namespace ARDOUR;
76 using namespace Editing;
79 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
81 , RouteTimeAxisView(ed, sess, rt, canvas)
83 // Make sure things are sane...
84 assert(!is_track() || is_audio_track());
86 subplugin_menu.set_name ("ArdourContextMenu");
90 pan_automation_item = 0;
91 gain_automation_item = 0;
93 _view = new AudioStreamView (*this);
95 add_gain_automation_child ();
96 add_pan_automation_child ();
98 ignore_toggle = false;
100 if (is_audio_track())
101 controls_ebox.set_name ("AudioTimeAxisViewControlsBaseUnselected");
103 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
107 set_state (*xml_node);
109 _route->panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
111 if (is_audio_track()) {
113 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
114 controls_base_selected_name = "AudioTrackControlsBaseSelected";
115 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
117 /* ask for notifications of any new RegionViews */
118 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
123 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
124 controls_base_selected_name = "AudioBusControlsBaseSelected";
125 controls_base_unselected_name = "AudioBusControlsBaseUnselected";
131 AudioTimeAxisView::~AudioTimeAxisView ()
136 AudioTimeAxisView::audio_view()
138 return dynamic_cast<AudioStreamView*>(_view);
142 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
145 xml_node->add_property ("shown_editor", "yes");
147 return TimeAxisView::show_at (y, nth, parent);
151 AudioTimeAxisView::hide ()
154 xml_node->add_property ("shown_editor", "no");
156 TimeAxisView::hide ();
160 AudioTimeAxisView::set_state (const XMLNode& node)
162 const XMLProperty *prop;
164 TimeAxisView::set_state (node);
166 if ((prop = node.property ("shown_editor")) != 0) {
167 if (prop->value() == "no") {
168 _marked_for_display = false;
170 _marked_for_display = true;
173 _marked_for_display = true;
176 XMLNodeList nlist = node.children();
177 XMLNodeConstIterator niter;
181 show_gain_automation = false;
182 show_pan_automation = false;
184 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
187 if (child_node->name() == "gain") {
188 XMLProperty *prop=child_node->property ("shown");
191 if (prop->value() == "yes") {
192 show_gain_automation = true;
198 if (child_node->name() == "pan") {
199 XMLProperty *prop=child_node->property ("shown");
202 if (prop->value() == "yes") {
203 show_pan_automation = true;
212 AudioTimeAxisView::build_automation_action_menu ()
214 using namespace Menu_Helpers;
216 RouteTimeAxisView::build_automation_action_menu ();
218 MenuList& automation_items = automation_action_menu->items();
220 automation_items.push_back (SeparatorElem());
222 automation_items.push_back (CheckMenuElem (_("Fader"),
223 mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
224 gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
225 gain_automation_item->set_active(show_gain_automation);
227 automation_items.push_back (CheckMenuElem (_("Pan"),
228 mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
229 pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
230 pan_automation_item->set_active(show_pan_automation);
235 AudioTimeAxisView::append_extra_display_menu_items ()
237 using namespace Menu_Helpers;
239 MenuList& items = display_menu->items();
242 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
243 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
246 Menu *waveform_menu = manage(new Menu);
247 MenuList& waveform_items = waveform_menu->items();
248 waveform_menu->set_name ("ArdourContextMenu");
250 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
251 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
252 ignore_toggle = true;
253 waveform_item->set_active (editor.show_waveforms());
254 ignore_toggle = false;
256 waveform_items.push_back (SeparatorElem());
258 RadioMenuItem::Group group;
260 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
261 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
263 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
264 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
266 waveform_items.push_back (SeparatorElem());
268 RadioMenuItem::Group group2;
270 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
271 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
273 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
274 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
276 // setting initial item state
277 AudioStreamView* asv = audio_view();
279 ignore_toggle = true;
280 if (asv->get_waveform_shape() == Rectified)
281 rectified_item->set_active(true);
282 else traditional_item->set_active(true);
284 if (asv->get_waveform_scale() == LogWaveform)
285 logscale_item->set_active(true);
286 else linearscale_item->set_active(true);
287 ignore_toggle = false;
290 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
294 AudioTimeAxisView::toggle_waveforms ()
296 AudioStreamView* asv = audio_view();
299 if (asv && waveform_item && !ignore_toggle) {
300 asv->set_show_waveforms (waveform_item->get_active());
305 AudioTimeAxisView::set_show_waveforms (bool yn)
307 AudioStreamView* asv = audio_view();
311 waveform_item->set_active (yn);
313 asv->set_show_waveforms (yn);
318 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
320 AudioStreamView* asv = audio_view();
323 asv->set_show_waveforms_recording (yn);
328 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
330 AudioStreamView* asv = audio_view();
332 if (asv && !ignore_toggle) {
333 asv->set_waveform_shape (shape);
340 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
342 AudioStreamView* asv = audio_view();
344 if (asv && !ignore_toggle) {
345 asv->set_waveform_scale (scale);
352 AudioTimeAxisView::add_gain_automation_child ()
355 AutomationLine* line;
357 gain_track = new GainAutomationTimeAxisView (_session,
363 _route->gain_automation_curve());
365 line = new AutomationGainLine ("automation gain",
368 *gain_track->canvas_display,
369 _route->gain_automation_curve());
371 line->set_line_color (color_map[cAutomationLine]);
374 gain_track->add_line (*line);
376 add_child (gain_track);
378 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
384 if ((node = gain_track->get_state_node()) != 0) {
385 if ((prop = node->property ("shown")) != 0) {
386 if (prop->value() == "yes") {
398 AudioTimeAxisView::add_pan_automation_child ()
402 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
406 add_child (pan_track);
408 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
415 if ((node = pan_track->get_state_node()) != 0) {
416 if ((prop = node->property ("shown")) != 0) {
417 if (prop->value() == "yes") {
429 AudioTimeAxisView::update_pans ()
433 pan_track->clear_lines ();
435 /* we don't draw lines for "greater than stereo" panning.
438 if (_route->n_outputs() > 2) {
442 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
444 AutomationLine* line;
446 line = new AutomationPanLine ("automation pan", _session, *pan_track,
447 *pan_track->canvas_display,
450 if (p == _route->panner().begin()) {
451 /* first line is a nice orange */
452 line->set_line_color (color_map[cLeftPanAutomationLine]);
454 /* second line is a nice blue */
455 line->set_line_color (color_map[cRightPanAutomationLine]);
458 pan_track->add_line (*line);
463 AudioTimeAxisView::toggle_gain_track ()
466 bool showit = gain_automation_item->get_active();
468 if (showit != gain_track->marked_for_display()) {
470 gain_track->set_marked_for_display (true);
471 gain_track->canvas_display->show();
472 gain_track->get_state_node()->add_property ("shown", X_("yes"));
474 gain_track->set_marked_for_display (false);
476 gain_track->get_state_node()->add_property ("shown", X_("no"));
479 /* now trigger a redisplay */
482 _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
488 AudioTimeAxisView::gain_hidden ()
490 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
492 if (gain_automation_item && !_hidden) {
493 gain_automation_item->set_active (false);
496 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
500 AudioTimeAxisView::toggle_pan_track ()
502 bool showit = pan_automation_item->get_active();
504 if (showit != pan_track->marked_for_display()) {
506 pan_track->set_marked_for_display (true);
507 pan_track->canvas_display->show();
508 pan_track->get_state_node()->add_property ("shown", X_("yes"));
510 pan_track->set_marked_for_display (false);
512 pan_track->get_state_node()->add_property ("shown", X_("no"));
515 /* now trigger a redisplay */
518 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
524 AudioTimeAxisView::pan_hidden ()
526 pan_track->get_state_node()->add_property ("shown", "no");
528 if (pan_automation_item && !_hidden) {
529 pan_automation_item->set_active (false);
532 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
536 AudioTimeAxisView::show_all_automation ()
540 pan_automation_item->set_active (true);
541 gain_automation_item->set_active (true);
543 RouteTimeAxisView::show_all_automation ();
547 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
551 AudioTimeAxisView::show_existing_automation ()
555 pan_automation_item->set_active (true);
556 gain_automation_item->set_active (true);
558 RouteTimeAxisView::show_existing_automation ();
562 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
566 AudioTimeAxisView::hide_all_automation ()
570 pan_automation_item->set_active (false);
571 gain_automation_item->set_active (false);
573 RouteTimeAxisView::hide_all_automation();
576 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
580 AudioTimeAxisView::show_all_xfades ()
582 AudioStreamView* asv = audio_view();
585 asv->show_all_xfades ();
590 AudioTimeAxisView::hide_all_xfades ()
592 AudioStreamView* asv = audio_view();
595 asv->hide_all_xfades ();
600 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
602 AudioStreamView* asv = audio_view();
605 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
606 asv->hide_xfades_involving (*rv);
611 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
613 AudioStreamView* asv = audio_view();
616 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
617 asv->reveal_xfades_involving (*rv);
622 AudioTimeAxisView::route_active_changed ()
624 RouteTimeAxisView::route_active_changed ();
626 if (is_audio_track()) {
627 if (_route->active()) {
628 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
629 controls_base_selected_name = "AudioTrackControlsBaseSelected";
630 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
632 controls_ebox.set_name ("AudioTrackControlsBaseInactiveUnselected");
633 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
634 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
637 if (_route->active()) {
638 controls_ebox.set_name ("BusControlsBaseUnselected");
639 controls_base_selected_name = "BusControlsBaseSelected";
640 controls_base_unselected_name = "BusControlsBaseUnselected";
642 controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
643 controls_base_selected_name = "BusControlsBaseInactiveSelected";
644 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
650 AudioTimeAxisView::get_child_xml_node (const string & childname)
652 return RouteUI::get_child_xml_node (childname);