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->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
181 _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
182 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
183 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
184 _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
189 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
190 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
191 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
192 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
194 /* pick up the correct freeze state */
199 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
200 ColorsChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
203 RouteTimeAxisView::~RouteTimeAxisView ()
205 GoingAway (); /* EMIT_SIGNAL */
207 vector_delete (&redirect_automation_curves);
209 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
214 delete playlist_menu;
218 if (playlist_action_menu) {
219 delete playlist_action_menu;
220 playlist_action_menu = 0;
230 RouteTimeAxisView::post_construct ()
232 /* map current state of the route */
234 update_diskstream_display ();
235 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
236 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
237 reset_redirect_automation_curves ();
241 RouteTimeAxisView::set_playlist (boost::shared_ptr<Playlist> newplaylist)
243 boost::shared_ptr<Playlist> pl = playlist();
246 modified_connection.disconnect ();
247 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
251 RouteTimeAxisView::playlist_modified ()
256 RouteTimeAxisView::edit_click (GdkEventButton *ev)
258 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
259 _route->set_edit_group (0, this);
263 using namespace Menu_Helpers;
265 MenuList& items = edit_group_menu.items ();
266 RadioMenuItem::Group group;
269 items.push_back (RadioMenuElem (group, _("No group"),
270 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
272 if (_route->edit_group() == 0) {
273 static_cast<RadioMenuItem*>(&items.back())->set_active ();
276 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
277 edit_group_menu.popup (ev->button, ev->time);
283 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
285 using namespace Menu_Helpers;
287 MenuList &items = edit_group_menu.items();
289 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
290 if (_route->edit_group() == eg) {
291 static_cast<RadioMenuItem*>(&items.back())->set_active ();
296 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
298 _route->set_edit_group (eg, this);
302 RouteTimeAxisView::playlist_changed ()
308 set_playlist (get_diskstream()->playlist());
313 RouteTimeAxisView::label_view ()
315 string x = _route->name();
317 if (x != name_entry.get_text()) {
318 name_entry.set_text (x);
321 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
325 RouteTimeAxisView::route_name_changed (void *src)
327 editor.route_name_changed (this);
332 RouteTimeAxisView::take_name_changed (void *src)
341 RouteTimeAxisView::playlist_click ()
343 // always build a new action menu
345 if (playlist_action_menu != 0) {
346 delete playlist_action_menu;
349 playlist_action_menu = new Menu;
350 playlist_action_menu->set_name ("ArdourContextMenu");
352 build_playlist_menu (playlist_action_menu);
353 editor.set_selected_track (*this, Selection::Add);
354 playlist_action_menu->popup (1, gtk_get_current_event_time());
358 RouteTimeAxisView::automation_click ()
360 if (automation_action_menu == 0) {
361 /* this seems odd, but the automation action
362 menu is built as part of the display menu.
364 build_display_menu ();
366 editor.set_selected_track (*this, Selection::Add);
367 automation_action_menu->popup (1, gtk_get_current_event_time());
371 RouteTimeAxisView::build_automation_action_menu ()
373 using namespace Menu_Helpers;
375 automation_action_menu = manage (new Menu);
376 MenuList& automation_items = automation_action_menu->items();
377 automation_action_menu->set_name ("ArdourContextMenu");
379 automation_items.push_back (MenuElem (_("Show all automation"),
380 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
382 automation_items.push_back (MenuElem (_("Show existing automation"),
383 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
385 automation_items.push_back (MenuElem (_("Hide all automation"),
386 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
388 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
392 RouteTimeAxisView::build_display_menu ()
394 using namespace Menu_Helpers;
396 /* get the size menu ready */
402 TimeAxisView::build_display_menu ();
404 /* now fill it with our stuff */
406 MenuList& items = display_menu->items();
407 display_menu->set_name ("ArdourContextMenu");
409 items.push_back (MenuElem (_("Height"), *size_menu));
410 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
412 items.push_back (SeparatorElem());
414 build_remote_control_menu ();
415 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
417 build_automation_action_menu ();
418 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
420 // Hook for derived classes to add type specific stuff
421 items.push_back (SeparatorElem());
422 append_extra_display_menu_items ();
423 items.push_back (SeparatorElem());
427 Menu* alignment_menu = manage (new Menu);
428 MenuList& alignment_items = alignment_menu->items();
429 alignment_menu->set_name ("ArdourContextMenu");
431 RadioMenuItem::Group align_group;
433 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
434 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
435 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
436 if (get_diskstream()->alignment_style() == ExistingMaterial)
437 align_existing_item->set_active();
439 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
440 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
441 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
442 if (get_diskstream()->alignment_style() == CaptureTime)
443 align_capture_item->set_active();
445 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
447 get_diskstream()->AlignmentStyleChanged.connect (
448 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
450 RadioMenuItem::Group mode_group;
451 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
452 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
453 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
454 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
455 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
456 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
459 switch (track()->mode()) {
460 case ARDOUR::Destructive:
461 destructive_track_mode_item->set_active ();
464 normal_track_mode_item->set_active ();
469 items.push_back (SeparatorElem());
470 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
471 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
472 route_active_menu_item->set_active (_route->active());
474 items.push_back (SeparatorElem());
475 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
478 static bool __reset_item (RadioMenuItem* item)
485 RouteTimeAxisView::set_track_mode (TrackMode mode)
488 RadioMenuItem* other_item;
492 item = normal_track_mode_item;
493 other_item = destructive_track_mode_item;
495 case ARDOUR::Destructive:
496 item = destructive_track_mode_item;
497 other_item = normal_track_mode_item;
500 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
505 if (item->get_active () && track()->mode() != mode) {
506 _set_track_mode (track().get(), mode, other_item);
511 RouteTimeAxisView::_set_track_mode (Track* track, TrackMode mode, RadioMenuItem* reset_item)
515 if (!track->can_use_mode (mode, needs_bounce)) {
519 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
522 cerr << "would bounce this one\n";
527 track->set_mode (mode);
529 rec_enable_button->remove ();
532 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
534 case ARDOUR::Destructive:
535 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
538 rec_enable_button->show_all ();
543 RouteTimeAxisView::track_mode_changed ()
547 switch (track()->mode()) {
549 item = normal_track_mode_item;
551 case ARDOUR::Destructive:
552 item = destructive_track_mode_item;
555 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
564 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
570 TimeAxisView::show_timestretch (start, end);
580 /* check that the time selection was made in our route, or our edit group.
581 remember that edit_group() == 0 implies the route is *not* in a edit group.
584 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
585 /* this doesn't apply to us */
589 /* ignore it if our edit group is not active */
591 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
596 if (timestretch_rect == 0) {
597 timestretch_rect = new SimpleRect (*canvas_display);
598 timestretch_rect->property_x1() = 0.0;
599 timestretch_rect->property_y1() = 0.0;
600 timestretch_rect->property_x2() = 0.0;
601 timestretch_rect->property_y2() = 0.0;
602 timestretch_rect->property_fill_color_rgba() = Config->canvasvar_TimeStretchFill.get();
603 timestretch_rect->property_outline_color_rgba() = Config->canvasvar_TimeStretchOutline.get();
606 timestretch_rect->show ();
607 timestretch_rect->raise_to_top ();
609 x1 = start / editor.get_current_zoom();
610 x2 = (end - 1) / editor.get_current_zoom();
613 timestretch_rect->property_x1() = x1;
614 timestretch_rect->property_y1() = 1.0;
615 timestretch_rect->property_x2() = x2;
616 timestretch_rect->property_y2() = y2;
620 RouteTimeAxisView::hide_timestretch ()
622 TimeAxisView::hide_timestretch ();
624 if (timestretch_rect) {
625 timestretch_rect->hide ();
630 RouteTimeAxisView::show_selection (TimeSelection& ts)
634 /* ignore it if our edit group is not active or if the selection was started
635 in some other track or edit group (remember that edit_group() == 0 means
636 that the track is not in an edit group).
639 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
640 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
646 TimeAxisView::show_selection (ts);
650 RouteTimeAxisView::set_height (TrackHeight h)
652 bool height_changed = (height == 0) || (h != height_style);
654 TimeAxisView::set_height (h);
659 _view->set_height ((double) height);
662 switch (height_style) {
664 xml_node->add_property ("track_height", "largest");
668 xml_node->add_property ("track_height", "large");
672 xml_node->add_property ("track_height", "larger");
676 xml_node->add_property ("track_height", "normal");
680 xml_node->add_property ("track_height", "smaller");
684 xml_node->add_property ("track_height", "small");
688 switch (height_style) {
698 if (rec_enable_button)
699 rec_enable_button->show();
701 edit_group_button.show();
703 visual_button.show();
705 automation_button.show();
707 if (is_track() && track()->mode() == ARDOUR::Normal) {
708 playlist_button.show();
718 if (rec_enable_button)
719 rec_enable_button->show();
721 edit_group_button.hide ();
723 visual_button.hide ();
725 automation_button.hide ();
727 if (is_track() && track()->mode() == ARDOUR::Normal) {
728 playlist_button.hide ();
738 if (rec_enable_button)
739 rec_enable_button->hide();
741 edit_group_button.hide ();
743 visual_button.hide ();
745 automation_button.hide ();
746 playlist_button.hide ();
747 name_label.set_text (_route->name());
751 if (height_changed) {
752 /* only emit the signal if the height really changed */
753 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
758 RouteTimeAxisView::select_track_color ()
760 if (RouteUI::choose_color ()) {
763 _view->apply_color (_color, StreamView::RegionColor);
769 RouteTimeAxisView::reset_samples_per_unit ()
771 set_samples_per_unit (editor.get_current_zoom());
775 RouteTimeAxisView::set_samples_per_unit (double spu)
779 if (get_diskstream() != 0) {
780 speed = get_diskstream()->speed();
784 _view->set_samples_per_unit (spu * speed);
787 TimeAxisView::set_samples_per_unit (spu * speed);
791 RouteTimeAxisView::align_style_changed ()
793 switch (get_diskstream()->alignment_style()) {
794 case ExistingMaterial:
795 if (!align_existing_item->get_active()) {
796 align_existing_item->set_active();
800 if (!align_capture_item->get_active()) {
801 align_capture_item->set_active();
808 RouteTimeAxisView::set_align_style (AlignStyle style)
813 case ExistingMaterial:
814 item = align_existing_item;
817 item = align_capture_item;
820 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
825 if (item->get_active()) {
826 get_diskstream()->set_align_style (style);
831 RouteTimeAxisView::rename_current_playlist ()
833 ArdourPrompter prompter (true);
836 boost::shared_ptr<Diskstream> ds = get_diskstream();
837 if (!ds || ds->destructive())
840 boost::shared_ptr<Playlist> pl = ds->playlist();
844 prompter.set_prompt (_("Name for playlist"));
845 prompter.set_initial_text (pl->name());
846 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
847 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
849 switch (prompter.run ()) {
850 case Gtk::RESPONSE_ACCEPT:
851 prompter.get_result (name);
863 RouteTimeAxisView::use_copy_playlist (bool prompt)
867 boost::shared_ptr<Diskstream> ds = get_diskstream();
868 if (!ds || ds->destructive())
871 boost::shared_ptr<const Playlist> pl = ds->playlist();
878 name = Playlist::bump_name (name, _session);
879 } while (_session.playlist_by_name(name));
881 // TODO: The prompter "new" button should be de-activated if the user
882 // specifies a playlist name which already exists in the session.
886 ArdourPrompter prompter (true);
888 prompter.set_prompt (_("Name for Playlist"));
889 prompter.set_initial_text (name);
890 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
891 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
892 prompter.show_all ();
894 switch (prompter.run ()) {
895 case Gtk::RESPONSE_ACCEPT:
896 prompter.get_result (name);
905 ds->use_copy_playlist ();
906 ds->playlist()->set_name (name);
911 RouteTimeAxisView::use_new_playlist (bool prompt)
915 boost::shared_ptr<Diskstream> ds = get_diskstream();
916 if (!ds || ds->destructive())
919 boost::shared_ptr<const Playlist> pl = ds->playlist();
926 name = Playlist::bump_name (name, _session);
927 } while (_session.playlist_by_name(name));
932 ArdourPrompter prompter (true);
934 prompter.set_prompt (_("Name for Playlist"));
935 prompter.set_initial_text (name);
936 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
937 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
939 switch (prompter.run ()) {
940 case Gtk::RESPONSE_ACCEPT:
941 prompter.get_result (name);
950 ds->use_new_playlist ();
951 ds->playlist()->set_name (name);
956 RouteTimeAxisView::clear_playlist ()
958 boost::shared_ptr<Diskstream> ds = get_diskstream();
959 if (!ds || ds->destructive())
962 boost::shared_ptr<Playlist> pl = ds->playlist();
966 editor.clear_playlist (pl);
970 RouteTimeAxisView::speed_changed ()
972 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
976 RouteTimeAxisView::diskstream_changed ()
978 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
982 RouteTimeAxisView::update_diskstream_display ()
984 if (!get_diskstream()) // bus
987 set_playlist (get_diskstream()->playlist());
992 RouteTimeAxisView::selection_click (GdkEventButton* ev)
994 if (Keyboard::modifier_state_equals (ev->state, (Keyboard::Shift|Keyboard::Control))) {
996 /* special case: select/deselect all tracks */
997 if (editor.get_selection().selected (this)) {
998 editor.get_selection().clear_tracks ();
1000 editor.select_all_tracks ();
1006 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1008 switch (Keyboard::selection_type (ev->state)) {
1009 case Selection::Toggle:
1010 editor.get_selection().toggle (*tracks);
1013 case Selection::Set:
1014 editor.get_selection().set (*tracks);
1017 case Selection::Extend:
1018 if (tracks->size() > 1) {
1019 /* add each one, do not "extend" */
1020 editor.get_selection().add (*tracks);
1022 /* extend to the single track */
1023 editor.extend_selection_to_track (*tracks->front());
1027 case Selection::Add:
1028 editor.get_selection().add (*tracks);
1036 RouteTimeAxisView::set_selected_points (PointSelection& points)
1038 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1039 (*i)->set_selected_points (points);
1044 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1047 _view->set_selected_regionviews (regions);
1051 /** Add the selectable things that we have to a list.
1052 * @param results List to add things to.
1055 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1059 if (get_diskstream() != 0) {
1060 speed = get_diskstream()->speed();
1063 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1064 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1066 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1067 _view->get_selectables (start_adjusted, end_adjusted, results);
1070 /* pick up visible automation tracks */
1072 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1073 if (!(*i)->hidden()) {
1074 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1080 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1083 _view->get_inverted_selectables (sel, results);
1086 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1087 if (!(*i)->hidden()) {
1088 (*i)->get_inverted_selectables (sel, results);
1096 RouteTimeAxisView::edit_group() const
1098 return _route->edit_group();
1102 RouteTimeAxisView::name() const
1104 return _route->name();
1107 boost::shared_ptr<Playlist>
1108 RouteTimeAxisView::playlist () const
1110 boost::shared_ptr<Diskstream> ds;
1112 if ((ds = get_diskstream()) != 0) {
1113 return ds->playlist();
1115 return boost::shared_ptr<Playlist> ();
1120 RouteTimeAxisView::name_entry_changed ()
1124 x = name_entry.get_text ();
1126 if (x == _route->name()) {
1130 strip_whitespace_edges(x);
1132 if (x.length() == 0) {
1133 name_entry.set_text (_route->name());
1137 if (_session.route_name_unique (x)) {
1138 _route->set_name (x, this);
1140 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1141 name_entry.set_text (_route->name());
1146 RouteTimeAxisView::visual_click ()
1148 popup_display_menu (0);
1152 RouteTimeAxisView::hide_click ()
1154 // LAME fix for hide_button refresh fix
1155 hide_button.set_sensitive(false);
1157 editor.hide_track_in_display (*this);
1159 hide_button.set_sensitive(true);
1162 boost::shared_ptr<Region>
1163 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1165 boost::shared_ptr<Diskstream> stream;
1166 boost::shared_ptr<Playlist> playlist;
1168 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1169 return playlist->find_next_region (pos, point, dir);
1172 return boost::shared_ptr<Region> ();
1176 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1178 boost::shared_ptr<Playlist> what_we_got;
1179 boost::shared_ptr<Diskstream> ds = get_diskstream();
1180 boost::shared_ptr<Playlist> playlist;
1184 /* route is a bus, not a track */
1188 playlist = ds->playlist();
1190 TimeSelection time (selection.time);
1191 float speed = ds->speed();
1192 if (speed != 1.0f) {
1193 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1194 (*i).start = session_frame_to_track_frame((*i).start, speed);
1195 (*i).end = session_frame_to_track_frame((*i).end, speed);
1199 XMLNode &before = playlist->get_state();
1202 if ((what_we_got = playlist->cut (time)) != 0) {
1203 editor.get_cut_buffer().add (what_we_got);
1204 _session.add_command( new MementoCommand<Playlist>(*playlist.get(), &before, &playlist->get_state()));
1209 if ((what_we_got = playlist->copy (time)) != 0) {
1210 editor.get_cut_buffer().add (what_we_got);
1215 if ((what_we_got = playlist->cut (time)) != 0) {
1216 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1217 what_we_got->release ();
1227 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1233 boost::shared_ptr<Playlist> playlist = get_diskstream()->playlist();
1234 PlaylistSelection::iterator p;
1236 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1238 if (p == selection.playlists.end()) {
1242 if (get_diskstream()->speed() != 1.0f)
1243 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1245 XMLNode &before = playlist->get_state();
1246 playlist->paste (*p, pos, times);
1247 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1254 RouteTimeAxisView::get_child_list()
1257 list<TimeAxisView*>redirect_children;
1259 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1260 if (!(*i)->hidden()) {
1261 redirect_children.push_back(*i);
1264 return redirect_children;
1269 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1271 using namespace Menu_Helpers;
1273 if (!menu || !is_track()) {
1277 MenuList& playlist_items = menu->items();
1278 menu->set_name ("ArdourContextMenu");
1279 playlist_items.clear();
1281 if (playlist_menu) {
1282 delete playlist_menu;
1285 playlist_menu = new Menu;
1286 playlist_menu->set_name ("ArdourContextMenu");
1288 vector<boost::shared_ptr<Playlist> > playlists;
1289 boost::shared_ptr<Diskstream> ds = get_diskstream();
1290 RadioMenuItem::Group playlist_group;
1292 _session.get_playlists (playlists);
1294 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1296 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1297 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1298 boost::weak_ptr<Playlist> (*i))));
1300 if (ds->playlist()->id() == (*i)->id()) {
1301 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1303 } else if (ds->playlist()->id() == (*i)->id()) {
1304 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1305 boost::weak_ptr<Playlist>(*i))));
1306 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1311 playlist_items.push_back (SeparatorElem());
1312 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1313 playlist_items.push_back (SeparatorElem());
1315 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1316 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1317 playlist_items.push_back (SeparatorElem());
1318 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1319 playlist_items.push_back (SeparatorElem());
1321 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1325 RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
1327 assert (is_track());
1329 boost::shared_ptr<Playlist> pl (wpl.lock());
1335 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
1338 get_diskstream()->use_playlist (apl);
1343 RouteTimeAxisView::show_playlist_selector ()
1345 editor.playlist_selector().show_for (this);
1349 RouteTimeAxisView::map_frozen ()
1355 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1357 switch (track()->freeze_state()) {
1359 playlist_button.set_sensitive (false);
1360 rec_enable_button->set_sensitive (false);
1363 playlist_button.set_sensitive (true);
1364 rec_enable_button->set_sensitive (true);
1370 RouteTimeAxisView::color_handler ()
1372 //case cTimeStretchOutline:
1373 if (timestretch_rect) {
1374 timestretch_rect->property_outline_color_rgba() = Config->canvasvar_TimeStretchOutline.get();
1376 //case cTimeStretchFill:
1377 if (timestretch_rect) {
1378 timestretch_rect->property_fill_color_rgba() = Config->canvasvar_TimeStretchFill.get();
1384 RouteTimeAxisView::show_all_automation ()
1388 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1389 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1390 if ((*ii)->view == 0) {
1391 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1394 (*ii)->menu_item->set_active (true);
1400 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1404 RouteTimeAxisView::show_existing_automation ()
1408 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1409 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1410 if ((*ii)->view != 0) {
1411 (*ii)->menu_item->set_active (true);
1418 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1422 RouteTimeAxisView::hide_all_automation ()
1426 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1427 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1428 (*ii)->menu_item->set_active (false);
1433 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1438 RouteTimeAxisView::region_view_added (RegionView* rv)
1440 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1441 AutomationTimeAxisView* atv;
1443 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1444 rv->add_ghost (*atv);
1450 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1452 rv->add_ghost (*atv);
1455 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1457 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1463 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1465 parent.remove_ran (this);
1473 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1476 remove_child (ran->view);
1480 RouteTimeAxisView::RedirectAutomationNode*
1481 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1483 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1485 if ((*i)->redirect == redirect) {
1487 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1488 if ((*ii)->what == what) {
1498 // FIXME: duplicated in midi_time_axis.cc
1500 legalize_for_xml_node (string str)
1502 string::size_type pos;
1503 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1509 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1510 legal.replace (pos, 1, "_");
1519 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1521 RedirectAutomationLine* ral;
1523 RedirectAutomationNode* ran;
1525 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1526 fatal << _("programming error: ")
1527 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1528 redirect->name(), what)
1538 name = redirect->describe_parameter (what);
1540 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1542 char state_name[256];
1543 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1545 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1547 ral = new RedirectAutomationLine (name,
1548 *redirect, what, _session, *ran->view,
1549 *ran->view->canvas_display, redirect->automation_list (what));
1551 ral->set_line_color (Config->canvasvar_RedirectAutomationLine.get());
1552 ral->queue_reset ();
1554 ran->view->add_line (*ral);
1556 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1558 if (!ran->view->marked_for_display()) {
1561 ran->menu_item->set_active (true);
1564 add_child (ran->view);
1567 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1570 redirect->mark_automation_visible (what, true);
1574 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1577 ran->menu_item->set_active (false);
1580 r->mark_automation_visible (ran->what, false);
1582 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1586 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1589 RedirectAutomationLine *ral;
1591 redirect->what_has_visible_automation (s);
1593 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1595 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1596 ral->queue_reset ();
1598 add_redirect_automation_curve (redirect, (*i));
1604 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1606 using namespace Menu_Helpers;
1607 RedirectAutomationInfo *rai;
1608 list<RedirectAutomationInfo*>::iterator x;
1610 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1611 std::set<uint32_t> has_visible_automation;
1613 r->what_has_visible_automation(has_visible_automation);
1615 if (automatable.empty()) {
1619 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1620 if ((*x)->redirect == r) {
1625 if (x == redirect_automation.end()) {
1627 rai = new RedirectAutomationInfo (r);
1628 redirect_automation.push_back (rai);
1636 /* any older menu was deleted at the top of redirects_changed()
1637 when we cleared the subplugin menu.
1640 rai->menu = manage (new Menu);
1641 MenuList& items = rai->menu->items();
1642 rai->menu->set_name ("ArdourContextMenu");
1646 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1648 RedirectAutomationNode* ran;
1649 CheckMenuItem* mitem;
1651 string name = r->describe_parameter (*i);
1653 items.push_back (CheckMenuElem (name));
1654 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1656 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1657 mitem->set_active(true);
1660 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1664 ran = new RedirectAutomationNode (*i, mitem, *this);
1666 rai->lines.push_back (ran);
1670 ran->menu_item = mitem;
1674 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1677 /* add the menu for this redirect, because the subplugin
1678 menu is always cleared at the top of redirects_changed().
1679 this is the result of some poor design in gtkmm and/or
1683 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1688 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1689 RouteTimeAxisView::RedirectAutomationNode* ran)
1691 bool showit = ran->menu_item->get_active();
1692 bool redraw = false;
1694 if (ran->view == 0 && showit) {
1695 add_redirect_automation_curve (rai->redirect, ran->what);
1699 if (showit != ran->view->marked_for_display()) {
1702 ran->view->set_marked_for_display (true);
1703 ran->view->canvas_display->show();
1705 rai->redirect->mark_automation_visible (ran->what, true);
1706 ran->view->set_marked_for_display (false);
1714 if (redraw && !no_redraw) {
1716 /* now trigger a redisplay */
1718 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1724 RouteTimeAxisView::redirects_changed (void *src)
1726 using namespace Menu_Helpers;
1728 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1729 (*i)->valid = false;
1732 subplugin_menu.items().clear ();
1734 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1735 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1737 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1739 list<RedirectAutomationInfo*>::iterator tmp;
1747 redirect_automation.erase (i);
1754 /* change in visibility was possible */
1756 _route->gui_changed ("track_height", this);
1759 RedirectAutomationLine *
1760 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1762 RedirectAutomationNode* ran;
1764 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1766 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1774 RouteTimeAxisView::reset_redirect_automation_curves ()
1776 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {
1782 RouteTimeAxisView::update_rec_display ()
1784 RouteUI::update_rec_display ();
1785 name_entry.set_sensitive (!_route->record_enabled());