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;
63 using namespace ARDOUR_UI_UTILS;
66 using namespace Editing;
68 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, ArdourCanvas::Canvas& canvas)
70 , RouteTimeAxisView(ed, sess, canvas)
75 AudioTimeAxisView::set_route (boost::shared_ptr<Route> rt)
79 /* RouteTimeAxisView::set_route() sets up some things in the View,
80 so it must be created before RouteTimeAxis::set_route() is
83 _view = new AudioStreamView (*this);
85 RouteTimeAxisView::set_route (rt);
87 _view->apply_color (gdk_color_to_rgba (color()), StreamView::RegionColor);
89 // Make sure things are sane...
90 assert(!is_track() || is_audio_track());
92 subplugin_menu.set_name ("ArdourContextMenu");
94 ignore_toggle = false;
96 if (is_audio_track()) {
97 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
99 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
102 /* if set_state above didn't create a gain automation child, we need to make one */
103 if (automation_child (GainAutomation) == 0) {
104 create_automation_child (GainAutomation, false);
107 if (_route->panner_shell()) {
108 _route->panner_shell()->Changed.connect (*this, invalidator (*this),
109 boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
112 /* map current state of the route */
114 processors_changed (RouteProcessorChange ());
115 reset_processor_automation_curves ();
116 ensure_pan_views (false);
117 update_control_names ();
119 if (is_audio_track()) {
121 /* ask for notifications of any new RegionViews */
122 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
124 if (!_editor.have_idled()) {
125 /* first idle will do what we need */
135 AudioTimeAxisView::~AudioTimeAxisView ()
140 AudioTimeAxisView::first_idle ()
147 AudioTimeAxisView::audio_view()
149 return dynamic_cast<AudioStreamView*>(_view);
153 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
155 set_gui_property ("visible", true);
156 return TimeAxisView::show_at (y, nth, parent);
160 AudioTimeAxisView::hide ()
162 set_gui_property ("visible", false);
163 TimeAxisView::hide ();
167 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
169 if (param.type() == NullAutomation) {
173 AutomationTracks::iterator existing = _automation_tracks.find (param);
175 if (existing != _automation_tracks.end()) {
177 /* automation track created because we had existing data for
178 * the processor, but visibility may need to be controlled
179 * since it will have been set visible by default.
182 existing->second->set_marked_for_display (show);
191 if (param.type() == GainAutomation) {
193 create_gain_automation_child (param, show);
195 } else if (param.type() == PanWidthAutomation ||
196 param.type() == PanElevationAutomation ||
197 param.type() == PanAzimuthAutomation) {
199 ensure_pan_views (show);
201 } else if (param.type() == PluginAutomation) {
203 /* handled elsewhere */
206 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
210 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
211 * panners that we have.
213 * @param show true to show any new views that we create, otherwise false.
216 AudioTimeAxisView::ensure_pan_views (bool show)
218 bool changed = false;
219 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
221 (*i)->set_marked_for_display (false);
224 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
228 if (!_route->panner()) {
232 set<Evoral::Parameter> params = _route->panner()->what_can_be_automated();
233 set<Evoral::Parameter>::iterator p;
235 for (p = params.begin(); p != params.end(); ++p) {
236 boost::shared_ptr<ARDOUR::AutomationControl> pan_control = _route->pannable()->automation_control(*p);
238 if (pan_control->parameter().type() == NullAutomation) {
239 error << "Pan control has NULL automation type!" << endmsg;
243 if (automation_child (pan_control->parameter ()).get () == 0) {
245 /* we don't already have an AutomationTimeAxisView for this parameter */
247 std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
249 boost::shared_ptr<AutomationTimeAxisView> t (
250 new AutomationTimeAxisView (_session,
254 pan_control->parameter (),
262 pan_tracks.push_back (t);
263 add_automation_child (*p, t, show);
265 pan_tracks.push_back (automation_child (pan_control->parameter ()));
271 AudioTimeAxisView::update_gain_track_visibility ()
273 bool const showit = gain_automation_item->get_active();
275 if (showit != string_is_affirmative (gain_track->gui_property ("visible"))) {
276 gain_track->set_marked_for_display (showit);
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();
290 bool changed = false;
292 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
293 if ((*i)->set_marked_for_display (showit)) {
299 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
304 AudioTimeAxisView::show_all_automation (bool apply_to_selection)
306 if (apply_to_selection) {
307 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_all_automation, _1, false));
312 RouteTimeAxisView::show_all_automation ();
320 AudioTimeAxisView::show_existing_automation (bool apply_to_selection)
322 if (apply_to_selection) {
323 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_existing_automation, _1, false));
327 RouteTimeAxisView::show_existing_automation ();
336 AudioTimeAxisView::hide_all_automation (bool apply_to_selection)
338 if (apply_to_selection) {
339 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::hide_all_automation, _1, false));
343 RouteTimeAxisView::hide_all_automation();
351 AudioTimeAxisView::route_active_changed ()
353 update_control_names ();
358 * Set up the names of the controls so that they are coloured
359 * correctly depending on whether this route is inactive or
364 AudioTimeAxisView::update_control_names ()
366 if (is_audio_track()) {
367 if (_route->active()) {
368 controls_base_selected_name = "AudioTrackControlsBaseSelected";
369 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
371 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
372 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
375 if (_route->active()) {
376 controls_base_selected_name = "BusControlsBaseSelected";
377 controls_base_unselected_name = "BusControlsBaseUnselected";
379 controls_base_selected_name = "BusControlsBaseInactiveSelected";
380 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
384 if (get_selected()) {
385 controls_ebox.set_name (controls_base_selected_name);
387 controls_ebox.set_name (controls_base_unselected_name);
392 AudioTimeAxisView::build_automation_action_menu (bool for_selection)
394 using namespace Menu_Helpers;
396 RouteTimeAxisView::build_automation_action_menu (for_selection);
398 MenuList& automation_items = automation_action_menu->items ();
400 automation_items.push_back (CheckMenuElem (_("Fader"), sigc::mem_fun (*this, &AudioTimeAxisView::update_gain_track_visibility)));
401 gain_automation_item = dynamic_cast<Gtk::CheckMenuItem*> (&automation_items.back ());
402 gain_automation_item->set_active ((!for_selection || _editor.get_selection().tracks.size() == 1) &&
403 (gain_track && string_is_affirmative (gain_track->gui_property ("visible"))));
405 _main_automation_menu_map[Evoral::Parameter(GainAutomation)] = gain_automation_item;
407 if (!pan_tracks.empty()) {
408 automation_items.push_back (CheckMenuElem (_("Pan"), sigc::mem_fun (*this, &AudioTimeAxisView::update_pan_track_visibility)));
409 pan_automation_item = dynamic_cast<Gtk::CheckMenuItem*> (&automation_items.back ());
410 pan_automation_item->set_active ((!for_selection || _editor.get_selection().tracks.size() == 1) &&
411 (!pan_tracks.empty() && string_is_affirmative (pan_tracks.front()->gui_property ("visible"))));
413 set<Evoral::Parameter> const & params = _route->pannable()->what_can_be_automated ();
414 for (set<Evoral::Parameter>::const_iterator p = params.begin(); p != params.end(); ++p) {
415 _main_automation_menu_map[*p] = pan_automation_item;
421 AudioTimeAxisView::enter_internal_edit_mode ()
424 audio_view()->enter_internal_edit_mode ();
429 AudioTimeAxisView::leave_internal_edit_mode ()
432 audio_view()->leave_internal_edit_mode ();