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/profile.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;
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;
100 controls_ebox.set_name ("AudioTimeAxisViewControlsBaseUnselected");
102 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
106 set_state (*xml_node);
108 _route->panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
110 update_control_names ();
112 if (is_audio_track()) {
114 /* ask for notifications of any new RegionViews */
115 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
117 if (!editor.have_idled()) {
118 /* first idle will do the rest */
128 AudioTimeAxisView::~AudioTimeAxisView ()
133 AudioTimeAxisView::first_idle ()
140 AudioTimeAxisView::audio_view()
142 return dynamic_cast<AudioStreamView*>(_view);
146 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
149 xml_node->add_property ("shown_editor", "yes");
151 return TimeAxisView::show_at (y, nth, parent);
155 AudioTimeAxisView::hide ()
158 xml_node->add_property ("shown_editor", "no");
160 TimeAxisView::hide ();
164 AudioTimeAxisView::set_state (const XMLNode& node)
166 const XMLProperty *prop;
168 TimeAxisView::set_state (node);
170 if ((prop = node.property ("shown_editor")) != 0) {
171 if (prop->value() == "no") {
172 _marked_for_display = false;
174 _marked_for_display = true;
177 _marked_for_display = true;
180 XMLNodeList nlist = node.children();
181 XMLNodeConstIterator niter;
185 show_gain_automation = false;
186 show_pan_automation = false;
188 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
191 if (child_node->name() == "gain") {
192 XMLProperty *prop=child_node->property ("shown");
195 if (prop->value() == "yes") {
196 show_gain_automation = true;
202 if (child_node->name() == "pan") {
203 XMLProperty *prop=child_node->property ("shown");
206 if (prop->value() == "yes") {
207 show_pan_automation = true;
216 AudioTimeAxisView::build_automation_action_menu ()
218 using namespace Menu_Helpers;
220 RouteTimeAxisView::build_automation_action_menu ();
222 MenuList& automation_items = automation_action_menu->items();
224 automation_items.push_back (SeparatorElem());
226 automation_items.push_back (CheckMenuElem (_("Fader"),
227 mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
228 gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
229 gain_automation_item->set_active(show_gain_automation);
231 automation_items.push_back (CheckMenuElem (_("Pan"),
232 mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
233 pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
234 pan_automation_item->set_active(show_pan_automation);
239 AudioTimeAxisView::append_extra_display_menu_items ()
241 using namespace Menu_Helpers;
243 MenuList& items = display_menu->items();
246 if (!Profile->get_sae()) {
247 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
248 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
252 Menu *waveform_menu = manage(new Menu);
253 MenuList& waveform_items = waveform_menu->items();
254 waveform_menu->set_name ("ArdourContextMenu");
256 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
257 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
258 ignore_toggle = true;
259 waveform_item->set_active (editor.show_waveforms());
260 ignore_toggle = false;
262 waveform_items.push_back (SeparatorElem());
264 RadioMenuItem::Group group;
266 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
267 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
269 if (!Profile->get_sae()) {
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());
276 waveform_items.push_back (SeparatorElem());
278 RadioMenuItem::Group group2;
280 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
281 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
283 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
284 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
286 // setting initial item state
287 AudioStreamView* asv = audio_view();
289 ignore_toggle = true;
290 if (asv->get_waveform_shape() == Rectified && rectified_item) {
291 rectified_item->set_active(true);
293 traditional_item->set_active(true);
296 if (asv->get_waveform_scale() == LogWaveform)
297 logscale_item->set_active(true);
298 else linearscale_item->set_active(true);
299 ignore_toggle = false;
302 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
306 AudioTimeAxisView::toggle_waveforms ()
308 AudioStreamView* asv = audio_view();
311 if (asv && waveform_item && !ignore_toggle) {
312 asv->set_show_waveforms (waveform_item->get_active());
317 AudioTimeAxisView::set_show_waveforms (bool yn)
319 AudioStreamView* asv = audio_view();
323 waveform_item->set_active (yn);
325 asv->set_show_waveforms (yn);
330 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
332 AudioStreamView* asv = audio_view();
335 asv->set_show_waveforms_recording (yn);
340 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
342 AudioStreamView* asv = audio_view();
344 if (asv && !ignore_toggle) {
345 asv->set_waveform_shape (shape);
352 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
354 AudioStreamView* asv = audio_view();
356 if (asv && !ignore_toggle) {
357 asv->set_waveform_scale (scale);
364 AudioTimeAxisView::add_gain_automation_child ()
367 AutomationLine* line;
369 gain_track = new GainAutomationTimeAxisView (_session,
375 _route->gain_automation_curve());
377 line = new AutomationGainLine ("automation gain",
380 *gain_track->canvas_display,
381 _route->gain_automation_curve());
383 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
386 gain_track->add_line (*line);
388 add_child (gain_track);
390 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
396 if ((node = gain_track->get_state_node()) != 0) {
397 if ((prop = node->property ("shown")) != 0) {
398 if (prop->value() == "yes") {
410 AudioTimeAxisView::add_pan_automation_child ()
414 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
418 add_child (pan_track);
420 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
427 if ((node = pan_track->get_state_node()) != 0) {
428 if ((prop = node->property ("shown")) != 0) {
429 if (prop->value() == "yes") {
441 AudioTimeAxisView::update_pans ()
445 pan_track->clear_lines ();
447 /* we don't draw lines for "greater than stereo" panning.
450 if (_route->n_outputs() > 2) {
454 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
456 AutomationLine* line;
458 line = new AutomationPanLine ("automation pan", _session, *pan_track,
459 *pan_track->canvas_display,
462 if (p == _route->panner().begin()) {
463 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
465 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
468 pan_track->add_line (*line);
473 AudioTimeAxisView::toggle_gain_track ()
475 bool showit = gain_automation_item->get_active();
477 if (showit != gain_track->marked_for_display()) {
479 gain_track->set_marked_for_display (true);
480 gain_track->canvas_display->show();
481 gain_track->get_state_node()->add_property ("shown", X_("yes"));
483 gain_track->set_marked_for_display (false);
485 gain_track->get_state_node()->add_property ("shown", X_("no"));
488 /* now trigger a redisplay */
491 _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
497 AudioTimeAxisView::gain_hidden ()
499 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
501 if (gain_automation_item && !_hidden) {
502 gain_automation_item->set_active (false);
505 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
509 AudioTimeAxisView::toggle_pan_track ()
511 bool showit = pan_automation_item->get_active();
513 if (showit != pan_track->marked_for_display()) {
515 pan_track->set_marked_for_display (true);
516 pan_track->canvas_display->show();
517 pan_track->get_state_node()->add_property ("shown", X_("yes"));
519 pan_track->set_marked_for_display (false);
521 pan_track->get_state_node()->add_property ("shown", X_("no"));
524 /* now trigger a redisplay */
527 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
533 AudioTimeAxisView::pan_hidden ()
535 pan_track->get_state_node()->add_property ("shown", "no");
537 if (pan_automation_item && !_hidden) {
538 pan_automation_item->set_active (false);
541 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
545 AudioTimeAxisView::show_all_automation ()
549 pan_automation_item->set_active (true);
550 gain_automation_item->set_active (true);
552 RouteTimeAxisView::show_all_automation ();
556 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
560 AudioTimeAxisView::show_existing_automation ()
564 pan_automation_item->set_active (true);
565 gain_automation_item->set_active (true);
567 RouteTimeAxisView::show_existing_automation ();
571 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
575 AudioTimeAxisView::hide_all_automation ()
579 pan_automation_item->set_active (false);
580 gain_automation_item->set_active (false);
582 RouteTimeAxisView::hide_all_automation();
585 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
589 AudioTimeAxisView::show_all_xfades ()
591 AudioStreamView* asv = audio_view();
594 asv->show_all_xfades ();
599 AudioTimeAxisView::hide_all_xfades ()
601 AudioStreamView* asv = audio_view();
604 asv->hide_all_xfades ();
609 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
611 AudioStreamView* asv = audio_view();
614 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
615 asv->hide_xfades_involving (*rv);
620 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
622 AudioStreamView* asv = audio_view();
625 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
626 asv->reveal_xfades_involving (*rv);
631 AudioTimeAxisView::route_active_changed ()
633 RouteTimeAxisView::route_active_changed ();
634 update_control_names ();
639 * Set up the names of the controls so that they are coloured
640 * correctly depending on whether this route is inactive or
645 AudioTimeAxisView::update_control_names ()
647 if (is_audio_track()) {
648 if (_route->active()) {
649 controls_base_selected_name = "AudioTrackControlsBaseSelected";
650 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
652 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
653 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
656 if (_route->active()) {
657 controls_base_selected_name = "BusControlsBaseSelected";
658 controls_base_unselected_name = "BusControlsBaseUnselected";
660 controls_base_selected_name = "BusControlsBaseInactiveSelected";
661 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
665 if (get_selected()) {
666 controls_ebox.set_name (controls_base_selected_name);
668 controls_ebox.set_name (controls_base_unselected_name);
673 AudioTimeAxisView::get_child_xml_node (const string & childname)
675 return RouteUI::get_child_xml_node (childname);