fix up file renaming code a little bit
[ArdourMidi.git] / gtk2_ardour / audio_time_axis.cc
blobfd809a9b0d7cafd692e299e9c43fa4b7b0bf4844
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/panner.h"
44 #include "ardour/playlist.h"
45 #include "ardour/processor.h"
46 #include "ardour/profile.h"
47 #include "ardour/session.h"
48 #include "ardour/session_playlist.h"
49 #include "ardour/utils.h"
51 #include "ardour_ui.h"
52 #include "audio_time_axis.h"
53 #include "automation_line.h"
54 #include "canvas_impl.h"
55 #include "crossfade_view.h"
56 #include "enums.h"
57 #include "gui_thread.h"
58 #include "automation_time_axis.h"
59 #include "keyboard.h"
60 #include "playlist_selector.h"
61 #include "prompter.h"
62 #include "public_editor.h"
63 #include "audio_region_view.h"
64 #include "simplerect.h"
65 #include "audio_streamview.h"
66 #include "utils.h"
68 #include "ardour/audio_track.h"
70 #include "i18n.h"
72 using namespace std;
73 using namespace ARDOUR;
74 using namespace PBD;
75 using namespace Gtk;
76 using namespace Editing;
78 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, boost::shared_ptr<Route> rt, Canvas& canvas)
79 : AxisView(sess)
80 , RouteTimeAxisView(ed, sess, rt, canvas)
82 // Make sure things are sane...
83 assert(!is_track() || is_audio_track());
85 subplugin_menu.set_name ("ArdourContextMenu");
87 _view = new AudioStreamView (*this);
89 ignore_toggle = false;
91 mute_button->set_active (false);
92 solo_button->set_active (false);
94 if (is_audio_track()) {
95 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
96 } else { // bus
97 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
100 ensure_xml_node ();
102 set_state (*xml_node, Stateful::loading_state_version);
104 /* if set_state above didn't create a gain automation child, we need to make one */
105 if (automation_child (GainAutomation) == 0) {
106 create_automation_child (GainAutomation, false);
109 if (_route->panner()) {
110 _route->panner()->Changed.connect (*this, invalidator (*this),
111 boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
114 /* map current state of the route */
116 processors_changed (RouteProcessorChange ());
117 reset_processor_automation_curves ();
118 ensure_pan_views (false);
119 update_control_names ();
121 if (is_audio_track()) {
123 /* ask for notifications of any new RegionViews */
124 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
126 if (!_editor.have_idled()) {
127 /* first idle will do what we need */
128 } else {
129 first_idle ();
132 } else {
133 post_construct ();
137 AudioTimeAxisView::~AudioTimeAxisView ()
141 void
142 AudioTimeAxisView::first_idle ()
144 _view->attach ();
145 post_construct ();
148 AudioStreamView*
149 AudioTimeAxisView::audio_view()
151 return dynamic_cast<AudioStreamView*>(_view);
154 guint32
155 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
157 ensure_xml_node ();
158 xml_node->add_property ("shown-editor", "yes");
160 return TimeAxisView::show_at (y, nth, parent);
163 void
164 AudioTimeAxisView::hide ()
166 ensure_xml_node ();
167 xml_node->add_property ("shown-editor", "no");
169 TimeAxisView::hide ();
173 void
174 AudioTimeAxisView::append_extra_display_menu_items ()
176 using namespace Menu_Helpers;
178 MenuList& items = display_menu->items();
180 // crossfade stuff
181 if (!Profile->get_sae()) {
182 items.push_back (MenuElem (_("Hide All Crossfades"), sigc::mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
183 items.push_back (MenuElem (_("Show All Crossfades"), sigc::mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
187 void
188 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
190 if (param.type() == GainAutomation) {
192 boost::shared_ptr<AutomationControl> c = _route->gain_control();
193 if (!c) {
194 error << "Route has no gain automation, unable to add automation track view." << endmsg;
195 return;
198 gain_track.reset (new AutomationTimeAxisView (_session,
199 _route, _route->amp(), c,
200 _editor,
201 *this,
202 false,
203 parent_canvas,
204 _route->amp()->describe_parameter(param)));
206 add_automation_child(Evoral::Parameter(GainAutomation), gain_track, show);
208 } else if (param.type() == PanAutomation) {
210 ensure_xml_node ();
211 ensure_pan_views (show);
213 } else {
214 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
218 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
219 * panners that we have.
221 * @param show true to show any new views that we create, otherwise false.
223 void
224 AudioTimeAxisView::ensure_pan_views (bool show)
226 if (!_route->panner()) {
227 return;
230 const set<Evoral::Parameter>& params = _route->panner()->what_can_be_automated();
231 set<Evoral::Parameter>::iterator p;
233 for (p = params.begin(); p != params.end(); ++p) {
234 boost::shared_ptr<ARDOUR::AutomationControl> pan_control
235 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
236 _route->panner()->control(*p));
238 if (pan_control->parameter().type() == NullAutomation) {
239 error << "Pan control has NULL automation type!" << endmsg;
240 continue;
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,
251 _route, _route->panner(), pan_control,
252 _editor,
253 *this,
254 false,
255 parent_canvas,
256 name)
259 pan_tracks.push_back (t);
260 add_automation_child (*p, t, show);
265 void
266 AudioTimeAxisView::update_gain_track_visibility ()
268 bool const showit = gain_automation_item->get_active();
270 if (showit != gain_track->marked_for_display()) {
271 if (showit) {
272 gain_track->set_marked_for_display (true);
273 gain_track->canvas_display()->show();
274 gain_track->canvas_background()->show();
275 gain_track->get_state_node()->add_property ("shown", X_("yes"));
276 } else {
277 gain_track->set_marked_for_display (false);
278 gain_track->hide ();
279 gain_track->get_state_node()->add_property ("shown", X_("no"));
282 /* now trigger a redisplay */
284 if (!no_redraw) {
285 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
290 void
291 AudioTimeAxisView::update_pan_track_visibility ()
293 bool const showit = pan_automation_item->get_active();
295 for (list<boost::shared_ptr<AutomationTimeAxisView> >::iterator i = pan_tracks.begin(); i != pan_tracks.end(); ++i) {
297 if (showit != (*i)->marked_for_display()) {
298 if (showit) {
299 (*i)->set_marked_for_display (true);
300 (*i)->canvas_display()->show();
301 (*i)->canvas_background()->show();
302 (*i)->get_state_node()->add_property ("shown", X_("yes"));
303 } else {
304 (*i)->set_marked_for_display (false);
305 (*i)->hide ();
306 (*i)->get_state_node()->add_property ("shown", X_("no"));
309 /* now trigger a redisplay */
310 if (!no_redraw) {
311 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
317 void
318 AudioTimeAxisView::show_all_automation ()
320 no_redraw = true;
322 RouteTimeAxisView::show_all_automation ();
324 no_redraw = false;
326 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
329 void
330 AudioTimeAxisView::show_existing_automation ()
332 no_redraw = true;
334 RouteTimeAxisView::show_existing_automation ();
336 no_redraw = false;
338 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
341 void
342 AudioTimeAxisView::hide_all_automation ()
344 no_redraw = true;
346 RouteTimeAxisView::hide_all_automation();
348 no_redraw = false;
349 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
352 void
353 AudioTimeAxisView::show_all_xfades ()
355 AudioStreamView* asv = audio_view();
357 if (asv) {
358 asv->show_all_xfades ();
362 void
363 AudioTimeAxisView::hide_all_xfades ()
365 AudioStreamView* asv = audio_view();
367 if (asv) {
368 asv->hide_all_xfades ();
372 void
373 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
375 AudioStreamView* asv = audio_view();
376 AudioRegionView* rv;
378 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
379 asv->hide_xfades_involving (*rv);
383 void
384 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
386 AudioStreamView* asv = audio_view();
387 AudioRegionView* rv;
389 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
390 asv->reveal_xfades_involving (*rv);
394 void
395 AudioTimeAxisView::route_active_changed ()
397 RouteTimeAxisView::route_active_changed ();
398 update_control_names ();
403 * Set up the names of the controls so that they are coloured
404 * correctly depending on whether this route is inactive or
405 * selected.
408 void
409 AudioTimeAxisView::update_control_names ()
411 if (is_audio_track()) {
412 if (_route->active()) {
413 controls_base_selected_name = "AudioTrackControlsBaseSelected";
414 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
415 } else {
416 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
417 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
419 } else {
420 if (_route->active()) {
421 controls_base_selected_name = "BusControlsBaseSelected";
422 controls_base_unselected_name = "BusControlsBaseUnselected";
423 } else {
424 controls_base_selected_name = "BusControlsBaseInactiveSelected";
425 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
429 if (get_selected()) {
430 controls_ebox.set_name (controls_base_selected_name);
431 } else {
432 controls_ebox.set_name (controls_base_unselected_name);
436 void
437 AudioTimeAxisView::build_automation_action_menu ()
439 using namespace Menu_Helpers;
441 RouteTimeAxisView::build_automation_action_menu ();
443 MenuList& automation_items = automation_action_menu->items ();
445 automation_items.push_back (CheckMenuElem (_("Fader"), sigc::mem_fun (*this, &AudioTimeAxisView::update_gain_track_visibility)));
446 gain_automation_item = dynamic_cast<CheckMenuItem*> (&automation_items.back ());
447 gain_automation_item->set_active (gain_track->marked_for_display ());
449 _main_automation_menu_map[Evoral::Parameter(GainAutomation)] = gain_automation_item;
451 automation_items.push_back (CheckMenuElem (_("Pan"), sigc::mem_fun (*this, &AudioTimeAxisView::update_pan_track_visibility)));
452 pan_automation_item = dynamic_cast<CheckMenuItem*> (&automation_items.back ());
453 pan_automation_item->set_active (pan_tracks.front()->marked_for_display ());
455 set<Evoral::Parameter> const & params = _route->panner()->what_can_be_automated ();
456 for (set<Evoral::Parameter>::iterator p = params.begin(); p != params.end(); ++p) {
457 _main_automation_menu_map[*p] = pan_automation_item;
461 void
462 AudioTimeAxisView::add_processor_to_subplugin_menu (boost::weak_ptr<Processor> wp)
464 /* we use this override to veto the Amp processor from the plugin menu,
465 as its automation lane can be accessed using the special "Fader" menu
466 option
469 boost::shared_ptr<Processor> p = wp.lock ();
470 if (!p) {
471 return;
474 if (boost::dynamic_pointer_cast<Amp> (p) == 0) {
475 RouteTimeAxisView::add_processor_to_subplugin_menu (wp);