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;
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 update_control_names ();
113 if (is_audio_track()) {
115 /* ask for notifications of any new RegionViews */
116 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
123 AudioTimeAxisView::~AudioTimeAxisView ()
128 AudioTimeAxisView::audio_view()
130 return dynamic_cast<AudioStreamView*>(_view);
134 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
137 xml_node->add_property ("shown_editor", "yes");
139 return TimeAxisView::show_at (y, nth, parent);
143 AudioTimeAxisView::hide ()
146 xml_node->add_property ("shown_editor", "no");
148 TimeAxisView::hide ();
152 AudioTimeAxisView::set_state (const XMLNode& node)
154 const XMLProperty *prop;
156 TimeAxisView::set_state (node);
158 if ((prop = node.property ("shown_editor")) != 0) {
159 if (prop->value() == "no") {
160 _marked_for_display = false;
162 _marked_for_display = true;
165 _marked_for_display = true;
168 XMLNodeList nlist = node.children();
169 XMLNodeConstIterator niter;
173 show_gain_automation = false;
174 show_pan_automation = false;
176 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
179 if (child_node->name() == "gain") {
180 XMLProperty *prop=child_node->property ("shown");
183 if (prop->value() == "yes") {
184 show_gain_automation = true;
190 if (child_node->name() == "pan") {
191 XMLProperty *prop=child_node->property ("shown");
194 if (prop->value() == "yes") {
195 show_pan_automation = true;
204 AudioTimeAxisView::build_automation_action_menu ()
206 using namespace Menu_Helpers;
208 RouteTimeAxisView::build_automation_action_menu ();
210 MenuList& automation_items = automation_action_menu->items();
212 automation_items.push_back (SeparatorElem());
214 automation_items.push_back (CheckMenuElem (_("Fader"),
215 mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
216 gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
217 gain_automation_item->set_active(show_gain_automation);
219 automation_items.push_back (CheckMenuElem (_("Pan"),
220 mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
221 pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
222 pan_automation_item->set_active(show_pan_automation);
227 AudioTimeAxisView::append_extra_display_menu_items ()
229 using namespace Menu_Helpers;
231 MenuList& items = display_menu->items();
234 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
235 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
238 Menu *waveform_menu = manage(new Menu);
239 MenuList& waveform_items = waveform_menu->items();
240 waveform_menu->set_name ("ArdourContextMenu");
242 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
243 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
244 ignore_toggle = true;
245 waveform_item->set_active (editor.show_waveforms());
246 ignore_toggle = false;
248 waveform_items.push_back (SeparatorElem());
250 RadioMenuItem::Group group;
252 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
253 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
255 if (!Profile->get_sae()) {
256 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
257 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
262 waveform_items.push_back (SeparatorElem());
264 RadioMenuItem::Group group2;
266 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
267 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
269 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
270 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
272 // setting initial item state
273 AudioStreamView* asv = audio_view();
275 ignore_toggle = true;
276 if (asv->get_waveform_shape() == Rectified && rectified_item) {
277 rectified_item->set_active(true);
279 traditional_item->set_active(true);
282 if (asv->get_waveform_scale() == LogWaveform)
283 logscale_item->set_active(true);
284 else linearscale_item->set_active(true);
285 ignore_toggle = false;
288 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
292 AudioTimeAxisView::toggle_waveforms ()
294 AudioStreamView* asv = audio_view();
297 if (asv && waveform_item && !ignore_toggle) {
298 asv->set_show_waveforms (waveform_item->get_active());
303 AudioTimeAxisView::set_show_waveforms (bool yn)
305 AudioStreamView* asv = audio_view();
309 waveform_item->set_active (yn);
311 asv->set_show_waveforms (yn);
316 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
318 AudioStreamView* asv = audio_view();
321 asv->set_show_waveforms_recording (yn);
326 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
328 AudioStreamView* asv = audio_view();
330 if (asv && !ignore_toggle) {
331 asv->set_waveform_shape (shape);
338 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
340 AudioStreamView* asv = audio_view();
342 if (asv && !ignore_toggle) {
343 asv->set_waveform_scale (scale);
350 AudioTimeAxisView::add_gain_automation_child ()
353 AutomationLine* line;
355 gain_track = new GainAutomationTimeAxisView (_session,
361 _route->gain_automation_curve());
363 line = new AutomationGainLine ("automation gain",
366 *gain_track->canvas_display,
367 _route->gain_automation_curve());
369 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
372 gain_track->add_line (*line);
374 add_child (gain_track);
376 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
382 if ((node = gain_track->get_state_node()) != 0) {
383 if ((prop = node->property ("shown")) != 0) {
384 if (prop->value() == "yes") {
396 AudioTimeAxisView::add_pan_automation_child ()
400 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
404 add_child (pan_track);
406 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
413 if ((node = pan_track->get_state_node()) != 0) {
414 if ((prop = node->property ("shown")) != 0) {
415 if (prop->value() == "yes") {
427 AudioTimeAxisView::update_pans ()
431 pan_track->clear_lines ();
433 /* we don't draw lines for "greater than stereo" panning.
436 if (_route->n_outputs() > 2) {
440 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
442 AutomationLine* line;
444 line = new AutomationPanLine ("automation pan", _session, *pan_track,
445 *pan_track->canvas_display,
448 if (p == _route->panner().begin()) {
449 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
451 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
454 pan_track->add_line (*line);
459 AudioTimeAxisView::toggle_gain_track ()
461 bool showit = gain_automation_item->get_active();
463 if (showit != gain_track->marked_for_display()) {
465 gain_track->set_marked_for_display (true);
466 gain_track->canvas_display->show();
467 gain_track->get_state_node()->add_property ("shown", X_("yes"));
469 gain_track->set_marked_for_display (false);
471 gain_track->get_state_node()->add_property ("shown", X_("no"));
474 /* now trigger a redisplay */
477 _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
483 AudioTimeAxisView::gain_hidden ()
485 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
487 if (gain_automation_item && !_hidden) {
488 gain_automation_item->set_active (false);
491 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
495 AudioTimeAxisView::toggle_pan_track ()
497 bool showit = pan_automation_item->get_active();
499 if (showit != pan_track->marked_for_display()) {
501 pan_track->set_marked_for_display (true);
502 pan_track->canvas_display->show();
503 pan_track->get_state_node()->add_property ("shown", X_("yes"));
505 pan_track->set_marked_for_display (false);
507 pan_track->get_state_node()->add_property ("shown", X_("no"));
510 /* now trigger a redisplay */
513 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
519 AudioTimeAxisView::pan_hidden ()
521 pan_track->get_state_node()->add_property ("shown", "no");
523 if (pan_automation_item && !_hidden) {
524 pan_automation_item->set_active (false);
527 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
531 AudioTimeAxisView::show_all_automation ()
535 pan_automation_item->set_active (true);
536 gain_automation_item->set_active (true);
538 RouteTimeAxisView::show_all_automation ();
542 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
546 AudioTimeAxisView::show_existing_automation ()
550 pan_automation_item->set_active (true);
551 gain_automation_item->set_active (true);
553 RouteTimeAxisView::show_existing_automation ();
557 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
561 AudioTimeAxisView::hide_all_automation ()
565 pan_automation_item->set_active (false);
566 gain_automation_item->set_active (false);
568 RouteTimeAxisView::hide_all_automation();
571 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
575 AudioTimeAxisView::show_all_xfades ()
577 AudioStreamView* asv = audio_view();
580 asv->show_all_xfades ();
585 AudioTimeAxisView::hide_all_xfades ()
587 AudioStreamView* asv = audio_view();
590 asv->hide_all_xfades ();
595 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
597 AudioStreamView* asv = audio_view();
600 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
601 asv->hide_xfades_involving (*rv);
606 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
608 AudioStreamView* asv = audio_view();
611 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
612 asv->reveal_xfades_involving (*rv);
617 AudioTimeAxisView::route_active_changed ()
619 RouteTimeAxisView::route_active_changed ();
620 update_control_names ();
625 * Set up the names of the controls so that they are coloured
626 * correctly depending on whether this route is inactive or
631 AudioTimeAxisView::update_control_names ()
633 if (is_audio_track()) {
634 if (_route->active()) {
635 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
636 controls_base_selected_name = "AudioTrackControlsBaseSelected";
637 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
639 controls_ebox.set_name ("AudioTrackControlsBaseInactiveUnselected");
640 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
641 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
644 if (_route->active()) {
645 controls_ebox.set_name ("BusControlsBaseUnselected");
646 controls_base_selected_name = "BusControlsBaseSelected";
647 controls_base_unselected_name = "BusControlsBaseUnselected";
649 controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
650 controls_base_selected_name = "BusControlsBaseInactiveSelected";
651 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
657 AudioTimeAxisView::get_child_xml_node (const string & childname)
659 return RouteUI::get_child_xml_node (childname);