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 "automation_time_axis.h"
61 #include "playlist_selector.h"
63 #include "public_editor.h"
64 #include "audio_region_view.h"
65 #include "simplerect.h"
66 #include "audio_streamview.h"
69 #include "ardour/audio_track.h"
74 using namespace ARDOUR;
77 using namespace Editing;
79 AudioTimeAxisView::AudioTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
81 , RouteTimeAxisView(ed, sess, rt, canvas)
83 // Make sure things are sane...
84 assert(!is_track() || is_audio_track());
86 subplugin_menu.set_name ("ArdourContextMenu");
88 _view = new AudioStreamView (*this);
90 ignore_toggle = false;
92 mute_button->set_active (false);
93 solo_button->set_active (false);
95 if (is_audio_track()) {
96 controls_ebox.set_name ("AudioTrackControlsBaseUnselected");
98 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
103 set_state (*xml_node);
105 /* if set_state above didn't create a gain automation child, we need to make one */
106 if (automation_track (GainAutomation) == 0) {
107 create_automation_child (GainAutomation, false);
110 if (_route->panner()) {
111 _route->panner()->Changed.connect (bind (
112 mem_fun(*this, &AudioTimeAxisView::ensure_pan_views),
116 /* map current state of the route */
118 processors_changed ();
119 reset_processor_automation_curves ();
120 ensure_pan_views (false);
121 update_control_names ();
123 if (is_audio_track()) {
125 /* ask for notifications of any new RegionViews */
126 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
128 if (!_editor.have_idled()) {
129 /* first idle will do what we need */
139 AudioTimeAxisView::~AudioTimeAxisView ()
144 AudioTimeAxisView::first_idle ()
151 AudioTimeAxisView::audio_view()
153 return dynamic_cast<AudioStreamView*>(_view);
157 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
160 xml_node->add_property ("shown-editor", "yes");
162 return TimeAxisView::show_at (y, nth, parent);
166 AudioTimeAxisView::hide ()
169 xml_node->add_property ("shown-editor", "no");
171 TimeAxisView::hide ();
176 AudioTimeAxisView::append_extra_display_menu_items ()
178 using namespace Menu_Helpers;
180 MenuList& items = display_menu->items();
183 if (!Profile->get_sae()) {
184 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
185 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
190 AudioTimeAxisView::build_mode_menu()
192 using namespace Menu_Helpers;
194 Menu* mode_menu = manage (new Menu);
195 MenuList& items = mode_menu->items();
196 mode_menu->set_name ("ArdourContextMenu");
198 RadioMenuItem::Group mode_group;
200 items.push_back (RadioMenuElem (mode_group, _("Normal"),
201 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Normal)));
202 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
204 items.push_back (RadioMenuElem (mode_group, _("Non Overlapping"),
205 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::NonLayered)));
206 non_layered_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
208 items.push_back (RadioMenuElem (mode_group, _("Tape"),
209 bind (mem_fun (*this, &AudioTimeAxisView::set_track_mode), ARDOUR::Destructive)));
210 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
212 switch (track()->mode()) {
213 case ARDOUR::Destructive:
214 destructive_track_mode_item->set_active ();
216 case ARDOUR::NonLayered:
217 non_layered_track_mode_item->set_active ();
220 normal_track_mode_item->set_active ();
228 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
230 AudioStreamView* asv = audio_view();
233 asv->set_show_waveforms_recording (yn);
238 AudioTimeAxisView::create_automation_child (const Evoral::Parameter& param, bool show)
240 if (param.type() == GainAutomation) {
242 boost::shared_ptr<AutomationControl> c = _route->gain_control();
244 error << "Route has no gain automation, unable to add automation track view." << endmsg;
248 boost::shared_ptr<AutomationTimeAxisView>
249 gain_track(new AutomationTimeAxisView (_session,
250 _route, _route->amp(), c,
255 _route->amp()->describe_parameter(param)));
257 add_automation_child(Evoral::Parameter(GainAutomation), gain_track, show);
259 } else if (param.type() == PanAutomation) {
262 ensure_pan_views (show);
265 error << "AudioTimeAxisView: unknown automation child " << EventTypeMap::instance().to_symbol(param) << endmsg;
269 /** Ensure that we have the appropriate AutomationTimeAxisViews for the
270 * panners that we have.
272 * @param show true to show any new views that we create, otherwise false.
275 AudioTimeAxisView::ensure_pan_views (bool show)
277 if (!_route->panner()) {
281 const set<Evoral::Parameter>& params = _route->panner()->what_can_be_automated();
282 set<Evoral::Parameter>::iterator p;
284 for (p = params.begin(); p != params.end(); ++p) {
285 boost::shared_ptr<ARDOUR::AutomationControl> pan_control
286 = boost::dynamic_pointer_cast<ARDOUR::AutomationControl>(
287 _route->panner()->data().control(*p));
289 if (pan_control->parameter().type() == NullAutomation) {
290 error << "Pan control has NULL automation type!" << endmsg;
294 if (automation_child (pan_control->parameter ()).get () == 0) {
296 /* we don't already have an AutomationTimeAxisView for this parameter */
298 std::string const name = _route->panner()->describe_parameter (pan_control->parameter ());
300 boost::shared_ptr<AutomationTimeAxisView> pan_track (
301 new AutomationTimeAxisView (_session,
302 _route, _route->panner(), pan_control,
309 add_automation_child (*p, pan_track, show);
315 AudioTimeAxisView::toggle_gain_track ()
317 bool showit = gain_automation_item->get_active();
319 if (showit != gain_track->marked_for_display()) {
321 gain_track->set_marked_for_display (true);
322 gain_track->canvas_display->show();
323 gain_track->canvas_background->show();
324 gain_track->get_state_node()->add_property ("shown", X_("yes"));
326 gain_track->set_marked_for_display (false);
328 gain_track->get_state_node()->add_property ("shown", X_("no"));
331 /* now trigger a redisplay */
334 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
340 AudioTimeAxisView::gain_hidden ()
342 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
344 if (gain_automation_item && !_hidden) {
345 gain_automation_item->set_active (false);
348 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
352 AudioTimeAxisView::toggle_pan_track ()
354 bool showit = pan_automation_item->get_active();
356 if (showit != pan_track->marked_for_display()) {
358 pan_track->set_marked_for_display (true);
359 pan_track->canvas_display->show();
360 pan_track->canvas_background->show();
361 pan_track->get_state_node()->add_property ("shown", X_("yes"));
363 pan_track->set_marked_for_display (false);
365 pan_track->get_state_node()->add_property ("shown", X_("no"));
368 /* now trigger a redisplay */
374 AudioTimeAxisView::show_all_automation ()
378 RouteTimeAxisView::show_all_automation ();
382 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
386 AudioTimeAxisView::show_existing_automation ()
390 RouteTimeAxisView::show_existing_automation ();
394 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
398 AudioTimeAxisView::hide_all_automation ()
402 RouteTimeAxisView::hide_all_automation();
405 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
409 AudioTimeAxisView::show_all_xfades ()
411 AudioStreamView* asv = audio_view();
414 asv->show_all_xfades ();
419 AudioTimeAxisView::hide_all_xfades ()
421 AudioStreamView* asv = audio_view();
424 asv->hide_all_xfades ();
429 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
431 AudioStreamView* asv = audio_view();
434 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
435 asv->hide_xfades_involving (*rv);
440 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
442 AudioStreamView* asv = audio_view();
445 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
446 asv->reveal_xfades_involving (*rv);
451 AudioTimeAxisView::route_active_changed ()
453 RouteTimeAxisView::route_active_changed ();
454 update_control_names ();
459 * Set up the names of the controls so that they are coloured
460 * correctly depending on whether this route is inactive or
465 AudioTimeAxisView::update_control_names ()
467 if (is_audio_track()) {
468 if (_route->active()) {
469 controls_base_selected_name = "AudioTrackControlsBaseSelected";
470 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
472 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
473 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
476 if (_route->active()) {
477 controls_base_selected_name = "BusControlsBaseSelected";
478 controls_base_unselected_name = "BusControlsBaseUnselected";
480 controls_base_selected_name = "BusControlsBaseInactiveSelected";
481 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
485 if (get_selected()) {
486 controls_ebox.set_name (controls_base_selected_name);
488 controls_ebox.set_name (controls_base_unselected_name);