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.
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>
54 #include "ardour_ui.h"
55 #include "route_time_axis.h"
56 #include "automation_time_axis.h"
57 #include "redirect_automation_time_axis.h"
58 #include "redirect_automation_line.h"
59 #include "canvas_impl.h"
60 #include "crossfade_view.h"
62 #include "gui_thread.h"
64 #include "playlist_selector.h"
65 #include "point_selection.h"
67 #include "public_editor.h"
68 #include "region_view.h"
69 #include "rgb_macros.h"
70 #include "selection.h"
71 #include "simplerect.h"
72 #include "streamview.h"
75 #include <ardour/track.h>
79 using namespace ARDOUR;
82 using namespace Editing;
85 RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
87 RouteUI(rt, sess, _("m"), _("s"), _("r")), // mute, solo, and record
88 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
89 parent_canvas (canvas),
91 edit_group_button (_("g")), // group
92 playlist_button (_("p")),
93 size_button (_("h")), // height
94 automation_button (_("a")),
95 visual_button (_("v"))
100 playlist_action_menu = 0;
101 automation_action_menu = 0;
103 timestretch_rect = 0;
106 ignore_toggle = false;
108 edit_group_button.set_name ("TrackGroupButton");
109 playlist_button.set_name ("TrackPlaylistButton");
110 automation_button.set_name ("TrackAutomationButton");
111 size_button.set_name ("TrackSizeButton");
112 visual_button.set_name ("TrackVisualButton");
113 hide_button.set_name ("TrackRemoveButton");
115 hide_button.add (*(manage (new Image (::get_icon("hide")))));
116 hide_button.show_all ();
118 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
119 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
120 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
121 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
122 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
123 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
125 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
126 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release));
127 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
128 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release));
134 rec_enable_button->remove ();
135 switch (track()->mode()) {
137 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
139 case ARDOUR::Destructive:
140 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
143 rec_enable_button->show_all ();
145 rec_enable_button->set_name ("RecordEnableButton");
146 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
147 rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
148 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
149 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
152 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
153 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
155 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
157 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
158 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
159 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
160 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
161 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
162 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
163 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
164 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
168 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
169 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
170 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
171 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
173 if (is_track() && track()->mode() == ARDOUR::Normal) {
174 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
177 /* remove focus from the buttons */
181 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
182 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
186 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
187 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
188 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
189 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
191 /* pick up the correct freeze state */
196 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
197 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
200 RouteTimeAxisView::~RouteTimeAxisView ()
202 GoingAway (); /* EMIT_SIGNAL */
204 vector_delete (&redirect_automation_curves);
206 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
211 delete playlist_menu;
215 if (playlist_action_menu) {
216 delete playlist_action_menu;
217 playlist_action_menu = 0;
227 RouteTimeAxisView::post_construct ()
229 /* map current state of the route */
231 update_diskstream_display ();
232 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
233 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
234 reset_redirect_automation_curves ();
238 RouteTimeAxisView::set_playlist (boost::shared_ptr<Playlist> newplaylist)
240 boost::shared_ptr<Playlist> pl = playlist();
243 modified_connection.disconnect ();
244 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
248 RouteTimeAxisView::playlist_modified ()
253 RouteTimeAxisView::edit_click (GdkEventButton *ev)
255 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
256 _route->set_edit_group (0, this);
260 using namespace Menu_Helpers;
262 MenuList& items = edit_group_menu.items ();
263 RadioMenuItem::Group group;
266 items.push_back (RadioMenuElem (group, _("No group"),
267 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
269 if (_route->edit_group() == 0) {
270 static_cast<RadioMenuItem*>(&items.back())->set_active ();
273 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
274 edit_group_menu.popup (ev->button, ev->time);
280 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
282 using namespace Menu_Helpers;
284 MenuList &items = edit_group_menu.items();
286 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
287 if (_route->edit_group() == eg) {
288 static_cast<RadioMenuItem*>(&items.back())->set_active ();
293 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
295 _route->set_edit_group (eg, this);
299 RouteTimeAxisView::playlist_changed ()
305 set_playlist (get_diskstream()->playlist());
310 RouteTimeAxisView::label_view ()
312 string x = _route->name();
314 if (x != name_entry.get_text()) {
315 name_entry.set_text (x);
318 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
322 RouteTimeAxisView::route_name_changed (void *src)
324 editor.route_name_changed (this);
329 RouteTimeAxisView::take_name_changed (void *src)
338 RouteTimeAxisView::playlist_click ()
340 // always build a new action menu
342 if (playlist_action_menu != 0) {
343 delete playlist_action_menu;
346 playlist_action_menu = new Menu;
347 playlist_action_menu->set_name ("ArdourContextMenu");
349 build_playlist_menu (playlist_action_menu);
350 editor.set_selected_track (*this, Selection::Add);
351 playlist_action_menu->popup (1, gtk_get_current_event_time());
355 RouteTimeAxisView::automation_click ()
357 if (automation_action_menu == 0) {
358 /* this seems odd, but the automation action
359 menu is built as part of the display menu.
361 build_display_menu ();
363 editor.set_selected_track (*this, Selection::Add);
364 automation_action_menu->popup (1, gtk_get_current_event_time());
368 RouteTimeAxisView::build_automation_action_menu ()
370 using namespace Menu_Helpers;
372 automation_action_menu = manage (new Menu);
373 MenuList& automation_items = automation_action_menu->items();
374 automation_action_menu->set_name ("ArdourContextMenu");
376 automation_items.push_back (MenuElem (_("Show all automation"),
377 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
379 automation_items.push_back (MenuElem (_("Show existing automation"),
380 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
382 automation_items.push_back (MenuElem (_("Hide all automation"),
383 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
385 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
389 RouteTimeAxisView::build_display_menu ()
391 using namespace Menu_Helpers;
393 /* get the size menu ready */
399 TimeAxisView::build_display_menu ();
401 /* now fill it with our stuff */
403 MenuList& items = display_menu->items();
404 display_menu->set_name ("ArdourContextMenu");
406 items.push_back (MenuElem (_("Height"), *size_menu));
407 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
409 items.push_back (SeparatorElem());
411 build_remote_control_menu ();
412 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
414 build_automation_action_menu ();
415 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
417 // Hook for derived classes to add type specific stuff
418 items.push_back (SeparatorElem());
419 append_extra_display_menu_items ();
420 items.push_back (SeparatorElem());
424 Menu* alignment_menu = manage (new Menu);
425 MenuList& alignment_items = alignment_menu->items();
426 alignment_menu->set_name ("ArdourContextMenu");
428 RadioMenuItem::Group align_group;
430 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
431 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
432 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
433 if (get_diskstream()->alignment_style() == ExistingMaterial)
434 align_existing_item->set_active();
436 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
437 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
438 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
439 if (get_diskstream()->alignment_style() == CaptureTime)
440 align_capture_item->set_active();
442 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
444 get_diskstream()->AlignmentStyleChanged.connect (
445 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
447 RadioMenuItem::Group mode_group;
448 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
449 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
450 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
451 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
452 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
453 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
456 switch (track()->mode()) {
457 case ARDOUR::Destructive:
458 destructive_track_mode_item->set_active ();
461 normal_track_mode_item->set_active ();
466 items.push_back (SeparatorElem());
467 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
468 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
469 route_active_menu_item->set_active (_route->active());
471 items.push_back (SeparatorElem());
472 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
475 static bool __reset_item (RadioMenuItem* item)
482 RouteTimeAxisView::set_track_mode (TrackMode mode)
485 RadioMenuItem* other_item;
489 item = normal_track_mode_item;
490 other_item = destructive_track_mode_item;
492 case ARDOUR::Destructive:
493 item = destructive_track_mode_item;
494 other_item = normal_track_mode_item;
497 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
502 if (item->get_active () && track()->mode() != mode) {
503 _set_track_mode (track(), mode, other_item);
508 RouteTimeAxisView::_set_track_mode (Track* track, TrackMode mode, RadioMenuItem* reset_item)
512 if (!track->can_use_mode (mode, needs_bounce)) {
516 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
519 cerr << "would bounce this one\n";
524 track->set_mode (mode);
526 rec_enable_button->remove ();
529 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
531 case ARDOUR::Destructive:
532 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
535 rec_enable_button->show_all ();
540 RouteTimeAxisView::track_mode_changed ()
544 switch (track()->mode()) {
546 item = normal_track_mode_item;
548 case ARDOUR::Destructive:
549 item = destructive_track_mode_item;
552 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
561 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
567 TimeAxisView::show_timestretch (start, end);
577 /* check that the time selection was made in our route, or our edit group.
578 remember that edit_group() == 0 implies the route is *not* in a edit group.
581 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
582 /* this doesn't apply to us */
586 /* ignore it if our edit group is not active */
588 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
593 if (timestretch_rect == 0) {
594 timestretch_rect = new SimpleRect (*canvas_display);
595 timestretch_rect->property_x1() = 0.0;
596 timestretch_rect->property_y1() = 0.0;
597 timestretch_rect->property_x2() = 0.0;
598 timestretch_rect->property_y2() = 0.0;
599 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
600 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
603 timestretch_rect->show ();
604 timestretch_rect->raise_to_top ();
606 x1 = start / editor.get_current_zoom();
607 x2 = (end - 1) / editor.get_current_zoom();
610 timestretch_rect->property_x1() = x1;
611 timestretch_rect->property_y1() = 1.0;
612 timestretch_rect->property_x2() = x2;
613 timestretch_rect->property_y2() = y2;
617 RouteTimeAxisView::hide_timestretch ()
619 TimeAxisView::hide_timestretch ();
621 if (timestretch_rect) {
622 timestretch_rect->hide ();
627 RouteTimeAxisView::show_selection (TimeSelection& ts)
631 /* ignore it if our edit group is not active or if the selection was started
632 in some other track or edit group (remember that edit_group() == 0 means
633 that the track is not in an edit group).
636 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
637 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
643 TimeAxisView::show_selection (ts);
647 RouteTimeAxisView::set_height (TrackHeight h)
649 bool height_changed = (height == 0) || (h != height_style);
651 TimeAxisView::set_height (h);
656 _view->set_height ((double) height);
659 switch (height_style) {
661 xml_node->add_property ("track_height", "largest");
665 xml_node->add_property ("track_height", "large");
669 xml_node->add_property ("track_height", "larger");
673 xml_node->add_property ("track_height", "normal");
677 xml_node->add_property ("track_height", "smaller");
681 xml_node->add_property ("track_height", "small");
685 switch (height_style) {
695 if (rec_enable_button)
696 rec_enable_button->show();
698 edit_group_button.show();
700 visual_button.show();
702 automation_button.show();
704 if (is_track() && track()->mode() == ARDOUR::Normal) {
705 playlist_button.show();
715 if (rec_enable_button)
716 rec_enable_button->show();
718 edit_group_button.hide ();
720 visual_button.hide ();
722 automation_button.hide ();
724 if (is_track() && track()->mode() == ARDOUR::Normal) {
725 playlist_button.hide ();
735 if (rec_enable_button)
736 rec_enable_button->hide();
738 edit_group_button.hide ();
740 visual_button.hide ();
742 automation_button.hide ();
743 playlist_button.hide ();
744 name_label.set_text (_route->name());
748 if (height_changed) {
749 /* only emit the signal if the height really changed */
750 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
755 RouteTimeAxisView::select_track_color ()
757 if (RouteUI::choose_color ()) {
760 _view->apply_color (_color, StreamView::RegionColor);
766 RouteTimeAxisView::reset_samples_per_unit ()
768 set_samples_per_unit (editor.get_current_zoom());
772 RouteTimeAxisView::set_samples_per_unit (double spu)
776 if (get_diskstream() != 0) {
777 speed = get_diskstream()->speed();
781 _view->set_samples_per_unit (spu * speed);
784 TimeAxisView::set_samples_per_unit (spu * speed);
788 RouteTimeAxisView::align_style_changed ()
790 switch (get_diskstream()->alignment_style()) {
791 case ExistingMaterial:
792 if (!align_existing_item->get_active()) {
793 align_existing_item->set_active();
797 if (!align_capture_item->get_active()) {
798 align_capture_item->set_active();
805 RouteTimeAxisView::set_align_style (AlignStyle style)
810 case ExistingMaterial:
811 item = align_existing_item;
814 item = align_capture_item;
817 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
822 if (item->get_active()) {
823 get_diskstream()->set_align_style (style);
828 RouteTimeAxisView::rename_current_playlist ()
830 ArdourPrompter prompter (true);
833 boost::shared_ptr<Diskstream> ds = get_diskstream();
834 if (!ds || ds->destructive())
837 boost::shared_ptr<Playlist> pl = ds->playlist();
841 prompter.set_prompt (_("Name for playlist"));
842 prompter.set_initial_text (pl->name());
843 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
844 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
846 switch (prompter.run ()) {
847 case Gtk::RESPONSE_ACCEPT:
848 prompter.get_result (name);
860 RouteTimeAxisView::use_copy_playlist (bool prompt)
864 boost::shared_ptr<Diskstream> ds = get_diskstream();
865 if (!ds || ds->destructive())
868 boost::shared_ptr<const Playlist> pl = ds->playlist();
875 name = Playlist::bump_name (name, _session);
876 } while (_session.playlist_by_name(name));
878 // TODO: The prompter "new" button should be de-activated if the user
879 // specifies a playlist name which already exists in the session.
883 ArdourPrompter prompter (true);
885 prompter.set_prompt (_("Name for Playlist"));
886 prompter.set_initial_text (name);
887 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
888 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
889 prompter.show_all ();
891 switch (prompter.run ()) {
892 case Gtk::RESPONSE_ACCEPT:
893 prompter.get_result (name);
902 ds->use_copy_playlist ();
903 ds->playlist()->set_name (name);
908 RouteTimeAxisView::use_new_playlist (bool prompt)
912 boost::shared_ptr<Diskstream> ds = get_diskstream();
913 if (!ds || ds->destructive())
916 boost::shared_ptr<const Playlist> pl = ds->playlist();
923 name = Playlist::bump_name (name, _session);
924 } while (_session.playlist_by_name(name));
929 ArdourPrompter prompter (true);
931 prompter.set_prompt (_("Name for Playlist"));
932 prompter.set_initial_text (name);
933 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
934 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
936 switch (prompter.run ()) {
937 case Gtk::RESPONSE_ACCEPT:
938 prompter.get_result (name);
947 ds->use_new_playlist ();
948 ds->playlist()->set_name (name);
953 RouteTimeAxisView::clear_playlist ()
955 boost::shared_ptr<Diskstream> ds = get_diskstream();
956 if (!ds || ds->destructive())
959 boost::shared_ptr<Playlist> pl = ds->playlist();
963 editor.clear_playlist (pl);
967 RouteTimeAxisView::speed_changed ()
969 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
973 RouteTimeAxisView::diskstream_changed ()
975 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
979 RouteTimeAxisView::update_diskstream_display ()
981 if (!get_diskstream()) // bus
984 set_playlist (get_diskstream()->playlist());
989 RouteTimeAxisView::selection_click (GdkEventButton* ev)
991 if (Keyboard::modifier_state_equals (ev->state, (Keyboard::Shift|Keyboard::Control))) {
993 /* special case: select/deselect all tracks */
994 if (editor.get_selection().selected (this)) {
995 editor.get_selection().clear_tracks ();
997 editor.select_all_tracks ();
1003 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1005 switch (Keyboard::selection_type (ev->state)) {
1006 case Selection::Toggle:
1007 editor.get_selection().toggle (*tracks);
1010 case Selection::Set:
1011 editor.get_selection().set (*tracks);
1014 case Selection::Extend:
1015 if (tracks->size() > 1) {
1016 /* add each one, do not "extend" */
1017 editor.get_selection().add (*tracks);
1019 /* extend to the single track */
1020 editor.extend_selection_to_track (*tracks->front());
1024 case Selection::Add:
1025 editor.get_selection().add (*tracks);
1033 RouteTimeAxisView::set_selected_points (PointSelection& points)
1035 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1036 (*i)->set_selected_points (points);
1041 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1044 _view->set_selected_regionviews (regions);
1049 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1053 if (get_diskstream() != 0) {
1054 speed = get_diskstream()->speed();
1057 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1058 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1060 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1061 _view->get_selectables (start_adjusted, end_adjusted, results);
1064 /* pick up visible automation tracks */
1066 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1067 if (!(*i)->hidden()) {
1068 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1074 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1077 _view->get_inverted_selectables (sel, results);
1080 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1081 if (!(*i)->hidden()) {
1082 (*i)->get_inverted_selectables (sel, results);
1090 RouteTimeAxisView::edit_group() const
1092 return _route->edit_group();
1096 RouteTimeAxisView::name() const
1098 return _route->name();
1101 boost::shared_ptr<Playlist>
1102 RouteTimeAxisView::playlist () const
1104 boost::shared_ptr<Diskstream> ds;
1106 if ((ds = get_diskstream()) != 0) {
1107 return ds->playlist();
1109 return boost::shared_ptr<Playlist> ();
1114 RouteTimeAxisView::name_entry_changed ()
1118 x = name_entry.get_text ();
1120 if (x == _route->name()) {
1124 strip_whitespace_edges(x);
1126 if (x.length() == 0) {
1127 name_entry.set_text (_route->name());
1131 if (_session.route_name_unique (x)) {
1132 _route->set_name (x, this);
1134 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1135 name_entry.set_text (_route->name());
1140 RouteTimeAxisView::visual_click ()
1142 popup_display_menu (0);
1146 RouteTimeAxisView::hide_click ()
1148 // LAME fix for hide_button refresh fix
1149 hide_button.set_sensitive(false);
1151 editor.hide_track_in_display (*this);
1153 hide_button.set_sensitive(true);
1156 boost::shared_ptr<Region>
1157 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1159 boost::shared_ptr<Diskstream> stream;
1160 boost::shared_ptr<Playlist> playlist;
1162 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1163 return playlist->find_next_region (pos, point, dir);
1166 return boost::shared_ptr<Region> ();
1170 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1172 boost::shared_ptr<Playlist> what_we_got;
1173 boost::shared_ptr<Diskstream> ds = get_diskstream();
1174 boost::shared_ptr<Playlist> playlist;
1178 /* route is a bus, not a track */
1182 playlist = ds->playlist();
1184 TimeSelection time (selection.time);
1185 float speed = ds->speed();
1186 if (speed != 1.0f) {
1187 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1188 (*i).start = session_frame_to_track_frame((*i).start, speed);
1189 (*i).end = session_frame_to_track_frame((*i).end, speed);
1193 XMLNode &before = playlist->get_state();
1196 if ((what_we_got = playlist->cut (time)) != 0) {
1197 editor.get_cut_buffer().add (what_we_got);
1198 _session.add_command( new MementoCommand<Playlist>(*playlist.get(), &before, &playlist->get_state()));
1203 if ((what_we_got = playlist->copy (time)) != 0) {
1204 editor.get_cut_buffer().add (what_we_got);
1209 if ((what_we_got = playlist->cut (time)) != 0) {
1210 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1211 what_we_got->release ();
1221 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1227 boost::shared_ptr<Playlist> playlist = get_diskstream()->playlist();
1228 PlaylistSelection::iterator p;
1230 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1232 if (p == selection.playlists.end()) {
1236 if (get_diskstream()->speed() != 1.0f)
1237 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1239 XMLNode &before = playlist->get_state();
1240 playlist->paste (*p, pos, times);
1241 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1248 RouteTimeAxisView::get_child_list()
1251 list<TimeAxisView*>redirect_children;
1253 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1254 if (!(*i)->hidden()) {
1255 redirect_children.push_back(*i);
1258 return redirect_children;
1263 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1265 using namespace Menu_Helpers;
1267 if (!menu || !is_track()) {
1271 MenuList& playlist_items = menu->items();
1272 menu->set_name ("ArdourContextMenu");
1273 playlist_items.clear();
1275 if (playlist_menu) {
1276 delete playlist_menu;
1279 playlist_menu = new Menu;
1280 playlist_menu->set_name ("ArdourContextMenu");
1282 vector<boost::shared_ptr<Playlist> > playlists;
1283 boost::shared_ptr<Diskstream> ds = get_diskstream();
1284 RadioMenuItem::Group playlist_group;
1286 _session.get_playlists (playlists);
1288 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1290 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1291 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1292 boost::weak_ptr<Playlist> (*i))));
1294 if (ds->playlist()->id() == (*i)->id()) {
1295 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1297 } else if (ds->playlist()->id() == (*i)->id()) {
1298 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1299 boost::weak_ptr<Playlist>(*i))));
1300 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1305 playlist_items.push_back (SeparatorElem());
1306 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1307 playlist_items.push_back (SeparatorElem());
1309 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1310 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1311 playlist_items.push_back (SeparatorElem());
1312 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1313 playlist_items.push_back (SeparatorElem());
1315 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1319 RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
1321 assert (is_track());
1323 boost::shared_ptr<Playlist> pl (wpl.lock());
1329 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
1332 get_diskstream()->use_playlist (apl);
1337 RouteTimeAxisView::show_playlist_selector ()
1339 editor.playlist_selector().show_for (this);
1343 RouteTimeAxisView::map_frozen ()
1349 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1351 switch (track()->freeze_state()) {
1353 playlist_button.set_sensitive (false);
1354 rec_enable_button->set_sensitive (false);
1357 playlist_button.set_sensitive (true);
1358 rec_enable_button->set_sensitive (true);
1364 RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
1367 case cTimeStretchOutline:
1368 timestretch_rect->property_outline_color_rgba() = val;
1370 case cTimeStretchFill:
1371 timestretch_rect->property_fill_color_rgba() = val;
1379 RouteTimeAxisView::show_all_automation ()
1383 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1384 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1385 if ((*ii)->view == 0) {
1386 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1389 (*ii)->menu_item->set_active (true);
1395 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1399 RouteTimeAxisView::show_existing_automation ()
1403 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1404 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1405 if ((*ii)->view != 0) {
1406 (*ii)->menu_item->set_active (true);
1413 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1417 RouteTimeAxisView::hide_all_automation ()
1421 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1422 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1423 (*ii)->menu_item->set_active (false);
1428 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1433 RouteTimeAxisView::region_view_added (RegionView* rv)
1435 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1436 AutomationTimeAxisView* atv;
1438 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1439 rv->add_ghost (*atv);
1445 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1447 rv->add_ghost (*atv);
1450 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1452 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1458 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1460 parent.remove_ran (this);
1468 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1471 remove_child (ran->view);
1475 RouteTimeAxisView::RedirectAutomationNode*
1476 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1478 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1480 if ((*i)->redirect == redirect) {
1482 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1483 if ((*ii)->what == what) {
1493 // FIXME: duplicated in midi_time_axis.cc
1495 legalize_for_xml_node (string str)
1497 string::size_type pos;
1498 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1504 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1505 legal.replace (pos, 1, "_");
1514 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1516 RedirectAutomationLine* ral;
1518 RedirectAutomationNode* ran;
1520 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1521 fatal << _("programming error: ")
1522 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1523 redirect->name(), what)
1533 name = redirect->describe_parameter (what);
1535 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1537 char state_name[256];
1538 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1540 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1542 ral = new RedirectAutomationLine (name,
1543 *redirect, what, _session, *ran->view,
1544 *ran->view->canvas_display, redirect->automation_list (what));
1546 ral->set_line_color (color_map[cRedirectAutomationLine]);
1547 ral->queue_reset ();
1549 ran->view->add_line (*ral);
1551 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1553 if (!ran->view->marked_for_display()) {
1556 ran->menu_item->set_active (true);
1559 add_child (ran->view);
1562 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1565 redirect->mark_automation_visible (what, true);
1569 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1572 ran->menu_item->set_active (false);
1575 r->mark_automation_visible (ran->what, false);
1577 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1581 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1584 RedirectAutomationLine *ral;
1586 redirect->what_has_visible_automation (s);
1588 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1590 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1591 ral->queue_reset ();
1593 add_redirect_automation_curve (redirect, (*i));
1599 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1601 using namespace Menu_Helpers;
1602 RedirectAutomationInfo *rai;
1603 list<RedirectAutomationInfo*>::iterator x;
1605 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1606 std::set<uint32_t> has_visible_automation;
1608 r->what_has_visible_automation(has_visible_automation);
1610 if (automatable.empty()) {
1614 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1615 if ((*x)->redirect == r) {
1620 if (x == redirect_automation.end()) {
1622 rai = new RedirectAutomationInfo (r);
1623 redirect_automation.push_back (rai);
1631 /* any older menu was deleted at the top of redirects_changed()
1632 when we cleared the subplugin menu.
1635 rai->menu = manage (new Menu);
1636 MenuList& items = rai->menu->items();
1637 rai->menu->set_name ("ArdourContextMenu");
1641 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1643 RedirectAutomationNode* ran;
1644 CheckMenuItem* mitem;
1646 string name = r->describe_parameter (*i);
1648 items.push_back (CheckMenuElem (name));
1649 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1651 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1652 mitem->set_active(true);
1655 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1659 ran = new RedirectAutomationNode (*i, mitem, *this);
1661 rai->lines.push_back (ran);
1665 ran->menu_item = mitem;
1669 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1672 /* add the menu for this redirect, because the subplugin
1673 menu is always cleared at the top of redirects_changed().
1674 this is the result of some poor design in gtkmm and/or
1678 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1683 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1684 RouteTimeAxisView::RedirectAutomationNode* ran)
1686 bool showit = ran->menu_item->get_active();
1687 bool redraw = false;
1689 if (ran->view == 0 && showit) {
1690 add_redirect_automation_curve (rai->redirect, ran->what);
1694 if (showit != ran->view->marked_for_display()) {
1697 ran->view->set_marked_for_display (true);
1698 ran->view->canvas_display->show();
1700 rai->redirect->mark_automation_visible (ran->what, true);
1701 ran->view->set_marked_for_display (false);
1709 if (redraw && !no_redraw) {
1711 /* now trigger a redisplay */
1713 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1719 RouteTimeAxisView::redirects_changed (void *src)
1721 using namespace Menu_Helpers;
1723 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1724 (*i)->valid = false;
1727 subplugin_menu.items().clear ();
1729 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1730 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1732 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1734 list<RedirectAutomationInfo*>::iterator tmp;
1742 redirect_automation.erase (i);
1749 /* change in visibility was possible */
1751 _route->gui_changed ("track_height", this);
1754 RedirectAutomationLine *
1755 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1757 RedirectAutomationNode* ran;
1759 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1761 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1769 RouteTimeAxisView::reset_redirect_automation_curves ()
1771 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {