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 solo_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
122 mute_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
123 playlist_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
124 automation_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
125 size_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
126 visual_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
127 hide_button.signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
129 solo_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::solo_press), false);
130 solo_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::solo_release), false);
131 mute_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::mute_press), false);
132 mute_button->signal_button_release_event().connect (mem_fun(*this, &RouteUI::mute_release), false);
133 edit_group_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::edit_click), false);
134 playlist_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::playlist_click));
135 automation_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::automation_click));
136 size_button.signal_button_release_event().connect (mem_fun(*this, &RouteTimeAxisView::size_click), false);
137 visual_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::visual_click));
138 hide_button.signal_clicked().connect (mem_fun(*this, &RouteTimeAxisView::hide_click));
141 rec_enable_button->set_active (false);
142 rec_enable_button->set_name ("TrackRecordEnableButton");
143 rec_enable_button->signal_button_press_event().connect (mem_fun (*this, &RouteTimeAxisView::select_me), false);
144 rec_enable_button->signal_button_press_event().connect (mem_fun(*this, &RouteUI::rec_enable_press));
145 controls_table.attach (*rec_enable_button, 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
146 ARDOUR_UI::instance()->tooltips().set_tip(*rec_enable_button, _("Record"));
149 controls_table.attach (*mute_button, 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
150 controls_table.attach (*solo_button, 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::FILL|Gtk::EXPAND, 0, 0);
152 controls_table.attach (edit_group_button, 6, 7, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
154 ARDOUR_UI::instance()->tooltips().set_tip(*solo_button,_("Solo"));
155 ARDOUR_UI::instance()->tooltips().set_tip(*mute_button,_("Mute"));
156 ARDOUR_UI::instance()->tooltips().set_tip(edit_group_button,_("Edit Group"));
157 ARDOUR_UI::instance()->tooltips().set_tip(size_button,_("Display Height"));
158 ARDOUR_UI::instance()->tooltips().set_tip(playlist_button,_("Playlist"));
159 ARDOUR_UI::instance()->tooltips().set_tip(automation_button, _("Automation"));
160 ARDOUR_UI::instance()->tooltips().set_tip(visual_button, _("Visual options"));
161 ARDOUR_UI::instance()->tooltips().set_tip(hide_button, _("Hide this track"));
165 controls_table.attach (hide_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
166 controls_table.attach (visual_button, 1, 2, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
167 controls_table.attach (size_button, 2, 3, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
168 controls_table.attach (automation_button, 3, 4, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
170 if (is_track() && track()->mode() == ARDOUR::Normal) {
171 controls_table.attach (playlist_button, 5, 6, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
174 /* remove focus from the buttons */
176 automation_button.unset_flags (Gtk::CAN_FOCUS);
177 solo_button->unset_flags (Gtk::CAN_FOCUS);
178 mute_button->unset_flags (Gtk::CAN_FOCUS);
179 edit_group_button.unset_flags (Gtk::CAN_FOCUS);
180 size_button.unset_flags (Gtk::CAN_FOCUS);
181 playlist_button.unset_flags (Gtk::CAN_FOCUS);
182 hide_button.unset_flags (Gtk::CAN_FOCUS);
183 visual_button.unset_flags (Gtk::CAN_FOCUS);
185 /* map current state of the route */
187 update_diskstream_display ();
190 //redirects_changed (0);
191 //reset_redirect_automation_curves ();
194 _route->mute_changed.connect (mem_fun(*this, &RouteUI::mute_changed));
195 _route->solo_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
196 _route->redirects_changed.connect (mem_fun(*this, &RouteTimeAxisView::redirects_changed));
197 _route->name_changed.connect (mem_fun(*this, &RouteTimeAxisView::route_name_changed));
198 _route->solo_safe_changed.connect (mem_fun(*this, &RouteUI::solo_changed));
202 track()->FreezeChange.connect (mem_fun(*this, &RouteTimeAxisView::map_frozen));
203 track()->DiskstreamChanged.connect (mem_fun(*this, &RouteTimeAxisView::diskstream_changed));
204 get_diskstream()->SpeedChanged.connect (mem_fun(*this, &RouteTimeAxisView::speed_changed));
206 /* ask for notifications of any new RegionViews */
207 // FIXME: _view is NULL, but it would be nice to attach this here :/
208 //_view->RegionViewAdded.connect (mem_fun(*this, &RouteTimeAxisView::region_view_added));
211 /* pick up the correct freeze state */
216 editor.ZoomChanged.connect (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
217 ColorChanged.connect (mem_fun (*this, &RouteTimeAxisView::color_handler));
220 RouteTimeAxisView::~RouteTimeAxisView ()
222 GoingAway (); /* EMIT_SIGNAL */
224 vector_delete (&redirect_automation_curves);
226 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
231 delete playlist_menu;
235 if (playlist_action_menu) {
236 delete playlist_action_menu;
237 playlist_action_menu = 0;
247 RouteTimeAxisView::set_playlist (Playlist *newplaylist)
249 Playlist *pl = playlist();
252 modified_connection.disconnect ();
253 state_changed_connection.disconnect ();
255 state_changed_connection = pl->StateChanged.connect (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed));
256 modified_connection = pl->Modified.connect (mem_fun(*this, &RouteTimeAxisView::playlist_modified));
260 RouteTimeAxisView::playlist_modified ()
265 RouteTimeAxisView::edit_click (GdkEventButton *ev)
267 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
268 _route->set_edit_group (0, this);
272 using namespace Menu_Helpers;
274 MenuList& items = edit_group_menu.items ();
275 RadioMenuItem::Group group;
278 items.push_back (RadioMenuElem (group, _("No group"),
279 bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), (RouteGroup *) 0)));
281 if (_route->edit_group() == 0) {
282 static_cast<RadioMenuItem*>(&items.back())->set_active ();
285 _session.foreach_edit_group (bind (mem_fun (*this, &RouteTimeAxisView::add_edit_group_menu_item), &group));
286 edit_group_menu.popup (ev->button, ev->time);
292 RouteTimeAxisView::add_edit_group_menu_item (RouteGroup *eg, RadioMenuItem::Group* group)
294 using namespace Menu_Helpers;
296 MenuList &items = edit_group_menu.items();
298 cerr << "adding edit group " << eg->name() << endl;
300 items.push_back (RadioMenuElem (*group, eg->name(), bind (mem_fun(*this, &RouteTimeAxisView::set_edit_group_from_menu), eg)));
301 if (_route->edit_group() == eg) {
302 static_cast<RadioMenuItem*>(&items.back())->set_active ();
307 RouteTimeAxisView::set_edit_group_from_menu (RouteGroup *eg)
310 _route->set_edit_group (eg, this);
314 RouteTimeAxisView::playlist_state_changed (Change ignored)
316 // ENSURE_GUI_THREAD (bind (mem_fun(*this, &RouteTimeAxisView::playlist_state_changed), ignored));
321 RouteTimeAxisView::playlist_changed ()
327 set_playlist (dynamic_cast<Playlist*>(get_diskstream()->playlist()));
332 RouteTimeAxisView::label_view ()
334 string x = _route->name();
336 if (x != name_entry.get_text()) {
337 name_entry.set_text (x);
340 ARDOUR_UI::instance()->tooltips().set_tip (name_entry, x);
344 RouteTimeAxisView::route_name_changed (void *src)
346 editor.route_name_changed (this);
351 RouteTimeAxisView::take_name_changed (void *src)
360 RouteTimeAxisView::playlist_click ()
362 // always build a new action menu
364 if (playlist_action_menu == 0) {
365 playlist_action_menu = new Menu;
366 playlist_action_menu->set_name ("ArdourContextMenu");
369 build_playlist_menu(playlist_action_menu);
371 playlist_action_menu->popup (1, 0);
375 RouteTimeAxisView::automation_click ()
377 if (automation_action_menu == 0) {
378 /* this seems odd, but the automation action
379 menu is built as part of the display menu.
381 build_display_menu ();
383 automation_action_menu->popup (1, 0);
387 RouteTimeAxisView::build_automation_action_menu ()
389 using namespace Menu_Helpers;
391 automation_action_menu = manage (new Menu);
392 MenuList& automation_items = automation_action_menu->items();
393 automation_action_menu->set_name ("ArdourContextMenu");
395 automation_items.push_back (MenuElem (_("Show all automation"),
396 mem_fun(*this, &RouteTimeAxisView::show_all_automation)));
398 automation_items.push_back (MenuElem (_("Show existing automation"),
399 mem_fun(*this, &RouteTimeAxisView::show_existing_automation)));
401 automation_items.push_back (MenuElem (_("Hide all automation"),
402 mem_fun(*this, &RouteTimeAxisView::hide_all_automation)));
404 automation_items.push_back (MenuElem (_("Plugins"), subplugin_menu));
408 RouteTimeAxisView::build_display_menu ()
410 using namespace Menu_Helpers;
412 /* get the size menu ready */
418 TimeAxisView::build_display_menu ();
420 /* now fill it with our stuff */
422 MenuList& items = display_menu->items();
423 display_menu->set_name ("ArdourContextMenu");
425 items.push_back (MenuElem (_("Height"), *size_menu));
426 items.push_back (MenuElem (_("Color"), mem_fun(*this, &RouteTimeAxisView::select_track_color)));
428 items.push_back (SeparatorElem());
430 build_remote_control_menu ();
431 items.push_back (MenuElem (_("Remote Control ID"), *remote_control_menu));
433 build_automation_action_menu ();
434 items.push_back (MenuElem (_("Automation"), *automation_action_menu));
436 // Hook for derived classes to add type specific stuff
437 items.push_back (SeparatorElem());
438 append_extra_display_menu_items ();
439 items.push_back (SeparatorElem());
443 Menu* alignment_menu = manage (new Menu);
444 MenuList& alignment_items = alignment_menu->items();
445 alignment_menu->set_name ("ArdourContextMenu");
447 RadioMenuItem::Group align_group;
449 alignment_items.push_back (RadioMenuElem (align_group, _("Align with existing material"),
450 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), ExistingMaterial)));
451 align_existing_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
452 if (get_diskstream()->alignment_style() == ExistingMaterial)
453 align_existing_item->set_active();
455 alignment_items.push_back (RadioMenuElem (align_group, _("Align with capture time"),
456 bind (mem_fun(*this, &RouteTimeAxisView::set_align_style), CaptureTime)));
457 align_capture_item = dynamic_cast<RadioMenuItem*>(&alignment_items.back());
458 if (get_diskstream()->alignment_style() == CaptureTime)
459 align_capture_item->set_active();
461 items.push_back (MenuElem (_("Alignment"), *alignment_menu));
463 get_diskstream()->AlignmentStyleChanged.connect (
464 mem_fun(*this, &RouteTimeAxisView::align_style_changed));
467 items.push_back (SeparatorElem());
468 items.push_back (CheckMenuElem (_("Active"), mem_fun(*this, &RouteUI::toggle_route_active)));
469 route_active_menu_item = dynamic_cast<CheckMenuItem *> (&items.back());
470 route_active_menu_item->set_active (_route->active());
472 items.push_back (SeparatorElem());
473 items.push_back (MenuElem (_("Remove"), mem_fun(*this, &RouteUI::remove_this_route)));
478 RouteTimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
484 TimeAxisView::show_timestretch (start, end);
494 /* check that the time selection was made in our route, or our edit group.
495 remember that edit_group() == 0 implies the route is *not* in a edit group.
498 if (!(ts.track == this || (ts.group != 0 && ts.group == _route->edit_group()))) {
499 /* this doesn't apply to us */
503 /* ignore it if our edit group is not active */
505 if ((ts.track != this) && _route->edit_group() && !_route->edit_group()->is_active()) {
510 if (timestretch_rect == 0) {
511 timestretch_rect = new SimpleRect (*canvas_display);
512 timestretch_rect->property_x1() = 0.0;
513 timestretch_rect->property_y1() = 0.0;
514 timestretch_rect->property_x2() = 0.0;
515 timestretch_rect->property_y2() = 0.0;
516 timestretch_rect->property_fill_color_rgba() = color_map[cTimeStretchFill];
517 timestretch_rect->property_outline_color_rgba() = color_map[cTimeStretchOutline];
520 timestretch_rect->show ();
521 timestretch_rect->raise_to_top ();
523 x1 = start / editor.get_current_zoom();
524 x2 = (end - 1) / editor.get_current_zoom();
527 timestretch_rect->property_x1() = x1;
528 timestretch_rect->property_y1() = 1.0;
529 timestretch_rect->property_x2() = x2;
530 timestretch_rect->property_y2() = y2;
534 RouteTimeAxisView::hide_timestretch ()
536 TimeAxisView::hide_timestretch ();
538 if (timestretch_rect) {
539 timestretch_rect->hide ();
544 RouteTimeAxisView::show_selection (TimeSelection& ts)
548 /* ignore it if our edit group is not active or if the selection was started
549 in some other track or edit group (remember that edit_group() == 0 means
550 that the track is not in an edit group).
553 if (((ts.track != this && !is_child (ts.track)) && _route->edit_group() && !_route->edit_group()->is_active()) ||
554 (!(ts.track == this || is_child (ts.track) || (ts.group != 0 && ts.group == _route->edit_group())))) {
560 TimeAxisView::show_selection (ts);
564 RouteTimeAxisView::set_height (TrackHeight h)
566 bool height_changed = (height == 0) || (h != height_style);
568 TimeAxisView::set_height (h);
572 _view->set_height ((double) height);
574 switch (height_style) {
576 xml_node->add_property ("track_height", "largest");
580 xml_node->add_property ("track_height", "large");
584 xml_node->add_property ("track_height", "larger");
588 xml_node->add_property ("track_height", "normal");
592 xml_node->add_property ("track_height", "smaller");
596 xml_node->add_property ("track_height", "small");
600 switch (height_style) {
608 mute_button->show_all();
609 solo_button->show_all();
610 if (rec_enable_button)
611 rec_enable_button->show_all();
613 edit_group_button.show_all();
614 hide_button.show_all();
615 visual_button.show_all();
616 size_button.show_all();
617 automation_button.show_all();
619 if (is_track() && track()->mode() == ARDOUR::Normal) {
620 playlist_button.show_all();
628 mute_button->show_all();
629 solo_button->show_all();
630 if (rec_enable_button)
631 rec_enable_button->show_all();
633 edit_group_button.hide ();
635 visual_button.hide ();
637 automation_button.hide ();
639 if (is_track() && track()->mode() == ARDOUR::Normal) {
640 playlist_button.hide ();
650 if (rec_enable_button)
651 rec_enable_button->hide();
653 edit_group_button.hide ();
655 visual_button.hide ();
657 automation_button.hide ();
658 playlist_button.hide ();
659 name_label.set_text (_route->name());
663 if (height_changed) {
664 /* only emit the signal if the height really changed */
665 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
670 RouteTimeAxisView::select_track_color ()
672 if (RouteUI::choose_color ()) {
675 _view->apply_color (_color, StreamView::RegionColor);
681 RouteTimeAxisView::reset_samples_per_unit ()
683 set_samples_per_unit (editor.get_current_zoom());
687 RouteTimeAxisView::set_samples_per_unit (double spu)
691 if (get_diskstream() != 0) {
692 speed = get_diskstream()->speed();
696 _view->set_samples_per_unit (spu * speed);
699 TimeAxisView::set_samples_per_unit (spu * speed);
703 RouteTimeAxisView::align_style_changed ()
705 switch (get_diskstream()->alignment_style()) {
706 case ExistingMaterial:
707 if (!align_existing_item->get_active()) {
708 align_existing_item->set_active();
712 if (!align_capture_item->get_active()) {
713 align_capture_item->set_active();
720 RouteTimeAxisView::set_align_style (AlignStyle style)
722 get_diskstream()->set_align_style (style);
726 RouteTimeAxisView::rename_current_playlist ()
728 ArdourPrompter prompter (true);
731 boost::shared_ptr<Diskstream> ds = get_diskstream();
732 if (!ds || ds->destructive())
735 Playlist *const pl = ds->playlist();
739 prompter.set_prompt (_("Name for playlist"));
740 prompter.set_initial_text (pl->name());
741 prompter.add_button (_("Rename"), Gtk::RESPONSE_ACCEPT);
742 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
744 switch (prompter.run ()) {
745 case Gtk::RESPONSE_ACCEPT:
746 prompter.get_result (name);
758 RouteTimeAxisView::use_copy_playlist (bool prompt)
762 boost::shared_ptr<Diskstream> ds = get_diskstream();
763 if (!ds || ds->destructive())
766 Playlist *const pl = ds->playlist();
770 name = Playlist::bump_name (pl->name(), _session);
774 ArdourPrompter prompter (true);
776 prompter.set_prompt (_("Name for Playlist"));
777 prompter.set_initial_text (name);
778 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
779 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
780 prompter.show_all ();
782 switch (prompter.run ()) {
783 case Gtk::RESPONSE_ACCEPT:
784 prompter.get_result (name);
793 ds->use_copy_playlist ();
799 RouteTimeAxisView::use_new_playlist (bool prompt)
803 boost::shared_ptr<Diskstream> ds = get_diskstream();
804 if (!ds || ds->destructive())
807 Playlist *const pl = ds->playlist();
811 name = Playlist::bump_name (pl->name(), _session);
815 ArdourPrompter prompter (true);
817 prompter.set_prompt (_("Name for Playlist"));
818 prompter.set_initial_text (name);
819 prompter.add_button (Gtk::Stock::NEW, Gtk::RESPONSE_ACCEPT);
820 prompter.set_response_sensitive (Gtk::RESPONSE_ACCEPT, false);
822 switch (prompter.run ()) {
823 case Gtk::RESPONSE_ACCEPT:
824 prompter.get_result (name);
833 ds->use_new_playlist ();
839 RouteTimeAxisView::clear_playlist ()
841 boost::shared_ptr<Diskstream> ds = get_diskstream();
842 if (!ds || ds->destructive())
845 Playlist *const pl = ds->playlist();
849 editor.clear_playlist (*pl);
853 RouteTimeAxisView::speed_changed ()
855 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::reset_samples_per_unit));
859 RouteTimeAxisView::diskstream_changed ()
861 Gtkmm2ext::UI::instance()->call_slot (mem_fun(*this, &RouteTimeAxisView::update_diskstream_display));
865 RouteTimeAxisView::update_diskstream_display ()
867 if (!get_diskstream()) // bus
870 set_playlist (get_diskstream()->playlist());
875 RouteTimeAxisView::selection_click (GdkEventButton* ev)
877 PublicEditor::TrackViewList* tracks = editor.get_valid_views (this, _route->edit_group());
879 switch (Keyboard::selection_type (ev->state)) {
880 case Selection::Toggle:
881 editor.get_selection().toggle (*tracks);
885 editor.get_selection().set (*tracks);
888 case Selection::Extend:
889 /* not defined yet */
897 RouteTimeAxisView::set_selected_points (PointSelection& points)
899 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
900 (*i)->set_selected_points (points);
905 RouteTimeAxisView::set_selected_regionviews (RegionSelection& regions)
907 _view->set_selected_regionviews (regions);
911 RouteTimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& results)
915 if (get_diskstream() != 0) {
916 speed = get_diskstream()->speed();
919 jack_nframes_t start_adjusted = session_frame_to_track_frame(start, speed);
920 jack_nframes_t end_adjusted = session_frame_to_track_frame(end, speed);
922 if (_view && ((top < 0.0 && bot < 0.0)) || touched (top, bot)) {
923 _view->get_selectables (start_adjusted, end_adjusted, results);
926 /* pick up visible automation tracks */
928 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
929 if (!(*i)->hidden()) {
930 (*i)->get_selectables (start_adjusted, end_adjusted, top, bot, results);
936 RouteTimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& results)
939 _view->get_inverted_selectables (sel, results);
942 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
943 if (!(*i)->hidden()) {
944 (*i)->get_inverted_selectables (sel, results);
952 RouteTimeAxisView::edit_group() const
954 return _route->edit_group();
958 RouteTimeAxisView::name() const
960 return _route->name();
964 RouteTimeAxisView::playlist () const
966 boost::shared_ptr<Diskstream> ds;
968 if ((ds = get_diskstream()) != 0) {
969 return ds->playlist();
976 RouteTimeAxisView::name_entry_changed ()
980 x = name_entry.get_text ();
982 if (x == _route->name()) {
986 if (x.length() == 0) {
987 name_entry.set_text (_route->name());
991 strip_whitespace_edges(x);
993 if (_session.route_name_unique (x)) {
994 _route->set_name (x, this);
996 ARDOUR_UI::instance()->popup_error (_("a track already exists with that name"));
997 name_entry.set_text (_route->name());
1002 RouteTimeAxisView::visual_click ()
1004 popup_display_menu (0);
1008 RouteTimeAxisView::hide_click ()
1010 editor.hide_track_in_display (*this);
1014 RouteTimeAxisView::find_next_region (jack_nframes_t pos, RegionPoint point, int32_t dir)
1016 boost::shared_ptr<Diskstream> stream;
1019 if ((stream = get_diskstream()) != 0 && (playlist = stream->playlist()) != 0) {
1020 return playlist->find_next_region (pos, point, dir);
1027 RouteTimeAxisView::cut_copy_clear (Selection& selection, CutCopyOp op)
1029 Playlist* what_we_got;
1030 boost::shared_ptr<Diskstream> ds = get_diskstream();
1035 /* route is a bus, not a track */
1039 playlist = ds->playlist();
1042 TimeSelection time (selection.time);
1043 float speed = ds->speed();
1044 if (speed != 1.0f) {
1045 for (TimeSelection::iterator i = time.begin(); i != time.end(); ++i) {
1046 (*i).start = session_frame_to_track_frame((*i).start, speed);
1047 (*i).end = session_frame_to_track_frame((*i).end, speed);
1051 XMLNode &before = playlist->get_state();
1054 if ((what_we_got = playlist->cut (time)) != 0) {
1055 editor.get_cut_buffer().add (what_we_got);
1056 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1061 if ((what_we_got = playlist->copy (time)) != 0) {
1062 editor.get_cut_buffer().add (what_we_got);
1067 if ((what_we_got = playlist->cut (time)) != 0) {
1068 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1069 what_we_got->unref ();
1079 RouteTimeAxisView::paste (jack_nframes_t pos, float times, Selection& selection, size_t nth)
1085 Playlist* playlist = get_diskstream()->playlist();
1086 PlaylistSelection::iterator p;
1088 for (p = selection.playlists.begin(); p != selection.playlists.end() && nth; ++p, --nth);
1090 if (p == selection.playlists.end()) {
1094 if (get_diskstream()->speed() != 1.0f)
1095 pos = session_frame_to_track_frame(pos, get_diskstream()->speed() );
1097 XMLNode &before = playlist->get_state();
1098 playlist->paste (**p, pos, times);
1099 _session.add_command( new MementoCommand<Playlist>(*playlist, &before, &playlist->get_state()));
1106 RouteTimeAxisView::get_child_list()
1109 list<TimeAxisView*>redirect_children;
1111 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1112 if (!(*i)->hidden()) {
1113 redirect_children.push_back(*i);
1116 return redirect_children;
1121 RouteTimeAxisView::build_playlist_menu (Gtk::Menu * menu)
1123 using namespace Menu_Helpers;
1125 if (!menu || !is_track()) {
1129 MenuList& playlist_items = menu->items();
1130 menu->set_name ("ArdourContextMenu");
1131 playlist_items.clear();
1133 if (playlist_menu) {
1134 delete playlist_menu;
1136 playlist_menu = new Menu;
1137 playlist_menu->set_name ("ArdourContextMenu");
1139 playlist_items.push_back (MenuElem (string_compose (_("Current: %1"), get_diskstream()->playlist()->name())));
1140 playlist_items.push_back (SeparatorElem());
1142 playlist_items.push_back (MenuElem (_("Rename"), mem_fun(*this, &RouteTimeAxisView::rename_current_playlist)));
1143 playlist_items.push_back (SeparatorElem());
1145 playlist_items.push_back (MenuElem (_("New"), mem_fun(editor, &PublicEditor::new_playlists)));
1146 playlist_items.push_back (MenuElem (_("New Copy"), mem_fun(editor, &PublicEditor::copy_playlists)));
1147 playlist_items.push_back (SeparatorElem());
1148 playlist_items.push_back (MenuElem (_("Clear Current"), mem_fun(editor, &PublicEditor::clear_playlists)));
1149 playlist_items.push_back (SeparatorElem());
1150 playlist_items.push_back (MenuElem(_("Select"), mem_fun(*this, &RouteTimeAxisView::show_playlist_selector)));
1155 RouteTimeAxisView::show_playlist_selector ()
1157 editor.playlist_selector().show_for (this);
1161 RouteTimeAxisView::map_frozen ()
1167 ENSURE_GUI_THREAD (mem_fun(*this, &RouteTimeAxisView::map_frozen));
1169 switch (track()->freeze_state()) {
1171 playlist_button.set_sensitive (false);
1172 rec_enable_button->set_sensitive (false);
1175 playlist_button.set_sensitive (true);
1176 rec_enable_button->set_sensitive (true);
1182 RouteTimeAxisView::color_handler (ColorID id, uint32_t val)
1185 case cTimeStretchOutline:
1186 timestretch_rect->property_outline_color_rgba() = val;
1188 case cTimeStretchFill:
1189 timestretch_rect->property_fill_color_rgba() = val;
1197 RouteTimeAxisView::select_me (GdkEventButton* ev)
1199 editor.get_selection().add (this);
1204 RouteTimeAxisView::show_all_automation ()
1208 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1209 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1210 if ((*ii)->view == 0) {
1211 add_redirect_automation_curve ((*i)->redirect, (*ii)->what);
1214 (*ii)->menu_item->set_active (true);
1220 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1224 RouteTimeAxisView::show_existing_automation ()
1228 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1229 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1230 if ((*ii)->view != 0) {
1231 (*ii)->menu_item->set_active (true);
1238 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1242 RouteTimeAxisView::hide_all_automation ()
1246 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1247 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1248 (*ii)->menu_item->set_active (false);
1253 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1258 RouteTimeAxisView::region_view_added (RegionView* rv)
1260 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
1261 AutomationTimeAxisView* atv;
1263 if ((atv = dynamic_cast<AutomationTimeAxisView*> (*i)) != 0) {
1264 rv->add_ghost (*atv);
1270 RouteTimeAxisView::add_ghost_to_redirect (RegionView* rv, AutomationTimeAxisView* atv)
1272 rv->add_ghost (*atv);
1275 RouteTimeAxisView::RedirectAutomationInfo::~RedirectAutomationInfo ()
1277 for (vector<RedirectAutomationNode*>::iterator i = lines.begin(); i != lines.end(); ++i) {
1283 RouteTimeAxisView::RedirectAutomationNode::~RedirectAutomationNode ()
1285 parent.remove_ran (this);
1293 RouteTimeAxisView::remove_ran (RedirectAutomationNode* ran)
1296 remove_child (ran->view);
1300 RouteTimeAxisView::RedirectAutomationNode*
1301 RouteTimeAxisView::find_redirect_automation_node (boost::shared_ptr<Redirect> redirect, uint32_t what)
1303 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1305 if ((*i)->redirect == redirect) {
1307 for (vector<RedirectAutomationNode*>::iterator ii = (*i)->lines.begin(); ii != (*i)->lines.end(); ++ii) {
1308 if ((*ii)->what == what) {
1318 // FIXME: duplicated in midi_time_axis.cc
1320 legalize_for_xml_node (string str)
1322 string::size_type pos;
1323 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=:";
1329 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
1330 legal.replace (pos, 1, "_");
1339 RouteTimeAxisView::add_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1341 RedirectAutomationLine* ral;
1343 RedirectAutomationNode* ran;
1345 if ((ran = find_redirect_automation_node (redirect, what)) == 0) {
1346 fatal << _("programming error: ")
1347 << string_compose (X_("redirect automation curve for %1:%2 not registered with audio track!"),
1348 redirect->name(), what)
1358 name = redirect->describe_parameter (what);
1360 /* create a string that is a legal XML node name that can be used to refer to this redirect+port combination */
1362 char state_name[256];
1363 snprintf (state_name, sizeof (state_name), "Redirect-%s-%" PRIu32, legalize_for_xml_node (redirect->name()).c_str(), what);
1365 ran->view = new RedirectAutomationTimeAxisView (_session, _route, editor, *this, parent_canvas, name, what, *redirect, state_name);
1367 ral = new RedirectAutomationLine (name,
1368 *redirect, what, _session, *ran->view,
1369 *ran->view->canvas_display, redirect->automation_list (what));
1371 ral->set_line_color (color_map[cRedirectAutomationLine]);
1372 ral->queue_reset ();
1374 ran->view->add_line (*ral);
1376 ran->view->Hiding.connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_automation_track_hidden), ran, redirect));
1378 if (!ran->view->marked_for_display()) {
1381 ran->menu_item->set_active (true);
1384 add_child (ran->view);
1386 _view->foreach_regionview (bind (mem_fun(*this, &RouteTimeAxisView::add_ghost_to_redirect), ran->view));
1388 redirect->mark_automation_visible (what, true);
1392 RouteTimeAxisView::redirect_automation_track_hidden (RouteTimeAxisView::RedirectAutomationNode* ran, boost::shared_ptr<Redirect> r)
1395 ran->menu_item->set_active (false);
1398 r->mark_automation_visible (ran->what, false);
1400 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1404 RouteTimeAxisView::add_existing_redirect_automation_curves (boost::shared_ptr<Redirect> redirect)
1407 RedirectAutomationLine *ral;
1409 redirect->what_has_visible_automation (s);
1411 for (set<uint32_t>::iterator i = s.begin(); i != s.end(); ++i) {
1413 if ((ral = find_redirect_automation_curve (redirect, *i)) != 0) {
1414 ral->queue_reset ();
1416 add_redirect_automation_curve (redirect, (*i));
1422 RouteTimeAxisView::add_redirect_to_subplugin_menu (boost::shared_ptr<Redirect> r)
1424 using namespace Menu_Helpers;
1425 RedirectAutomationInfo *rai;
1426 list<RedirectAutomationInfo*>::iterator x;
1428 const std::set<uint32_t>& automatable = r->what_can_be_automated ();
1429 std::set<uint32_t> has_visible_automation;
1431 r->what_has_visible_automation(has_visible_automation);
1433 if (automatable.empty()) {
1437 for (x = redirect_automation.begin(); x != redirect_automation.end(); ++x) {
1438 if ((*x)->redirect == r) {
1443 if (x == redirect_automation.end()) {
1445 rai = new RedirectAutomationInfo (r);
1446 redirect_automation.push_back (rai);
1454 /* any older menu was deleted at the top of redirects_changed()
1455 when we cleared the subplugin menu.
1458 rai->menu = manage (new Menu);
1459 MenuList& items = rai->menu->items();
1460 rai->menu->set_name ("ArdourContextMenu");
1464 for (std::set<uint32_t>::const_iterator i = automatable.begin(); i != automatable.end(); ++i) {
1466 RedirectAutomationNode* ran;
1467 CheckMenuItem* mitem;
1469 string name = r->describe_parameter (*i);
1471 items.push_back (CheckMenuElem (name));
1472 mitem = dynamic_cast<CheckMenuItem*> (&items.back());
1474 if (has_visible_automation.find((*i)) != has_visible_automation.end()) {
1475 mitem->set_active(true);
1478 if ((ran = find_redirect_automation_node (r, *i)) == 0) {
1482 ran = new RedirectAutomationNode (*i, mitem, *this);
1484 rai->lines.push_back (ran);
1488 ran->menu_item = mitem;
1492 mitem->signal_toggled().connect (bind (mem_fun(*this, &RouteTimeAxisView::redirect_menu_item_toggled), rai, ran));
1495 /* add the menu for this redirect, because the subplugin
1496 menu is always cleared at the top of redirects_changed().
1497 this is the result of some poor design in gtkmm and/or
1501 subplugin_menu.items().push_back (MenuElem (r->name(), *rai->menu));
1506 RouteTimeAxisView::redirect_menu_item_toggled (RouteTimeAxisView::RedirectAutomationInfo* rai,
1507 RouteTimeAxisView::RedirectAutomationNode* ran)
1509 bool showit = ran->menu_item->get_active();
1510 bool redraw = false;
1512 if (ran->view == 0 && showit) {
1513 add_redirect_automation_curve (rai->redirect, ran->what);
1517 if (showit != ran->view->marked_for_display()) {
1520 ran->view->set_marked_for_display (true);
1521 ran->view->canvas_display->show();
1523 rai->redirect->mark_automation_visible (ran->what, true);
1524 ran->view->set_marked_for_display (false);
1532 if (redraw && !no_redraw) {
1534 /* now trigger a redisplay */
1536 _route->gui_changed ("track_height", (void *) 0); /* EMIT_SIGNAL */
1542 RouteTimeAxisView::redirects_changed (void *src)
1544 using namespace Menu_Helpers;
1546 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ++i) {
1547 (*i)->valid = false;
1550 subplugin_menu.items().clear ();
1552 _route->foreach_redirect (this, &RouteTimeAxisView::add_redirect_to_subplugin_menu);
1553 _route->foreach_redirect (this, &RouteTimeAxisView::add_existing_redirect_automation_curves);
1555 for (list<RedirectAutomationInfo*>::iterator i = redirect_automation.begin(); i != redirect_automation.end(); ) {
1557 list<RedirectAutomationInfo*>::iterator tmp;
1565 redirect_automation.erase (i);
1572 /* change in visibility was possible */
1574 _route->gui_changed ("track_height", this);
1577 RedirectAutomationLine *
1578 RouteTimeAxisView::find_redirect_automation_curve (boost::shared_ptr<Redirect> redirect, uint32_t what)
1580 RedirectAutomationNode* ran;
1582 if ((ran = find_redirect_automation_node (redirect, what)) != 0) {
1584 return dynamic_cast<RedirectAutomationLine*> (ran->view->lines.front());
1592 RouteTimeAxisView::reset_redirect_automation_curves ()
1594 for (vector<RedirectAutomationLine*>::iterator i = redirect_automation_curves.begin(); i != redirect_automation_curves.end(); ++i) {