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;
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 if (is_audio_track()) {
112 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
113 controls_base_selected_name = "AudioTrackControlsBaseSelected";
114 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
116 /* ask for notifications of any new RegionViews */
117 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
122 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
123 controls_base_selected_name = "AudioBusControlsBaseSelected";
124 controls_base_unselected_name = "AudioBusControlsBaseUnselected";
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));
293 AudioTimeAxisView::toggle_waveforms ()
295 AudioStreamView* asv = audio_view();
298 if (asv && waveform_item && !ignore_toggle) {
299 asv->set_show_waveforms (waveform_item->get_active());
304 AudioTimeAxisView::set_show_waveforms (bool yn)
306 AudioStreamView* asv = audio_view();
310 waveform_item->set_active (yn);
312 asv->set_show_waveforms (yn);
317 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
319 AudioStreamView* asv = audio_view();
322 asv->set_show_waveforms_recording (yn);
327 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
329 AudioStreamView* asv = audio_view();
331 if (asv && !ignore_toggle) {
332 asv->set_waveform_shape (shape);
339 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
341 AudioStreamView* asv = audio_view();
343 if (asv && !ignore_toggle) {
344 asv->set_waveform_scale (scale);
351 AudioTimeAxisView::add_gain_automation_child ()
354 AutomationLine* line;
356 gain_track = new GainAutomationTimeAxisView (_session,
362 _route->gain_automation_curve());
364 line = new AutomationGainLine ("automation gain",
367 *gain_track->canvas_display,
368 _route->gain_automation_curve());
370 line->set_line_color (color_map[cAutomationLine]);
373 gain_track->add_line (*line);
375 add_child (gain_track);
377 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
383 if ((node = gain_track->get_state_node()) != 0) {
384 if ((prop = node->property ("shown")) != 0) {
385 if (prop->value() == "yes") {
397 AudioTimeAxisView::add_pan_automation_child ()
401 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
405 add_child (pan_track);
407 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
414 if ((node = pan_track->get_state_node()) != 0) {
415 if ((prop = node->property ("shown")) != 0) {
416 if (prop->value() == "yes") {
428 AudioTimeAxisView::update_pans ()
432 pan_track->clear_lines ();
434 /* we don't draw lines for "greater than stereo" panning.
437 if (_route->n_outputs() > 2) {
441 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
443 AutomationLine* line;
445 line = new AutomationPanLine ("automation pan", _session, *pan_track,
446 *pan_track->canvas_display,
449 if (p == _route->panner().begin()) {
450 /* first line is a nice orange */
451 line->set_line_color (color_map[cLeftPanAutomationLine]);
453 /* second line is a nice blue */
454 line->set_line_color (color_map[cRightPanAutomationLine]);
457 pan_track->add_line (*line);
462 AudioTimeAxisView::toggle_gain_track ()
465 bool showit = gain_automation_item->get_active();
467 if (showit != gain_track->marked_for_display()) {
469 gain_track->set_marked_for_display (true);
470 gain_track->canvas_display->show();
471 gain_track->get_state_node()->add_property ("shown", X_("yes"));
473 gain_track->set_marked_for_display (false);
475 gain_track->get_state_node()->add_property ("shown", X_("no"));
478 /* now trigger a redisplay */
481 _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
487 AudioTimeAxisView::gain_hidden ()
489 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
491 if (gain_automation_item && !_hidden) {
492 gain_automation_item->set_active (false);
495 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
499 AudioTimeAxisView::toggle_pan_track ()
501 bool showit = pan_automation_item->get_active();
503 if (showit != pan_track->marked_for_display()) {
505 pan_track->set_marked_for_display (true);
506 pan_track->canvas_display->show();
507 pan_track->get_state_node()->add_property ("shown", X_("yes"));
509 pan_track->set_marked_for_display (false);
511 pan_track->get_state_node()->add_property ("shown", X_("no"));
514 /* now trigger a redisplay */
517 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
523 AudioTimeAxisView::pan_hidden ()
525 pan_track->get_state_node()->add_property ("shown", "no");
527 if (pan_automation_item && !_hidden) {
528 pan_automation_item->set_active (false);
531 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
535 AudioTimeAxisView::show_all_automation ()
539 pan_automation_item->set_active (true);
540 gain_automation_item->set_active (true);
542 RouteTimeAxisView::show_all_automation ();
546 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
550 AudioTimeAxisView::show_existing_automation ()
554 pan_automation_item->set_active (true);
555 gain_automation_item->set_active (true);
557 RouteTimeAxisView::show_existing_automation ();
561 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
565 AudioTimeAxisView::hide_all_automation ()
569 pan_automation_item->set_active (false);
570 gain_automation_item->set_active (false);
572 RouteTimeAxisView::hide_all_automation();
575 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
579 AudioTimeAxisView::show_all_xfades ()
581 AudioStreamView* asv = audio_view();
584 asv->show_all_xfades ();
589 AudioTimeAxisView::hide_all_xfades ()
591 AudioStreamView* asv = audio_view();
594 asv->hide_all_xfades ();
599 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
601 AudioStreamView* asv = audio_view();
604 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
605 asv->hide_xfades_involving (*rv);
610 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
612 AudioStreamView* asv = audio_view();
615 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
616 asv->reveal_xfades_involving (*rv);
621 AudioTimeAxisView::route_active_changed ()
623 RouteTimeAxisView::route_active_changed ();
625 if (is_audio_track()) {
626 if (_route->active()) {
627 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
628 controls_base_selected_name = "AudioTrackControlsBaseSelected";
629 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
631 controls_ebox.set_name ("AudioTrackControlsBaseInactiveUnselected");
632 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
633 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
636 if (_route->active()) {
637 controls_ebox.set_name ("BusControlsBaseUnselected");
638 controls_base_selected_name = "BusControlsBaseSelected";
639 controls_base_unselected_name = "BusControlsBaseUnselected";
641 controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
642 controls_base_selected_name = "BusControlsBaseInactiveSelected";
643 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
649 AudioTimeAxisView::get_child_xml_node (const string & childname)
651 return RouteUI::get_child_xml_node (childname);