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_icon("hide")))));
118 hide_button.show_all ();
120 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
121 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
122 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
123 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
124 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
125 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
127 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press));
128 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release));
129 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press));
130 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release));
136 rec_enable_button->remove ();
137 switch (track()->mode()) {
139 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
141 case ARDOUR::Destructive:
142 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
145 rec_enable_button->show_all ();
147 rec_enable_button->set_name ("TrackRecordEnableButton");
148 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
149 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
150 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
153 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
154 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
156 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
158 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
159 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
160 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
161 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
162 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
163 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
164 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
165 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
169 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
170 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
171 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
172 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
174 if (is_track() && track()->mode() == ARDOUR::Normal) {
175 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
178 /* remove focus from the buttons */
180 automation_button.unset_flags (Gtk::CAN_FOCUS);
181 solo_button->unset_flags (Gtk::CAN_FOCUS);
182 mute_button->unset_flags (Gtk::CAN_FOCUS);
183 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
184 size_button.unset_flags (Gtk::CAN_FOCUS);
185 playlist_button.unset_flags (Gtk::CAN_FOCUS);
186 hide_button.unset_flags (Gtk::CAN_FOCUS);
187 visual_button.unset_flags (Gtk::CAN_FOCUS);
189 /* map current state of the route */
191 update_diskstream_display ();
192 redirects_changed (0);
193 reset_redirect_automation_curves ();
196 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
197 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
201 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
202 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
203 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
204 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
206 /* ask for notifications of any new RegionViews */
207 // FIXME: _view is NULL, but it would be nice to attach this here :/
208 //_view->RegionViewAdded.connect (mem_fun(*this, &RouteTimeAxisView::region_view_added));
211 /* pick up the correct freeze state */
216 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
217 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
221 RouteTimeAxisView::~RouteTimeAxisView ()
223 GoingAway (); /* EMIT_SIGNAL */
225 vector_delete (&redirect_automation_curves);
227 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
232 delete playlist_menu;
236 if (playlist_action_menu) {
237 delete playlist_action_menu;
238 playlist_action_menu = 0;
248 RouteTimeAxisView::set_playlist (Playlist *newplaylist)
250 Playlist *pl = playlist();
253 modified_connection.disconnect ();
254 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
258 RouteTimeAxisView::playlist_modified ()
263 RouteTimeAxisView::edit_click (GdkEventButton *ev)
265 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
266 _route->set_edit_group (0, this);
270 using namespace Menu_Helpers;
272 MenuList& items = edit_group_menu.items ();
273 RadioMenuItem::Group group;
276 items.push_back (RadioMenuElem (group, _("No group"),
277 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
279 if (_route->edit_group() == 0) {
280 static_cast<RadioMenuItem*>(&items.back())->set_active ();
283 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
284 edit_group_menu.popup (ev->button, ev->time);
290 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
292 using namespace Menu_Helpers;
294 MenuList &items = edit_group_menu.items();
296 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
297 if (_route->edit_group() == eg) {
298 static_cast<RadioMenuItem*>(&items.back())->set_active ();
303 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
305 _route->set_edit_group (eg, this);
309 RouteTimeAxisView::playlist_changed ()
315 set_playlist (dynamic_cast<Playlist*>(get_diskstream()->playlist()));
320 RouteTimeAxisView::label_view ()
322 string x = _route->name();
324 if (x != name_entry.get_text()) {
325 name_entry.set_text (x);
328 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
332 RouteTimeAxisView::route_name_changed (void *src)
334 editor.route_name_changed (this);
339 RouteTimeAxisView::take_name_changed (void *src)
348 RouteTimeAxisView::playlist_click ()
350 // always build a new action menu
352 if (playlist_action_menu != 0) {
353 delete playlist_action_menu;
356 playlist_action_menu = new Menu;
357 playlist_action_menu->set_name ("ArdourContextMenu");
359 build_playlist_menu (playlist_action_menu);
360 editor.set_selected_track (*this, Selection::Add);
361 playlist_action_menu->popup (1, gtk_get_current_event_time());
365 RouteTimeAxisView::automation_click ()
367 if (automation_action_menu == 0) {
368 /* this seems odd, but the automation action
369 menu is built as part of the display menu.
371 build_display_menu ();
373 editor.set_selected_track (*this, Selection::Add);
374 automation_action_menu->popup (1, gtk_get_current_event_time());
378 RouteTimeAxisView::build_automation_action_menu ()
380 using namespace Menu_Helpers;
382 automation_action_menu = manage (new Menu);
383 MenuList& automation_items = automation_action_menu->items();
384 automation_action_menu->set_name ("ArdourContextMenu");
386 automation_items.push_back (MenuElem (_("Show all automation"),
387 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
389 automation_items.push_back (MenuElem (_("Show existing automation"),
390 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
392 automation_items.push_back (MenuElem (_("Hide all automation"),
393 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
395 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
399 RouteTimeAxisView::build_display_menu ()
401 using namespace Menu_Helpers;
403 /* get the size menu ready */
409 TimeAxisView::build_display_menu ();
411 /* now fill it with our stuff */
413 MenuList& items = display_menu->items();
414 display_menu->set_name ("ArdourContextMenu");
416 items.push_back (MenuElem (_("Height"), *size_menu));
417 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
419 items.push_back (SeparatorElem());
421 build_remote_control_menu ();
422 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
424 build_automation_action_menu ();
425 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
427 // Hook for derived classes to add type specific stuff
428 items.push_back (SeparatorElem());
429 append_extra_display_menu_items ();
430 items.push_back (SeparatorElem());
434 Menu* alignment_menu = manage (new Menu);
435 MenuList& alignment_items = alignment_menu->items();
436 alignment_menu->set_name ("ArdourContextMenu");
438 RadioMenuItem::Group align_group;
440 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
441 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
442 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
443 if (get_diskstream()->alignment_style() == ExistingMaterial)
444 align_existing_item->set_active();
446 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
447 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
448 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
449 if (get_diskstream()->alignment_style() == CaptureTime)
450 align_capture_item->set_active();
452 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
454 get_diskstream()->AlignmentStyleChanged.connect (
455 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
457 RadioMenuItem::Group mode_group;
458 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
459 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
460 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
461 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
462 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
463 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
466 switch (track()->mode()) {
467 case ARDOUR::Destructive:
468 destructive_track_mode_item->set_active ();
471 normal_track_mode_item->set_active ();
476 items.push_back (SeparatorElem());
477 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
478 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
479 route_active_menu_item->set_active (_route->active());
481 items.push_back (SeparatorElem());
482 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
485 static bool __reset_item (RadioMenuItem* item)
487 cerr << "reset item to true\n";
493 RouteTimeAxisView::set_track_mode (TrackMode mode)
496 RadioMenuItem* other_item;
500 item = normal_track_mode_item;
501 other_item = destructive_track_mode_item;
503 case ARDOUR::Destructive:
504 item = destructive_track_mode_item;
505 other_item = normal_track_mode_item;
508 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
513 if (item->get_active () && track()->mode() != mode) {
514 _set_track_mode (track(), mode, other_item);
519 RouteTimeAxisView::_set_track_mode (Track* track, TrackMode mode, RadioMenuItem* reset_item)
523 if (!track->can_use_mode (mode, needs_bounce)) {
527 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
530 cerr << "would bounce this one\n";
535 track->set_mode (mode);
537 rec_enable_button->remove ();
540 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
542 case ARDOUR::Destructive:
543 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
546 rec_enable_button->show_all ();
551 RouteTimeAxisView::track_mode_changed ()
555 switch (track()->mode()) {
557 item = normal_track_mode_item;
559 case ARDOUR::Destructive:
560 item = destructive_track_mode_item;
563 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
572 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
578 TimeAxisView::show_timestretch (start, end);
588 /* check that the time selection was made in our route, or our edit group.
589 remember that edit_group() == 0 implies the route is *not* in a edit group.
592 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
593 /* this doesn't apply to us */
597 /* ignore it if our edit group is not active */
599 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
604 if (timestretch_rect == 0) {
605 timestretch_rect = new SimpleRect (*canvas_display);
606 timestretch_rect->property_x1() = 0.0;
607 timestretch_rect->property_y1() = 0.0;
608 timestretch_rect->property_x2() = 0.0;
609 timestretch_rect->property_y2() = 0.0;
610 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
611 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
614 timestretch_rect->show ();
615 timestretch_rect->raise_to_top ();
617 x1 = start / editor.get_current_zoom();
618 x2 = (end - 1) / editor.get_current_zoom();
621 timestretch_rect->property_x1() = x1;
622 timestretch_rect->property_y1() = 1.0;
623 timestretch_rect->property_x2() = x2;
624 timestretch_rect->property_y2() = y2;
628 RouteTimeAxisView::hide_timestretch ()
630 TimeAxisView::hide_timestretch ();
632 if (timestretch_rect) {
633 timestretch_rect->hide ();
638 RouteTimeAxisView::show_selection (TimeSelection& ts)
642 /* ignore it if our edit group is not active or if the selection was started
643 in some other track or edit group (remember that edit_group() == 0 means
644 that the track is not in an edit group).
647 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
648 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
654 TimeAxisView::show_selection (ts);
658 RouteTimeAxisView::set_height (TrackHeight h)
660 bool height_changed = (height == 0) || (h != height_style);
662 TimeAxisView::set_height (h);
666 _view->set_height ((double) height);
668 switch (height_style) {
670 xml_node->add_property ("track_height", "largest");
674 xml_node->add_property ("track_height", "large");
678 xml_node->add_property ("track_height", "larger");
682 xml_node->add_property ("track_height", "normal");
686 xml_node->add_property ("track_height", "smaller");
690 xml_node->add_property ("track_height", "small");
694 switch (height_style) {
704 if (rec_enable_button)
705 rec_enable_button->show();
707 edit_group_button.show();
709 visual_button.show();
711 automation_button.show();
713 if (is_track() && track()->mode() == ARDOUR::Normal) {
714 playlist_button.show();
724 if (rec_enable_button)
725 rec_enable_button->show();
727 edit_group_button.hide ();
729 visual_button.hide ();
731 automation_button.hide ();
733 if (is_track() && track()->mode() == ARDOUR::Normal) {
734 playlist_button.hide ();
744 if (rec_enable_button)
745 rec_enable_button->hide();
747 edit_group_button.hide ();
749 visual_button.hide ();
751 automation_button.hide ();
752 playlist_button.hide ();
753 name_label.set_text (_route->name());
757 if (height_changed) {
758 /* only emit the signal if the height really changed */
759 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
764 RouteTimeAxisView::select_track_color ()
766 if (RouteUI::choose_color ()) {
769 _view->apply_color (_color, StreamView::RegionColor);
775 RouteTimeAxisView::reset_samples_per_unit ()
777 set_samples_per_unit (editor.get_current_zoom());
781 RouteTimeAxisView::set_samples_per_unit (double spu)
785 if (get_diskstream() != 0) {
786 speed = get_diskstream()->speed();
790 _view->set_samples_per_unit (spu * speed);
793 TimeAxisView::set_samples_per_unit (spu * speed);
797 RouteTimeAxisView::align_style_changed ()
799 switch (get_diskstream()->alignment_style()) {
800 case ExistingMaterial:
801 if (!align_existing_item->get_active()) {
802 align_existing_item->set_active();
806 if (!align_capture_item->get_active()) {
807 align_capture_item->set_active();
814 RouteTimeAxisView::set_align_style (AlignStyle style)
819 case ExistingMaterial:
820 item = align_existing_item;
823 item = align_capture_item;
826 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
831 if (item->get_active()) {
832 get_diskstream()->set_align_style (style);
837 RouteTimeAxisView::rename_current_playlist ()
839 ArdourPrompter prompter (true);
842 boost::shared_ptr<Diskstream> ds = get_diskstream();
843 if (!ds || ds->destructive())
846 Playlist *const pl = ds->playlist();
850 prompter.set_prompt (_("Name for playlist"));
851 prompter.set_initial_text (pl->name());
852 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
853 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
855 switch (prompter.run ()) {
856 case Gtk::RESPONSE_ACCEPT:
857 prompter.get_result (name);
869 RouteTimeAxisView::use_copy_playlist (bool prompt)
873 boost::shared_ptr<Diskstream> ds = get_diskstream();
874 if (!ds || ds->destructive())
877 Playlist *const pl = ds->playlist();
884 name = Playlist::bump_name (name, _session);
885 } while (_session.playlist_by_name(name));
887 // TODO: The prompter "new" button should be de-activated if the user
888 // specifies a playlist name which already exists in the session.
892 ArdourPrompter prompter (true);
894 prompter.set_prompt (_("Name for Playlist"));
895 prompter.set_initial_text (name);
896 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
897 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
898 prompter.show_all ();
900 switch (prompter.run ()) {
901 case Gtk::RESPONSE_ACCEPT:
902 prompter.get_result (name);
911 ds->use_copy_playlist ();
912 ds->playlist()->set_name (name);
917 RouteTimeAxisView::use_new_playlist (bool prompt)
921 boost::shared_ptr<Diskstream> ds = get_diskstream();
922 if (!ds || ds->destructive())
925 Playlist *const pl = ds->playlist();
932 name = Playlist::bump_name (name, _session);
933 } while (_session.playlist_by_name(name));
938 ArdourPrompter prompter (true);
940 prompter.set_prompt (_("Name for Playlist"));
941 prompter.set_initial_text (name);
942 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
943 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
945 switch (prompter.run ()) {
946 case Gtk::RESPONSE_ACCEPT:
947 prompter.get_result (name);
956 ds->use_new_playlist ();
957 ds->playlist()->set_name (name);
962 RouteTimeAxisView::clear_playlist ()
964 boost::shared_ptr<Diskstream> ds = get_diskstream();
965 if (!ds || ds->destructive())
968 Playlist *const pl = ds->playlist();
972 editor.clear_playlist (*pl);
976 RouteTimeAxisView::speed_changed ()
978 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
982 RouteTimeAxisView::diskstream_changed ()
984 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
988 RouteTimeAxisView::update_diskstream_display ()
990 if (!get_diskstream()) // bus
993 set_playlist (get_diskstream()->playlist());
998 RouteTimeAxisView::selection_click (GdkEventButton* ev)
1000 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1002 switch (Keyboard::selection_type (ev->state)) {
1003 case Selection::Toggle:
1004 editor.get_selection().toggle (*tracks);
1007 case Selection::Set:
1008 editor.get_selection().set (*tracks);
1011 case Selection::Extend:
1012 /* not defined yet */
1015 case Selection::Add:
1016 editor.get_selection().add (*tracks);
1024 RouteTimeAxisView::set_selected_points (PointSelection& points)
1026 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1027 (*i)->set_selected_points (points);
1032 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1034 _view->set_selected_regionviews (regions);
1038 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1042 if (get_diskstream() != 0) {
1043 speed = get_diskstream()->speed();
1046 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1047 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1049 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1050 _view->get_selectables (start_adjusted, end_adjusted, results);
1053 /* pick up visible automation tracks */
1055 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1056 if (!(*i)->hidden()) {
1057 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1063 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1066 _view->get_inverted_selectables (sel, results);
1069 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1070 if (!(*i)->hidden()) {
1071 (*i)->get_inverted_selectables (sel, results);
1079 RouteTimeAxisView::edit_group() const
1081 return _route->edit_group();
1085 RouteTimeAxisView::name() const
1087 return _route->name();
1091 RouteTimeAxisView::playlist () const
1093 boost::shared_ptr<Diskstream> ds;
1095 if ((ds = get_diskstream()) != 0) {
1096 return ds->playlist();
1103 RouteTimeAxisView::name_entry_changed ()
1107 x = name_entry.get_text ();
1109 if (x == _route->name()) {
1113 strip_whitespace_edges(x);
1115 if (x.length() == 0) {
1116 name_entry.set_text (_route->name());
1120 if (_session.route_name_unique (x)) {
1121 _route->set_name (x, this);
1123 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1124 name_entry.set_text (_route->name());
1129 RouteTimeAxisView::visual_click ()
1131 popup_display_menu (0);
1135 RouteTimeAxisView::hide_click ()
1137 // LAME fix for hide_button refresh fix
1138 hide_button.set_sensitive(false);
1140 editor.hide_track_in_display (*this);
1142 hide_button.set_sensitive(true);
1145 boost::shared_ptr<Region>
1146 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1148 boost::shared_ptr<Diskstream> stream;
1149 Playlist *playlist = 0;
1151 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1152 return playlist->find_next_region (pos, point, dir);
1155 return boost::shared_ptr<Region> ();
1159 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1161 Playlist* what_we_got;
1162 boost::shared_ptr<Diskstream> ds = get_diskstream();
1167 /* route is a bus, not a track */
1171 playlist = ds->playlist();
1174 TimeSelection time (selection.time);
1175 float speed = ds->speed();
1176 if (speed != 1.0f) {
1177 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1178 (*i).start = session_frame_to_track_frame((*i).start, speed);
1179 (*i).end = session_frame_to_track_frame((*i).end, speed);
1183 XMLNode &before = playlist->get_state();
1186 if ((what_we_got = playlist->cut (time)) != 0) {
1187 editor.get_cut_buffer().add (what_we_got);
1188 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1193 if ((what_we_got = playlist->copy (time)) != 0) {
1194 editor.get_cut_buffer().add (what_we_got);
1199 if ((what_we_got = playlist->cut (time)) != 0) {
1200 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1201 what_we_got->unref ();
1211 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1217 Playlist* playlist = get_diskstream()->playlist();
1218 PlaylistSelection::iterator p;
1220 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1222 if (p == selection.playlists.end()) {
1226 if (get_diskstream()->speed() != 1.0f)
1227 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1229 XMLNode &before = playlist->get_state();
1230 playlist->paste (**p, pos, times);
1231 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1238 RouteTimeAxisView::get_child_list()
1241 list<TimeAxisView*>redirect_children;
1243 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1244 if (!(*i)->hidden()) {
1245 redirect_children.push_back(*i);
1248 return redirect_children;
1253 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1255 using namespace Menu_Helpers;
1257 if (!menu || !is_track()) {
1261 MenuList& playlist_items = menu->items();
1262 menu->set_name ("ArdourContextMenu");
1263 playlist_items.clear();
1265 if (playlist_menu) {
1266 delete playlist_menu;
1269 playlist_menu = new Menu;
1270 playlist_menu->set_name ("ArdourContextMenu");
1272 vector<Playlist*> playlists;
1273 boost::shared_ptr<Diskstream> ds = get_diskstream();
1274 RadioMenuItem::Group playlist_group;
1276 _session.get_playlists (playlists);
1278 for (vector<Playlist*>::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1280 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1281 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist), (*i))));
1283 if (ds->playlist()->id() == (*i)->id()) {
1284 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1286 } else if (ds->playlist()->id() == (*i)->id()) {
1287 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist), (*i))));
1288 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1295 playlist_items.push_back (SeparatorElem());
1296 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1297 playlist_items.push_back (SeparatorElem());
1299 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1300 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1301 playlist_items.push_back (SeparatorElem());
1302 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1303 playlist_items.push_back (SeparatorElem());
1305 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1309 RouteTimeAxisView::use_playlist (Playlist* pl)
1311 AudioPlaylist* apl = dynamic_cast<AudioPlaylist*> (pl);
1313 assert (is_track());
1316 get_diskstream()->use_playlist (apl);
1321 RouteTimeAxisView::show_playlist_selector ()
1323 editor.playlist_selector().show_for (this);
1327 RouteTimeAxisView::map_frozen ()
1333 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1335 switch (track()->freeze_state()) {
1337 playlist_button.set_sensitive (false);
1338 rec_enable_button->set_sensitive (false);
1341 playlist_button.set_sensitive (true);
1342 rec_enable_button->set_sensitive (true);
1348 RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
1351 case cTimeStretchOutline:
1352 timestretch_rect->property_outline_color_rgba() = val;
1354 case cTimeStretchFill:
1355 timestretch_rect->property_fill_color_rgba() = val;
1363 RouteTimeAxisView::show_all_automation ()
1367 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1368 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1369 if ((*ii)->view == 0) {
1370 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1373 (*ii)->menu_item->set_active (true);
1379 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1383 RouteTimeAxisView::show_existing_automation ()
1387 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1388 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1389 if ((*ii)->view != 0) {
1390 (*ii)->menu_item->set_active (true);
1397 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1401 RouteTimeAxisView::hide_all_automation ()
1405 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1406 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1407 (*ii)->menu_item->set_active (false);
1412 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1417 RouteTimeAxisView::region_view_added (RegionView* rv)
1419 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1420 AutomationTimeAxisView* atv;
1422 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1423 rv->add_ghost (*atv);
1429 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1431 rv->add_ghost (*atv);
1434 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1436 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1442 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1444 parent.remove_ran (this);
1452 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1455 remove_child (ran->view);
1459 RouteTimeAxisView::RedirectAutomationNode*
1460 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1462 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1464 if ((*i)->redirect == redirect) {
1466 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1467 if ((*ii)->what == what) {
1477 // FIXME: duplicated in midi_time_axis.cc
1479 legalize_for_xml_node (string str)
1481 string::size_type pos;
1482 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1488 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1489 legal.replace (pos, 1, "_");
1498 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1500 RedirectAutomationLine* ral;
1502 RedirectAutomationNode* ran;
1504 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1505 fatal << _("programming error: ")
1506 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1507 redirect->name(), what)
1517 name = redirect->describe_parameter (what);
1519 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1521 char state_name[256];
1522 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1524 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1526 ral = new RedirectAutomationLine (name,
1527 *redirect, what, _session, *ran->view,
1528 *ran->view->canvas_display, redirect->automation_list (what));
1530 ral->set_line_color (color_map[cRedirectAutomationLine]);
1531 ral->queue_reset ();
1533 ran->view->add_line (*ral);
1535 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1537 if (!ran->view->marked_for_display()) {
1540 ran->menu_item->set_active (true);
1543 add_child (ran->view);
1545 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1547 redirect->mark_automation_visible (what, true);
1551 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1554 ran->menu_item->set_active (false);
1557 r->mark_automation_visible (ran->what, false);
1559 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1563 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1566 RedirectAutomationLine *ral;
1568 redirect->what_has_visible_automation (s);
1570 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1572 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1573 ral->queue_reset ();
1575 add_redirect_automation_curve (redirect, (*i));
1581 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1583 using namespace Menu_Helpers;
1584 RedirectAutomationInfo *rai;
1585 list<RedirectAutomationInfo*>::iterator x;
1587 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1588 std::set<uint32_t> has_visible_automation;
1590 r->what_has_visible_automation(has_visible_automation);
1592 if (automatable.empty()) {
1596 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1597 if ((*x)->redirect == r) {
1602 if (x == redirect_automation.end()) {
1604 rai = new RedirectAutomationInfo (r);
1605 redirect_automation.push_back (rai);
1613 /* any older menu was deleted at the top of redirects_changed()
1614 when we cleared the subplugin menu.
1617 rai->menu = manage (new Menu);
1618 MenuList& items = rai->menu->items();
1619 rai->menu->set_name ("ArdourContextMenu");
1623 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1625 RedirectAutomationNode* ran;
1626 CheckMenuItem* mitem;
1628 string name = r->describe_parameter (*i);
1630 items.push_back (CheckMenuElem (name));
1631 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1633 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1634 mitem->set_active(true);
1637 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1641 ran = new RedirectAutomationNode (*i, mitem, *this);
1643 rai->lines.push_back (ran);
1647 ran->menu_item = mitem;
1651 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1654 /* add the menu for this redirect, because the subplugin
1655 menu is always cleared at the top of redirects_changed().
1656 this is the result of some poor design in gtkmm and/or
1660 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1665 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1666 RouteTimeAxisView::RedirectAutomationNode* ran)
1668 bool showit = ran->menu_item->get_active();
1669 bool redraw = false;
1671 if (ran->view == 0 && showit) {
1672 add_redirect_automation_curve (rai->redirect, ran->what);
1676 if (showit != ran->view->marked_for_display()) {
1679 ran->view->set_marked_for_display (true);
1680 ran->view->canvas_display->show();
1682 rai->redirect->mark_automation_visible (ran->what, true);
1683 ran->view->set_marked_for_display (false);
1691 if (redraw && !no_redraw) {
1693 /* now trigger a redisplay */
1695 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1701 RouteTimeAxisView::redirects_changed (void *src)
1703 using namespace Menu_Helpers;
1705 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1706 (*i)->valid = false;
1709 subplugin_menu.items().clear ();
1711 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1712 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1714 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1716 list<RedirectAutomationInfo*>::iterator tmp;
1724 redirect_automation.erase (i);
1731 /* change in visibility was possible */
1733 _route->gui_changed ("track_height", this);
1736 RedirectAutomationLine *
1737 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1739 RedirectAutomationNode* ran;
1741 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1743 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1751 RouteTimeAxisView::reset_redirect_automation_curves ()
1753 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {