various fixes to MidiRegionView selection handling, key handling, drawing of ghost...
[ardour2.git] / gtk2_ardour / audio_time_axis.cc
blobd06652b648e5483589f3e5f0cf635dda705034b7
1 /*
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.
20 #include <cstdlib>
21 #include <cmath>
22 #include <cassert>
24 #include <algorithm>
25 #include <string>
26 #include <vector>
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"
58 #include "enums.h"
59 #include "gui_thread.h"
60 #include "automation_time_axis.h"
61 #include "keyboard.h"
62 #include "playlist_selector.h"
63 #include "prompter.h"
64 #include "public_editor.h"
65 #include "audio_region_view.h"
66 #include "simplerect.h"
67 #include "audio_streamview.h"
68 #include "utils.h"
70 #include "ardour/audio_track.h"
72 #include "i18n.h"
74 using namespace std;
75 using namespace ARDOUR;
76 using namespace PBD;
77 using namespace Gtk;
78 using namespace Editing;
80 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, Canvas& canvas)
81 : AxisView(sess)
82 , RouteTimeAxisView(ed, sess, canvas)
86 void
87 AudioTimeAxisView::set_route (boost::shared_ptr<Route> rt)
89 RouteTimeAxisView::set_route (rt);
91 // Make sure things are sane...
92 assert(!is_track() || is_audio_track());
94 subplugin_menu.set_name ("ArdourContextMenu");
96 _view = new AudioStreamView (*this);
98 ignore_toggle = false;
100 mute_button->set_active (false);
101 solo_button->set_active (false);
103 if (is_audio_track()) {
104 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
105 } else { // bus
106 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
109 /* if set_state above didn't create a gain automation child, we need to make one */
110 if (automation_child (GainAutomation) == 0) {
111 create_automation_child (GainAutomation, false);
114 if (_route->panner()) {
115 _route->panner_shell()->Changed.connect (*this, invalidator (*this),
116 boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
119 /* map current state of the route */
121 processors_changed (RouteProcessorChange ());
122 reset_processor_automation_curves ();
123 ensure_pan_views (false);
124 update_control_names ();
126 if (is_audio_track()) {
128 /* ask for notifications of any new RegionViews */
129 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
131 if (!_editor.have_idled()) {
132 /* first idle will do what we need */
133 } else {
134 first_idle ();
137 } else {
138 post_construct ();
142 AudioTimeAxisView::~AudioTimeAxisView ()
146 void
147 AudioTimeAxisView::first_idle ()
149 _view->attach ();
150 post_construct ();
153 AudioStreamView*
154 AudioTimeAxisView::audio_view()
156 return dynamic_cast<AudioStreamView*>(_view);
159 guint32
160 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
162 set_gui_property ("visible", true);
163 return TimeAxisView::show_at (y, nth, parent);
166 void
167 AudioTimeAxisView::hide ()
169 set_gui_property ("visible", false);
170 TimeAxisView::hide ();
174 void
175 AudioTimeAxisView::append_extra_display_menu_items ()
177 using namespace Menu_Helpers;
179 MenuList& items = display_menu->items();
181 // crossfade stuff
182 if (!Profile->get_sae() && is_track ()) {
183 items.push_back (MenuElem (_("Hide All Crossfades"), sigc::bind (sigc::mem_fun(*this, &AudioTimeAxisView::hide_all_xfades), true)));
184 items.push_back (MenuElem (_("Show All Crossfades"), sigc::bind (sigc::mem_fun(*this, &AudioTimeAxisView::show_all_xfades), true)));
185 items.push_back (SeparatorElem ());
189 void
190 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
192 if (param.type() == NullAutomation) {
193 cerr << "WARNING: Attempt to create NullAutomation child, ignoring" << endl;
194 return;
197 AutomationTracks::iterator existing = _automation_tracks.find (param);
199 if (existing != _automation_tracks.end()) {
201 /* automation track created because we had existing data for
202 * the processor, but visibility may need to be controlled
203 * since it will have been set visible by default.
206 existing->second->set_marked_for_display (show);
208 if (!no_redraw) {
209 request_redraw ();
212 return;
215 if (param.type() == GainAutomation) {
217 create_gain_automation_child (param, show);
219 } else if (param.type() == PanWidthAutomation ||
220 param.type() == PanElevationAutomation ||
221 param.type() == PanAzimuthAutomation) {
223 ensure_pan_views (show);
225 } else if (param.type() == PluginAutomation) {
227 /* handled elsewhere */
229 } else {
230 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
234 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
235 * panners that we have.
237 * @param show true to show any new views that we create, otherwise false.
239 void
240 AudioTimeAxisView::ensure_pan_views (bool show)
242 if (!_route->panner()) {
243 return;
246 set<Evoral::Parameter> params = _route->panner()->what_can_be_automated();
247 set<Evoral::Parameter>::iterator p;
249 for (p = params.begin(); p != params.end(); ++p) {
250 boost::shared_ptr<ARDOUR::AutomationControl> pan_control = _route->pannable()->automation_control(*p);
252 if (pan_control->parameter().type() == NullAutomation) {
253 error << "Pan control has NULL automation type!" << endmsg;
254 continue;
257 if (automation_child (pan_control->parameter ()).get () == 0) {
259 /* we don't already have an AutomationTimeAxisView for this parameter */
261 std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
263 boost::shared_ptr<AutomationTimeAxisView> t (
264 new AutomationTimeAxisView (_session,
265 _route,
266 _route->pannable(),
267 pan_control,
268 pan_control->parameter (),
269 _editor,
270 *this,
271 false,
272 parent_canvas,
273 name)
276 pan_tracks.push_back (t);
277 add_automation_child (*p, t, show);
282 void
283 AudioTimeAxisView::update_gain_track_visibility ()
285 bool const showit = gain_automation_item->get_active();
287 if (showit != string_is_affirmative (gain_track->gui_property ("visible"))) {
288 gain_track->set_marked_for_display (showit);
290 /* now trigger a redisplay */
292 if (!no_redraw) {
293 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
298 void
299 AudioTimeAxisView::update_pan_track_visibility ()
301 bool const showit = pan_automation_item->get_active();
302 bool changed = false;
304 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
305 if ((*i)->set_marked_for_display (showit)) {
306 changed = true;
310 if (changed) {
311 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
315 void
316 AudioTimeAxisView::show_all_automation (bool apply_to_selection)
318 if (apply_to_selection) {
319 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_all_automation, _1, false));
320 } else {
322 no_redraw = true;
324 RouteTimeAxisView::show_all_automation ();
326 no_redraw = false;
327 request_redraw ();
331 void
332 AudioTimeAxisView::show_existing_automation (bool apply_to_selection)
334 if (apply_to_selection) {
335 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_existing_automation, _1, false));
336 } else {
337 no_redraw = true;
339 RouteTimeAxisView::show_existing_automation ();
341 no_redraw = false;
343 request_redraw ();
347 void
348 AudioTimeAxisView::hide_all_automation (bool apply_to_selection)
350 if (apply_to_selection) {
351 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::hide_all_automation, _1, false));
352 } else {
353 no_redraw = true;
355 RouteTimeAxisView::hide_all_automation();
357 no_redraw = false;
358 request_redraw ();
362 void
363 AudioTimeAxisView::show_all_xfades (bool apply_to_selection)
365 if (apply_to_selection) {
366 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::show_all_xfades, _1, false));
367 } else {
368 AudioStreamView* asv = audio_view ();
369 if (asv) {
370 asv->show_all_xfades ();
375 void
376 AudioTimeAxisView::hide_all_xfades (bool apply_to_selection)
378 if (apply_to_selection) {
379 _editor.get_selection().tracks.foreach_audio_time_axis (boost::bind (&AudioTimeAxisView::hide_all_xfades, _1, false));
380 } else {
381 AudioStreamView* asv = audio_view ();
382 if (asv) {
383 asv->hide_all_xfades ();
388 void
389 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
391 AudioStreamView* asv = audio_view();
392 AudioRegionView* rv;
394 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
395 asv->hide_xfades_involving (*rv);
399 void
400 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
402 AudioStreamView* asv = audio_view();
403 AudioRegionView* rv;
405 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
406 asv->reveal_xfades_involving (*rv);
410 void
411 AudioTimeAxisView::route_active_changed ()
413 update_control_names ();
418 * Set up the names of the controls so that they are coloured
419 * correctly depending on whether this route is inactive or
420 * selected.
423 void
424 AudioTimeAxisView::update_control_names ()
426 if (is_audio_track()) {
427 if (_route->active()) {
428 controls_base_selected_name = "AudioTrackControlsBaseSelected";
429 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
430 } else {
431 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
432 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
434 } else {
435 if (_route->active()) {
436 controls_base_selected_name = "BusControlsBaseSelected";
437 controls_base_unselected_name = "BusControlsBaseUnselected";
438 } else {
439 controls_base_selected_name = "BusControlsBaseInactiveSelected";
440 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
444 if (get_selected()) {
445 controls_ebox.set_name (controls_base_selected_name);
446 } else {
447 controls_ebox.set_name (controls_base_unselected_name);
451 void
452 AudioTimeAxisView::build_automation_action_menu (bool for_selection)
454 using namespace Menu_Helpers;
456 RouteTimeAxisView::build_automation_action_menu (for_selection);
458 MenuList& automation_items = automation_action_menu->items ();
460 automation_items.push_back (CheckMenuElem (_("Fader"), sigc::mem_fun (*this, &AudioTimeAxisView::update_gain_track_visibility)));
461 gain_automation_item = dynamic_cast<CheckMenuItem*> (&automation_items.back ());
462 gain_automation_item->set_active ((!for_selection || _editor.get_selection().tracks.size() == 1) &&
463 (gain_track && string_is_affirmative (gain_track->gui_property ("visible"))));
465 _main_automation_menu_map[Evoral::Parameter(GainAutomation)] = gain_automation_item;
467 automation_items.push_back (CheckMenuElem (_("Pan"), sigc::mem_fun (*this, &AudioTimeAxisView::update_pan_track_visibility)));
468 pan_automation_item = dynamic_cast<CheckMenuItem*> (&automation_items.back ());
469 pan_automation_item->set_active ((!for_selection || _editor.get_selection().tracks.size() == 1) &&
470 (!pan_tracks.empty() && string_is_affirmative (pan_tracks.front()->gui_property ("visible"))));
472 set<Evoral::Parameter> const & params = _route->pannable()->what_can_be_automated ();
473 for (set<Evoral::Parameter>::iterator p = params.begin(); p != params.end(); ++p) {
474 _main_automation_menu_map[*p] = pan_automation_item;
478 void
479 AudioTimeAxisView::enter_internal_edit_mode ()
481 if (audio_view()) {
482 audio_view()->enter_internal_edit_mode ();
486 void
487 AudioTimeAxisView::leave_internal_edit_mode ()
489 if (audio_view()) {
490 audio_view()->leave_internal_edit_mode ();