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/utils.h>
34 #include <gtkmm2ext/selector.h>
36 #include "ardour_ui.h"
37 #include "global_signals.h"
38 #include "gui_thread.h"
39 #include "public_editor.h"
40 #include "time_axis_view.h"
41 #include "region_view.h"
42 #include "ghostregion.h"
43 #include "simplerect.h"
44 #include "simpleline.h"
45 #include "selection.h"
47 #include "rgb_macros.h"
49 #include "streamview.h"
50 #include "editor_drag.h"
57 using namespace ARDOUR;
59 using namespace Editing;
60 using namespace ArdourCanvas;
61 using Gtkmm2ext::Keyboard;
63 const double trim_handle_size = 6.0; /* pixels */
64 uint32_t TimeAxisView::button_height = 0;
65 uint32_t TimeAxisView::extra_height = 0;
66 int const TimeAxisView::_max_order = 512;
67 PBD::Signal1<void,TimeAxisView*> TimeAxisView::CatchDeletion;
69 TimeAxisView::TimeAxisView (ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* rent, Canvas& /*canvas*/)
71 , controls_table (2, 8)
76 , _preresize_cursor (0)
77 , _have_preresize_cursor (false)
80 if (extra_height == 0) {
84 _canvas_background = new Group (*ed.get_background_group (), 0.0, 0.0);
85 _canvas_display = new Group (*ed.get_trackview_group (), 0.0, 0.0);
86 _canvas_display->hide(); // reveal as needed
88 selection_group = new Group (*_canvas_display);
89 selection_group->set_data (X_("timeselection"), (void *) 1);
90 selection_group->hide();
92 _ghost_group = new Group (*_canvas_display);
93 _ghost_group->lower_to_bottom();
99 in_destructor = false;
101 _effective_height = 0;
103 last_name_entry_key_press_event = 0;
104 name_packing = NamePackingBits (0);
105 _resize_drag_start = -1;
108 Create the standard LHS Controls
109 We create the top-level container and name add the name label here,
110 subclasses can add to the layout as required
113 name_entry.set_name ("EditorTrackNameDisplay");
114 name_entry.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_release));
115 name_entry.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_press));
116 name_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_release));
117 name_entry.signal_activate().connect (sigc::mem_fun(*this, &TimeAxisView::name_entry_activated));
118 name_entry.signal_focus_in_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_in));
119 name_entry.signal_focus_out_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_out));
120 Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
122 name_label.set_name ("TrackLabel");
123 name_label.set_alignment (0.0, 0.5);
125 /* typically, either name_label OR name_entry are visible,
126 but not both. its up to derived classes to show/hide them as they
132 controls_table.set_size_request (200);
133 controls_table.set_row_spacings (2);
134 controls_table.set_col_spacings (2);
135 controls_table.set_border_width (2);
136 controls_table.set_homogeneous (true);
138 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 3, 0);
139 controls_table.show_all ();
140 controls_table.set_no_show_all ();
142 HSeparator* separator = manage (new HSeparator());
144 controls_vbox.pack_start (controls_table, false, false);
145 controls_vbox.show ();
147 //controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
148 controls_ebox.add (controls_vbox);
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 controls_hbox.pack_start (controls_ebox, true, true);
166 controls_hbox.show ();
168 time_axis_vbox.pack_start (controls_hbox, true, true);
169 time_axis_vbox.pack_end (*separator, false, false);
170 time_axis_vbox.show();
172 ColorsChanged.connect (sigc::mem_fun (*this, &TimeAxisView::color_handler));
174 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
177 TimeAxisView::~TimeAxisView()
179 in_destructor = true;
181 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
185 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
187 delete (*i)->start_trim;
188 delete (*i)->end_trim;
192 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
194 delete (*i)->start_trim;
195 delete (*i)->end_trim;
198 delete selection_group;
201 delete _canvas_background;
202 _canvas_background = 0;
204 delete _canvas_display;
214 TimeAxisView::hide ()
220 _canvas_display->hide ();
221 _canvas_background->hide ();
223 if (control_parent) {
224 control_parent->remove (time_axis_vbox);
231 /* now hide children */
233 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
237 /* if its hidden, it cannot be selected */
238 _editor.get_selection().remove (this);
239 /* and neither can its regions */
240 _editor.get_selection().remove_regions (this);
245 /** Display this TimeAxisView as the nth component of the parent box, at y.
247 * @param y y position.
248 * @param nth index for this TimeAxisView, increased if this view has children.
249 * @param parent parent component.
250 * @return height of this TimeAxisView.
253 TimeAxisView::show_at (double y, int& nth, VBox *parent)
255 if (control_parent) {
256 control_parent->reorder_child (time_axis_vbox, nth);
258 control_parent = parent;
259 parent->pack_start (time_axis_vbox, false, false);
260 parent->reorder_child (time_axis_vbox, nth);
265 if (_y_position != y) {
266 _canvas_display->property_y () = y;
267 _canvas_background->property_y () = y;
269 _canvas_display->move (0.0, 0.0);
270 _canvas_background->move (0.0, 0.0);
275 _canvas_background->raise_to_top ();
276 _canvas_display->raise_to_top ();
278 _canvas_background->show ();
279 _canvas_display->show ();
283 _effective_height = current_height ();
285 /* now show relevant children */
287 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
288 if ((*i)->marked_for_display()) {
290 _effective_height += (*i)->show_at (y + _effective_height, nth, parent);
296 return _effective_height;
300 TimeAxisView::clip_to_viewport ()
302 if (marked_for_display()) {
303 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()) {
304 _canvas_background->hide ();
305 _canvas_display->hide ();
308 _canvas_background->show ();
309 _canvas_display->show ();
315 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
317 switch (ev->direction) {
319 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
322 } else if (Keyboard::no_modifiers_active (ev->state)) {
323 _editor.scroll_tracks_up_line();
328 case GDK_SCROLL_DOWN:
329 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
332 } else if (Keyboard::no_modifiers_active (ev->state)) {
333 _editor.scroll_tracks_down_line();
339 /* no handling for left/right, yet */
347 TimeAxisView::controls_ebox_button_press (GdkEventButton* event)
349 if (maybe_set_cursor (event->y) > 0) {
350 _resize_drag_start = event->y_root;
357 TimeAxisView::idle_resize (uint32_t h)
364 TimeAxisView::controls_ebox_motion (GdkEventMotion* ev)
366 if (_resize_drag_start >= 0) {
367 /* (ab)use the DragManager to do autoscrolling; adjust the event coordinates
368 into the world coordinate space that DragManager::motion_handler is expecting,
369 and then fake a DragManager motion event so that when maybe_autoscroll
370 asks DragManager for the current pointer position it will get the correct
374 controls_ebox.translate_coordinates (*control_parent, ev->x, ev->y, tx, ty);
375 ev->y = ty - _editor.get_trackview_group_vertical_offset();
376 _editor.drags()->motion_handler ((GdkEvent *) ev, false);
377 _editor.maybe_autoscroll (false, true, false, ev->y_root < _resize_drag_start);
379 /* now do the actual TAV resize */
380 int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
381 _editor.add_to_idle_resize (this, delta);
382 _resize_drag_start = ev->y_root;
384 /* not dragging but ... */
385 maybe_set_cursor (ev->y);
392 TimeAxisView::controls_ebox_leave (GdkEventCrossing*)
394 if (_have_preresize_cursor) {
395 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
396 _have_preresize_cursor = false;
402 TimeAxisView::maybe_set_cursor (int y)
404 /* XXX no Gtkmm Gdk::Window::get_cursor() */
405 Glib::RefPtr<Gdk::Window> win = controls_ebox.get_window();
407 if (y > (gint) floor (controls_ebox.get_height() * 0.75)) {
409 /* y-coordinate in lower 25% */
411 if (!_have_preresize_cursor) {
412 _preresize_cursor = gdk_window_get_cursor (win->gobj());
413 _have_preresize_cursor = true;
414 win->set_cursor (Gdk::Cursor(Gdk::SB_V_DOUBLE_ARROW));
419 } else if (_have_preresize_cursor) {
420 gdk_window_set_cursor (win->gobj(), _preresize_cursor);
421 _have_preresize_cursor = false;
430 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
432 if (_resize_drag_start >= 0) {
433 if (_have_preresize_cursor) {
434 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
435 _preresize_cursor = 0;
436 _have_preresize_cursor = false;
438 _editor.stop_canvas_autoscroll ();
439 _resize_drag_start = -1;
442 switch (ev->button) {
444 selection_click (ev);
448 popup_display_menu (ev->time);
456 TimeAxisView::selection_click (GdkEventButton* ev)
458 Selection::Operation op = ArdourKeyboard::selection_type (ev->state);
459 _editor.set_selected_track (*this, op, false);
463 /** Steps through the defined heights for this TrackView.
464 * @param coarser true if stepping should decrease in size, otherwise false.
467 TimeAxisView::step_height (bool coarser)
469 static const uint32_t step = 25;
473 if (height <= preset_height (HeightSmall)) {
475 } else if (height <= preset_height (HeightNormal) && height > preset_height (HeightSmall)) {
476 set_height_enum (HeightSmall);
478 set_height (height - step);
483 if (height <= preset_height(HeightSmall)) {
484 set_height_enum (HeightNormal);
486 set_height (height + step);
493 TimeAxisView::set_height_enum (Height h, bool apply_to_selection)
495 if (apply_to_selection) {
496 _editor.get_selection().tracks.foreach_time_axis (boost::bind (&TimeAxisView::set_height_enum, _1, h, false));
498 set_height (preset_height (h));
503 TimeAxisView::set_height (uint32_t h)
505 if (h < preset_height (HeightSmall)) {
506 h = preset_height (HeightSmall);
509 time_axis_vbox.property_height_request () = h;
513 snprintf (buf, sizeof (buf), "%u", height);
514 set_gui_property ("height", buf);
516 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
520 if (canvas_item_visible (selection_group)) {
521 /* resize the selection rect */
522 show_selection (_editor.get_selection().time);
527 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
529 TrackViewList::iterator i;
531 switch (ev->keyval) {
533 name_entry.select_region (0,0);
534 controls_ebox.grab_focus ();
535 name_entry_changed ();
538 /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
539 * generates a different ev->keyval, rather than setting
542 case GDK_ISO_Left_Tab:
545 name_entry_changed ();
546 TrackViewList const & allviews = _editor.get_track_views ();
547 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
549 if (ev->keyval == GDK_Tab) {
550 if (i != allviews.end()) {
552 if (++i == allviews.end()) {
556 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
558 if (rtav && rtav->route()->record_enabled()) {
562 if (!(*i)->hidden()) {
569 if (i != allviews.begin()) {
571 if (i == allviews.begin()) {
577 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
579 if (rtav && rtav->route()->record_enabled()) {
583 if (!(*i)->hidden()) {
591 if ((i != allviews.end()) && (*i != this) && !(*i)->hidden()) {
592 (*i)->name_entry.grab_focus();
593 _editor.ensure_time_axis_view_is_visible (**i);
600 name_entry_changed ();
607 #ifdef TIMEOUT_NAME_EDIT
608 /* adapt the timeout to reflect the user's typing speed */
610 guint32 name_entry_timeout;
612 if (last_name_entry_key_press_event) {
613 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
614 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
616 /* start with a 1 second timeout */
617 name_entry_timeout = 1000;
620 last_name_entry_key_press_event = ev->time;
622 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
624 name_entry_key_timeout.disconnect();
625 name_entry_key_timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
632 TimeAxisView::name_entry_focus_in (GdkEventFocus*)
634 name_entry.select_region (0, -1);
635 name_entry.set_state (STATE_SELECTED);
640 TimeAxisView::name_entry_focus_out (GdkEventFocus*)
644 last_name_entry_key_press_event = 0;
645 name_entry_key_timeout.disconnect ();
646 name_entry.select_region (0,0);
647 name_entry.set_state (STATE_NORMAL);
649 /* do the real stuff */
651 name_entry_changed ();
657 TimeAxisView::name_entry_key_timed_out ()
659 name_entry_activated();
664 TimeAxisView::name_entry_activated ()
666 controls_ebox.grab_focus();
670 TimeAxisView::name_entry_changed ()
675 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
677 if (ev->button == 3) {
684 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
686 if (ev->button == 3) {
687 popup_display_menu (ev->time);
694 TimeAxisView::conditionally_add_to_selection ()
696 Selection& s (_editor.get_selection ());
698 if (!s.selected (this)) {
699 _editor.set_selected_track (*this, Selection::Set);
704 TimeAxisView::popup_display_menu (guint32 when)
706 conditionally_add_to_selection ();
708 build_display_menu ();
709 display_menu->popup (1, when);
713 TimeAxisView::set_selected (bool yn)
715 if (yn == _selected) {
719 Selectable::set_selected (yn);
722 controls_ebox.set_name (controls_base_selected_name);
723 time_axis_vbox.set_name (controls_base_selected_name);
724 controls_vbox.set_name (controls_base_selected_name);
726 controls_ebox.set_name (controls_base_unselected_name);
727 time_axis_vbox.set_name (controls_base_unselected_name);
728 controls_vbox.set_name (controls_base_unselected_name);
731 /* children will be set for the yn=true case. but when deselecting
732 the editor only has a list of top-level trackviews, so we
733 have to do this here.
736 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
737 (*i)->set_selected (false);
743 TimeAxisView::build_display_menu ()
745 using namespace Menu_Helpers;
749 display_menu = new Menu;
750 display_menu->set_name ("ArdourContextMenu");
752 // Just let implementing classes define what goes into the manu
756 TimeAxisView::set_samples_per_unit (double spu)
758 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
759 (*i)->set_samples_per_unit (spu);
762 AnalysisFeatureList::const_iterator i;
763 list<ArdourCanvas::SimpleLine*>::iterator l;
767 TimeAxisView::show_timestretch (framepos_t start, framepos_t end, int layers, int layer)
769 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
770 (*i)->show_timestretch (start, end, layers, layer);
775 TimeAxisView::hide_timestretch ()
777 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
778 (*i)->hide_timestretch ();
783 TimeAxisView::show_selection (TimeSelection& ts)
790 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
791 (*i)->show_selection (ts);
794 if (canvas_item_visible (selection_group)) {
795 while (!used_selection_rects.empty()) {
796 free_selection_rects.push_front (used_selection_rects.front());
797 used_selection_rects.pop_front();
798 free_selection_rects.front()->rect->hide();
799 free_selection_rects.front()->start_trim->hide();
800 free_selection_rects.front()->end_trim->hide();
802 selection_group->hide();
805 selection_group->show();
806 selection_group->raise_to_top();
808 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
809 framepos_t start, end;
814 cnt = end - start + 1;
816 rect = get_selection_rect ((*i).id);
818 x1 = _editor.frame_to_unit (start);
819 x2 = _editor.frame_to_unit (start + cnt - 1);
820 y2 = current_height();
822 rect->rect->property_x1() = x1;
823 rect->rect->property_y1() = 1.0;
824 rect->rect->property_x2() = x2;
825 rect->rect->property_y2() = y2;
827 // trim boxes are at the top for selections
830 rect->start_trim->property_x1() = x1;
831 rect->start_trim->property_y1() = 1.0;
832 rect->start_trim->property_x2() = x1 + trim_handle_size;
833 rect->start_trim->property_y2() = y2;
835 rect->end_trim->property_x1() = x2 - trim_handle_size;
836 rect->end_trim->property_y1() = 1.0;
837 rect->end_trim->property_x2() = x2;
838 rect->end_trim->property_y2() = y2;
840 rect->start_trim->show();
841 rect->end_trim->show();
843 rect->start_trim->hide();
844 rect->end_trim->hide();
848 used_selection_rects.push_back (rect);
853 TimeAxisView::reshow_selection (TimeSelection& ts)
857 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
858 (*i)->show_selection (ts);
863 TimeAxisView::hide_selection ()
865 if (canvas_item_visible (selection_group)) {
866 while (!used_selection_rects.empty()) {
867 free_selection_rects.push_front (used_selection_rects.front());
868 used_selection_rects.pop_front();
869 free_selection_rects.front()->rect->hide();
870 free_selection_rects.front()->start_trim->hide();
871 free_selection_rects.front()->end_trim->hide();
873 selection_group->hide();
876 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
877 (*i)->hide_selection ();
882 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
884 /* find the selection rect this is for. we have the item corresponding to one
888 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
889 if ((*i)->start_trim == item || (*i)->end_trim == item) {
891 /* make one trim handle be "above" the other so that if they overlap,
892 the top one is the one last used.
895 (*i)->rect->raise_to_top ();
896 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
897 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
905 TimeAxisView::get_selection_rect (uint32_t id)
909 /* check to see if we already have a visible rect for this particular selection ID */
911 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
912 if ((*i)->id == id) {
917 /* ditto for the free rect list */
919 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
920 if ((*i)->id == id) {
921 SelectionRect* ret = (*i);
922 free_selection_rects.erase (i);
927 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
929 if (free_selection_rects.empty()) {
931 rect = new SelectionRect;
933 rect->rect = new SimpleRect (*selection_group);
934 rect->rect->property_outline_what() = 0x0;
935 rect->rect->property_x1() = 0.0;
936 rect->rect->property_y1() = 0.0;
937 rect->rect->property_x2() = 0.0;
938 rect->rect->property_y2() = 0.0;
939 rect->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
941 rect->start_trim = new SimpleRect (*selection_group);
942 rect->start_trim->property_outline_what() = 0x0;
943 rect->start_trim->property_x1() = 0.0;
944 rect->start_trim->property_x2() = 0.0;
946 rect->end_trim = new SimpleRect (*selection_group);
947 rect->end_trim->property_outline_what() = 0x0;
948 rect->end_trim->property_x1() = 0.0;
949 rect->end_trim->property_x2() = 0.0;
951 free_selection_rects.push_front (rect);
953 rect->rect->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
954 rect->start_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
955 rect->end_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
958 rect = free_selection_rects.front();
960 free_selection_rects.pop_front();
964 struct null_deleter { void operator()(void const *) const {} };
967 TimeAxisView::is_child (TimeAxisView* tav)
969 return find (children.begin(), children.end(), boost::shared_ptr<TimeAxisView>(tav, null_deleter())) != children.end();
973 TimeAxisView::add_child (boost::shared_ptr<TimeAxisView> child)
975 children.push_back (child);
979 TimeAxisView::remove_child (boost::shared_ptr<TimeAxisView> child)
981 Children::iterator i;
983 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
988 /** Get selectable things within a given range.
989 * @param start Start time in session frames.
990 * @param end End time in session frames.
991 * @param top Top y range, in trackview coordinates (ie 0 is the top of the track view)
992 * @param bot Bottom y range, in trackview coordinates (ie 0 is the top of the track view)
993 * @param result Filled in with selectable things.
996 TimeAxisView::get_selectables (framepos_t /*start*/, framepos_t /*end*/, double /*top*/, double /*bot*/, list<Selectable*>& /*result*/)
1002 TimeAxisView::get_inverted_selectables (Selection& /*sel*/, list<Selectable*>& /*result*/)
1008 TimeAxisView::add_ghost (RegionView* rv)
1010 GhostRegion* gr = rv->add_ghost (*this);
1013 ghosts.push_back(gr);
1018 TimeAxisView::remove_ghost (RegionView* rv)
1020 rv->remove_ghost_in (*this);
1024 TimeAxisView::erase_ghost (GhostRegion* gr)
1026 if (in_destructor) {
1030 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1039 TimeAxisView::touched (double top, double bot)
1041 /* remember: this is X Window - coordinate space starts in upper left and moves down.
1042 y_position is the "origin" or "top" of the track.
1045 double mybot = _y_position + current_height();
1047 return ((_y_position <= bot && _y_position >= top) ||
1048 ((mybot <= bot) && (top < mybot)) ||
1049 (mybot >= bot && _y_position < top));
1053 TimeAxisView::set_parent (TimeAxisView& p)
1059 TimeAxisView::reset_height ()
1061 set_height (height);
1063 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1064 (*i)->set_height ((*i)->height);
1069 TimeAxisView::compute_heights ()
1071 Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
1072 Gtk::Table two_row_table (2, 8);
1073 Gtk::Table one_row_table (1, 8);
1075 const int border_width = 2;
1077 const int separator_height = 2;
1078 extra_height = (2 * border_width) + separator_height;
1080 window.add (one_row_table);
1082 one_row_table.set_border_width (border_width);
1083 one_row_table.set_row_spacings (0);
1084 one_row_table.set_col_spacings (0);
1085 one_row_table.set_homogeneous (true);
1087 two_row_table.set_border_width (border_width);
1088 two_row_table.set_row_spacings (0);
1089 two_row_table.set_col_spacings (0);
1090 two_row_table.set_homogeneous (true);
1092 for (int i = 0; i < 5; ++i) {
1093 buttons[i] = manage (new Button (X_("f")));
1094 buttons[i]->set_name ("TrackMuteButton");
1097 one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1099 one_row_table.show_all ();
1100 Gtk::Requisition req(one_row_table.size_request ());
1102 // height required to show 1 row of buttons
1103 button_height = req.height;
1107 TimeAxisView::show_name_label ()
1109 if (!(name_packing & NameLabelPacked)) {
1110 name_hbox.pack_start (name_label, true, true);
1111 name_packing = NamePackingBits (name_packing | NameLabelPacked);
1118 TimeAxisView::show_name_entry ()
1120 if (!(name_packing & NameEntryPacked)) {
1121 name_hbox.pack_start (name_entry, true, true);
1122 name_packing = NamePackingBits (name_packing | NameEntryPacked);
1129 TimeAxisView::hide_name_label ()
1131 if (name_packing & NameLabelPacked) {
1132 name_hbox.remove (name_label);
1133 name_packing = NamePackingBits (name_packing & ~NameLabelPacked);
1138 TimeAxisView::hide_name_entry ()
1140 if (name_packing & NameEntryPacked) {
1141 name_hbox.remove (name_entry);
1142 name_packing = NamePackingBits (name_packing & ~NameEntryPacked);
1147 TimeAxisView::color_handler ()
1149 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); i++) {
1153 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
1155 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1156 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1158 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1159 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1161 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1162 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1165 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
1167 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1168 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1170 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1171 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1173 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1174 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1178 /** @return Pair: TimeAxisView, layer index.
1179 * TimeAxisView is non-0 if this object covers y, or one of its children does.
1180 * If the covering object is a child axis, then the child is returned.
1181 * TimeAxisView is 0 otherwise.
1182 * Layer index is the layer number (possibly fractional) if the TimeAxisView is valid
1183 * and is in stacked or expanded * region display mode, otherwise 0.
1185 std::pair<TimeAxisView*, double>
1186 TimeAxisView::covers_y_position (double y)
1189 return std::make_pair ((TimeAxisView *) 0, 0);
1192 if (_y_position <= y && y < (_y_position + height)) {
1194 /* work out the layer index if appropriate */
1196 switch (layer_display ()) {
1202 l = layer_t ((_y_position + height - y) / (view()->child_height ()));
1203 /* clamp to max layers to be on the safe side; sometimes the above calculation
1204 returns a too-high value */
1205 if (l >= view()->layers ()) {
1206 l = view()->layers() - 1;
1212 int const n = floor ((_y_position + height - y) / (view()->child_height ()));
1214 if (l >= (view()->layers() - 0.5)) {
1215 l = view()->layers() - 0.5;
1221 return std::make_pair (this, l);
1224 for (Children::const_iterator i = children.begin(); i != children.end(); ++i) {
1226 std::pair<TimeAxisView*, int> const r = (*i)->covers_y_position (y);
1232 return std::make_pair ((TimeAxisView *) 0, 0);
1237 TimeAxisView::preset_height (Height h)
1241 return (button_height * 2) + extra_height + 250;
1243 return (button_height * 2) + extra_height + 150;
1245 return (button_height * 2) + extra_height + 50;
1247 return (button_height * 2) + extra_height;
1249 return button_height + extra_height;
1256 /** @return Child time axis views that are not hidden */
1257 TimeAxisView::Children
1258 TimeAxisView::get_child_list ()
1262 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1263 if (!(*i)->hidden()) {
1272 TimeAxisView::build_size_menu ()
1274 if (_size_menu && _size_menu->gobj ()) {
1280 using namespace Menu_Helpers;
1282 _size_menu = new Menu;
1283 _size_menu->set_name ("ArdourContextMenu");
1284 MenuList& items = _size_menu->items();
1286 items.push_back (MenuElem (_("Largest"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLargest, true)));
1287 items.push_back (MenuElem (_("Larger"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarger, true)));
1288 items.push_back (MenuElem (_("Large"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarge, true)));
1289 items.push_back (MenuElem (_("Normal"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightNormal, true)));
1290 items.push_back (MenuElem (_("Small"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightSmall, true)));
1294 TimeAxisView::reset_visual_state ()
1296 /* this method is not required to trigger a global redraw */
1298 string str = gui_property ("height");
1301 set_height (atoi (str));
1303 set_height (preset_height (HeightNormal));
1308 TrackViewList::filter_to_unique_playlists ()
1310 std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
1313 for (iterator i = begin(); i != end(); ++i) {
1314 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*i);
1316 /* not a route: include it anyway */
1319 boost::shared_ptr<ARDOUR::Track> t = rtav->track();
1321 if (playlists.insert (t->playlist()).second) {
1322 /* playlist not seen yet */
1326 /* not a track: include it anyway */