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/processor.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_line.h"
54 #include "canvas_impl.h"
55 #include "crossfade_view.h"
57 #include "automation_time_axis.h"
59 #include "playlist_selector.h"
61 #include "public_editor.h"
62 #include "audio_region_view.h"
63 #include "simplerect.h"
64 #include "audio_streamview.h"
67 #include <ardour/audio_track.h>
71 using namespace ARDOUR;
74 using namespace Editing;
76 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
78 , RouteTimeAxisView(ed, sess, rt, canvas)
80 // Make sure things are sane...
81 assert(!is_track() || is_audio_track());
83 subplugin_menu.set_name ("ArdourContextMenu");
86 _view = new AudioStreamView (*this);
88 ignore_toggle = false;
90 mute_button->set_active (false);
91 solo_button->set_active (false);
93 if (is_audio_track()) {
94 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
96 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
101 set_state (*xml_node);
103 /* if set_state above didn't create a gain automation child, we need to make one */
104 if (automation_track (GainAutomation) == 0) {
105 create_automation_child (GainAutomation, false);
108 _route->panner().Changed.connect (bind (mem_fun(*this, &AudioTimeAxisView::ensure_pan_views), false));
110 /* map current state of the route */
112 processors_changed ();
113 reset_processor_automation_curves ();
114 ensure_pan_views (false);
115 update_control_names ();
117 if (is_audio_track()) {
119 /* ask for notifications of any new RegionViews */
120 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
122 if (!editor.have_idled()) {
123 /* first idle will do what we need */
133 AudioTimeAxisView::~AudioTimeAxisView ()
138 AudioTimeAxisView::first_idle ()
145 AudioTimeAxisView::audio_view()
147 return dynamic_cast<AudioStreamView*>(_view);
151 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
154 xml_node->add_property ("shown-editor", "yes");
156 return TimeAxisView::show_at (y, nth, parent);
160 AudioTimeAxisView::hide ()
163 xml_node->add_property ("shown-editor", "no");
165 TimeAxisView::hide ();
170 AudioTimeAxisView::append_extra_display_menu_items ()
172 using namespace Menu_Helpers;
174 MenuList& items = display_menu->items();
177 if (!Profile->get_sae()) {
178 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
179 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
183 Menu *waveform_menu = manage(new Menu);
184 MenuList& waveform_items = waveform_menu->items();
185 waveform_menu->set_name ("ArdourContextMenu");
187 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
188 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
189 ignore_toggle = true;
190 waveform_item->set_active (editor.show_waveforms());
191 ignore_toggle = false;
193 waveform_items.push_back (SeparatorElem());
195 RadioMenuItem::Group group;
197 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
198 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
200 if (!Profile->get_sae()) {
201 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
202 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
207 waveform_items.push_back (SeparatorElem());
209 RadioMenuItem::Group group2;
211 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
212 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
214 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
215 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
217 // setting initial item state
218 AudioStreamView* asv = audio_view();
220 ignore_toggle = true;
221 if (asv->get_waveform_shape() == Rectified && rectified_item) {
222 rectified_item->set_active(true);
224 traditional_item->set_active(true);
227 if (asv->get_waveform_scale() == LogWaveform)
228 logscale_item->set_active(true);
229 else linearscale_item->set_active(true);
230 ignore_toggle = false;
233 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
238 AudioTimeAxisView::build_mode_menu()
240 using namespace Menu_Helpers;
242 Menu* mode_menu = manage (new Menu);
243 MenuList& items = mode_menu->items();
244 mode_menu->set_name ("ArdourContextMenu");
246 RadioMenuItem::Group mode_group;
247 items.push_back (RadioMenuElem (mode_group, _("Normal"),
248 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Normal)));
249 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
250 items.push_back (RadioMenuElem (mode_group, _("Tape"),
251 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Destructive)));
252 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
254 switch (track()->mode()) {
255 case ARDOUR::Destructive:
256 destructive_track_mode_item->set_active ();
259 normal_track_mode_item->set_active ();
267 AudioTimeAxisView::toggle_waveforms ()
269 AudioStreamView* asv = audio_view();
272 if (asv && waveform_item && !ignore_toggle) {
273 asv->set_show_waveforms (waveform_item->get_active());
278 AudioTimeAxisView::set_show_waveforms (bool yn)
280 AudioStreamView* asv = audio_view();
284 waveform_item->set_active (yn);
286 asv->set_show_waveforms (yn);
291 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
293 AudioStreamView* asv = audio_view();
296 asv->set_show_waveforms_recording (yn);
301 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
303 AudioStreamView* asv = audio_view();
305 if (asv && !ignore_toggle) {
306 asv->set_waveform_shape (shape);
313 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
315 AudioStreamView* asv = audio_view();
317 if (asv && !ignore_toggle) {
318 asv->set_waveform_scale (scale);
325 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
327 if (param.type() == GainAutomation) {
329 boost::shared_ptr<AutomationControl> c = _route->gain_control();
331 error << "Route has no gain automation, unable to add automation track view." << endmsg;
335 boost::shared_ptr<AutomationTimeAxisView> gain_track(new AutomationTimeAxisView (_session,
341 _route->describe_parameter(param)));
343 add_automation_child(Evoral::Parameter(GainAutomation), gain_track, show);
345 } else if (param.type() == PanAutomation) {
348 ensure_pan_views (show);
351 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
355 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
356 * panners that we have.
358 * @param show true to show any new views that we create, otherwise false.
361 AudioTimeAxisView::ensure_pan_views (bool show)
363 const set<Evoral::Parameter>& params = _route->panner().what_can_be_automated();
364 set<Evoral::Parameter>::iterator p;
366 for (p = params.begin(); p != params.end(); ++p) {
367 boost::shared_ptr<ARDOUR::AutomationControl> pan_control
368 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
369 _route->panner().data().control(*p));
371 if (pan_control->parameter().type() == NullAutomation) {
372 error << "Pan control has NULL automation type!" << endmsg;
376 if (automation_child (pan_control->parameter ()).get () == 0) {
378 /* we don't already have an AutomationTimeAxisView for this parameter */
380 std::string const name = _route->describe_parameter (pan_control->parameter ());
382 boost::shared_ptr<AutomationTimeAxisView> pan_track (
383 new AutomationTimeAxisView (_session,
384 _route, _route, pan_control,
393 add_automation_child (*p, pan_track, show);
399 AudioTimeAxisView::toggle_gain_track ()
401 bool showit = gain_automation_item->get_active();
403 if (showit != gain_track->marked_for_display()) {
405 gain_track->set_marked_for_display (true);
406 gain_track->canvas_display->show();
407 gain_track->canvas_background->show();
408 gain_track->get_state_node()->add_property ("shown", X_("yes"));
410 gain_track->set_marked_for_display (false);
412 gain_track->get_state_node()->add_property ("shown", X_("no"));
415 /* now trigger a redisplay */
418 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
424 AudioTimeAxisView::gain_hidden ()
426 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
428 if (gain_automation_item && !_hidden) {
429 gain_automation_item->set_active (false);
432 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
436 AudioTimeAxisView::toggle_pan_track ()
438 bool showit = pan_automation_item->get_active();
440 if (showit != pan_track->marked_for_display()) {
442 pan_track->set_marked_for_display (true);
443 pan_track->canvas_display->show();
444 pan_track->canvas_background->show();
445 pan_track->get_state_node()->add_property ("shown", X_("yes"));
447 pan_track->set_marked_for_display (false);
449 pan_track->get_state_node()->add_property ("shown", X_("no"));
452 /* now trigger a redisplay */
458 AudioTimeAxisView::show_all_automation ()
462 RouteTimeAxisView::show_all_automation ();
466 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
470 AudioTimeAxisView::show_existing_automation ()
474 RouteTimeAxisView::show_existing_automation ();
478 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
482 AudioTimeAxisView::hide_all_automation ()
486 RouteTimeAxisView::hide_all_automation();
489 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
493 AudioTimeAxisView::show_all_xfades ()
495 AudioStreamView* asv = audio_view();
498 asv->show_all_xfades ();
503 AudioTimeAxisView::hide_all_xfades ()
505 AudioStreamView* asv = audio_view();
508 asv->hide_all_xfades ();
513 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
515 AudioStreamView* asv = audio_view();
518 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
519 asv->hide_xfades_involving (*rv);
524 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
526 AudioStreamView* asv = audio_view();
529 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
530 asv->reveal_xfades_involving (*rv);
535 AudioTimeAxisView::route_active_changed ()
537 RouteTimeAxisView::route_active_changed ();
538 update_control_names ();
543 * Set up the names of the controls so that they are coloured
544 * correctly depending on whether this route is inactive or
549 AudioTimeAxisView::update_control_names ()
551 if (is_audio_track()) {
552 if (_route->active()) {
553 controls_base_selected_name = "AudioTrackControlsBaseSelected";
554 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
556 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
557 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
560 if (_route->active()) {
561 controls_base_selected_name = "BusControlsBaseSelected";
562 controls_base_unselected_name = "BusControlsBaseUnselected";
564 controls_base_selected_name = "BusControlsBaseInactiveSelected";
565 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
569 if (get_selected()) {
570 controls_ebox.set_name (controls_base_selected_name);
572 controls_ebox.set_name (controls_base_unselected_name);