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>
53 #include <ardour/profile.h>
55 #include "ardour_ui.h"
56 #include "route_time_axis.h"
57 #include "automation_time_axis.h"
58 #include "redirect_automation_time_axis.h"
59 #include "redirect_automation_line.h"
60 #include "canvas_impl.h"
61 #include "crossfade_view.h"
63 #include "gui_thread.h"
65 #include "playlist_selector.h"
66 #include "point_selection.h"
68 #include "public_editor.h"
69 #include "region_view.h"
70 #include "rgb_macros.h"
71 #include "selection.h"
72 #include "simplerect.h"
73 #include "streamview.h"
76 #include <ardour/track.h>
80 using namespace ARDOUR;
83 using namespace Editing;
86 RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
88 RouteUI(rt, sess, _("m"), _("s"), _("r")), // mute, solo, and record
89 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
90 parent_canvas (canvas),
92 edit_group_button (_("g")), // group
93 playlist_button (_("p")),
94 size_button (_("h")), // height
95 automation_button (_("a")),
96 visual_button (_("v")),
100 lm.set_no_show_all();
104 playlist_action_menu = 0;
105 automation_action_menu = 0;
107 timestretch_rect = 0;
109 destructive_track_mode_item = 0;
110 normal_track_mode_item = 0;
112 ignore_toggle = false;
114 edit_group_button.set_name ("TrackGroupButton");
115 playlist_button.set_name ("TrackPlaylistButton");
116 automation_button.set_name ("TrackAutomationButton");
117 size_button.set_name ("TrackSizeButton");
118 visual_button.set_name ("TrackVisualButton");
119 hide_button.set_name ("TrackRemoveButton");
121 hide_button.add (*(manage (new Image (::get_icon("hide")))));
122 hide_button.show_all ();
124 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
125 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
126 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
127 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
128 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
129 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
131 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
132 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release));
133 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
134 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release));
140 rec_enable_button->remove ();
141 switch (track()->mode()) {
143 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
145 case ARDOUR::Destructive:
146 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
149 rec_enable_button->show_all ();
151 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press), false);
152 rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
153 controls_table.attach (*rec_enable_button, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
154 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
158 controls_hbox.pack_start(lm, false, false);
159 _route->meter_change.connect (mem_fun(*this, &RouteTimeAxisView::meter_changed));
160 _route->input_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
161 _route->output_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
163 controls_table.attach (*mute_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
164 controls_table.attach (*solo_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
166 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
168 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
169 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
170 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
171 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
172 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
173 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
174 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
175 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
181 /* old school - when we used to put an extra row of buttons in place */
183 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
184 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
185 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
186 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
190 controls_table.attach (automation_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
193 if (is_track() && track()->mode() == ARDOUR::Normal) {
194 controls_table.attach (playlist_button, 4, 5, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
199 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
200 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
204 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
205 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
206 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
207 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
209 /* pick up the correct freeze state */
214 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
215 ColorsChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
218 RouteTimeAxisView::~RouteTimeAxisView ()
220 GoingAway (); /* EMIT_SIGNAL */
222 vector_delete (&redirect_automation_curves);
224 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
229 delete playlist_menu;
233 if (playlist_action_menu) {
234 delete playlist_action_menu;
235 playlist_action_menu = 0;
245 RouteTimeAxisView::post_construct ()
247 /* map current state of the route */
249 update_diskstream_display ();
250 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
251 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
252 reset_redirect_automation_curves ();
256 RouteTimeAxisView::set_playlist (boost::shared_ptr<Playlist> newplaylist)
258 boost::shared_ptr<Playlist> pl = playlist();
261 modified_connection.disconnect ();
262 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
266 RouteTimeAxisView::playlist_modified ()
271 RouteTimeAxisView::edit_click (GdkEventButton *ev)
273 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
274 _route->set_edit_group (0, this);
278 using namespace Menu_Helpers;
280 MenuList& items = edit_group_menu.items ();
281 RadioMenuItem::Group group;
284 items.push_back (RadioMenuElem (group, _("No group"),
285 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
287 if (_route->edit_group() == 0) {
288 static_cast<RadioMenuItem*>(&items.back())->set_active ();
291 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
292 edit_group_menu.popup (ev->button, ev->time);
298 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
300 using namespace Menu_Helpers;
302 MenuList &items = edit_group_menu.items();
304 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
305 if (_route->edit_group() == eg) {
306 static_cast<RadioMenuItem*>(&items.back())->set_active ();
311 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
313 _route->set_edit_group (eg, this);
317 RouteTimeAxisView::playlist_changed ()
322 set_playlist (get_diskstream()->playlist());
327 RouteTimeAxisView::label_view ()
329 string x = _route->name();
331 if (x != name_entry.get_text()) {
332 name_entry.set_text (x);
335 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
339 RouteTimeAxisView::route_name_changed (void *src)
341 editor.route_name_changed (this);
346 RouteTimeAxisView::take_name_changed (void *src)
355 RouteTimeAxisView::playlist_click ()
357 // always build a new action menu
359 if (playlist_action_menu != 0) {
360 delete playlist_action_menu;
363 playlist_action_menu = new Menu;
364 playlist_action_menu->set_name ("ArdourContextMenu");
366 build_playlist_menu (playlist_action_menu);
367 editor.set_selected_track (*this, Selection::Add);
368 playlist_action_menu->popup (1, gtk_get_current_event_time());
372 RouteTimeAxisView::automation_click ()
374 if (automation_action_menu == 0) {
375 /* this seems odd, but the automation action
376 menu is built as part of the display menu.
378 build_display_menu ();
380 editor.set_selected_track (*this, Selection::Add);
381 automation_action_menu->popup (1, gtk_get_current_event_time());
385 RouteTimeAxisView::build_automation_action_menu ()
387 using namespace Menu_Helpers;
389 automation_action_menu = manage (new Menu);
390 MenuList& automation_items = automation_action_menu->items();
391 automation_action_menu->set_name ("ArdourContextMenu");
393 automation_items.push_back (MenuElem (_("Show all automation"),
394 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
396 automation_items.push_back (MenuElem (_("Show existing automation"),
397 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
399 automation_items.push_back (MenuElem (_("Hide all automation"),
400 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
402 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
406 RouteTimeAxisView::build_display_menu ()
408 using namespace Menu_Helpers;
410 /* get the size menu ready */
416 TimeAxisView::build_display_menu ();
418 /* now fill it with our stuff */
420 MenuList& items = display_menu->items();
421 display_menu->set_name ("ArdourContextMenu");
423 items.push_back (MenuElem (_("Height"), *size_menu));
424 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
426 items.push_back (SeparatorElem());
428 build_remote_control_menu ();
429 build_automation_action_menu ();
431 if (!Profile->get_sae()) {
432 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
433 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
434 items.push_back (SeparatorElem());
437 // Hook for derived classes to add type specific stuff
438 append_extra_display_menu_items ();
439 items.push_back (SeparatorElem());
443 Menu* alignment_menu = manage (new Menu);
444 MenuList& alignment_items = alignment_menu->items();
445 alignment_menu->set_name ("ArdourContextMenu");
447 RadioMenuItem::Group align_group;
449 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
450 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
451 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
452 if (get_diskstream()->alignment_style() == ExistingMaterial)
453 align_existing_item->set_active();
455 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
456 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
457 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
458 if (get_diskstream()->alignment_style() == CaptureTime)
459 align_capture_item->set_active();
461 if (!Profile->get_sae()) {
462 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
463 get_diskstream()->AlignmentStyleChanged.connect (mem_fun(*this, &RouteTimeAxisView::align_style_changed));
465 RadioMenuItem::Group mode_group;
466 items.push_back (RadioMenuElem (mode_group, _("Normal mode"),
467 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Normal)));
468 normal_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
469 items.push_back (RadioMenuElem (mode_group, _("Tape mode"),
470 bind (mem_fun (*this, &RouteTimeAxisView::set_track_mode), ARDOUR::Destructive)));
471 destructive_track_mode_item = dynamic_cast<RadioMenuItem*>(&items.back());
473 switch (track()->mode()) {
474 case ARDOUR::Destructive:
475 destructive_track_mode_item->set_active ();
478 normal_track_mode_item->set_active ();
482 items.push_back (SeparatorElem());
486 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
487 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
488 route_active_menu_item->set_active (_route->active());
490 items.push_back (SeparatorElem());
491 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
494 static bool __reset_item (RadioMenuItem* item)
501 RouteTimeAxisView::set_track_mode (TrackMode mode)
504 RadioMenuItem* other_item;
508 item = normal_track_mode_item;
509 other_item = destructive_track_mode_item;
511 case ARDOUR::Destructive:
512 item = destructive_track_mode_item;
513 other_item = normal_track_mode_item;
516 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
521 if (item && other_item && item->get_active () && track()->mode() != mode) {
522 _set_track_mode (track(), mode, other_item);
527 RouteTimeAxisView::_set_track_mode (boost::shared_ptr<Track> track, TrackMode mode, RadioMenuItem* reset_item)
531 if (!track->can_use_mode (mode, needs_bounce)) {
535 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
538 cerr << "would bounce this one\n";
543 track->set_mode (mode);
545 rec_enable_button->remove ();
548 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
550 case ARDOUR::Destructive:
551 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
554 rec_enable_button->show_all ();
559 RouteTimeAxisView::track_mode_changed ()
563 switch (track()->mode()) {
565 item = normal_track_mode_item;
567 case ARDOUR::Destructive:
568 item = destructive_track_mode_item;
571 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
580 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
586 TimeAxisView::show_timestretch (start, end);
596 /* check that the time selection was made in our route, or our edit group.
597 remember that edit_group() == 0 implies the route is *not* in a edit group.
600 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
601 /* this doesn't apply to us */
605 /* ignore it if our edit group is not active */
607 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
612 if (timestretch_rect == 0) {
613 timestretch_rect = new SimpleRect (*canvas_display);
614 timestretch_rect->property_x1() = 0.0;
615 timestretch_rect->property_y1() = 0.0;
616 timestretch_rect->property_x2() = 0.0;
617 timestretch_rect->property_y2() = 0.0;
618 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
619 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
622 timestretch_rect->show ();
623 timestretch_rect->raise_to_top ();
625 x1 = start / editor.get_current_zoom();
626 x2 = (end - 1) / editor.get_current_zoom();
629 timestretch_rect->property_x1() = x1;
630 timestretch_rect->property_y1() = 1.0;
631 timestretch_rect->property_x2() = x2;
632 timestretch_rect->property_y2() = y2;
636 RouteTimeAxisView::hide_timestretch ()
638 TimeAxisView::hide_timestretch ();
640 if (timestretch_rect) {
641 timestretch_rect->hide ();
646 RouteTimeAxisView::show_selection (TimeSelection& ts)
650 /* ignore it if our edit group is not active or if the selection was started
651 in some other track or edit group (remember that edit_group() == 0 means
652 that the track is not in an edit group).
655 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
656 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
662 TimeAxisView::show_selection (ts);
666 RouteTimeAxisView::set_height (TrackHeight h)
668 int gmlen = (height_to_pixels (h)) - 5;
669 bool height_changed = (height == 0) || (h != height_style);
670 lm.setup_meters (gmlen);
671 TimeAxisView::set_height (h);
676 _view->set_height ((double) height);
679 switch (height_style) {
681 xml_node->add_property ("track_height", "largest");
685 xml_node->add_property ("track_height", "large");
689 xml_node->add_property ("track_height", "larger");
693 xml_node->add_property ("track_height", "normal");
697 xml_node->add_property ("track_height", "smaller");
701 xml_node->add_property ("track_height", "small");
705 switch (height_style) {
716 if (rec_enable_button)
717 rec_enable_button->show();
719 edit_group_button.show();
721 visual_button.show();
723 automation_button.show();
725 if (is_track() && track()->mode() == ARDOUR::Normal) {
726 playlist_button.show();
737 if (rec_enable_button)
738 rec_enable_button->show();
740 edit_group_button.hide ();
742 visual_button.hide ();
744 automation_button.hide ();
746 if (is_track() && track()->mode() == ARDOUR::Normal) {
747 playlist_button.hide ();
758 if (rec_enable_button)
759 rec_enable_button->hide();
761 edit_group_button.hide ();
763 visual_button.hide ();
765 automation_button.hide ();
766 playlist_button.hide ();
767 name_label.set_text (_route->name());
771 if (height_changed) {
772 /* only emit the signal if the height really changed */
773 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
778 RouteTimeAxisView::select_track_color ()
780 if (RouteUI::choose_color ()) {
783 _view->apply_color (_color, StreamView::RegionColor);
789 RouteTimeAxisView::reset_samples_per_unit ()
791 set_samples_per_unit (editor.get_current_zoom());
795 RouteTimeAxisView::set_samples_per_unit (double spu)
799 if (get_diskstream() != 0) {
800 speed = get_diskstream()->speed();
804 _view->set_samples_per_unit (spu * speed);
807 TimeAxisView::set_samples_per_unit (spu * speed);
811 RouteTimeAxisView::align_style_changed ()
813 switch (get_diskstream()->alignment_style()) {
814 case ExistingMaterial:
815 if (!align_existing_item->get_active()) {
816 align_existing_item->set_active();
820 if (!align_capture_item->get_active()) {
821 align_capture_item->set_active();
828 RouteTimeAxisView::set_align_style (AlignStyle style)
833 case ExistingMaterial:
834 item = align_existing_item;
837 item = align_capture_item;
840 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
845 if (item->get_active()) {
846 get_diskstream()->set_align_style (style);
851 RouteTimeAxisView::rename_current_playlist ()
853 ArdourPrompter prompter (true);
856 boost::shared_ptr<Diskstream> ds = get_diskstream();
857 if (!ds || ds->destructive())
860 boost::shared_ptr<Playlist> pl = ds->playlist();
864 prompter.set_prompt (_("Name for playlist"));
865 prompter.set_initial_text (pl->name());
866 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
867 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
869 switch (prompter.run ()) {
870 case Gtk::RESPONSE_ACCEPT:
871 prompter.get_result (name);
883 RouteTimeAxisView::use_copy_playlist (bool prompt)
887 boost::shared_ptr<Diskstream> ds = get_diskstream();
888 if (!ds || ds->destructive())
891 boost::shared_ptr<const Playlist> pl = ds->playlist();
898 name = Playlist::bump_name (name, _session);
899 } while (_session.playlist_by_name(name));
901 // TODO: The prompter "new" button should be de-activated if the user
902 // specifies a playlist name which already exists in the session.
906 ArdourPrompter prompter (true);
908 prompter.set_prompt (_("Name for Playlist"));
909 prompter.set_initial_text (name);
910 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
911 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
912 prompter.show_all ();
914 switch (prompter.run ()) {
915 case Gtk::RESPONSE_ACCEPT:
916 prompter.get_result (name);
925 ds->use_copy_playlist ();
926 ds->playlist()->set_name (name);
931 RouteTimeAxisView::use_new_playlist (bool prompt)
935 boost::shared_ptr<Diskstream> ds = get_diskstream();
936 if (!ds || ds->destructive())
939 boost::shared_ptr<const Playlist> pl = ds->playlist();
946 name = Playlist::bump_name (name, _session);
947 } while (_session.playlist_by_name(name));
952 ArdourPrompter prompter (true);
954 prompter.set_prompt (_("Name for Playlist"));
955 prompter.set_initial_text (name);
956 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
957 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
959 switch (prompter.run ()) {
960 case Gtk::RESPONSE_ACCEPT:
961 prompter.get_result (name);
970 ds->use_new_playlist ();
971 ds->playlist()->set_name (name);
976 RouteTimeAxisView::clear_playlist ()
978 boost::shared_ptr<Diskstream> ds = get_diskstream();
979 if (!ds || ds->destructive())
982 boost::shared_ptr<Playlist> pl = ds->playlist();
986 editor.clear_playlist (pl);
990 RouteTimeAxisView::speed_changed ()
992 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
996 RouteTimeAxisView::diskstream_changed ()
998 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
1002 RouteTimeAxisView::update_diskstream_display ()
1004 if (!get_diskstream()) // bus
1007 set_playlist (get_diskstream()->playlist());
1012 RouteTimeAxisView::selection_click (GdkEventButton* ev)
1014 if (Keyboard::modifier_state_equals (ev->state, (Keyboard::TertiaryModifier|Keyboard::PrimaryModifier))) {
1016 /* special case: select/deselect all tracks */
1017 if (editor.get_selection().selected (this)) {
1018 editor.get_selection().clear_tracks ();
1020 editor.select_all_tracks ();
1026 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1028 switch (Keyboard::selection_type (ev->state)) {
1029 case Selection::Toggle:
1030 editor.get_selection().toggle (*tracks);
1033 case Selection::Set:
1034 editor.get_selection().set (*tracks);
1037 case Selection::Extend:
1038 if (tracks->size() > 1) {
1039 /* add each one, do not "extend" */
1040 editor.get_selection().add (*tracks);
1042 /* extend to the single track */
1043 editor.extend_selection_to_track (*tracks->front());
1047 case Selection::Add:
1048 editor.get_selection().add (*tracks);
1056 RouteTimeAxisView::set_selected_points (PointSelection& points)
1058 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1059 (*i)->set_selected_points (points);
1064 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1067 _view->set_selected_regionviews (regions);
1072 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1076 if (get_diskstream() != 0) {
1077 speed = get_diskstream()->speed();
1080 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1081 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1083 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1084 _view->get_selectables (start_adjusted, end_adjusted, results);
1087 /* pick up visible automation tracks */
1089 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1090 if (!(*i)->hidden()) {
1091 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1097 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1100 _view->get_inverted_selectables (sel, results);
1103 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1104 if (!(*i)->hidden()) {
1105 (*i)->get_inverted_selectables (sel, results);
1113 RouteTimeAxisView::edit_group() const
1115 return _route->edit_group();
1119 RouteTimeAxisView::name() const
1121 return _route->name();
1124 boost::shared_ptr<Playlist>
1125 RouteTimeAxisView::playlist () const
1127 boost::shared_ptr<Diskstream> ds;
1129 if ((ds = get_diskstream()) != 0) {
1130 return ds->playlist();
1132 return boost::shared_ptr<Playlist> ();
1137 RouteTimeAxisView::name_entry_changed ()
1141 x = name_entry.get_text ();
1143 if (x == _route->name()) {
1147 strip_whitespace_edges(x);
1149 if (x.length() == 0) {
1150 name_entry.set_text (_route->name());
1154 if (_session.route_name_unique (x)) {
1155 _route->set_name (x, this);
1157 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1158 name_entry.set_text (_route->name());
1163 RouteTimeAxisView::visual_click ()
1165 popup_display_menu (0);
1169 RouteTimeAxisView::hide_click ()
1171 // LAME fix for hide_button refresh fix
1172 hide_button.set_sensitive(false);
1174 editor.hide_track_in_display (*this);
1176 hide_button.set_sensitive(true);
1179 boost::shared_ptr<Region>
1180 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1182 boost::shared_ptr<Diskstream> stream;
1183 boost::shared_ptr<Playlist> playlist;
1185 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1186 return playlist->find_next_region (pos, point, dir);
1189 return boost::shared_ptr<Region> ();
1193 RouteTimeAxisView::find_next_region_boundary (nframes64_t pos, int32_t dir)
1195 boost::shared_ptr<Diskstream> stream;
1196 boost::shared_ptr<Playlist> playlist;
1198 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1199 return playlist->find_next_region_boundary (pos, dir);
1206 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1208 boost::shared_ptr<Playlist> what_we_got;
1209 boost::shared_ptr<Diskstream> ds = get_diskstream();
1210 boost::shared_ptr<Playlist> playlist;
1214 /* route is a bus, not a track */
1218 playlist = ds->playlist();
1220 TimeSelection time (selection.time);
1221 float speed = ds->speed();
1222 if (speed != 1.0f) {
1223 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1224 (*i).start = session_frame_to_track_frame((*i).start, speed);
1225 (*i).end = session_frame_to_track_frame((*i).end, speed);
1229 XMLNode &before = playlist->get_state();
1232 if ((what_we_got = playlist->cut (time)) != 0) {
1233 editor.get_cut_buffer().add (what_we_got);
1234 _session.add_command( new MementoCommand<Playlist>(*playlist.get(), &before, &playlist->get_state()));
1239 if ((what_we_got = playlist->copy (time)) != 0) {
1240 editor.get_cut_buffer().add (what_we_got);
1245 if ((what_we_got = playlist->cut (time)) != 0) {
1246 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1247 what_we_got->release ();
1257 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1263 boost::shared_ptr<Playlist> playlist = get_diskstream()->playlist();
1264 PlaylistSelection::iterator p;
1266 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1268 if (p == selection.playlists.end()) {
1272 if (get_diskstream()->speed() != 1.0f)
1273 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1275 XMLNode &before = playlist->get_state();
1276 playlist->paste (*p, pos, times);
1277 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1284 RouteTimeAxisView::get_child_list()
1287 list<TimeAxisView*>redirect_children;
1289 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1290 if (!(*i)->hidden()) {
1291 redirect_children.push_back(*i);
1294 return redirect_children;
1299 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1301 using namespace Menu_Helpers;
1303 if (!menu || !is_track()) {
1307 MenuList& playlist_items = menu->items();
1308 menu->set_name ("ArdourContextMenu");
1309 playlist_items.clear();
1311 if (playlist_menu) {
1312 delete playlist_menu;
1315 playlist_menu = new Menu;
1316 playlist_menu->set_name ("ArdourContextMenu");
1318 vector<boost::shared_ptr<Playlist> > playlists;
1319 boost::shared_ptr<Diskstream> ds = get_diskstream();
1320 RadioMenuItem::Group playlist_group;
1322 _session.get_playlists (playlists);
1324 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1326 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1327 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1328 boost::weak_ptr<Playlist> (*i))));
1330 if (ds->playlist()->id() == (*i)->id()) {
1331 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1333 } else if (ds->playlist()->id() == (*i)->id()) {
1334 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1335 boost::weak_ptr<Playlist>(*i))));
1336 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1341 playlist_items.push_back (SeparatorElem());
1342 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1343 playlist_items.push_back (SeparatorElem());
1345 playlist_items.push_back (MenuElem (_("New"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
1346 playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
1347 playlist_items.push_back (SeparatorElem());
1348 playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this)));
1349 playlist_items.push_back (SeparatorElem());
1351 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1355 RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
1357 assert (is_track());
1359 boost::shared_ptr<Playlist> pl (wpl.lock());
1365 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
1368 get_diskstream()->use_playlist (apl);
1373 RouteTimeAxisView::show_playlist_selector ()
1375 editor.playlist_selector().show_for (this);
1379 RouteTimeAxisView::map_frozen ()
1385 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1387 switch (track()->freeze_state()) {
1389 playlist_button.set_sensitive (false);
1390 rec_enable_button->set_sensitive (false);
1393 playlist_button.set_sensitive (true);
1394 rec_enable_button->set_sensitive (true);
1400 RouteTimeAxisView::color_handler ()
1402 if (timestretch_rect) {
1403 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
1406 if (timestretch_rect) {
1407 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
1414 RouteTimeAxisView::show_all_automation ()
1418 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1419 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1420 if ((*ii)->view == 0) {
1421 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1424 (*ii)->menu_item->set_active (true);
1430 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1434 RouteTimeAxisView::show_existing_automation ()
1438 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1439 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1440 if ((*ii)->view != 0) {
1441 (*ii)->menu_item->set_active (true);
1448 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1452 RouteTimeAxisView::hide_all_automation ()
1456 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1457 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1458 (*ii)->menu_item->set_active (false);
1463 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1468 RouteTimeAxisView::region_view_added (RegionView* rv)
1470 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1471 AutomationTimeAxisView* atv;
1473 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1474 rv->add_ghost (*atv);
1480 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1482 rv->add_ghost (*atv);
1485 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1487 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1493 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1495 parent.remove_ran (this);
1503 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1506 remove_child (ran->view);
1510 RouteTimeAxisView::RedirectAutomationNode*
1511 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1513 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1515 if ((*i)->redirect == redirect) {
1517 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1518 if ((*ii)->what == what) {
1528 // FIXME: duplicated in midi_time_axis.cc
1530 legalize_for_xml_node (string str)
1532 string::size_type pos;
1533 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=:";
1539 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1540 legal.replace (pos, 1, "_");
1549 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1551 RedirectAutomationLine* ral;
1553 RedirectAutomationNode* ran;
1555 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1556 fatal << _("programming error: ")
1557 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1558 redirect->name(), what)
1568 name = redirect->describe_parameter (what);
1570 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1572 char state_name[256];
1573 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1575 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1577 ral = new RedirectAutomationLine (name,
1578 *redirect, what, _session, *ran->view,
1579 *ran->view->canvas_display, redirect->automation_list (what));
1581 ral->set_line_color (ARDOUR_UI::config()->canvasvar_RedirectAutomationLine.get());
1582 ral->queue_reset ();
1584 ran->view->add_line (*ral);
1586 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1588 if (!ran->view->marked_for_display()) {
1591 ran->menu_item->set_active (true);
1594 add_child (ran->view);
1597 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1600 redirect->mark_automation_visible (what, true);
1604 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1607 ran->menu_item->set_active (false);
1610 r->mark_automation_visible (ran->what, false);
1612 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1616 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1619 RedirectAutomationLine *ral;
1621 redirect->what_has_visible_automation (s);
1623 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1625 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1626 ral->queue_reset ();
1628 add_redirect_automation_curve (redirect, (*i));
1634 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1636 using namespace Menu_Helpers;
1637 RedirectAutomationInfo *rai;
1638 list<RedirectAutomationInfo*>::iterator x;
1640 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1641 std::set<uint32_t> has_visible_automation;
1643 r->what_has_visible_automation(has_visible_automation);
1645 if (automatable.empty()) {
1649 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1650 if ((*x)->redirect == r) {
1655 if (x == redirect_automation.end()) {
1657 rai = new RedirectAutomationInfo (r);
1658 redirect_automation.push_back (rai);
1666 /* any older menu was deleted at the top of redirects_changed()
1667 when we cleared the subplugin menu.
1670 rai->menu = manage (new Menu);
1671 MenuList& items = rai->menu->items();
1672 rai->menu->set_name ("ArdourContextMenu");
1676 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1678 RedirectAutomationNode* ran;
1679 CheckMenuItem* mitem;
1681 string name = r->describe_parameter (*i);
1683 items.push_back (CheckMenuElem (name));
1684 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1686 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1687 mitem->set_active(true);
1690 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1694 ran = new RedirectAutomationNode (*i, mitem, *this);
1696 rai->lines.push_back (ran);
1700 ran->menu_item = mitem;
1704 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1707 /* add the menu for this redirect, because the subplugin
1708 menu is always cleared at the top of redirects_changed().
1709 this is the result of some poor design in gtkmm and/or
1713 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1718 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1719 RouteTimeAxisView::RedirectAutomationNode* ran)
1721 bool showit = ran->menu_item->get_active();
1722 bool redraw = false;
1724 if (ran->view == 0 && showit) {
1725 add_redirect_automation_curve (rai->redirect, ran->what);
1729 if (showit != ran->view->marked_for_display()) {
1732 ran->view->set_marked_for_display (true);
1733 ran->view->canvas_display->show();
1735 rai->redirect->mark_automation_visible (ran->what, true);
1736 ran->view->set_marked_for_display (false);
1744 if (redraw && !no_redraw) {
1746 /* now trigger a redisplay */
1748 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1754 RouteTimeAxisView::redirects_changed (void *src)
1756 using namespace Menu_Helpers;
1758 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1759 (*i)->valid = false;
1762 subplugin_menu.items().clear ();
1764 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1765 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1767 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1769 list<RedirectAutomationInfo*>::iterator tmp;
1777 redirect_automation.erase (i);
1784 /* change in visibility was possible */
1786 _route->gui_changed ("track_height", this);
1789 RedirectAutomationLine *
1790 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1792 RedirectAutomationNode* ran;
1794 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1796 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1804 RouteTimeAxisView::reset_redirect_automation_curves ()
1806 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {
1812 RouteTimeAxisView::update_rec_display ()
1814 RouteUI::update_rec_display ();
1815 name_entry.set_sensitive (!_route->record_enabled());
1819 RouteTimeAxisView::fast_update ()
1821 lm.update_meters ();
1825 RouteTimeAxisView::hide_meter ()
1832 RouteTimeAxisView::show_meter ()
1838 RouteTimeAxisView::reset_meter ()
1840 if (Config->get_show_track_meters()) {
1841 lm.setup_meters (height-5);
1848 RouteTimeAxisView::clear_meter ()
1854 RouteTimeAxisView::meter_changed (void *src)
1856 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::meter_changed), src));
1861 RouteTimeAxisView::io_changed (IOChange change, void *src)