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 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));
122 AudioTimeAxisView::~AudioTimeAxisView ()
127 AudioTimeAxisView::audio_view()
129 return dynamic_cast<AudioStreamView*>(_view);
133 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
136 xml_node->add_property ("shown_editor", "yes");
138 return TimeAxisView::show_at (y, nth, parent);
142 AudioTimeAxisView::hide ()
145 xml_node->add_property ("shown_editor", "no");
147 TimeAxisView::hide ();
151 AudioTimeAxisView::set_state (const XMLNode& node)
153 const XMLProperty *prop;
155 TimeAxisView::set_state (node);
157 if ((prop = node.property ("shown_editor")) != 0) {
158 if (prop->value() == "no") {
159 _marked_for_display = false;
161 _marked_for_display = true;
164 _marked_for_display = true;
167 XMLNodeList nlist = node.children();
168 XMLNodeConstIterator niter;
172 show_gain_automation = false;
173 show_pan_automation = false;
175 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
178 if (child_node->name() == "gain") {
179 XMLProperty *prop=child_node->property ("shown");
182 if (prop->value() == "yes") {
183 show_gain_automation = true;
189 if (child_node->name() == "pan") {
190 XMLProperty *prop=child_node->property ("shown");
193 if (prop->value() == "yes") {
194 show_pan_automation = true;
203 AudioTimeAxisView::build_automation_action_menu ()
205 using namespace Menu_Helpers;
207 RouteTimeAxisView::build_automation_action_menu ();
209 MenuList& automation_items = automation_action_menu->items();
211 automation_items.push_back (SeparatorElem());
213 automation_items.push_back (CheckMenuElem (_("Fader"),
214 mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
215 gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
216 gain_automation_item->set_active(show_gain_automation);
218 automation_items.push_back (CheckMenuElem (_("Pan"),
219 mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
220 pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
221 pan_automation_item->set_active(show_pan_automation);
226 AudioTimeAxisView::append_extra_display_menu_items ()
228 using namespace Menu_Helpers;
230 MenuList& items = display_menu->items();
233 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
234 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
237 Menu *waveform_menu = manage(new Menu);
238 MenuList& waveform_items = waveform_menu->items();
239 waveform_menu->set_name ("ArdourContextMenu");
241 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
242 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
243 ignore_toggle = true;
244 waveform_item->set_active (editor.show_waveforms());
245 ignore_toggle = false;
247 waveform_items.push_back (SeparatorElem());
249 RadioMenuItem::Group group;
251 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
252 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
254 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
255 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
257 waveform_items.push_back (SeparatorElem());
259 RadioMenuItem::Group group2;
261 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
262 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
264 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
265 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
267 // setting initial item state
268 AudioStreamView* asv = audio_view();
270 ignore_toggle = true;
271 if (asv->get_waveform_shape() == Rectified)
272 rectified_item->set_active(true);
273 else traditional_item->set_active(true);
275 if (asv->get_waveform_scale() == LogWaveform)
276 logscale_item->set_active(true);
277 else linearscale_item->set_active(true);
278 ignore_toggle = false;
281 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
285 AudioTimeAxisView::toggle_waveforms ()
287 AudioStreamView* asv = audio_view();
290 if (asv && waveform_item && !ignore_toggle) {
291 asv->set_show_waveforms (waveform_item->get_active());
296 AudioTimeAxisView::set_show_waveforms (bool yn)
298 AudioStreamView* asv = audio_view();
302 waveform_item->set_active (yn);
304 asv->set_show_waveforms (yn);
309 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
311 AudioStreamView* asv = audio_view();
314 asv->set_show_waveforms_recording (yn);
319 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
321 AudioStreamView* asv = audio_view();
323 if (asv && !ignore_toggle) {
324 asv->set_waveform_shape (shape);
331 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
333 AudioStreamView* asv = audio_view();
335 if (asv && !ignore_toggle) {
336 asv->set_waveform_scale (scale);
343 AudioTimeAxisView::add_gain_automation_child ()
346 AutomationLine* line;
348 gain_track = new GainAutomationTimeAxisView (_session,
354 _route->gain_automation_curve());
356 line = new AutomationGainLine ("automation gain",
359 *gain_track->canvas_display,
360 _route->gain_automation_curve());
362 line->set_line_color (color_map[cAutomationLine]);
365 gain_track->add_line (*line);
367 add_child (gain_track);
369 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
375 if ((node = gain_track->get_state_node()) != 0) {
376 if ((prop = node->property ("shown")) != 0) {
377 if (prop->value() == "yes") {
389 AudioTimeAxisView::add_pan_automation_child ()
393 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("pan"));
397 add_child (pan_track);
399 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
406 if ((node = pan_track->get_state_node()) != 0) {
407 if ((prop = node->property ("shown")) != 0) {
408 if (prop->value() == "yes") {
420 AudioTimeAxisView::update_pans ()
424 pan_track->clear_lines ();
426 /* we don't draw lines for "greater than stereo" panning.
429 if (_route->n_outputs() > 2) {
433 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
435 AutomationLine* line;
437 line = new AutomationPanLine ("automation pan", _session, *pan_track,
438 *pan_track->canvas_display,
441 if (p == _route->panner().begin()) {
442 /* first line is a nice orange */
443 line->set_line_color (color_map[cLeftPanAutomationLine]);
445 /* second line is a nice blue */
446 line->set_line_color (color_map[cRightPanAutomationLine]);
449 pan_track->add_line (*line);
454 AudioTimeAxisView::toggle_gain_track ()
457 bool showit = gain_automation_item->get_active();
459 if (showit != gain_track->marked_for_display()) {
461 gain_track->set_marked_for_display (true);
462 gain_track->canvas_display->show();
463 gain_track->get_state_node()->add_property ("shown", X_("yes"));
465 gain_track->set_marked_for_display (false);
467 gain_track->get_state_node()->add_property ("shown", X_("no"));
470 /* now trigger a redisplay */
473 _route->gui_changed (X_("track_height"), (void *) 0); /* EMIT_SIGNAL */
479 AudioTimeAxisView::gain_hidden ()
481 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
483 if (gain_automation_item && !_hidden) {
484 gain_automation_item->set_active (false);
487 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
491 AudioTimeAxisView::toggle_pan_track ()
493 bool showit = pan_automation_item->get_active();
495 if (showit != pan_track->marked_for_display()) {
497 pan_track->set_marked_for_display (true);
498 pan_track->canvas_display->show();
499 pan_track->get_state_node()->add_property ("shown", X_("yes"));
501 pan_track->set_marked_for_display (false);
503 pan_track->get_state_node()->add_property ("shown", X_("no"));
506 /* now trigger a redisplay */
509 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
515 AudioTimeAxisView::pan_hidden ()
517 pan_track->get_state_node()->add_property ("shown", "no");
519 if (pan_automation_item && !_hidden) {
520 pan_automation_item->set_active (false);
523 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
527 AudioTimeAxisView::show_all_automation ()
531 pan_automation_item->set_active (true);
532 gain_automation_item->set_active (true);
534 RouteTimeAxisView::show_all_automation ();
538 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
542 AudioTimeAxisView::show_existing_automation ()
546 pan_automation_item->set_active (true);
547 gain_automation_item->set_active (true);
549 RouteTimeAxisView::show_existing_automation ();
553 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
557 AudioTimeAxisView::hide_all_automation ()
561 pan_automation_item->set_active (false);
562 gain_automation_item->set_active (false);
564 RouteTimeAxisView::hide_all_automation();
567 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
571 AudioTimeAxisView::show_all_xfades ()
573 AudioStreamView* asv = audio_view();
576 asv->show_all_xfades ();
581 AudioTimeAxisView::hide_all_xfades ()
583 AudioStreamView* asv = audio_view();
586 asv->hide_all_xfades ();
591 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
593 AudioStreamView* asv = audio_view();
596 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
597 asv->hide_xfades_involving (*rv);
602 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
604 AudioStreamView* asv = audio_view();
607 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
608 asv->reveal_xfades_involving (*rv);
613 AudioTimeAxisView::route_active_changed ()
615 RouteTimeAxisView::route_active_changed ();
616 update_control_names ();
621 * Set up the names of the controls so that they are coloured
622 * correctly depending on whether this route is inactive or
627 AudioTimeAxisView::update_control_names ()
629 if (is_audio_track()) {
630 if (_route->active()) {
631 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
632 controls_base_selected_name = "AudioTrackControlsBaseSelected";
633 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
635 controls_ebox.set_name ("AudioTrackControlsBaseInactiveUnselected");
636 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
637 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
640 if (_route->active()) {
641 controls_ebox.set_name ("BusControlsBaseUnselected");
642 controls_base_selected_name = "BusControlsBaseSelected";
643 controls_base_unselected_name = "BusControlsBaseUnselected";
645 controls_ebox.set_name ("BusControlsBaseInactiveUnselected");
646 controls_base_selected_name = "BusControlsBaseInactiveSelected";
647 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
653 AudioTimeAxisView::get_child_xml_node (const string & childname)
655 return RouteUI::get_child_xml_node (childname);