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 mute_button->set_active (false);
109 solo_button->set_active (false);
111 mute_button->set_name ("TrackMuteButton");
112 solo_button->set_name ("SoloButton");
113 edit_group_button.set_name ("TrackGroupButton");
114 playlist_button.set_name ("TrackPlaylistButton");
115 automation_button.set_name ("TrackAutomationButton");
116 size_button.set_name ("TrackSizeButton");
117 visual_button.set_name ("TrackVisualButton");
118 hide_button.set_name ("TrackRemoveButton");
120 hide_button.add (*(manage (new Image (::get_icon("hide")))));
121 hide_button.show_all ();
123 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
124 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
125 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
126 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
127 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
128 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
130 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press));
131 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release));
132 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press));
133 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release));
139 rec_enable_button->remove ();
140 switch (track()->mode()) {
142 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
144 case ARDOUR::Destructive:
145 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
148 rec_enable_button->show_all ();
150 rec_enable_button->set_name ("TrackRecordEnableButton");
151 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
152 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
153 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
156 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
157 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
159 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
161 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
162 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
163 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
164 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
165 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
166 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
167 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
168 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
172 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
173 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
174 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
175 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
177 if (is_track() && track()->mode() == ARDOUR::Normal) {
178 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
181 /* remove focus from the buttons */
183 automation_button.unset_flags (Gtk::CAN_FOCUS);
184 solo_button->unset_flags (Gtk::CAN_FOCUS);
185 mute_button->unset_flags (Gtk::CAN_FOCUS);
186 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
187 size_button.unset_flags (Gtk::CAN_FOCUS);
188 playlist_button.unset_flags (Gtk::CAN_FOCUS);
189 hide_button.unset_flags (Gtk::CAN_FOCUS);
190 visual_button.unset_flags (Gtk::CAN_FOCUS);
192 /* map current state of the route */
194 update_diskstream_display ();
197 //redirects_changed (0);
198 //reset_redirect_automation_curves ();
201 _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
202 _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
203 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
204 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
205 _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
210 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
211 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
212 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
213 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
215 /* ask for notifications of any new RegionViews */
216 // FIXME: _view is NULL, but it would be nice to attach this here :/
217 //_view->RegionViewAdded.connect (mem_fun(*this, &RouteTimeAxisView::region_view_added));
220 /* pick up the correct freeze state */
225 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
226 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
230 RouteTimeAxisView::~RouteTimeAxisView ()
232 GoingAway (); /* EMIT_SIGNAL */
234 vector_delete (&redirect_automation_curves);
236 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
241 delete playlist_menu;
245 if (playlist_action_menu) {
246 delete playlist_action_menu;
247 playlist_action_menu = 0;
257 RouteTimeAxisView::set_playlist (Playlist *newplaylist)
259 Playlist *pl = playlist();
262 modified_connection.disconnect ();
263 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
267 RouteTimeAxisView::playlist_modified ()
272 RouteTimeAxisView::edit_click (GdkEventButton *ev)
274 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
275 _route->set_edit_group (0, this);
279 using namespace Menu_Helpers;
281 MenuList& items = edit_group_menu.items ();
282 RadioMenuItem::Group group;
285 items.push_back (RadioMenuElem (group, _("No group"),
286 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
288 if (_route->edit_group() == 0) {
289 static_cast<RadioMenuItem*>(&items.back())->set_active ();
292 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
293 edit_group_menu.popup (ev->button, ev->time);
299 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
301 using namespace Menu_Helpers;
303 MenuList &items = edit_group_menu.items();
305 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
306 if (_route->edit_group() == eg) {
307 static_cast<RadioMenuItem*>(&items.back())->set_active ();
312 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
314 _route->set_edit_group (eg, this);
318 RouteTimeAxisView::playlist_changed ()
324 set_playlist (dynamic_cast<Playlist*>(get_diskstream()->playlist()));
329 RouteTimeAxisView::label_view ()
331 string x = _route->name();
333 if (x != name_entry.get_text()) {
334 name_entry.set_text (x);
337 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
341 RouteTimeAxisView::route_name_changed (void *src)
343 editor.route_name_changed (this);
348 RouteTimeAxisView::take_name_changed (void *src)
357 RouteTimeAxisView::playlist_click ()
359 // always build a new action menu
361 if (playlist_action_menu != 0) {
362 delete playlist_action_menu;
365 playlist_action_menu = new Menu;
366 playlist_action_menu->set_name ("ArdourContextMenu");
368 build_playlist_menu (playlist_action_menu);
369 editor.set_selected_track (*this, Selection::Add);
370 playlist_action_menu->popup (1, 0);
374 RouteTimeAxisView::automation_click ()
376 if (automation_action_menu == 0) {
377 /* this seems odd, but the automation action
378 menu is built as part of the display menu.
380 build_display_menu ();
382 editor.set_selected_track (*this, Selection::Add);
383 automation_action_menu->popup (1, 0);
387 RouteTimeAxisView::build_automation_action_menu ()
389 using namespace Menu_Helpers;
391 automation_action_menu = manage (new Menu);
392 MenuList& automation_items = automation_action_menu->items();
393 automation_action_menu->set_name ("ArdourContextMenu");
395 automation_items.push_back (MenuElem (_("Show all automation"),
396 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
398 automation_items.push_back (MenuElem (_("Show existing automation"),
399 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
401 automation_items.push_back (MenuElem (_("Hide all automation"),
402 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
404 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
408 RouteTimeAxisView::build_display_menu ()
410 using namespace Menu_Helpers;
412 /* get the size menu ready */
418 TimeAxisView::build_display_menu ();
420 /* now fill it with our stuff */
422 MenuList& items = display_menu->items();
423 display_menu->set_name ("ArdourContextMenu");
425 items.push_back (MenuElem (_("Height"), *size_menu));
426 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
428 items.push_back (SeparatorElem());
430 build_remote_control_menu ();
431 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
433 build_automation_action_menu ();
434 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
436 // Hook for derived classes to add type specific stuff
437 items.push_back (SeparatorElem());
438 append_extra_display_menu_items ();
439 items.push_back (SeparatorElem());
443 Menu* alignment_menu = manage (new Menu);
444 MenuList& alignment_items = alignment_menu->items();
445 alignment_menu->set_name ("ArdourContextMenu");
447 RadioMenuItem::Group align_group;
449 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
450 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
451 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
452 if (get_diskstream()->alignment_style() == ExistingMaterial)
453 align_existing_item->set_active();
455 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
456 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
457 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
458 if (get_diskstream()->alignment_style() == CaptureTime)
459 align_capture_item->set_active();
461 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
463 get_diskstream()->AlignmentStyleChanged.connect (
464 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
466 RadioMenuItem::Group mode_group;
467 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
468 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
469 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
470 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
471 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
472 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
475 switch (track()->mode()) {
476 case ARDOUR::Destructive:
477 destructive_track_mode_item->set_active ();
480 normal_track_mode_item->set_active ();
485 items.push_back (SeparatorElem());
486 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
487 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
488 route_active_menu_item->set_active (_route->active());
490 items.push_back (SeparatorElem());
491 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
494 static bool __reset_item (RadioMenuItem* item)
496 cerr << "reset item to true\n";
502 RouteTimeAxisView::set_track_mode (TrackMode mode)
505 RadioMenuItem* other_item;
509 item = normal_track_mode_item;
510 other_item = destructive_track_mode_item;
512 case ARDOUR::Destructive:
513 item = destructive_track_mode_item;
514 other_item = normal_track_mode_item;
517 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
522 if (item->get_active () && track()->mode() != mode) {
523 _set_track_mode (track(), mode, other_item);
528 RouteTimeAxisView::_set_track_mode (Track* track, TrackMode mode, RadioMenuItem* reset_item)
532 if (!track->can_use_mode (mode, needs_bounce)) {
536 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
539 cerr << "would bounce this one\n";
544 track->set_mode (mode);
546 rec_enable_button->remove ();
549 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
551 case ARDOUR::Destructive:
552 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
555 rec_enable_button->show_all ();
560 RouteTimeAxisView::track_mode_changed ()
564 switch (track()->mode()) {
566 item = normal_track_mode_item;
568 case ARDOUR::Destructive:
569 item = destructive_track_mode_item;
572 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
581 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
587 TimeAxisView::show_timestretch (start, end);
597 /* check that the time selection was made in our route, or our edit group.
598 remember that edit_group() == 0 implies the route is *not* in a edit group.
601 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
602 /* this doesn't apply to us */
606 /* ignore it if our edit group is not active */
608 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
613 if (timestretch_rect == 0) {
614 timestretch_rect = new SimpleRect (*canvas_display);
615 timestretch_rect->property_x1() = 0.0;
616 timestretch_rect->property_y1() = 0.0;
617 timestretch_rect->property_x2() = 0.0;
618 timestretch_rect->property_y2() = 0.0;
619 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
620 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
623 timestretch_rect->show ();
624 timestretch_rect->raise_to_top ();
626 x1 = start / editor.get_current_zoom();
627 x2 = (end - 1) / editor.get_current_zoom();
630 timestretch_rect->property_x1() = x1;
631 timestretch_rect->property_y1() = 1.0;
632 timestretch_rect->property_x2() = x2;
633 timestretch_rect->property_y2() = y2;
637 RouteTimeAxisView::hide_timestretch ()
639 TimeAxisView::hide_timestretch ();
641 if (timestretch_rect) {
642 timestretch_rect->hide ();
647 RouteTimeAxisView::show_selection (TimeSelection& ts)
651 /* ignore it if our edit group is not active or if the selection was started
652 in some other track or edit group (remember that edit_group() == 0 means
653 that the track is not in an edit group).
656 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
657 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
663 TimeAxisView::show_selection (ts);
667 RouteTimeAxisView::set_height (TrackHeight h)
669 bool height_changed = (height == 0) || (h != height_style);
671 TimeAxisView::set_height (h);
675 _view->set_height ((double) height);
677 switch (height_style) {
679 xml_node->add_property ("track_height", "largest");
683 xml_node->add_property ("track_height", "large");
687 xml_node->add_property ("track_height", "larger");
691 xml_node->add_property ("track_height", "normal");
695 xml_node->add_property ("track_height", "smaller");
699 xml_node->add_property ("track_height", "small");
703 switch (height_style) {
713 if (rec_enable_button)
714 rec_enable_button->show();
716 edit_group_button.show();
718 visual_button.show();
720 automation_button.show();
722 if (is_track() && track()->mode() == ARDOUR::Normal) {
723 playlist_button.show();
733 if (rec_enable_button)
734 rec_enable_button->show();
736 edit_group_button.hide ();
738 visual_button.hide ();
740 automation_button.hide ();
742 if (is_track() && track()->mode() == ARDOUR::Normal) {
743 playlist_button.hide ();
753 if (rec_enable_button)
754 rec_enable_button->hide();
756 edit_group_button.hide ();
758 visual_button.hide ();
760 automation_button.hide ();
761 playlist_button.hide ();
762 name_label.set_text (_route->name());
766 if (height_changed) {
767 /* only emit the signal if the height really changed */
768 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
773 RouteTimeAxisView::select_track_color ()
775 if (RouteUI::choose_color ()) {
778 _view->apply_color (_color, StreamView::RegionColor);
784 RouteTimeAxisView::reset_samples_per_unit ()
786 set_samples_per_unit (editor.get_current_zoom());
790 RouteTimeAxisView::set_samples_per_unit (double spu)
794 if (get_diskstream() != 0) {
795 speed = get_diskstream()->speed();
799 _view->set_samples_per_unit (spu * speed);
802 TimeAxisView::set_samples_per_unit (spu * speed);
806 RouteTimeAxisView::align_style_changed ()
808 switch (get_diskstream()->alignment_style()) {
809 case ExistingMaterial:
810 if (!align_existing_item->get_active()) {
811 align_existing_item->set_active();
815 if (!align_capture_item->get_active()) {
816 align_capture_item->set_active();
823 RouteTimeAxisView::set_align_style (AlignStyle style)
828 case ExistingMaterial:
829 item = align_existing_item;
832 item = align_capture_item;
835 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
840 if (item->get_active()) {
841 get_diskstream()->set_align_style (style);
846 RouteTimeAxisView::rename_current_playlist ()
848 ArdourPrompter prompter (true);
851 boost::shared_ptr<Diskstream> ds = get_diskstream();
852 if (!ds || ds->destructive())
855 Playlist *const pl = ds->playlist();
859 prompter.set_prompt (_("Name for playlist"));
860 prompter.set_initial_text (pl->name());
861 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
862 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
864 switch (prompter.run ()) {
865 case Gtk::RESPONSE_ACCEPT:
866 prompter.get_result (name);
878 RouteTimeAxisView::use_copy_playlist (bool prompt)
882 boost::shared_ptr<Diskstream> ds = get_diskstream();
883 if (!ds || ds->destructive())
886 Playlist *const pl = ds->playlist();
890 name = Playlist::bump_name (pl->name(), _session);
894 ArdourPrompter prompter (true);
896 prompter.set_prompt (_("Name for Playlist"));
897 prompter.set_initial_text (name);
898 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
899 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
900 prompter.show_all ();
902 switch (prompter.run ()) {
903 case Gtk::RESPONSE_ACCEPT:
904 prompter.get_result (name);
913 ds->use_copy_playlist ();
914 ds->playlist()->set_name (name);
919 RouteTimeAxisView::use_new_playlist (bool prompt)
923 boost::shared_ptr<Diskstream> ds = get_diskstream();
924 if (!ds || ds->destructive())
927 Playlist *const pl = ds->playlist();
931 name = Playlist::bump_name (pl->name(), _session);
935 ArdourPrompter prompter (true);
937 prompter.set_prompt (_("Name for Playlist"));
938 prompter.set_initial_text (name);
939 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
940 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
942 switch (prompter.run ()) {
943 case Gtk::RESPONSE_ACCEPT:
944 prompter.get_result (name);
953 ds->use_new_playlist ();
954 ds->playlist()->set_name (name);
959 RouteTimeAxisView::clear_playlist ()
961 boost::shared_ptr<Diskstream> ds = get_diskstream();
962 if (!ds || ds->destructive())
965 Playlist *const pl = ds->playlist();
969 editor.clear_playlist (*pl);
973 RouteTimeAxisView::speed_changed ()
975 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
979 RouteTimeAxisView::diskstream_changed ()
981 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
985 RouteTimeAxisView::update_diskstream_display ()
987 if (!get_diskstream()) // bus
990 set_playlist (get_diskstream()->playlist());
995 RouteTimeAxisView::selection_click (GdkEventButton* ev)
997 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
999 switch (Keyboard::selection_type (ev->state)) {
1000 case Selection::Toggle:
1001 editor.get_selection().toggle (*tracks);
1004 case Selection::Set:
1005 editor.get_selection().set (*tracks);
1008 case Selection::Extend:
1009 /* not defined yet */
1012 case Selection::Add:
1013 editor.get_selection().add (*tracks);
1021 RouteTimeAxisView::set_selected_points (PointSelection& points)
1023 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1024 (*i)->set_selected_points (points);
1029 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1031 _view->set_selected_regionviews (regions);
1035 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1039 if (get_diskstream() != 0) {
1040 speed = get_diskstream()->speed();
1043 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1044 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1046 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1047 _view->get_selectables (start_adjusted, end_adjusted, results);
1050 /* pick up visible automation tracks */
1052 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1053 if (!(*i)->hidden()) {
1054 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1060 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1063 _view->get_inverted_selectables (sel, results);
1066 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1067 if (!(*i)->hidden()) {
1068 (*i)->get_inverted_selectables (sel, results);
1076 RouteTimeAxisView::edit_group() const
1078 return _route->edit_group();
1082 RouteTimeAxisView::name() const
1084 return _route->name();
1088 RouteTimeAxisView::playlist () const
1090 boost::shared_ptr<Diskstream> ds;
1092 if ((ds = get_diskstream()) != 0) {
1093 return ds->playlist();
1100 RouteTimeAxisView::name_entry_changed ()
1104 x = name_entry.get_text ();
1106 if (x == _route->name()) {
1110 if (x.length() == 0) {
1111 name_entry.set_text (_route->name());
1115 strip_whitespace_edges(x);
1117 if (_session.route_name_unique (x)) {
1118 _route->set_name (x, this);
1120 ARDOUR_UI::instance()->popup_error (_("a track already exists with that name"));
1121 name_entry.set_text (_route->name());
1126 RouteTimeAxisView::visual_click ()
1128 popup_display_menu (0);
1132 RouteTimeAxisView::hide_click ()
1134 // LAME fix for hide_button refresh fix
1135 hide_button.set_sensitive(false);
1137 editor.hide_track_in_display (*this);
1139 hide_button.set_sensitive(true);
1142 boost::shared_ptr<Region>
1143 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1145 boost::shared_ptr<Diskstream> stream;
1148 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1149 return playlist->find_next_region (pos, point, dir);
1152 return boost::shared_ptr<Region> ();
1156 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1158 Playlist* what_we_got;
1159 boost::shared_ptr<Diskstream> ds = get_diskstream();
1164 /* route is a bus, not a track */
1168 playlist = ds->playlist();
1171 TimeSelection time (selection.time);
1172 float speed = ds->speed();
1173 if (speed != 1.0f) {
1174 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1175 (*i).start = session_frame_to_track_frame((*i).start, speed);
1176 (*i).end = session_frame_to_track_frame((*i).end, speed);
1180 XMLNode &before = playlist->get_state();
1183 if ((what_we_got = playlist->cut (time)) != 0) {
1184 editor.get_cut_buffer().add (what_we_got);
1185 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1190 if ((what_we_got = playlist->copy (time)) != 0) {
1191 editor.get_cut_buffer().add (what_we_got);
1196 if ((what_we_got = playlist->cut (time)) != 0) {
1197 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1198 what_we_got->unref ();
1208 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1214 Playlist* playlist = get_diskstream()->playlist();
1215 PlaylistSelection::iterator p;
1217 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1219 if (p == selection.playlists.end()) {
1223 if (get_diskstream()->speed() != 1.0f)
1224 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1226 XMLNode &before = playlist->get_state();
1227 playlist->paste (**p, pos, times);
1228 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1235 RouteTimeAxisView::get_child_list()
1238 list<TimeAxisView*>redirect_children;
1240 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1241 if (!(*i)->hidden()) {
1242 redirect_children.push_back(*i);
1245 return redirect_children;
1250 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1252 using namespace Menu_Helpers;
1254 if (!menu || !is_track()) {
1258 MenuList& playlist_items = menu->items();
1259 menu->set_name ("ArdourContextMenu");
1260 playlist_items.clear();
1262 if (playlist_menu) {
1263 delete playlist_menu;
1266 playlist_menu = new Menu;
1267 playlist_menu->set_name ("ArdourContextMenu");
1269 vector<Playlist*> playlists;
1270 boost::shared_ptr<Diskstream> ds = get_diskstream();
1271 RadioMenuItem::Group playlist_group;
1273 _session.get_playlists (playlists);
1275 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1277 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1278 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist), (*i))));
1280 if (ds->playlist()->id() == (*i)->id()) {
1281 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1286 playlist_items.push_back (SeparatorElem());
1287 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1288 playlist_items.push_back (SeparatorElem());
1290 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1291 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1292 playlist_items.push_back (SeparatorElem());
1293 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1294 playlist_items.push_back (SeparatorElem());
1296 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1300 RouteTimeAxisView::use_playlist (Playlist* pl)
1302 AudioPlaylist* apl = dynamic_cast<AudioPlaylist*> (pl);
1304 assert (is_track());
1307 get_diskstream()->use_playlist (apl);
1312 RouteTimeAxisView::show_playlist_selector ()
1314 editor.playlist_selector().show_for (this);
1318 RouteTimeAxisView::map_frozen ()
1324 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1326 switch (track()->freeze_state()) {
1328 playlist_button.set_sensitive (false);
1329 rec_enable_button->set_sensitive (false);
1332 playlist_button.set_sensitive (true);
1333 rec_enable_button->set_sensitive (true);
1339 RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
1342 case cTimeStretchOutline:
1343 timestretch_rect->property_outline_color_rgba() = val;
1345 case cTimeStretchFill:
1346 timestretch_rect->property_fill_color_rgba() = val;
1354 RouteTimeAxisView::show_all_automation ()
1358 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1359 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1360 if ((*ii)->view == 0) {
1361 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1364 (*ii)->menu_item->set_active (true);
1370 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1374 RouteTimeAxisView::show_existing_automation ()
1378 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1379 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1380 if ((*ii)->view != 0) {
1381 (*ii)->menu_item->set_active (true);
1388 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1392 RouteTimeAxisView::hide_all_automation ()
1396 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1397 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1398 (*ii)->menu_item->set_active (false);
1403 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1408 RouteTimeAxisView::region_view_added (RegionView* rv)
1410 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1411 AutomationTimeAxisView* atv;
1413 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1414 rv->add_ghost (*atv);
1420 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1422 rv->add_ghost (*atv);
1425 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1427 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1433 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1435 parent.remove_ran (this);
1443 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1446 remove_child (ran->view);
1450 RouteTimeAxisView::RedirectAutomationNode*
1451 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1453 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1455 if ((*i)->redirect == redirect) {
1457 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1458 if ((*ii)->what == what) {
1468 // FIXME: duplicated in midi_time_axis.cc
1470 legalize_for_xml_node (string str)
1472 string::size_type pos;
1473 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1479 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1480 legal.replace (pos, 1, "_");
1489 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1491 RedirectAutomationLine* ral;
1493 RedirectAutomationNode* ran;
1495 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1496 fatal << _("programming error: ")
1497 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1498 redirect->name(), what)
1508 name = redirect->describe_parameter (what);
1510 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1512 char state_name[256];
1513 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1515 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1517 ral = new RedirectAutomationLine (name,
1518 *redirect, what, _session, *ran->view,
1519 *ran->view->canvas_display, redirect->automation_list (what));
1521 ral->set_line_color (color_map[cRedirectAutomationLine]);
1522 ral->queue_reset ();
1524 ran->view->add_line (*ral);
1526 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1528 if (!ran->view->marked_for_display()) {
1531 ran->menu_item->set_active (true);
1534 add_child (ran->view);
1536 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1538 redirect->mark_automation_visible (what, true);
1542 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1545 ran->menu_item->set_active (false);
1548 r->mark_automation_visible (ran->what, false);
1550 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1554 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1557 RedirectAutomationLine *ral;
1559 redirect->what_has_visible_automation (s);
1561 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1563 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1564 ral->queue_reset ();
1566 add_redirect_automation_curve (redirect, (*i));
1572 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1574 using namespace Menu_Helpers;
1575 RedirectAutomationInfo *rai;
1576 list<RedirectAutomationInfo*>::iterator x;
1578 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1579 std::set<uint32_t> has_visible_automation;
1581 r->what_has_visible_automation(has_visible_automation);
1583 if (automatable.empty()) {
1587 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1588 if ((*x)->redirect == r) {
1593 if (x == redirect_automation.end()) {
1595 rai = new RedirectAutomationInfo (r);
1596 redirect_automation.push_back (rai);
1604 /* any older menu was deleted at the top of redirects_changed()
1605 when we cleared the subplugin menu.
1608 rai->menu = manage (new Menu);
1609 MenuList& items = rai->menu->items();
1610 rai->menu->set_name ("ArdourContextMenu");
1614 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1616 RedirectAutomationNode* ran;
1617 CheckMenuItem* mitem;
1619 string name = r->describe_parameter (*i);
1621 items.push_back (CheckMenuElem (name));
1622 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1624 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1625 mitem->set_active(true);
1628 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1632 ran = new RedirectAutomationNode (*i, mitem, *this);
1634 rai->lines.push_back (ran);
1638 ran->menu_item = mitem;
1642 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1645 /* add the menu for this redirect, because the subplugin
1646 menu is always cleared at the top of redirects_changed().
1647 this is the result of some poor design in gtkmm and/or
1651 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1656 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1657 RouteTimeAxisView::RedirectAutomationNode* ran)
1659 bool showit = ran->menu_item->get_active();
1660 bool redraw = false;
1662 if (ran->view == 0 && showit) {
1663 add_redirect_automation_curve (rai->redirect, ran->what);
1667 if (showit != ran->view->marked_for_display()) {
1670 ran->view->set_marked_for_display (true);
1671 ran->view->canvas_display->show();
1673 rai->redirect->mark_automation_visible (ran->what, true);
1674 ran->view->set_marked_for_display (false);
1682 if (redraw && !no_redraw) {
1684 /* now trigger a redisplay */
1686 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1692 RouteTimeAxisView::redirects_changed (void *src)
1694 using namespace Menu_Helpers;
1696 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1697 (*i)->valid = false;
1700 subplugin_menu.items().clear ();
1702 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1703 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1705 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1707 list<RedirectAutomationInfo*>::iterator tmp;
1715 redirect_automation.erase (i);
1722 /* change in visibility was possible */
1724 _route->gui_changed ("track_height", this);
1727 RedirectAutomationLine *
1728 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1730 RedirectAutomationNode* ran;
1732 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1734 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1742 RouteTimeAxisView::reset_redirect_automation_curves ()
1744 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {