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"
48 #include "canvas_impl.h"
50 #include "gui_thread.h"
51 #include "automation_time_axis.h"
53 #include "playlist_selector.h"
55 #include "public_editor.h"
56 #include "audio_region_view.h"
57 #include "simplerect.h"
58 #include "audio_streamview.h"
64 using namespace ARDOUR;
67 using namespace Editing;
69 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, Canvas& canvas)
71 , RouteTimeAxisView(ed, sess, canvas)
76 AudioTimeAxisView::set_route (boost::shared_ptr<Route> rt)
80 /* RouteTimeAxisView::set_route() sets up some things in the View,
81 so it must be created before RouteTimeAxis::set_route() is
84 _view = new AudioStreamView (*this);
86 RouteTimeAxisView::set_route (rt);
88 _view->apply_color (color (), StreamView::RegionColor);
90 // Make sure things are sane...
91 assert(!is_track() || is_audio_track());
93 subplugin_menu.set_name ("ArdourContextMenu");
95 ignore_toggle = false;
97 if (is_audio_track()) {
98 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
100 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
103 /* if set_state above didn't create a gain automation child, we need to make one */
104 if (automation_child (GainAutomation) == 0) {
105 create_automation_child (GainAutomation, false);
108 if (_route->panner_shell()) {
109 _route->panner_shell()->Changed.connect (*this, invalidator (*this),
110 boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
113 /* map current state of the route */
115 processors_changed (RouteProcessorChange ());
116 reset_processor_automation_curves ();
117 ensure_pan_views (false);
118 update_control_names ();
120 if (is_audio_track()) {
122 /* ask for notifications of any new RegionViews */
123 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
125 if (!_editor.have_idled()) {
126 /* first idle will do what we need */
136 AudioTimeAxisView::~AudioTimeAxisView ()
141 AudioTimeAxisView::first_idle ()
148 AudioTimeAxisView::audio_view()
150 return dynamic_cast<AudioStreamView*>(_view);
154 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
156 set_gui_property ("visible", true);
157 return TimeAxisView::show_at (y, nth, parent);
161 AudioTimeAxisView::hide ()
163 set_gui_property ("visible", false);
164 TimeAxisView::hide ();
168 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
170 if (param.type() == NullAutomation) {
174 AutomationTracks::iterator existing = _automation_tracks.find (param);
176 if (existing != _automation_tracks.end()) {
178 /* automation track created because we had existing data for
179 * the processor, but visibility may need to be controlled
180 * since it will have been set visible by default.
183 existing->second->set_marked_for_display (show);
192 if (param.type() == GainAutomation) {
194 create_gain_automation_child (param, show);
196 } else if (param.type() == PanWidthAutomation ||
197 param.type() == PanElevationAutomation ||
198 param.type() == PanAzimuthAutomation) {
200 ensure_pan_views (show);
202 } else if (param.type() == PluginAutomation) {
204 /* handled elsewhere */
207 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
211 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
212 * panners that we have.
214 * @param show true to show any new views that we create, otherwise false.
217 AudioTimeAxisView::ensure_pan_views (bool show)
219 bool changed = false;
220 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
222 (*i)->set_marked_for_display (false);
225 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
229 if (!_route->panner()) {
233 set<Evoral::Parameter> params = _route->panner()->what_can_be_automated();
234 set<Evoral::Parameter>::iterator p;
236 for (p = params.begin(); p != params.end(); ++p) {
237 boost::shared_ptr<ARDOUR::AutomationControl> pan_control = _route->pannable()->automation_control(*p);
239 if (pan_control->parameter().type() == NullAutomation) {
240 error << "Pan control has NULL automation type!" << endmsg;
244 if (automation_child (pan_control->parameter ()).get () == 0) {
246 /* we don't already have an AutomationTimeAxisView for this parameter */
248 std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
250 boost::shared_ptr<AutomationTimeAxisView> t (
251 new AutomationTimeAxisView (_session,
255 pan_control->parameter (),
263 pan_tracks.push_back (t);
264 add_automation_child (*p, t, show);
266 pan_tracks.push_back (automation_child (pan_control->parameter ()));
272 AudioTimeAxisView::update_gain_track_visibility ()
274 bool const showit = gain_automation_item->get_active();
276 if (showit != string_is_affirmative (gain_track->gui_property ("visible"))) {
277 gain_track->set_marked_for_display (showit);
279 /* now trigger a redisplay */
282 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
288 AudioTimeAxisView::update_pan_track_visibility ()
290 bool const showit = pan_automation_item->get_active();
291 bool changed = false;
293 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
294 if ((*i)->set_marked_for_display (showit)) {
300 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
305 AudioTimeAxisView::show_all_automation (bool apply_to_selection)
307 if (apply_to_selection) {
308 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_all_automation, _1, false));
313 RouteTimeAxisView::show_all_automation ();
321 AudioTimeAxisView::show_existing_automation (bool apply_to_selection)
323 if (apply_to_selection) {
324 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_existing_automation, _1, false));
328 RouteTimeAxisView::show_existing_automation ();
337 AudioTimeAxisView::hide_all_automation (bool apply_to_selection)
339 if (apply_to_selection) {
340 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::hide_all_automation, _1, false));
344 RouteTimeAxisView::hide_all_automation();
352 AudioTimeAxisView::route_active_changed ()
354 update_control_names ();
359 * Set up the names of the controls so that they are coloured
360 * correctly depending on whether this route is inactive or
365 AudioTimeAxisView::update_control_names ()
367 if (is_audio_track()) {
368 if (_route->active()) {
369 controls_base_selected_name = "AudioTrackControlsBaseSelected";
370 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
372 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
373 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
376 if (_route->active()) {
377 controls_base_selected_name = "BusControlsBaseSelected";
378 controls_base_unselected_name = "BusControlsBaseUnselected";
380 controls_base_selected_name = "BusControlsBaseInactiveSelected";
381 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
385 if (get_selected()) {
386 controls_ebox.set_name (controls_base_selected_name);
388 controls_ebox.set_name (controls_base_unselected_name);
393 AudioTimeAxisView::build_automation_action_menu (bool for_selection)
395 using namespace Menu_Helpers;
397 RouteTimeAxisView::build_automation_action_menu (for_selection);
399 MenuList& automation_items = automation_action_menu->items ();
401 automation_items.push_back (CheckMenuElem (_("Fader"), sigc::mem_fun (*this, &AudioTimeAxisView::update_gain_track_visibility)));
402 gain_automation_item = dynamic_cast<CheckMenuItem*> (&automation_items.back ());
403 gain_automation_item->set_active ((!for_selection || _editor.get_selection().tracks.size() == 1) &&
404 (gain_track && string_is_affirmative (gain_track->gui_property ("visible"))));
406 _main_automation_menu_map[Evoral::Parameter(GainAutomation)] = gain_automation_item;
408 if (!pan_tracks.empty()) {
409 automation_items.push_back (CheckMenuElem (_("Pan"), sigc::mem_fun (*this, &AudioTimeAxisView::update_pan_track_visibility)));
410 pan_automation_item = dynamic_cast<CheckMenuItem*> (&automation_items.back ());
411 pan_automation_item->set_active ((!for_selection || _editor.get_selection().tracks.size() == 1) &&
412 (!pan_tracks.empty() && string_is_affirmative (pan_tracks.front()->gui_property ("visible"))));
414 set<Evoral::Parameter> const & params = _route->pannable()->what_can_be_automated ();
415 for (set<Evoral::Parameter>::iterator p = params.begin(); p != params.end(); ++p) {
416 _main_automation_menu_map[*p] = pan_automation_item;
422 AudioTimeAxisView::enter_internal_edit_mode ()
425 audio_view()->enter_internal_edit_mode ();
430 AudioTimeAxisView::leave_internal_edit_mode ()
433 audio_view()->leave_internal_edit_mode ();