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.
28 #include <sigc++/bind.h>
30 #include <pbd/error.h>
31 #include <pbd/stl_delete.h>
32 #include <pbd/memento_command.h>
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>
40 #include <ardour/audioplaylist.h>
41 #include <ardour/audio_diskstream.h>
42 #include <ardour/insert.h>
43 #include <ardour/location.h>
44 #include <ardour/panner.h>
45 #include <ardour/playlist.h>
46 #include <ardour/session.h>
47 #include <ardour/session_playlist.h>
48 #include <ardour/utils.h>
50 #include "ardour_ui.h"
51 #include "audio_time_axis.h"
52 #include "automation_gain_line.h"
53 #include "automation_pan_line.h"
54 #include "canvas_impl.h"
55 #include "crossfade_view.h"
57 #include "gain_automation_time_axis.h"
59 #include "pan_automation_time_axis.h"
60 #include "playlist_selector.h"
62 #include "public_editor.h"
63 #include "audio_region_view.h"
64 #include "simplerect.h"
65 #include "audio_streamview.h"
68 #include <ardour/audio_track.h>
72 using namespace ARDOUR;
75 using namespace Editing;
78 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
80 , RouteTimeAxisView(ed, sess, rt, canvas)
82 // Make sure things are sane...
83 assert(!is_track() || is_audio_track());
85 subplugin_menu.set_name ("ArdourContextMenu");
89 pan_automation_item = 0;
90 gain_automation_item = 0;
92 _view = new AudioStreamView (*this);
94 add_gain_automation_child ();
95 add_pan_automation_child ();
97 ignore_toggle = false;
99 mute_button->set_active (false);
100 solo_button->set_active (false);
102 if (is_audio_track())
103 controls_ebox.set_name ("AudioTimeAxisViewControlsBaseUnselected");
105 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
107 /* map current state of the route */
109 redirects_changed (0);
110 reset_redirect_automation_curves ();
114 set_state (*xml_node);
116 _route->panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
118 update_control_names ();
120 if (is_audio_track()) {
122 /* ask for notifications of any new RegionViews */
123 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
130 AudioTimeAxisView::~AudioTimeAxisView ()
135 AudioTimeAxisView::audio_view()
137 return dynamic_cast<AudioStreamView*>(_view);
141 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
144 xml_node->add_property ("shown_editor", "yes");
146 return TimeAxisView::show_at (y, nth, parent);
150 AudioTimeAxisView::hide ()
153 xml_node->add_property ("shown_editor", "no");
155 TimeAxisView::hide ();
159 AudioTimeAxisView::set_state (const XMLNode& node)
161 const XMLProperty *prop;
163 TimeAxisView::set_state (node);
165 if ((prop = node.property ("shown_editor")) != 0) {
166 if (prop->value() == "no") {
167 _marked_for_display = false;
169 _marked_for_display = true;
172 _marked_for_display = true;
175 XMLNodeList nlist = node.children();
176 XMLNodeConstIterator niter;
180 show_gain_automation = false;
181 show_pan_automation = false;
183 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
186 if (child_node->name() == "gain") {
187 XMLProperty *prop=child_node->property ("shown");
190 if (prop->value() == "yes") {
191 show_gain_automation = true;
197 if (child_node->name() == "pan") {
198 XMLProperty *prop=child_node->property ("shown");
201 if (prop->value() == "yes") {
202 show_pan_automation = true;
211 AudioTimeAxisView::build_automation_action_menu ()
213 using namespace Menu_Helpers;
215 RouteTimeAxisView::build_automation_action_menu ();
217 MenuList& automation_items = automation_action_menu->items();
219 automation_items.push_back (SeparatorElem());
221 automation_items.push_back (CheckMenuElem (_("Fader"),
222 mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
223 gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
224 gain_automation_item->set_active(show_gain_automation);
226 automation_items.push_back (CheckMenuElem (_("Pan"),
227 mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
228 pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
229 pan_automation_item->set_active(show_pan_automation);
234 AudioTimeAxisView::append_extra_display_menu_items ()
236 using namespace Menu_Helpers;
238 MenuList& items = display_menu->items();
241 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
242 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
245 Menu *waveform_menu = manage(new Menu);
246 MenuList& waveform_items = waveform_menu->items();
247 waveform_menu->set_name ("ArdourContextMenu");
249 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
250 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
251 ignore_toggle = true;
252 waveform_item->set_active (editor.show_waveforms());
253 ignore_toggle = false;
255 waveform_items.push_back (SeparatorElem());
257 RadioMenuItem::Group group;
259 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
260 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
262 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
263 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
265 waveform_items.push_back (SeparatorElem());
267 RadioMenuItem::Group group2;
269 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
270 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
272 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
273 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
275 // setting initial item state
276 AudioStreamView* asv = audio_view();
278 ignore_toggle = true;
279 if (asv->get_waveform_shape() == Rectified)
280 rectified_item->set_active(true);
281 else traditional_item->set_active(true);
283 if (asv->get_waveform_scale() == LogWaveform)
284 logscale_item->set_active(true);
285 else linearscale_item->set_active(true);
286 ignore_toggle = false;
289 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
292 Menu *layers_menu = manage(new Menu);
293 MenuList &layers_items = layers_menu->items();
294 layers_menu->set_name("ArdourContextMenu");
296 RadioMenuItem::Group layers_group;
298 layers_items.push_back(RadioMenuElem (layers_group, _("Overlaid"), bind (mem_fun (*this, &AudioTimeAxisView::set_layer_display), Overlaid)));
299 layers_items.push_back(RadioMenuElem (layers_group, _("Stacked"), bind (mem_fun (*this, &AudioTimeAxisView::set_layer_display), Stacked)));
301 items.push_back (MenuElem (_("Layers"), *layers_menu));
305 AudioTimeAxisView::toggle_waveforms ()
307 AudioStreamView* asv = audio_view();
310 if (asv && waveform_item && !ignore_toggle) {
311 asv->set_show_waveforms (waveform_item->get_active());
316 AudioTimeAxisView::set_show_waveforms (bool yn)
318 AudioStreamView* asv = audio_view();
322 waveform_item->set_active (yn);
324 asv->set_show_waveforms (yn);
329 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
331 AudioStreamView* asv = audio_view();
334 asv->set_show_waveforms_recording (yn);
339 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
341 AudioStreamView* asv = audio_view();
343 if (asv && !ignore_toggle) {
344 asv->set_waveform_shape (shape);
351 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
353 AudioStreamView* asv = audio_view();
355 if (asv && !ignore_toggle) {
356 asv->set_waveform_scale (scale);
363 AudioTimeAxisView::add_gain_automation_child ()
366 AutomationLine* line;
368 gain_track = new GainAutomationTimeAxisView (_session,
374 _route->gain_automation_curve());
376 line = new AutomationGainLine ("automation gain",
379 *gain_track->canvas_display,
380 _route->gain_automation_curve());
382 line->set_line_color (color_map[cAutomationLine]);
385 gain_track->add_line (*line);
387 add_child (gain_track);
389 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
395 if ((node = gain_track->get_state_node()) != 0) {
396 if ((prop = node->property ("shown")) != 0) {
397 if (prop->value() == "yes") {
409 AudioTimeAxisView::add_pan_automation_child ()
413 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
417 add_child (pan_track);
419 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
426 if ((node = pan_track->get_state_node()) != 0) {
427 if ((prop = node->property ("shown")) != 0) {
428 if (prop->value() == "yes") {
440 AudioTimeAxisView::update_pans ()
444 pan_track->clear_lines ();
446 /* we don't draw lines for "greater than stereo" panning.
449 if (_route->n_outputs().n_audio() > 2) {
453 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
455 AutomationLine* line;
457 line = new AutomationPanLine ("automation pan", _session, *pan_track,
458 *pan_track->canvas_display,
461 if (p == _route->panner().begin()) {
462 /* first line is a nice orange */
463 line->set_line_color (color_map[cLeftPanAutomationLine]);
465 /* second line is a nice blue */
466 line->set_line_color (color_map[cRightPanAutomationLine]);
469 pan_track->add_line (*line);
474 AudioTimeAxisView::toggle_gain_track ()
477 bool showit = gain_automation_item->get_active();
479 if (showit != gain_track->marked_for_display()) {
481 gain_track->set_marked_for_display (true);
482 gain_track->canvas_display->show();
483 gain_track->get_state_node()->add_property ("shown", X_("yes"));
485 gain_track->set_marked_for_display (false);
487 gain_track->get_state_node()->add_property ("shown", X_("no"));
490 /* now trigger a redisplay */
493 _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
499 AudioTimeAxisView::gain_hidden ()
501 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
503 if (gain_automation_item && !_hidden) {
504 gain_automation_item->set_active (false);
507 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
511 AudioTimeAxisView::toggle_pan_track ()
513 bool showit = pan_automation_item->get_active();
515 if (showit != pan_track->marked_for_display()) {
517 pan_track->set_marked_for_display (true);
518 pan_track->canvas_display->show();
519 pan_track->get_state_node()->add_property ("shown", X_("yes"));
521 pan_track->set_marked_for_display (false);
523 pan_track->get_state_node()->add_property ("shown", X_("no"));
526 /* now trigger a redisplay */
529 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
535 AudioTimeAxisView::pan_hidden ()
537 pan_track->get_state_node()->add_property ("shown", "no");
539 if (pan_automation_item && !_hidden) {
540 pan_automation_item->set_active (false);
543 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
547 AudioTimeAxisView::show_all_automation ()
551 pan_automation_item->set_active (true);
552 gain_automation_item->set_active (true);
554 RouteTimeAxisView::show_all_automation ();
558 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
562 AudioTimeAxisView::show_existing_automation ()
566 pan_automation_item->set_active (true);
567 gain_automation_item->set_active (true);
569 RouteTimeAxisView::show_existing_automation ();
573 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
577 AudioTimeAxisView::hide_all_automation ()
581 pan_automation_item->set_active (false);
582 gain_automation_item->set_active (false);
584 RouteTimeAxisView::hide_all_automation();
587 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
591 AudioTimeAxisView::show_all_xfades ()
593 AudioStreamView* asv = audio_view();
596 asv->show_all_xfades ();
601 AudioTimeAxisView::hide_all_xfades ()
603 AudioStreamView* asv = audio_view();
606 asv->hide_all_xfades ();
611 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
613 AudioStreamView* asv = audio_view();
616 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
617 asv->hide_xfades_involving (*rv);
622 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
624 AudioStreamView* asv = audio_view();
627 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
628 asv->reveal_xfades_involving (*rv);
633 AudioTimeAxisView::route_active_changed ()
635 RouteTimeAxisView::route_active_changed ();
636 update_control_names ();
641 * Set up the names of the controls so that they are coloured
642 * correctly depending on whether this route is inactive or
647 AudioTimeAxisView::update_control_names ()
649 if (is_audio_track()) {
650 if (_route->active()) {
651 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
652 controls_base_selected_name = "AudioTrackControlsBaseSelected";
653 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
655 controls_ebox.set_name ("AudioTrackControlsBaseInactiveUnselected");
656 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
657 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
660 if (_route->active()) {
661 controls_ebox.set_name ("BusControlsBaseUnselected");
662 controls_base_selected_name = "BusControlsBaseSelected";
663 controls_base_unselected_name = "BusControlsBaseUnselected";
665 controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
666 controls_base_selected_name = "BusControlsBaseInactiveSelected";
667 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
673 AudioTimeAxisView::get_child_xml_node (const string & childname)
675 return RouteUI::get_child_xml_node (childname);
679 AudioTimeAxisView::set_layer_display (LayerDisplay d)
681 AudioStreamView* asv = audio_view ();
683 asv->set_layer_display (d);