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 /* XXX is this incomplete? i don't think its very useful atm
123 solo_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
124 mute_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
125 playlist_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
126 automation_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
127 size_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
128 visual_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
129 hide_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
132 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
133 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
134 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
135 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
136 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
137 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
138 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
139 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
140 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
141 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
144 rec_enable_button->set_active (false);
145 rec_enable_button->set_name ("TrackRecordEnableButton");
146 //rec_enable_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
147 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
148 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
149 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
152 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
153 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
155 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
157 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
158 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
159 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
160 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
161 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
162 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
163 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
164 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
168 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
169 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
170 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
171 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
173 if (is_track() && track()->mode() == ARDOUR::Normal) {
174 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
177 /* remove focus from the buttons */
179 automation_button.unset_flags (Gtk::CAN_FOCUS);
180 solo_button->unset_flags (Gtk::CAN_FOCUS);
181 mute_button->unset_flags (Gtk::CAN_FOCUS);
182 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
183 size_button.unset_flags (Gtk::CAN_FOCUS);
184 playlist_button.unset_flags (Gtk::CAN_FOCUS);
185 hide_button.unset_flags (Gtk::CAN_FOCUS);
186 visual_button.unset_flags (Gtk::CAN_FOCUS);
188 /* map current state of the route */
190 update_diskstream_display ();
193 //redirects_changed (0);
194 //reset_redirect_automation_curves ();
197 _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
198 _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
199 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
200 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
201 _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
205 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
206 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
207 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
209 /* ask for notifications of any new RegionViews */
210 // FIXME: _view is NULL, but it would be nice to attach this here :/
211 //_view->RegionViewAdded.connect (mem_fun(*this, &RouteTimeAxisView::region_view_added));
214 /* pick up the correct freeze state */
219 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
220 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
223 RouteTimeAxisView::~RouteTimeAxisView ()
225 GoingAway (); /* EMIT_SIGNAL */
227 vector_delete (&redirect_automation_curves);
229 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
234 delete playlist_menu;
238 if (playlist_action_menu) {
239 delete playlist_action_menu;
240 playlist_action_menu = 0;
250 RouteTimeAxisView::set_playlist (Playlist *newplaylist)
252 Playlist *pl = playlist();
255 modified_connection.disconnect ();
256 state_changed_connection.disconnect ();
258 state_changed_connection = pl->StateChanged.connect (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed));
259 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
263 RouteTimeAxisView::playlist_modified ()
268 RouteTimeAxisView::edit_click (GdkEventButton *ev)
270 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
271 _route->set_edit_group (0, this);
275 using namespace Menu_Helpers;
277 MenuList& items = edit_group_menu.items ();
278 RadioMenuItem::Group group;
281 items.push_back (RadioMenuElem (group, _("No group"),
282 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
284 if (_route->edit_group() == 0) {
285 static_cast<RadioMenuItem*>(&items.back())->set_active ();
288 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
289 edit_group_menu.popup (ev->button, ev->time);
295 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
297 using namespace Menu_Helpers;
299 MenuList &items = edit_group_menu.items();
301 cerr << "adding edit group " << eg->name() << endl;
303 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
304 if (_route->edit_group() == eg) {
305 static_cast<RadioMenuItem*>(&items.back())->set_active ();
310 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
313 _route->set_edit_group (eg, this);
317 RouteTimeAxisView::playlist_state_changed (Change ignored)
319 // ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed), ignored));
324 RouteTimeAxisView::playlist_changed ()
330 set_playlist (dynamic_cast<Playlist*>(get_diskstream()->playlist()));
335 RouteTimeAxisView::label_view ()
337 string x = _route->name();
339 if (x != name_entry.get_text()) {
340 name_entry.set_text (x);
343 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
347 RouteTimeAxisView::route_name_changed (void *src)
349 editor.route_name_changed (this);
354 RouteTimeAxisView::take_name_changed (void *src)
363 RouteTimeAxisView::playlist_click ()
365 // always build a new action menu
367 if (playlist_action_menu == 0) {
368 playlist_action_menu = new Menu;
369 playlist_action_menu->set_name ("ArdourContextMenu");
372 build_playlist_menu(playlist_action_menu);
374 playlist_action_menu->popup (1, 0);
378 RouteTimeAxisView::automation_click ()
380 if (automation_action_menu == 0) {
381 /* this seems odd, but the automation action
382 menu is built as part of the display menu.
384 build_display_menu ();
386 automation_action_menu->popup (1, 0);
390 RouteTimeAxisView::build_automation_action_menu ()
392 using namespace Menu_Helpers;
394 automation_action_menu = manage (new Menu);
395 MenuList& automation_items = automation_action_menu->items();
396 automation_action_menu->set_name ("ArdourContextMenu");
398 automation_items.push_back (MenuElem (_("Show all automation"),
399 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
401 automation_items.push_back (MenuElem (_("Show existing automation"),
402 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
404 automation_items.push_back (MenuElem (_("Hide all automation"),
405 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
407 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
411 RouteTimeAxisView::build_display_menu ()
413 using namespace Menu_Helpers;
415 /* get the size menu ready */
421 TimeAxisView::build_display_menu ();
423 /* now fill it with our stuff */
425 MenuList& items = display_menu->items();
426 display_menu->set_name ("ArdourContextMenu");
428 items.push_back (MenuElem (_("Height"), *size_menu));
429 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
431 items.push_back (SeparatorElem());
433 build_remote_control_menu ();
434 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
436 build_automation_action_menu ();
437 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
439 // Hook for derived classes to add type specific stuff
440 items.push_back (SeparatorElem());
441 append_extra_display_menu_items ();
442 items.push_back (SeparatorElem());
446 Menu* alignment_menu = manage (new Menu);
447 MenuList& alignment_items = alignment_menu->items();
448 alignment_menu->set_name ("ArdourContextMenu");
450 RadioMenuItem::Group align_group;
452 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
453 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
454 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
455 if (get_diskstream()->alignment_style() == ExistingMaterial)
456 align_existing_item->set_active();
458 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
459 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
460 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
461 if (get_diskstream()->alignment_style() == CaptureTime)
462 align_capture_item->set_active();
464 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
466 get_diskstream()->AlignmentStyleChanged.connect (
467 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
470 items.push_back (SeparatorElem());
471 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
472 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
473 route_active_menu_item->set_active (_route->active());
475 items.push_back (SeparatorElem());
476 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
481 RouteTimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
487 TimeAxisView::show_timestretch (start, end);
497 /* check that the time selection was made in our route, or our edit group.
498 remember that edit_group() == 0 implies the route is *not* in a edit group.
501 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
502 /* this doesn't apply to us */
506 /* ignore it if our edit group is not active */
508 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
513 if (timestretch_rect == 0) {
514 timestretch_rect = new SimpleRect (*canvas_display);
515 timestretch_rect->property_x1() = 0.0;
516 timestretch_rect->property_y1() = 0.0;
517 timestretch_rect->property_x2() = 0.0;
518 timestretch_rect->property_y2() = 0.0;
519 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
520 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
523 timestretch_rect->show ();
524 timestretch_rect->raise_to_top ();
526 x1 = start / editor.get_current_zoom();
527 x2 = (end - 1) / editor.get_current_zoom();
530 timestretch_rect->property_x1() = x1;
531 timestretch_rect->property_y1() = 1.0;
532 timestretch_rect->property_x2() = x2;
533 timestretch_rect->property_y2() = y2;
537 RouteTimeAxisView::hide_timestretch ()
539 TimeAxisView::hide_timestretch ();
541 if (timestretch_rect) {
542 timestretch_rect->hide ();
547 RouteTimeAxisView::show_selection (TimeSelection& ts)
551 /* ignore it if our edit group is not active or if the selection was started
552 in some other track or edit group (remember that edit_group() == 0 means
553 that the track is not in an edit group).
556 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
557 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
563 TimeAxisView::show_selection (ts);
567 RouteTimeAxisView::set_height (TrackHeight h)
569 bool height_changed = (height == 0) || (h != height_style);
571 TimeAxisView::set_height (h);
575 _view->set_height ((double) height);
577 switch (height_style) {
579 xml_node->add_property ("track_height", "largest");
583 xml_node->add_property ("track_height", "large");
587 xml_node->add_property ("track_height", "larger");
591 xml_node->add_property ("track_height", "normal");
595 xml_node->add_property ("track_height", "smaller");
599 xml_node->add_property ("track_height", "small");
603 switch (height_style) {
611 mute_button->show_all();
612 solo_button->show_all();
613 if (rec_enable_button)
614 rec_enable_button->show_all();
616 edit_group_button.show_all();
617 hide_button.show_all();
618 visual_button.show_all();
619 size_button.show_all();
620 automation_button.show_all();
622 if (is_track() && track()->mode() == ARDOUR::Normal) {
623 playlist_button.show_all();
631 mute_button->show_all();
632 solo_button->show_all();
633 if (rec_enable_button)
634 rec_enable_button->show_all();
636 edit_group_button.hide ();
638 visual_button.hide ();
640 automation_button.hide ();
642 if (is_track() && track()->mode() == ARDOUR::Normal) {
643 playlist_button.hide ();
653 if (rec_enable_button)
654 rec_enable_button->hide();
656 edit_group_button.hide ();
658 visual_button.hide ();
660 automation_button.hide ();
661 playlist_button.hide ();
662 name_label.set_text (_route->name());
666 if (height_changed) {
667 /* only emit the signal if the height really changed */
668 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
673 RouteTimeAxisView::select_track_color ()
675 if (RouteUI::choose_color ()) {
678 _view->apply_color (_color, StreamView::RegionColor);
684 RouteTimeAxisView::reset_samples_per_unit ()
686 set_samples_per_unit (editor.get_current_zoom());
690 RouteTimeAxisView::set_samples_per_unit (double spu)
694 if (get_diskstream() != 0) {
695 speed = get_diskstream()->speed();
699 _view->set_samples_per_unit (spu * speed);
702 TimeAxisView::set_samples_per_unit (spu * speed);
706 RouteTimeAxisView::align_style_changed ()
708 switch (get_diskstream()->alignment_style()) {
709 case ExistingMaterial:
710 if (!align_existing_item->get_active()) {
711 align_existing_item->set_active();
715 if (!align_capture_item->get_active()) {
716 align_capture_item->set_active();
723 RouteTimeAxisView::set_align_style (AlignStyle style)
725 get_diskstream()->set_align_style (style);
729 RouteTimeAxisView::rename_current_playlist ()
731 ArdourPrompter prompter (true);
734 boost::shared_ptr<Diskstream> ds = get_diskstream();
735 if (!ds || ds->destructive())
738 Playlist *const pl = ds->playlist();
742 prompter.set_prompt (_("Name for playlist"));
743 prompter.set_initial_text (pl->name());
744 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
745 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
747 switch (prompter.run ()) {
748 case Gtk::RESPONSE_ACCEPT:
749 prompter.get_result (name);
761 RouteTimeAxisView::use_copy_playlist (bool prompt)
765 boost::shared_ptr<Diskstream> ds = get_diskstream();
766 if (!ds || ds->destructive())
769 Playlist *const pl = ds->playlist();
773 name = Playlist::bump_name (pl->name(), _session);
777 ArdourPrompter prompter (true);
779 prompter.set_prompt (_("Name for Playlist"));
780 prompter.set_initial_text (name);
781 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
782 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
783 prompter.show_all ();
785 switch (prompter.run ()) {
786 case Gtk::RESPONSE_ACCEPT:
787 prompter.get_result (name);
796 ds->use_copy_playlist ();
802 RouteTimeAxisView::use_new_playlist (bool prompt)
806 boost::shared_ptr<Diskstream> ds = get_diskstream();
807 if (!ds || ds->destructive())
810 Playlist *const pl = ds->playlist();
814 name = Playlist::bump_name (pl->name(), _session);
818 ArdourPrompter prompter (true);
820 prompter.set_prompt (_("Name for Playlist"));
821 prompter.set_initial_text (name);
822 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
823 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
825 switch (prompter.run ()) {
826 case Gtk::RESPONSE_ACCEPT:
827 prompter.get_result (name);
836 ds->use_new_playlist ();
842 RouteTimeAxisView::clear_playlist ()
844 boost::shared_ptr<Diskstream> ds = get_diskstream();
845 if (!ds || ds->destructive())
848 Playlist *const pl = ds->playlist();
852 editor.clear_playlist (*pl);
856 RouteTimeAxisView::speed_changed ()
858 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
862 RouteTimeAxisView::diskstream_changed ()
864 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
868 RouteTimeAxisView::update_diskstream_display ()
870 if (!get_diskstream()) // bus
873 set_playlist (get_diskstream()->playlist());
878 RouteTimeAxisView::selection_click (GdkEventButton* ev)
880 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
882 switch (Keyboard::selection_type (ev->state)) {
883 case Selection::Toggle:
884 editor.get_selection().toggle (*tracks);
888 editor.get_selection().set (*tracks);
891 case Selection::Extend:
892 /* not defined yet */
900 RouteTimeAxisView::set_selected_points (PointSelection& points)
902 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
903 (*i)->set_selected_points (points);
908 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
910 _view->set_selected_regionviews (regions);
914 RouteTimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& results)
918 if (get_diskstream() != 0) {
919 speed = get_diskstream()->speed();
922 jack_nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
923 jack_nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
925 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
926 _view->get_selectables (start_adjusted, end_adjusted, results);
929 /* pick up visible automation tracks */
931 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
932 if (!(*i)->hidden()) {
933 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
939 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
942 _view->get_inverted_selectables (sel, results);
945 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
946 if (!(*i)->hidden()) {
947 (*i)->get_inverted_selectables (sel, results);
955 RouteTimeAxisView::edit_group() const
957 return _route->edit_group();
961 RouteTimeAxisView::name() const
963 return _route->name();
967 RouteTimeAxisView::playlist () const
969 boost::shared_ptr<Diskstream> ds;
971 if ((ds = get_diskstream()) != 0) {
972 return ds->playlist();
979 RouteTimeAxisView::name_entry_changed ()
983 x = name_entry.get_text ();
985 if (x == _route->name()) {
989 if (x.length() == 0) {
990 name_entry.set_text (_route->name());
994 strip_whitespace_edges(x);
996 if (_session.route_name_unique (x)) {
997 _route->set_name (x, this);
999 ARDOUR_UI::instance()->popup_error (_("a track already exists with that name"));
1000 name_entry.set_text (_route->name());
1005 RouteTimeAxisView::visual_click ()
1007 popup_display_menu (0);
1011 RouteTimeAxisView::hide_click ()
1013 editor.hide_track_in_display (*this);
1016 boost::shared_ptr<Region>
1017 RouteTimeAxisView::find_next_region (jack_nframes_t pos, RegionPoint point, int32_t dir)
1019 boost::shared_ptr<Diskstream> stream;
1022 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1023 return playlist->find_next_region (pos, point, dir);
1026 return boost::shared_ptr<Region> ();
1030 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1032 Playlist* what_we_got;
1033 boost::shared_ptr<Diskstream> ds = get_diskstream();
1038 /* route is a bus, not a track */
1042 playlist = ds->playlist();
1045 TimeSelection time (selection.time);
1046 float speed = ds->speed();
1047 if (speed != 1.0f) {
1048 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1049 (*i).start = session_frame_to_track_frame((*i).start, speed);
1050 (*i).end = session_frame_to_track_frame((*i).end, speed);
1054 XMLNode &before = playlist->get_state();
1057 if ((what_we_got = playlist->cut (time)) != 0) {
1058 editor.get_cut_buffer().add (what_we_got);
1059 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1064 if ((what_we_got = playlist->copy (time)) != 0) {
1065 editor.get_cut_buffer().add (what_we_got);
1070 if ((what_we_got = playlist->cut (time)) != 0) {
1071 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
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 XMLNode &before = playlist->get_state();
1101 playlist->paste (**p, pos, times);
1102 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
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) {