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/bindable_button.h>
37 #include <gtkmm2ext/utils.h>
39 #include "ardour/amp.h"
40 #include "ardour/audioplaylist.h"
41 #include "ardour/event_type_map.h"
42 #include "ardour/location.h"
43 #include "ardour/pannable.h"
44 #include "ardour/panner.h"
45 #include "ardour/panner_shell.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 "gui_thread.h"
60 #include "automation_time_axis.h"
62 #include "playlist_selector.h"
64 #include "public_editor.h"
65 #include "audio_region_view.h"
66 #include "simplerect.h"
67 #include "audio_streamview.h"
70 #include "ardour/audio_track.h"
75 using namespace ARDOUR;
78 using namespace Editing;
80 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, boost::shared_ptr<Route> rt, Canvas& canvas)
82 , RouteTimeAxisView(ed, sess, rt, canvas)
84 // Make sure things are sane...
85 assert(!is_track() || is_audio_track());
87 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, Stateful::loading_state_version);
106 /* if set_state above didn't create a gain automation child, we need to make one */
107 if (automation_child (GainAutomation) == 0) {
108 create_automation_child (GainAutomation, false);
111 if (_route->panner()) {
112 _route->panner_shell()->Changed.connect (*this, invalidator (*this),
113 boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
116 /* map current state of the route */
118 processors_changed (RouteProcessorChange ());
119 reset_processor_automation_curves ();
120 ensure_pan_views (false);
121 update_control_names ();
123 if (is_audio_track()) {
125 /* ask for notifications of any new RegionViews */
126 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
128 if (!_editor.have_idled()) {
129 /* first idle will do what we need */
139 AudioTimeAxisView::~AudioTimeAxisView ()
144 AudioTimeAxisView::first_idle ()
151 AudioTimeAxisView::audio_view()
153 return dynamic_cast<AudioStreamView*>(_view);
157 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
160 xml_node->add_property ("shown-editor", "yes");
162 return TimeAxisView::show_at (y, nth, parent);
166 AudioTimeAxisView::hide ()
169 xml_node->add_property ("shown-editor", "no");
171 TimeAxisView::hide ();
176 AudioTimeAxisView::append_extra_display_menu_items ()
178 using namespace Menu_Helpers;
180 MenuList& items = display_menu->items();
183 if (!Profile->get_sae() && is_track ()) {
184 items.push_back (MenuElem (_("Hide All Crossfades"), sigc::mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
185 items.push_back (MenuElem (_("Show All Crossfades"), sigc::mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
186 items.push_back (SeparatorElem ());
191 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
193 if (param.type() == GainAutomation) {
195 create_gain_automation_child (param, show);
197 } else if (param.type() == PanWidthAutomation ||
198 param.type() == PanElevationAutomation ||
199 param.type() == PanAzimuthAutomation) {
202 ensure_pan_views (show);
204 } else if (param.type() == PluginAutomation) {
206 /* handled elsewhere */
209 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
213 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
214 * panners that we have.
216 * @param show true to show any new views that we create, otherwise false.
219 AudioTimeAxisView::ensure_pan_views (bool show)
221 if (!_route->panner()) {
225 set<Evoral::Parameter> params = _route->panner()->what_can_be_automated();
226 set<Evoral::Parameter>::iterator p;
228 for (p = params.begin(); p != params.end(); ++p) {
229 boost::shared_ptr<ARDOUR::AutomationControl> pan_control = _route->pannable()->automation_control(*p);
231 if (pan_control->parameter().type() == NullAutomation) {
232 error << "Pan control has NULL automation type!" << endmsg;
236 if (automation_child (pan_control->parameter ()).get () == 0) {
238 /* we don't already have an AutomationTimeAxisView for this parameter */
240 std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
242 boost::shared_ptr<AutomationTimeAxisView> t (
243 new AutomationTimeAxisView (_session,
247 pan_control->parameter (),
255 pan_tracks.push_back (t);
256 add_automation_child (*p, t, show);
262 AudioTimeAxisView::update_gain_track_visibility ()
264 bool const showit = gain_automation_item->get_active();
266 if (showit != gain_track->marked_for_display()) {
268 gain_track->set_marked_for_display (true);
269 gain_track->canvas_display()->show();
270 gain_track->canvas_background()->show();
271 gain_track->get_state_node()->add_property ("shown", X_("yes"));
273 gain_track->set_marked_for_display (false);
275 gain_track->get_state_node()->add_property ("shown", X_("no"));
278 /* now trigger a redisplay */
281 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
287 AudioTimeAxisView::update_pan_track_visibility ()
289 bool const showit = pan_automation_item->get_active();
291 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
293 if (showit != (*i)->marked_for_display()) {
295 (*i)->set_marked_for_display (true);
296 (*i)->canvas_display()->show();
297 (*i)->canvas_background()->show();
298 (*i)->get_state_node()->add_property ("shown", X_("yes"));
300 (*i)->set_marked_for_display (false);
302 (*i)->get_state_node()->add_property ("shown", X_("no"));
305 /* now trigger a redisplay */
307 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
314 AudioTimeAxisView::show_all_automation ()
318 RouteTimeAxisView::show_all_automation ();
322 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
326 AudioTimeAxisView::show_existing_automation ()
330 RouteTimeAxisView::show_existing_automation ();
334 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
338 AudioTimeAxisView::hide_all_automation ()
342 RouteTimeAxisView::hide_all_automation();
345 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
349 AudioTimeAxisView::show_all_xfades ()
351 AudioStreamView* asv = audio_view();
354 asv->show_all_xfades ();
359 AudioTimeAxisView::hide_all_xfades ()
361 AudioStreamView* asv = audio_view();
364 asv->hide_all_xfades ();
369 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
371 AudioStreamView* asv = audio_view();
374 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
375 asv->hide_xfades_involving (*rv);
380 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
382 AudioStreamView* asv = audio_view();
385 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
386 asv->reveal_xfades_involving (*rv);
391 AudioTimeAxisView::route_active_changed ()
393 RouteTimeAxisView::route_active_changed ();
394 update_control_names ();
399 * Set up the names of the controls so that they are coloured
400 * correctly depending on whether this route is inactive or
405 AudioTimeAxisView::update_control_names ()
407 if (is_audio_track()) {
408 if (_route->active()) {
409 controls_base_selected_name = "AudioTrackControlsBaseSelected";
410 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
412 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
413 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
416 if (_route->active()) {
417 controls_base_selected_name = "BusControlsBaseSelected";
418 controls_base_unselected_name = "BusControlsBaseUnselected";
420 controls_base_selected_name = "BusControlsBaseInactiveSelected";
421 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
425 if (get_selected()) {
426 controls_ebox.set_name (controls_base_selected_name);
428 controls_ebox.set_name (controls_base_unselected_name);
433 AudioTimeAxisView::build_automation_action_menu ()
435 using namespace Menu_Helpers;
437 RouteTimeAxisView::build_automation_action_menu ();
439 MenuList& automation_items = automation_action_menu->items ();
441 automation_items.push_back (CheckMenuElem (_("Fader"), sigc::mem_fun (*this, &AudioTimeAxisView::update_gain_track_visibility)));
442 gain_automation_item = dynamic_cast<CheckMenuItem*> (&automation_items.back ());
443 gain_automation_item->set_active (gain_track->marked_for_display ());
445 _main_automation_menu_map[Evoral::Parameter(GainAutomation)] = gain_automation_item;
447 automation_items.push_back (CheckMenuElem (_("Pan"), sigc::mem_fun (*this, &AudioTimeAxisView::update_pan_track_visibility)));
448 pan_automation_item = dynamic_cast<CheckMenuItem*> (&automation_items.back ());
449 pan_automation_item->set_active (pan_tracks.front()->marked_for_display ());
451 set<Evoral::Parameter> const & params = _route->pannable()->what_can_be_automated ();
452 for (set<Evoral::Parameter>::iterator p = params.begin(); p != params.end(); ++p) {
453 _main_automation_menu_map[*p] = pan_automation_item;
458 AudioTimeAxisView::add_processor_to_subplugin_menu (boost::weak_ptr<Processor> wp)
460 /* we use this override to veto the Amp processor from the plugin menu,
461 as its automation lane can be accessed using the special "Fader" menu
465 boost::shared_ptr<Processor> p = wp.lock ();
470 if (boost::dynamic_pointer_cast<Amp> (p) == 0) {
471 RouteTimeAxisView::add_processor_to_subplugin_menu (wp);