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/memento_command.h>
35 #include <gtkmm2ext/gtk_ui.h>
36 #include <gtkmm2ext/selector.h>
37 #include <gtkmm2ext/stop_signal.h>
38 #include <gtkmm2ext/bindable_button.h>
39 #include <gtkmm2ext/utils.h>
41 #include <ardour/audioplaylist.h>
42 #include <ardour/audio_diskstream.h>
43 #include <ardour/insert.h>
44 #include <ardour/location.h>
45 #include <ardour/panner.h>
46 #include <ardour/playlist.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 mute_button->set_active (false);
101 solo_button->set_active (false);
103 if (is_audio_track())
104 controls_ebox.set_name ("AudioTimeAxisViewControlsBaseUnselected");
106 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
108 /* map current state of the route */
110 redirects_changed (0);
111 reset_redirect_automation_curves ();
115 set_state (*xml_node);
117 _route->panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
121 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
122 controls_base_selected_name = "AudioTrackControlsBaseSelected";
123 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
125 /* ask for notifications of any new RegionViews */
126 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
131 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
132 controls_base_selected_name = "AudioBusControlsBaseSelected";
133 controls_base_unselected_name = "AudioBusControlsBaseUnselected";
139 AudioTimeAxisView::~AudioTimeAxisView ()
144 AudioTimeAxisView::audio_view()
146 return dynamic_cast<AudioStreamView*>(_view);
150 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
153 xml_node->add_property ("shown_editor", "yes");
155 return TimeAxisView::show_at (y, nth, parent);
159 AudioTimeAxisView::hide ()
162 xml_node->add_property ("shown_editor", "no");
164 TimeAxisView::hide ();
168 AudioTimeAxisView::set_state (const XMLNode& node)
170 const XMLProperty *prop;
172 TimeAxisView::set_state (node);
174 if ((prop = node.property ("shown_editor")) != 0) {
175 if (prop->value() == "no") {
176 _marked_for_display = false;
178 _marked_for_display = true;
181 _marked_for_display = true;
184 XMLNodeList nlist = node.children();
185 XMLNodeConstIterator niter;
189 show_gain_automation = false;
190 show_pan_automation = false;
192 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
195 if (child_node->name() == "gain") {
196 XMLProperty *prop=child_node->property ("shown");
199 if (prop->value() == "yes") {
200 show_gain_automation = true;
206 if (child_node->name() == "pan") {
207 XMLProperty *prop=child_node->property ("shown");
210 if (prop->value() == "yes") {
211 show_pan_automation = true;
220 AudioTimeAxisView::build_automation_action_menu ()
222 using namespace Menu_Helpers;
224 RouteTimeAxisView::build_automation_action_menu ();
226 MenuList& automation_items = automation_action_menu->items();
228 automation_items.push_back (SeparatorElem());
230 automation_items.push_back (CheckMenuElem (_("Fader"),
231 mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
232 gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
233 gain_automation_item->set_active(show_gain_automation);
235 automation_items.push_back (CheckMenuElem (_("Pan"),
236 mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
237 pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
238 pan_automation_item->set_active(show_pan_automation);
243 AudioTimeAxisView::append_extra_display_menu_items ()
245 using namespace Menu_Helpers;
247 MenuList& items = display_menu->items();
250 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
251 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
254 Menu *waveform_menu = manage(new Menu);
255 MenuList& waveform_items = waveform_menu->items();
256 waveform_menu->set_name ("ArdourContextMenu");
258 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
259 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
260 ignore_toggle = true;
261 waveform_item->set_active (editor.show_waveforms());
262 ignore_toggle = false;
264 waveform_items.push_back (SeparatorElem());
266 RadioMenuItem::Group group;
268 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
269 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
271 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
272 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
274 waveform_items.push_back (SeparatorElem());
276 RadioMenuItem::Group group2;
278 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
279 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
281 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
282 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
284 // setting initial item state
285 AudioStreamView* asv = audio_view();
287 ignore_toggle = true;
288 if (asv->get_waveform_shape() == Rectified)
289 rectified_item->set_active(true);
290 else traditional_item->set_active(true);
292 if (asv->get_waveform_scale() == LogWaveform)
293 logscale_item->set_active(true);
294 else linearscale_item->set_active(true);
295 ignore_toggle = false;
298 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
302 AudioTimeAxisView::toggle_waveforms ()
304 AudioStreamView* asv = audio_view();
307 if (asv && waveform_item && !ignore_toggle) {
308 asv->set_show_waveforms (waveform_item->get_active());
313 AudioTimeAxisView::set_show_waveforms (bool yn)
315 AudioStreamView* asv = audio_view();
319 waveform_item->set_active (yn);
321 asv->set_show_waveforms (yn);
326 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
328 AudioStreamView* asv = audio_view();
331 asv->set_show_waveforms_recording (yn);
336 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
338 AudioStreamView* asv = audio_view();
340 if (asv && !ignore_toggle) {
341 asv->set_waveform_shape (shape);
348 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
350 AudioStreamView* asv = audio_view();
352 if (asv && !ignore_toggle) {
353 asv->set_waveform_scale (scale);
360 AudioTimeAxisView::add_gain_automation_child ()
363 AutomationLine* line;
365 gain_track = new GainAutomationTimeAxisView (_session,
371 _route->gain_automation_curve());
373 line = new AutomationGainLine ("automation gain",
376 *gain_track->canvas_display,
377 _route->gain_automation_curve());
379 line->set_line_color (color_map[cAutomationLine]);
382 gain_track->add_line (*line);
384 add_child (gain_track);
386 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
392 if ((node = gain_track->get_state_node()) != 0) {
393 if ((prop = node->property ("shown")) != 0) {
394 if (prop->value() == "yes") {
406 AudioTimeAxisView::add_pan_automation_child ()
410 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
414 add_child (pan_track);
416 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
423 if ((node = pan_track->get_state_node()) != 0) {
424 if ((prop = node->property ("shown")) != 0) {
425 if (prop->value() == "yes") {
437 AudioTimeAxisView::update_pans ()
441 pan_track->clear_lines ();
443 /* we don't draw lines for "greater than stereo" panning.
446 if (_route->n_outputs().get(DataType::AUDIO) > 2) {
450 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
452 AutomationLine* line;
454 line = new AutomationPanLine ("automation pan", _session, *pan_track,
455 *pan_track->canvas_display,
458 if (p == _route->panner().begin()) {
459 /* first line is a nice orange */
460 line->set_line_color (color_map[cLeftPanAutomationLine]);
462 /* second line is a nice blue */
463 line->set_line_color (color_map[cRightPanAutomationLine]);
466 pan_track->add_line (*line);
471 AudioTimeAxisView::toggle_gain_track ()
474 bool showit = gain_automation_item->get_active();
476 if (showit != gain_track->marked_for_display()) {
478 gain_track->set_marked_for_display (true);
479 gain_track->canvas_display->show();
480 gain_track->get_state_node()->add_property ("shown", X_("yes"));
482 gain_track->set_marked_for_display (false);
484 gain_track->get_state_node()->add_property ("shown", X_("no"));
487 /* now trigger a redisplay */
490 _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
496 AudioTimeAxisView::gain_hidden ()
498 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
500 if (gain_automation_item && !_hidden) {
501 gain_automation_item->set_active (false);
504 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
508 AudioTimeAxisView::toggle_pan_track ()
510 bool showit = pan_automation_item->get_active();
512 if (showit != pan_track->marked_for_display()) {
514 pan_track->set_marked_for_display (true);
515 pan_track->canvas_display->show();
516 pan_track->get_state_node()->add_property ("shown", X_("yes"));
518 pan_track->set_marked_for_display (false);
520 pan_track->get_state_node()->add_property ("shown", X_("no"));
523 /* now trigger a redisplay */
526 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
532 AudioTimeAxisView::pan_hidden ()
534 pan_track->get_state_node()->add_property ("shown", "no");
536 if (pan_automation_item && !_hidden) {
537 pan_automation_item->set_active (false);
540 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
544 AudioTimeAxisView::show_all_automation ()
548 pan_automation_item->set_active (true);
549 gain_automation_item->set_active (true);
551 RouteTimeAxisView::show_all_automation ();
555 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
559 AudioTimeAxisView::show_existing_automation ()
563 pan_automation_item->set_active (true);
564 gain_automation_item->set_active (true);
566 RouteTimeAxisView::show_existing_automation ();
570 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
574 AudioTimeAxisView::hide_all_automation ()
578 pan_automation_item->set_active (false);
579 gain_automation_item->set_active (false);
581 RouteTimeAxisView::hide_all_automation();
584 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
588 AudioTimeAxisView::show_all_xfades ()
590 AudioStreamView* asv = audio_view();
593 asv->show_all_xfades ();
598 AudioTimeAxisView::hide_all_xfades ()
600 AudioStreamView* asv = audio_view();
603 asv->hide_all_xfades ();
608 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
610 AudioStreamView* asv = audio_view();
613 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
614 asv->hide_xfades_involving (*rv);
619 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
621 AudioStreamView* asv = audio_view();
624 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
625 asv->reveal_xfades_involving (*rv);
630 AudioTimeAxisView::route_active_changed ()
632 RouteTimeAxisView::route_active_changed ();
634 if (is_audio_track()) {
635 if (_route->active()) {
636 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
637 controls_base_selected_name = "AudioTrackControlsBaseSelected";
638 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
640 controls_ebox.set_name ("AudioTrackControlsBaseInactiveUnselected");
641 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
642 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
645 if (_route->active()) {
646 controls_ebox.set_name ("BusControlsBaseUnselected");
647 controls_base_selected_name = "BusControlsBaseSelected";
648 controls_base_unselected_name = "BusControlsBaseUnselected";
650 controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
651 controls_base_selected_name = "BusControlsBaseInactiveSelected";
652 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
658 AudioTimeAxisView::get_child_xml_node (const string & childname)
660 return RouteUI::get_child_xml_node (childname);