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/amp.h"
41 #include "ardour/audio_diskstream.h"
42 #include "ardour/audioplaylist.h"
43 #include "ardour/event_type_map.h"
44 #include "ardour/location.h"
45 #include "ardour/panner.h"
46 #include "ardour/playlist.h"
47 #include "ardour/processor.h"
48 #include "ardour/profile.h"
49 #include "ardour/session.h"
50 #include "ardour/session_playlist.h"
51 #include "ardour/utils.h"
53 #include "ardour_ui.h"
54 #include "audio_time_axis.h"
55 #include "automation_line.h"
56 #include "canvas_impl.h"
57 #include "crossfade_view.h"
59 #include "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"
74 using namespace ARDOUR;
77 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");
89 _view = new AudioStreamView (*this);
91 ignore_toggle = false;
93 mute_button->set_active (false);
94 solo_button->set_active (false);
96 if (is_audio_track()) {
97 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
99 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
104 set_state (*xml_node);
106 /* if set_state above didn't create a gain automation child, we need to make one */
107 if (automation_track (GainAutomation) == 0) {
108 create_automation_child (GainAutomation, false);
111 if (_route->panner()) {
112 _route->panner()->Changed.connect (bind (
113 mem_fun(*this, &AudioTimeAxisView::ensure_pan_views),
117 /* map current state of the route */
119 processors_changed ();
120 reset_processor_automation_curves ();
121 ensure_pan_views (false);
122 update_control_names ();
124 if (is_audio_track()) {
126 /* ask for notifications of any new RegionViews */
127 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
129 if (!_editor.have_idled()) {
130 /* first idle will do what we need */
140 AudioTimeAxisView::~AudioTimeAxisView ()
145 AudioTimeAxisView::first_idle ()
152 AudioTimeAxisView::audio_view()
154 return dynamic_cast<AudioStreamView*>(_view);
158 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
161 xml_node->add_property ("shown-editor", "yes");
163 return TimeAxisView::show_at (y, nth, parent);
167 AudioTimeAxisView::hide ()
170 xml_node->add_property ("shown-editor", "no");
172 TimeAxisView::hide ();
177 AudioTimeAxisView::append_extra_display_menu_items ()
179 using namespace Menu_Helpers;
181 MenuList& items = display_menu->items();
184 if (!Profile->get_sae()) {
185 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
186 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
190 Menu *waveform_menu = manage(new Menu);
191 MenuList& waveform_items = waveform_menu->items();
192 waveform_menu->set_name ("ArdourContextMenu");
194 waveform_items.push_back (CheckMenuElem (_("Show waveforms"), mem_fun(*this, &AudioTimeAxisView::toggle_waveforms)));
195 waveform_item = static_cast<CheckMenuItem *> (&waveform_items.back());
196 ignore_toggle = true;
197 waveform_item->set_active (_editor.show_waveforms());
198 ignore_toggle = false;
200 waveform_items.push_back (SeparatorElem());
202 RadioMenuItem::Group group;
204 waveform_items.push_back (RadioMenuElem (group, _("Traditional"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Traditional)));
205 traditional_item = static_cast<RadioMenuItem *> (&waveform_items.back());
207 if (!Profile->get_sae()) {
208 waveform_items.push_back (RadioMenuElem (group, _("Rectified"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_shape), Rectified)));
209 rectified_item = static_cast<RadioMenuItem *> (&waveform_items.back());
214 waveform_items.push_back (SeparatorElem());
216 RadioMenuItem::Group group2;
218 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
219 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
221 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
222 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
224 // setting initial item state
225 AudioStreamView* asv = audio_view();
227 ignore_toggle = true;
228 if (asv->get_waveform_shape() == Rectified && rectified_item) {
229 rectified_item->set_active(true);
231 traditional_item->set_active(true);
234 if (asv->get_waveform_scale() == LogWaveform)
235 logscale_item->set_active(true);
236 else linearscale_item->set_active(true);
237 ignore_toggle = false;
240 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
245 AudioTimeAxisView::build_mode_menu()
247 using namespace Menu_Helpers;
249 Menu* mode_menu = manage (new Menu);
250 MenuList& items = mode_menu->items();
251 mode_menu->set_name ("ArdourContextMenu");
253 RadioMenuItem::Group mode_group;
255 items.push_back (RadioMenuElem (mode_group, _("Normal"),
256 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Normal)));
257 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
259 items.push_back (RadioMenuElem (mode_group, _("Non Overlapping"),
260 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::NonLayered)));
261 non_layered_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
263 items.push_back (RadioMenuElem (mode_group, _("Tape"),
264 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Destructive)));
265 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
267 switch (track()->mode()) {
268 case ARDOUR::Destructive:
269 destructive_track_mode_item->set_active ();
271 case ARDOUR::NonLayered:
272 non_layered_track_mode_item->set_active ();
275 normal_track_mode_item->set_active ();
283 AudioTimeAxisView::toggle_waveforms ()
285 AudioStreamView* asv = audio_view();
288 if (asv && waveform_item && !ignore_toggle) {
289 asv->set_show_waveforms (waveform_item->get_active());
294 AudioTimeAxisView::set_show_waveforms (bool yn)
296 AudioStreamView* asv = audio_view();
300 waveform_item->set_active (yn);
302 asv->set_show_waveforms (yn);
307 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
309 AudioStreamView* asv = audio_view();
312 asv->set_show_waveforms_recording (yn);
317 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
319 AudioStreamView* asv = audio_view();
321 if (asv && !ignore_toggle) {
322 asv->set_waveform_shape (shape);
329 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
331 AudioStreamView* asv = audio_view();
333 if (asv && !ignore_toggle) {
334 asv->set_waveform_scale (scale);
341 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
343 if (param.type() == GainAutomation) {
345 boost::shared_ptr<AutomationControl> c = _route->gain_control();
347 error << "Route has no gain automation, unable to add automation track view." << endmsg;
351 boost::shared_ptr<AutomationTimeAxisView>
352 gain_track(new AutomationTimeAxisView (_session,
353 _route, _route->amp(), c,
358 _route->amp()->describe_parameter(param)));
360 add_automation_child(Evoral::Parameter(GainAutomation), gain_track, show);
362 } else if (param.type() == PanAutomation) {
365 ensure_pan_views (show);
368 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
372 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
373 * panners that we have.
375 * @param show true to show any new views that we create, otherwise false.
378 AudioTimeAxisView::ensure_pan_views (bool show)
380 if (!_route->panner()) {
384 const set<Evoral::Parameter>& params = _route->panner()->what_can_be_automated();
385 set<Evoral::Parameter>::iterator p;
387 for (p = params.begin(); p != params.end(); ++p) {
388 boost::shared_ptr<ARDOUR::AutomationControl> pan_control
389 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
390 _route->panner()->data().control(*p));
392 if (pan_control->parameter().type() == NullAutomation) {
393 error << "Pan control has NULL automation type!" << endmsg;
397 if (automation_child (pan_control->parameter ()).get () == 0) {
399 /* we don't already have an AutomationTimeAxisView for this parameter */
401 std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
403 boost::shared_ptr<AutomationTimeAxisView> pan_track (
404 new AutomationTimeAxisView (_session,
405 _route, _route->panner(), pan_control,
412 add_automation_child (*p, pan_track, show);
418 AudioTimeAxisView::toggle_gain_track ()
420 bool showit = gain_automation_item->get_active();
422 if (showit != gain_track->marked_for_display()) {
424 gain_track->set_marked_for_display (true);
425 gain_track->canvas_display->show();
426 gain_track->canvas_background->show();
427 gain_track->get_state_node()->add_property ("shown", X_("yes"));
429 gain_track->set_marked_for_display (false);
431 gain_track->get_state_node()->add_property ("shown", X_("no"));
434 /* now trigger a redisplay */
437 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
443 AudioTimeAxisView::gain_hidden ()
445 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
447 if (gain_automation_item && !_hidden) {
448 gain_automation_item->set_active (false);
451 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
455 AudioTimeAxisView::toggle_pan_track ()
457 bool showit = pan_automation_item->get_active();
459 if (showit != pan_track->marked_for_display()) {
461 pan_track->set_marked_for_display (true);
462 pan_track->canvas_display->show();
463 pan_track->canvas_background->show();
464 pan_track->get_state_node()->add_property ("shown", X_("yes"));
466 pan_track->set_marked_for_display (false);
468 pan_track->get_state_node()->add_property ("shown", X_("no"));
471 /* now trigger a redisplay */
477 AudioTimeAxisView::show_all_automation ()
481 RouteTimeAxisView::show_all_automation ();
485 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
489 AudioTimeAxisView::show_existing_automation ()
493 RouteTimeAxisView::show_existing_automation ();
497 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
501 AudioTimeAxisView::hide_all_automation ()
505 RouteTimeAxisView::hide_all_automation();
508 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
512 AudioTimeAxisView::show_all_xfades ()
514 AudioStreamView* asv = audio_view();
517 asv->show_all_xfades ();
522 AudioTimeAxisView::hide_all_xfades ()
524 AudioStreamView* asv = audio_view();
527 asv->hide_all_xfades ();
532 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
534 AudioStreamView* asv = audio_view();
537 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
538 asv->hide_xfades_involving (*rv);
543 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
545 AudioStreamView* asv = audio_view();
548 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
549 asv->reveal_xfades_involving (*rv);
554 AudioTimeAxisView::route_active_changed ()
556 RouteTimeAxisView::route_active_changed ();
557 update_control_names ();
562 * Set up the names of the controls so that they are coloured
563 * correctly depending on whether this route is inactive or
568 AudioTimeAxisView::update_control_names ()
570 if (is_audio_track()) {
571 if (_route->active()) {
572 controls_base_selected_name = "AudioTrackControlsBaseSelected";
573 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
575 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
576 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
579 if (_route->active()) {
580 controls_base_selected_name = "BusControlsBaseSelected";
581 controls_base_unselected_name = "BusControlsBaseUnselected";
583 controls_base_selected_name = "BusControlsBaseInactiveSelected";
584 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
588 if (get_selected()) {
589 controls_ebox.set_name (controls_base_selected_name);
591 controls_ebox.set_name (controls_base_unselected_name);