the missing flush call for plugins
[ardour2.git] / gtk2_ardour / route_time_axis.cc
blob3127f712030e45b51b1ad74065c398da03d70800
1 /*
2 Copyright (C) 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.
19 #include <cstdlib>
20 #include <cmath>
21 #include <cassert>
23 #include <algorithm>
24 #include <string>
25 #include <vector>
27 #include <sigc++/bind.h>
29 #include <pbd/error.h>
30 #include <pbd/stl_delete.h>
31 #include <pbd/whitespace.h>
32 #include <pbd/memento_command.h>
34 #include <gtkmm/menu.h>
35 #include <gtkmm/menuitem.h>
36 #include <gtkmm2ext/gtk_ui.h>
37 #include <gtkmm2ext/selector.h>
38 #include <gtkmm2ext/stop_signal.h>
39 #include <gtkmm2ext/bindable_button.h>
40 #include <gtkmm2ext/utils.h>
42 #include <ardour/playlist.h>
43 #include <ardour/audioplaylist.h>
44 #include <ardour/diskstream.h>
45 #include <ardour/insert.h>
46 #include <ardour/ladspa_plugin.h>
47 #include <ardour/location.h>
48 #include <ardour/panner.h>
49 #include <ardour/playlist.h>
50 #include <ardour/session.h>
51 #include <ardour/session_playlist.h>
52 #include <ardour/utils.h>
53 #include <ardour/profile.h>
55 #include "ardour_ui.h"
56 #include "route_time_axis.h"
57 #include "automation_time_axis.h"
58 #include "redirect_automation_time_axis.h"
59 #include "redirect_automation_line.h"
60 #include "canvas_impl.h"
61 #include "crossfade_view.h"
62 #include "enums.h"
63 #include "gui_thread.h"
64 #include "keyboard.h"
65 #include "playlist_selector.h"
66 #include "point_selection.h"
67 #include "prompter.h"
68 #include "public_editor.h"
69 #include "region_view.h"
70 #include "rgb_macros.h"
71 #include "selection.h"
72 #include "simplerect.h"
73 #include "streamview.h"
74 #include "utils.h"
76 #include <ardour/track.h>
78 #include "i18n.h"
80 using namespace ARDOUR;
81 using namespace PBD;
82 using namespace Gtkmm2ext;
83 using namespace Gtk;
84 using namespace Editing;
85 using namespace std;
87 Glib::RefPtr<Gdk::Pixbuf> RouteTimeAxisView::slider;
89 void
90 RouteTimeAxisView::setup_slider_pix ()
92 if ((slider = ::get_icon ("fader_belt_h")) == 0) {
93 throw failed_constructor ();
97 RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
98 : AxisView(sess),
99 RouteUI(rt, sess, _("m"), _("s"), _("r")), // mute, solo, and record
100 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
101 parent_canvas (canvas),
102 button_table (3, 3),
103 edit_group_button (_("g")), // group
104 playlist_button (_("p")),
105 size_button (_("h")), // height
106 automation_button (_("a")),
107 visual_button (_("v")),
108 gm (sess, slider, true)
110 gm.set_io (rt);
111 gm.get_level_meter().set_no_show_all();
112 gm.get_level_meter().setup_meters(50);
114 _has_state = true;
115 playlist_menu = 0;
116 playlist_action_menu = 0;
117 automation_action_menu = 0;
118 _view = 0;
119 timestretch_rect = 0;
120 no_redraw = false;
121 destructive_track_mode_item = 0;
122 normal_track_mode_item = 0;
124 ignore_toggle = false;
126 edit_group_button.set_name ("TrackGroupButton");
127 playlist_button.set_name ("TrackPlaylistButton");
128 automation_button.set_name ("TrackAutomationButton");
129 size_button.set_name ("TrackSizeButton");
130 visual_button.set_name ("TrackVisualButton");
131 hide_button.set_name ("TrackRemoveButton");
133 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
134 playlist_button.unset_flags (Gtk::CAN_FOCUS);
135 automation_button.unset_flags (Gtk::CAN_FOCUS);
136 size_button.unset_flags (Gtk::CAN_FOCUS);
137 visual_button.unset_flags (Gtk::CAN_FOCUS);
138 hide_button.unset_flags (Gtk::CAN_FOCUS);
140 hide_button.add (*(manage (new Image (::get_icon("hide")))));
141 hide_button.show_all ();
143 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
144 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
145 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
146 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
147 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
148 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
150 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
151 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
152 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
153 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
155 if (is_track()) {
157 /* use icon */
159 rec_enable_button->remove ();
160 switch (track()->mode()) {
161 case ARDOUR::Normal:
162 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
163 break;
164 case ARDOUR::Destructive:
165 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
166 break;
168 rec_enable_button->show_all ();
170 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press), false);
171 rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
172 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
173 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
175 rec_enable_button->set_sensitive (_session.writable());
178 controls_hbox.pack_start(gm.get_level_meter(), false, false);
179 _route->meter_change.connect (mem_fun(*this, &RouteTimeAxisView::meter_changed));
180 _route->input_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
181 _route->output_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
183 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
184 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
186 controls_table.attach (edit_group_button, 7, 8, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
187 controls_table.attach (gm.get_gain_slider(), 0, 5, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0);
189 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
190 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
191 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
192 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
193 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
194 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
195 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
196 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
198 label_view ();
200 if (0) {
202 /* old school - when we used to put an extra row of buttons in place */
204 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
205 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
206 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
207 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
209 } else {
211 controls_table.attach (automation_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
214 if (is_track() && track()->mode() == ARDOUR::Normal) {
215 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
218 y_position = -1;
220 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
221 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
223 if (is_track()) {
225 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
226 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
227 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
228 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
230 /* pick up the correct freeze state */
231 map_frozen ();
235 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
236 ColorsChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
238 gm.get_gain_slider().signal_scroll_event().connect(mem_fun(*this, &RouteTimeAxisView::controls_ebox_scroll), false);
239 gm.get_gain_slider().set_name ("TrackGainFader");
242 RouteTimeAxisView::~RouteTimeAxisView ()
244 GoingAway (); /* EMIT_SIGNAL */
246 vector_delete (&redirect_automation_curves);
248 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
249 delete *i;
252 if (playlist_menu) {
253 delete playlist_menu;
254 playlist_menu = 0;
257 if (playlist_action_menu) {
258 delete playlist_action_menu;
259 playlist_action_menu = 0;
262 if (_view) {
263 delete _view;
264 _view = 0;
268 void
269 RouteTimeAxisView::post_construct ()
271 /* map current state of the route */
273 update_diskstream_display ();
274 subplugin_menu.items().clear ();
275 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
276 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
277 reset_redirect_automation_curves ();
280 void
281 RouteTimeAxisView::set_playlist (boost::shared_ptr<Playlist> newplaylist)
283 boost::shared_ptr<Playlist> pl = playlist();
284 assert(pl);
286 modified_connection.disconnect ();
287 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
290 void
291 RouteTimeAxisView::playlist_modified ()
295 gint
296 RouteTimeAxisView::edit_click (GdkEventButton *ev)
298 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
299 _route->set_edit_group (0, this);
300 return FALSE;
303 using namespace Menu_Helpers;
305 MenuList& items = edit_group_menu.items ();
306 RadioMenuItem::Group group;
308 items.clear ();
309 items.push_back (RadioMenuElem (group, _("No group"),
310 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
312 if (_route->edit_group() == 0) {
313 static_cast<RadioMenuItem*>(&items.back())->set_active ();
316 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
317 edit_group_menu.popup (ev->button, ev->time);
319 return FALSE;
322 void
323 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
325 using namespace Menu_Helpers;
327 MenuList &items = edit_group_menu.items();
329 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
330 if (_route->edit_group() == eg) {
331 static_cast<RadioMenuItem*>(&items.back())->set_active ();
335 void
336 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
338 _route->set_edit_group (eg, this);
341 void
342 RouteTimeAxisView::playlist_changed ()
344 label_view ();
346 if (is_track()) {
347 set_playlist (get_diskstream()->playlist());
351 void
352 RouteTimeAxisView::label_view ()
354 string x = _route->name();
356 if (x != name_entry.get_text()) {
357 name_entry.set_text (x);
360 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
363 void
364 RouteTimeAxisView::route_name_changed (void *src)
366 editor.route_name_changed (this);
367 label_view ();
370 void
371 RouteTimeAxisView::take_name_changed (void *src)
374 if (src != this) {
375 label_view ();
379 void
380 RouteTimeAxisView::playlist_click ()
382 // always build a new action menu
384 if (playlist_action_menu != 0) {
385 delete playlist_action_menu;
388 playlist_action_menu = new Menu;
389 playlist_action_menu->set_name ("ArdourContextMenu");
391 build_playlist_menu (playlist_action_menu);
393 conditionally_add_to_selection ();
394 playlist_action_menu->popup (1, gtk_get_current_event_time());
397 void
398 RouteTimeAxisView::automation_click ()
400 conditionally_add_to_selection ();
401 if (!automation_action_menu)
402 build_automation_action_menu ();
403 automation_action_menu->popup (1, gtk_get_current_event_time());
406 void
407 RouteTimeAxisView::build_automation_action_menu ()
409 using namespace Menu_Helpers;
411 automation_action_menu = manage (new Menu);
412 MenuList& automation_items = automation_action_menu->items();
413 automation_action_menu->set_name ("ArdourContextMenu");
415 automation_items.push_back (MenuElem (_("Show all automation"),
416 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
418 automation_items.push_back (MenuElem (_("Show existing automation"),
419 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
421 automation_items.push_back (MenuElem (_("Hide all automation"),
422 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
424 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
427 void
428 RouteTimeAxisView::build_display_menu ()
430 using namespace Menu_Helpers;
432 /* get the size menu ready */
434 build_size_menu ();
436 /* prepare it */
438 TimeAxisView::build_display_menu ();
440 /* now fill it with our stuff */
442 MenuList& items = display_menu->items();
443 display_menu->set_name ("ArdourContextMenu");
445 items.push_back (MenuElem (_("Height"), *size_menu));
446 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
448 items.push_back (SeparatorElem());
450 if (!Profile->get_sae()) {
451 build_remote_control_menu ();
452 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
453 /* rebuild this every time */
454 build_automation_action_menu ();
455 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
456 items.push_back (SeparatorElem());
459 // Hook for derived classes to add type specific stuff
460 append_extra_display_menu_items ();
461 items.push_back (SeparatorElem());
463 if (is_track()) {
465 Menu* alignment_menu = manage (new Menu);
466 MenuList& alignment_items = alignment_menu->items();
467 alignment_menu->set_name ("ArdourContextMenu");
469 RadioMenuItem::Group align_group;
471 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
472 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
473 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
474 if (get_diskstream()->alignment_style() == ExistingMaterial)
475 align_existing_item->set_active();
477 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
478 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
479 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
480 if (get_diskstream()->alignment_style() == CaptureTime)
481 align_capture_item->set_active();
483 if (!Profile->get_sae()) {
484 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
485 get_diskstream()->AlignmentStyleChanged.connect (mem_fun(*this, &RouteTimeAxisView::align_style_changed));
487 RadioMenuItem::Group mode_group;
488 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
489 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
490 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
491 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
492 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
493 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
495 switch (track()->mode()) {
496 case ARDOUR::Destructive:
497 destructive_track_mode_item->set_active ();
498 break;
499 case ARDOUR::Normal:
500 normal_track_mode_item->set_active ();
501 break;
504 items.push_back (SeparatorElem());
508 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
509 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
510 route_active_menu_item->set_active (_route->active());
512 items.push_back (SeparatorElem());
513 items.push_back (MenuElem (_("Hide"), mem_fun(*this, &RouteTimeAxisView::hide_click)));
514 if (!Profile->get_sae()) {
515 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
516 } else {
517 items.push_front (SeparatorElem());
518 items.push_front (MenuElem (_("Delete"), mem_fun(*this, &RouteUI::remove_this_route)));
522 static bool __reset_item (RadioMenuItem* item)
524 item->set_active ();
525 return false;
528 void
529 RouteTimeAxisView::set_track_mode (TrackMode mode)
531 RadioMenuItem* item;
532 RadioMenuItem* other_item;
534 switch (mode) {
535 case ARDOUR::Normal:
536 item = normal_track_mode_item;
537 other_item = destructive_track_mode_item;
538 break;
539 case ARDOUR::Destructive:
540 item = destructive_track_mode_item;
541 other_item = normal_track_mode_item;
542 break;
543 default:
544 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
545 /*NOTREACHED*/
546 return;
549 if (item && other_item && item->get_active () && track()->mode() != mode) {
550 _set_track_mode (track(), mode, other_item);
554 void
555 RouteTimeAxisView::_set_track_mode (boost::shared_ptr<Track> track, TrackMode mode, RadioMenuItem* reset_item)
557 bool needs_bounce;
559 if (!track->can_use_mode (mode, needs_bounce)) {
561 if (!needs_bounce) {
562 /* cannot be done */
563 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
564 return;
565 } else {
566 cerr << "would bounce this one\n";
567 return;
571 track->set_mode (mode);
573 rec_enable_button->remove ();
574 switch (mode) {
575 case ARDOUR::Normal:
576 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
577 break;
578 case ARDOUR::Destructive:
579 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
580 break;
582 rec_enable_button->show_all ();
586 void
587 RouteTimeAxisView::track_mode_changed ()
589 RadioMenuItem* item;
591 switch (track()->mode()) {
592 case ARDOUR::Normal:
593 item = normal_track_mode_item;
594 break;
595 case ARDOUR::Destructive:
596 item = destructive_track_mode_item;
597 break;
598 default:
599 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
600 /*NOTREACHED*/
601 return;
604 item->set_active ();
607 void
608 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
610 double x1;
611 double x2;
612 double y2;
614 TimeAxisView::show_timestretch (start, end);
616 hide_timestretch ();
618 #if 0
619 if (ts.empty()) {
620 return;
624 /* check that the time selection was made in our route, or our edit group.
625 remember that edit_group() == 0 implies the route is *not* in a edit group.
628 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
629 /* this doesn't apply to us */
630 return;
633 /* ignore it if our edit group is not active */
635 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
636 return;
638 #endif
640 if (timestretch_rect == 0) {
641 timestretch_rect = new SimpleRect (*canvas_display);
642 timestretch_rect->property_x1() = 0.0;
643 timestretch_rect->property_y1() = 0.0;
644 timestretch_rect->property_x2() = 0.0;
645 timestretch_rect->property_y2() = 0.0;
646 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
647 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
650 timestretch_rect->show ();
651 timestretch_rect->raise_to_top ();
653 x1 = start / editor.get_current_zoom();
654 x2 = (end - 1) / editor.get_current_zoom();
655 y2 = current_height() - 2;
657 timestretch_rect->property_x1() = x1;
658 timestretch_rect->property_y1() = 1.0;
659 timestretch_rect->property_x2() = x2;
660 timestretch_rect->property_y2() = y2;
663 void
664 RouteTimeAxisView::hide_timestretch ()
666 TimeAxisView::hide_timestretch ();
668 if (timestretch_rect) {
669 timestretch_rect->hide ();
673 void
674 RouteTimeAxisView::show_selection (TimeSelection& ts)
677 #if 0
678 /* ignore it if our edit group is not active or if the selection was started
679 in some other track or edit group (remember that edit_group() == 0 means
680 that the track is not in an edit group).
683 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
684 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
685 hide_selection ();
686 return;
688 #endif
690 TimeAxisView::show_selection (ts);
693 void
694 RouteTimeAxisView::set_height (uint32_t h)
696 int gmlen = h - 5;
697 bool height_changed = (height == 0) || (h != height);
698 gm.get_level_meter().setup_meters (gmlen);
700 TimeAxisView::set_height (h);
702 ensure_xml_node ();
704 if (_view) {
705 _view->set_height ((double) current_height());
708 char buf[32];
709 snprintf (buf, sizeof (buf), "%u", height);
710 xml_node->add_property ("height", buf);
712 if (height >= hNormal) {
713 reset_meter();
714 show_name_entry ();
715 hide_name_label ();
717 gm.get_gain_slider().show();
718 mute_button->show();
719 solo_button->show();
720 if (rec_enable_button)
721 rec_enable_button->show();
723 edit_group_button.show();
724 hide_button.show();
725 visual_button.show();
726 size_button.show();
727 automation_button.show();
729 if (is_track() && track()->mode() == ARDOUR::Normal) {
730 playlist_button.show();
733 } else if (height >= hSmaller) {
735 reset_meter();
736 show_name_entry ();
737 hide_name_label ();
739 gm.get_gain_slider().hide();
740 mute_button->show();
741 solo_button->show();
742 if (rec_enable_button)
743 rec_enable_button->show();
745 edit_group_button.hide ();
746 hide_button.hide ();
747 visual_button.hide ();
748 size_button.hide ();
749 automation_button.hide ();
751 if (is_track() && track()->mode() == ARDOUR::Normal) {
752 playlist_button.hide ();
755 } else {
757 hide_meter ();
759 /* don't allow name_entry to be hidden while
760 it has focus, otherwise the GUI becomes unusable.
763 if (name_entry.has_focus()) {
764 if (name_entry.get_text() != _route->name()) {
765 name_entry_changed ();
767 controls_ebox.grab_focus ();
770 hide_name_entry ();
771 show_name_label ();
773 gm.get_gain_slider().hide();
774 mute_button->hide();
775 solo_button->hide();
776 if (rec_enable_button)
777 rec_enable_button->hide();
779 edit_group_button.hide ();
780 hide_button.hide ();
781 visual_button.hide ();
782 size_button.hide ();
783 automation_button.hide ();
784 playlist_button.hide ();
785 name_label.set_text (_route->name());
788 if (height_changed) {
789 /* only emit the signal if the height really changed */
790 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
794 void
795 RouteTimeAxisView::select_track_color ()
797 if (RouteUI::choose_color ()) {
799 if (_view) {
800 _view->apply_color (_color, StreamView::RegionColor);
805 void
806 RouteTimeAxisView::reset_samples_per_unit ()
808 set_samples_per_unit (editor.get_current_zoom());
811 void
812 RouteTimeAxisView::set_samples_per_unit (double spu)
814 double speed = 1.0;
816 if (get_diskstream() != 0) {
817 speed = get_diskstream()->speed();
820 if (_view) {
821 _view->set_samples_per_unit (spu * speed);
824 TimeAxisView::set_samples_per_unit (spu * speed);
827 void
828 RouteTimeAxisView::align_style_changed ()
830 switch (get_diskstream()->alignment_style()) {
831 case ExistingMaterial:
832 if (!align_existing_item->get_active()) {
833 align_existing_item->set_active();
835 break;
836 case CaptureTime:
837 if (!align_capture_item->get_active()) {
838 align_capture_item->set_active();
840 break;
844 void
845 RouteTimeAxisView::set_align_style (AlignStyle style)
847 RadioMenuItem* item;
849 switch (style) {
850 case ExistingMaterial:
851 item = align_existing_item;
852 break;
853 case CaptureTime:
854 item = align_capture_item;
855 break;
856 default:
857 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
858 /*NOTREACHED*/
859 return;
862 if (item->get_active()) {
863 get_diskstream()->set_align_style (style);
867 void
868 RouteTimeAxisView::rename_current_playlist ()
870 ArdourPrompter prompter (true);
871 string name;
873 boost::shared_ptr<Diskstream> ds = get_diskstream();
874 if (!ds || ds->destructive())
875 return;
877 boost::shared_ptr<Playlist> pl = ds->playlist();
878 if (!pl)
879 return;
881 prompter.set_prompt (_("Name for playlist"));
882 prompter.set_initial_text (pl->name());
883 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
884 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
886 switch (prompter.run ()) {
887 case Gtk::RESPONSE_ACCEPT:
888 prompter.get_result (name);
889 if (name.length()) {
890 pl->set_name (name);
892 break;
894 default:
895 break;
899 std::string
900 RouteTimeAxisView::resolve_new_group_playlist_name(std::string &basename, vector<boost::shared_ptr<Playlist> > const & playlists)
902 std::string ret(basename);
904 std::string group_string = "."+edit_group()->name()+".";
906 // iterate through all playlists
907 int maxnumber = 0;
908 for (vector<boost::shared_ptr<Playlist> >::const_iterator i = playlists.begin(); i != playlists.end(); ++i) {
909 std::string tmp = (*i)->name();
911 std::string::size_type idx = tmp.find(group_string);
912 // find those which belong to this group
913 if (idx != string::npos) {
914 tmp = tmp.substr(idx + group_string.length());
916 // and find the largest current number
917 int x = atoi(tmp.c_str());
918 if (x > maxnumber) {
919 maxnumber = x;
924 maxnumber++;
926 char buf[32];
927 snprintf (buf, sizeof(buf), "%d", maxnumber);
929 ret = this->name()+"."+edit_group()->name()+"."+buf;
931 return ret;
934 void
935 RouteTimeAxisView::use_copy_playlist (bool prompt, vector<boost::shared_ptr<Playlist> > const & playlists_before_op)
937 string name;
939 boost::shared_ptr<Diskstream> ds = get_diskstream();
940 if (!ds || ds->destructive())
941 return;
943 boost::shared_ptr<const Playlist> pl = ds->playlist();
944 if (!pl)
945 return;
947 name = pl->name();
949 if (edit_group() && edit_group()->is_active()) {
950 name = resolve_new_group_playlist_name(name, playlists_before_op);
953 while (_session.playlist_by_name(name)) {
954 name = Playlist::bump_name (name, _session);
957 // TODO: The prompter "new" button should be de-activated if the user
958 // specifies a playlist name which already exists in the session.
960 if (prompt) {
962 ArdourPrompter prompter (true);
964 prompter.set_prompt (_("Name for Playlist"));
965 prompter.set_initial_text (name);
966 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
967 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
968 prompter.show_all ();
970 switch (prompter.run ()) {
971 case Gtk::RESPONSE_ACCEPT:
972 prompter.get_result (name);
973 break;
975 default:
976 return;
980 if (name.length()) {
981 ds->use_copy_playlist ();
982 ds->playlist()->set_name (name);
986 void
987 RouteTimeAxisView::use_new_playlist (bool prompt, vector<boost::shared_ptr<Playlist> > const & playlists_before_op)
989 string name;
991 boost::shared_ptr<Diskstream> ds = get_diskstream();
992 if (!ds || ds->destructive())
993 return;
995 boost::shared_ptr<const Playlist> pl = ds->playlist();
996 if (!pl)
997 return;
999 name = pl->name();
1001 if (edit_group() && edit_group()->is_active()) {
1002 name = resolve_new_group_playlist_name(name,playlists_before_op);
1005 while (_session.playlist_by_name(name)) {
1006 name = Playlist::bump_name (name, _session);
1010 if (prompt) {
1012 ArdourPrompter prompter (true);
1014 prompter.set_prompt (_("Name for Playlist"));
1015 prompter.set_initial_text (name);
1016 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
1017 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
1019 switch (prompter.run ()) {
1020 case Gtk::RESPONSE_ACCEPT:
1021 prompter.get_result (name);
1022 break;
1024 default:
1025 return;
1029 if (name.length()) {
1030 ds->use_new_playlist ();
1031 ds->playlist()->set_name (name);
1035 void
1036 RouteTimeAxisView::clear_playlist ()
1038 boost::shared_ptr<Diskstream> ds = get_diskstream();
1039 if (!ds || ds->destructive())
1040 return;
1042 boost::shared_ptr<Playlist> pl = ds->playlist();
1043 if (!pl)
1044 return;
1046 editor.clear_playlist (pl);
1049 void
1050 RouteTimeAxisView::speed_changed ()
1052 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
1055 void
1056 RouteTimeAxisView::diskstream_changed ()
1058 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
1061 void
1062 RouteTimeAxisView::update_diskstream_display ()
1064 if (!get_diskstream()) // bus
1065 return;
1067 set_playlist (get_diskstream()->playlist());
1068 map_frozen ();
1071 void
1072 RouteTimeAxisView::selection_click (GdkEventButton* ev)
1074 if (Keyboard::modifier_state_equals (ev->state, (Keyboard::TertiaryModifier|Keyboard::PrimaryModifier))) {
1076 /* special case: select/deselect all tracks */
1077 if (editor.get_selection().selected (this)) {
1078 editor.get_selection().clear_tracks ();
1079 } else {
1080 editor.select_all_tracks ();
1083 return;
1086 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1088 switch (Keyboard::selection_type (ev->state)) {
1089 case Selection::Toggle:
1090 editor.get_selection().toggle (*tracks);
1091 break;
1093 case Selection::Set:
1094 editor.get_selection().set (*tracks);
1095 break;
1097 case Selection::Extend:
1098 if (tracks->size() > 1) {
1099 /* add each one, do not "extend" */
1100 editor.get_selection().add (*tracks);
1101 } else {
1102 /* extend to the single track */
1103 editor.extend_selection_to_track (*tracks->front());
1105 break;
1107 case Selection::Add:
1108 editor.get_selection().add (*tracks);
1109 break;
1112 delete tracks;
1115 void
1116 RouteTimeAxisView::set_selected_points (PointSelection& points)
1118 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1119 (*i)->set_selected_points (points);
1123 void
1124 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1126 if (_view) {
1127 _view->set_selected_regionviews (regions);
1131 void
1132 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1134 double speed = 1.0;
1136 if (get_diskstream() != 0) {
1137 speed = get_diskstream()->speed();
1140 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1141 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1143 if ((_view && ((top < 0.0 && bot < 0.0))) || touched (top, bot)) {
1144 _view->get_selectables (start_adjusted, end_adjusted, results);
1147 /* pick up visible automation tracks */
1149 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1150 if (!(*i)->hidden()) {
1151 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1156 void
1157 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1159 if (_view) {
1160 _view->get_inverted_selectables (sel, results);
1163 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1164 if (!(*i)->hidden()) {
1165 (*i)->get_inverted_selectables (sel, results);
1169 return;
1172 RouteGroup*
1173 RouteTimeAxisView::edit_group() const
1175 return _route->edit_group();
1178 string
1179 RouteTimeAxisView::name() const
1181 return _route->name();
1184 boost::shared_ptr<Playlist>
1185 RouteTimeAxisView::playlist () const
1187 boost::shared_ptr<Diskstream> ds;
1189 if ((ds = get_diskstream()) != 0) {
1190 return ds->playlist();
1191 } else {
1192 return boost::shared_ptr<Playlist> ();
1196 void
1197 RouteTimeAxisView::name_entry_changed ()
1199 string x;
1201 x = name_entry.get_text ();
1203 if (x == _route->name()) {
1204 return;
1207 strip_whitespace_edges(x);
1209 if (x.length() == 0) {
1210 name_entry.set_text (_route->name());
1211 return;
1214 if (_session.route_name_unique (x)) {
1215 _route->set_name (x, this);
1216 } else {
1217 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1218 name_entry.set_text (_route->name());
1222 void
1223 RouteTimeAxisView::visual_click ()
1225 popup_display_menu (0);
1228 void
1229 RouteTimeAxisView::hide_click ()
1231 // LAME fix for hide_button refresh fix
1232 hide_button.set_sensitive(false);
1234 editor.hide_track_in_display (*this);
1236 hide_button.set_sensitive(true);
1239 boost::shared_ptr<Region>
1240 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1242 boost::shared_ptr<Diskstream> stream;
1243 boost::shared_ptr<Playlist> playlist;
1245 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1246 return playlist->find_next_region (pos, point, dir);
1249 return boost::shared_ptr<Region> ();
1252 nframes64_t
1253 RouteTimeAxisView::find_next_region_boundary (nframes64_t pos, int32_t dir)
1255 boost::shared_ptr<Diskstream> stream;
1256 boost::shared_ptr<Playlist> playlist;
1258 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1259 return playlist->find_next_region_boundary (pos, dir);
1262 return -1;
1265 bool
1266 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1268 boost::shared_ptr<Playlist> what_we_got;
1269 boost::shared_ptr<Diskstream> ds = get_diskstream();
1270 boost::shared_ptr<Playlist> playlist;
1271 bool ret = false;
1273 if (ds == 0) {
1274 /* route is a bus, not a track */
1275 return false;
1278 playlist = ds->playlist();
1280 TimeSelection time (selection.time);
1281 float speed = ds->speed();
1282 if (speed != 1.0f) {
1283 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1284 (*i).start = session_frame_to_track_frame((*i).start, speed);
1285 (*i).end = session_frame_to_track_frame((*i).end, speed);
1289 XMLNode &before = playlist->get_state();
1290 switch (op) {
1291 case Cut:
1292 if ((what_we_got = playlist->cut (time)) != 0) {
1293 editor.get_cut_buffer().add (what_we_got);
1294 _session.add_command( new MementoCommand<Playlist>(*playlist.get(), &before, &playlist->get_state()));
1295 ret = true;
1297 break;
1298 case Copy:
1299 if ((what_we_got = playlist->copy (time)) != 0) {
1300 editor.get_cut_buffer().add (what_we_got);
1302 break;
1304 case Clear:
1305 if ((what_we_got = playlist->cut (time)) != 0) {
1306 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1307 what_we_got->release ();
1308 ret = true;
1310 break;
1313 return ret;
1316 bool
1317 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1319 if (!is_track()) {
1320 return false;
1323 boost::shared_ptr<Playlist> playlist = get_diskstream()->playlist();
1324 PlaylistSelection::iterator p;
1326 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1328 if (p == selection.playlists.end()) {
1329 return false;
1332 if (get_diskstream()->speed() != 1.0f)
1333 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1335 XMLNode &before = playlist->get_state();
1336 playlist->paste (*p, pos, times);
1337 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1339 return true;
1343 list<TimeAxisView*>
1344 RouteTimeAxisView::get_child_list()
1347 list<TimeAxisView*>redirect_children;
1349 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1350 if (!(*i)->hidden()) {
1351 redirect_children.push_back(*i);
1354 return redirect_children;
1358 struct PlaylistSorter {
1359 bool operator() (boost::shared_ptr<Playlist> a, boost::shared_ptr<Playlist> b) const {
1360 return a->sort_id() < b->sort_id();
1364 void
1365 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1367 using namespace Menu_Helpers;
1369 if (!menu || !is_track()) {
1370 return;
1373 MenuList& playlist_items = menu->items();
1374 menu->set_name ("ArdourContextMenu");
1375 playlist_items.clear();
1377 vector<boost::shared_ptr<Playlist> > playlists, playlists_ds;
1378 boost::shared_ptr<Diskstream> ds = get_diskstream();
1379 RadioMenuItem::Group playlist_group;
1381 _session.get_playlists (playlists);
1383 /* find the playlists for this diskstream */
1384 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1385 if (((*i)->get_orig_diskstream_id() == ds->id()) || (ds->playlist()->id() == (*i)->id())) {
1386 playlists_ds.push_back(*i);
1390 /* sort the playlists */
1391 PlaylistSorter cmp;
1392 sort(playlists_ds.begin(), playlists_ds.end(), cmp);
1394 /* add the playlists to the menu */
1395 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists_ds.begin(); i != playlists_ds.end(); ++i) {
1396 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name()));
1397 RadioMenuItem *item = static_cast<RadioMenuItem*>(&playlist_items.back());
1399 item->signal_toggled().connect(bind (mem_fun (*this, &RouteTimeAxisView::use_playlist), item, boost::weak_ptr<Playlist> (*i)));
1401 if (ds->playlist()->id() == (*i)->id()) {
1402 item->set_active();
1406 playlist_items.push_back (SeparatorElem());
1407 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1408 playlist_items.push_back (SeparatorElem());
1410 if (!edit_group() || !edit_group()->is_active()) {
1411 playlist_items.push_back (MenuElem (_("New"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
1412 playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
1413 } else {
1414 // Use a label which tells the user what is happening
1415 playlist_items.push_back (MenuElem (_("New Take"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
1416 playlist_items.push_back (MenuElem (_("Copy Take"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
1419 playlist_items.push_back (SeparatorElem());
1420 playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this)));
1421 playlist_items.push_back (SeparatorElem());
1422 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1425 void
1426 RouteTimeAxisView::use_playlist (RadioMenuItem *item, boost::weak_ptr<Playlist> wpl)
1428 assert (is_track());
1430 // exit if we were triggered by deactivating the old playlist
1431 if (!item->get_active()) {
1432 return;
1435 boost::shared_ptr<Playlist> pl (wpl.lock());
1437 if (!pl) {
1438 return;
1441 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
1443 if (apl) {
1444 if (get_diskstream()->playlist() == apl) {
1445 // exit when use_playlist is called by the creation of the playlist menu
1446 // or the playlist choice is unchanged
1447 return;
1450 get_diskstream()->use_playlist (apl);
1452 if (edit_group() && edit_group()->is_active()) {
1453 //PBD::stacktrace(cerr, 20);
1454 std::string group_string = "."+edit_group()->name()+".";
1456 std::string take_name = apl->name();
1457 std::string::size_type idx = take_name.find(group_string);
1459 if (idx == std::string::npos)
1460 return;
1462 take_name = take_name.substr(idx + group_string.length()); // find the bit containing the take number / name
1464 for (list<Route*>::const_iterator i = edit_group()->route_list().begin(); i != edit_group()->route_list().end(); ++i) {
1465 if ( (*i) == this->route().get()) {
1466 continue;
1469 std::string playlist_name = (*i)->name()+group_string+take_name;
1471 Track *track = dynamic_cast<Track *>(*i);
1472 if (!track) {
1473 continue;
1476 boost::shared_ptr<Playlist> ipl = session().playlist_by_name(playlist_name);
1477 if (!ipl) {
1478 // No playlist for this track for this take yet, make it
1479 track->diskstream()->use_new_playlist();
1480 track->diskstream()->playlist()->set_name(playlist_name);
1481 } else {
1482 track->diskstream()->use_playlist(ipl);
1485 //(*i)->get_dis
1491 void
1492 RouteTimeAxisView::show_playlist_selector ()
1494 editor.playlist_selector().show_for (this);
1497 void
1498 RouteTimeAxisView::map_frozen ()
1500 if (!is_track()) {
1501 return;
1504 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1506 switch (track()->freeze_state()) {
1507 case Track::Frozen:
1508 playlist_button.set_sensitive (false);
1509 rec_enable_button->set_sensitive (false);
1510 break;
1511 default:
1512 playlist_button.set_sensitive (true);
1513 rec_enable_button->set_sensitive (true);
1514 break;
1518 void
1519 RouteTimeAxisView::color_handler ()
1521 if (timestretch_rect) {
1522 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
1525 if (timestretch_rect) {
1526 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
1529 reset_meter();
1532 void
1533 RouteTimeAxisView::show_all_automation ()
1535 no_redraw = true;
1537 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1538 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1539 if ((*ii)->view == 0) {
1540 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1543 (*ii)->menu_item->set_active (true);
1547 no_redraw = false;
1549 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1552 void
1553 RouteTimeAxisView::show_existing_automation ()
1555 no_redraw = true;
1557 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1558 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1559 if ((*ii)->view != 0) {
1560 (*ii)->menu_item->set_active (true);
1565 no_redraw = false;
1567 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1570 void
1571 RouteTimeAxisView::hide_all_automation ()
1573 no_redraw = true;
1575 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1576 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1577 (*ii)->menu_item->set_active (false);
1581 no_redraw = false;
1582 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1586 void
1587 RouteTimeAxisView::region_view_added (RegionView* rv)
1589 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1590 AutomationTimeAxisView* atv;
1592 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1593 rv->add_ghost (*atv);
1598 void
1599 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1601 rv->add_ghost (*atv);
1604 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1606 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1607 delete *i;
1612 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1614 parent.remove_ran (this);
1616 if (view) {
1617 delete view;
1621 void
1622 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1624 if (ran->view) {
1625 remove_child (ran->view);
1629 RouteTimeAxisView::RedirectAutomationNode*
1630 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1632 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1634 if ((*i)->redirect == redirect) {
1636 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1637 if ((*ii)->what == what) {
1638 return *ii;
1644 return 0;
1647 // FIXME: duplicated in midi_time_axis.cc
1648 static string
1649 legalize_for_xml_node (string str)
1651 string::size_type pos;
1652 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=:";
1653 string legal;
1655 legal = str;
1656 pos = 0;
1658 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1659 legal.replace (pos, 1, "_");
1660 pos += 1;
1663 return legal;
1667 void
1668 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1670 RedirectAutomationLine* ral;
1671 string name;
1672 RedirectAutomationNode* ran;
1674 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1675 fatal << _("programming error: ")
1676 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1677 redirect->name(), what)
1678 << endmsg;
1679 /*NOTREACHED*/
1680 return;
1683 if (ran->view) {
1684 return;
1687 name = redirect->describe_parameter (what);
1689 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1691 char state_name[256];
1692 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1694 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1696 ral = new RedirectAutomationLine (name,
1697 *redirect, what, _session, *ran->view,
1698 *ran->view->canvas_display, redirect->automation_list (what));
1700 ral->set_line_color (ARDOUR_UI::config()->canvasvar_RedirectAutomationLine.get());
1701 ral->queue_reset ();
1703 ran->view->add_line (*ral);
1705 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1707 if (!ran->view->marked_for_display()) {
1708 ran->view->hide ();
1709 } else {
1710 ran->menu_item->set_active (true);
1713 add_child (ran->view);
1715 if (_view) {
1716 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1719 redirect->mark_automation_visible (what, true);
1722 void
1723 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1725 if (!_hidden) {
1726 ran->menu_item->set_active (false);
1729 r->mark_automation_visible (ran->what, false);
1731 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1734 void
1735 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1737 set<uint32_t> s;
1738 RedirectAutomationLine *ral;
1740 redirect->what_has_visible_automation (s);
1742 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1744 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1745 ral->queue_reset ();
1746 } else {
1747 add_redirect_automation_curve (redirect, (*i));
1752 void
1753 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1755 using namespace Menu_Helpers;
1756 RedirectAutomationInfo *rai;
1757 list<RedirectAutomationInfo*>::iterator x;
1759 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1760 std::set<uint32_t> has_visible_automation;
1762 r->what_has_visible_automation(has_visible_automation);
1764 if (automatable.empty()) {
1765 return;
1768 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1769 if ((*x)->redirect == r) {
1770 break;
1774 if (x == redirect_automation.end()) {
1776 rai = new RedirectAutomationInfo (r);
1777 redirect_automation.push_back (rai);
1779 } else {
1781 rai = *x;
1785 /* any older menu was deleted at the top of redirects_changed()
1786 when we cleared the subplugin menu.
1789 rai->menu = manage (new Menu);
1790 MenuList& items = rai->menu->items();
1791 rai->menu->set_name ("ArdourContextMenu");
1793 items.clear ();
1795 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1797 RedirectAutomationNode* ran;
1798 CheckMenuItem* mitem;
1800 string name = r->describe_parameter (*i);
1802 items.push_back (CheckMenuElem (name));
1803 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1805 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1806 mitem->set_active(true);
1809 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1811 /* new item */
1813 ran = new RedirectAutomationNode (*i, mitem, *this);
1815 rai->lines.push_back (ran);
1817 } else {
1819 ran->menu_item = mitem;
1823 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1826 /* add the menu for this redirect, because the subplugin
1827 menu is always cleared at the top of redirects_changed().
1828 this is the result of some poor design in gtkmm and/or
1829 GTK+.
1832 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1833 rai->valid = true;
1836 void
1837 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1838 RouteTimeAxisView::RedirectAutomationNode* ran)
1840 bool showit = ran->menu_item->get_active();
1841 bool redraw = false;
1843 if (ran->view == 0 && showit) {
1844 add_redirect_automation_curve (rai->redirect, ran->what);
1845 redraw = true;
1848 if (showit != ran->view->marked_for_display()) {
1850 if (showit) {
1851 ran->menu_item->set_active(true);
1852 ran->view->set_marked_for_display (true);
1853 ran->view->canvas_display->show();
1854 ran->view->canvas_background->show();
1855 } else {
1856 ran->menu_item->set_active(false);
1857 rai->redirect->mark_automation_visible (ran->what, true);
1858 ran->view->set_marked_for_display (false);
1859 ran->view->hide ();
1862 redraw = true;
1866 if (redraw && !no_redraw) {
1868 /* now trigger a redisplay */
1870 _route->gui_changed ("visible_tracks", (void *) 0); /* EMIT_SIGNAL */
1875 void
1876 RouteTimeAxisView::redirects_changed (void *src)
1878 using namespace Menu_Helpers;
1880 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1881 (*i)->valid = false;
1884 subplugin_menu.items().clear ();
1886 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1887 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1889 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1891 list<RedirectAutomationInfo*>::iterator tmp;
1893 tmp = i;
1894 ++tmp;
1896 if (!(*i)->valid) {
1898 delete *i;
1899 redirect_automation.erase (i);
1903 i = tmp;
1906 /* change in visibility was possible */
1908 _route->gui_changed ("visible_tracks", this);
1911 RedirectAutomationLine *
1912 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1914 RedirectAutomationNode* ran;
1916 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1917 if (ran->view) {
1918 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1922 return 0;
1925 void
1926 RouteTimeAxisView::reset_redirect_automation_curves ()
1928 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {
1929 (*i)->reset();
1933 void
1934 RouteTimeAxisView::update_rec_display ()
1936 RouteUI::update_rec_display ();
1937 name_entry.set_sensitive (!_route->record_enabled());
1940 void
1941 RouteTimeAxisView::fast_update ()
1943 gm.get_level_meter().update_meters ();
1946 void
1947 RouteTimeAxisView::hide_meter ()
1949 clear_meter ();
1950 gm.get_level_meter().hide_meters ();
1953 void
1954 RouteTimeAxisView::show_meter ()
1956 reset_meter ();
1959 void
1960 RouteTimeAxisView::reset_meter ()
1962 if (Config->get_show_track_meters()) {
1963 gm.get_level_meter().setup_meters (height-5);
1964 } else {
1965 hide_meter ();
1969 void
1970 RouteTimeAxisView::clear_meter ()
1972 gm.get_level_meter().clear_meters ();
1975 void
1976 RouteTimeAxisView::meter_changed (void *src)
1978 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::meter_changed), src));
1979 reset_meter();
1982 void
1983 RouteTimeAxisView::io_changed (IOChange change, void *src)
1985 reset_meter ();