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/event_type_map.h"
40 #include "ardour/pannable.h"
41 #include "ardour/panner.h"
42 #include "ardour/panner_shell.h"
44 #include "ardour_button.h"
45 #include "ardour_ui.h"
46 #include "audio_time_axis.h"
47 #include "automation_line.h"
49 #include "gui_thread.h"
50 #include "automation_time_axis.h"
52 #include "playlist_selector.h"
54 #include "public_editor.h"
55 #include "audio_region_view.h"
56 #include "audio_streamview.h"
62 using namespace ARDOUR;
65 using namespace Editing;
67 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, ArdourCanvas::Canvas& canvas)
69 , RouteTimeAxisView(ed, sess, canvas)
74 AudioTimeAxisView::set_route (boost::shared_ptr<Route> rt)
78 /* RouteTimeAxisView::set_route() sets up some things in the View,
79 so it must be created before RouteTimeAxis::set_route() is
82 _view = new AudioStreamView (*this);
84 RouteTimeAxisView::set_route (rt);
86 _view->apply_color (color (), StreamView::RegionColor);
88 // Make sure things are sane...
89 assert(!is_track() || is_audio_track());
91 subplugin_menu.set_name ("ArdourContextMenu");
93 ignore_toggle = false;
95 if (is_audio_track()) {
96 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
98 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
101 /* if set_state above didn't create a gain automation child, we need to make one */
102 if (automation_child (GainAutomation) == 0) {
103 create_automation_child (GainAutomation, false);
106 if (_route->panner_shell()) {
107 _route->panner_shell()->Changed.connect (*this, invalidator (*this),
108 boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
111 /* map current state of the route */
113 processors_changed (RouteProcessorChange ());
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 (sigc::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)
154 set_gui_property ("visible", true);
155 return TimeAxisView::show_at (y, nth, parent);
159 AudioTimeAxisView::hide ()
161 set_gui_property ("visible", false);
162 TimeAxisView::hide ();
166 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
168 if (param.type() == NullAutomation) {
172 AutomationTracks::iterator existing = _automation_tracks.find (param);
174 if (existing != _automation_tracks.end()) {
176 /* automation track created because we had existing data for
177 * the processor, but visibility may need to be controlled
178 * since it will have been set visible by default.
181 existing->second->set_marked_for_display (show);
190 if (param.type() == GainAutomation) {
192 create_gain_automation_child (param, show);
194 } else if (param.type() == PanWidthAutomation ||
195 param.type() == PanElevationAutomation ||
196 param.type() == PanAzimuthAutomation) {
198 ensure_pan_views (show);
200 } else if (param.type() == PluginAutomation) {
202 /* handled elsewhere */
205 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
209 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
210 * panners that we have.
212 * @param show true to show any new views that we create, otherwise false.
215 AudioTimeAxisView::ensure_pan_views (bool show)
217 bool changed = false;
218 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
220 (*i)->set_marked_for_display (false);
223 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
227 if (!_route->panner()) {
231 set<Evoral::Parameter> params = _route->panner()->what_can_be_automated();
232 set<Evoral::Parameter>::iterator p;
234 for (p = params.begin(); p != params.end(); ++p) {
235 boost::shared_ptr<ARDOUR::AutomationControl> pan_control = _route->pannable()->automation_control(*p);
237 if (pan_control->parameter().type() == NullAutomation) {
238 error << "Pan control has NULL automation type!" << endmsg;
242 if (automation_child (pan_control->parameter ()).get () == 0) {
244 /* we don't already have an AutomationTimeAxisView for this parameter */
246 std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
248 boost::shared_ptr<AutomationTimeAxisView> t (
249 new AutomationTimeAxisView (_session,
253 pan_control->parameter (),
261 pan_tracks.push_back (t);
262 add_automation_child (*p, t, show);
264 pan_tracks.push_back (automation_child (pan_control->parameter ()));
270 AudioTimeAxisView::update_gain_track_visibility ()
272 bool const showit = gain_automation_item->get_active();
274 if (showit != string_is_affirmative (gain_track->gui_property ("visible"))) {
275 gain_track->set_marked_for_display (showit);
277 /* now trigger a redisplay */
280 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
286 AudioTimeAxisView::update_pan_track_visibility ()
288 bool const showit = pan_automation_item->get_active();
289 bool changed = false;
291 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
292 if ((*i)->set_marked_for_display (showit)) {
298 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
303 AudioTimeAxisView::show_all_automation (bool apply_to_selection)
305 if (apply_to_selection) {
306 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_all_automation, _1, false));
311 RouteTimeAxisView::show_all_automation ();
319 AudioTimeAxisView::show_existing_automation (bool apply_to_selection)
321 if (apply_to_selection) {
322 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_existing_automation, _1, false));
326 RouteTimeAxisView::show_existing_automation ();
335 AudioTimeAxisView::hide_all_automation (bool apply_to_selection)
337 if (apply_to_selection) {
338 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::hide_all_automation, _1, false));
342 RouteTimeAxisView::hide_all_automation();
350 AudioTimeAxisView::route_active_changed ()
352 update_control_names ();
357 * Set up the names of the controls so that they are coloured
358 * correctly depending on whether this route is inactive or
363 AudioTimeAxisView::update_control_names ()
365 if (is_audio_track()) {
366 if (_route->active()) {
367 controls_base_selected_name = "AudioTrackControlsBaseSelected";
368 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
370 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
371 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
374 if (_route->active()) {
375 controls_base_selected_name = "BusControlsBaseSelected";
376 controls_base_unselected_name = "BusControlsBaseUnselected";
378 controls_base_selected_name = "BusControlsBaseInactiveSelected";
379 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
383 if (get_selected()) {
384 controls_ebox.set_name (controls_base_selected_name);
386 controls_ebox.set_name (controls_base_unselected_name);
391 AudioTimeAxisView::build_automation_action_menu (bool for_selection)
393 using namespace Menu_Helpers;
395 RouteTimeAxisView::build_automation_action_menu (for_selection);
397 MenuList& automation_items = automation_action_menu->items ();
399 automation_items.push_back (CheckMenuElem (_("Fader"), sigc::mem_fun (*this, &AudioTimeAxisView::update_gain_track_visibility)));
400 gain_automation_item = dynamic_cast<Gtk::CheckMenuItem*> (&automation_items.back ());
401 gain_automation_item->set_active ((!for_selection || _editor.get_selection().tracks.size() == 1) &&
402 (gain_track && string_is_affirmative (gain_track->gui_property ("visible"))));
404 _main_automation_menu_map[Evoral::Parameter(GainAutomation)] = gain_automation_item;
406 if (!pan_tracks.empty()) {
407 automation_items.push_back (CheckMenuElem (_("Pan"), sigc::mem_fun (*this, &AudioTimeAxisView::update_pan_track_visibility)));
408 pan_automation_item = dynamic_cast<Gtk::CheckMenuItem*> (&automation_items.back ());
409 pan_automation_item->set_active ((!for_selection || _editor.get_selection().tracks.size() == 1) &&
410 (!pan_tracks.empty() && string_is_affirmative (pan_tracks.front()->gui_property ("visible"))));
412 set<Evoral::Parameter> const & params = _route->pannable()->what_can_be_automated ();
413 for (set<Evoral::Parameter>::const_iterator p = params.begin(); p != params.end(); ++p) {
414 _main_automation_menu_map[*p] = pan_automation_item;
420 AudioTimeAxisView::enter_internal_edit_mode ()
423 audio_view()->enter_internal_edit_mode ();
428 AudioTimeAxisView::leave_internal_edit_mode ()
431 audio_view()->leave_internal_edit_mode ();