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/diskstream.h>
44 #include <ardour/insert.h>
45 #include <ardour/ladspa_plugin.h>
46 #include <ardour/location.h>
47 #include <ardour/panner.h>
48 #include <ardour/playlist.h>
49 #include <ardour/session.h>
50 #include <ardour/session_playlist.h>
51 #include <ardour/utils.h>
53 #include "ardour_ui.h"
54 #include "route_time_axis.h"
55 #include "automation_time_axis.h"
56 #include "redirect_automation_time_axis.h"
57 #include "redirect_automation_line.h"
58 #include "canvas_impl.h"
59 #include "crossfade_view.h"
61 #include "gui_thread.h"
63 #include "playlist_selector.h"
64 #include "point_selection.h"
66 #include "public_editor.h"
67 #include "region_view.h"
68 #include "rgb_macros.h"
69 #include "selection.h"
70 #include "simplerect.h"
71 #include "streamview.h"
74 #include <ardour/track.h>
78 using namespace ARDOUR;
81 using namespace Editing;
84 RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
86 RouteUI(rt, sess, _("m"), _("s"), _("r")), // mute, solo, and record
87 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
88 parent_canvas (canvas),
90 edit_group_button (_("g")), // group
91 playlist_button (_("p")),
92 size_button (_("h")), // height
93 automation_button (_("a")),
94 visual_button (_("v"))
99 playlist_action_menu = 0;
100 automation_action_menu = 0;
102 timestretch_rect = 0;
105 ignore_toggle = false;
107 mute_button->set_active (false);
108 solo_button->set_active (false);
110 mute_button->set_name ("TrackMuteButton");
111 solo_button->set_name ("SoloButton");
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_xpm("small_x.xpm")))));
121 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
122 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
123 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
124 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
125 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
126 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
128 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
129 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
130 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
131 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
134 rec_enable_button->set_active (false);
135 rec_enable_button->set_name ("TrackRecordEnableButton");
136 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
137 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
138 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
141 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
142 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
144 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
146 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
147 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
148 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
149 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
150 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
151 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
152 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
153 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
157 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
158 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
159 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
160 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
162 if (is_track() && track()->mode() == ARDOUR::Normal) {
163 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
166 /* remove focus from the buttons */
168 automation_button.unset_flags (Gtk::CAN_FOCUS);
169 solo_button->unset_flags (Gtk::CAN_FOCUS);
170 mute_button->unset_flags (Gtk::CAN_FOCUS);
171 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
172 size_button.unset_flags (Gtk::CAN_FOCUS);
173 playlist_button.unset_flags (Gtk::CAN_FOCUS);
174 hide_button.unset_flags (Gtk::CAN_FOCUS);
175 visual_button.unset_flags (Gtk::CAN_FOCUS);
177 /* map current state of the route */
179 update_diskstream_display ();
182 //redirects_changed (0);
183 //reset_redirect_automation_curves ();
186 _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
187 _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
188 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
189 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
190 _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
195 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
196 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
197 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
199 /* ask for notifications of any new RegionViews */
200 // FIXME: _view is NULL, but it would be nice to attach this here :/
201 //_view->RegionViewAdded.connect (mem_fun(*this, &RouteTimeAxisView::region_view_added));
204 /* pick up the correct freeze state */
209 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
210 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
214 RouteTimeAxisView::~RouteTimeAxisView ()
216 GoingAway (); /* EMIT_SIGNAL */
218 vector_delete (&redirect_automation_curves);
220 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
225 delete playlist_menu;
229 if (playlist_action_menu) {
230 delete playlist_action_menu;
231 playlist_action_menu = 0;
241 RouteTimeAxisView::set_playlist (Playlist *newplaylist)
243 Playlist *pl = playlist();
246 modified_connection.disconnect ();
247 state_changed_connection.disconnect ();
249 state_changed_connection = pl->StateChanged.connect (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed));
250 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
254 RouteTimeAxisView::playlist_modified ()
259 RouteTimeAxisView::edit_click (GdkEventButton *ev)
261 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
262 _route->set_edit_group (0, this);
266 using namespace Menu_Helpers;
268 MenuList& items = edit_group_menu.items ();
269 RadioMenuItem::Group group;
272 items.push_back (RadioMenuElem (group, _("No group"),
273 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
275 if (_route->edit_group() == 0) {
276 static_cast<RadioMenuItem*>(&items.back())->set_active ();
279 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
280 edit_group_menu.popup (ev->button, ev->time);
286 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
288 using namespace Menu_Helpers;
290 MenuList &items = edit_group_menu.items();
292 cerr << "adding edit group " << eg->name() << endl;
294 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
295 if (_route->edit_group() == eg) {
296 static_cast<RadioMenuItem*>(&items.back())->set_active ();
301 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
304 _route->set_edit_group (eg, this);
308 RouteTimeAxisView::playlist_state_changed (Change ignored)
310 // ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed), ignored));
315 RouteTimeAxisView::playlist_changed ()
321 set_playlist (dynamic_cast<Playlist*>(get_diskstream()->playlist()));
326 RouteTimeAxisView::label_view ()
328 string x = _route->name();
330 if (x != name_entry.get_text()) {
331 name_entry.set_text (x);
334 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
338 RouteTimeAxisView::route_name_changed (void *src)
340 editor.route_name_changed (this);
345 RouteTimeAxisView::take_name_changed (void *src)
354 RouteTimeAxisView::playlist_click ()
356 // always build a new action menu
358 if (playlist_action_menu == 0) {
359 playlist_action_menu = new Menu;
360 playlist_action_menu->set_name ("ArdourContextMenu");
363 build_playlist_menu(playlist_action_menu);
365 playlist_action_menu->popup (1, 0);
369 RouteTimeAxisView::automation_click ()
371 if (automation_action_menu == 0) {
372 /* this seems odd, but the automation action
373 menu is built as part of the display menu.
375 build_display_menu ();
377 automation_action_menu->popup (1, 0);
381 RouteTimeAxisView::build_automation_action_menu ()
383 using namespace Menu_Helpers;
385 automation_action_menu = manage (new Menu);
386 MenuList& automation_items = automation_action_menu->items();
387 automation_action_menu->set_name ("ArdourContextMenu");
389 automation_items.push_back (MenuElem (_("Show all automation"),
390 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
392 automation_items.push_back (MenuElem (_("Show existing automation"),
393 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
395 automation_items.push_back (MenuElem (_("Hide all automation"),
396 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
398 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
402 RouteTimeAxisView::build_display_menu ()
404 using namespace Menu_Helpers;
406 /* get the size menu ready */
412 TimeAxisView::build_display_menu ();
414 /* now fill it with our stuff */
416 MenuList& items = display_menu->items();
417 display_menu->set_name ("ArdourContextMenu");
419 items.push_back (MenuElem (_("Height"), *size_menu));
420 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
422 items.push_back (SeparatorElem());
424 build_remote_control_menu ();
425 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
427 build_automation_action_menu ();
428 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
430 // Hook for derived classes to add type specific stuff
431 items.push_back (SeparatorElem());
432 append_extra_display_menu_items ();
433 items.push_back (SeparatorElem());
437 Menu* alignment_menu = manage (new Menu);
438 MenuList& alignment_items = alignment_menu->items();
439 alignment_menu->set_name ("ArdourContextMenu");
441 RadioMenuItem::Group align_group;
443 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
444 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
445 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
446 if (get_diskstream()->alignment_style() == ExistingMaterial)
447 align_existing_item->set_active();
449 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
450 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
451 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
452 if (get_diskstream()->alignment_style() == CaptureTime)
453 align_capture_item->set_active();
455 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
457 get_diskstream()->AlignmentStyleChanged.connect (
458 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
461 items.push_back (SeparatorElem());
462 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
463 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
464 route_active_menu_item->set_active (_route->active());
466 items.push_back (SeparatorElem());
467 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
472 RouteTimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
478 TimeAxisView::show_timestretch (start, end);
488 /* check that the time selection was made in our route, or our edit group.
489 remember that edit_group() == 0 implies the route is *not* in a edit group.
492 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
493 /* this doesn't apply to us */
497 /* ignore it if our edit group is not active */
499 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
504 if (timestretch_rect == 0) {
505 timestretch_rect = new SimpleRect (*canvas_display);
506 timestretch_rect->property_x1() = 0.0;
507 timestretch_rect->property_y1() = 0.0;
508 timestretch_rect->property_x2() = 0.0;
509 timestretch_rect->property_y2() = 0.0;
510 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
511 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
514 timestretch_rect->show ();
515 timestretch_rect->raise_to_top ();
517 x1 = start / editor.get_current_zoom();
518 x2 = (end - 1) / editor.get_current_zoom();
521 timestretch_rect->property_x1() = x1;
522 timestretch_rect->property_y1() = 1.0;
523 timestretch_rect->property_x2() = x2;
524 timestretch_rect->property_y2() = y2;
528 RouteTimeAxisView::hide_timestretch ()
530 TimeAxisView::hide_timestretch ();
532 if (timestretch_rect) {
533 timestretch_rect->hide ();
538 RouteTimeAxisView::show_selection (TimeSelection& ts)
542 /* ignore it if our edit group is not active or if the selection was started
543 in some other track or edit group (remember that edit_group() == 0 means
544 that the track is not in an edit group).
547 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
548 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
554 TimeAxisView::show_selection (ts);
558 RouteTimeAxisView::set_height (TrackHeight h)
560 bool height_changed = (height == 0) || (h != height_style);
562 TimeAxisView::set_height (h);
566 _view->set_height ((double) height);
568 switch (height_style) {
570 xml_node->add_property ("track_height", "largest");
574 xml_node->add_property ("track_height", "large");
578 xml_node->add_property ("track_height", "larger");
582 xml_node->add_property ("track_height", "normal");
586 xml_node->add_property ("track_height", "smaller");
590 xml_node->add_property ("track_height", "small");
594 switch (height_style) {
604 if (rec_enable_button)
605 rec_enable_button->show();
607 edit_group_button.show();
609 visual_button.show();
611 automation_button.show();
613 if (is_track() && track()->mode() == ARDOUR::Normal) {
614 playlist_button.show();
624 if (rec_enable_button)
625 rec_enable_button->show();
627 edit_group_button.hide ();
629 visual_button.hide ();
631 automation_button.hide ();
633 if (is_track() && track()->mode() == ARDOUR::Normal) {
634 playlist_button.hide ();
644 if (rec_enable_button)
645 rec_enable_button->hide();
647 edit_group_button.hide ();
649 visual_button.hide ();
651 automation_button.hide ();
652 playlist_button.hide ();
653 name_label.set_text (_route->name());
657 if (height_changed) {
658 /* only emit the signal if the height really changed */
659 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
664 RouteTimeAxisView::select_track_color ()
666 if (RouteUI::choose_color ()) {
669 _view->apply_color (_color, StreamView::RegionColor);
675 RouteTimeAxisView::reset_samples_per_unit ()
677 set_samples_per_unit (editor.get_current_zoom());
681 RouteTimeAxisView::set_samples_per_unit (double spu)
685 if (get_diskstream() != 0) {
686 speed = get_diskstream()->speed();
690 _view->set_samples_per_unit (spu * speed);
693 TimeAxisView::set_samples_per_unit (spu * speed);
697 RouteTimeAxisView::align_style_changed ()
699 switch (get_diskstream()->alignment_style()) {
700 case ExistingMaterial:
701 if (!align_existing_item->get_active()) {
702 align_existing_item->set_active();
706 if (!align_capture_item->get_active()) {
707 align_capture_item->set_active();
714 RouteTimeAxisView::set_align_style (AlignStyle style)
716 get_diskstream()->set_align_style (style);
720 RouteTimeAxisView::rename_current_playlist ()
722 ArdourPrompter prompter (true);
725 boost::shared_ptr<Diskstream> ds = get_diskstream();
726 if (!ds || ds->destructive())
729 Playlist *const pl = ds->playlist();
733 prompter.set_prompt (_("Name for playlist"));
734 prompter.set_initial_text (pl->name());
735 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
736 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
738 switch (prompter.run ()) {
739 case Gtk::RESPONSE_ACCEPT:
740 prompter.get_result (name);
752 RouteTimeAxisView::use_copy_playlist (bool prompt)
756 boost::shared_ptr<Diskstream> ds = get_diskstream();
757 if (!ds || ds->destructive())
760 Playlist *const pl = ds->playlist();
764 name = Playlist::bump_name (pl->name(), _session);
768 ArdourPrompter prompter (true);
770 prompter.set_prompt (_("Name for Playlist"));
771 prompter.set_initial_text (name);
772 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
773 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
774 prompter.show_all ();
776 switch (prompter.run ()) {
777 case Gtk::RESPONSE_ACCEPT:
778 prompter.get_result (name);
787 ds->use_copy_playlist ();
793 RouteTimeAxisView::use_new_playlist (bool prompt)
797 boost::shared_ptr<Diskstream> ds = get_diskstream();
798 if (!ds || ds->destructive())
801 Playlist *const pl = ds->playlist();
805 name = Playlist::bump_name (pl->name(), _session);
809 ArdourPrompter prompter (true);
811 prompter.set_prompt (_("Name for Playlist"));
812 prompter.set_initial_text (name);
813 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
814 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
816 switch (prompter.run ()) {
817 case Gtk::RESPONSE_ACCEPT:
818 prompter.get_result (name);
827 ds->use_new_playlist ();
833 RouteTimeAxisView::clear_playlist ()
835 boost::shared_ptr<Diskstream> ds = get_diskstream();
836 if (!ds || ds->destructive())
839 Playlist *const pl = ds->playlist();
843 editor.clear_playlist (*pl);
847 RouteTimeAxisView::speed_changed ()
849 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
853 RouteTimeAxisView::diskstream_changed ()
855 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
859 RouteTimeAxisView::update_diskstream_display ()
861 if (!get_diskstream()) // bus
864 set_playlist (get_diskstream()->playlist());
869 RouteTimeAxisView::selection_click (GdkEventButton* ev)
871 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
873 switch (Keyboard::selection_type (ev->state)) {
874 case Selection::Toggle:
875 editor.get_selection().toggle (*tracks);
879 editor.get_selection().set (*tracks);
882 case Selection::Extend:
883 /* not defined yet */
891 RouteTimeAxisView::set_selected_points (PointSelection& points)
893 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
894 (*i)->set_selected_points (points);
899 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
901 _view->set_selected_regionviews (regions);
905 RouteTimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& results)
909 if (get_diskstream() != 0) {
910 speed = get_diskstream()->speed();
913 jack_nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
914 jack_nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
916 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
917 _view->get_selectables (start_adjusted, end_adjusted, results);
920 /* pick up visible automation tracks */
922 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
923 if (!(*i)->hidden()) {
924 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
930 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
933 _view->get_inverted_selectables (sel, results);
936 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
937 if (!(*i)->hidden()) {
938 (*i)->get_inverted_selectables (sel, results);
946 RouteTimeAxisView::edit_group() const
948 return _route->edit_group();
952 RouteTimeAxisView::name() const
954 return _route->name();
958 RouteTimeAxisView::playlist () const
960 boost::shared_ptr<Diskstream> ds;
962 if ((ds = get_diskstream()) != 0) {
963 return ds->playlist();
970 RouteTimeAxisView::name_entry_changed ()
974 x = name_entry.get_text ();
976 if (x == _route->name()) {
980 if (x.length() == 0) {
981 name_entry.set_text (_route->name());
985 strip_whitespace_edges(x);
987 if (_session.route_name_unique (x)) {
988 _route->set_name (x, this);
990 ARDOUR_UI::instance()->popup_error (_("a track already exists with that name"));
991 name_entry.set_text (_route->name());
996 RouteTimeAxisView::visual_click ()
998 popup_display_menu (0);
1002 RouteTimeAxisView::hide_click ()
1004 editor.hide_track_in_display (*this);
1007 boost::shared_ptr<Region>
1008 RouteTimeAxisView::find_next_region (jack_nframes_t pos, RegionPoint point, int32_t dir)
1010 boost::shared_ptr<Diskstream> stream;
1013 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1014 return playlist->find_next_region (pos, point, dir);
1017 return boost::shared_ptr<Region> ();
1021 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1023 Playlist* what_we_got;
1024 boost::shared_ptr<Diskstream> ds = get_diskstream();
1029 /* route is a bus, not a track */
1033 playlist = ds->playlist();
1036 TimeSelection time (selection.time);
1037 float speed = ds->speed();
1038 if (speed != 1.0f) {
1039 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1040 (*i).start = session_frame_to_track_frame((*i).start, speed);
1041 (*i).end = session_frame_to_track_frame((*i).end, speed);
1045 XMLNode &before = playlist->get_state();
1048 if ((what_we_got = playlist->cut (time)) != 0) {
1049 editor.get_cut_buffer().add (what_we_got);
1050 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1055 if ((what_we_got = playlist->copy (time)) != 0) {
1056 editor.get_cut_buffer().add (what_we_got);
1061 if ((what_we_got = playlist->cut (time)) != 0) {
1062 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1063 what_we_got->unref ();
1073 RouteTimeAxisView::paste (jack_nframes_t pos, float times, Selection& selection, size_t nth)
1079 Playlist* playlist = get_diskstream()->playlist();
1080 PlaylistSelection::iterator p;
1082 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1084 if (p == selection.playlists.end()) {
1088 if (get_diskstream()->speed() != 1.0f)
1089 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1091 XMLNode &before = playlist->get_state();
1092 playlist->paste (**p, pos, times);
1093 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1100 RouteTimeAxisView::get_child_list()
1103 list<TimeAxisView*>redirect_children;
1105 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1106 if (!(*i)->hidden()) {
1107 redirect_children.push_back(*i);
1110 return redirect_children;
1115 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1117 using namespace Menu_Helpers;
1119 if (!menu || !is_track()) {
1123 MenuList& playlist_items = menu->items();
1124 menu->set_name ("ArdourContextMenu");
1125 playlist_items.clear();
1127 if (playlist_menu) {
1128 delete playlist_menu;
1130 playlist_menu = new Menu;
1131 playlist_menu->set_name ("ArdourContextMenu");
1133 playlist_items.push_back (MenuElem (string_compose (_("Current: %1"), get_diskstream()->playlist()->name())));
1134 playlist_items.push_back (SeparatorElem());
1136 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1137 playlist_items.push_back (SeparatorElem());
1139 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1140 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1141 playlist_items.push_back (SeparatorElem());
1142 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1143 playlist_items.push_back (SeparatorElem());
1144 playlist_items.push_back (MenuElem(_("Select"), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1149 RouteTimeAxisView::show_playlist_selector ()
1151 editor.playlist_selector().show_for (this);
1155 RouteTimeAxisView::map_frozen ()
1161 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1163 switch (track()->freeze_state()) {
1165 playlist_button.set_sensitive (false);
1166 rec_enable_button->set_sensitive (false);
1169 playlist_button.set_sensitive (true);
1170 rec_enable_button->set_sensitive (true);
1176 RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
1179 case cTimeStretchOutline:
1180 timestretch_rect->property_outline_color_rgba() = val;
1182 case cTimeStretchFill:
1183 timestretch_rect->property_fill_color_rgba() = val;
1191 RouteTimeAxisView::show_all_automation ()
1195 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1196 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1197 if ((*ii)->view == 0) {
1198 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1201 (*ii)->menu_item->set_active (true);
1207 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1211 RouteTimeAxisView::show_existing_automation ()
1215 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1216 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1217 if ((*ii)->view != 0) {
1218 (*ii)->menu_item->set_active (true);
1225 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1229 RouteTimeAxisView::hide_all_automation ()
1233 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1234 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1235 (*ii)->menu_item->set_active (false);
1240 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1245 RouteTimeAxisView::region_view_added (RegionView* rv)
1247 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1248 AutomationTimeAxisView* atv;
1250 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1251 rv->add_ghost (*atv);
1257 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1259 rv->add_ghost (*atv);
1262 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1264 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1270 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1272 parent.remove_ran (this);
1280 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1283 remove_child (ran->view);
1287 RouteTimeAxisView::RedirectAutomationNode*
1288 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1290 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1292 if ((*i)->redirect == redirect) {
1294 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1295 if ((*ii)->what == what) {
1305 // FIXME: duplicated in midi_time_axis.cc
1307 legalize_for_xml_node (string str)
1309 string::size_type pos;
1310 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1316 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1317 legal.replace (pos, 1, "_");
1326 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1328 RedirectAutomationLine* ral;
1330 RedirectAutomationNode* ran;
1332 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1333 fatal << _("programming error: ")
1334 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1335 redirect->name(), what)
1345 name = redirect->describe_parameter (what);
1347 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1349 char state_name[256];
1350 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1352 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1354 ral = new RedirectAutomationLine (name,
1355 *redirect, what, _session, *ran->view,
1356 *ran->view->canvas_display, redirect->automation_list (what));
1358 ral->set_line_color (color_map[cRedirectAutomationLine]);
1359 ral->queue_reset ();
1361 ran->view->add_line (*ral);
1363 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1365 if (!ran->view->marked_for_display()) {
1368 ran->menu_item->set_active (true);
1371 add_child (ran->view);
1373 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1375 redirect->mark_automation_visible (what, true);
1379 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1382 ran->menu_item->set_active (false);
1385 r->mark_automation_visible (ran->what, false);
1387 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1391 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1394 RedirectAutomationLine *ral;
1396 redirect->what_has_visible_automation (s);
1398 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1400 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1401 ral->queue_reset ();
1403 add_redirect_automation_curve (redirect, (*i));
1409 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1411 using namespace Menu_Helpers;
1412 RedirectAutomationInfo *rai;
1413 list<RedirectAutomationInfo*>::iterator x;
1415 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1416 std::set<uint32_t> has_visible_automation;
1418 r->what_has_visible_automation(has_visible_automation);
1420 if (automatable.empty()) {
1424 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1425 if ((*x)->redirect == r) {
1430 if (x == redirect_automation.end()) {
1432 rai = new RedirectAutomationInfo (r);
1433 redirect_automation.push_back (rai);
1441 /* any older menu was deleted at the top of redirects_changed()
1442 when we cleared the subplugin menu.
1445 rai->menu = manage (new Menu);
1446 MenuList& items = rai->menu->items();
1447 rai->menu->set_name ("ArdourContextMenu");
1451 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1453 RedirectAutomationNode* ran;
1454 CheckMenuItem* mitem;
1456 string name = r->describe_parameter (*i);
1458 items.push_back (CheckMenuElem (name));
1459 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1461 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1462 mitem->set_active(true);
1465 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1469 ran = new RedirectAutomationNode (*i, mitem, *this);
1471 rai->lines.push_back (ran);
1475 ran->menu_item = mitem;
1479 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1482 /* add the menu for this redirect, because the subplugin
1483 menu is always cleared at the top of redirects_changed().
1484 this is the result of some poor design in gtkmm and/or
1488 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1493 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1494 RouteTimeAxisView::RedirectAutomationNode* ran)
1496 bool showit = ran->menu_item->get_active();
1497 bool redraw = false;
1499 if (ran->view == 0 && showit) {
1500 add_redirect_automation_curve (rai->redirect, ran->what);
1504 if (showit != ran->view->marked_for_display()) {
1507 ran->view->set_marked_for_display (true);
1508 ran->view->canvas_display->show();
1510 rai->redirect->mark_automation_visible (ran->what, true);
1511 ran->view->set_marked_for_display (false);
1519 if (redraw && !no_redraw) {
1521 /* now trigger a redisplay */
1523 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1529 RouteTimeAxisView::redirects_changed (void *src)
1531 using namespace Menu_Helpers;
1533 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1534 (*i)->valid = false;
1537 subplugin_menu.items().clear ();
1539 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1540 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1542 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1544 list<RedirectAutomationInfo*>::iterator tmp;
1552 redirect_automation.erase (i);
1559 /* change in visibility was possible */
1561 _route->gui_changed ("track_height", this);
1564 RedirectAutomationLine *
1565 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1567 RedirectAutomationNode* ran;
1569 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1571 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1579 RouteTimeAxisView::reset_redirect_automation_curves ()
1581 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {