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;
110 ignore_toggle = false;
112 edit_group_button.set_name ("TrackGroupButton");
113 playlist_button.set_name ("TrackPlaylistButton");
114 automation_button.set_name ("TrackAutomationButton");
115 size_button.set_name ("TrackSizeButton");
116 visual_button.set_name ("TrackVisualButton");
117 hide_button.set_name ("TrackRemoveButton");
119 hide_button.add (*(manage (new Image (::get_icon("hide")))));
120 hide_button.show_all ();
122 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
123 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
124 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
125 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
126 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
127 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
129 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
130 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release));
131 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
132 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release));
138 rec_enable_button->remove ();
139 switch (track()->mode()) {
141 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
143 case ARDOUR::Destructive:
144 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
147 rec_enable_button->show_all ();
149 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press), false);
150 rec_enable_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::rec_enable_release));
151 controls_table.attach (*rec_enable_button, 4, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
152 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
156 controls_hbox.pack_start(lm, false, false);
157 _route->meter_change.connect (mem_fun(*this, &RouteTimeAxisView::meter_changed));
158 _route->input_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
159 _route->output_changed.connect (mem_fun(*this, &RouteTimeAxisView::io_changed));
161 controls_table.attach (*mute_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
162 controls_table.attach (*solo_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
164 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
166 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
167 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
168 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
169 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
170 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
171 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
172 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
173 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
177 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
178 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
179 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
180 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
182 if (is_track() && track()->mode() == ARDOUR::Normal) {
183 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
186 /* remove focus from the buttons */
190 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
191 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
195 track()->TrackModeChanged.connect (mem_fun(*this, &RouteTimeAxisView::track_mode_changed));
196 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
197 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
198 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
200 /* pick up the correct freeze state */
205 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
206 ColorsChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
209 RouteTimeAxisView::~RouteTimeAxisView ()
211 GoingAway (); /* EMIT_SIGNAL */
213 vector_delete (&redirect_automation_curves);
215 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
220 delete playlist_menu;
224 if (playlist_action_menu) {
225 delete playlist_action_menu;
226 playlist_action_menu = 0;
236 RouteTimeAxisView::post_construct ()
238 /* map current state of the route */
240 update_diskstream_display ();
241 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
242 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
243 reset_redirect_automation_curves ();
247 RouteTimeAxisView::set_playlist (boost::shared_ptr<Playlist> newplaylist)
249 boost::shared_ptr<Playlist> pl = playlist();
252 modified_connection.disconnect ();
253 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
257 RouteTimeAxisView::playlist_modified ()
262 RouteTimeAxisView::edit_click (GdkEventButton *ev)
264 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
265 _route->set_edit_group (0, this);
269 using namespace Menu_Helpers;
271 MenuList& items = edit_group_menu.items ();
272 RadioMenuItem::Group group;
275 items.push_back (RadioMenuElem (group, _("No group"),
276 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
278 if (_route->edit_group() == 0) {
279 static_cast<RadioMenuItem*>(&items.back())->set_active ();
282 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
283 edit_group_menu.popup (ev->button, ev->time);
289 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
291 using namespace Menu_Helpers;
293 MenuList &items = edit_group_menu.items();
295 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
296 if (_route->edit_group() == eg) {
297 static_cast<RadioMenuItem*>(&items.back())->set_active ();
302 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
304 _route->set_edit_group (eg, this);
308 RouteTimeAxisView::playlist_changed ()
313 set_playlist (get_diskstream()->playlist());
318 RouteTimeAxisView::label_view ()
320 string x = _route->name();
322 if (x != name_entry.get_text()) {
323 name_entry.set_text (x);
326 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
330 RouteTimeAxisView::route_name_changed (void *src)
332 editor.route_name_changed (this);
337 RouteTimeAxisView::take_name_changed (void *src)
346 RouteTimeAxisView::playlist_click ()
348 // always build a new action menu
350 if (playlist_action_menu != 0) {
351 delete playlist_action_menu;
354 playlist_action_menu = new Menu;
355 playlist_action_menu->set_name ("ArdourContextMenu");
357 build_playlist_menu (playlist_action_menu);
358 editor.set_selected_track (*this, Selection::Add);
359 playlist_action_menu->popup (1, gtk_get_current_event_time());
363 RouteTimeAxisView::automation_click ()
365 if (automation_action_menu == 0) {
366 /* this seems odd, but the automation action
367 menu is built as part of the display menu.
369 build_display_menu ();
371 editor.set_selected_track (*this, Selection::Add);
372 automation_action_menu->popup (1, gtk_get_current_event_time());
376 RouteTimeAxisView::build_automation_action_menu ()
378 using namespace Menu_Helpers;
380 automation_action_menu = manage (new Menu);
381 MenuList& automation_items = automation_action_menu->items();
382 automation_action_menu->set_name ("ArdourContextMenu");
384 automation_items.push_back (MenuElem (_("Show all automation"),
385 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
387 automation_items.push_back (MenuElem (_("Show existing automation"),
388 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
390 automation_items.push_back (MenuElem (_("Hide all automation"),
391 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
393 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
397 RouteTimeAxisView::build_display_menu ()
399 using namespace Menu_Helpers;
401 /* get the size menu ready */
407 TimeAxisView::build_display_menu ();
409 /* now fill it with our stuff */
411 MenuList& items = display_menu->items();
412 display_menu->set_name ("ArdourContextMenu");
414 items.push_back (MenuElem (_("Height"), *size_menu));
415 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
417 items.push_back (SeparatorElem());
419 build_remote_control_menu ();
420 if (!Profile->get_sae()) {
421 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 if (!Profile->get_sae()) {
453 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
454 get_diskstream()->AlignmentStyleChanged.connect (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)
492 RouteTimeAxisView::set_track_mode (TrackMode mode)
495 RadioMenuItem* other_item;
499 item = normal_track_mode_item;
500 other_item = destructive_track_mode_item;
502 case ARDOUR::Destructive:
503 item = destructive_track_mode_item;
504 other_item = normal_track_mode_item;
507 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", mode) << endmsg;
512 if (item->get_active () && track()->mode() != mode) {
513 _set_track_mode (track(), mode, other_item);
518 RouteTimeAxisView::_set_track_mode (boost::shared_ptr<Track> track, TrackMode mode, RadioMenuItem* reset_item)
522 if (!track->can_use_mode (mode, needs_bounce)) {
526 Glib::signal_idle().connect (bind (sigc::ptr_fun (__reset_item), reset_item));
529 cerr << "would bounce this one\n";
534 track->set_mode (mode);
536 rec_enable_button->remove ();
539 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_normal_red"))))));
541 case ARDOUR::Destructive:
542 rec_enable_button->add (*(manage (new Image (::get_icon (X_("record_tape_red"))))));
545 rec_enable_button->show_all ();
550 RouteTimeAxisView::track_mode_changed ()
554 switch (track()->mode()) {
556 item = normal_track_mode_item;
558 case ARDOUR::Destructive:
559 item = destructive_track_mode_item;
562 fatal << string_compose (_("programming error: %1 %2"), "illegal track mode in RouteTimeAxisView::set_track_mode", track()->mode()) << endmsg;
571 RouteTimeAxisView::show_timestretch (nframes_t start, nframes_t end)
577 TimeAxisView::show_timestretch (start, end);
587 /* check that the time selection was made in our route, or our edit group.
588 remember that edit_group() == 0 implies the route is *not* in a edit group.
591 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
592 /* this doesn't apply to us */
596 /* ignore it if our edit group is not active */
598 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
603 if (timestretch_rect == 0) {
604 timestretch_rect = new SimpleRect (*canvas_display);
605 timestretch_rect->property_x1() = 0.0;
606 timestretch_rect->property_y1() = 0.0;
607 timestretch_rect->property_x2() = 0.0;
608 timestretch_rect->property_y2() = 0.0;
609 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
610 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
613 timestretch_rect->show ();
614 timestretch_rect->raise_to_top ();
616 x1 = start / editor.get_current_zoom();
617 x2 = (end - 1) / editor.get_current_zoom();
620 timestretch_rect->property_x1() = x1;
621 timestretch_rect->property_y1() = 1.0;
622 timestretch_rect->property_x2() = x2;
623 timestretch_rect->property_y2() = y2;
627 RouteTimeAxisView::hide_timestretch ()
629 TimeAxisView::hide_timestretch ();
631 if (timestretch_rect) {
632 timestretch_rect->hide ();
637 RouteTimeAxisView::show_selection (TimeSelection& ts)
641 /* ignore it if our edit group is not active or if the selection was started
642 in some other track or edit group (remember that edit_group() == 0 means
643 that the track is not in an edit group).
646 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
647 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
653 TimeAxisView::show_selection (ts);
657 RouteTimeAxisView::set_height (TrackHeight h)
659 int gmlen = (height_to_pixels (h)) - 5;
660 bool height_changed = (height == 0) || (h != height_style);
661 lm.setup_meters (gmlen);
662 TimeAxisView::set_height (h);
667 _view->set_height ((double) height);
670 switch (height_style) {
672 xml_node->add_property ("track_height", "largest");
676 xml_node->add_property ("track_height", "large");
680 xml_node->add_property ("track_height", "larger");
684 xml_node->add_property ("track_height", "normal");
688 xml_node->add_property ("track_height", "smaller");
692 xml_node->add_property ("track_height", "small");
696 switch (height_style) {
707 if (rec_enable_button)
708 rec_enable_button->show();
710 edit_group_button.show();
712 visual_button.show();
714 automation_button.show();
716 if (is_track() && track()->mode() == ARDOUR::Normal) {
717 playlist_button.show();
728 if (rec_enable_button)
729 rec_enable_button->show();
731 edit_group_button.hide ();
733 visual_button.hide ();
735 automation_button.hide ();
737 if (is_track() && track()->mode() == ARDOUR::Normal) {
738 playlist_button.hide ();
749 if (rec_enable_button)
750 rec_enable_button->hide();
752 edit_group_button.hide ();
754 visual_button.hide ();
756 automation_button.hide ();
757 playlist_button.hide ();
758 name_label.set_text (_route->name());
762 if (height_changed) {
763 /* only emit the signal if the height really changed */
764 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
769 RouteTimeAxisView::select_track_color ()
771 if (RouteUI::choose_color ()) {
774 _view->apply_color (_color, StreamView::RegionColor);
780 RouteTimeAxisView::reset_samples_per_unit ()
782 set_samples_per_unit (editor.get_current_zoom());
786 RouteTimeAxisView::set_samples_per_unit (double spu)
790 if (get_diskstream() != 0) {
791 speed = get_diskstream()->speed();
795 _view->set_samples_per_unit (spu * speed);
798 TimeAxisView::set_samples_per_unit (spu * speed);
802 RouteTimeAxisView::align_style_changed ()
804 switch (get_diskstream()->alignment_style()) {
805 case ExistingMaterial:
806 if (!align_existing_item->get_active()) {
807 align_existing_item->set_active();
811 if (!align_capture_item->get_active()) {
812 align_capture_item->set_active();
819 RouteTimeAxisView::set_align_style (AlignStyle style)
824 case ExistingMaterial:
825 item = align_existing_item;
828 item = align_capture_item;
831 fatal << string_compose (_("programming error: %1 %2"), "illegal align style in RouteTimeAxisView::set_align_style", style) << endmsg;
836 if (item->get_active()) {
837 get_diskstream()->set_align_style (style);
842 RouteTimeAxisView::rename_current_playlist ()
844 ArdourPrompter prompter (true);
847 boost::shared_ptr<Diskstream> ds = get_diskstream();
848 if (!ds || ds->destructive())
851 boost::shared_ptr<Playlist> pl = ds->playlist();
855 prompter.set_prompt (_("Name for playlist"));
856 prompter.set_initial_text (pl->name());
857 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
858 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
860 switch (prompter.run ()) {
861 case Gtk::RESPONSE_ACCEPT:
862 prompter.get_result (name);
874 RouteTimeAxisView::use_copy_playlist (bool prompt)
878 boost::shared_ptr<Diskstream> ds = get_diskstream();
879 if (!ds || ds->destructive())
882 boost::shared_ptr<const Playlist> pl = ds->playlist();
889 name = Playlist::bump_name (name, _session);
890 } while (_session.playlist_by_name(name));
892 // TODO: The prompter "new" button should be de-activated if the user
893 // specifies a playlist name which already exists in the session.
897 ArdourPrompter prompter (true);
899 prompter.set_prompt (_("Name for Playlist"));
900 prompter.set_initial_text (name);
901 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
902 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
903 prompter.show_all ();
905 switch (prompter.run ()) {
906 case Gtk::RESPONSE_ACCEPT:
907 prompter.get_result (name);
916 ds->use_copy_playlist ();
917 ds->playlist()->set_name (name);
922 RouteTimeAxisView::use_new_playlist (bool prompt)
926 boost::shared_ptr<Diskstream> ds = get_diskstream();
927 if (!ds || ds->destructive())
930 boost::shared_ptr<const Playlist> pl = ds->playlist();
937 name = Playlist::bump_name (name, _session);
938 } while (_session.playlist_by_name(name));
943 ArdourPrompter prompter (true);
945 prompter.set_prompt (_("Name for Playlist"));
946 prompter.set_initial_text (name);
947 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
948 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, true);
950 switch (prompter.run ()) {
951 case Gtk::RESPONSE_ACCEPT:
952 prompter.get_result (name);
961 ds->use_new_playlist ();
962 ds->playlist()->set_name (name);
967 RouteTimeAxisView::clear_playlist ()
969 boost::shared_ptr<Diskstream> ds = get_diskstream();
970 if (!ds || ds->destructive())
973 boost::shared_ptr<Playlist> pl = ds->playlist();
977 editor.clear_playlist (pl);
981 RouteTimeAxisView::speed_changed ()
983 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
987 RouteTimeAxisView::diskstream_changed ()
989 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
993 RouteTimeAxisView::update_diskstream_display ()
995 if (!get_diskstream()) // bus
998 set_playlist (get_diskstream()->playlist());
1003 RouteTimeAxisView::selection_click (GdkEventButton* ev)
1005 if (Keyboard::modifier_state_equals (ev->state, (Keyboard::Shift|Keyboard::Control))) {
1007 /* special case: select/deselect all tracks */
1008 if (editor.get_selection().selected (this)) {
1009 editor.get_selection().clear_tracks ();
1011 editor.select_all_tracks ();
1017 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
1019 switch (Keyboard::selection_type (ev->state)) {
1020 case Selection::Toggle:
1021 editor.get_selection().toggle (*tracks);
1024 case Selection::Set:
1025 editor.get_selection().set (*tracks);
1028 case Selection::Extend:
1029 if (tracks->size() > 1) {
1030 /* add each one, do not "extend" */
1031 editor.get_selection().add (*tracks);
1033 /* extend to the single track */
1034 editor.extend_selection_to_track (*tracks->front());
1038 case Selection::Add:
1039 editor.get_selection().add (*tracks);
1047 RouteTimeAxisView::set_selected_points (PointSelection& points)
1049 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1050 (*i)->set_selected_points (points);
1055 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
1058 _view->set_selected_regionviews (regions);
1063 RouteTimeAxisView::get_selectables (nframes_t start, nframes_t end, double top, double bot, list<Selectable*>& results)
1067 if (get_diskstream() != 0) {
1068 speed = get_diskstream()->speed();
1071 nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
1072 nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
1074 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
1075 _view->get_selectables (start_adjusted, end_adjusted, results);
1078 /* pick up visible automation tracks */
1080 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1081 if (!(*i)->hidden()) {
1082 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
1088 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
1091 _view->get_inverted_selectables (sel, results);
1094 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1095 if (!(*i)->hidden()) {
1096 (*i)->get_inverted_selectables (sel, results);
1104 RouteTimeAxisView::edit_group() const
1106 return _route->edit_group();
1110 RouteTimeAxisView::name() const
1112 return _route->name();
1115 boost::shared_ptr<Playlist>
1116 RouteTimeAxisView::playlist () const
1118 boost::shared_ptr<Diskstream> ds;
1120 if ((ds = get_diskstream()) != 0) {
1121 return ds->playlist();
1123 return boost::shared_ptr<Playlist> ();
1128 RouteTimeAxisView::name_entry_changed ()
1132 x = name_entry.get_text ();
1134 if (x == _route->name()) {
1138 strip_whitespace_edges(x);
1140 if (x.length() == 0) {
1141 name_entry.set_text (_route->name());
1145 if (_session.route_name_unique (x)) {
1146 _route->set_name (x, this);
1148 ARDOUR_UI::instance()->popup_error (_("A track already exists with that name"));
1149 name_entry.set_text (_route->name());
1154 RouteTimeAxisView::visual_click ()
1156 popup_display_menu (0);
1160 RouteTimeAxisView::hide_click ()
1162 // LAME fix for hide_button refresh fix
1163 hide_button.set_sensitive(false);
1165 editor.hide_track_in_display (*this);
1167 hide_button.set_sensitive(true);
1170 boost::shared_ptr<Region>
1171 RouteTimeAxisView::find_next_region (nframes_t pos, RegionPoint point, int32_t dir)
1173 boost::shared_ptr<Diskstream> stream;
1174 boost::shared_ptr<Playlist> playlist;
1176 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1177 return playlist->find_next_region (pos, point, dir);
1180 return boost::shared_ptr<Region> ();
1184 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1186 boost::shared_ptr<Playlist> what_we_got;
1187 boost::shared_ptr<Diskstream> ds = get_diskstream();
1188 boost::shared_ptr<Playlist> playlist;
1192 /* route is a bus, not a track */
1196 playlist = ds->playlist();
1198 TimeSelection time (selection.time);
1199 float speed = ds->speed();
1200 if (speed != 1.0f) {
1201 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1202 (*i).start = session_frame_to_track_frame((*i).start, speed);
1203 (*i).end = session_frame_to_track_frame((*i).end, speed);
1207 XMLNode &before = playlist->get_state();
1210 if ((what_we_got = playlist->cut (time)) != 0) {
1211 editor.get_cut_buffer().add (what_we_got);
1212 _session.add_command( new MementoCommand<Playlist>(*playlist.get(), &before, &playlist->get_state()));
1217 if ((what_we_got = playlist->copy (time)) != 0) {
1218 editor.get_cut_buffer().add (what_we_got);
1223 if ((what_we_got = playlist->cut (time)) != 0) {
1224 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1225 what_we_got->release ();
1235 RouteTimeAxisView::paste (nframes_t pos, float times, Selection& selection, size_t nth)
1241 boost::shared_ptr<Playlist> playlist = get_diskstream()->playlist();
1242 PlaylistSelection::iterator p;
1244 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1246 if (p == selection.playlists.end()) {
1250 if (get_diskstream()->speed() != 1.0f)
1251 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1253 XMLNode &before = playlist->get_state();
1254 playlist->paste (*p, pos, times);
1255 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1262 RouteTimeAxisView::get_child_list()
1265 list<TimeAxisView*>redirect_children;
1267 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1268 if (!(*i)->hidden()) {
1269 redirect_children.push_back(*i);
1272 return redirect_children;
1277 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1279 using namespace Menu_Helpers;
1281 if (!menu || !is_track()) {
1285 MenuList& playlist_items = menu->items();
1286 menu->set_name ("ArdourContextMenu");
1287 playlist_items.clear();
1289 if (playlist_menu) {
1290 delete playlist_menu;
1293 playlist_menu = new Menu;
1294 playlist_menu->set_name ("ArdourContextMenu");
1296 vector<boost::shared_ptr<Playlist> > playlists;
1297 boost::shared_ptr<Diskstream> ds = get_diskstream();
1298 RadioMenuItem::Group playlist_group;
1300 _session.get_playlists (playlists);
1302 for (vector<boost::shared_ptr<Playlist> >::iterator i = playlists.begin(); i != playlists.end(); ++i) {
1304 if ((*i)->get_orig_diskstream_id() == ds->id()) {
1305 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1306 boost::weak_ptr<Playlist> (*i))));
1308 if (ds->playlist()->id() == (*i)->id()) {
1309 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1311 } else if (ds->playlist()->id() == (*i)->id()) {
1312 playlist_items.push_back (RadioMenuElem (playlist_group, (*i)->name(), bind (mem_fun (*this, &RouteTimeAxisView::use_playlist),
1313 boost::weak_ptr<Playlist>(*i))));
1314 static_cast<RadioMenuItem*>(&playlist_items.back())->set_active();
1319 playlist_items.push_back (SeparatorElem());
1320 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1321 playlist_items.push_back (SeparatorElem());
1323 playlist_items.push_back (MenuElem (_("New"), bind(mem_fun(editor, &PublicEditor::new_playlists), this)));
1324 playlist_items.push_back (MenuElem (_("New Copy"), bind(mem_fun(editor, &PublicEditor::copy_playlists), this)));
1325 playlist_items.push_back (SeparatorElem());
1326 playlist_items.push_back (MenuElem (_("Clear Current"), bind(mem_fun(editor, &PublicEditor::clear_playlists), this)));
1327 playlist_items.push_back (SeparatorElem());
1329 playlist_items.push_back (MenuElem(_("Select from all ..."), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1333 RouteTimeAxisView::use_playlist (boost::weak_ptr<Playlist> wpl)
1335 assert (is_track());
1337 boost::shared_ptr<Playlist> pl (wpl.lock());
1343 boost::shared_ptr<AudioPlaylist> apl = boost::dynamic_pointer_cast<AudioPlaylist> (pl);
1346 get_diskstream()->use_playlist (apl);
1351 RouteTimeAxisView::show_playlist_selector ()
1353 editor.playlist_selector().show_for (this);
1357 RouteTimeAxisView::map_frozen ()
1363 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1365 switch (track()->freeze_state()) {
1367 playlist_button.set_sensitive (false);
1368 rec_enable_button->set_sensitive (false);
1371 playlist_button.set_sensitive (true);
1372 rec_enable_button->set_sensitive (true);
1378 RouteTimeAxisView::color_handler ()
1380 if (timestretch_rect) {
1381 timestretch_rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchOutline.get();
1384 if (timestretch_rect) {
1385 timestretch_rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_TimeStretchFill.get();
1390 RouteTimeAxisView::show_all_automation ()
1394 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1395 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1396 if ((*ii)->view == 0) {
1397 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1400 (*ii)->menu_item->set_active (true);
1406 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1410 RouteTimeAxisView::show_existing_automation ()
1414 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1415 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1416 if ((*ii)->view != 0) {
1417 (*ii)->menu_item->set_active (true);
1424 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1428 RouteTimeAxisView::hide_all_automation ()
1432 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1433 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1434 (*ii)->menu_item->set_active (false);
1439 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1444 RouteTimeAxisView::region_view_added (RegionView* rv)
1446 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1447 AutomationTimeAxisView* atv;
1449 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1450 rv->add_ghost (*atv);
1456 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1458 rv->add_ghost (*atv);
1461 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1463 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1469 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1471 parent.remove_ran (this);
1479 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1482 remove_child (ran->view);
1486 RouteTimeAxisView::RedirectAutomationNode*
1487 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1489 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1491 if ((*i)->redirect == redirect) {
1493 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1494 if ((*ii)->what == what) {
1504 // FIXME: duplicated in midi_time_axis.cc
1506 legalize_for_xml_node (string str)
1508 string::size_type pos;
1509 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=:";
1515 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1516 legal.replace (pos, 1, "_");
1525 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1527 RedirectAutomationLine* ral;
1529 RedirectAutomationNode* ran;
1531 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1532 fatal << _("programming error: ")
1533 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1534 redirect->name(), what)
1544 name = redirect->describe_parameter (what);
1546 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1548 char state_name[256];
1549 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1551 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1553 ral = new RedirectAutomationLine (name,
1554 *redirect, what, _session, *ran->view,
1555 *ran->view->canvas_display, redirect->automation_list (what));
1557 ral->set_line_color (ARDOUR_UI::config()->canvasvar_RedirectAutomationLine.get());
1558 ral->queue_reset ();
1560 ran->view->add_line (*ral);
1562 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1564 if (!ran->view->marked_for_display()) {
1567 ran->menu_item->set_active (true);
1570 add_child (ran->view);
1573 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1576 redirect->mark_automation_visible (what, true);
1580 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1583 ran->menu_item->set_active (false);
1586 r->mark_automation_visible (ran->what, false);
1588 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1592 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1595 RedirectAutomationLine *ral;
1597 redirect->what_has_visible_automation (s);
1599 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1601 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1602 ral->queue_reset ();
1604 add_redirect_automation_curve (redirect, (*i));
1610 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1612 using namespace Menu_Helpers;
1613 RedirectAutomationInfo *rai;
1614 list<RedirectAutomationInfo*>::iterator x;
1616 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1617 std::set<uint32_t> has_visible_automation;
1619 r->what_has_visible_automation(has_visible_automation);
1621 if (automatable.empty()) {
1625 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1626 if ((*x)->redirect == r) {
1631 if (x == redirect_automation.end()) {
1633 rai = new RedirectAutomationInfo (r);
1634 redirect_automation.push_back (rai);
1642 /* any older menu was deleted at the top of redirects_changed()
1643 when we cleared the subplugin menu.
1646 rai->menu = manage (new Menu);
1647 MenuList& items = rai->menu->items();
1648 rai->menu->set_name ("ArdourContextMenu");
1652 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1654 RedirectAutomationNode* ran;
1655 CheckMenuItem* mitem;
1657 string name = r->describe_parameter (*i);
1659 items.push_back (CheckMenuElem (name));
1660 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1662 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1663 mitem->set_active(true);
1666 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1670 ran = new RedirectAutomationNode (*i, mitem, *this);
1672 rai->lines.push_back (ran);
1676 ran->menu_item = mitem;
1680 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1683 /* add the menu for this redirect, because the subplugin
1684 menu is always cleared at the top of redirects_changed().
1685 this is the result of some poor design in gtkmm and/or
1689 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1694 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1695 RouteTimeAxisView::RedirectAutomationNode* ran)
1697 bool showit = ran->menu_item->get_active();
1698 bool redraw = false;
1700 if (ran->view == 0 && showit) {
1701 add_redirect_automation_curve (rai->redirect, ran->what);
1705 if (showit != ran->view->marked_for_display()) {
1708 ran->view->set_marked_for_display (true);
1709 ran->view->canvas_display->show();
1711 rai->redirect->mark_automation_visible (ran->what, true);
1712 ran->view->set_marked_for_display (false);
1720 if (redraw && !no_redraw) {
1722 /* now trigger a redisplay */
1724 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1730 RouteTimeAxisView::redirects_changed (void *src)
1732 using namespace Menu_Helpers;
1734 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1735 (*i)->valid = false;
1738 subplugin_menu.items().clear ();
1740 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1741 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1743 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1745 list<RedirectAutomationInfo*>::iterator tmp;
1753 redirect_automation.erase (i);
1760 /* change in visibility was possible */
1762 _route->gui_changed ("track_height", this);
1765 RedirectAutomationLine *
1766 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1768 RedirectAutomationNode* ran;
1770 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1772 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1780 RouteTimeAxisView::reset_redirect_automation_curves ()
1782 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {
1788 RouteTimeAxisView::update_rec_display ()
1790 RouteUI::update_rec_display ();
1791 name_entry.set_sensitive (!_route->record_enabled());
1795 RouteTimeAxisView::fast_update ()
1797 lm.update_meters ();
1801 RouteTimeAxisView::hide_meter ()
1808 RouteTimeAxisView::show_meter ()
1814 RouteTimeAxisView::reset_meter ()
1816 if (Config->get_show_track_meters()) {
1817 lm.setup_meters (height-5);
1824 RouteTimeAxisView::clear_meter ()
1830 RouteTimeAxisView::meter_changed (void *src)
1832 ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::meter_changed), src));
1837 RouteTimeAxisView::io_changed (IOChange change, void *src)