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/whitespace.h>
34 #include <pbd/memento_command.h>
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>
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>
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"
59 #include "gain_automation_time_axis.h"
61 #include "pan_automation_time_axis.h"
62 #include "playlist_selector.h"
64 #include "public_editor.h"
65 #include "audio_region_view.h"
66 #include "simplerect.h"
67 #include "audio_streamview.h"
70 #include <ardour/audio_track.h>
74 using namespace ARDOUR;
77 using namespace Editing;
80 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
82 , RouteTimeAxisView(ed, sess, rt, canvas)
84 // Make sure things are sane...
85 assert(!is_track() || is_audio_track());
87 subplugin_menu.set_name ("ArdourContextMenu");
91 pan_automation_item = 0;
92 gain_automation_item = 0;
94 _view = new AudioStreamView (*this);
96 add_gain_automation_child ();
97 add_pan_automation_child ();
99 ignore_toggle = false;
101 mute_button->set_active (false);
102 solo_button->set_active (false);
104 if (is_audio_track())
105 controls_ebox.set_name ("AudioTimeAxisViewControlsBaseUnselected");
107 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
109 /* map current state of the route */
111 redirects_changed (0);
112 reset_redirect_automation_curves ();
116 set_state (*xml_node);
118 _route->panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
122 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
123 controls_base_selected_name = "AudioTrackControlsBaseSelected";
124 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
126 /* ask for notifications of any new RegionViews */
127 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
132 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
133 controls_base_selected_name = "AudioBusControlsBaseSelected";
134 controls_base_unselected_name = "AudioBusControlsBaseUnselected";
138 AudioTimeAxisView::~AudioTimeAxisView ()
143 AudioTimeAxisView::audio_view()
145 return dynamic_cast<AudioStreamView*>(_view);
149 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
152 xml_node->add_property ("shown_editor", "yes");
154 return TimeAxisView::show_at (y, nth, parent);
158 AudioTimeAxisView::hide ()
161 xml_node->add_property ("shown_editor", "no");
163 TimeAxisView::hide ();
167 AudioTimeAxisView::set_state (const XMLNode& node)
169 const XMLProperty *prop;
171 TimeAxisView::set_state (node);
173 if ((prop = node.property ("shown_editor")) != 0) {
174 if (prop->value() == "no") {
175 _marked_for_display = false;
177 _marked_for_display = true;
180 _marked_for_display = true;
183 XMLNodeList nlist = node.children();
184 XMLNodeConstIterator niter;
188 show_gain_automation = false;
189 show_pan_automation = false;
191 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
194 if (child_node->name() == "gain") {
195 XMLProperty *prop=child_node->property ("shown");
198 if (prop->value() == "yes") {
199 show_gain_automation = true;
205 if (child_node->name() == "pan") {
206 XMLProperty *prop=child_node->property ("shown");
209 if (prop->value() == "yes") {
210 show_pan_automation = true;
219 AudioTimeAxisView::build_automation_action_menu ()
221 using namespace Menu_Helpers;
223 RouteTimeAxisView::build_automation_action_menu ();
225 MenuList& automation_items = automation_action_menu->items();
227 automation_items.push_back (SeparatorElem());
229 automation_items.push_back (CheckMenuElem (_("Fader"),
230 mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
231 gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
232 gain_automation_item->set_active(show_gain_automation);
234 automation_items.push_back (CheckMenuElem (_("Pan"),
235 mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
236 pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
237 pan_automation_item->set_active(show_pan_automation);
242 AudioTimeAxisView::append_extra_display_menu_items ()
244 using namespace Menu_Helpers;
246 MenuList& items = display_menu->items();
249 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
250 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
253 Menu *waveform_menu = manage(new Menu);
254 MenuList& waveform_items = waveform_menu->items();
255 waveform_menu->set_name ("ArdourContextMenu");
257 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
258 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
259 ignore_toggle = true;
260 waveform_item->set_active (editor.show_waveforms());
261 ignore_toggle = false;
263 RadioMenuItem::Group group;
265 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
266 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
268 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
269 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
271 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
275 AudioTimeAxisView::toggle_waveforms ()
277 AudioStreamView* asv = audio_view();
280 if (asv && waveform_item && !ignore_toggle) {
281 asv->set_show_waveforms (waveform_item->get_active());
286 AudioTimeAxisView::set_show_waveforms (bool yn)
288 AudioStreamView* asv = audio_view();
292 waveform_item->set_active (yn);
294 asv->set_show_waveforms (yn);
299 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
301 AudioStreamView* asv = audio_view();
304 asv->set_show_waveforms_recording (yn);
309 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
311 AudioStreamView* asv = audio_view();
314 asv->set_waveform_shape (shape);
321 AudioTimeAxisView::add_gain_automation_child ()
324 AutomationLine* line;
326 gain_track = new GainAutomationTimeAxisView (_session,
332 _route->gain_automation_curve());
334 line = new AutomationGainLine ("automation gain",
337 *gain_track->canvas_display,
338 _route->gain_automation_curve());
340 line->set_line_color (color_map[cAutomationLine]);
343 gain_track->add_line (*line);
345 add_child (gain_track);
347 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
353 if ((node = gain_track->get_state_node()) != 0) {
354 if ((prop = node->property ("shown")) != 0) {
355 if (prop->value() == "yes") {
367 AudioTimeAxisView::add_pan_automation_child ()
371 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
375 add_child (pan_track);
377 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
384 if ((node = pan_track->get_state_node()) != 0) {
385 if ((prop = node->property ("shown")) != 0) {
386 if (prop->value() == "yes") {
398 AudioTimeAxisView::update_pans ()
402 pan_track->clear_lines ();
404 /* we don't draw lines for "greater than stereo" panning.
407 if (_route->n_outputs().get(DataType::AUDIO) > 2) {
411 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
413 AutomationLine* line;
415 line = new AutomationPanLine ("automation pan", _session, *pan_track,
416 *pan_track->canvas_display,
419 if (p == _route->panner().begin()) {
420 /* first line is a nice orange */
421 line->set_line_color (color_map[cLeftPanAutomationLine]);
423 /* second line is a nice blue */
424 line->set_line_color (color_map[cRightPanAutomationLine]);
427 pan_track->add_line (*line);
432 AudioTimeAxisView::toggle_gain_track ()
435 bool showit = gain_automation_item->get_active();
437 if (showit != gain_track->marked_for_display()) {
439 gain_track->set_marked_for_display (true);
440 gain_track->canvas_display->show();
441 gain_track->get_state_node()->add_property ("shown", X_("yes"));
443 gain_track->set_marked_for_display (false);
445 gain_track->get_state_node()->add_property ("shown", X_("no"));
448 /* now trigger a redisplay */
451 _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
457 AudioTimeAxisView::gain_hidden ()
459 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
461 if (gain_automation_item && !_hidden) {
462 gain_automation_item->set_active (false);
465 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
469 AudioTimeAxisView::toggle_pan_track ()
471 bool showit = pan_automation_item->get_active();
473 if (showit != pan_track->marked_for_display()) {
475 pan_track->set_marked_for_display (true);
476 pan_track->canvas_display->show();
477 pan_track->get_state_node()->add_property ("shown", X_("yes"));
479 pan_track->set_marked_for_display (false);
481 pan_track->get_state_node()->add_property ("shown", X_("no"));
484 /* now trigger a redisplay */
487 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
493 AudioTimeAxisView::pan_hidden ()
495 pan_track->get_state_node()->add_property ("shown", "no");
497 if (pan_automation_item && !_hidden) {
498 pan_automation_item->set_active (false);
501 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
505 AudioTimeAxisView::show_all_automation ()
509 pan_automation_item->set_active (true);
510 gain_automation_item->set_active (true);
512 RouteTimeAxisView::show_all_automation ();
516 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
520 AudioTimeAxisView::show_existing_automation ()
524 pan_automation_item->set_active (true);
525 gain_automation_item->set_active (true);
527 RouteTimeAxisView::show_existing_automation ();
531 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
535 AudioTimeAxisView::hide_all_automation ()
539 pan_automation_item->set_active (false);
540 gain_automation_item->set_active (false);
542 RouteTimeAxisView::hide_all_automation();
545 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
549 AudioTimeAxisView::show_all_xfades ()
551 AudioStreamView* asv = audio_view();
554 asv->show_all_xfades ();
559 AudioTimeAxisView::hide_all_xfades ()
561 AudioStreamView* asv = audio_view();
564 asv->hide_all_xfades ();
569 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
571 AudioStreamView* asv = audio_view();
574 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
575 asv->hide_xfades_involving (*rv);
580 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
582 AudioStreamView* asv = audio_view();
585 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
586 asv->reveal_xfades_involving (*rv);
591 AudioTimeAxisView::route_active_changed ()
593 RouteTimeAxisView::route_active_changed ();
595 if (is_audio_track()) {
596 if (_route->active()) {
597 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
598 controls_base_selected_name = "AudioTrackControlsBaseSelected";
599 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
601 controls_ebox.set_name ("AudioTrackControlsBaseInactiveUnselected");
602 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
603 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
606 if (_route->active()) {
607 controls_ebox.set_name ("BusControlsBaseUnselected");
608 controls_base_selected_name = "BusControlsBaseSelected";
609 controls_base_unselected_name = "BusControlsBaseUnselected";
611 controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
612 controls_base_selected_name = "BusControlsBaseInactiveSelected";
613 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
619 AudioTimeAxisView::get_child_xml_node (const string & childname)
621 return RouteUI::get_child_xml_node (childname);