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)
74 , _name_editing (false)
80 , in_destructor (false)
85 , last_name_entry_key_press_event (0)
88 , _effective_height (0)
89 , _resize_drag_start (-1)
90 , _preresize_cursor (0)
91 , _have_preresize_cursor (false)
93 , _ebox_release_can_act (true)
95 if (extra_height == 0) {
99 _canvas_background = new Group (*ed.get_background_group (), 0.0, 0.0);
100 _canvas_display = new Group (*ed.get_trackview_group (), 0.0, 0.0);
101 _canvas_display->hide(); // reveal as needed
103 selection_group = new Group (*_canvas_display);
104 selection_group->set_data (X_("timeselection"), (void *) 1);
105 selection_group->hide();
107 _ghost_group = new Group (*_canvas_display);
108 _ghost_group->lower_to_bottom();
109 _ghost_group->show();
111 name_label.set_name ("TrackLabel");
112 name_label.set_alignment (0.0, 0.5);
113 ARDOUR_UI::instance()->set_tip (name_label, _("Track/Bus name (double click to edit)"));
115 /* typically, either name_label OR name_entry are visible,
116 but not both. its up to derived classes to show/hide them as they
122 controls_table.set_size_request (200);
123 controls_table.set_row_spacings (2);
124 controls_table.set_col_spacings (2);
125 controls_table.set_border_width (2);
126 controls_table.set_homogeneous (true);
128 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 3, 0);
129 controls_table.show_all ();
130 controls_table.set_no_show_all ();
132 HSeparator* separator = manage (new HSeparator());
134 controls_vbox.pack_start (controls_table, false, false);
135 controls_vbox.show ();
137 //controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
138 controls_ebox.add (controls_vbox);
139 controls_ebox.add_events (Gdk::BUTTON_PRESS_MASK|
140 Gdk::BUTTON_RELEASE_MASK|
141 Gdk::POINTER_MOTION_MASK|
142 Gdk::ENTER_NOTIFY_MASK|
143 Gdk::LEAVE_NOTIFY_MASK|
145 controls_ebox.set_flags (CAN_FOCUS);
147 /* note that this handler connects *before* the default handler */
148 controls_ebox.signal_scroll_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_scroll), true);
149 controls_ebox.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_press));
150 controls_ebox.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
151 controls_ebox.signal_motion_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_motion));
152 controls_ebox.signal_leave_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_leave));
153 controls_ebox.show ();
155 controls_hbox.pack_start (controls_ebox, true, true);
156 controls_hbox.show ();
158 time_axis_vbox.pack_start (controls_hbox, true, true);
159 time_axis_vbox.pack_end (*separator, false, false);
160 time_axis_vbox.show();
162 ColorsChanged.connect (sigc::mem_fun (*this, &TimeAxisView::color_handler));
164 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), boost::bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
167 TimeAxisView::~TimeAxisView()
169 in_destructor = true;
171 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
175 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
177 delete (*i)->start_trim;
178 delete (*i)->end_trim;
182 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
184 delete (*i)->start_trim;
185 delete (*i)->end_trim;
188 delete selection_group;
191 delete _canvas_background;
192 _canvas_background = 0;
194 delete _canvas_display;
204 TimeAxisView::hide ()
210 _canvas_display->hide ();
211 _canvas_background->hide ();
213 if (control_parent) {
214 control_parent->remove (time_axis_vbox);
221 /* now hide children */
223 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
227 /* if its hidden, it cannot be selected */
228 _editor.get_selection().remove (this);
229 /* and neither can its regions */
230 _editor.get_selection().remove_regions (this);
235 /** Display this TimeAxisView as the nth component of the parent box, at y.
237 * @param y y position.
238 * @param nth index for this TimeAxisView, increased if this view has children.
239 * @param parent parent component.
240 * @return height of this TimeAxisView.
243 TimeAxisView::show_at (double y, int& nth, VBox *parent)
245 if (control_parent) {
246 control_parent->reorder_child (time_axis_vbox, nth);
248 control_parent = parent;
249 parent->pack_start (time_axis_vbox, false, false);
250 parent->reorder_child (time_axis_vbox, nth);
255 if (_y_position != y) {
256 _canvas_display->property_y () = y;
257 _canvas_background->property_y () = y;
259 _canvas_display->move (0.0, 0.0);
260 _canvas_background->move (0.0, 0.0);
265 _canvas_background->raise_to_top ();
266 _canvas_display->raise_to_top ();
268 _canvas_background->show ();
269 _canvas_display->show ();
273 _effective_height = current_height ();
275 /* now show relevant children */
277 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
278 if ((*i)->marked_for_display()) {
280 _effective_height += (*i)->show_at (y + _effective_height, nth, parent);
286 return _effective_height;
290 TimeAxisView::clip_to_viewport ()
292 if (marked_for_display()) {
293 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()) {
294 _canvas_background->hide ();
295 _canvas_display->hide ();
298 _canvas_background->show ();
299 _canvas_display->show ();
305 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
307 switch (ev->direction) {
309 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
310 /* See Editor::_stepping_axis_view for notes on this hack */
311 Editor& e = dynamic_cast<Editor&> (_editor);
312 if (!e.stepping_axis_view ()) {
313 e.set_stepping_axis_view (this);
315 e.stepping_axis_view()->step_height (false);
317 } else if (Keyboard::no_modifiers_active (ev->state)) {
318 _editor.scroll_tracks_up_line();
323 case GDK_SCROLL_DOWN:
324 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
325 /* See Editor::_stepping_axis_view for notes on this hack */
326 Editor& e = dynamic_cast<Editor&> (_editor);
327 if (!e.stepping_axis_view ()) {
328 e.set_stepping_axis_view (this);
330 e.stepping_axis_view()->step_height (true);
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 ((event->button == 1 && event->type == GDK_2BUTTON_PRESS) || Keyboard::is_edit_event (event)) {
350 /* see if it is inside the name label */
351 if (name_label.is_ancestor (controls_ebox)) {
354 controls_ebox.translate_coordinates (name_label, event->x, event->y, nlx, nly);
355 Gtk::Allocation a = name_label.get_allocation ();
356 if (nlx > 0 && nlx < a.get_width() && nly > 0 && nly < a.get_height()) {
357 begin_name_edit ((GdkEvent*) event);
358 _ebox_release_can_act = false;
365 _ebox_release_can_act = true;
367 if (maybe_set_cursor (event->y) > 0) {
368 _resize_drag_start = event->y_root;
375 TimeAxisView::idle_resize (uint32_t h)
382 TimeAxisView::controls_ebox_motion (GdkEventMotion* ev)
384 if (_resize_drag_start >= 0) {
385 /* (ab)use the DragManager to do autoscrolling; adjust the event coordinates
386 into the world coordinate space that DragManager::motion_handler is expecting,
387 and then fake a DragManager motion event so that when maybe_autoscroll
388 asks DragManager for the current pointer position it will get the correct
392 controls_ebox.translate_coordinates (*control_parent, ev->x, ev->y, tx, ty);
393 ev->y = ty - _editor.get_trackview_group_vertical_offset();
394 _editor.drags()->motion_handler ((GdkEvent *) ev, false);
395 _editor.maybe_autoscroll (false, true, false, ev->y_root < _resize_drag_start);
397 /* now do the actual TAV resize */
398 int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
399 _editor.add_to_idle_resize (this, delta);
400 _resize_drag_start = ev->y_root;
402 /* not dragging but ... */
403 maybe_set_cursor (ev->y);
410 TimeAxisView::controls_ebox_leave (GdkEventCrossing*)
412 if (_have_preresize_cursor) {
413 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
414 _have_preresize_cursor = false;
420 TimeAxisView::maybe_set_cursor (int y)
422 /* XXX no Gtkmm Gdk::Window::get_cursor() */
423 Glib::RefPtr<Gdk::Window> win = controls_ebox.get_window();
425 if (y > (gint) floor (controls_ebox.get_height() * 0.75)) {
427 /* y-coordinate in lower 25% */
429 if (!_have_preresize_cursor) {
430 _preresize_cursor = gdk_window_get_cursor (win->gobj());
431 _have_preresize_cursor = true;
432 win->set_cursor (Gdk::Cursor(Gdk::SB_V_DOUBLE_ARROW));
437 } else if (_have_preresize_cursor) {
438 gdk_window_set_cursor (win->gobj(), _preresize_cursor);
439 _have_preresize_cursor = false;
448 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
450 if (_resize_drag_start >= 0) {
451 if (_have_preresize_cursor) {
452 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
453 _preresize_cursor = 0;
454 _have_preresize_cursor = false;
456 _editor.stop_canvas_autoscroll ();
457 _resize_drag_start = -1;
460 if (!_ebox_release_can_act) {
464 switch (ev->button) {
466 selection_click (ev);
470 popup_display_menu (ev->time);
478 TimeAxisView::selection_click (GdkEventButton* ev)
480 Selection::Operation op = ArdourKeyboard::selection_type (ev->state);
481 _editor.set_selected_track (*this, op, false);
485 /** Steps through the defined heights for this TrackView.
486 * @param coarser true if stepping should decrease in size, otherwise false.
489 TimeAxisView::step_height (bool coarser)
491 static const uint32_t step = 25;
495 if (height <= preset_height (HeightSmall)) {
497 } else if (height <= preset_height (HeightNormal) && height > preset_height (HeightSmall)) {
498 set_height_enum (HeightSmall);
500 set_height (height - step);
505 if (height <= preset_height(HeightSmall)) {
506 set_height_enum (HeightNormal);
508 set_height (height + step);
515 TimeAxisView::set_height_enum (Height h, bool apply_to_selection)
517 if (apply_to_selection) {
518 _editor.get_selection().tracks.foreach_time_axis (boost::bind (&TimeAxisView::set_height_enum, _1, h, false));
520 set_height (preset_height (h));
525 TimeAxisView::set_height (uint32_t h)
527 if (h < preset_height (HeightSmall)) {
528 h = preset_height (HeightSmall);
531 time_axis_vbox.property_height_request () = h;
535 snprintf (buf, sizeof (buf), "%u", height);
536 set_gui_property ("height", buf);
538 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
542 if (canvas_item_visible (selection_group)) {
543 /* resize the selection rect */
544 show_selection (_editor.get_selection().time);
549 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
551 TrackViewList::iterator i;
553 switch (ev->keyval) {
555 // revert back to the way it was because
556 // name_entry_changed() will still be called as we drop focus.
557 name_entry->set_text (name_label.get_text());
558 // moving the focus will trigger everything else
559 controls_ebox.grab_focus ();
562 /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
563 * generates a different ev->keyval, rather than setting
566 case GDK_ISO_Left_Tab:
569 TrackViewList const & allviews = _editor.get_track_views ();
570 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
572 if (ev->keyval == GDK_Tab) {
573 if (i != allviews.end()) {
576 if (++i == allviews.end()) {
580 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
582 if (rtav && rtav->route()->record_enabled()) {
586 if (!(*i)->hidden()) {
593 if (i != allviews.begin()) {
595 if (i == allviews.begin()) {
601 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*>(*i);
603 if (rtav && rtav->route()->record_enabled()) {
607 if (!(*i)->hidden()) {
615 /* moving the focus will trigger everything else that is needed */
617 if ((i != allviews.end()) && (*i != this) && !(*i)->hidden()) {
618 _editor.ensure_time_axis_view_is_visible (**i);
619 (*i)->begin_name_edit ((GdkEvent*) ev);
621 controls_ebox.grab_focus ();
629 controls_ebox.grab_focus ();
636 #ifdef TIMEOUT_NAME_EDIT
637 /* adapt the timeout to reflect the user's typing speed */
639 guint32 name_entry_timeout;
641 if (last_name_entry_key_press_event) {
642 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
643 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
645 /* start with a 1 second timeout */
646 name_entry_timeout = 1000;
649 last_name_entry_key_press_event = ev->time;
651 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
653 name_entry_key_timeout.disconnect();
654 name_entry_key_timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
662 TimeAxisView::begin_name_edit (GdkEvent* event)
668 if (can_edit_name()) {
670 _name_editing = true;
673 name_entry->select_region (0, -1);
674 name_entry->set_state (STATE_SELECTED);
675 name_entry->grab_focus ();
676 name_entry->start_editing (event);
681 TimeAxisView::end_name_edit (bool push_focus)
683 if (!_name_editing) {
687 if (can_edit_name()) {
689 _name_editing = false;
691 last_name_entry_key_press_event = 0;
692 name_entry_key_timeout.disconnect ();
695 controls_ebox.grab_focus ();
699 name_entry_changed ();
704 TimeAxisView::name_entry_changed ()
709 TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
711 begin_name_edit ((GdkEvent*) ev);
716 TimeAxisView::name_entry_focus_out (GdkEventFocus*)
718 end_name_edit (false);
723 TimeAxisView::name_entry_key_timed_out ()
725 name_entry_activated();
730 TimeAxisView::name_entry_activated ()
732 end_name_edit (true);
736 TimeAxisView::can_edit_name () const
742 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
744 if (ev->button == 3) {
748 if (ev->button == 1) {
749 if (ev->type != GDK_2BUTTON_PRESS) {
750 conditionally_add_to_selection ();
758 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
760 if (ev->button == 3) {
761 popup_display_menu (ev->time);
768 TimeAxisView::conditionally_add_to_selection ()
770 Selection& s (_editor.get_selection ());
772 if (!s.selected (this)) {
773 _editor.set_selected_track (*this, Selection::Set);
778 TimeAxisView::popup_display_menu (guint32 when)
780 conditionally_add_to_selection ();
782 build_display_menu ();
783 display_menu->popup (1, when);
787 TimeAxisView::set_selected (bool yn)
789 if (yn == _selected) {
793 Selectable::set_selected (yn);
796 controls_ebox.set_name (controls_base_selected_name);
797 time_axis_vbox.set_name (controls_base_selected_name);
798 controls_vbox.set_name (controls_base_selected_name);
800 controls_ebox.set_name (controls_base_unselected_name);
801 time_axis_vbox.set_name (controls_base_unselected_name);
802 controls_vbox.set_name (controls_base_unselected_name);
805 /* children will be set for the yn=true case. but when deselecting
806 the editor only has a list of top-level trackviews, so we
807 have to do this here.
810 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
811 (*i)->set_selected (false);
817 TimeAxisView::build_display_menu ()
819 using namespace Menu_Helpers;
823 display_menu = new Menu;
824 display_menu->set_name ("ArdourContextMenu");
826 // Just let implementing classes define what goes into the manu
830 TimeAxisView::set_samples_per_unit (double spu)
832 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
833 (*i)->set_samples_per_unit (spu);
836 AnalysisFeatureList::const_iterator i;
837 list<ArdourCanvas::SimpleLine*>::iterator l;
841 TimeAxisView::show_timestretch (framepos_t start, framepos_t end, int layers, int layer)
843 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
844 (*i)->show_timestretch (start, end, layers, layer);
849 TimeAxisView::hide_timestretch ()
851 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
852 (*i)->hide_timestretch ();
857 TimeAxisView::show_selection (TimeSelection& ts)
864 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
865 (*i)->show_selection (ts);
868 if (canvas_item_visible (selection_group)) {
869 while (!used_selection_rects.empty()) {
870 free_selection_rects.push_front (used_selection_rects.front());
871 used_selection_rects.pop_front();
872 free_selection_rects.front()->rect->hide();
873 free_selection_rects.front()->start_trim->hide();
874 free_selection_rects.front()->end_trim->hide();
876 selection_group->hide();
879 selection_group->show();
880 selection_group->raise_to_top();
882 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
883 framepos_t start, end;
888 cnt = end - start + 1;
890 rect = get_selection_rect ((*i).id);
892 x1 = _editor.frame_to_unit (start);
893 x2 = _editor.frame_to_unit (start + cnt - 1);
894 y2 = current_height();
896 rect->rect->property_x1() = x1;
897 rect->rect->property_y1() = 1.0;
898 rect->rect->property_x2() = x2;
899 rect->rect->property_y2() = y2;
901 // trim boxes are at the top for selections
904 rect->start_trim->property_x1() = x1;
905 rect->start_trim->property_y1() = 1.0;
906 rect->start_trim->property_x2() = x1 + trim_handle_size;
907 rect->start_trim->property_y2() = y2;
909 rect->end_trim->property_x1() = x2 - trim_handle_size;
910 rect->end_trim->property_y1() = 1.0;
911 rect->end_trim->property_x2() = x2;
912 rect->end_trim->property_y2() = y2;
914 rect->start_trim->show();
915 rect->end_trim->show();
917 rect->start_trim->hide();
918 rect->end_trim->hide();
922 used_selection_rects.push_back (rect);
927 TimeAxisView::reshow_selection (TimeSelection& ts)
931 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
932 (*i)->show_selection (ts);
937 TimeAxisView::hide_selection ()
939 if (canvas_item_visible (selection_group)) {
940 while (!used_selection_rects.empty()) {
941 free_selection_rects.push_front (used_selection_rects.front());
942 used_selection_rects.pop_front();
943 free_selection_rects.front()->rect->hide();
944 free_selection_rects.front()->start_trim->hide();
945 free_selection_rects.front()->end_trim->hide();
947 selection_group->hide();
950 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
951 (*i)->hide_selection ();
956 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
958 /* find the selection rect this is for. we have the item corresponding to one
962 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
963 if ((*i)->start_trim == item || (*i)->end_trim == item) {
965 /* make one trim handle be "above" the other so that if they overlap,
966 the top one is the one last used.
969 (*i)->rect->raise_to_top ();
970 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
971 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
979 TimeAxisView::get_selection_rect (uint32_t id)
983 /* check to see if we already have a visible rect for this particular selection ID */
985 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
986 if ((*i)->id == id) {
991 /* ditto for the free rect list */
993 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
994 if ((*i)->id == id) {
995 SelectionRect* ret = (*i);
996 free_selection_rects.erase (i);
1001 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
1003 if (free_selection_rects.empty()) {
1005 rect = new SelectionRect;
1007 rect->rect = new SimpleRect (*selection_group);
1008 rect->rect->property_outline_what() = 0x0;
1009 rect->rect->property_x1() = 0.0;
1010 rect->rect->property_y1() = 0.0;
1011 rect->rect->property_x2() = 0.0;
1012 rect->rect->property_y2() = 0.0;
1013 rect->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1015 rect->start_trim = new SimpleRect (*selection_group);
1016 rect->start_trim->property_outline_what() = 0x0;
1017 rect->start_trim->property_x1() = 0.0;
1018 rect->start_trim->property_x2() = 0.0;
1020 rect->end_trim = new SimpleRect (*selection_group);
1021 rect->end_trim->property_outline_what() = 0x0;
1022 rect->end_trim->property_x1() = 0.0;
1023 rect->end_trim->property_x2() = 0.0;
1025 free_selection_rects.push_front (rect);
1027 rect->rect->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
1028 rect->start_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
1029 rect->end_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
1032 rect = free_selection_rects.front();
1034 free_selection_rects.pop_front();
1038 struct null_deleter { void operator()(void const *) const {} };
1041 TimeAxisView::is_child (TimeAxisView* tav)
1043 return find (children.begin(), children.end(), boost::shared_ptr<TimeAxisView>(tav, null_deleter())) != children.end();
1047 TimeAxisView::add_child (boost::shared_ptr<TimeAxisView> child)
1049 children.push_back (child);
1053 TimeAxisView::remove_child (boost::shared_ptr<TimeAxisView> child)
1055 Children::iterator i;
1057 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
1062 /** Get selectable things within a given range.
1063 * @param start Start time in session frames.
1064 * @param end End time in session frames.
1065 * @param top Top y range, in trackview coordinates (ie 0 is the top of the track view)
1066 * @param bot Bottom y range, in trackview coordinates (ie 0 is the top of the track view)
1067 * @param result Filled in with selectable things.
1070 TimeAxisView::get_selectables (framepos_t /*start*/, framepos_t /*end*/, double /*top*/, double /*bot*/, list<Selectable*>& /*result*/)
1076 TimeAxisView::get_inverted_selectables (Selection& /*sel*/, list<Selectable*>& /*result*/)
1082 TimeAxisView::add_ghost (RegionView* rv)
1084 GhostRegion* gr = rv->add_ghost (*this);
1087 ghosts.push_back(gr);
1092 TimeAxisView::remove_ghost (RegionView* rv)
1094 rv->remove_ghost_in (*this);
1098 TimeAxisView::erase_ghost (GhostRegion* gr)
1100 if (in_destructor) {
1104 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1113 TimeAxisView::touched (double top, double bot)
1115 /* remember: this is X Window - coordinate space starts in upper left and moves down.
1116 y_position is the "origin" or "top" of the track.
1119 double mybot = _y_position + current_height();
1121 return ((_y_position <= bot && _y_position >= top) ||
1122 ((mybot <= bot) && (top < mybot)) ||
1123 (mybot >= bot && _y_position < top));
1127 TimeAxisView::set_parent (TimeAxisView& p)
1133 TimeAxisView::reset_height ()
1135 set_height (height);
1137 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1138 (*i)->set_height ((*i)->height);
1143 TimeAxisView::compute_heights ()
1145 Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
1146 Gtk::Table two_row_table (2, 8);
1147 Gtk::Table one_row_table (1, 8);
1149 const int border_width = 2;
1151 const int separator_height = 2;
1152 extra_height = (2 * border_width) + separator_height;
1154 window.add (one_row_table);
1156 one_row_table.set_border_width (border_width);
1157 one_row_table.set_row_spacings (0);
1158 one_row_table.set_col_spacings (0);
1159 one_row_table.set_homogeneous (true);
1161 two_row_table.set_border_width (border_width);
1162 two_row_table.set_row_spacings (0);
1163 two_row_table.set_col_spacings (0);
1164 two_row_table.set_homogeneous (true);
1166 for (int i = 0; i < 5; ++i) {
1167 buttons[i] = manage (new Button (X_("f")));
1168 buttons[i]->set_name ("TrackMuteButton");
1171 one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1173 one_row_table.show_all ();
1174 Gtk::Requisition req(one_row_table.size_request ());
1176 // height required to show 1 row of buttons
1177 button_height = req.height;
1181 TimeAxisView::show_name_label ()
1183 if (name_entry && name_entry->is_ancestor (name_hbox)) {
1184 name_hbox.remove (*name_entry);
1187 if (!name_label.is_ancestor (name_hbox) && name_label.get_parent() == 0) {
1188 name_hbox.pack_start (name_label, true, true);
1195 TimeAxisView::show_name_entry ()
1199 Create the standard LHS Controls
1200 We create the top-level container and name add the name label here,
1201 subclasses can add to the layout as required
1204 name_entry = new Gtkmm2ext::FocusEntry;
1206 name_entry->set_name ("EditorTrackNameDisplay");
1207 name_entry->signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_release), false);
1208 name_entry->signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_press), false);
1209 name_entry->signal_key_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_release));
1210 name_entry->signal_activate().connect (sigc::mem_fun(*this, &TimeAxisView::name_entry_activated));
1211 name_entry->signal_focus_in_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_in));
1212 name_entry->signal_focus_out_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_out));
1213 Gtkmm2ext::set_size_request_to_display_given_text (*name_entry, N_("gTortnam"), 10, 10); // just represents a short name
1215 name_entry->set_text (name_label.get_text());
1218 if (name_label.is_ancestor (name_hbox)) {
1219 name_hbox.remove (name_label);
1222 if (!name_entry->is_ancestor (name_hbox) && name_label.get_parent() == 0) {
1223 name_hbox.pack_start (*name_entry, true, true);
1225 name_entry->show ();
1230 TimeAxisView::color_handler ()
1232 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); i++) {
1236 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
1238 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1239 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1241 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1242 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1244 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1245 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1248 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
1250 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1251 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1253 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1254 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1256 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1257 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1261 /** @return Pair: TimeAxisView, layer index.
1262 * TimeAxisView is non-0 if this object covers y, or one of its children does.
1263 * If the covering object is a child axis, then the child is returned.
1264 * TimeAxisView is 0 otherwise.
1265 * Layer index is the layer number (possibly fractional) if the TimeAxisView is valid
1266 * and is in stacked or expanded * region display mode, otherwise 0.
1268 std::pair<TimeAxisView*, double>
1269 TimeAxisView::covers_y_position (double y)
1272 return std::make_pair ((TimeAxisView *) 0, 0);
1275 if (_y_position <= y && y < (_y_position + height)) {
1277 /* work out the layer index if appropriate */
1279 switch (layer_display ()) {
1285 l = layer_t ((_y_position + height - y) / (view()->child_height ()));
1286 /* clamp to max layers to be on the safe side; sometimes the above calculation
1287 returns a too-high value */
1288 if (l >= view()->layers ()) {
1289 l = view()->layers() - 1;
1295 int const n = floor ((_y_position + height - y) / (view()->child_height ()));
1297 if (l >= (view()->layers() - 0.5)) {
1298 l = view()->layers() - 0.5;
1304 return std::make_pair (this, l);
1307 for (Children::const_iterator i = children.begin(); i != children.end(); ++i) {
1309 std::pair<TimeAxisView*, int> const r = (*i)->covers_y_position (y);
1315 return std::make_pair ((TimeAxisView *) 0, 0);
1320 TimeAxisView::preset_height (Height h)
1324 return (button_height * 2) + extra_height + 260;
1326 return (button_height * 2) + extra_height + 160;
1328 return (button_height * 2) + extra_height + 60;
1330 return (button_height * 2) + extra_height + 10;
1332 return button_height + extra_height;
1339 /** @return Child time axis views that are not hidden */
1340 TimeAxisView::Children
1341 TimeAxisView::get_child_list ()
1345 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1346 if (!(*i)->hidden()) {
1355 TimeAxisView::build_size_menu ()
1357 if (_size_menu && _size_menu->gobj ()) {
1363 using namespace Menu_Helpers;
1365 _size_menu = new Menu;
1366 _size_menu->set_name ("ArdourContextMenu");
1367 MenuList& items = _size_menu->items();
1369 items.push_back (MenuElem (_("Largest"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLargest, true)));
1370 items.push_back (MenuElem (_("Larger"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarger, true)));
1371 items.push_back (MenuElem (_("Large"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarge, true)));
1372 items.push_back (MenuElem (_("Normal"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightNormal, true)));
1373 items.push_back (MenuElem (_("Small"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightSmall, true)));
1377 TimeAxisView::reset_visual_state ()
1379 /* this method is not required to trigger a global redraw */
1381 string str = gui_property ("height");
1384 set_height (atoi (str));
1386 set_height (preset_height (HeightNormal));
1391 TrackViewList::filter_to_unique_playlists ()
1393 std::set<boost::shared_ptr<ARDOUR::Playlist> > playlists;
1396 for (iterator i = begin(); i != end(); ++i) {
1397 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*i);
1399 /* not a route: include it anyway */
1402 boost::shared_ptr<ARDOUR::Track> t = rtav->track();
1404 if (playlists.insert (t->playlist()).second) {
1405 /* playlist not seen yet */
1409 /* not a track: include it anyway */