fix import/embed with "sequence files" option
[ardour2.git] / gtk2_ardour / audio_time_axis.cc
blob9f4f709cfc21846fd1337b66df1dc912a61873d0
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/stop_signal.h>
37 #include <gtkmm2ext/bindable_button.h>
38 #include <gtkmm2ext/utils.h>
40 #include <ardour/audioplaylist.h>
41 #include <ardour/audio_diskstream.h>
42 #include <ardour/insert.h>
43 #include <ardour/location.h>
44 #include <ardour/panner.h>
45 #include <ardour/playlist.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_gain_line.h"
54 #include "automation_pan_line.h"
55 #include "canvas_impl.h"
56 #include "crossfade_view.h"
57 #include "enums.h"
58 #include "gain_automation_time_axis.h"
59 #include "keyboard.h"
60 #include "pan_automation_time_axis.h"
61 #include "playlist_selector.h"
62 #include "prompter.h"
63 #include "public_editor.h"
64 #include "audio_region_view.h"
65 #include "simplerect.h"
66 #include "audio_streamview.h"
67 #include "utils.h"
69 #include <ardour/audio_track.h>
71 #include "i18n.h"
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");
86 gain_track = 0;
87 pan_track = 0;
88 waveform_item = 0;
89 pan_automation_item = 0;
90 gain_automation_item = 0;
92 _view = new AudioStreamView (*this);
94 add_gain_automation_child ();
95 add_pan_automation_child ();
97 ignore_toggle = false;
99 if (is_audio_track())
100 controls_ebox.set_name ("AudioTimeAxisViewControlsBaseUnselected");
101 else // bus
102 controls_ebox.set_name ("AudioBusControlsBaseUnselected");
104 ensure_xml_node ();
106 set_state (*xml_node);
108 _route->panner().Changed.connect (mem_fun(*this, &AudioTimeAxisView::update_pans));
110 update_control_names ();
112 if (is_audio_track()) {
114 /* ask for notifications of any new RegionViews */
115 _view->RegionViewAdded.connect (mem_fun(*this, &AudioTimeAxisView::region_view_added));
117 if (!editor.have_idled()) {
118 /* first idle will do what we need */
119 } else {
120 first_idle ();
123 } else {
124 post_construct ();
128 AudioTimeAxisView::~AudioTimeAxisView ()
132 void
133 AudioTimeAxisView::first_idle ()
135 _view->attach ();
136 post_construct ();
139 AudioStreamView*
140 AudioTimeAxisView::audio_view()
142 return dynamic_cast<AudioStreamView*>(_view);
145 guint32
146 AudioTimeAxisView::show_at (double y, int& nth, Gtk::VBox *parent)
148 ensure_xml_node ();
149 xml_node->add_property ("shown_editor", "yes");
151 return TimeAxisView::show_at (y, nth, parent);
154 void
155 AudioTimeAxisView::hide ()
157 ensure_xml_node ();
158 xml_node->add_property ("shown_editor", "no");
160 TimeAxisView::hide ();
164 AudioTimeAxisView::set_state (const XMLNode& node)
166 const XMLProperty *prop;
167 int ret;
169 if ((ret = TimeAxisView::set_state (node)) != 0) {
170 return ret;
173 /* if the TimeAxisView had marked this not for display,
174 then do not allow this to override it.
177 if ((prop = node.property ("marked_for_display")) == 0) {
178 if ((prop = node.property ("shown_editor")) != 0) {
179 if (prop->value() == "no") {
180 _marked_for_display = false;
181 } else {
182 _marked_for_display = true;
184 } else {
185 _marked_for_display = true;
189 XMLNodeList nlist = node.children();
190 XMLNodeConstIterator niter;
191 XMLNode *child_node;
194 show_gain_automation = false;
195 show_pan_automation = false;
197 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
198 child_node = *niter;
200 if (child_node->name() == "gain") {
201 XMLProperty *prop=child_node->property ("shown");
203 if (prop != 0) {
204 if (string_is_affirmative (prop->value())) {
205 show_gain_automation = true;
208 continue;
211 if (child_node->name() == "pan") {
212 XMLProperty *prop=child_node->property ("shown");
214 if (prop != 0) {
215 if (string_is_affirmative (prop->value())) {
216 show_pan_automation = true;
219 continue;
223 return 0;
226 void
227 AudioTimeAxisView::build_automation_action_menu ()
229 using namespace Menu_Helpers;
231 RouteTimeAxisView::build_automation_action_menu ();
233 MenuList& automation_items = automation_action_menu->items();
235 automation_items.push_back (SeparatorElem());
237 automation_items.push_back (CheckMenuElem (_("Fader"),
238 mem_fun(*this, &AudioTimeAxisView::toggle_gain_track)));
239 gain_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
240 gain_automation_item->set_active(show_gain_automation);
242 automation_items.push_back (CheckMenuElem (_("Pan"),
243 mem_fun(*this, &AudioTimeAxisView::toggle_pan_track)));
244 pan_automation_item = static_cast<CheckMenuItem*> (&automation_items.back());
245 pan_automation_item->set_active(show_pan_automation);
249 void
250 AudioTimeAxisView::append_extra_display_menu_items ()
252 using namespace Menu_Helpers;
254 MenuList& items = display_menu->items();
256 // crossfade stuff
257 if (!Profile->get_sae()) {
258 items.push_back (MenuElem (_("Hide all crossfades"), mem_fun(*this, &AudioTimeAxisView::hide_all_xfades)));
259 items.push_back (MenuElem (_("Show all crossfades"), mem_fun(*this, &AudioTimeAxisView::show_all_xfades)));
262 // waveform menu
263 Menu *waveform_menu = manage(new Menu);
264 MenuList& waveform_items = waveform_menu->items();
265 waveform_menu->set_name ("ArdourContextMenu");
267 RadioMenuItem::Group group2;
269 waveform_items.push_back (RadioMenuElem (group2, _("Linear"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LinearWaveform)));
270 linearscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
272 waveform_items.push_back (RadioMenuElem (group2, _("Logarithmic"), bind (mem_fun(*this, &AudioTimeAxisView::set_waveform_scale), LogWaveform)));
273 logscale_item = static_cast<RadioMenuItem *> (&waveform_items.back());
275 // setting initial item state
276 AudioStreamView* asv = audio_view();
277 if (asv) {
278 ignore_toggle = true;
279 if (asv->get_waveform_scale() == LogWaveform)
280 logscale_item->set_active(true);
281 else linearscale_item->set_active(true);
282 ignore_toggle = false;
285 items.push_back (MenuElem (_("Waveform"), *waveform_menu));
288 void
289 AudioTimeAxisView::toggle_waveforms ()
291 AudioStreamView* asv = audio_view();
292 assert(asv);
294 if (asv && waveform_item && !ignore_toggle) {
295 asv->set_show_waveforms (waveform_item->get_active());
299 void
300 AudioTimeAxisView::set_show_waveforms (bool yn)
302 AudioStreamView* asv = audio_view();
303 assert(asv);
305 if (waveform_item) {
306 waveform_item->set_active (yn);
307 } else {
308 asv->set_show_waveforms (yn);
312 void
313 AudioTimeAxisView::set_show_waveforms_recording (bool yn)
315 AudioStreamView* asv = audio_view();
317 if (asv) {
318 asv->set_show_waveforms_recording (yn);
322 void
323 AudioTimeAxisView::set_show_waveforms_rectified (bool yn)
325 AudioStreamView* asv = audio_view();
327 if (asv) {
328 asv->set_waveform_shape ( yn ? Rectified : Traditional );
332 void
333 AudioTimeAxisView::set_waveform_shape (WaveformShape shape)
335 AudioStreamView* asv = audio_view();
337 if (asv && !ignore_toggle) {
338 asv->set_waveform_shape (shape);
341 map_frozen ();
344 void
345 AudioTimeAxisView::set_waveform_scale (WaveformScale scale)
347 AudioStreamView* asv = audio_view();
349 if (asv && !ignore_toggle) {
350 asv->set_waveform_scale (scale);
353 map_frozen ();
356 void
357 AudioTimeAxisView::add_gain_automation_child ()
359 XMLProperty* prop;
360 AutomationLine* line;
362 gain_track = new GainAutomationTimeAxisView (_session,
363 _route,
364 editor,
365 *this,
366 parent_canvas,
367 _("Fader"),
368 _route->gain_automation_curve());
370 line = new AutomationGainLine ("automation gain",
371 _session,
372 *gain_track,
373 *gain_track->canvas_display,
374 _route->gain_automation_curve());
376 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
379 gain_track->add_line (*line);
381 add_child (gain_track);
383 gain_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::gain_hidden));
385 bool hideit = true;
387 XMLNode* node;
389 if ((node = gain_track->get_state_node()) != 0) {
390 if ((prop = node->property ("shown")) != 0) {
391 if (string_is_affirmative (prop->value())) {
392 hideit = false;
397 if (hideit) {
398 gain_track->hide ();
402 void
403 AudioTimeAxisView::add_pan_automation_child ()
405 XMLProperty* prop;
407 pan_track = new PanAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, _("Pan"));
409 update_pans ();
411 add_child (pan_track);
413 pan_track->Hiding.connect (mem_fun(*this, &AudioTimeAxisView::pan_hidden));
415 ensure_xml_node ();
416 bool hideit = true;
418 XMLNode* node;
420 if ((node = pan_track->get_state_node()) != 0) {
421 if ((prop = node->property ("shown")) != 0) {
422 if (string_is_affirmative (prop->value())) {
423 hideit = false;
428 if (hideit) {
429 pan_track->hide ();
433 void
434 AudioTimeAxisView::update_pans ()
436 Panner::iterator p;
438 pan_track->clear_lines ();
440 /* we don't draw lines for "greater than stereo" panning.
443 if (_route->n_outputs() > 2) {
444 return;
447 for (p = _route->panner().begin(); p != _route->panner().end(); ++p) {
449 AutomationLine* line;
451 line = new AutomationPanLine ("automation pan", _session, *pan_track,
452 *pan_track->canvas_display,
453 (*p)->automation());
455 if (p == _route->panner().begin()) {
456 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
457 } else {
458 line->set_line_color (ARDOUR_UI::config()->canvasvar_AutomationLine.get());
461 pan_track->add_line (*line);
465 void
466 AudioTimeAxisView::toggle_gain_track ()
468 bool showit = gain_automation_item->get_active();
470 if (showit != gain_track->marked_for_display()) {
471 if (showit) {
472 gain_track->set_marked_for_display (true);
473 gain_track->canvas_display->show();
474 gain_track->canvas_background->show();
475 gain_track->get_state_node()->add_property ("shown", X_("yes"));
476 } else {
477 gain_track->set_marked_for_display (false);
478 gain_track->hide ();
479 gain_track->get_state_node()->add_property ("shown", X_("no"));
482 /* now trigger a redisplay */
484 if (!no_redraw) {
485 _route->gui_changed (X_("visible_tracks"), (void *) 0); /* EMIT_SIGNAL */
490 void
491 AudioTimeAxisView::gain_hidden ()
493 gain_track->get_state_node()->add_property (X_("shown"), X_("no"));
495 if (gain_automation_item && !_hidden) {
496 gain_automation_item->set_active (false);
499 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
502 void
503 AudioTimeAxisView::toggle_pan_track ()
505 bool showit = pan_automation_item->get_active();
507 if (showit != pan_track->marked_for_display()) {
508 if (showit) {
509 pan_track->set_marked_for_display (true);
510 pan_track->canvas_display->show();
511 pan_track->canvas_background->show();
512 pan_track->get_state_node()->add_property ("shown", X_("yes"));
513 } else {
514 pan_track->set_marked_for_display (false);
515 pan_track->hide ();
516 pan_track->get_state_node()->add_property ("shown", X_("no"));
519 /* now trigger a redisplay */
521 if (!no_redraw) {
522 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
527 void
528 AudioTimeAxisView::pan_hidden ()
530 pan_track->get_state_node()->add_property ("shown", "no");
532 if (pan_automation_item && !_hidden) {
533 pan_automation_item->set_active (false);
536 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
539 void
540 AudioTimeAxisView::show_all_automation ()
542 no_redraw = true;
544 pan_automation_item->set_active (true);
545 gain_automation_item->set_active (true);
547 RouteTimeAxisView::show_all_automation ();
549 no_redraw = false;
551 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
554 void
555 AudioTimeAxisView::show_existing_automation ()
557 no_redraw = true;
559 pan_automation_item->set_active (true);
560 gain_automation_item->set_active (true);
562 RouteTimeAxisView::show_existing_automation ();
564 no_redraw = false;
566 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
569 void
570 AudioTimeAxisView::hide_all_automation ()
572 no_redraw = true;
574 pan_automation_item->set_active (false);
575 gain_automation_item->set_active (false);
577 RouteTimeAxisView::hide_all_automation();
579 no_redraw = false;
580 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
583 void
584 AudioTimeAxisView::show_all_xfades ()
586 AudioStreamView* asv = audio_view();
588 if (asv) {
589 asv->show_all_xfades ();
593 void
594 AudioTimeAxisView::hide_all_xfades ()
596 AudioStreamView* asv = audio_view();
598 if (asv) {
599 asv->hide_all_xfades ();
603 void
604 AudioTimeAxisView::hide_dependent_views (TimeAxisViewItem& tavi)
606 AudioStreamView* asv = audio_view();
607 AudioRegionView* rv;
609 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
610 asv->hide_xfades_involving (*rv);
614 void
615 AudioTimeAxisView::reveal_dependent_views (TimeAxisViewItem& tavi)
617 AudioStreamView* asv = audio_view();
618 AudioRegionView* rv;
620 if (asv && (rv = dynamic_cast<AudioRegionView*>(&tavi)) != 0) {
621 asv->reveal_xfades_involving (*rv);
625 void
626 AudioTimeAxisView::route_active_changed ()
628 RouteTimeAxisView::route_active_changed ();
629 update_control_names ();
634 * Set up the names of the controls so that they are coloured
635 * correctly depending on whether this route is inactive or
636 * selected.
639 void
640 AudioTimeAxisView::update_control_names ()
642 if (is_audio_track()) {
643 if (_route->active()) {
644 controls_base_selected_name = "AudioTrackControlsBaseSelected";
645 controls_base_unselected_name = "AudioTrackControlsBaseUnselected";
646 } else {
647 controls_base_selected_name = "AudioTrackControlsBaseInactiveSelected";
648 controls_base_unselected_name = "AudioTrackControlsBaseInactiveUnselected";
650 } else {
651 if (_route->active()) {
652 controls_base_selected_name = "BusControlsBaseSelected";
653 controls_base_unselected_name = "BusControlsBaseUnselected";
654 } else {
655 controls_base_selected_name = "BusControlsBaseInactiveSelected";
656 controls_base_unselected_name = "BusControlsBaseInactiveUnselected";
660 if (get_selected()) {
661 controls_ebox.set_name (controls_base_selected_name);
662 } else {
663 controls_ebox.set_name (controls_base_unselected_name);
667 XMLNode*
668 AudioTimeAxisView::get_child_xml_node (const string & childname)
670 return RouteUI::get_child_xml_node (childname);