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"
58 using namespace ARDOUR;
60 using namespace Editing;
61 using namespace ArdourCanvas;
62 using Gtkmm2ext::Keyboard;
64 const double trim_handle_size = 6.0; /* pixels */
65 uint32_t TimeAxisView::button_height = 0;
66 uint32_t TimeAxisView::extra_height = 0;
67 int const TimeAxisView::_max_order = 512;
68 PBD::Signal1<void,TimeAxisView*> TimeAxisView::CatchDeletion;
70 TimeAxisView::TimeAxisView (ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* rent, Canvas& /*canvas*/)
72 , controls_table (2, 8)
77 , _preresize_cursor (0)
78 , _have_preresize_cursor (false)
81 if (extra_height == 0) {
85 _canvas_background = new Group (*ed.get_background_group (), 0.0, 0.0);
86 _canvas_display = new Group (*ed.get_trackview_group (), 0.0, 0.0);
87 _canvas_display->hide(); // reveal as needed
89 selection_group = new Group (*_canvas_display);
90 selection_group->set_data (X_("timeselection"), (void *) 1);
91 selection_group->hide();
93 _ghost_group = new Group (*_canvas_display);
94 _ghost_group->lower_to_bottom();
100 in_destructor = false;
102 _effective_height = 0;
104 last_name_entry_key_press_event = 0;
105 name_packing = NamePackingBits (0);
106 _resize_drag_start = -1;
109 Create the standard LHS Controls
110 We create the top-level container and name add the name label here,
111 subclasses can add to the layout as required
114 name_entry.set_name ("EditorTrackNameDisplay");
115 name_entry.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_release));
116 name_entry.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_press));
117 name_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_release));
118 name_entry.signal_activate().connect (sigc::mem_fun(*this, &TimeAxisView::name_entry_activated));
119 name_entry.signal_focus_in_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_in));
120 name_entry.signal_focus_out_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_out));
121 Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
123 name_label.set_name ("TrackLabel");
124 name_label.set_alignment (0.0, 0.5);
126 /* typically, either name_label OR name_entry are visible,
127 but not both. its up to derived classes to show/hide them as they
133 controls_table.set_size_request (200);
134 controls_table.set_row_spacings (2);
135 controls_table.set_col_spacings (2);
136 controls_table.set_border_width (2);
137 controls_table.set_homogeneous (true);
139 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 3, 0);
140 controls_table.show_all ();
141 controls_table.set_no_show_all ();
143 HSeparator* separator = manage (new HSeparator());
145 controls_vbox.pack_start (controls_table, false, false);
146 controls_vbox.show ();
148 //controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
149 controls_ebox.add (controls_vbox);
150 controls_ebox.add_events (Gdk::BUTTON_PRESS_MASK|
151 Gdk::BUTTON_RELEASE_MASK|
152 Gdk::POINTER_MOTION_MASK|
153 Gdk::ENTER_NOTIFY_MASK|
154 Gdk::LEAVE_NOTIFY_MASK|
156 controls_ebox.set_flags (CAN_FOCUS);
158 /* note that this handler connects *before* the default handler */
159 controls_ebox.signal_scroll_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_scroll), true);
160 controls_ebox.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_press));
161 controls_ebox.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
162 controls_ebox.signal_motion_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_motion));
163 controls_ebox.signal_leave_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_leave));
164 controls_ebox.show ();
166 controls_hbox.pack_start (controls_ebox, true, true);
167 controls_hbox.show ();
169 time_axis_vbox.pack_start (controls_hbox, true, true);
170 time_axis_vbox.pack_end (*separator, false, false);
171 time_axis_vbox.show();
173 ColorsChanged.connect (sigc::mem_fun (*this, &TimeAxisView::color_handler));
175 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
178 TimeAxisView::~TimeAxisView()
180 in_destructor = true;
182 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
186 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
188 delete (*i)->start_trim;
189 delete (*i)->end_trim;
193 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
195 delete (*i)->start_trim;
196 delete (*i)->end_trim;
199 delete selection_group;
202 delete _canvas_background;
203 _canvas_background = 0;
205 delete _canvas_display;
215 TimeAxisView::hide ()
221 _canvas_display->hide ();
222 _canvas_background->hide ();
224 if (control_parent) {
225 control_parent->remove (time_axis_vbox);
232 /* now hide children */
234 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
238 /* if its hidden, it cannot be selected */
239 _editor.get_selection().remove (this);
240 /* and neither can its regions */
241 _editor.get_selection().remove_regions (this);
246 /** Display this TimeAxisView as the nth component of the parent box, at y.
248 * @param y y position.
249 * @param nth index for this TimeAxisView, increased if this view has children.
250 * @param parent parent component.
251 * @return height of this TimeAxisView.
254 TimeAxisView::show_at (double y, int& nth, VBox *parent)
256 if (control_parent) {
257 control_parent->reorder_child (time_axis_vbox, nth);
259 control_parent = parent;
260 parent->pack_start (time_axis_vbox, false, false);
261 parent->reorder_child (time_axis_vbox, nth);
266 if (_y_position != y) {
267 _canvas_display->property_y () = y;
268 _canvas_background->property_y () = y;
270 _canvas_display->move (0.0, 0.0);
271 _canvas_background->move (0.0, 0.0);
276 _canvas_background->raise_to_top ();
277 _canvas_display->raise_to_top ();
279 _canvas_background->show ();
280 _canvas_display->show ();
284 _effective_height = current_height ();
286 /* now show relevant children */
288 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
289 if ((*i)->marked_for_display()) {
291 _effective_height += (*i)->show_at (y + _effective_height, nth, parent);
297 return _effective_height;
301 TimeAxisView::clip_to_viewport ()
303 if (marked_for_display()) {
304 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()) {
305 _canvas_background->hide ();
306 _canvas_display->hide ();
309 _canvas_background->show ();
310 _canvas_display->show ();
316 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
318 switch (ev->direction) {
320 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
321 /* See Editor::_stepping_axis_view for notes on this hack */
322 Editor& e = dynamic_cast<Editor&> (_editor);
323 if (!e.stepping_axis_view ()) {
324 e.set_stepping_axis_view (this);
326 e.stepping_axis_view()->step_height (false);
328 } else if (Keyboard::no_modifiers_active (ev->state)) {
329 _editor.scroll_tracks_up_line();
334 case GDK_SCROLL_DOWN:
335 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
336 /* See Editor::_stepping_axis_view for notes on this hack */
337 Editor& e = dynamic_cast<Editor&> (_editor);
338 if (!e.stepping_axis_view ()) {
339 e.set_stepping_axis_view (this);
341 e.stepping_axis_view()->step_height (true);
343 } else if (Keyboard::no_modifiers_active (ev->state)) {
344 _editor.scroll_tracks_down_line();
350 /* no handling for left/right, yet */
358 TimeAxisView::controls_ebox_button_press (GdkEventButton* event)
360 if (maybe_set_cursor (event->y) > 0) {
361 _resize_drag_start = event->y_root;
368 TimeAxisView::idle_resize (uint32_t h)
375 TimeAxisView::controls_ebox_motion (GdkEventMotion* ev)
377 if (_resize_drag_start >= 0) {
378 /* (ab)use the DragManager to do autoscrolling; adjust the event coordinates
379 into the world coordinate space that DragManager::motion_handler is expecting,
380 and then fake a DragManager motion event so that when maybe_autoscroll
381 asks DragManager for the current pointer position it will get the correct
385 controls_ebox.translate_coordinates (*control_parent, ev->x, ev->y, tx, ty);
386 ev->y = ty - _editor.get_trackview_group_vertical_offset();
387 _editor.drags()->motion_handler ((GdkEvent *) ev, false);
388 _editor.maybe_autoscroll (false, true, false, ev->y_root < _resize_drag_start);
390 /* now do the actual TAV resize */
391 int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
392 _editor.add_to_idle_resize (this, delta);
393 _resize_drag_start = ev->y_root;
395 /* not dragging but ... */
396 maybe_set_cursor (ev->y);
403 TimeAxisView::controls_ebox_leave (GdkEventCrossing*)
405 if (_have_preresize_cursor) {
406 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
407 _have_preresize_cursor = false;
413 TimeAxisView::maybe_set_cursor (int y)
415 /* XXX no Gtkmm Gdk::Window::get_cursor() */
416 Glib::RefPtr<Gdk::Window> win = controls_ebox.get_window();
418 if (y > (gint) floor (controls_ebox.get_height() * 0.75)) {
420 /* y-coordinate in lower 25% */
422 if (!_have_preresize_cursor) {
423 _preresize_cursor = gdk_window_get_cursor (win->gobj());
424 _have_preresize_cursor = true;
425 win->set_cursor (Gdk::Cursor(Gdk::SB_V_DOUBLE_ARROW));
430 } else if (_have_preresize_cursor) {
431 gdk_window_set_cursor (win->gobj(), _preresize_cursor);
432 _have_preresize_cursor = false;
441 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
443 if (_resize_drag_start >= 0) {
444 if (_have_preresize_cursor) {
445 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
446 _preresize_cursor = 0;
447 _have_preresize_cursor = false;
449 _editor.stop_canvas_autoscroll ();
450 _resize_drag_start = -1;
453 switch (ev->button) {
455 selection_click (ev);
459 popup_display_menu (ev->time);
467 TimeAxisView::selection_click (GdkEventButton* ev)
469 Selection::Operation op = ArdourKeyboard::selection_type (ev->state);
470 _editor.set_selected_track (*this, op, false);
474 /** Steps through the defined heights for this TrackView.
475 * @param coarser true if stepping should decrease in size, otherwise false.
478 TimeAxisView::step_height (bool coarser)
480 static const uint32_t step = 25;
484 if (height <= preset_height (HeightSmall)) {
486 } else if (height <= preset_height (HeightNormal) && height > preset_height (HeightSmall)) {
487 set_height_enum (HeightSmall);
489 set_height (height - step);
494 if (height <= preset_height(HeightSmall)) {
495 set_height_enum (HeightNormal);
497 set_height (height + step);
504 TimeAxisView::set_height_enum (Height h, bool apply_to_selection)
506 if (apply_to_selection) {
507 _editor.get_selection().tracks.foreach_time_axis (boost::bind (&TimeAxisView::set_height_enum, _1, h, false));
509 set_height (preset_height (h));
514 TimeAxisView::set_height (uint32_t h)
516 if (h < preset_height (HeightSmall)) {
517 h = preset_height (HeightSmall);
520 time_axis_vbox.property_height_request () = h;
524 snprintf (buf, sizeof (buf), "%u", height);
525 set_gui_property ("height", buf);
527 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
531 if (canvas_item_visible (selection_group)) {
532 /* resize the selection rect */
533 show_selection (_editor.get_selection().time);
538 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
540 TrackViewList::iterator i;
542 switch (ev->keyval) {
544 name_entry.select_region (0,0);
545 controls_ebox.grab_focus ();
546 name_entry_changed ();
549 /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
550 * generates a different ev->keyval, rather than setting
553 case GDK_ISO_Left_Tab:
556 name_entry_changed ();
557 TrackViewList const & allviews = _editor.get_track_views ();
558 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
560 if (ev->keyval == GDK_Tab) {
561 if (i != allviews.end()) {
563 if (++i == allviews.end()) {
567 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
569 if (rtav && rtav->route()->record_enabled()) {
573 if (!(*i)->hidden()) {
580 if (i != allviews.begin()) {
582 if (i == allviews.begin()) {
588 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
590 if (rtav && rtav->route()->record_enabled()) {
594 if (!(*i)->hidden()) {
602 if ((i != allviews.end()) && (*i != this) && !(*i)->hidden()) {
603 (*i)->name_entry.grab_focus();
604 _editor.ensure_time_axis_view_is_visible (**i);
611 name_entry_changed ();
618 #ifdef TIMEOUT_NAME_EDIT
619 /* adapt the timeout to reflect the user's typing speed */
621 guint32 name_entry_timeout;
623 if (last_name_entry_key_press_event) {
624 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
625 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
627 /* start with a 1 second timeout */
628 name_entry_timeout = 1000;
631 last_name_entry_key_press_event = ev->time;
633 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
635 name_entry_key_timeout.disconnect();
636 name_entry_key_timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
643 TimeAxisView::name_entry_focus_in (GdkEventFocus*)
645 name_entry.select_region (0, -1);
646 name_entry.set_state (STATE_SELECTED);
651 TimeAxisView::name_entry_focus_out (GdkEventFocus*)
655 last_name_entry_key_press_event = 0;
656 name_entry_key_timeout.disconnect ();
657 name_entry.select_region (0,0);
658 name_entry.set_state (STATE_NORMAL);
660 /* do the real stuff */
662 name_entry_changed ();
668 TimeAxisView::name_entry_key_timed_out ()
670 name_entry_activated();
675 TimeAxisView::name_entry_activated ()
677 controls_ebox.grab_focus();
681 TimeAxisView::name_entry_changed ()
686 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
688 if (ev->button == 3) {
695 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
697 if (ev->button == 3) {
698 popup_display_menu (ev->time);
705 TimeAxisView::conditionally_add_to_selection ()
707 Selection& s (_editor.get_selection ());
709 if (!s.selected (this)) {
710 _editor.set_selected_track (*this, Selection::Set);
715 TimeAxisView::popup_display_menu (guint32 when)
717 conditionally_add_to_selection ();
719 build_display_menu ();
720 display_menu->popup (1, when);
724 TimeAxisView::set_selected (bool yn)
726 if (yn == _selected) {
730 Selectable::set_selected (yn);
733 controls_ebox.set_name (controls_base_selected_name);
734 time_axis_vbox.set_name (controls_base_selected_name);
735 controls_vbox.set_name (controls_base_selected_name);
737 controls_ebox.set_name (controls_base_unselected_name);
738 time_axis_vbox.set_name (controls_base_unselected_name);
739 controls_vbox.set_name (controls_base_unselected_name);
742 /* children will be set for the yn=true case. but when deselecting
743 the editor only has a list of top-level trackviews, so we
744 have to do this here.
747 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
748 (*i)->set_selected (false);
754 TimeAxisView::build_display_menu ()
756 using namespace Menu_Helpers;
760 display_menu = new Menu;
761 display_menu->set_name ("ArdourContextMenu");
763 // Just let implementing classes define what goes into the manu
767 TimeAxisView::set_samples_per_unit (double spu)
769 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
770 (*i)->set_samples_per_unit (spu);
773 AnalysisFeatureList::const_iterator i;
774 list<ArdourCanvas::SimpleLine*>::iterator l;
778 TimeAxisView::show_timestretch (framepos_t start, framepos_t end, int layers, int layer)
780 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
781 (*i)->show_timestretch (start, end, layers, layer);
786 TimeAxisView::hide_timestretch ()
788 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
789 (*i)->hide_timestretch ();
794 TimeAxisView::show_selection (TimeSelection& ts)
801 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
802 (*i)->show_selection (ts);
805 if (canvas_item_visible (selection_group)) {
806 while (!used_selection_rects.empty()) {
807 free_selection_rects.push_front (used_selection_rects.front());
808 used_selection_rects.pop_front();
809 free_selection_rects.front()->rect->hide();
810 free_selection_rects.front()->start_trim->hide();
811 free_selection_rects.front()->end_trim->hide();
813 selection_group->hide();
816 selection_group->show();
817 selection_group->raise_to_top();
819 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
820 framepos_t start, end;
825 cnt = end - start + 1;
827 rect = get_selection_rect ((*i).id);
829 x1 = _editor.frame_to_unit (start);
830 x2 = _editor.frame_to_unit (start + cnt - 1);
831 y2 = current_height();
833 rect->rect->property_x1() = x1;
834 rect->rect->property_y1() = 1.0;
835 rect->rect->property_x2() = x2;
836 rect->rect->property_y2() = y2;
838 // trim boxes are at the top for selections
841 rect->start_trim->property_x1() = x1;
842 rect->start_trim->property_y1() = 1.0;
843 rect->start_trim->property_x2() = x1 + trim_handle_size;
844 rect->start_trim->property_y2() = y2;
846 rect->end_trim->property_x1() = x2 - trim_handle_size;
847 rect->end_trim->property_y1() = 1.0;
848 rect->end_trim->property_x2() = x2;
849 rect->end_trim->property_y2() = y2;
851 rect->start_trim->show();
852 rect->end_trim->show();
854 rect->start_trim->hide();
855 rect->end_trim->hide();
859 used_selection_rects.push_back (rect);
864 TimeAxisView::reshow_selection (TimeSelection& ts)
868 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
869 (*i)->show_selection (ts);
874 TimeAxisView::hide_selection ()
876 if (canvas_item_visible (selection_group)) {
877 while (!used_selection_rects.empty()) {
878 free_selection_rects.push_front (used_selection_rects.front());
879 used_selection_rects.pop_front();
880 free_selection_rects.front()->rect->hide();
881 free_selection_rects.front()->start_trim->hide();
882 free_selection_rects.front()->end_trim->hide();
884 selection_group->hide();
887 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
888 (*i)->hide_selection ();
893 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
895 /* find the selection rect this is for. we have the item corresponding to one
899 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
900 if ((*i)->start_trim == item || (*i)->end_trim == item) {
902 /* make one trim handle be "above" the other so that if they overlap,
903 the top one is the one last used.
906 (*i)->rect->raise_to_top ();
907 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
908 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
916 TimeAxisView::get_selection_rect (uint32_t id)
920 /* check to see if we already have a visible rect for this particular selection ID */
922 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
923 if ((*i)->id == id) {
928 /* ditto for the free rect list */
930 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
931 if ((*i)->id == id) {
932 SelectionRect* ret = (*i);
933 free_selection_rects.erase (i);
938 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
940 if (free_selection_rects.empty()) {
942 rect = new SelectionRect;
944 rect->rect = new SimpleRect (*selection_group);
945 rect->rect->property_outline_what() = 0x0;
946 rect->rect->property_x1() = 0.0;
947 rect->rect->property_y1() = 0.0;
948 rect->rect->property_x2() = 0.0;
949 rect->rect->property_y2() = 0.0;
950 rect->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
952 rect->start_trim = new SimpleRect (*selection_group);
953 rect->start_trim->property_outline_what() = 0x0;
954 rect->start_trim->property_x1() = 0.0;
955 rect->start_trim->property_x2() = 0.0;
957 rect->end_trim = new SimpleRect (*selection_group);
958 rect->end_trim->property_outline_what() = 0x0;
959 rect->end_trim->property_x1() = 0.0;
960 rect->end_trim->property_x2() = 0.0;
962 free_selection_rects.push_front (rect);
964 rect->rect->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
965 rect->start_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
966 rect->end_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
969 rect = free_selection_rects.front();
971 free_selection_rects.pop_front();
975 struct null_deleter { void operator()(void const *) const {} };
978 TimeAxisView::is_child (TimeAxisView* tav)
980 return find (children.begin(), children.end(), boost::shared_ptr<TimeAxisView>(tav, null_deleter())) != children.end();
984 TimeAxisView::add_child (boost::shared_ptr<TimeAxisView> child)
986 children.push_back (child);
990 TimeAxisView::remove_child (boost::shared_ptr<TimeAxisView> child)
992 Children::iterator i;
994 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
999 /** Get selectable things within a given range.
1000 * @param start Start time in session frames.
1001 * @param end End time in session frames.
1002 * @param top Top y range, in trackview coordinates (ie 0 is the top of the track view)
1003 * @param bot Bottom y range, in trackview coordinates (ie 0 is the top of the track view)
1004 * @param result Filled in with selectable things.
1007 TimeAxisView::get_selectables (framepos_t /*start*/, framepos_t /*end*/, double /*top*/, double /*bot*/, list<Selectable*>& /*result*/)
1013 TimeAxisView::get_inverted_selectables (Selection& /*sel*/, list<Selectable*>& /*result*/)
1019 TimeAxisView::add_ghost (RegionView* rv)
1021 GhostRegion* gr = rv->add_ghost (*this);
1024 ghosts.push_back(gr);
1029 TimeAxisView::remove_ghost (RegionView* rv)
1031 rv->remove_ghost_in (*this);
1035 TimeAxisView::erase_ghost (GhostRegion* gr)
1037 if (in_destructor) {
1041 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1050 TimeAxisView::touched (double top, double bot)
1052 /* remember: this is X Window - coordinate space starts in upper left and moves down.
1053 y_position is the "origin" or "top" of the track.
1056 double mybot = _y_position + current_height();
1058 return ((_y_position <= bot && _y_position >= top) ||
1059 ((mybot <= bot) && (top < mybot)) ||
1060 (mybot >= bot && _y_position < top));
1064 TimeAxisView::set_parent (TimeAxisView& p)
1070 TimeAxisView::reset_height ()
1072 set_height (height);
1074 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1075 (*i)->set_height ((*i)->height);
1080 TimeAxisView::compute_heights ()
1082 Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
1083 Gtk::Table two_row_table (2, 8);
1084 Gtk::Table one_row_table (1, 8);
1086 const int border_width = 2;
1088 const int separator_height = 2;
1089 extra_height = (2 * border_width) + separator_height;
1091 window.add (one_row_table);
1093 one_row_table.set_border_width (border_width);
1094 one_row_table.set_row_spacings (0);
1095 one_row_table.set_col_spacings (0);
1096 one_row_table.set_homogeneous (true);
1098 two_row_table.set_border_width (border_width);
1099 two_row_table.set_row_spacings (0);
1100 two_row_table.set_col_spacings (0);
1101 two_row_table.set_homogeneous (true);
1103 for (int i = 0; i < 5; ++i) {
1104 buttons[i] = manage (new Button (X_("f")));
1105 buttons[i]->set_name ("TrackMuteButton");
1108 one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1110 one_row_table.show_all ();
1111 Gtk::Requisition req(one_row_table.size_request ());
1113 // height required to show 1 row of buttons
1114 button_height = req.height;
1118 TimeAxisView::show_name_label ()
1120 if (!(name_packing & NameLabelPacked)) {
1121 name_hbox.pack_start (name_label, true, true);
1122 name_packing = NamePackingBits (name_packing | NameLabelPacked);
1129 TimeAxisView::show_name_entry ()
1131 if (!(name_packing & NameEntryPacked)) {
1132 name_hbox.pack_start (name_entry, true, true);
1133 name_packing = NamePackingBits (name_packing | NameEntryPacked);
1140 TimeAxisView::hide_name_label ()
1142 if (name_packing & NameLabelPacked) {
1143 name_hbox.remove (name_label);
1144 name_packing = NamePackingBits (name_packing & ~NameLabelPacked);
1149 TimeAxisView::hide_name_entry ()
1151 if (name_packing & NameEntryPacked) {
1152 name_hbox.remove (name_entry);
1153 name_packing = NamePackingBits (name_packing & ~NameEntryPacked);
1158 TimeAxisView::color_handler ()
1160 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); i++) {
1164 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
1166 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1167 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1169 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1170 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1172 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1173 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1176 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
1178 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1179 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1181 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1182 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1184 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1185 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1189 /** @return Pair: TimeAxisView, layer index.
1190 * TimeAxisView is non-0 if this object covers y, or one of its children does.
1191 * If the covering object is a child axis, then the child is returned.
1192 * TimeAxisView is 0 otherwise.
1193 * Layer index is the layer number (possibly fractional) if the TimeAxisView is valid
1194 * and is in stacked or expanded * region display mode, otherwise 0.
1196 std::pair<TimeAxisView*, double>
1197 TimeAxisView::covers_y_position (double y)
1200 return std::make_pair ((TimeAxisView *) 0, 0);
1203 if (_y_position <= y && y < (_y_position + height)) {
1205 /* work out the layer index if appropriate */
1207 switch (layer_display ()) {
1213 l = layer_t ((_y_position + height - y) / (view()->child_height ()));
1214 /* clamp to max layers to be on the safe side; sometimes the above calculation
1215 returns a too-high value */
1216 if (l >= view()->layers ()) {
1217 l = view()->layers() - 1;
1223 int const n = floor ((_y_position + height - y) / (view()->child_height ()));
1225 if (l >= (view()->layers() - 0.5)) {
1226 l = view()->layers() - 0.5;
1232 return std::make_pair (this, l);
1235 for (Children::const_iterator i = children.begin(); i != children.end(); ++i) {
1237 std::pair<TimeAxisView*, int> const r = (*i)->covers_y_position (y);
1243 return std::make_pair ((TimeAxisView *) 0, 0);
1248 TimeAxisView::preset_height (Height h)
1252 return (button_height * 2) + extra_height + 260;
1254 return (button_height * 2) + extra_height + 160;
1256 return (button_height * 2) + extra_height + 60;
1258 return (button_height * 2) + extra_height + 10;
1260 return button_height + extra_height;
1267 /** @return Child time axis views that are not hidden */
1268 TimeAxisView::Children
1269 TimeAxisView::get_child_list ()
1273 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1274 if (!(*i)->hidden()) {
1283 TimeAxisView::build_size_menu ()
1285 if (_size_menu && _size_menu->gobj ()) {
1291 using namespace Menu_Helpers;
1293 _size_menu = new Menu;
1294 _size_menu->set_name ("ArdourContextMenu");
1295 MenuList& items = _size_menu->items();
1297 items.push_back (MenuElem (_("Largest"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLargest, true)));
1298 items.push_back (MenuElem (_("Larger"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarger, true)));
1299 items.push_back (MenuElem (_("Large"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarge, true)));
1300 items.push_back (MenuElem (_("Normal"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightNormal, true)));
1301 items.push_back (MenuElem (_("Small"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightSmall, true)));
1305 TimeAxisView::reset_visual_state ()
1307 /* this method is not required to trigger a global redraw */
1309 string str = gui_property ("height");
1312 set_height (atoi (str));
1314 set_height (preset_height (HeightNormal));
1319 TrackViewList::filter_to_unique_playlists ()
1321 std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
1324 for (iterator i = begin(); i != end(); ++i) {
1325 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*i);
1327 /* not a route: include it anyway */
1330 boost::shared_ptr<ARDOUR::Track> t = rtav->track();
1332 if (playlists.insert (t->playlist()).second) {
1333 /* playlist not seen yet */
1337 /* not a track: include it anyway */