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_name ("TrackMuteButton");
109 solo_button->set_name ("SoloButton");
110 edit_group_button.set_name ("TrackGroupButton");
111 playlist_button.set_name ("TrackPlaylistButton");
112 automation_button.set_name ("TrackAutomationButton");
113 size_button.set_name ("TrackSizeButton");
114 visual_button.set_name ("TrackVisualButton");
115 hide_button.set_name ("TrackRemoveButton");
117 hide_button.add (*(manage (new Image (get_xpm("small_x.xpm")))));
119 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
120 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
121 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
122 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
123 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
124 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
126 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
127 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
128 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
129 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
135 rec_enable_button->remove ();
136 switch (track()->mode()) {
138 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
140 case ARDOUR::Destructive:
141 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
144 rec_enable_button->show_all ();
146 rec_enable_button->set_name ("TrackRecordEnableButton");
147 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
148 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
149 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
152 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
153 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
155 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
157 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
158 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
159 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
160 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
161 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
162 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
163 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
164 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
168 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
169 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
170 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
171 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
173 if (is_track() && track()->mode() == ARDOUR::Normal) {
174 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
177 /* remove focus from the buttons */
179 automation_button.unset_flags (Gtk::CAN_FOCUS);
180 solo_button->unset_flags (Gtk::CAN_FOCUS);
181 mute_button->unset_flags (Gtk::CAN_FOCUS);
182 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
183 size_button.unset_flags (Gtk::CAN_FOCUS);
184 playlist_button.unset_flags (Gtk::CAN_FOCUS);
185 hide_button.unset_flags (Gtk::CAN_FOCUS);
186 visual_button.unset_flags (Gtk::CAN_FOCUS);
188 /* map current state of the route */
190 update_diskstream_display ();
191 redirects_changed (0);
192 reset_redirect_automation_curves ();
195 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
196 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
200 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
201 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
202 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
203 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
205 /* ask for notifications of any new RegionViews */
206 // FIXME: _view is NULL, but it would be nice to attach this here :/
207 //_view->RegionViewAdded.connect (mem_fun(*this, &RouteTimeAxisView::region_view_added));
210 /* pick up the correct freeze state */
215 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
216 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
220 RouteTimeAxisView::~RouteTimeAxisView ()
222 GoingAway (); /* EMIT_SIGNAL */
224 vector_delete (&redirect_automation_curves);
226 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
231 delete playlist_menu;
235 if (playlist_action_menu) {
236 delete playlist_action_menu;
237 playlist_action_menu = 0;
247 RouteTimeAxisView::set_playlist (Playlist *newplaylist)
249 Playlist *pl = playlist();
252 modified_connection.disconnect ();
253 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
257 RouteTimeAxisView::playlist_modified ()
262 RouteTimeAxisView::edit_click (GdkEventButton *ev)
264 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
265 _route->set_edit_group (0, this);
269 using namespace Menu_Helpers;
271 MenuList& items = edit_group_menu.items ();
272 RadioMenuItem::Group group;
275 items.push_back (RadioMenuElem (group, _("No group"),
276 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
278 if (_route->edit_group() == 0) {
279 static_cast<RadioMenuItem*>(&items.back())->set_active ();
282 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
283 edit_group_menu.popup (ev->button, ev->time);
289 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
291 using namespace Menu_Helpers;
293 MenuList &items = edit_group_menu.items();
295 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
296 if (_route->edit_group() == eg) {
297 static_cast<RadioMenuItem*>(&items.back())->set_active ();
302 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
304 _route->set_edit_group (eg, this);
308 RouteTimeAxisView::playlist_changed ()
314 set_playlist (dynamic_cast<Playlist*>(get_diskstream()->playlist()));
319 RouteTimeAxisView::label_view ()
321 string x = _route->name();
323 if (x != name_entry.get_text()) {
324 name_entry.set_text (x);
327 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
331 RouteTimeAxisView::route_name_changed (void *src)
333 editor.route_name_changed (this);
338 RouteTimeAxisView::take_name_changed (void *src)
347 RouteTimeAxisView::playlist_click ()
349 // always build a new action menu
351 if (playlist_action_menu != 0) {
352 delete playlist_action_menu;
355 playlist_action_menu = new Menu;
356 playlist_action_menu->set_name ("ArdourContextMenu");
358 build_playlist_menu (playlist_action_menu);
359 editor.set_selected_track (*this, Selection::Add);
360 playlist_action_menu->popup (1, 0);
364 RouteTimeAxisView::automation_click ()
366 if (automation_action_menu == 0) {
367 /* this seems odd, but the automation action
368 menu is built as part of the display menu.
370 build_display_menu ();
372 editor.set_selected_track (*this, Selection::Add);
373 automation_action_menu->popup (1, 0);
377 RouteTimeAxisView::build_automation_action_menu ()
379 using namespace Menu_Helpers;
381 automation_action_menu = manage (new Menu);
382 MenuList& automation_items = automation_action_menu->items();
383 automation_action_menu->set_name ("ArdourContextMenu");
385 automation_items.push_back (MenuElem (_("Show all automation"),
386 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
388 automation_items.push_back (MenuElem (_("Show existing automation"),
389 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
391 automation_items.push_back (MenuElem (_("Hide all automation"),
392 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
394 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
398 RouteTimeAxisView::build_display_menu ()
400 using namespace Menu_Helpers;
402 /* get the size menu ready */
408 TimeAxisView::build_display_menu ();
410 /* now fill it with our stuff */
412 MenuList& items = display_menu->items();
413 display_menu->set_name ("ArdourContextMenu");
415 items.push_back (MenuElem (_("Height"), *size_menu));
416 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
418 items.push_back (SeparatorElem());
420 build_remote_control_menu ();
421 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
423 build_automation_action_menu ();
424 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
426 // Hook for derived classes to add type specific stuff
427 items.push_back (SeparatorElem());
428 append_extra_display_menu_items ();
429 items.push_back (SeparatorElem());
433 Menu* alignment_menu = manage (new Menu);
434 MenuList& alignment_items = alignment_menu->items();
435 alignment_menu->set_name ("ArdourContextMenu");
437 RadioMenuItem::Group align_group;
439 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
440 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
441 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
442 if (get_diskstream()->alignment_style() == ExistingMaterial)
443 align_existing_item->set_active();
445 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
446 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
447 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
448 if (get_diskstream()->alignment_style() == CaptureTime)
449 align_capture_item->set_active();
451 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
453 get_diskstream()->AlignmentStyleChanged.connect (
454 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
456 RadioMenuItem::Group mode_group;
457 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
458 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
459 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
460 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
461 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
462 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
465 switch (track()->mode()) {
466 case ARDOUR::Destructive:
467 destructive_track_mode_item->set_active ();
470 normal_track_mode_item->set_active ();
475 items.push_back (SeparatorElem());
476 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
477 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
478 route_active_menu_item->set_active (_route->active());
480 items.push_back (SeparatorElem());
481 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
484 static bool __reset_item (RadioMenuItem* item)
486 cerr << "reset item to true\n";
492 RouteTimeAxisView::set_track_mode (TrackMode mode)
495 RadioMenuItem* other_item;
499 item = normal_track_mode_item;
500 other_item = destructive_track_mode_item;
502 case ARDOUR::Destructive:
503 item = destructive_track_mode_item;
504 other_item = normal_track_mode_item;
507 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
512 if (item->get_active () && track()->mode() != mode) {
513 _set_track_mode (track(), mode, other_item);
518 RouteTimeAxisView::_set_track_mode (Track* track, TrackMode mode, RadioMenuItem* reset_item)
522 if (!track->can_use_mode (mode, needs_bounce)) {
526 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
529 cerr << "would bounce this one\n";
534 track->set_mode (mode);
536 rec_enable_button->remove ();
539 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
541 case ARDOUR::Destructive:
542 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
545 rec_enable_button->show_all ();
550 RouteTimeAxisView::track_mode_changed ()
554 switch (track()->mode()) {
556 item = normal_track_mode_item;
558 case ARDOUR::Destructive:
559 item = destructive_track_mode_item;
562 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
571 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
577 TimeAxisView::show_timestretch (start, end);
587 /* check that the time selection was made in our route, or our edit group.
588 remember that edit_group() == 0 implies the route is *not* in a edit group.
591 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
592 /* this doesn't apply to us */
596 /* ignore it if our edit group is not active */
598 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
603 if (timestretch_rect == 0) {
604 timestretch_rect = new SimpleRect (*canvas_display);
605 timestretch_rect->property_x1() = 0.0;
606 timestretch_rect->property_y1() = 0.0;
607 timestretch_rect->property_x2() = 0.0;
608 timestretch_rect->property_y2() = 0.0;
609 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
610 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
613 timestretch_rect->show ();
614 timestretch_rect->raise_to_top ();
616 x1 = start / editor.get_current_zoom();
617 x2 = (end - 1) / editor.get_current_zoom();
620 timestretch_rect->property_x1() = x1;
621 timestretch_rect->property_y1() = 1.0;
622 timestretch_rect->property_x2() = x2;
623 timestretch_rect->property_y2() = y2;
627 RouteTimeAxisView::hide_timestretch ()
629 TimeAxisView::hide_timestretch ();
631 if (timestretch_rect) {
632 timestretch_rect->hide ();
637 RouteTimeAxisView::show_selection (TimeSelection& ts)
641 /* ignore it if our edit group is not active or if the selection was started
642 in some other track or edit group (remember that edit_group() == 0 means
643 that the track is not in an edit group).
646 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
647 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
653 TimeAxisView::show_selection (ts);
657 RouteTimeAxisView::set_height (TrackHeight h)
659 bool height_changed = (height == 0) || (h != height_style);
661 TimeAxisView::set_height (h);
665 _view->set_height ((double) height);
667 switch (height_style) {
669 xml_node->add_property ("track_height", "largest");
673 xml_node->add_property ("track_height", "large");
677 xml_node->add_property ("track_height", "larger");
681 xml_node->add_property ("track_height", "normal");
685 xml_node->add_property ("track_height", "smaller");
689 xml_node->add_property ("track_height", "small");
693 switch (height_style) {
703 if (rec_enable_button)
704 rec_enable_button->show();
706 edit_group_button.show();
708 visual_button.show();
710 automation_button.show();
712 if (is_track() && track()->mode() == ARDOUR::Normal) {
713 playlist_button.show();
723 if (rec_enable_button)
724 rec_enable_button->show();
726 edit_group_button.hide ();
728 visual_button.hide ();
730 automation_button.hide ();
732 if (is_track() && track()->mode() == ARDOUR::Normal) {
733 playlist_button.hide ();
743 if (rec_enable_button)
744 rec_enable_button->hide();
746 edit_group_button.hide ();
748 visual_button.hide ();
750 automation_button.hide ();
751 playlist_button.hide ();
752 name_label.set_text (_route->name());
756 if (height_changed) {
757 /* only emit the signal if the height really changed */
758 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
763 RouteTimeAxisView::select_track_color ()
765 if (RouteUI::choose_color ()) {
768 _view->apply_color (_color, StreamView::RegionColor);
774 RouteTimeAxisView::reset_samples_per_unit ()
776 set_samples_per_unit (editor.get_current_zoom());
780 RouteTimeAxisView::set_samples_per_unit (double spu)
784 if (get_diskstream() != 0) {
785 speed = get_diskstream()->speed();
789 _view->set_samples_per_unit (spu * speed);
792 TimeAxisView::set_samples_per_unit (spu * speed);
796 RouteTimeAxisView::align_style_changed ()
798 switch (get_diskstream()->alignment_style()) {
799 case ExistingMaterial:
800 if (!align_existing_item->get_active()) {
801 align_existing_item->set_active();
805 if (!align_capture_item->get_active()) {
806 align_capture_item->set_active();
813 RouteTimeAxisView::set_align_style (AlignStyle style)
818 case ExistingMaterial:
819 item = align_existing_item;
822 item = align_capture_item;
825 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
830 if (item->get_active()) {
831 get_diskstream()->set_align_style (style);
836 RouteTimeAxisView::rename_current_playlist ()
838 ArdourPrompter prompter (true);
841 boost::shared_ptr<Diskstream> ds = get_diskstream();
842 if (!ds || ds->destructive())
845 Playlist *const pl = ds->playlist();
849 prompter.set_prompt (_("Name for playlist"));
850 prompter.set_initial_text (pl->name());
851 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
852 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
854 switch (prompter.run ()) {
855 case Gtk::RESPONSE_ACCEPT:
856 prompter.get_result (name);
868 RouteTimeAxisView::use_copy_playlist (bool prompt)
872 boost::shared_ptr<Diskstream> ds = get_diskstream();
873 if (!ds || ds->destructive())
876 Playlist *const pl = ds->playlist();
880 name = Playlist::bump_name (pl->name(), _session);
884 ArdourPrompter prompter (true);
886 prompter.set_prompt (_("Name for Playlist"));
887 prompter.set_initial_text (name);
888 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
889 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
890 prompter.show_all ();
892 switch (prompter.run ()) {
893 case Gtk::RESPONSE_ACCEPT:
894 prompter.get_result (name);
903 ds->use_copy_playlist ();
904 ds->playlist()->set_name (name);
909 RouteTimeAxisView::use_new_playlist (bool prompt)
913 boost::shared_ptr<Diskstream> ds = get_diskstream();
914 if (!ds || ds->destructive())
917 Playlist *const pl = ds->playlist();
921 name = Playlist::bump_name (pl->name(), _session);
925 ArdourPrompter prompter (true);
927 prompter.set_prompt (_("Name for Playlist"));
928 prompter.set_initial_text (name);
929 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
930 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
932 switch (prompter.run ()) {
933 case Gtk::RESPONSE_ACCEPT:
934 prompter.get_result (name);
943 ds->use_new_playlist ();
944 ds->playlist()->set_name (name);
949 RouteTimeAxisView::clear_playlist ()
951 boost::shared_ptr<Diskstream> ds = get_diskstream();
952 if (!ds || ds->destructive())
955 Playlist *const pl = ds->playlist();
959 editor.clear_playlist (*pl);
963 RouteTimeAxisView::speed_changed ()
965 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
969 RouteTimeAxisView::diskstream_changed ()
971 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
975 RouteTimeAxisView::update_diskstream_display ()
977 if (!get_diskstream()) // bus
980 set_playlist (get_diskstream()->playlist());
985 RouteTimeAxisView::selection_click (GdkEventButton* ev)
987 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
989 switch (Keyboard::selection_type (ev->state)) {
990 case Selection::Toggle:
991 editor.get_selection().toggle (*tracks);
995 editor.get_selection().set (*tracks);
998 case Selection::Extend:
999 /* not defined yet */
1002 case Selection::Add:
1003 editor.get_selection().add (*tracks);
1011 RouteTimeAxisView::set_selected_points (PointSelection& points)
1013 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1014 (*i)->set_selected_points (points);
1019 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1021 _view->set_selected_regionviews (regions);
1025 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1029 if (get_diskstream() != 0) {
1030 speed = get_diskstream()->speed();
1033 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1034 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1036 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1037 _view->get_selectables (start_adjusted, end_adjusted, results);
1040 /* pick up visible automation tracks */
1042 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1043 if (!(*i)->hidden()) {
1044 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1050 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1053 _view->get_inverted_selectables (sel, results);
1056 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1057 if (!(*i)->hidden()) {
1058 (*i)->get_inverted_selectables (sel, results);
1066 RouteTimeAxisView::edit_group() const
1068 return _route->edit_group();
1072 RouteTimeAxisView::name() const
1074 return _route->name();
1078 RouteTimeAxisView::playlist () const
1080 boost::shared_ptr<Diskstream> ds;
1082 if ((ds = get_diskstream()) != 0) {
1083 return ds->playlist();
1090 RouteTimeAxisView::name_entry_changed ()
1094 x = name_entry.get_text ();
1096 if (x == _route->name()) {
1100 if (x.length() == 0) {
1101 name_entry.set_text (_route->name());
1105 strip_whitespace_edges(x);
1107 if (_session.route_name_unique (x)) {
1108 _route->set_name (x, this);
1110 ARDOUR_UI::instance()->popup_error (_("a track already exists with that name"));
1111 name_entry.set_text (_route->name());
1116 RouteTimeAxisView::visual_click ()
1118 popup_display_menu (0);
1122 RouteTimeAxisView::hide_click ()
1124 editor.hide_track_in_display (*this);
1127 boost::shared_ptr<Region>
1128 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1130 boost::shared_ptr<Diskstream> stream;
1133 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1134 return playlist->find_next_region (pos, point, dir);
1137 return boost::shared_ptr<Region> ();
1141 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1143 Playlist* what_we_got;
1144 boost::shared_ptr<Diskstream> ds = get_diskstream();
1149 /* route is a bus, not a track */
1153 playlist = ds->playlist();
1156 TimeSelection time (selection.time);
1157 float speed = ds->speed();
1158 if (speed != 1.0f) {
1159 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1160 (*i).start = session_frame_to_track_frame((*i).start, speed);
1161 (*i).end = session_frame_to_track_frame((*i).end, speed);
1165 XMLNode &before = playlist->get_state();
1168 if ((what_we_got = playlist->cut (time)) != 0) {
1169 editor.get_cut_buffer().add (what_we_got);
1170 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1175 if ((what_we_got = playlist->copy (time)) != 0) {
1176 editor.get_cut_buffer().add (what_we_got);
1181 if ((what_we_got = playlist->cut (time)) != 0) {
1182 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1183 what_we_got->unref ();
1193 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1199 Playlist* playlist = get_diskstream()->playlist();
1200 PlaylistSelection::iterator p;
1202 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1204 if (p == selection.playlists.end()) {
1208 if (get_diskstream()->speed() != 1.0f)
1209 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1211 XMLNode &before = playlist->get_state();
1212 playlist->paste (**p, pos, times);
1213 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1220 RouteTimeAxisView::get_child_list()
1223 list<TimeAxisView*>redirect_children;
1225 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1226 if (!(*i)->hidden()) {
1227 redirect_children.push_back(*i);
1230 return redirect_children;
1235 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1237 using namespace Menu_Helpers;
1239 if (!menu || !is_track()) {
1243 MenuList& playlist_items = menu->items();
1244 menu->set_name ("ArdourContextMenu");
1245 playlist_items.clear();
1247 if (playlist_menu) {
1248 delete playlist_menu;
1251 playlist_menu = new Menu;
1252 playlist_menu->set_name ("ArdourContextMenu");
1254 vector<Playlist*> playlists;
1255 boost::shared_ptr<Diskstream> ds = get_diskstream();
1256 RadioMenuItem::Group playlist_group;
1258 _session.get_playlists (playlists);
1260 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1262 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1263 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist), (*i))));
1265 if (ds->playlist()->id() == (*i)->id()) {
1266 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1271 playlist_items.push_back (SeparatorElem());
1272 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1273 playlist_items.push_back (SeparatorElem());
1275 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1276 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1277 playlist_items.push_back (SeparatorElem());
1278 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1279 playlist_items.push_back (SeparatorElem());
1281 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1285 RouteTimeAxisView::use_playlist (Playlist* pl)
1287 AudioPlaylist* apl = dynamic_cast<AudioPlaylist*> (pl);
1289 assert (is_track());
1292 get_diskstream()->use_playlist (apl);
1297 RouteTimeAxisView::show_playlist_selector ()
1299 editor.playlist_selector().show_for (this);
1303 RouteTimeAxisView::map_frozen ()
1309 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1311 switch (track()->freeze_state()) {
1313 playlist_button.set_sensitive (false);
1314 rec_enable_button->set_sensitive (false);
1317 playlist_button.set_sensitive (true);
1318 rec_enable_button->set_sensitive (true);
1324 RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
1327 case cTimeStretchOutline:
1328 timestretch_rect->property_outline_color_rgba() = val;
1330 case cTimeStretchFill:
1331 timestretch_rect->property_fill_color_rgba() = val;
1339 RouteTimeAxisView::show_all_automation ()
1343 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1344 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1345 if ((*ii)->view == 0) {
1346 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1349 (*ii)->menu_item->set_active (true);
1355 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1359 RouteTimeAxisView::show_existing_automation ()
1363 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1364 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1365 if ((*ii)->view != 0) {
1366 (*ii)->menu_item->set_active (true);
1373 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1377 RouteTimeAxisView::hide_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 (*ii)->menu_item->set_active (false);
1388 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1393 RouteTimeAxisView::region_view_added (RegionView* rv)
1395 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1396 AutomationTimeAxisView* atv;
1398 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1399 rv->add_ghost (*atv);
1405 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1407 rv->add_ghost (*atv);
1410 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1412 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1418 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1420 parent.remove_ran (this);
1428 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1431 remove_child (ran->view);
1435 RouteTimeAxisView::RedirectAutomationNode*
1436 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1438 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1440 if ((*i)->redirect == redirect) {
1442 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1443 if ((*ii)->what == what) {
1453 // FIXME: duplicated in midi_time_axis.cc
1455 legalize_for_xml_node (string str)
1457 string::size_type pos;
1458 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1464 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1465 legal.replace (pos, 1, "_");
1474 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1476 RedirectAutomationLine* ral;
1478 RedirectAutomationNode* ran;
1480 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1481 fatal << _("programming error: ")
1482 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1483 redirect->name(), what)
1493 name = redirect->describe_parameter (what);
1495 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1497 char state_name[256];
1498 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1500 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1502 ral = new RedirectAutomationLine (name,
1503 *redirect, what, _session, *ran->view,
1504 *ran->view->canvas_display, redirect->automation_list (what));
1506 ral->set_line_color (color_map[cRedirectAutomationLine]);
1507 ral->queue_reset ();
1509 ran->view->add_line (*ral);
1511 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1513 if (!ran->view->marked_for_display()) {
1516 ran->menu_item->set_active (true);
1519 add_child (ran->view);
1521 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1523 redirect->mark_automation_visible (what, true);
1527 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1530 ran->menu_item->set_active (false);
1533 r->mark_automation_visible (ran->what, false);
1535 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1539 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1542 RedirectAutomationLine *ral;
1544 redirect->what_has_visible_automation (s);
1546 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1548 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1549 ral->queue_reset ();
1551 add_redirect_automation_curve (redirect, (*i));
1557 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1559 using namespace Menu_Helpers;
1560 RedirectAutomationInfo *rai;
1561 list<RedirectAutomationInfo*>::iterator x;
1563 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1564 std::set<uint32_t> has_visible_automation;
1566 r->what_has_visible_automation(has_visible_automation);
1568 if (automatable.empty()) {
1572 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1573 if ((*x)->redirect == r) {
1578 if (x == redirect_automation.end()) {
1580 rai = new RedirectAutomationInfo (r);
1581 redirect_automation.push_back (rai);
1589 /* any older menu was deleted at the top of redirects_changed()
1590 when we cleared the subplugin menu.
1593 rai->menu = manage (new Menu);
1594 MenuList& items = rai->menu->items();
1595 rai->menu->set_name ("ArdourContextMenu");
1599 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1601 RedirectAutomationNode* ran;
1602 CheckMenuItem* mitem;
1604 string name = r->describe_parameter (*i);
1606 items.push_back (CheckMenuElem (name));
1607 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1609 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1610 mitem->set_active(true);
1613 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1617 ran = new RedirectAutomationNode (*i, mitem, *this);
1619 rai->lines.push_back (ran);
1623 ran->menu_item = mitem;
1627 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1630 /* add the menu for this redirect, because the subplugin
1631 menu is always cleared at the top of redirects_changed().
1632 this is the result of some poor design in gtkmm and/or
1636 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1641 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1642 RouteTimeAxisView::RedirectAutomationNode* ran)
1644 bool showit = ran->menu_item->get_active();
1645 bool redraw = false;
1647 if (ran->view == 0 && showit) {
1648 add_redirect_automation_curve (rai->redirect, ran->what);
1652 if (showit != ran->view->marked_for_display()) {
1655 ran->view->set_marked_for_display (true);
1656 ran->view->canvas_display->show();
1658 rai->redirect->mark_automation_visible (ran->what, true);
1659 ran->view->set_marked_for_display (false);
1667 if (redraw && !no_redraw) {
1669 /* now trigger a redisplay */
1671 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1677 RouteTimeAxisView::redirects_changed (void *src)
1679 using namespace Menu_Helpers;
1681 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1682 (*i)->valid = false;
1685 subplugin_menu.items().clear ();
1687 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1688 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1690 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1692 list<RedirectAutomationInfo*>::iterator tmp;
1700 redirect_automation.erase (i);
1707 /* change in visibility was possible */
1709 _route->gui_changed ("track_height", this);
1712 RedirectAutomationLine *
1713 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1715 RedirectAutomationNode* ran;
1717 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1719 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1727 RouteTimeAxisView::reset_redirect_automation_curves ()
1729 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {