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>
33 #include <gtkmm/menu.h>
34 #include <gtkmm/menuitem.h>
35 #include <gtkmm2ext/gtk_ui.h>
36 #include <gtkmm2ext/selector.h>
37 #include <gtkmm2ext/stop_signal.h>
38 #include <gtkmm2ext/bindable_button.h>
39 #include <gtkmm2ext/utils.h>
41 #include <ardour/playlist.h>
42 #include <ardour/diskstream.h>
43 #include <ardour/insert.h>
44 #include <ardour/ladspa_plugin.h>
45 #include <ardour/location.h>
46 #include <ardour/panner.h>
47 #include <ardour/playlist.h>
48 #include <ardour/session.h>
49 #include <ardour/session_playlist.h>
50 #include <ardour/utils.h>
52 #include "ardour_ui.h"
53 #include "route_time_axis.h"
54 #include "automation_time_axis.h"
55 #include "redirect_automation_time_axis.h"
56 #include "redirect_automation_line.h"
57 #include "canvas_impl.h"
58 #include "crossfade_view.h"
60 #include "gui_thread.h"
62 #include "playlist_selector.h"
63 #include "plugin_selector.h"
64 #include "plugin_ui.h"
65 #include "point_selection.h"
67 #include "public_editor.h"
68 #include "region_view.h"
69 #include "rgb_macros.h"
70 #include "selection.h"
71 #include "simplerect.h"
72 #include "streamview.h"
75 #include <ardour/track.h>
79 using namespace ARDOUR;
82 using namespace Editing;
85 RouteTimeAxisView::RouteTimeAxisView (PublicEditor& ed, Session& sess, boost::shared_ptr<Route> rt, Canvas& canvas)
87 RouteUI(rt, sess, _("m"), _("s"), _("r")), // mute, solo, and record
88 TimeAxisView(sess,ed,(TimeAxisView*) 0, canvas),
89 parent_canvas (canvas),
91 edit_group_button (_("g")), // group
92 playlist_button (_("p")),
93 size_button (_("h")), // height
94 automation_button (_("a")),
95 visual_button (_("v"))
100 playlist_action_menu = 0;
101 automation_action_menu = 0;
103 timestretch_rect = 0;
106 ignore_toggle = false;
108 mute_button->set_active (false);
109 solo_button->set_active (false);
111 mute_button->set_name ("TrackMuteButton");
112 solo_button->set_name ("SoloButton");
113 edit_group_button.set_name ("TrackGroupButton");
114 playlist_button.set_name ("TrackPlaylistButton");
115 automation_button.set_name ("TrackAutomationButton");
116 size_button.set_name ("TrackSizeButton");
117 visual_button.set_name ("TrackVisualButton");
118 hide_button.set_name ("TrackRemoveButton");
120 hide_button.add (*(manage (new Image (get_xpm("small_x.xpm")))));
122 solo_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
123 mute_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
124 playlist_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
125 automation_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
126 size_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
127 visual_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
128 hide_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
130 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
131 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
132 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
133 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
134 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
135 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
136 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
137 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
138 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
139 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
142 rec_enable_button->set_active (false);
143 rec_enable_button->set_name ("TrackRecordEnableButton");
144 rec_enable_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
145 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
146 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
147 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
150 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
151 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
153 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
155 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
156 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
157 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
158 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
159 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
160 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
161 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
162 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
166 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
167 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
168 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
169 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
171 if (is_track() && track()->mode() == ARDOUR::Normal) {
172 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
175 /* remove focus from the buttons */
177 automation_button.unset_flags (Gtk::CAN_FOCUS);
178 solo_button->unset_flags (Gtk::CAN_FOCUS);
179 mute_button->unset_flags (Gtk::CAN_FOCUS);
180 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
181 size_button.unset_flags (Gtk::CAN_FOCUS);
182 playlist_button.unset_flags (Gtk::CAN_FOCUS);
183 hide_button.unset_flags (Gtk::CAN_FOCUS);
184 visual_button.unset_flags (Gtk::CAN_FOCUS);
186 /* map current state of the route */
188 update_diskstream_display ();
191 //redirects_changed (0);
192 //reset_redirect_automation_curves ();
195 _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
196 _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
197 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
198 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
199 _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
203 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
204 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
205 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
207 /* ask for notifications of any new RegionViews */
208 // FIXME: _view is NULL, but it would be nice to attach this here :/
209 //_view->RegionViewAdded.connect (mem_fun(*this, &RouteTimeAxisView::region_view_added));
212 /* pick up the correct freeze state */
217 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
218 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
221 RouteTimeAxisView::~RouteTimeAxisView ()
223 GoingAway (); /* EMIT_SIGNAL */
225 vector_delete (&redirect_automation_curves);
227 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
232 delete playlist_menu;
236 if (playlist_action_menu) {
237 delete playlist_action_menu;
238 playlist_action_menu = 0;
248 RouteTimeAxisView::set_playlist (Playlist *newplaylist)
250 Playlist *pl = playlist();
253 modified_connection.disconnect ();
254 state_changed_connection.disconnect ();
256 state_changed_connection = pl->StateChanged.connect (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed));
257 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
261 RouteTimeAxisView::playlist_modified ()
266 RouteTimeAxisView::edit_click (GdkEventButton *ev)
268 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
269 _route->set_edit_group (0, this);
273 using namespace Menu_Helpers;
275 MenuList& items = edit_group_menu.items ();
276 RadioMenuItem::Group group;
279 items.push_back (RadioMenuElem (group, _("No group"),
280 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
282 if (_route->edit_group() == 0) {
283 static_cast<RadioMenuItem*>(&items.back())->set_active ();
286 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
287 edit_group_menu.popup (ev->button, ev->time);
293 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
295 using namespace Menu_Helpers;
297 MenuList &items = edit_group_menu.items();
299 cerr << "adding edit group " << eg->name() << endl;
301 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
302 if (_route->edit_group() == eg) {
303 static_cast<RadioMenuItem*>(&items.back())->set_active ();
308 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
311 _route->set_edit_group (eg, this);
315 RouteTimeAxisView::playlist_state_changed (Change ignored)
317 // ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed), ignored));
322 RouteTimeAxisView::playlist_changed ()
328 set_playlist (dynamic_cast<Playlist*>(get_diskstream()->playlist()));
333 RouteTimeAxisView::label_view ()
335 string x = _route->name();
337 if (x != name_entry.get_text()) {
338 name_entry.set_text (x);
341 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
345 RouteTimeAxisView::route_name_changed (void *src)
347 editor.route_name_changed (this);
352 RouteTimeAxisView::take_name_changed (void *src)
361 RouteTimeAxisView::playlist_click ()
363 // always build a new action menu
365 if (playlist_action_menu == 0) {
366 playlist_action_menu = new Menu;
367 playlist_action_menu->set_name ("ArdourContextMenu");
370 build_playlist_menu(playlist_action_menu);
372 playlist_action_menu->popup (1, 0);
376 RouteTimeAxisView::automation_click ()
378 if (automation_action_menu == 0) {
379 /* this seems odd, but the automation action
380 menu is built as part of the display menu.
382 build_display_menu ();
384 automation_action_menu->popup (1, 0);
388 RouteTimeAxisView::build_automation_action_menu ()
390 using namespace Menu_Helpers;
392 automation_action_menu = manage (new Menu);
393 MenuList& automation_items = automation_action_menu->items();
394 automation_action_menu->set_name ("ArdourContextMenu");
396 automation_items.push_back (MenuElem (_("Show all automation"),
397 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
399 automation_items.push_back (MenuElem (_("Show existing automation"),
400 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
402 automation_items.push_back (MenuElem (_("Hide all automation"),
403 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
405 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
409 RouteTimeAxisView::build_display_menu ()
411 using namespace Menu_Helpers;
413 /* get the size menu ready */
419 TimeAxisView::build_display_menu ();
421 /* now fill it with our stuff */
423 MenuList& items = display_menu->items();
424 display_menu->set_name ("ArdourContextMenu");
426 items.push_back (MenuElem (_("Height"), *size_menu));
427 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
429 items.push_back (SeparatorElem());
431 build_remote_control_menu ();
432 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
434 build_automation_action_menu ();
435 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
437 // Hook for derived classes to add type specific stuff
438 items.push_back (SeparatorElem());
439 append_extra_display_menu_items ();
440 items.push_back (SeparatorElem());
444 Menu* alignment_menu = manage (new Menu);
445 MenuList& alignment_items = alignment_menu->items();
446 alignment_menu->set_name ("ArdourContextMenu");
448 RadioMenuItem::Group align_group;
450 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
451 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
452 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
453 if (get_diskstream()->alignment_style() == ExistingMaterial)
454 align_existing_item->set_active();
456 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
457 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
458 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
459 if (get_diskstream()->alignment_style() == CaptureTime)
460 align_capture_item->set_active();
462 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
464 get_diskstream()->AlignmentStyleChanged.connect (
465 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
468 items.push_back (SeparatorElem());
469 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
470 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
471 route_active_menu_item->set_active (_route->active());
473 items.push_back (SeparatorElem());
474 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
479 RouteTimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
485 TimeAxisView::show_timestretch (start, end);
495 /* check that the time selection was made in our route, or our edit group.
496 remember that edit_group() == 0 implies the route is *not* in a edit group.
499 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
500 /* this doesn't apply to us */
504 /* ignore it if our edit group is not active */
506 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
511 if (timestretch_rect == 0) {
512 timestretch_rect = new SimpleRect (*canvas_display);
513 timestretch_rect->property_x1() = 0.0;
514 timestretch_rect->property_y1() = 0.0;
515 timestretch_rect->property_x2() = 0.0;
516 timestretch_rect->property_y2() = 0.0;
517 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
518 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
521 timestretch_rect->show ();
522 timestretch_rect->raise_to_top ();
524 x1 = start / editor.get_current_zoom();
525 x2 = (end - 1) / editor.get_current_zoom();
528 timestretch_rect->property_x1() = x1;
529 timestretch_rect->property_y1() = 1.0;
530 timestretch_rect->property_x2() = x2;
531 timestretch_rect->property_y2() = y2;
535 RouteTimeAxisView::hide_timestretch ()
537 TimeAxisView::hide_timestretch ();
539 if (timestretch_rect) {
540 timestretch_rect->hide ();
545 RouteTimeAxisView::show_selection (TimeSelection& ts)
549 /* ignore it if our edit group is not active or if the selection was started
550 in some other track or edit group (remember that edit_group() == 0 means
551 that the track is not in an edit group).
554 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
555 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
561 TimeAxisView::show_selection (ts);
565 RouteTimeAxisView::set_height (TrackHeight h)
567 bool height_changed = (height == 0) || (h != height_style);
569 TimeAxisView::set_height (h);
573 _view->set_height ((double) height);
575 switch (height_style) {
577 xml_node->add_property ("track_height", "largest");
581 xml_node->add_property ("track_height", "large");
585 xml_node->add_property ("track_height", "larger");
589 xml_node->add_property ("track_height", "normal");
593 xml_node->add_property ("track_height", "smaller");
597 xml_node->add_property ("track_height", "small");
601 switch (height_style) {
609 mute_button->show_all();
610 solo_button->show_all();
611 if (rec_enable_button)
612 rec_enable_button->show_all();
614 edit_group_button.show_all();
615 hide_button.show_all();
616 visual_button.show_all();
617 size_button.show_all();
618 automation_button.show_all();
620 if (is_track() && track()->mode() == ARDOUR::Normal) {
621 playlist_button.show_all();
629 mute_button->show_all();
630 solo_button->show_all();
631 if (rec_enable_button)
632 rec_enable_button->show_all();
634 edit_group_button.hide ();
636 visual_button.hide ();
638 automation_button.hide ();
640 if (is_track() && track()->mode() == ARDOUR::Normal) {
641 playlist_button.hide ();
651 if (rec_enable_button)
652 rec_enable_button->hide();
654 edit_group_button.hide ();
656 visual_button.hide ();
658 automation_button.hide ();
659 playlist_button.hide ();
660 name_label.set_text (_route->name());
664 if (height_changed) {
665 /* only emit the signal if the height really changed */
666 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
671 RouteTimeAxisView::select_track_color ()
673 if (RouteUI::choose_color ()) {
676 _view->apply_color (_color, StreamView::RegionColor);
682 RouteTimeAxisView::reset_samples_per_unit ()
684 set_samples_per_unit (editor.get_current_zoom());
688 RouteTimeAxisView::set_samples_per_unit (double spu)
692 if (get_diskstream() != 0) {
693 speed = get_diskstream()->speed();
697 _view->set_samples_per_unit (spu * speed);
700 TimeAxisView::set_samples_per_unit (spu * speed);
704 RouteTimeAxisView::align_style_changed ()
706 switch (get_diskstream()->alignment_style()) {
707 case ExistingMaterial:
708 if (!align_existing_item->get_active()) {
709 align_existing_item->set_active();
713 if (!align_capture_item->get_active()) {
714 align_capture_item->set_active();
721 RouteTimeAxisView::set_align_style (AlignStyle style)
723 get_diskstream()->set_align_style (style);
727 RouteTimeAxisView::rename_current_playlist ()
729 ArdourPrompter prompter (true);
732 Diskstream *const ds = get_diskstream();
733 if (!ds || ds->destructive())
736 Playlist *const pl = ds->playlist();
740 prompter.set_prompt (_("Name for playlist"));
741 prompter.set_initial_text (pl->name());
742 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
743 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
745 switch (prompter.run ()) {
746 case Gtk::RESPONSE_ACCEPT:
747 prompter.get_result (name);
759 RouteTimeAxisView::use_copy_playlist (bool prompt)
763 Diskstream *const ds = get_diskstream();
764 if (!ds || ds->destructive())
767 Playlist *const pl = ds->playlist();
771 name = Playlist::bump_name (pl->name(), _session);
775 ArdourPrompter prompter (true);
777 prompter.set_prompt (_("Name for Playlist"));
778 prompter.set_initial_text (name);
779 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
780 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
781 prompter.show_all ();
783 switch (prompter.run ()) {
784 case Gtk::RESPONSE_ACCEPT:
785 prompter.get_result (name);
794 ds->use_copy_playlist ();
800 RouteTimeAxisView::use_new_playlist (bool prompt)
804 Diskstream *const ds = get_diskstream();
805 if (!ds || ds->destructive())
808 Playlist *const pl = ds->playlist();
812 name = Playlist::bump_name (pl->name(), _session);
816 ArdourPrompter prompter (true);
818 prompter.set_prompt (_("Name for Playlist"));
819 prompter.set_initial_text (name);
820 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
821 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
823 switch (prompter.run ()) {
824 case Gtk::RESPONSE_ACCEPT:
825 prompter.get_result (name);
834 ds->use_new_playlist ();
840 RouteTimeAxisView::clear_playlist ()
842 Diskstream *const ds = get_diskstream();
843 if (!ds || ds->destructive())
846 Playlist *const pl = ds->playlist();
850 editor.clear_playlist (*pl);
854 RouteTimeAxisView::speed_changed ()
856 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
860 RouteTimeAxisView::diskstream_changed ()
862 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
866 RouteTimeAxisView::update_diskstream_display ()
868 if (!get_diskstream()) // bus
871 set_playlist (get_diskstream()->playlist());
876 RouteTimeAxisView::selection_click (GdkEventButton* ev)
878 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
880 switch (Keyboard::selection_type (ev->state)) {
881 case Selection::Toggle:
882 /* XXX this is not right */
883 editor.get_selection().add (*tracks);
887 editor.get_selection().set (*tracks);
890 case Selection::Extend:
891 /* not defined yet */
899 RouteTimeAxisView::set_selected_points (PointSelection& points)
901 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
902 (*i)->set_selected_points (points);
907 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
909 _view->set_selected_regionviews (regions);
913 RouteTimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& results)
917 if (get_diskstream() != 0) {
918 speed = get_diskstream()->speed();
921 jack_nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
922 jack_nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
924 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
925 _view->get_selectables (start_adjusted, end_adjusted, results);
928 /* pick up visible automation tracks */
930 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
931 if (!(*i)->hidden()) {
932 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
938 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
941 _view->get_inverted_selectables (sel, results);
944 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
945 if (!(*i)->hidden()) {
946 (*i)->get_inverted_selectables (sel, results);
954 RouteTimeAxisView::edit_group() const
956 return _route->edit_group();
960 RouteTimeAxisView::name() const
962 return _route->name();
966 RouteTimeAxisView::playlist () const
970 if ((ds = get_diskstream()) != 0) {
971 return ds->playlist();
978 RouteTimeAxisView::name_entry_changed ()
982 x = name_entry.get_text ();
984 if (x == _route->name()) {
988 if (x.length() == 0) {
989 name_entry.set_text (_route->name());
993 strip_whitespace_edges(x);
995 if (_session.route_name_unique (x)) {
996 _route->set_name (x, this);
998 ARDOUR_UI::instance()->popup_error (_("a track already exists with that name"));
999 name_entry.set_text (_route->name());
1004 RouteTimeAxisView::visual_click ()
1006 popup_display_menu (0);
1010 RouteTimeAxisView::hide_click ()
1012 editor.hide_track_in_display (*this);
1016 RouteTimeAxisView::find_next_region (jack_nframes_t pos, RegionPoint point, int32_t dir)
1021 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1022 return playlist->find_next_region (pos, point, dir);
1029 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1031 Playlist* what_we_got;
1032 Diskstream* ds = get_diskstream();
1037 /* route is a bus, not a track */
1041 playlist = ds->playlist();
1044 TimeSelection time (selection.time);
1045 float speed = ds->speed();
1046 if (speed != 1.0f) {
1047 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1048 (*i).start = session_frame_to_track_frame((*i).start, speed);
1049 (*i).end = session_frame_to_track_frame((*i).end, speed);
1055 _session.add_undo (playlist->get_memento());
1056 if ((what_we_got = playlist->cut (time)) != 0) {
1057 editor.get_cut_buffer().add (what_we_got);
1058 _session.add_redo_no_execute (playlist->get_memento());
1063 if ((what_we_got = playlist->copy (time)) != 0) {
1064 editor.get_cut_buffer().add (what_we_got);
1069 _session.add_undo (playlist->get_memento());
1070 if ((what_we_got = playlist->cut (time)) != 0) {
1071 _session.add_redo_no_execute (playlist->get_memento());
1072 what_we_got->unref ();
1082 RouteTimeAxisView::paste (jack_nframes_t pos, float times, Selection& selection, size_t nth)
1088 Playlist* playlist = get_diskstream()->playlist();
1089 PlaylistSelection::iterator p;
1091 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1093 if (p == selection.playlists.end()) {
1097 if (get_diskstream()->speed() != 1.0f)
1098 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1100 _session.add_undo (playlist->get_memento());
1101 playlist->paste (**p, pos, times);
1102 _session.add_redo_no_execute (playlist->get_memento());
1109 RouteTimeAxisView::get_child_list()
1112 list<TimeAxisView*>redirect_children;
1114 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1115 if (!(*i)->hidden()) {
1116 redirect_children.push_back(*i);
1119 return redirect_children;
1124 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1126 using namespace Menu_Helpers;
1128 if (!menu || !is_track()) {
1132 MenuList& playlist_items = menu->items();
1133 menu->set_name ("ArdourContextMenu");
1134 playlist_items.clear();
1136 if (playlist_menu) {
1137 delete playlist_menu;
1139 playlist_menu = new Menu;
1140 playlist_menu->set_name ("ArdourContextMenu");
1142 playlist_items.push_back (MenuElem (string_compose (_("Current: %1"), get_diskstream()->playlist()->name())));
1143 playlist_items.push_back (SeparatorElem());
1145 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1146 playlist_items.push_back (SeparatorElem());
1148 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1149 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1150 playlist_items.push_back (SeparatorElem());
1151 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1152 playlist_items.push_back (SeparatorElem());
1153 playlist_items.push_back (MenuElem(_("Select"), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1158 RouteTimeAxisView::show_playlist_selector ()
1160 editor.playlist_selector().show_for (this);
1164 RouteTimeAxisView::map_frozen ()
1170 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1172 switch (track()->freeze_state()) {
1174 playlist_button.set_sensitive (false);
1175 rec_enable_button->set_sensitive (false);
1178 playlist_button.set_sensitive (true);
1179 rec_enable_button->set_sensitive (true);
1185 RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
1188 case cTimeStretchOutline:
1189 timestretch_rect->property_outline_color_rgba() = val;
1191 case cTimeStretchFill:
1192 timestretch_rect->property_fill_color_rgba() = val;
1200 RouteTimeAxisView::select_me (GdkEventButton* ev)
1202 editor.get_selection().add (this);
1207 RouteTimeAxisView::show_all_automation ()
1211 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1212 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1213 if ((*ii)->view == 0) {
1214 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1217 (*ii)->menu_item->set_active (true);
1223 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1227 RouteTimeAxisView::show_existing_automation ()
1231 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1232 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1233 if ((*ii)->view != 0) {
1234 (*ii)->menu_item->set_active (true);
1241 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1245 RouteTimeAxisView::hide_all_automation ()
1249 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1250 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1251 (*ii)->menu_item->set_active (false);
1256 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1261 RouteTimeAxisView::region_view_added (RegionView* rv)
1263 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1264 AutomationTimeAxisView* atv;
1266 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1267 rv->add_ghost (*atv);
1273 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1275 rv->add_ghost (*atv);
1278 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1280 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1286 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1288 parent.remove_ran (this);
1296 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1299 remove_child (ran->view);
1303 RouteTimeAxisView::RedirectAutomationNode*
1304 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1306 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1308 if ((*i)->redirect == redirect) {
1310 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1311 if ((*ii)->what == what) {
1321 // FIXME: duplicated in midi_time_axis.cc
1323 legalize_for_xml_node (string str)
1325 string::size_type pos;
1326 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1332 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1333 legal.replace (pos, 1, "_");
1342 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1344 RedirectAutomationLine* ral;
1346 RedirectAutomationNode* ran;
1348 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1349 fatal << _("programming error: ")
1350 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1351 redirect->name(), what)
1361 name = redirect->describe_parameter (what);
1363 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1365 char state_name[256];
1366 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1368 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1370 ral = new RedirectAutomationLine (name,
1371 *redirect, what, _session, *ran->view,
1372 *ran->view->canvas_display, redirect->automation_list (what));
1374 ral->set_line_color (color_map[cRedirectAutomationLine]);
1375 ral->queue_reset ();
1377 ran->view->add_line (*ral);
1379 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1381 if (!ran->view->marked_for_display()) {
1384 ran->menu_item->set_active (true);
1387 add_child (ran->view);
1389 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1391 redirect->mark_automation_visible (what, true);
1395 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1398 ran->menu_item->set_active (false);
1401 r->mark_automation_visible (ran->what, false);
1403 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1407 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1410 RedirectAutomationLine *ral;
1412 redirect->what_has_visible_automation (s);
1414 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1416 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1417 ral->queue_reset ();
1419 add_redirect_automation_curve (redirect, (*i));
1425 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1427 using namespace Menu_Helpers;
1428 RedirectAutomationInfo *rai;
1429 list<RedirectAutomationInfo*>::iterator x;
1431 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1432 std::set<uint32_t> has_visible_automation;
1434 r->what_has_visible_automation(has_visible_automation);
1436 if (automatable.empty()) {
1440 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1441 if ((*x)->redirect == r) {
1446 if (x == redirect_automation.end()) {
1448 rai = new RedirectAutomationInfo (r);
1449 redirect_automation.push_back (rai);
1457 /* any older menu was deleted at the top of redirects_changed()
1458 when we cleared the subplugin menu.
1461 rai->menu = manage (new Menu);
1462 MenuList& items = rai->menu->items();
1463 rai->menu->set_name ("ArdourContextMenu");
1467 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1469 RedirectAutomationNode* ran;
1470 CheckMenuItem* mitem;
1472 string name = r->describe_parameter (*i);
1474 items.push_back (CheckMenuElem (name));
1475 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1477 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1478 mitem->set_active(true);
1481 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1485 ran = new RedirectAutomationNode (*i, mitem, *this);
1487 rai->lines.push_back (ran);
1491 ran->menu_item = mitem;
1495 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1498 /* add the menu for this redirect, because the subplugin
1499 menu is always cleared at the top of redirects_changed().
1500 this is the result of some poor design in gtkmm and/or
1504 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1509 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1510 RouteTimeAxisView::RedirectAutomationNode* ran)
1512 bool showit = ran->menu_item->get_active();
1513 bool redraw = false;
1515 if (ran->view == 0 && showit) {
1516 add_redirect_automation_curve (rai->redirect, ran->what);
1520 if (showit != ran->view->marked_for_display()) {
1523 ran->view->set_marked_for_display (true);
1524 ran->view->canvas_display->show();
1526 rai->redirect->mark_automation_visible (ran->what, true);
1527 ran->view->set_marked_for_display (false);
1535 if (redraw && !no_redraw) {
1537 /* now trigger a redisplay */
1539 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1545 RouteTimeAxisView::redirects_changed (void *src)
1547 using namespace Menu_Helpers;
1549 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1550 (*i)->valid = false;
1553 subplugin_menu.items().clear ();
1555 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1556 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1558 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1560 list<RedirectAutomationInfo*>::iterator tmp;
1568 redirect_automation.erase (i);
1575 /* change in visibility was possible */
1577 _route->gui_changed ("track_height", this);
1580 RedirectAutomationLine *
1581 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1583 RedirectAutomationNode* ran;
1585 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1587 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1595 RouteTimeAxisView::reset_redirect_automation_curves ()
1597 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {