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_name("TrackSeparator");
138 separator->set_size_request(-1, 1);
141 controls_vbox.pack_start (controls_table, false, false);
142 controls_vbox.show ();
144 controls_hbox.pack_start (controls_vbox, true, true);
145 controls_hbox.show ();
147 //controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
148 controls_ebox.add (controls_hbox);
149 controls_ebox.add_events (Gdk::BUTTON_PRESS_MASK|
150 Gdk::BUTTON_RELEASE_MASK|
151 Gdk::POINTER_MOTION_MASK|
152 Gdk::ENTER_NOTIFY_MASK|
153 Gdk::LEAVE_NOTIFY_MASK|
155 controls_ebox.set_flags (CAN_FOCUS);
157 /* note that this handler connects *before* the default handler */
158 controls_ebox.signal_scroll_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_scroll), true);
159 controls_ebox.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_press));
160 controls_ebox.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
161 controls_ebox.signal_motion_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_motion));
162 controls_ebox.signal_leave_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_leave));
163 controls_ebox.show ();
165 time_axis_vbox.pack_start (controls_ebox, true, true, 0);
166 time_axis_vbox.pack_end (*separator, false, false);
167 time_axis_vbox.show();
169 ColorsChanged.connect (sigc::mem_fun (*this, &TimeAxisView::color_handler));
171 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
174 TimeAxisView::~TimeAxisView()
176 in_destructor = true;
178 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
182 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
184 delete (*i)->start_trim;
185 delete (*i)->end_trim;
189 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
191 delete (*i)->start_trim;
192 delete (*i)->end_trim;
195 delete selection_group;
198 delete _canvas_background;
199 _canvas_background = 0;
201 delete _canvas_display;
211 TimeAxisView::hide ()
217 _canvas_display->hide ();
218 _canvas_background->hide ();
220 if (control_parent) {
221 control_parent->remove (time_axis_vbox);
228 /* now hide children */
230 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
234 /* if its hidden, it cannot be selected */
235 _editor.get_selection().remove (this);
236 /* and neither can its regions */
237 _editor.get_selection().remove_regions (this);
242 /** Display this TimeAxisView as the nth component of the parent box, at y.
244 * @param y y position.
245 * @param nth index for this TimeAxisView, increased if this view has children.
246 * @param parent parent component.
247 * @return height of this TimeAxisView.
250 TimeAxisView::show_at (double y, int& nth, VBox *parent)
252 if (control_parent) {
253 control_parent->reorder_child (time_axis_vbox, nth);
255 control_parent = parent;
256 parent->pack_start (time_axis_vbox, false, false);
257 parent->reorder_child (time_axis_vbox, nth);
262 if (_y_position != y) {
263 _canvas_display->property_y () = y;
264 _canvas_background->property_y () = y;
266 _canvas_display->move (0.0, 0.0);
267 _canvas_background->move (0.0, 0.0);
272 _canvas_background->raise_to_top ();
273 _canvas_display->raise_to_top ();
275 _canvas_background->show ();
276 _canvas_display->show ();
280 _effective_height = current_height ();
282 /* now show relevant children */
284 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
285 if ((*i)->marked_for_display()) {
287 _effective_height += (*i)->show_at (y + _effective_height, nth, parent);
293 return _effective_height;
297 TimeAxisView::clip_to_viewport ()
299 if (marked_for_display()) {
300 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()) {
301 _canvas_background->hide ();
302 _canvas_display->hide ();
305 _canvas_background->show ();
306 _canvas_display->show ();
312 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
314 switch (ev->direction) {
316 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollZoomVerticalModifier)) {
317 /* See Editor::_stepping_axis_view for notes on this hack */
318 Editor& e = dynamic_cast<Editor&> (_editor);
319 if (!e.stepping_axis_view ()) {
320 e.set_stepping_axis_view (this);
322 e.stepping_axis_view()->step_height (false);
324 } else if (Keyboard::no_modifiers_active (ev->state)) {
325 _editor.scroll_tracks_up_line();
330 case GDK_SCROLL_DOWN:
331 if (Keyboard::modifier_state_equals (ev->state, Keyboard::ScrollZoomVerticalModifier)) {
332 /* See Editor::_stepping_axis_view for notes on this hack */
333 Editor& e = dynamic_cast<Editor&> (_editor);
334 if (!e.stepping_axis_view ()) {
335 e.set_stepping_axis_view (this);
337 e.stepping_axis_view()->step_height (true);
339 } else if (Keyboard::no_modifiers_active (ev->state)) {
340 _editor.scroll_tracks_down_line();
346 /* no handling for left/right, yet */
354 TimeAxisView::controls_ebox_button_press (GdkEventButton* event)
356 if ((event->button == 1 && event->type == GDK_2BUTTON_PRESS) || Keyboard::is_edit_event (event)) {
357 /* see if it is inside the name label */
358 if (name_label.is_ancestor (controls_ebox)) {
361 controls_ebox.translate_coordinates (name_label, event->x, event->y, nlx, nly);
362 Gtk::Allocation a = name_label.get_allocation ();
363 if (nlx > 0 && nlx < a.get_width() && nly > 0 && nly < a.get_height()) {
365 _ebox_release_can_act = false;
372 _ebox_release_can_act = true;
374 if (maybe_set_cursor (event->y) > 0) {
375 _resize_drag_start = event->y_root;
382 TimeAxisView::idle_resize (uint32_t h)
389 TimeAxisView::controls_ebox_motion (GdkEventMotion* ev)
391 if (_resize_drag_start >= 0) {
392 /* (ab)use the DragManager to do autoscrolling; adjust the event coordinates
393 into the world coordinate space that DragManager::motion_handler is expecting,
394 and then fake a DragManager motion event so that when maybe_autoscroll
395 asks DragManager for the current pointer position it will get the correct
399 controls_ebox.translate_coordinates (*control_parent, ev->x, ev->y, tx, ty);
400 ev->y = ty - _editor.get_trackview_group_vertical_offset();
401 _editor.drags()->motion_handler ((GdkEvent *) ev, false);
402 _editor.maybe_autoscroll (false, true, false, ev->y_root < _resize_drag_start);
404 /* now do the actual TAV resize */
405 int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
406 _editor.add_to_idle_resize (this, delta);
407 _resize_drag_start = ev->y_root;
409 /* not dragging but ... */
410 maybe_set_cursor (ev->y);
413 gdk_event_request_motions(ev);
418 TimeAxisView::controls_ebox_leave (GdkEventCrossing*)
420 if (_have_preresize_cursor) {
421 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
422 _have_preresize_cursor = false;
428 TimeAxisView::maybe_set_cursor (int y)
430 /* XXX no Gtkmm Gdk::Window::get_cursor() */
431 Glib::RefPtr<Gdk::Window> win = controls_ebox.get_window();
433 if (y > (gint) floor (controls_ebox.get_height() * 0.75)) {
435 /* y-coordinate in lower 25% */
437 if (!_have_preresize_cursor) {
438 _preresize_cursor = gdk_window_get_cursor (win->gobj());
439 _have_preresize_cursor = true;
440 win->set_cursor (Gdk::Cursor(Gdk::SB_V_DOUBLE_ARROW));
445 } else if (_have_preresize_cursor) {
446 gdk_window_set_cursor (win->gobj(), _preresize_cursor);
447 _have_preresize_cursor = false;
456 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
458 if (_resize_drag_start >= 0) {
459 if (_have_preresize_cursor) {
460 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
461 _preresize_cursor = 0;
462 _have_preresize_cursor = false;
464 _editor.stop_canvas_autoscroll ();
465 _resize_drag_start = -1;
468 if (!_ebox_release_can_act) {
472 switch (ev->button) {
474 selection_click (ev);
478 popup_display_menu (ev->time);
486 TimeAxisView::selection_click (GdkEventButton* ev)
488 Selection::Operation op = ArdourKeyboard::selection_type (ev->state);
489 _editor.set_selected_track (*this, op, false);
493 /** Steps through the defined heights for this TrackView.
494 * @param coarser true if stepping should decrease in size, otherwise false.
497 TimeAxisView::step_height (bool coarser)
499 static const uint32_t step = 25;
503 if (height <= preset_height (HeightSmall)) {
505 } else if (height <= preset_height (HeightNormal) && height > preset_height (HeightSmall)) {
506 set_height_enum (HeightSmall);
508 set_height (height - step);
513 if (height <= preset_height(HeightSmall)) {
514 set_height_enum (HeightNormal);
516 set_height (height + step);
523 TimeAxisView::set_height_enum (Height h, bool apply_to_selection)
525 if (apply_to_selection) {
526 _editor.get_selection().tracks.foreach_time_axis (boost::bind (&TimeAxisView::set_height_enum, _1, h, false));
528 set_height (preset_height (h));
533 TimeAxisView::set_height (uint32_t h)
535 if (h < preset_height (HeightSmall)) {
536 h = preset_height (HeightSmall);
539 time_axis_vbox.property_height_request () = h;
543 snprintf (buf, sizeof (buf), "%u", height);
544 set_gui_property ("height", buf);
546 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
550 if (canvas_item_visible (selection_group)) {
551 /* resize the selection rect */
552 show_selection (_editor.get_selection().time);
557 TimeAxisView::name_entry_key_press (GdkEventKey* ev)
559 /* steal escape, tabs from GTK */
561 switch (ev->keyval) {
563 case GDK_ISO_Left_Tab:
571 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
573 TrackViewList::iterator i;
575 switch (ev->keyval) {
577 end_name_edit (RESPONSE_CANCEL);
580 /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
581 * generates a different ev->keyval, rather than setting
584 case GDK_ISO_Left_Tab:
585 end_name_edit (RESPONSE_APPLY);
589 end_name_edit (RESPONSE_ACCEPT);
599 TimeAxisView::name_entry_focus_out (GdkEventFocus*)
601 end_name_edit (RESPONSE_OK);
606 TimeAxisView::begin_name_edit ()
612 if (can_edit_name()) {
614 name_entry = manage (new Gtkmm2ext::FocusEntry);
616 name_entry->set_name ("EditorTrackNameDisplay");
617 name_entry->signal_key_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_press), false);
618 name_entry->signal_key_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_release), false);
619 name_entry->signal_focus_out_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_out));
620 name_entry->set_text (name_label.get_text());
621 name_entry->signal_activate().connect (sigc::bind (sigc::mem_fun (*this, &TimeAxisView::end_name_edit), RESPONSE_OK));
623 if (name_label.is_ancestor (name_hbox)) {
624 name_hbox.remove (name_label);
627 name_hbox.pack_start (*name_entry);
630 name_entry->select_region (0, -1);
631 name_entry->set_state (STATE_SELECTED);
632 name_entry->grab_focus ();
633 name_entry->start_editing (0);
638 TimeAxisView::end_name_edit (int response)
644 bool edit_next = false;
645 bool edit_prev = false;
648 case RESPONSE_CANCEL:
651 name_entry_changed ();
653 case RESPONSE_ACCEPT:
654 name_entry_changed ();
657 name_entry_changed ();
661 /* this will delete the name_entry. but it will also drop focus, which
662 * will cause another callback to this function, so set name_entry = 0
663 * first to ensure we don't double-remove etc. etc.
666 Gtk::Entry* tmp = name_entry;
668 name_hbox.remove (*tmp);
670 /* put the name label back */
672 name_hbox.pack_start (name_label);
677 TrackViewList const & allviews = _editor.get_track_views ();
678 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
680 if (i != allviews.end()) {
683 if (++i == allviews.end()) {
687 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
689 if (rtav && rtav->route()->record_enabled()) {
693 if (!(*i)->hidden()) {
700 if ((i != allviews.end()) && (*i != this) && !(*i)->hidden()) {
701 _editor.ensure_time_axis_view_is_visible (**i);
702 (*i)->begin_name_edit ();
705 } else if (edit_prev) {
707 TrackViewList const & allviews = _editor.get_track_views ();
708 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
710 if (i != allviews.begin()) {
712 if (i == allviews.begin()) {
718 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
720 if (rtav && rtav->route()->record_enabled()) {
724 if (!(*i)->hidden()) {
731 if ((i != allviews.end()) && (*i != this) && !(*i)->hidden()) {
732 _editor.ensure_time_axis_view_is_visible (**i);
733 (*i)->begin_name_edit ();
739 TimeAxisView::name_entry_changed ()
744 TimeAxisView::can_edit_name () const
750 TimeAxisView::conditionally_add_to_selection ()
752 Selection& s (_editor.get_selection ());
754 if (!s.selected (this)) {
755 _editor.set_selected_track (*this, Selection::Set);
760 TimeAxisView::popup_display_menu (guint32 when)
762 conditionally_add_to_selection ();
764 build_display_menu ();
765 display_menu->popup (1, when);
769 TimeAxisView::set_selected (bool yn)
771 if (yn == _selected) {
775 Selectable::set_selected (yn);
778 controls_ebox.set_name (controls_base_selected_name);
779 time_axis_vbox.set_name (controls_base_selected_name);
780 controls_vbox.set_name (controls_base_selected_name);
782 controls_ebox.set_name (controls_base_unselected_name);
783 time_axis_vbox.set_name (controls_base_unselected_name);
784 controls_vbox.set_name (controls_base_unselected_name);
787 /* children will be set for the yn=true case. but when deselecting
788 the editor only has a list of top-level trackviews, so we
789 have to do this here.
792 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
793 (*i)->set_selected (false);
799 TimeAxisView::build_display_menu ()
801 using namespace Menu_Helpers;
805 display_menu = new Menu;
806 display_menu->set_name ("ArdourContextMenu");
808 // Just let implementing classes define what goes into the manu
812 TimeAxisView::set_samples_per_unit (double spu)
814 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
815 (*i)->set_samples_per_unit (spu);
818 AnalysisFeatureList::const_iterator i;
819 list<ArdourCanvas::SimpleLine*>::iterator l;
823 TimeAxisView::show_timestretch (framepos_t start, framepos_t end, int layers, int layer)
825 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
826 (*i)->show_timestretch (start, end, layers, layer);
831 TimeAxisView::hide_timestretch ()
833 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
834 (*i)->hide_timestretch ();
839 TimeAxisView::show_selection (TimeSelection& ts)
846 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
847 (*i)->show_selection (ts);
850 if (canvas_item_visible (selection_group)) {
851 while (!used_selection_rects.empty()) {
852 free_selection_rects.push_front (used_selection_rects.front());
853 used_selection_rects.pop_front();
854 free_selection_rects.front()->rect->hide();
855 free_selection_rects.front()->start_trim->hide();
856 free_selection_rects.front()->end_trim->hide();
858 selection_group->hide();
861 selection_group->show();
862 selection_group->raise_to_top();
864 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
865 framepos_t start, end;
870 cnt = end - start + 1;
872 rect = get_selection_rect ((*i).id);
874 x1 = _editor.frame_to_unit (start);
875 x2 = _editor.frame_to_unit (start + cnt - 1);
876 y2 = current_height();
878 rect->rect->property_x1() = x1;
879 rect->rect->property_y1() = 1.0;
880 rect->rect->property_x2() = x2;
881 rect->rect->property_y2() = y2;
883 // trim boxes are at the top for selections
886 rect->start_trim->property_x1() = x1;
887 rect->start_trim->property_y1() = 1.0;
888 rect->start_trim->property_x2() = x1 + trim_handle_size;
889 rect->start_trim->property_y2() = y2;
891 rect->end_trim->property_x1() = x2 - trim_handle_size;
892 rect->end_trim->property_y1() = 1.0;
893 rect->end_trim->property_x2() = x2;
894 rect->end_trim->property_y2() = y2;
896 rect->start_trim->show();
897 rect->end_trim->show();
899 rect->start_trim->hide();
900 rect->end_trim->hide();
904 used_selection_rects.push_back (rect);
909 TimeAxisView::reshow_selection (TimeSelection& ts)
913 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
914 (*i)->show_selection (ts);
919 TimeAxisView::hide_selection ()
921 if (canvas_item_visible (selection_group)) {
922 while (!used_selection_rects.empty()) {
923 free_selection_rects.push_front (used_selection_rects.front());
924 used_selection_rects.pop_front();
925 free_selection_rects.front()->rect->hide();
926 free_selection_rects.front()->start_trim->hide();
927 free_selection_rects.front()->end_trim->hide();
929 selection_group->hide();
932 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
933 (*i)->hide_selection ();
938 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
940 /* find the selection rect this is for. we have the item corresponding to one
944 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
945 if ((*i)->start_trim == item || (*i)->end_trim == item) {
947 /* make one trim handle be "above" the other so that if they overlap,
948 the top one is the one last used.
951 (*i)->rect->raise_to_top ();
952 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
953 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
961 TimeAxisView::get_selection_rect (uint32_t id)
965 /* check to see if we already have a visible rect for this particular selection ID */
967 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
968 if ((*i)->id == id) {
973 /* ditto for the free rect list */
975 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
976 if ((*i)->id == id) {
977 SelectionRect* ret = (*i);
978 free_selection_rects.erase (i);
983 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
985 if (free_selection_rects.empty()) {
987 rect = new SelectionRect;
989 rect->rect = new SimpleRect (*selection_group);
990 rect->rect->property_outline_what() = 0x0;
991 rect->rect->property_x1() = 0.0;
992 rect->rect->property_y1() = 0.0;
993 rect->rect->property_x2() = 0.0;
994 rect->rect->property_y2() = 0.0;
995 rect->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
997 rect->start_trim = new SimpleRect (*selection_group);
998 rect->start_trim->property_outline_what() = 0x0;
999 rect->start_trim->property_x1() = 0.0;
1000 rect->start_trim->property_x2() = 0.0;
1002 rect->end_trim = new SimpleRect (*selection_group);
1003 rect->end_trim->property_outline_what() = 0x0;
1004 rect->end_trim->property_x1() = 0.0;
1005 rect->end_trim->property_x2() = 0.0;
1007 free_selection_rects.push_front (rect);
1009 rect->rect->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
1010 rect->start_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
1011 rect->end_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
1014 rect = free_selection_rects.front();
1016 free_selection_rects.pop_front();
1020 struct null_deleter { void operator()(void const *) const {} };
1023 TimeAxisView::is_child (TimeAxisView* tav)
1025 return find (children.begin(), children.end(), boost::shared_ptr<TimeAxisView>(tav, null_deleter())) != children.end();
1029 TimeAxisView::add_child (boost::shared_ptr<TimeAxisView> child)
1031 children.push_back (child);
1035 TimeAxisView::remove_child (boost::shared_ptr<TimeAxisView> child)
1037 Children::iterator i;
1039 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
1044 /** Get selectable things within a given range.
1045 * @param start Start time in session frames.
1046 * @param end End time in session frames.
1047 * @param top Top y range, in trackview coordinates (ie 0 is the top of the track view)
1048 * @param bot Bottom y range, in trackview coordinates (ie 0 is the top of the track view)
1049 * @param result Filled in with selectable things.
1052 TimeAxisView::get_selectables (framepos_t /*start*/, framepos_t /*end*/, double /*top*/, double /*bot*/, list<Selectable*>& /*result*/)
1058 TimeAxisView::get_inverted_selectables (Selection& /*sel*/, list<Selectable*>& /*result*/)
1064 TimeAxisView::add_ghost (RegionView* rv)
1066 GhostRegion* gr = rv->add_ghost (*this);
1069 ghosts.push_back(gr);
1074 TimeAxisView::remove_ghost (RegionView* rv)
1076 rv->remove_ghost_in (*this);
1080 TimeAxisView::erase_ghost (GhostRegion* gr)
1082 if (in_destructor) {
1086 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1095 TimeAxisView::touched (double top, double bot)
1097 /* remember: this is X Window - coordinate space starts in upper left and moves down.
1098 y_position is the "origin" or "top" of the track.
1101 double mybot = _y_position + current_height();
1103 return ((_y_position <= bot && _y_position >= top) ||
1104 ((mybot <= bot) && (top < mybot)) ||
1105 (mybot >= bot && _y_position < top));
1109 TimeAxisView::set_parent (TimeAxisView& p)
1115 TimeAxisView::reset_height ()
1117 set_height (height);
1119 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1120 (*i)->set_height ((*i)->height);
1125 TimeAxisView::compute_heights ()
1127 Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
1128 Gtk::Table two_row_table (2, 8);
1129 Gtk::Table one_row_table (1, 8);
1131 const int border_width = 2;
1133 const int separator_height = 2;
1134 extra_height = (2 * border_width) + separator_height;
1136 window.add (one_row_table);
1138 one_row_table.set_border_width (border_width);
1139 one_row_table.set_row_spacings (0);
1140 one_row_table.set_col_spacings (0);
1141 one_row_table.set_homogeneous (true);
1143 two_row_table.set_border_width (border_width);
1144 two_row_table.set_row_spacings (0);
1145 two_row_table.set_col_spacings (0);
1146 two_row_table.set_homogeneous (true);
1148 for (int i = 0; i < 5; ++i) {
1149 buttons[i] = manage (new Button (X_("f")));
1150 buttons[i]->set_name ("TrackMuteButton");
1153 one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1155 one_row_table.show_all ();
1156 Gtk::Requisition req(one_row_table.size_request ());
1158 // height required to show 1 row of buttons
1159 button_height = req.height;
1163 TimeAxisView::color_handler ()
1165 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); i++) {
1169 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
1171 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1172 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1174 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1175 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1177 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1178 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1181 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
1183 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1184 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1186 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1187 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1189 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1190 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1194 /** @return Pair: TimeAxisView, layer index.
1195 * TimeAxisView is non-0 if this object covers y, or one of its children does.
1196 * If the covering object is a child axis, then the child is returned.
1197 * TimeAxisView is 0 otherwise.
1198 * Layer index is the layer number (possibly fractional) if the TimeAxisView is valid
1199 * and is in stacked or expanded * region display mode, otherwise 0.
1201 std::pair<TimeAxisView*, double>
1202 TimeAxisView::covers_y_position (double y)
1205 return std::make_pair ((TimeAxisView *) 0, 0);
1208 if (_y_position <= y && y < (_y_position + height)) {
1210 /* work out the layer index if appropriate */
1212 switch (layer_display ()) {
1218 l = layer_t ((_y_position + height - y) / (view()->child_height ()));
1219 /* clamp to max layers to be on the safe side; sometimes the above calculation
1220 returns a too-high value */
1221 if (l >= view()->layers ()) {
1222 l = view()->layers() - 1;
1228 int const n = floor ((_y_position + height - y) / (view()->child_height ()));
1230 if (l >= (view()->layers() - 0.5)) {
1231 l = view()->layers() - 0.5;
1237 return std::make_pair (this, l);
1240 for (Children::const_iterator i = children.begin(); i != children.end(); ++i) {
1242 std::pair<TimeAxisView*, int> const r = (*i)->covers_y_position (y);
1248 return std::make_pair ((TimeAxisView *) 0, 0);
1253 TimeAxisView::preset_height (Height h)
1257 return (button_height * 2) + extra_height + 260;
1259 return (button_height * 2) + extra_height + 160;
1261 return (button_height * 2) + extra_height + 60;
1263 return (button_height * 2) + extra_height + 10;
1265 return button_height + extra_height;
1272 /** @return Child time axis views that are not hidden */
1273 TimeAxisView::Children
1274 TimeAxisView::get_child_list ()
1278 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1279 if (!(*i)->hidden()) {
1288 TimeAxisView::build_size_menu ()
1290 if (_size_menu && _size_menu->gobj ()) {
1296 using namespace Menu_Helpers;
1298 _size_menu = new Menu;
1299 _size_menu->set_name ("ArdourContextMenu");
1300 MenuList& items = _size_menu->items();
1302 items.push_back (MenuElem (_("Largest"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLargest, true)));
1303 items.push_back (MenuElem (_("Larger"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarger, true)));
1304 items.push_back (MenuElem (_("Large"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarge, true)));
1305 items.push_back (MenuElem (_("Normal"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightNormal, true)));
1306 items.push_back (MenuElem (_("Small"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightSmall, true)));
1310 TimeAxisView::reset_visual_state ()
1312 /* this method is not required to trigger a global redraw */
1314 string str = gui_property ("height");
1317 set_height (atoi (str));
1319 set_height (preset_height (HeightNormal));
1324 TrackViewList::filter_to_unique_playlists ()
1326 std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
1329 for (iterator i = begin(); i != end(); ++i) {
1330 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*i);
1332 /* not a route: include it anyway */
1335 boost::shared_ptr<ARDOUR::Track> t = rtav->track();
1337 if (playlists.insert (t->playlist()).second) {
1338 /* playlist not seen yet */
1342 /* not a track: include it anyway */