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/audio_diskstream.h>
41 #include <ardour/audioplaylist.h>
42 #include <ardour/event_type_map.h>
43 #include <ardour/location.h>
44 #include <ardour/panner.h>
45 #include <ardour/playlist.h>
46 #include <ardour/processor.h>
47 #include <ardour/profile.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_line.h"
55 #include "canvas_impl.h"
56 #include "crossfade_view.h"
58 #include "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;
77 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
79 , RouteTimeAxisView(ed, sess, rt, canvas)
81 // Make sure things are sane...
82 assert(!is_track() || is_audio_track());
84 subplugin_menu.set_name ("ArdourContextMenu");
87 _view = new AudioStreamView (*this);
89 ignore_toggle = false;
91 mute_button->set_active (false);
92 solo_button->set_active (false);
94 if (is_audio_track()) {
95 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
97 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
102 set_state (*xml_node);
104 /* if set_state above didn't create a gain automation child, we need to make one */
105 if (automation_track (GainAutomation) == 0) {
106 create_automation_child (GainAutomation, false);
109 _route->panner().Changed.connect (bind (mem_fun(*this, &AudioTimeAxisView::ensure_pan_views), false));
111 /* map current state of the route */
113 processors_changed ();
114 reset_processor_automation_curves ();
115 ensure_pan_views (false);
116 update_control_names ();
118 if (is_audio_track()) {
120 /* ask for notifications of any new RegionViews */
121 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
123 if (!_editor.have_idled()) {
124 /* first idle will do what we need */
134 AudioTimeAxisView::~AudioTimeAxisView ()
139 AudioTimeAxisView::first_idle ()
146 AudioTimeAxisView::audio_view()
148 return dynamic_cast<AudioStreamView*>(_view);
152 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
155 xml_node->add_property ("shown-editor", "yes");
157 return TimeAxisView::show_at (y, nth, parent);
161 AudioTimeAxisView::hide ()
164 xml_node->add_property ("shown-editor", "no");
166 TimeAxisView::hide ();
171 AudioTimeAxisView::append_extra_display_menu_items ()
173 using namespace Menu_Helpers;
175 MenuList& items = display_menu->items();
178 if (!Profile->get_sae()) {
179 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
180 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
184 Menu *waveform_menu = manage(new Menu);
185 MenuList& waveform_items = waveform_menu->items();
186 waveform_menu->set_name ("ArdourContextMenu");
188 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
189 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
190 ignore_toggle = true;
191 waveform_item->set_active (_editor.show_waveforms());
192 ignore_toggle = false;
194 waveform_items.push_back (SeparatorElem());
196 RadioMenuItem::Group group;
198 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
199 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
201 if (!Profile->get_sae()) {
202 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
203 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
208 waveform_items.push_back (SeparatorElem());
210 RadioMenuItem::Group group2;
212 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
213 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
215 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
216 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
218 // setting initial item state
219 AudioStreamView* asv = audio_view();
221 ignore_toggle = true;
222 if (asv->get_waveform_shape() == Rectified && rectified_item) {
223 rectified_item->set_active(true);
225 traditional_item->set_active(true);
228 if (asv->get_waveform_scale() == LogWaveform)
229 logscale_item->set_active(true);
230 else linearscale_item->set_active(true);
231 ignore_toggle = false;
234 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
239 AudioTimeAxisView::build_mode_menu()
241 using namespace Menu_Helpers;
243 Menu* mode_menu = manage (new Menu);
244 MenuList& items = mode_menu->items();
245 mode_menu->set_name ("ArdourContextMenu");
247 RadioMenuItem::Group mode_group;
248 items.push_back (RadioMenuElem (mode_group, _("Normal"),
249 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Normal)));
250 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
251 items.push_back (RadioMenuElem (mode_group, _("Tape"),
252 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Destructive)));
253 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
255 switch (track()->mode()) {
256 case ARDOUR::Destructive:
257 destructive_track_mode_item->set_active ();
260 normal_track_mode_item->set_active ();
268 AudioTimeAxisView::toggle_waveforms ()
270 AudioStreamView* asv = audio_view();
273 if (asv && waveform_item && !ignore_toggle) {
274 asv->set_show_waveforms (waveform_item->get_active());
279 AudioTimeAxisView::set_show_waveforms (bool yn)
281 AudioStreamView* asv = audio_view();
285 waveform_item->set_active (yn);
287 asv->set_show_waveforms (yn);
292 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
294 AudioStreamView* asv = audio_view();
297 asv->set_show_waveforms_recording (yn);
302 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
304 AudioStreamView* asv = audio_view();
306 if (asv && !ignore_toggle) {
307 asv->set_waveform_shape (shape);
314 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
316 AudioStreamView* asv = audio_view();
318 if (asv && !ignore_toggle) {
319 asv->set_waveform_scale (scale);
326 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
328 if (param.type() == GainAutomation) {
330 boost::shared_ptr<AutomationControl> c = _route->gain_control();
332 error << "Route has no gain automation, unable to add automation track view." << endmsg;
336 boost::shared_ptr<AutomationTimeAxisView> gain_track(new AutomationTimeAxisView (_session,
342 _route->describe_parameter(param)));
344 add_automation_child(Evoral::Parameter(GainAutomation), gain_track, show);
346 } else if (param.type() == PanAutomation) {
349 ensure_pan_views (show);
352 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
356 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
357 * panners that we have.
359 * @param show true to show any new views that we create, otherwise false.
362 AudioTimeAxisView::ensure_pan_views (bool show)
364 const set<Evoral::Parameter>& params = _route->panner().what_can_be_automated();
365 set<Evoral::Parameter>::iterator p;
367 for (p = params.begin(); p != params.end(); ++p) {
368 boost::shared_ptr<ARDOUR::AutomationControl> pan_control
369 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
370 _route->panner().data().control(*p));
372 if (pan_control->parameter().type() == NullAutomation) {
373 error << "Pan control has NULL automation type!" << endmsg;
377 if (automation_child (pan_control->parameter ()).get () == 0) {
379 /* we don't already have an AutomationTimeAxisView for this parameter */
381 std::string const name = _route->describe_parameter (pan_control->parameter ());
383 boost::shared_ptr<AutomationTimeAxisView> pan_track (
384 new AutomationTimeAxisView (_session,
385 _route, _route, pan_control,
392 add_automation_child (*p, pan_track, show);
398 AudioTimeAxisView::toggle_gain_track ()
400 bool showit = gain_automation_item->get_active();
402 if (showit != gain_track->marked_for_display()) {
404 gain_track->set_marked_for_display (true);
405 gain_track->canvas_display->show();
406 gain_track->canvas_background->show();
407 gain_track->get_state_node()->add_property ("shown", X_("yes"));
409 gain_track->set_marked_for_display (false);
411 gain_track->get_state_node()->add_property ("shown", X_("no"));
414 /* now trigger a redisplay */
417 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
423 AudioTimeAxisView::gain_hidden ()
425 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
427 if (gain_automation_item && !_hidden) {
428 gain_automation_item->set_active (false);
431 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
435 AudioTimeAxisView::toggle_pan_track ()
437 bool showit = pan_automation_item->get_active();
439 if (showit != pan_track->marked_for_display()) {
441 pan_track->set_marked_for_display (true);
442 pan_track->canvas_display->show();
443 pan_track->canvas_background->show();
444 pan_track->get_state_node()->add_property ("shown", X_("yes"));
446 pan_track->set_marked_for_display (false);
448 pan_track->get_state_node()->add_property ("shown", X_("no"));
451 /* now trigger a redisplay */
457 AudioTimeAxisView::show_all_automation ()
461 RouteTimeAxisView::show_all_automation ();
465 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
469 AudioTimeAxisView::show_existing_automation ()
473 RouteTimeAxisView::show_existing_automation ();
477 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
481 AudioTimeAxisView::hide_all_automation ()
485 RouteTimeAxisView::hide_all_automation();
488 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
492 AudioTimeAxisView::show_all_xfades ()
494 AudioStreamView* asv = audio_view();
497 asv->show_all_xfades ();
502 AudioTimeAxisView::hide_all_xfades ()
504 AudioStreamView* asv = audio_view();
507 asv->hide_all_xfades ();
512 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
514 AudioStreamView* asv = audio_view();
517 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
518 asv->hide_xfades_involving (*rv);
523 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
525 AudioStreamView* asv = audio_view();
528 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
529 asv->reveal_xfades_involving (*rv);
534 AudioTimeAxisView::route_active_changed ()
536 RouteTimeAxisView::route_active_changed ();
537 update_control_names ();
542 * Set up the names of the controls so that they are coloured
543 * correctly depending on whether this route is inactive or
548 AudioTimeAxisView::update_control_names ()
550 if (is_audio_track()) {
551 if (_route->active()) {
552 controls_base_selected_name = "AudioTrackControlsBaseSelected";
553 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
555 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
556 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
559 if (_route->active()) {
560 controls_base_selected_name = "BusControlsBaseSelected";
561 controls_base_unselected_name = "BusControlsBaseUnselected";
563 controls_base_selected_name = "BusControlsBaseInactiveSelected";
564 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
568 if (get_selected()) {
569 controls_ebox.set_name (controls_base_selected_name);
571 controls_ebox.set_name (controls_base_unselected_name);