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")),
99 gpm.setup_atv_meter(50);
102 playlist_action_menu = 0;
103 automation_action_menu = 0;
105 timestretch_rect = 0;
108 ignore_toggle = false;
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), false);
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), false);
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->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press), false);
148 rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
149 controls_table.attach (*rec_enable_button, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
150 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
154 controls_hbox.pack_end(gpm);
155 _route->meter_change.connect (mem_fun(*this, &RouteTimeAxisView::meter_changed));
156 _route->input_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
157 _route->output_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
159 controls_table.attach (*mute_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
160 controls_table.attach (*solo_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
162 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
164 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
165 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
166 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
167 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
168 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
169 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
170 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
171 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
175 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
176 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
177 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
178 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
180 if (is_track() && track()->mode() == ARDOUR::Normal) {
181 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
184 /* remove focus from the buttons */
188 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
189 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
193 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
194 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
195 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
196 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
198 /* pick up the correct freeze state */
203 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
204 ColorsChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
207 RouteTimeAxisView::~RouteTimeAxisView ()
209 GoingAway (); /* EMIT_SIGNAL */
211 vector_delete (&redirect_automation_curves);
213 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
218 delete playlist_menu;
222 if (playlist_action_menu) {
223 delete playlist_action_menu;
224 playlist_action_menu = 0;
234 RouteTimeAxisView::post_construct ()
236 /* map current state of the route */
238 update_diskstream_display ();
239 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
240 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
241 reset_redirect_automation_curves ();
245 RouteTimeAxisView::set_playlist (boost::shared_ptr<Playlist> newplaylist)
247 boost::shared_ptr<Playlist> pl = playlist();
250 modified_connection.disconnect ();
251 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
255 RouteTimeAxisView::playlist_modified ()
260 RouteTimeAxisView::edit_click (GdkEventButton *ev)
262 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
263 _route->set_edit_group (0, this);
267 using namespace Menu_Helpers;
269 MenuList& items = edit_group_menu.items ();
270 RadioMenuItem::Group group;
273 items.push_back (RadioMenuElem (group, _("No group"),
274 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
276 if (_route->edit_group() == 0) {
277 static_cast<RadioMenuItem*>(&items.back())->set_active ();
280 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
281 edit_group_menu.popup (ev->button, ev->time);
287 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
289 using namespace Menu_Helpers;
291 MenuList &items = edit_group_menu.items();
293 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
294 if (_route->edit_group() == eg) {
295 static_cast<RadioMenuItem*>(&items.back())->set_active ();
300 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
302 _route->set_edit_group (eg, this);
306 RouteTimeAxisView::playlist_changed ()
311 set_playlist (get_diskstream()->playlist());
316 RouteTimeAxisView::label_view ()
318 string x = _route->name();
320 if (x != name_entry.get_text()) {
321 name_entry.set_text (x);
324 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
328 RouteTimeAxisView::route_name_changed (void *src)
330 editor.route_name_changed (this);
335 RouteTimeAxisView::take_name_changed (void *src)
344 RouteTimeAxisView::playlist_click ()
346 // always build a new action menu
348 if (playlist_action_menu != 0) {
349 delete playlist_action_menu;
352 playlist_action_menu = new Menu;
353 playlist_action_menu->set_name ("ArdourContextMenu");
355 build_playlist_menu (playlist_action_menu);
356 editor.set_selected_track (*this, Selection::Add);
357 playlist_action_menu->popup (1, gtk_get_current_event_time());
361 RouteTimeAxisView::automation_click ()
363 if (automation_action_menu == 0) {
364 /* this seems odd, but the automation action
365 menu is built as part of the display menu.
367 build_display_menu ();
369 editor.set_selected_track (*this, Selection::Add);
370 automation_action_menu->popup (1, gtk_get_current_event_time());
374 RouteTimeAxisView::build_automation_action_menu ()
376 using namespace Menu_Helpers;
378 automation_action_menu = manage (new Menu);
379 MenuList& automation_items = automation_action_menu->items();
380 automation_action_menu->set_name ("ArdourContextMenu");
382 automation_items.push_back (MenuElem (_("Show all automation"),
383 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
385 automation_items.push_back (MenuElem (_("Show existing automation"),
386 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
388 automation_items.push_back (MenuElem (_("Hide all automation"),
389 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
391 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
395 RouteTimeAxisView::build_display_menu ()
397 using namespace Menu_Helpers;
399 /* get the size menu ready */
405 TimeAxisView::build_display_menu ();
407 /* now fill it with our stuff */
409 MenuList& items = display_menu->items();
410 display_menu->set_name ("ArdourContextMenu");
412 items.push_back (MenuElem (_("Height"), *size_menu));
413 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
415 items.push_back (SeparatorElem());
417 build_remote_control_menu ();
418 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
420 build_automation_action_menu ();
421 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
423 // Hook for derived classes to add type specific stuff
424 items.push_back (SeparatorElem());
425 append_extra_display_menu_items ();
426 items.push_back (SeparatorElem());
430 Menu* alignment_menu = manage (new Menu);
431 MenuList& alignment_items = alignment_menu->items();
432 alignment_menu->set_name ("ArdourContextMenu");
434 RadioMenuItem::Group align_group;
436 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
437 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
438 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
439 if (get_diskstream()->alignment_style() == ExistingMaterial)
440 align_existing_item->set_active();
442 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
443 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
444 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
445 if (get_diskstream()->alignment_style() == CaptureTime)
446 align_capture_item->set_active();
448 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
450 get_diskstream()->AlignmentStyleChanged.connect (
451 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
453 RadioMenuItem::Group mode_group;
454 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
455 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
456 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
457 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
458 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
459 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
462 switch (track()->mode()) {
463 case ARDOUR::Destructive:
464 destructive_track_mode_item->set_active ();
467 normal_track_mode_item->set_active ();
472 items.push_back (SeparatorElem());
473 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
474 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
475 route_active_menu_item->set_active (_route->active());
477 items.push_back (SeparatorElem());
478 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
481 static bool __reset_item (RadioMenuItem* item)
488 RouteTimeAxisView::set_track_mode (TrackMode mode)
491 RadioMenuItem* other_item;
495 item = normal_track_mode_item;
496 other_item = destructive_track_mode_item;
498 case ARDOUR::Destructive:
499 item = destructive_track_mode_item;
500 other_item = normal_track_mode_item;
503 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
508 if (item->get_active () && track()->mode() != mode) {
509 _set_track_mode (track(), mode, other_item);
514 RouteTimeAxisView::_set_track_mode (boost::shared_ptr<Track> track, TrackMode mode, RadioMenuItem* reset_item)
518 if (!track->can_use_mode (mode, needs_bounce)) {
522 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
525 cerr << "would bounce this one\n";
530 track->set_mode (mode);
532 rec_enable_button->remove ();
535 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
537 case ARDOUR::Destructive:
538 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
541 rec_enable_button->show_all ();
546 RouteTimeAxisView::track_mode_changed ()
550 switch (track()->mode()) {
552 item = normal_track_mode_item;
554 case ARDOUR::Destructive:
555 item = destructive_track_mode_item;
558 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
567 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
573 TimeAxisView::show_timestretch (start, end);
583 /* check that the time selection was made in our route, or our edit group.
584 remember that edit_group() == 0 implies the route is *not* in a edit group.
587 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
588 /* this doesn't apply to us */
592 /* ignore it if our edit group is not active */
594 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
599 if (timestretch_rect == 0) {
600 timestretch_rect = new SimpleRect (*canvas_display);
601 timestretch_rect->property_x1() = 0.0;
602 timestretch_rect->property_y1() = 0.0;
603 timestretch_rect->property_x2() = 0.0;
604 timestretch_rect->property_y2() = 0.0;
605 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
606 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
609 timestretch_rect->show ();
610 timestretch_rect->raise_to_top ();
612 x1 = start / editor.get_current_zoom();
613 x2 = (end - 1) / editor.get_current_zoom();
616 timestretch_rect->property_x1() = x1;
617 timestretch_rect->property_y1() = 1.0;
618 timestretch_rect->property_x2() = x2;
619 timestretch_rect->property_y2() = y2;
623 RouteTimeAxisView::hide_timestretch ()
625 TimeAxisView::hide_timestretch ();
627 if (timestretch_rect) {
628 timestretch_rect->hide ();
633 RouteTimeAxisView::show_selection (TimeSelection& ts)
637 /* ignore it if our edit group is not active or if the selection was started
638 in some other track or edit group (remember that edit_group() == 0 means
639 that the track is not in an edit group).
642 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
643 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
649 TimeAxisView::show_selection (ts);
653 RouteTimeAxisView::set_height (TrackHeight h)
655 int gmlen = (height_to_pixels (h)) - 5;
656 bool height_changed = (height == 0) || (h != height_style);
657 gpm.setup_atv_meter (gmlen);
658 TimeAxisView::set_height (h);
663 _view->set_height ((double) height);
666 switch (height_style) {
668 xml_node->add_property ("track_height", "largest");
672 xml_node->add_property ("track_height", "large");
676 xml_node->add_property ("track_height", "larger");
680 xml_node->add_property ("track_height", "normal");
684 xml_node->add_property ("track_height", "smaller");
688 xml_node->add_property ("track_height", "small");
692 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();
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 ();
745 if (rec_enable_button)
746 rec_enable_button->hide();
748 edit_group_button.hide ();
750 visual_button.hide ();
752 automation_button.hide ();
753 playlist_button.hide ();
754 name_label.set_text (_route->name());
758 if (height_changed) {
759 /* only emit the signal if the height really changed */
760 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
765 RouteTimeAxisView::select_track_color ()
767 if (RouteUI::choose_color ()) {
770 _view->apply_color (_color, StreamView::RegionColor);
776 RouteTimeAxisView::reset_samples_per_unit ()
778 set_samples_per_unit (editor.get_current_zoom());
782 RouteTimeAxisView::set_samples_per_unit (double spu)
786 if (get_diskstream() != 0) {
787 speed = get_diskstream()->speed();
791 _view->set_samples_per_unit (spu * speed);
794 TimeAxisView::set_samples_per_unit (spu * speed);
798 RouteTimeAxisView::align_style_changed ()
800 switch (get_diskstream()->alignment_style()) {
801 case ExistingMaterial:
802 if (!align_existing_item->get_active()) {
803 align_existing_item->set_active();
807 if (!align_capture_item->get_active()) {
808 align_capture_item->set_active();
815 RouteTimeAxisView::set_align_style (AlignStyle style)
820 case ExistingMaterial:
821 item = align_existing_item;
824 item = align_capture_item;
827 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
832 if (item->get_active()) {
833 get_diskstream()->set_align_style (style);
838 RouteTimeAxisView::rename_current_playlist ()
840 ArdourPrompter prompter (true);
843 boost::shared_ptr<Diskstream> ds = get_diskstream();
844 if (!ds || ds->destructive())
847 boost::shared_ptr<Playlist> pl = ds->playlist();
851 prompter.set_prompt (_("Name for playlist"));
852 prompter.set_initial_text (pl->name());
853 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
854 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
856 switch (prompter.run ()) {
857 case Gtk::RESPONSE_ACCEPT:
858 prompter.get_result (name);
870 RouteTimeAxisView::use_copy_playlist (bool prompt)
874 boost::shared_ptr<Diskstream> ds = get_diskstream();
875 if (!ds || ds->destructive())
878 boost::shared_ptr<const Playlist> pl = ds->playlist();
885 name = Playlist::bump_name (name, _session);
886 } while (_session.playlist_by_name(name));
888 // TODO: The prompter "new" button should be de-activated if the user
889 // specifies a playlist name which already exists in the session.
893 ArdourPrompter prompter (true);
895 prompter.set_prompt (_("Name for Playlist"));
896 prompter.set_initial_text (name);
897 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
898 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
899 prompter.show_all ();
901 switch (prompter.run ()) {
902 case Gtk::RESPONSE_ACCEPT:
903 prompter.get_result (name);
912 ds->use_copy_playlist ();
913 ds->playlist()->set_name (name);
918 RouteTimeAxisView::use_new_playlist (bool prompt)
922 boost::shared_ptr<Diskstream> ds = get_diskstream();
923 if (!ds || ds->destructive())
926 boost::shared_ptr<const Playlist> pl = ds->playlist();
933 name = Playlist::bump_name (name, _session);
934 } while (_session.playlist_by_name(name));
939 ArdourPrompter prompter (true);
941 prompter.set_prompt (_("Name for Playlist"));
942 prompter.set_initial_text (name);
943 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
944 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
946 switch (prompter.run ()) {
947 case Gtk::RESPONSE_ACCEPT:
948 prompter.get_result (name);
957 ds->use_new_playlist ();
958 ds->playlist()->set_name (name);
963 RouteTimeAxisView::clear_playlist ()
965 boost::shared_ptr<Diskstream> ds = get_diskstream();
966 if (!ds || ds->destructive())
969 boost::shared_ptr<Playlist> pl = ds->playlist();
973 editor.clear_playlist (pl);
977 RouteTimeAxisView::speed_changed ()
979 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
983 RouteTimeAxisView::diskstream_changed ()
985 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
989 RouteTimeAxisView::update_diskstream_display ()
991 if (!get_diskstream()) // bus
994 set_playlist (get_diskstream()->playlist());
999 RouteTimeAxisView::selection_click (GdkEventButton* ev)
1001 if (Keyboard::modifier_state_equals (ev->state, (Keyboard::Shift|Keyboard::Control))) {
1003 /* special case: select/deselect all tracks */
1004 if (editor.get_selection().selected (this)) {
1005 editor.get_selection().clear_tracks ();
1007 editor.select_all_tracks ();
1013 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1015 switch (Keyboard::selection_type (ev->state)) {
1016 case Selection::Toggle:
1017 editor.get_selection().toggle (*tracks);
1020 case Selection::Set:
1021 editor.get_selection().set (*tracks);
1024 case Selection::Extend:
1025 if (tracks->size() > 1) {
1026 /* add each one, do not "extend" */
1027 editor.get_selection().add (*tracks);
1029 /* extend to the single track */
1030 editor.extend_selection_to_track (*tracks->front());
1034 case Selection::Add:
1035 editor.get_selection().add (*tracks);
1043 RouteTimeAxisView::set_selected_points (PointSelection& points)
1045 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1046 (*i)->set_selected_points (points);
1051 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1054 _view->set_selected_regionviews (regions);
1059 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1063 if (get_diskstream() != 0) {
1064 speed = get_diskstream()->speed();
1067 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1068 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1070 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1071 _view->get_selectables (start_adjusted, end_adjusted, results);
1074 /* pick up visible automation tracks */
1076 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1077 if (!(*i)->hidden()) {
1078 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1084 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1087 _view->get_inverted_selectables (sel, results);
1090 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1091 if (!(*i)->hidden()) {
1092 (*i)->get_inverted_selectables (sel, results);
1100 RouteTimeAxisView::edit_group() const
1102 return _route->edit_group();
1106 RouteTimeAxisView::name() const
1108 return _route->name();
1111 boost::shared_ptr<Playlist>
1112 RouteTimeAxisView::playlist () const
1114 boost::shared_ptr<Diskstream> ds;
1116 if ((ds = get_diskstream()) != 0) {
1117 return ds->playlist();
1119 return boost::shared_ptr<Playlist> ();
1124 RouteTimeAxisView::name_entry_changed ()
1128 x = name_entry.get_text ();
1130 if (x == _route->name()) {
1134 strip_whitespace_edges(x);
1136 if (x.length() == 0) {
1137 name_entry.set_text (_route->name());
1141 if (_session.route_name_unique (x)) {
1142 _route->set_name (x, this);
1144 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1145 name_entry.set_text (_route->name());
1150 RouteTimeAxisView::visual_click ()
1152 popup_display_menu (0);
1156 RouteTimeAxisView::hide_click ()
1158 // LAME fix for hide_button refresh fix
1159 hide_button.set_sensitive(false);
1161 editor.hide_track_in_display (*this);
1163 hide_button.set_sensitive(true);
1166 boost::shared_ptr<Region>
1167 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1169 boost::shared_ptr<Diskstream> stream;
1170 boost::shared_ptr<Playlist> playlist;
1172 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1173 return playlist->find_next_region (pos, point, dir);
1176 return boost::shared_ptr<Region> ();
1180 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1182 boost::shared_ptr<Playlist> what_we_got;
1183 boost::shared_ptr<Diskstream> ds = get_diskstream();
1184 boost::shared_ptr<Playlist> playlist;
1188 /* route is a bus, not a track */
1192 playlist = ds->playlist();
1194 TimeSelection time (selection.time);
1195 float speed = ds->speed();
1196 if (speed != 1.0f) {
1197 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1198 (*i).start = session_frame_to_track_frame((*i).start, speed);
1199 (*i).end = session_frame_to_track_frame((*i).end, speed);
1203 XMLNode &before = playlist->get_state();
1206 if ((what_we_got = playlist->cut (time)) != 0) {
1207 editor.get_cut_buffer().add (what_we_got);
1208 _session.add_command( new MementoCommand<Playlist>(*playlist.get(), &before, &playlist->get_state()));
1213 if ((what_we_got = playlist->copy (time)) != 0) {
1214 editor.get_cut_buffer().add (what_we_got);
1219 if ((what_we_got = playlist->cut (time)) != 0) {
1220 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1221 what_we_got->release ();
1231 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1237 boost::shared_ptr<Playlist> playlist = get_diskstream()->playlist();
1238 PlaylistSelection::iterator p;
1240 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1242 if (p == selection.playlists.end()) {
1246 if (get_diskstream()->speed() != 1.0f)
1247 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1249 XMLNode &before = playlist->get_state();
1250 playlist->paste (*p, pos, times);
1251 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1258 RouteTimeAxisView::get_child_list()
1261 list<TimeAxisView*>redirect_children;
1263 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1264 if (!(*i)->hidden()) {
1265 redirect_children.push_back(*i);
1268 return redirect_children;
1273 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1275 using namespace Menu_Helpers;
1277 if (!menu || !is_track()) {
1281 MenuList& playlist_items = menu->items();
1282 menu->set_name ("ArdourContextMenu");
1283 playlist_items.clear();
1285 if (playlist_menu) {
1286 delete playlist_menu;
1289 playlist_menu = new Menu;
1290 playlist_menu->set_name ("ArdourContextMenu");
1292 vector<boost::shared_ptr<Playlist> > playlists;
1293 boost::shared_ptr<Diskstream> ds = get_diskstream();
1294 RadioMenuItem::Group playlist_group;
1296 _session.get_playlists (playlists);
1298 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1300 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1301 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1302 boost::weak_ptr<Playlist> (*i))));
1304 if (ds->playlist()->id() == (*i)->id()) {
1305 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1307 } else if (ds->playlist()->id() == (*i)->id()) {
1308 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1309 boost::weak_ptr<Playlist>(*i))));
1310 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1315 playlist_items.push_back (SeparatorElem());
1316 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1317 playlist_items.push_back (SeparatorElem());
1319 playlist_items.push_back (MenuElem (_("New"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
1320 playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
1321 playlist_items.push_back (SeparatorElem());
1322 playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this)));
1323 playlist_items.push_back (SeparatorElem());
1325 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1329 RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
1331 assert (is_track());
1333 boost::shared_ptr<Playlist> pl (wpl.lock());
1339 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
1342 get_diskstream()->use_playlist (apl);
1347 RouteTimeAxisView::show_playlist_selector ()
1349 editor.playlist_selector().show_for (this);
1353 RouteTimeAxisView::map_frozen ()
1359 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1361 switch (track()->freeze_state()) {
1363 playlist_button.set_sensitive (false);
1364 rec_enable_button->set_sensitive (false);
1367 playlist_button.set_sensitive (true);
1368 rec_enable_button->set_sensitive (true);
1374 RouteTimeAxisView::color_handler ()
1376 if (timestretch_rect) {
1377 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
1380 if (timestretch_rect) {
1381 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
1386 RouteTimeAxisView::show_all_automation ()
1390 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1391 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1392 if ((*ii)->view == 0) {
1393 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1396 (*ii)->menu_item->set_active (true);
1402 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1406 RouteTimeAxisView::show_existing_automation ()
1410 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1411 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1412 if ((*ii)->view != 0) {
1413 (*ii)->menu_item->set_active (true);
1420 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1424 RouteTimeAxisView::hide_all_automation ()
1428 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1429 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1430 (*ii)->menu_item->set_active (false);
1435 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1440 RouteTimeAxisView::region_view_added (RegionView* rv)
1442 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1443 AutomationTimeAxisView* atv;
1445 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1446 rv->add_ghost (*atv);
1452 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1454 rv->add_ghost (*atv);
1457 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1459 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1465 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1467 parent.remove_ran (this);
1475 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1478 remove_child (ran->view);
1482 RouteTimeAxisView::RedirectAutomationNode*
1483 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1485 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1487 if ((*i)->redirect == redirect) {
1489 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1490 if ((*ii)->what == what) {
1500 // FIXME: duplicated in midi_time_axis.cc
1502 legalize_for_xml_node (string str)
1504 string::size_type pos;
1505 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=:";
1511 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1512 legal.replace (pos, 1, "_");
1521 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1523 RedirectAutomationLine* ral;
1525 RedirectAutomationNode* ran;
1527 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1528 fatal << _("programming error: ")
1529 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1530 redirect->name(), what)
1540 name = redirect->describe_parameter (what);
1542 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1544 char state_name[256];
1545 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1547 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1549 ral = new RedirectAutomationLine (name,
1550 *redirect, what, _session, *ran->view,
1551 *ran->view->canvas_display, redirect->automation_list (what));
1553 ral->set_line_color (ARDOUR_UI::config()->canvasvar_RedirectAutomationLine.get());
1554 ral->queue_reset ();
1556 ran->view->add_line (*ral);
1558 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1560 if (!ran->view->marked_for_display()) {
1563 ran->menu_item->set_active (true);
1566 add_child (ran->view);
1569 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1572 redirect->mark_automation_visible (what, true);
1576 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1579 ran->menu_item->set_active (false);
1582 r->mark_automation_visible (ran->what, false);
1584 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1588 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1591 RedirectAutomationLine *ral;
1593 redirect->what_has_visible_automation (s);
1595 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1597 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1598 ral->queue_reset ();
1600 add_redirect_automation_curve (redirect, (*i));
1606 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1608 using namespace Menu_Helpers;
1609 RedirectAutomationInfo *rai;
1610 list<RedirectAutomationInfo*>::iterator x;
1612 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1613 std::set<uint32_t> has_visible_automation;
1615 r->what_has_visible_automation(has_visible_automation);
1617 if (automatable.empty()) {
1621 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1622 if ((*x)->redirect == r) {
1627 if (x == redirect_automation.end()) {
1629 rai = new RedirectAutomationInfo (r);
1630 redirect_automation.push_back (rai);
1638 /* any older menu was deleted at the top of redirects_changed()
1639 when we cleared the subplugin menu.
1642 rai->menu = manage (new Menu);
1643 MenuList& items = rai->menu->items();
1644 rai->menu->set_name ("ArdourContextMenu");
1648 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1650 RedirectAutomationNode* ran;
1651 CheckMenuItem* mitem;
1653 string name = r->describe_parameter (*i);
1655 items.push_back (CheckMenuElem (name));
1656 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1658 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1659 mitem->set_active(true);
1662 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1666 ran = new RedirectAutomationNode (*i, mitem, *this);
1668 rai->lines.push_back (ran);
1672 ran->menu_item = mitem;
1676 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1679 /* add the menu for this redirect, because the subplugin
1680 menu is always cleared at the top of redirects_changed().
1681 this is the result of some poor design in gtkmm and/or
1685 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1690 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1691 RouteTimeAxisView::RedirectAutomationNode* ran)
1693 bool showit = ran->menu_item->get_active();
1694 bool redraw = false;
1696 if (ran->view == 0 && showit) {
1697 add_redirect_automation_curve (rai->redirect, ran->what);
1701 if (showit != ran->view->marked_for_display()) {
1704 ran->view->set_marked_for_display (true);
1705 ran->view->canvas_display->show();
1707 rai->redirect->mark_automation_visible (ran->what, true);
1708 ran->view->set_marked_for_display (false);
1716 if (redraw && !no_redraw) {
1718 /* now trigger a redisplay */
1720 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1726 RouteTimeAxisView::redirects_changed (void *src)
1728 using namespace Menu_Helpers;
1730 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1731 (*i)->valid = false;
1734 subplugin_menu.items().clear ();
1736 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1737 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1739 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1741 list<RedirectAutomationInfo*>::iterator tmp;
1749 redirect_automation.erase (i);
1756 /* change in visibility was possible */
1758 _route->gui_changed ("track_height", this);
1761 RedirectAutomationLine *
1762 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1764 RedirectAutomationNode* ran;
1766 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1768 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1776 RouteTimeAxisView::reset_redirect_automation_curves ()
1778 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {
1784 RouteTimeAxisView::update_rec_display ()
1786 RouteUI::update_rec_display ();
1787 name_entry.set_sensitive (!_route->record_enabled());
1791 RouteTimeAxisView::fast_update ()
1793 gpm.update_meters ();
1797 RouteTimeAxisView::hide_meter ()
1803 RouteTimeAxisView::show_meter ()
1809 RouteTimeAxisView::reset_meter ()
1811 gpm.setup_atv_meter (height-5);
1815 RouteTimeAxisView::clear_meter ()
1817 gpm.clear_meters ();
1821 RouteTimeAxisView::meter_changed (void *src)
1823 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::meter_changed), src));
1828 RouteTimeAxisView::io_changed (IOChange change, void *src)