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/stop_signal.h>
37 #include <gtkmm2ext/bindable_button.h>
38 #include <gtkmm2ext/utils.h>
40 #include "ardour/amp.h"
41 #include "ardour/audio_diskstream.h"
42 #include "ardour/audioplaylist.h"
43 #include "ardour/event_type_map.h"
44 #include "ardour/location.h"
45 #include "ardour/panner.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"
59 #include "gui_thread.h"
60 #include "automation_time_axis.h"
62 #include "playlist_selector.h"
64 #include "public_editor.h"
65 #include "audio_region_view.h"
66 #include "simplerect.h"
67 #include "audio_streamview.h"
70 #include "ardour/audio_track.h"
75 using namespace ARDOUR;
78 using namespace Editing;
80 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session* sess, boost::shared_ptr<Route> rt, Canvas& canvas)
82 , RouteTimeAxisView(ed, sess, rt, canvas)
84 // Make sure things are sane...
85 assert(!is_track() || is_audio_track());
87 subplugin_menu.set_name ("ArdourContextMenu");
89 _view = new AudioStreamView (*this);
91 ignore_toggle = false;
93 mute_button->set_active (false);
94 solo_button->set_active (false);
96 if (is_audio_track()) {
97 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
99 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
104 set_state (*xml_node, Stateful::loading_state_version);
106 /* if set_state above didn't create a gain automation child, we need to make one */
107 if (automation_track (GainAutomation) == 0) {
108 create_automation_child (GainAutomation, false);
111 if (_route->panner()) {
112 _route->panner()->Changed.connect (*this, boost::bind (&AudioTimeAxisView::ensure_pan_views, this, false), gui_context());
115 /* map current state of the route */
117 processors_changed (RouteProcessorChange ());
118 reset_processor_automation_curves ();
119 ensure_pan_views (false);
120 update_control_names ();
122 if (is_audio_track()) {
124 /* ask for notifications of any new RegionViews */
125 _view->RegionViewAdded.connect (sigc::mem_fun(*this, &AudioTimeAxisView::region_view_added));
127 if (!_editor.have_idled()) {
128 /* first idle will do what we need */
138 AudioTimeAxisView::~AudioTimeAxisView ()
143 AudioTimeAxisView::first_idle ()
150 AudioTimeAxisView::audio_view()
152 return dynamic_cast<AudioStreamView*>(_view);
156 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
159 xml_node->add_property ("shown-editor", "yes");
161 return TimeAxisView::show_at (y, nth, parent);
165 AudioTimeAxisView::hide ()
168 xml_node->add_property ("shown-editor", "no");
170 TimeAxisView::hide ();
175 AudioTimeAxisView::append_extra_display_menu_items ()
177 using namespace Menu_Helpers;
179 MenuList& items = display_menu->items();
182 if (!Profile->get_sae()) {
183 items.push_back (MenuElem (_("Hide All Crossfades"), sigc::mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
184 items.push_back (MenuElem (_("Show All Crossfades"), sigc::mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
189 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
191 AudioStreamView* asv = audio_view();
194 asv->set_show_waveforms_recording (yn);
199 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
201 if (param.type() == GainAutomation) {
203 boost::shared_ptr<AutomationControl> c = _route->gain_control();
205 error << "Route has no gain automation, unable to add automation track view." << endmsg;
209 boost::shared_ptr<AutomationTimeAxisView>
210 gain_track(new AutomationTimeAxisView (_session,
211 _route, _route->amp(), c,
216 _route->amp()->describe_parameter(param)));
218 add_automation_child(Evoral::Parameter(GainAutomation), gain_track, show);
220 } else if (param.type() == PanAutomation) {
223 ensure_pan_views (show);
226 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
230 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
231 * panners that we have.
233 * @param show true to show any new views that we create, otherwise false.
236 AudioTimeAxisView::ensure_pan_views (bool show)
238 if (!_route->panner()) {
242 const set<Evoral::Parameter>& params = _route->panner()->what_can_be_automated();
243 set<Evoral::Parameter>::iterator p;
245 for (p = params.begin(); p != params.end(); ++p) {
246 boost::shared_ptr<ARDOUR::AutomationControl> pan_control
247 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
248 _route->panner()->control(*p));
250 if (pan_control->parameter().type() == NullAutomation) {
251 error << "Pan control has NULL automation type!" << endmsg;
255 if (automation_child (pan_control->parameter ()).get () == 0) {
257 /* we don't already have an AutomationTimeAxisView for this parameter */
259 std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
261 boost::shared_ptr<AutomationTimeAxisView> pan_track (
262 new AutomationTimeAxisView (_session,
263 _route, _route->panner(), pan_control,
270 add_automation_child (*p, pan_track, show);
276 AudioTimeAxisView::toggle_gain_track ()
278 bool showit = gain_automation_item->get_active();
280 if (showit != gain_track->marked_for_display()) {
282 gain_track->set_marked_for_display (true);
283 gain_track->canvas_display->show();
284 gain_track->canvas_background->show();
285 gain_track->get_state_node()->add_property ("shown", X_("yes"));
287 gain_track->set_marked_for_display (false);
289 gain_track->get_state_node()->add_property ("shown", X_("no"));
292 /* now trigger a redisplay */
295 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
301 AudioTimeAxisView::gain_hidden ()
303 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
305 if (gain_automation_item && !_hidden) {
306 gain_automation_item->set_active (false);
309 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
313 AudioTimeAxisView::toggle_pan_track ()
315 bool showit = pan_automation_item->get_active();
317 if (showit != pan_track->marked_for_display()) {
319 pan_track->set_marked_for_display (true);
320 pan_track->canvas_display->show();
321 pan_track->canvas_background->show();
322 pan_track->get_state_node()->add_property ("shown", X_("yes"));
324 pan_track->set_marked_for_display (false);
326 pan_track->get_state_node()->add_property ("shown", X_("no"));
329 /* now trigger a redisplay */
335 AudioTimeAxisView::show_all_automation ()
339 RouteTimeAxisView::show_all_automation ();
343 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
347 AudioTimeAxisView::show_existing_automation ()
351 RouteTimeAxisView::show_existing_automation ();
355 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
359 AudioTimeAxisView::hide_all_automation ()
363 RouteTimeAxisView::hide_all_automation();
366 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
370 AudioTimeAxisView::show_all_xfades ()
372 AudioStreamView* asv = audio_view();
375 asv->show_all_xfades ();
380 AudioTimeAxisView::hide_all_xfades ()
382 AudioStreamView* asv = audio_view();
385 asv->hide_all_xfades ();
390 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
392 AudioStreamView* asv = audio_view();
395 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
396 asv->hide_xfades_involving (*rv);
401 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
403 AudioStreamView* asv = audio_view();
406 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
407 asv->reveal_xfades_involving (*rv);
412 AudioTimeAxisView::route_active_changed ()
414 RouteTimeAxisView::route_active_changed ();
415 update_control_names ();
420 * Set up the names of the controls so that they are coloured
421 * correctly depending on whether this route is inactive or
426 AudioTimeAxisView::update_control_names ()
428 if (is_audio_track()) {
429 if (_route->active()) {
430 controls_base_selected_name = "AudioTrackControlsBaseSelected";
431 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
433 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
434 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
437 if (_route->active()) {
438 controls_base_selected_name = "BusControlsBaseSelected";
439 controls_base_unselected_name = "BusControlsBaseUnselected";
441 controls_base_selected_name = "BusControlsBaseInactiveSelected";
442 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
446 if (get_selected()) {
447 controls_ebox.set_name (controls_base_selected_name);
449 controls_ebox.set_name (controls_base_unselected_name);