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->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press), false);
146 rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
147 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
148 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
151 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
152 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
154 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
156 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
157 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
158 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
159 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
160 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
161 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
162 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
163 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
167 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
168 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
169 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
170 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
172 if (is_track() && track()->mode() == ARDOUR::Normal) {
173 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
176 /* remove focus from the buttons */
180 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
181 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
185 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
186 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
187 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
188 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
190 /* pick up the correct freeze state */
195 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
196 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
199 RouteTimeAxisView::~RouteTimeAxisView ()
201 GoingAway (); /* EMIT_SIGNAL */
203 vector_delete (&redirect_automation_curves);
205 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
210 delete playlist_menu;
214 if (playlist_action_menu) {
215 delete playlist_action_menu;
216 playlist_action_menu = 0;
226 RouteTimeAxisView::post_construct ()
228 /* map current state of the route */
230 update_diskstream_display ();
231 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
232 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
233 reset_redirect_automation_curves ();
237 RouteTimeAxisView::set_playlist (boost::shared_ptr<Playlist> newplaylist)
239 boost::shared_ptr<Playlist> pl = playlist();
242 modified_connection.disconnect ();
243 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
247 RouteTimeAxisView::playlist_modified ()
252 RouteTimeAxisView::edit_click (GdkEventButton *ev)
254 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
255 _route->set_edit_group (0, this);
259 using namespace Menu_Helpers;
261 MenuList& items = edit_group_menu.items ();
262 RadioMenuItem::Group group;
265 items.push_back (RadioMenuElem (group, _("No group"),
266 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
268 if (_route->edit_group() == 0) {
269 static_cast<RadioMenuItem*>(&items.back())->set_active ();
272 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
273 edit_group_menu.popup (ev->button, ev->time);
279 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
281 using namespace Menu_Helpers;
283 MenuList &items = edit_group_menu.items();
285 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
286 if (_route->edit_group() == eg) {
287 static_cast<RadioMenuItem*>(&items.back())->set_active ();
292 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
294 _route->set_edit_group (eg, this);
298 RouteTimeAxisView::playlist_changed ()
303 set_playlist (get_diskstream()->playlist());
308 RouteTimeAxisView::label_view ()
310 string x = _route->name();
312 if (x != name_entry.get_text()) {
313 name_entry.set_text (x);
316 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
320 RouteTimeAxisView::route_name_changed (void *src)
322 editor.route_name_changed (this);
327 RouteTimeAxisView::take_name_changed (void *src)
336 RouteTimeAxisView::playlist_click ()
338 // always build a new action menu
340 if (playlist_action_menu != 0) {
341 delete playlist_action_menu;
344 playlist_action_menu = new Menu;
345 playlist_action_menu->set_name ("ArdourContextMenu");
347 build_playlist_menu (playlist_action_menu);
348 editor.set_selected_track (*this, Selection::Add);
349 playlist_action_menu->popup (1, gtk_get_current_event_time());
353 RouteTimeAxisView::automation_click ()
355 if (automation_action_menu == 0) {
356 /* this seems odd, but the automation action
357 menu is built as part of the display menu.
359 build_display_menu ();
361 editor.set_selected_track (*this, Selection::Add);
362 automation_action_menu->popup (1, gtk_get_current_event_time());
366 RouteTimeAxisView::build_automation_action_menu ()
368 using namespace Menu_Helpers;
370 automation_action_menu = manage (new Menu);
371 MenuList& automation_items = automation_action_menu->items();
372 automation_action_menu->set_name ("ArdourContextMenu");
374 automation_items.push_back (MenuElem (_("Show all automation"),
375 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
377 automation_items.push_back (MenuElem (_("Show existing automation"),
378 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
380 automation_items.push_back (MenuElem (_("Hide all automation"),
381 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
383 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
387 RouteTimeAxisView::build_display_menu ()
389 using namespace Menu_Helpers;
391 /* get the size menu ready */
397 TimeAxisView::build_display_menu ();
399 /* now fill it with our stuff */
401 MenuList& items = display_menu->items();
402 display_menu->set_name ("ArdourContextMenu");
404 items.push_back (MenuElem (_("Height"), *size_menu));
405 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
407 items.push_back (SeparatorElem());
409 build_remote_control_menu ();
410 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
412 build_automation_action_menu ();
413 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
415 // Hook for derived classes to add type specific stuff
416 items.push_back (SeparatorElem());
417 append_extra_display_menu_items ();
418 items.push_back (SeparatorElem());
422 Menu* alignment_menu = manage (new Menu);
423 MenuList& alignment_items = alignment_menu->items();
424 alignment_menu->set_name ("ArdourContextMenu");
426 RadioMenuItem::Group align_group;
428 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
429 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
430 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
431 if (get_diskstream()->alignment_style() == ExistingMaterial)
432 align_existing_item->set_active();
434 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
435 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
436 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
437 if (get_diskstream()->alignment_style() == CaptureTime)
438 align_capture_item->set_active();
440 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
442 get_diskstream()->AlignmentStyleChanged.connect (
443 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
445 RadioMenuItem::Group mode_group;
446 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
447 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
448 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
449 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
450 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
451 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
454 switch (track()->mode()) {
455 case ARDOUR::Destructive:
456 destructive_track_mode_item->set_active ();
459 normal_track_mode_item->set_active ();
464 items.push_back (SeparatorElem());
465 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
466 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
467 route_active_menu_item->set_active (_route->active());
469 items.push_back (SeparatorElem());
470 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
473 static bool __reset_item (RadioMenuItem* item)
480 RouteTimeAxisView::set_track_mode (TrackMode mode)
483 RadioMenuItem* other_item;
487 item = normal_track_mode_item;
488 other_item = destructive_track_mode_item;
490 case ARDOUR::Destructive:
491 item = destructive_track_mode_item;
492 other_item = normal_track_mode_item;
495 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
500 if (item->get_active () && track()->mode() != mode) {
501 _set_track_mode (track(), mode, other_item);
506 RouteTimeAxisView::_set_track_mode (Track* track, TrackMode mode, RadioMenuItem* reset_item)
510 if (!track->can_use_mode (mode, needs_bounce)) {
514 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
517 cerr << "would bounce this one\n";
522 track->set_mode (mode);
524 rec_enable_button->remove ();
527 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
529 case ARDOUR::Destructive:
530 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
533 rec_enable_button->show_all ();
538 RouteTimeAxisView::track_mode_changed ()
542 switch (track()->mode()) {
544 item = normal_track_mode_item;
546 case ARDOUR::Destructive:
547 item = destructive_track_mode_item;
550 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
559 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
565 TimeAxisView::show_timestretch (start, end);
575 /* check that the time selection was made in our route, or our edit group.
576 remember that edit_group() == 0 implies the route is *not* in a edit group.
579 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
580 /* this doesn't apply to us */
584 /* ignore it if our edit group is not active */
586 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
591 if (timestretch_rect == 0) {
592 timestretch_rect = new SimpleRect (*canvas_display);
593 timestretch_rect->property_x1() = 0.0;
594 timestretch_rect->property_y1() = 0.0;
595 timestretch_rect->property_x2() = 0.0;
596 timestretch_rect->property_y2() = 0.0;
597 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
598 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
601 timestretch_rect->show ();
602 timestretch_rect->raise_to_top ();
604 x1 = start / editor.get_current_zoom();
605 x2 = (end - 1) / editor.get_current_zoom();
608 timestretch_rect->property_x1() = x1;
609 timestretch_rect->property_y1() = 1.0;
610 timestretch_rect->property_x2() = x2;
611 timestretch_rect->property_y2() = y2;
615 RouteTimeAxisView::hide_timestretch ()
617 TimeAxisView::hide_timestretch ();
619 if (timestretch_rect) {
620 timestretch_rect->hide ();
625 RouteTimeAxisView::show_selection (TimeSelection& ts)
629 /* ignore it if our edit group is not active or if the selection was started
630 in some other track or edit group (remember that edit_group() == 0 means
631 that the track is not in an edit group).
634 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
635 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
641 TimeAxisView::show_selection (ts);
645 RouteTimeAxisView::set_height (TrackHeight h)
647 bool height_changed = (height == 0) || (h != height_style);
649 TimeAxisView::set_height (h);
654 _view->set_height ((double) height);
657 switch (height_style) {
659 xml_node->add_property ("track_height", "largest");
663 xml_node->add_property ("track_height", "large");
667 xml_node->add_property ("track_height", "larger");
671 xml_node->add_property ("track_height", "normal");
675 xml_node->add_property ("track_height", "smaller");
679 xml_node->add_property ("track_height", "small");
683 switch (height_style) {
693 if (rec_enable_button)
694 rec_enable_button->show();
696 edit_group_button.show();
698 visual_button.show();
700 automation_button.show();
702 if (is_track() && track()->mode() == ARDOUR::Normal) {
703 playlist_button.show();
713 if (rec_enable_button)
714 rec_enable_button->show();
716 edit_group_button.hide ();
718 visual_button.hide ();
720 automation_button.hide ();
722 if (is_track() && track()->mode() == ARDOUR::Normal) {
723 playlist_button.hide ();
733 if (rec_enable_button)
734 rec_enable_button->hide();
736 edit_group_button.hide ();
738 visual_button.hide ();
740 automation_button.hide ();
741 playlist_button.hide ();
742 name_label.set_text (_route->name());
746 if (height_changed) {
747 /* only emit the signal if the height really changed */
748 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
753 RouteTimeAxisView::select_track_color ()
755 if (RouteUI::choose_color ()) {
758 _view->apply_color (_color, StreamView::RegionColor);
764 RouteTimeAxisView::reset_samples_per_unit ()
766 set_samples_per_unit (editor.get_current_zoom());
770 RouteTimeAxisView::set_samples_per_unit (double spu)
774 if (get_diskstream() != 0) {
775 speed = get_diskstream()->speed();
779 _view->set_samples_per_unit (spu * speed);
782 TimeAxisView::set_samples_per_unit (spu * speed);
786 RouteTimeAxisView::align_style_changed ()
788 switch (get_diskstream()->alignment_style()) {
789 case ExistingMaterial:
790 if (!align_existing_item->get_active()) {
791 align_existing_item->set_active();
795 if (!align_capture_item->get_active()) {
796 align_capture_item->set_active();
803 RouteTimeAxisView::set_align_style (AlignStyle style)
808 case ExistingMaterial:
809 item = align_existing_item;
812 item = align_capture_item;
815 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
820 if (item->get_active()) {
821 get_diskstream()->set_align_style (style);
826 RouteTimeAxisView::rename_current_playlist ()
828 ArdourPrompter prompter (true);
831 boost::shared_ptr<Diskstream> ds = get_diskstream();
832 if (!ds || ds->destructive())
835 boost::shared_ptr<Playlist> pl = ds->playlist();
839 prompter.set_prompt (_("Name for playlist"));
840 prompter.set_initial_text (pl->name());
841 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
842 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
844 switch (prompter.run ()) {
845 case Gtk::RESPONSE_ACCEPT:
846 prompter.get_result (name);
858 RouteTimeAxisView::use_copy_playlist (bool prompt)
862 boost::shared_ptr<Diskstream> ds = get_diskstream();
863 if (!ds || ds->destructive())
866 boost::shared_ptr<const Playlist> pl = ds->playlist();
873 name = Playlist::bump_name (name, _session);
874 } while (_session.playlist_by_name(name));
876 // TODO: The prompter "new" button should be de-activated if the user
877 // specifies a playlist name which already exists in the session.
881 ArdourPrompter prompter (true);
883 prompter.set_prompt (_("Name for Playlist"));
884 prompter.set_initial_text (name);
885 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
886 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
887 prompter.show_all ();
889 switch (prompter.run ()) {
890 case Gtk::RESPONSE_ACCEPT:
891 prompter.get_result (name);
900 ds->use_copy_playlist ();
901 ds->playlist()->set_name (name);
906 RouteTimeAxisView::use_new_playlist (bool prompt)
910 boost::shared_ptr<Diskstream> ds = get_diskstream();
911 if (!ds || ds->destructive())
914 boost::shared_ptr<const Playlist> pl = ds->playlist();
921 name = Playlist::bump_name (name, _session);
922 } while (_session.playlist_by_name(name));
927 ArdourPrompter prompter (true);
929 prompter.set_prompt (_("Name for Playlist"));
930 prompter.set_initial_text (name);
931 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
932 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
934 switch (prompter.run ()) {
935 case Gtk::RESPONSE_ACCEPT:
936 prompter.get_result (name);
945 ds->use_new_playlist ();
946 ds->playlist()->set_name (name);
951 RouteTimeAxisView::clear_playlist ()
953 boost::shared_ptr<Diskstream> ds = get_diskstream();
954 if (!ds || ds->destructive())
957 boost::shared_ptr<Playlist> pl = ds->playlist();
961 editor.clear_playlist (pl);
965 RouteTimeAxisView::speed_changed ()
967 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
971 RouteTimeAxisView::diskstream_changed ()
973 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
977 RouteTimeAxisView::update_diskstream_display ()
979 if (!get_diskstream()) // bus
982 set_playlist (get_diskstream()->playlist());
987 RouteTimeAxisView::selection_click (GdkEventButton* ev)
989 if (Keyboard::modifier_state_equals (ev->state, (Keyboard::Shift|Keyboard::Control))) {
991 /* special case: select/deselect all tracks */
992 if (editor.get_selection().selected (this)) {
993 editor.get_selection().clear_tracks ();
995 editor.select_all_tracks ();
1001 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1003 switch (Keyboard::selection_type (ev->state)) {
1004 case Selection::Toggle:
1005 editor.get_selection().toggle (*tracks);
1008 case Selection::Set:
1009 editor.get_selection().set (*tracks);
1012 case Selection::Extend:
1013 if (tracks->size() > 1) {
1014 /* add each one, do not "extend" */
1015 editor.get_selection().add (*tracks);
1017 /* extend to the single track */
1018 editor.extend_selection_to_track (*tracks->front());
1022 case Selection::Add:
1023 editor.get_selection().add (*tracks);
1031 RouteTimeAxisView::set_selected_points (PointSelection& points)
1033 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1034 (*i)->set_selected_points (points);
1039 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1042 _view->set_selected_regionviews (regions);
1047 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1051 if (get_diskstream() != 0) {
1052 speed = get_diskstream()->speed();
1055 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1056 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1058 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1059 _view->get_selectables (start_adjusted, end_adjusted, results);
1062 /* pick up visible automation tracks */
1064 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1065 if (!(*i)->hidden()) {
1066 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1072 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1075 _view->get_inverted_selectables (sel, results);
1078 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1079 if (!(*i)->hidden()) {
1080 (*i)->get_inverted_selectables (sel, results);
1088 RouteTimeAxisView::edit_group() const
1090 return _route->edit_group();
1094 RouteTimeAxisView::name() const
1096 return _route->name();
1099 boost::shared_ptr<Playlist>
1100 RouteTimeAxisView::playlist () const
1102 boost::shared_ptr<Diskstream> ds;
1104 if ((ds = get_diskstream()) != 0) {
1105 return ds->playlist();
1107 return boost::shared_ptr<Playlist> ();
1112 RouteTimeAxisView::name_entry_changed ()
1116 x = name_entry.get_text ();
1118 if (x == _route->name()) {
1122 strip_whitespace_edges(x);
1124 if (x.length() == 0) {
1125 name_entry.set_text (_route->name());
1129 if (_session.route_name_unique (x)) {
1130 _route->set_name (x, this);
1132 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1133 name_entry.set_text (_route->name());
1138 RouteTimeAxisView::visual_click ()
1140 popup_display_menu (0);
1144 RouteTimeAxisView::hide_click ()
1146 // LAME fix for hide_button refresh fix
1147 hide_button.set_sensitive(false);
1149 editor.hide_track_in_display (*this);
1151 hide_button.set_sensitive(true);
1154 boost::shared_ptr<Region>
1155 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1157 boost::shared_ptr<Diskstream> stream;
1158 boost::shared_ptr<Playlist> playlist;
1160 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1161 return playlist->find_next_region (pos, point, dir);
1164 return boost::shared_ptr<Region> ();
1168 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1170 boost::shared_ptr<Playlist> what_we_got;
1171 boost::shared_ptr<Diskstream> ds = get_diskstream();
1172 boost::shared_ptr<Playlist> playlist;
1176 /* route is a bus, not a track */
1180 playlist = ds->playlist();
1182 TimeSelection time (selection.time);
1183 float speed = ds->speed();
1184 if (speed != 1.0f) {
1185 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1186 (*i).start = session_frame_to_track_frame((*i).start, speed);
1187 (*i).end = session_frame_to_track_frame((*i).end, speed);
1191 XMLNode &before = playlist->get_state();
1194 if ((what_we_got = playlist->cut (time)) != 0) {
1195 editor.get_cut_buffer().add (what_we_got);
1196 _session.add_command( new MementoCommand<Playlist>(*playlist.get(), &before, &playlist->get_state()));
1201 if ((what_we_got = playlist->copy (time)) != 0) {
1202 editor.get_cut_buffer().add (what_we_got);
1207 if ((what_we_got = playlist->cut (time)) != 0) {
1208 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1209 what_we_got->release ();
1219 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1225 boost::shared_ptr<Playlist> playlist = get_diskstream()->playlist();
1226 PlaylistSelection::iterator p;
1228 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1230 if (p == selection.playlists.end()) {
1234 if (get_diskstream()->speed() != 1.0f)
1235 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1237 XMLNode &before = playlist->get_state();
1238 playlist->paste (*p, pos, times);
1239 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1246 RouteTimeAxisView::get_child_list()
1249 list<TimeAxisView*>redirect_children;
1251 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1252 if (!(*i)->hidden()) {
1253 redirect_children.push_back(*i);
1256 return redirect_children;
1261 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1263 using namespace Menu_Helpers;
1265 if (!menu || !is_track()) {
1269 MenuList& playlist_items = menu->items();
1270 menu->set_name ("ArdourContextMenu");
1271 playlist_items.clear();
1273 if (playlist_menu) {
1274 delete playlist_menu;
1277 playlist_menu = new Menu;
1278 playlist_menu->set_name ("ArdourContextMenu");
1280 vector<boost::shared_ptr<Playlist> > playlists;
1281 boost::shared_ptr<Diskstream> ds = get_diskstream();
1282 RadioMenuItem::Group playlist_group;
1284 _session.get_playlists (playlists);
1286 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1288 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1289 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1290 boost::weak_ptr<Playlist> (*i))));
1292 if (ds->playlist()->id() == (*i)->id()) {
1293 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1295 } else if (ds->playlist()->id() == (*i)->id()) {
1296 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1297 boost::weak_ptr<Playlist>(*i))));
1298 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1303 playlist_items.push_back (SeparatorElem());
1304 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1305 playlist_items.push_back (SeparatorElem());
1307 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1308 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1309 playlist_items.push_back (SeparatorElem());
1310 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1311 playlist_items.push_back (SeparatorElem());
1313 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1317 RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
1319 assert (is_track());
1321 boost::shared_ptr<Playlist> pl (wpl.lock());
1327 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
1330 get_diskstream()->use_playlist (apl);
1335 RouteTimeAxisView::show_playlist_selector ()
1337 editor.playlist_selector().show_for (this);
1341 RouteTimeAxisView::map_frozen ()
1347 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1349 switch (track()->freeze_state()) {
1351 playlist_button.set_sensitive (false);
1352 rec_enable_button->set_sensitive (false);
1355 playlist_button.set_sensitive (true);
1356 rec_enable_button->set_sensitive (true);
1362 RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
1365 case cTimeStretchOutline:
1366 timestretch_rect->property_outline_color_rgba() = val;
1368 case cTimeStretchFill:
1369 timestretch_rect->property_fill_color_rgba() = val;
1377 RouteTimeAxisView::show_all_automation ()
1381 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1382 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1383 if ((*ii)->view == 0) {
1384 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1387 (*ii)->menu_item->set_active (true);
1393 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1397 RouteTimeAxisView::show_existing_automation ()
1401 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1402 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1403 if ((*ii)->view != 0) {
1404 (*ii)->menu_item->set_active (true);
1411 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1415 RouteTimeAxisView::hide_all_automation ()
1419 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1420 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1421 (*ii)->menu_item->set_active (false);
1426 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1431 RouteTimeAxisView::region_view_added (RegionView* rv)
1433 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1434 AutomationTimeAxisView* atv;
1436 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1437 rv->add_ghost (*atv);
1443 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1445 rv->add_ghost (*atv);
1448 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1450 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1456 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1458 parent.remove_ran (this);
1466 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1469 remove_child (ran->view);
1473 RouteTimeAxisView::RedirectAutomationNode*
1474 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1476 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1478 if ((*i)->redirect == redirect) {
1480 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1481 if ((*ii)->what == what) {
1491 // FIXME: duplicated in midi_time_axis.cc
1493 legalize_for_xml_node (string str)
1495 string::size_type pos;
1496 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1502 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1503 legal.replace (pos, 1, "_");
1512 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1514 RedirectAutomationLine* ral;
1516 RedirectAutomationNode* ran;
1518 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1519 fatal << _("programming error: ")
1520 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1521 redirect->name(), what)
1531 name = redirect->describe_parameter (what);
1533 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1535 char state_name[256];
1536 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1538 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1540 ral = new RedirectAutomationLine (name,
1541 *redirect, what, _session, *ran->view,
1542 *ran->view->canvas_display, redirect->automation_list (what));
1544 ral->set_line_color (color_map[cRedirectAutomationLine]);
1545 ral->queue_reset ();
1547 ran->view->add_line (*ral);
1549 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1551 if (!ran->view->marked_for_display()) {
1554 ran->menu_item->set_active (true);
1557 add_child (ran->view);
1560 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1563 redirect->mark_automation_visible (what, true);
1567 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1570 ran->menu_item->set_active (false);
1573 r->mark_automation_visible (ran->what, false);
1575 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1579 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1582 RedirectAutomationLine *ral;
1584 redirect->what_has_visible_automation (s);
1586 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1588 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1589 ral->queue_reset ();
1591 add_redirect_automation_curve (redirect, (*i));
1597 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1599 using namespace Menu_Helpers;
1600 RedirectAutomationInfo *rai;
1601 list<RedirectAutomationInfo*>::iterator x;
1603 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1604 std::set<uint32_t> has_visible_automation;
1606 r->what_has_visible_automation(has_visible_automation);
1608 if (automatable.empty()) {
1612 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1613 if ((*x)->redirect == r) {
1618 if (x == redirect_automation.end()) {
1620 rai = new RedirectAutomationInfo (r);
1621 redirect_automation.push_back (rai);
1629 /* any older menu was deleted at the top of redirects_changed()
1630 when we cleared the subplugin menu.
1633 rai->menu = manage (new Menu);
1634 MenuList& items = rai->menu->items();
1635 rai->menu->set_name ("ArdourContextMenu");
1639 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1641 RedirectAutomationNode* ran;
1642 CheckMenuItem* mitem;
1644 string name = r->describe_parameter (*i);
1646 items.push_back (CheckMenuElem (name));
1647 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1649 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1650 mitem->set_active(true);
1653 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1657 ran = new RedirectAutomationNode (*i, mitem, *this);
1659 rai->lines.push_back (ran);
1663 ran->menu_item = mitem;
1667 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1670 /* add the menu for this redirect, because the subplugin
1671 menu is always cleared at the top of redirects_changed().
1672 this is the result of some poor design in gtkmm and/or
1676 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1681 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1682 RouteTimeAxisView::RedirectAutomationNode* ran)
1684 bool showit = ran->menu_item->get_active();
1685 bool redraw = false;
1687 if (ran->view == 0 && showit) {
1688 add_redirect_automation_curve (rai->redirect, ran->what);
1692 if (showit != ran->view->marked_for_display()) {
1695 ran->view->set_marked_for_display (true);
1696 ran->view->canvas_display->show();
1698 rai->redirect->mark_automation_visible (ran->what, true);
1699 ran->view->set_marked_for_display (false);
1707 if (redraw && !no_redraw) {
1709 /* now trigger a redisplay */
1711 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1717 RouteTimeAxisView::redirects_changed (void *src)
1719 using namespace Menu_Helpers;
1721 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1722 (*i)->valid = false;
1725 subplugin_menu.items().clear ();
1727 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1728 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1730 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1732 list<RedirectAutomationInfo*>::iterator tmp;
1740 redirect_automation.erase (i);
1747 /* change in visibility was possible */
1749 _route->gui_changed ("track_height", this);
1752 RedirectAutomationLine *
1753 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1755 RedirectAutomationNode* ran;
1757 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1759 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1767 RouteTimeAxisView::reset_redirect_automation_curves ()
1769 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {
1775 RouteTimeAxisView::update_rec_display ()
1777 RouteUI::update_rec_display ();
1778 name_entry.set_sensitive (!_route->record_enabled());