2 Copyright (C) 2000 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.
26 #include <libgnomecanvasmm.h>
27 #include <libgnomecanvasmm/canvas.h>
28 #include <libgnomecanvasmm/item.h>
30 #include "pbd/error.h"
31 #include "pbd/convert.h"
33 #include <gtkmm2ext/doi.h>
34 #include <gtkmm2ext/utils.h>
35 #include <gtkmm2ext/selector.h>
37 #include "ardour_ui.h"
38 #include "ardour_dialog.h"
39 #include "global_signals.h"
40 #include "gui_thread.h"
41 #include "public_editor.h"
42 #include "time_axis_view.h"
43 #include "region_view.h"
44 #include "ghostregion.h"
45 #include "simplerect.h"
46 #include "simpleline.h"
47 #include "selection.h"
49 #include "rgb_macros.h"
51 #include "streamview.h"
52 #include "editor_drag.h"
60 using namespace ARDOUR;
62 using namespace Editing;
63 using namespace ArdourCanvas;
64 using Gtkmm2ext::Keyboard;
66 const double trim_handle_size = 6.0; /* pixels */
67 uint32_t TimeAxisView::button_height = 0;
68 uint32_t TimeAxisView::extra_height = 0;
69 int const TimeAxisView::_max_order = 512;
70 PBD::Signal1<void,TimeAxisView*> TimeAxisView::CatchDeletion;
72 TimeAxisView::TimeAxisView (ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* rent, Canvas& /*canvas*/)
74 , controls_table (2, 8)
75 , _name_editing (false)
81 , in_destructor (false)
89 , _effective_height (0)
90 , _resize_drag_start (-1)
91 , _preresize_cursor (0)
92 , _have_preresize_cursor (false)
94 , _ebox_release_can_act (true)
96 if (extra_height == 0) {
100 _canvas_background = new Group (*ed.get_background_group (), 0.0, 0.0);
101 _canvas_display = new Group (*ed.get_trackview_group (), 0.0, 0.0);
102 _canvas_display->hide(); // reveal as needed
104 selection_group = new Group (*_canvas_display);
105 selection_group->set_data (X_("timeselection"), (void *) 1);
106 selection_group->hide();
108 _ghost_group = new Group (*_canvas_display);
109 _ghost_group->lower_to_bottom();
110 _ghost_group->show();
112 name_label.set_name ("TrackLabel");
113 name_label.set_alignment (0.0, 0.5);
114 ARDOUR_UI::instance()->set_tip (name_label, _("Track/Bus name (double click to edit)"));
116 Gtk::Entry* an_entry = new Gtk::Entry;
117 Gtk::Requisition req;
118 an_entry->size_request (req);
119 name_label.set_size_request (-1, req.height);
122 name_hbox.pack_start (name_label, true, true);
126 controls_table.set_size_request (200);
127 controls_table.set_row_spacings (2);
128 controls_table.set_col_spacings (2);
129 controls_table.set_border_width (2);
130 controls_table.set_homogeneous (true);
132 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 3, 0);
133 controls_table.show_all ();
134 controls_table.set_no_show_all ();
136 HSeparator* separator = manage (new HSeparator());
137 separator->set_size_request(-1, 1);
140 controls_vbox.pack_start (controls_table, false, false);
141 controls_vbox.show ();
143 controls_hbox.pack_start (controls_vbox, true, true);
144 controls_hbox.show ();
146 //controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
147 controls_ebox.add (controls_hbox);
148 controls_ebox.add_events (Gdk::BUTTON_PRESS_MASK|
149 Gdk::BUTTON_RELEASE_MASK|
150 Gdk::POINTER_MOTION_MASK|
151 Gdk::ENTER_NOTIFY_MASK|
152 Gdk::LEAVE_NOTIFY_MASK|
154 controls_ebox.set_flags (CAN_FOCUS);
156 /* note that this handler connects *before* the default handler */
157 controls_ebox.signal_scroll_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_scroll), true);
158 controls_ebox.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_press));
159 controls_ebox.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
160 controls_ebox.signal_motion_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_motion));
161 controls_ebox.signal_leave_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_leave));
162 controls_ebox.show ();
164 time_axis_vbox.pack_start (controls_ebox, true, true, 0);
165 time_axis_vbox.pack_end (*separator, false, false);
166 time_axis_vbox.show();
168 ColorsChanged.connect (sigc::mem_fun (*this, &TimeAxisView::color_handler));
170 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
173 TimeAxisView::~TimeAxisView()
175 in_destructor = true;
177 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
181 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
183 delete (*i)->start_trim;
184 delete (*i)->end_trim;
188 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
190 delete (*i)->start_trim;
191 delete (*i)->end_trim;
194 delete selection_group;
197 delete _canvas_background;
198 _canvas_background = 0;
200 delete _canvas_display;
210 TimeAxisView::hide ()
216 _canvas_display->hide ();
217 _canvas_background->hide ();
219 if (control_parent) {
220 control_parent->remove (time_axis_vbox);
227 /* now hide children */
229 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
233 /* if its hidden, it cannot be selected */
234 _editor.get_selection().remove (this);
235 /* and neither can its regions */
236 _editor.get_selection().remove_regions (this);
241 /** Display this TimeAxisView as the nth component of the parent box, at y.
243 * @param y y position.
244 * @param nth index for this TimeAxisView, increased if this view has children.
245 * @param parent parent component.
246 * @return height of this TimeAxisView.
249 TimeAxisView::show_at (double y, int& nth, VBox *parent)
251 if (control_parent) {
252 control_parent->reorder_child (time_axis_vbox, nth);
254 control_parent = parent;
255 parent->pack_start (time_axis_vbox, false, false);
256 parent->reorder_child (time_axis_vbox, nth);
261 if (_y_position != y) {
262 _canvas_display->property_y () = y;
263 _canvas_background->property_y () = y;
265 _canvas_display->move (0.0, 0.0);
266 _canvas_background->move (0.0, 0.0);
271 _canvas_background->raise_to_top ();
272 _canvas_display->raise_to_top ();
274 _canvas_background->show ();
275 _canvas_display->show ();
279 _effective_height = current_height ();
281 /* now show relevant children */
283 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
284 if ((*i)->marked_for_display()) {
286 _effective_height += (*i)->show_at (y + _effective_height, nth, parent);
292 return _effective_height;
296 TimeAxisView::clip_to_viewport ()
298 if (marked_for_display()) {
299 if (_y_position + _effective_height < _editor.get_trackview_group_vertical_offset () || _y_position > _editor.get_trackview_group_vertical_offset () + _canvas_display->get_canvas()->get_height()) {
300 _canvas_background->hide ();
301 _canvas_display->hide ();
304 _canvas_background->show ();
305 _canvas_display->show ();
311 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
313 switch (ev->direction) {
315 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollZoomVerticalModifier)) {
316 /* See Editor::_stepping_axis_view for notes on this hack */
317 Editor& e = dynamic_cast<Editor&> (_editor);
318 if (!e.stepping_axis_view ()) {
319 e.set_stepping_axis_view (this);
321 e.stepping_axis_view()->step_height (false);
323 } else if (Keyboard::no_modifiers_active (ev->state)) {
324 _editor.scroll_tracks_up_line();
329 case GDK_SCROLL_DOWN:
330 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollZoomVerticalModifier)) {
331 /* See Editor::_stepping_axis_view for notes on this hack */
332 Editor& e = dynamic_cast<Editor&> (_editor);
333 if (!e.stepping_axis_view ()) {
334 e.set_stepping_axis_view (this);
336 e.stepping_axis_view()->step_height (true);
338 } else if (Keyboard::no_modifiers_active (ev->state)) {
339 _editor.scroll_tracks_down_line();
345 /* no handling for left/right, yet */
353 TimeAxisView::controls_ebox_button_press (GdkEventButton* event)
355 if ((event->button == 1 && event->type == GDK_2BUTTON_PRESS) || Keyboard::is_edit_event (event)) {
356 /* see if it is inside the name label */
357 if (name_label.is_ancestor (controls_ebox)) {
360 controls_ebox.translate_coordinates (name_label, event->x, event->y, nlx, nly);
361 Gtk::Allocation a = name_label.get_allocation ();
362 if (nlx > 0 && nlx < a.get_width() && nly > 0 && nly < a.get_height()) {
364 _ebox_release_can_act = false;
371 _ebox_release_can_act = true;
373 if (maybe_set_cursor (event->y) > 0) {
374 _resize_drag_start = event->y_root;
381 TimeAxisView::idle_resize (uint32_t h)
388 TimeAxisView::controls_ebox_motion (GdkEventMotion* ev)
390 if (_resize_drag_start >= 0) {
391 /* (ab)use the DragManager to do autoscrolling; adjust the event coordinates
392 into the world coordinate space that DragManager::motion_handler is expecting,
393 and then fake a DragManager motion event so that when maybe_autoscroll
394 asks DragManager for the current pointer position it will get the correct
398 controls_ebox.translate_coordinates (*control_parent, ev->x, ev->y, tx, ty);
399 ev->y = ty - _editor.get_trackview_group_vertical_offset();
400 _editor.drags()->motion_handler ((GdkEvent *) ev, false);
401 _editor.maybe_autoscroll (false, true, false, ev->y_root < _resize_drag_start);
403 /* now do the actual TAV resize */
404 int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
405 _editor.add_to_idle_resize (this, delta);
406 _resize_drag_start = ev->y_root;
408 /* not dragging but ... */
409 maybe_set_cursor (ev->y);
416 TimeAxisView::controls_ebox_leave (GdkEventCrossing*)
418 if (_have_preresize_cursor) {
419 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
420 _have_preresize_cursor = false;
426 TimeAxisView::maybe_set_cursor (int y)
428 /* XXX no Gtkmm Gdk::Window::get_cursor() */
429 Glib::RefPtr<Gdk::Window> win = controls_ebox.get_window();
431 if (y > (gint) floor (controls_ebox.get_height() * 0.75)) {
433 /* y-coordinate in lower 25% */
435 if (!_have_preresize_cursor) {
436 _preresize_cursor = gdk_window_get_cursor (win->gobj());
437 _have_preresize_cursor = true;
438 win->set_cursor (Gdk::Cursor(Gdk::SB_V_DOUBLE_ARROW));
443 } else if (_have_preresize_cursor) {
444 gdk_window_set_cursor (win->gobj(), _preresize_cursor);
445 _have_preresize_cursor = false;
454 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
456 if (_resize_drag_start >= 0) {
457 if (_have_preresize_cursor) {
458 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
459 _preresize_cursor = 0;
460 _have_preresize_cursor = false;
462 _editor.stop_canvas_autoscroll ();
463 _resize_drag_start = -1;
466 if (!_ebox_release_can_act) {
470 switch (ev->button) {
472 selection_click (ev);
476 popup_display_menu (ev->time);
484 TimeAxisView::selection_click (GdkEventButton* ev)
486 Selection::Operation op = ArdourKeyboard::selection_type (ev->state);
487 _editor.set_selected_track (*this, op, false);
491 /** Steps through the defined heights for this TrackView.
492 * @param coarser true if stepping should decrease in size, otherwise false.
495 TimeAxisView::step_height (bool coarser)
497 static const uint32_t step = 25;
501 if (height <= preset_height (HeightSmall)) {
503 } else if (height <= preset_height (HeightNormal) && height > preset_height (HeightSmall)) {
504 set_height_enum (HeightSmall);
506 set_height (height - step);
511 if (height <= preset_height(HeightSmall)) {
512 set_height_enum (HeightNormal);
514 set_height (height + step);
521 TimeAxisView::set_height_enum (Height h, bool apply_to_selection)
523 if (apply_to_selection) {
524 _editor.get_selection().tracks.foreach_time_axis (boost::bind (&TimeAxisView::set_height_enum, _1, h, false));
526 set_height (preset_height (h));
531 TimeAxisView::set_height (uint32_t h)
533 if (h < preset_height (HeightSmall)) {
534 h = preset_height (HeightSmall);
537 time_axis_vbox.property_height_request () = h;
541 snprintf (buf, sizeof (buf), "%u", height);
542 set_gui_property ("height", buf);
544 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
548 if (canvas_item_visible (selection_group)) {
549 /* resize the selection rect */
550 show_selection (_editor.get_selection().time);
555 TimeAxisView::name_entry_key_press (GdkEventKey* ev)
557 /* steal escape, tabs from GTK */
559 switch (ev->keyval) {
561 case GDK_ISO_Left_Tab:
569 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
571 TrackViewList::iterator i;
573 switch (ev->keyval) {
575 end_name_edit (RESPONSE_CANCEL);
578 /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
579 * generates a different ev->keyval, rather than setting
582 case GDK_ISO_Left_Tab:
583 end_name_edit (RESPONSE_APPLY);
587 end_name_edit (RESPONSE_ACCEPT);
597 TimeAxisView::name_entry_focus_out (GdkEventFocus*)
599 end_name_edit (RESPONSE_OK);
604 TimeAxisView::begin_name_edit ()
610 if (can_edit_name()) {
612 name_entry = manage (new Gtkmm2ext::FocusEntry);
614 name_entry->set_name ("EditorTrackNameDisplay");
615 name_entry->signal_key_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_press), false);
616 name_entry->signal_key_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_release), false);
617 name_entry->signal_focus_out_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_out));
618 name_entry->set_text (name_label.get_text());
619 name_entry->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TimeAxisView::end_name_edit), RESPONSE_OK));
621 if (name_label.is_ancestor (name_hbox)) {
622 name_hbox.remove (name_label);
625 name_hbox.pack_start (*name_entry);
628 name_entry->select_region (0, -1);
629 name_entry->set_state (STATE_SELECTED);
630 name_entry->grab_focus ();
631 name_entry->start_editing (0);
636 TimeAxisView::end_name_edit (int response)
642 bool edit_next = false;
643 bool edit_prev = false;
646 case RESPONSE_CANCEL:
649 name_entry_changed ();
651 case RESPONSE_ACCEPT:
652 name_entry_changed ();
655 name_entry_changed ();
659 /* this will delete the name_entry. but it will also drop focus, which
660 * will cause another callback to this function, so set name_entry = 0
661 * first to ensure we don't double-remove etc. etc.
664 Gtk::Entry* tmp = name_entry;
666 name_hbox.remove (*tmp);
668 /* put the name label back */
670 name_hbox.pack_start (name_label);
675 TrackViewList const & allviews = _editor.get_track_views ();
676 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
678 if (i != allviews.end()) {
681 if (++i == allviews.end()) {
685 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
687 if (rtav && rtav->route()->record_enabled()) {
691 if (!(*i)->hidden()) {
698 if ((i != allviews.end()) && (*i != this) && !(*i)->hidden()) {
699 _editor.ensure_time_axis_view_is_visible (**i);
700 (*i)->begin_name_edit ();
703 } else if (edit_prev) {
705 TrackViewList const & allviews = _editor.get_track_views ();
706 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
708 if (i != allviews.begin()) {
710 if (i == allviews.begin()) {
716 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
718 if (rtav && rtav->route()->record_enabled()) {
722 if (!(*i)->hidden()) {
729 if ((i != allviews.end()) && (*i != this) && !(*i)->hidden()) {
730 _editor.ensure_time_axis_view_is_visible (**i);
731 (*i)->begin_name_edit ();
737 TimeAxisView::name_entry_changed ()
742 TimeAxisView::can_edit_name () const
748 TimeAxisView::conditionally_add_to_selection ()
750 Selection& s (_editor.get_selection ());
752 if (!s.selected (this)) {
753 _editor.set_selected_track (*this, Selection::Set);
758 TimeAxisView::popup_display_menu (guint32 when)
760 conditionally_add_to_selection ();
762 build_display_menu ();
763 display_menu->popup (1, when);
767 TimeAxisView::set_selected (bool yn)
769 if (yn == _selected) {
773 Selectable::set_selected (yn);
776 controls_ebox.set_name (controls_base_selected_name);
777 time_axis_vbox.set_name (controls_base_selected_name);
778 controls_vbox.set_name (controls_base_selected_name);
780 controls_ebox.set_name (controls_base_unselected_name);
781 time_axis_vbox.set_name (controls_base_unselected_name);
782 controls_vbox.set_name (controls_base_unselected_name);
785 /* children will be set for the yn=true case. but when deselecting
786 the editor only has a list of top-level trackviews, so we
787 have to do this here.
790 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
791 (*i)->set_selected (false);
797 TimeAxisView::build_display_menu ()
799 using namespace Menu_Helpers;
803 display_menu = new Menu;
804 display_menu->set_name ("ArdourContextMenu");
806 // Just let implementing classes define what goes into the manu
810 TimeAxisView::set_samples_per_unit (double spu)
812 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
813 (*i)->set_samples_per_unit (spu);
816 AnalysisFeatureList::const_iterator i;
817 list<ArdourCanvas::SimpleLine*>::iterator l;
821 TimeAxisView::show_timestretch (framepos_t start, framepos_t end, int layers, int layer)
823 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
824 (*i)->show_timestretch (start, end, layers, layer);
829 TimeAxisView::hide_timestretch ()
831 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
832 (*i)->hide_timestretch ();
837 TimeAxisView::show_selection (TimeSelection& ts)
844 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
845 (*i)->show_selection (ts);
848 if (canvas_item_visible (selection_group)) {
849 while (!used_selection_rects.empty()) {
850 free_selection_rects.push_front (used_selection_rects.front());
851 used_selection_rects.pop_front();
852 free_selection_rects.front()->rect->hide();
853 free_selection_rects.front()->start_trim->hide();
854 free_selection_rects.front()->end_trim->hide();
856 selection_group->hide();
859 selection_group->show();
860 selection_group->raise_to_top();
862 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
863 framepos_t start, end;
868 cnt = end - start + 1;
870 rect = get_selection_rect ((*i).id);
872 x1 = _editor.frame_to_unit (start);
873 x2 = _editor.frame_to_unit (start + cnt - 1);
874 y2 = current_height();
876 rect->rect->property_x1() = x1;
877 rect->rect->property_y1() = 1.0;
878 rect->rect->property_x2() = x2;
879 rect->rect->property_y2() = y2;
881 // trim boxes are at the top for selections
884 rect->start_trim->property_x1() = x1;
885 rect->start_trim->property_y1() = 1.0;
886 rect->start_trim->property_x2() = x1 + trim_handle_size;
887 rect->start_trim->property_y2() = y2;
889 rect->end_trim->property_x1() = x2 - trim_handle_size;
890 rect->end_trim->property_y1() = 1.0;
891 rect->end_trim->property_x2() = x2;
892 rect->end_trim->property_y2() = y2;
894 rect->start_trim->show();
895 rect->end_trim->show();
897 rect->start_trim->hide();
898 rect->end_trim->hide();
902 used_selection_rects.push_back (rect);
907 TimeAxisView::reshow_selection (TimeSelection& ts)
911 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
912 (*i)->show_selection (ts);
917 TimeAxisView::hide_selection ()
919 if (canvas_item_visible (selection_group)) {
920 while (!used_selection_rects.empty()) {
921 free_selection_rects.push_front (used_selection_rects.front());
922 used_selection_rects.pop_front();
923 free_selection_rects.front()->rect->hide();
924 free_selection_rects.front()->start_trim->hide();
925 free_selection_rects.front()->end_trim->hide();
927 selection_group->hide();
930 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
931 (*i)->hide_selection ();
936 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
938 /* find the selection rect this is for. we have the item corresponding to one
942 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
943 if ((*i)->start_trim == item || (*i)->end_trim == item) {
945 /* make one trim handle be "above" the other so that if they overlap,
946 the top one is the one last used.
949 (*i)->rect->raise_to_top ();
950 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
951 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
959 TimeAxisView::get_selection_rect (uint32_t id)
963 /* check to see if we already have a visible rect for this particular selection ID */
965 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
966 if ((*i)->id == id) {
971 /* ditto for the free rect list */
973 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
974 if ((*i)->id == id) {
975 SelectionRect* ret = (*i);
976 free_selection_rects.erase (i);
981 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
983 if (free_selection_rects.empty()) {
985 rect = new SelectionRect;
987 rect->rect = new SimpleRect (*selection_group);
988 rect->rect->property_outline_what() = 0x0;
989 rect->rect->property_x1() = 0.0;
990 rect->rect->property_y1() = 0.0;
991 rect->rect->property_x2() = 0.0;
992 rect->rect->property_y2() = 0.0;
993 rect->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
995 rect->start_trim = new SimpleRect (*selection_group);
996 rect->start_trim->property_outline_what() = 0x0;
997 rect->start_trim->property_x1() = 0.0;
998 rect->start_trim->property_x2() = 0.0;
1000 rect->end_trim = new SimpleRect (*selection_group);
1001 rect->end_trim->property_outline_what() = 0x0;
1002 rect->end_trim->property_x1() = 0.0;
1003 rect->end_trim->property_x2() = 0.0;
1005 free_selection_rects.push_front (rect);
1007 rect->rect->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
1008 rect->start_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
1009 rect->end_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
1012 rect = free_selection_rects.front();
1014 free_selection_rects.pop_front();
1018 struct null_deleter { void operator()(void const *) const {} };
1021 TimeAxisView::is_child (TimeAxisView* tav)
1023 return find (children.begin(), children.end(), boost::shared_ptr<TimeAxisView>(tav, null_deleter())) != children.end();
1027 TimeAxisView::add_child (boost::shared_ptr<TimeAxisView> child)
1029 children.push_back (child);
1033 TimeAxisView::remove_child (boost::shared_ptr<TimeAxisView> child)
1035 Children::iterator i;
1037 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
1042 /** Get selectable things within a given range.
1043 * @param start Start time in session frames.
1044 * @param end End time in session frames.
1045 * @param top Top y range, in trackview coordinates (ie 0 is the top of the track view)
1046 * @param bot Bottom y range, in trackview coordinates (ie 0 is the top of the track view)
1047 * @param result Filled in with selectable things.
1050 TimeAxisView::get_selectables (framepos_t /*start*/, framepos_t /*end*/, double /*top*/, double /*bot*/, list<Selectable*>& /*result*/)
1056 TimeAxisView::get_inverted_selectables (Selection& /*sel*/, list<Selectable*>& /*result*/)
1062 TimeAxisView::add_ghost (RegionView* rv)
1064 GhostRegion* gr = rv->add_ghost (*this);
1067 ghosts.push_back(gr);
1072 TimeAxisView::remove_ghost (RegionView* rv)
1074 rv->remove_ghost_in (*this);
1078 TimeAxisView::erase_ghost (GhostRegion* gr)
1080 if (in_destructor) {
1084 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1093 TimeAxisView::touched (double top, double bot)
1095 /* remember: this is X Window - coordinate space starts in upper left and moves down.
1096 y_position is the "origin" or "top" of the track.
1099 double mybot = _y_position + current_height();
1101 return ((_y_position <= bot && _y_position >= top) ||
1102 ((mybot <= bot) && (top < mybot)) ||
1103 (mybot >= bot && _y_position < top));
1107 TimeAxisView::set_parent (TimeAxisView& p)
1113 TimeAxisView::reset_height ()
1115 set_height (height);
1117 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1118 (*i)->set_height ((*i)->height);
1123 TimeAxisView::compute_heights ()
1125 Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
1126 Gtk::Table two_row_table (2, 8);
1127 Gtk::Table one_row_table (1, 8);
1129 const int border_width = 2;
1131 const int separator_height = 2;
1132 extra_height = (2 * border_width) + separator_height;
1134 window.add (one_row_table);
1136 one_row_table.set_border_width (border_width);
1137 one_row_table.set_row_spacings (0);
1138 one_row_table.set_col_spacings (0);
1139 one_row_table.set_homogeneous (true);
1141 two_row_table.set_border_width (border_width);
1142 two_row_table.set_row_spacings (0);
1143 two_row_table.set_col_spacings (0);
1144 two_row_table.set_homogeneous (true);
1146 for (int i = 0; i < 5; ++i) {
1147 buttons[i] = manage (new Button (X_("f")));
1148 buttons[i]->set_name ("TrackMuteButton");
1151 one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1153 one_row_table.show_all ();
1154 Gtk::Requisition req(one_row_table.size_request ());
1156 // height required to show 1 row of buttons
1157 button_height = req.height;
1161 TimeAxisView::color_handler ()
1163 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); i++) {
1167 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
1169 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1170 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1172 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1173 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1175 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1176 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1179 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
1181 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1182 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1184 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1185 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1187 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1188 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1192 /** @return Pair: TimeAxisView, layer index.
1193 * TimeAxisView is non-0 if this object covers y, or one of its children does.
1194 * If the covering object is a child axis, then the child is returned.
1195 * TimeAxisView is 0 otherwise.
1196 * Layer index is the layer number (possibly fractional) if the TimeAxisView is valid
1197 * and is in stacked or expanded * region display mode, otherwise 0.
1199 std::pair<TimeAxisView*, double>
1200 TimeAxisView::covers_y_position (double y)
1203 return std::make_pair ((TimeAxisView *) 0, 0);
1206 if (_y_position <= y && y < (_y_position + height)) {
1208 /* work out the layer index if appropriate */
1210 switch (layer_display ()) {
1216 l = layer_t ((_y_position + height - y) / (view()->child_height ()));
1217 /* clamp to max layers to be on the safe side; sometimes the above calculation
1218 returns a too-high value */
1219 if (l >= view()->layers ()) {
1220 l = view()->layers() - 1;
1226 int const n = floor ((_y_position + height - y) / (view()->child_height ()));
1228 if (l >= (view()->layers() - 0.5)) {
1229 l = view()->layers() - 0.5;
1235 return std::make_pair (this, l);
1238 for (Children::const_iterator i = children.begin(); i != children.end(); ++i) {
1240 std::pair<TimeAxisView*, int> const r = (*i)->covers_y_position (y);
1246 return std::make_pair ((TimeAxisView *) 0, 0);
1251 TimeAxisView::preset_height (Height h)
1255 return (button_height * 2) + extra_height + 260;
1257 return (button_height * 2) + extra_height + 160;
1259 return (button_height * 2) + extra_height + 60;
1261 return (button_height * 2) + extra_height + 10;
1263 return button_height + extra_height;
1270 /** @return Child time axis views that are not hidden */
1271 TimeAxisView::Children
1272 TimeAxisView::get_child_list ()
1276 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1277 if (!(*i)->hidden()) {
1286 TimeAxisView::build_size_menu ()
1288 if (_size_menu && _size_menu->gobj ()) {
1294 using namespace Menu_Helpers;
1296 _size_menu = new Menu;
1297 _size_menu->set_name ("ArdourContextMenu");
1298 MenuList& items = _size_menu->items();
1300 items.push_back (MenuElem (_("Largest"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLargest, true)));
1301 items.push_back (MenuElem (_("Larger"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarger, true)));
1302 items.push_back (MenuElem (_("Large"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarge, true)));
1303 items.push_back (MenuElem (_("Normal"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightNormal, true)));
1304 items.push_back (MenuElem (_("Small"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightSmall, true)));
1308 TimeAxisView::reset_visual_state ()
1310 /* this method is not required to trigger a global redraw */
1312 string str = gui_property ("height");
1315 set_height (atoi (str));
1317 set_height (preset_height (HeightNormal));
1322 TrackViewList::filter_to_unique_playlists ()
1324 std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
1327 for (iterator i = begin(); i != end(); ++i) {
1328 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*i);
1330 /* not a route: include it anyway */
1333 boost::shared_ptr<ARDOUR::Track> t = rtav->track();
1335 if (playlists.insert (t->playlist()).second) {
1336 /* playlist not seen yet */
1340 /* not a track: include it anyway */