when tabbing between track/bus name entries, attempt to scroll appropriately (#4223)
[ardour2.git] / gtk2_ardour / time_axis_view.cc
blob71a830982c83952be3a4eae1efbe63c02328de1e
1 /*
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.
20 #include <cstdlib>
21 #include <cmath>
22 #include <algorithm>
23 #include <string>
24 #include <list>
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/session.h"
37 #include "ardour/utils.h"
38 #include "ardour/ladspa_plugin.h"
39 #include "ardour/processor.h"
40 #include "ardour/location.h"
42 #include "ardour_ui.h"
43 #include "global_signals.h"
44 #include "gui_thread.h"
45 #include "public_editor.h"
46 #include "time_axis_view.h"
47 #include "region_view.h"
48 #include "ghostregion.h"
49 #include "simplerect.h"
50 #include "simpleline.h"
51 #include "selection.h"
52 #include "keyboard.h"
53 #include "rgb_macros.h"
54 #include "utils.h"
55 #include "streamview.h"
56 #include "editor_drag.h"
58 #include "i18n.h"
60 using namespace std;
61 using namespace Gtk;
62 using namespace Gdk;
63 using namespace ARDOUR;
64 using namespace PBD;
65 using namespace Editing;
66 using namespace ArdourCanvas;
67 using Gtkmm2ext::Keyboard;
69 const double trim_handle_size = 6.0; /* pixels */
70 uint32_t TimeAxisView::extra_height;
71 uint32_t TimeAxisView::small_height;
72 int const TimeAxisView::_max_order = 512;
73 PBD::Signal1<void,TimeAxisView*> TimeAxisView::CatchDeletion;
75 TimeAxisView::TimeAxisView (ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* rent, Canvas& /*canvas*/)
76 : AxisView (sess)
77 , controls_table (2, 8)
78 , _size_menu (0)
79 , _y_position (0)
80 , _editor (ed)
81 , _order (0)
82 , _preresize_cursor (0)
83 , _have_preresize_cursor (false)
84 , _ghost_group (0)
86 if (extra_height == 0) {
87 compute_heights ();
90 _canvas_background = new Group (*ed.get_background_group (), 0.0, 0.0);
91 _canvas_display = new Group (*ed.get_trackview_group (), 0.0, 0.0);
92 _canvas_display->hide(); // reveal as needed
94 selection_group = new Group (*_canvas_display);
95 selection_group->set_data (X_("timeselection"), (void *) 1);
96 selection_group->hide();
98 _ghost_group = new Group (*_canvas_display);
99 _ghost_group->lower_to_bottom();
100 _ghost_group->show();
102 control_parent = 0;
103 display_menu = 0;
104 _hidden = false;
105 in_destructor = false;
106 height = 0;
107 _effective_height = 0;
108 parent = rent;
109 last_name_entry_key_press_event = 0;
110 name_packing = NamePackingBits (0);
111 _resize_drag_start = -1;
114 Create the standard LHS Controls
115 We create the top-level container and name add the name label here,
116 subclasses can add to the layout as required
119 name_entry.set_name ("EditorTrackNameDisplay");
120 name_entry.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_release));
121 name_entry.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_press));
122 name_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_release));
123 name_entry.signal_activate().connect (sigc::mem_fun(*this, &TimeAxisView::name_entry_activated));
124 name_entry.signal_focus_in_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_in));
125 name_entry.signal_focus_out_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_out));
126 Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
128 name_label.set_name ("TrackLabel");
129 name_label.set_alignment (0.0, 0.5);
131 /* typically, either name_label OR name_entry are visible,
132 but not both. its up to derived classes to show/hide them as they
133 wish.
136 name_hbox.show ();
138 controls_table.set_size_request (200);
139 controls_table.set_row_spacings (0);
140 controls_table.set_col_spacings (0);
141 controls_table.set_homogeneous (true);
143 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 3, 0);
144 controls_table.show_all ();
145 controls_table.set_no_show_all ();
147 HSeparator* separator = manage (new HSeparator());
149 controls_vbox.pack_start (controls_table, false, false);
150 controls_vbox.show ();
152 //controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
153 controls_ebox.add (controls_vbox);
154 controls_ebox.add_events (Gdk::BUTTON_PRESS_MASK|
155 Gdk::BUTTON_RELEASE_MASK|
156 Gdk::POINTER_MOTION_MASK|
157 Gdk::ENTER_NOTIFY_MASK|
158 Gdk::LEAVE_NOTIFY_MASK|
159 Gdk::SCROLL_MASK);
160 controls_ebox.set_flags (CAN_FOCUS);
162 controls_ebox.signal_scroll_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_scroll), true);
163 controls_ebox.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_press));
164 controls_ebox.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
165 controls_ebox.signal_motion_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_motion));
166 controls_ebox.signal_leave_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_leave));
167 controls_ebox.show ();
169 controls_hbox.pack_start (controls_ebox, true, true);
170 controls_hbox.show ();
172 time_axis_vbox.pack_start (controls_hbox, true, true);
173 time_axis_vbox.pack_end (*separator, false, false);
174 time_axis_vbox.show();
176 ColorsChanged.connect (sigc::mem_fun (*this, &TimeAxisView::color_handler));
178 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
181 TimeAxisView::~TimeAxisView()
183 in_destructor = true;
185 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
186 delete *i;
189 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
190 delete (*i)->rect;
191 delete (*i)->start_trim;
192 delete (*i)->end_trim;
196 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
197 delete (*i)->rect;
198 delete (*i)->start_trim;
199 delete (*i)->end_trim;
202 delete selection_group;
203 selection_group = 0;
205 delete _canvas_background;
206 _canvas_background = 0;
208 delete _canvas_display;
209 _canvas_display = 0;
211 delete display_menu;
212 display_menu = 0;
214 delete _size_menu;
217 void
218 TimeAxisView::hide ()
220 if (_hidden) {
221 return;
224 _canvas_display->hide ();
225 _canvas_background->hide ();
227 if (control_parent) {
228 control_parent->remove (time_axis_vbox);
229 control_parent = 0;
232 _y_position = -1;
233 _hidden = true;
235 /* now hide children */
237 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
238 (*i)->hide ();
241 /* if its hidden, it cannot be selected */
242 _editor.get_selection().remove (this);
243 /* and neither can its regions */
244 _editor.get_selection().remove_regions (this);
246 Hiding ();
249 /** Display this TimeAxisView as the nth component of the parent box, at y.
251 * @param y y position.
252 * @param nth index for this TimeAxisView, increased if this view has children.
253 * @param parent parent component.
254 * @return height of this TimeAxisView.
256 guint32
257 TimeAxisView::show_at (double y, int& nth, VBox *parent)
259 if (control_parent) {
260 control_parent->reorder_child (time_axis_vbox, nth);
261 } else {
262 control_parent = parent;
263 parent->pack_start (time_axis_vbox, false, false);
264 parent->reorder_child (time_axis_vbox, nth);
267 _order = nth;
269 if (_y_position != y) {
270 _canvas_display->property_y () = y;
271 _canvas_background->property_y () = y;
272 /* silly canvas */
273 _canvas_display->move (0.0, 0.0);
274 _canvas_background->move (0.0, 0.0);
275 _y_position = y;
279 _canvas_background->raise_to_top ();
280 _canvas_display->raise_to_top ();
282 _canvas_background->show ();
283 _canvas_display->show ();
285 _hidden = false;
287 _effective_height = current_height ();
289 /* now show relevant children */
291 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
292 if ((*i)->marked_for_display()) {
293 ++nth;
294 _effective_height += (*i)->show_at (y + _effective_height, nth, parent);
295 } else {
296 (*i)->hide ();
300 return _effective_height;
303 void
304 TimeAxisView::clip_to_viewport ()
306 if (marked_for_display()) {
307 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()) {
308 _canvas_background->hide ();
309 _canvas_display->hide ();
310 return;
312 _canvas_background->show ();
313 _canvas_display->show ();
315 return;
318 bool
319 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
321 if (Keyboard::some_magic_widget_has_focus()) {
322 return false;
325 switch (ev->direction) {
326 case GDK_SCROLL_UP:
327 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
328 step_height (false);
329 return true;
330 } else if (Keyboard::no_modifiers_active (ev->state)) {
331 _editor.scroll_tracks_up_line();
332 return true;
334 break;
336 case GDK_SCROLL_DOWN:
337 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
338 step_height (true);
339 return true;
340 } else if (Keyboard::no_modifiers_active (ev->state)) {
341 _editor.scroll_tracks_down_line();
342 return true;
344 break;
346 default:
347 /* no handling for left/right, yet */
348 break;
351 return false;
354 bool
355 TimeAxisView::controls_ebox_button_press (GdkEventButton* event)
357 if (maybe_set_cursor (event->y) > 0) {
358 _resize_drag_start = event->y_root;
361 return true;
364 void
365 TimeAxisView::idle_resize (uint32_t h)
367 set_height (h);
371 bool
372 TimeAxisView::controls_ebox_motion (GdkEventMotion* ev)
374 if (_resize_drag_start >= 0) {
375 /* (ab)use the DragManager to do autoscrolling; adjust the event coordinates
376 into the world coordinate space that DragManager::motion_handler is expecting,
377 and then fake a DragManager motion event so that when maybe_autoscroll
378 asks DragManager for the current pointer position it will get the correct
379 answers.
381 int tx, ty;
382 controls_ebox.translate_coordinates (*control_parent, ev->x, ev->y, tx, ty);
383 ev->y = ty - _editor.get_trackview_group_vertical_offset();
384 _editor.drags()->motion_handler ((GdkEvent *) ev, false);
385 _editor.maybe_autoscroll (false, true);
387 /* now do the actual TAV resize */
388 int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
389 _editor.add_to_idle_resize (this, delta);
390 _resize_drag_start = ev->y_root;
391 } else {
392 /* not dragging but ... */
393 maybe_set_cursor (ev->y);
396 return true;
399 bool
400 TimeAxisView::controls_ebox_leave (GdkEventCrossing* ev)
402 if (_have_preresize_cursor) {
403 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
404 _have_preresize_cursor = false;
406 return true;
409 bool
410 TimeAxisView::maybe_set_cursor (int y)
412 /* XXX no Gtkmm Gdk::Window::get_cursor() */
413 Glib::RefPtr<Gdk::Window> win = controls_ebox.get_window();
415 if (y > (gint) floor (controls_ebox.get_height() * 0.75)) {
417 /* y-coordinate in lower 25% */
419 if (!_have_preresize_cursor) {
420 _preresize_cursor = gdk_window_get_cursor (win->gobj());
421 _have_preresize_cursor = true;
422 win->set_cursor (Gdk::Cursor(Gdk::SB_V_DOUBLE_ARROW));
425 return 1;
427 } else if (_have_preresize_cursor) {
428 gdk_window_set_cursor (win->gobj(), _preresize_cursor);
429 _have_preresize_cursor = false;
431 return -1;
434 return 0;
437 bool
438 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
440 if (_resize_drag_start >= 0) {
441 if (_have_preresize_cursor) {
442 gdk_window_set_cursor (controls_ebox.get_window()->gobj(), _preresize_cursor);
443 _preresize_cursor = 0;
444 _have_preresize_cursor = false;
446 _editor.stop_canvas_autoscroll ();
447 _resize_drag_start = -1;
450 switch (ev->button) {
451 case 1:
452 selection_click (ev);
453 break;
455 case 3:
456 popup_display_menu (ev->time);
457 break;
460 return true;
463 void
464 TimeAxisView::selection_click (GdkEventButton* ev)
466 Selection::Operation op = ArdourKeyboard::selection_type (ev->state);
467 _editor.set_selected_track (*this, op, false);
471 /** Steps through the defined heights for this TrackView.
472 * @param coarser true if stepping should decrease in size, otherwise false.
474 void
475 TimeAxisView::step_height (bool coarser)
477 static const uint32_t step = 25;
479 if (coarser) {
481 if (height <= preset_height (HeightSmall)) {
482 return;
483 } else if (height <= preset_height (HeightNormal) && height > preset_height (HeightSmall)) {
484 set_height_enum (HeightSmall);
485 } else {
486 set_height (height - step);
489 } else {
491 if (height <= preset_height(HeightSmall)) {
492 set_height_enum (HeightNormal);
493 } else {
494 set_height (height + step);
500 void
501 TimeAxisView::set_heights (uint32_t h)
503 TrackSelection& ts (_editor.get_selection().tracks);
505 for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
506 (*i)->set_height (h);
510 void
511 TimeAxisView::set_height_enum (Height h, bool apply_to_selection)
513 if (apply_to_selection) {
514 _editor.get_selection().tracks.foreach_time_axis (boost::bind (&TimeAxisView::set_height_enum, _1, h, false));
515 } else {
516 set_height (preset_height (h));
520 void
521 TimeAxisView::set_height (uint32_t h)
523 if (h < preset_height (HeightSmall)) {
524 h = preset_height (HeightSmall);
527 time_axis_vbox.property_height_request () = h;
528 height = h;
530 char buf[32];
531 snprintf (buf, sizeof (buf), "%u", height);
532 set_gui_property ("height", buf);
534 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
535 (*i)->set_height ();
538 if (canvas_item_visible (selection_group)) {
539 /* resize the selection rect */
540 show_selection (_editor.get_selection().time);
544 bool
545 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
547 TrackViewList::iterator i;
549 switch (ev->keyval) {
550 case GDK_Escape:
551 name_entry.select_region (0,0);
552 controls_ebox.grab_focus ();
553 name_entry_changed ();
554 return true;
556 /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
557 * generates a different ev->keyval, rather than setting
558 * ev->state.
560 case GDK_ISO_Left_Tab:
561 case GDK_Tab:
563 name_entry_changed ();
564 TrackViewList const & allviews = _editor.get_track_views ();
565 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
566 if (ev->keyval == GDK_Tab) {
567 if (i != allviews.end()) {
568 do {
569 if (++i == allviews.end()) {
570 return true;
572 } while((*i)->hidden());
574 } else {
575 if (i != allviews.begin()) {
576 do {
577 if (i == allviews.begin()) {
578 return true;
580 --i;
581 } while ((*i)->hidden());
585 (*i)->name_entry.grab_focus();
586 _editor.ensure_time_axis_view_is_visible (**i);
588 return true;
590 case GDK_Up:
591 case GDK_Down:
592 name_entry_changed ();
593 return true;
595 default:
596 break;
599 #ifdef TIMEOUT_NAME_EDIT
600 /* adapt the timeout to reflect the user's typing speed */
602 guint32 name_entry_timeout;
604 if (last_name_entry_key_press_event) {
605 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
606 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
607 } else {
608 /* start with a 1 second timeout */
609 name_entry_timeout = 1000;
612 last_name_entry_key_press_event = ev->time;
614 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
616 name_entry_key_timeout.disconnect();
617 name_entry_key_timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
618 #endif
620 return false;
623 bool
624 TimeAxisView::name_entry_focus_in (GdkEventFocus*)
626 name_entry.select_region (0, -1);
627 name_entry.set_name ("EditorActiveTrackNameDisplay");
628 return false;
631 bool
632 TimeAxisView::name_entry_focus_out (GdkEventFocus*)
634 /* clean up */
636 last_name_entry_key_press_event = 0;
637 name_entry_key_timeout.disconnect ();
638 name_entry.set_name ("EditorTrackNameDisplay");
639 name_entry.select_region (0,0);
641 /* do the real stuff */
643 name_entry_changed ();
645 return false;
648 bool
649 TimeAxisView::name_entry_key_timed_out ()
651 name_entry_activated();
652 return false;
655 void
656 TimeAxisView::name_entry_activated ()
658 controls_ebox.grab_focus();
661 void
662 TimeAxisView::name_entry_changed ()
666 bool
667 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
669 if (ev->button == 3) {
670 return true;
672 return false;
675 bool
676 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
678 if (ev->button == 3) {
679 popup_display_menu (ev->time);
680 return true;
682 return false;
685 void
686 TimeAxisView::conditionally_add_to_selection ()
688 Selection& s (_editor.get_selection ());
690 if (!s.selected (this)) {
691 _editor.set_selected_track (*this, Selection::Set);
695 void
696 TimeAxisView::popup_display_menu (guint32 when)
698 conditionally_add_to_selection ();
700 build_display_menu ();
701 display_menu->popup (1, when);
704 void
705 TimeAxisView::set_selected (bool yn)
707 if (yn == _selected) {
708 return;
711 Selectable::set_selected (yn);
713 if (_selected) {
714 controls_ebox.set_name (controls_base_selected_name);
715 time_axis_vbox.set_name (controls_base_selected_name);
716 controls_vbox.set_name (controls_base_selected_name);
717 } else {
718 controls_ebox.set_name (controls_base_unselected_name);
719 time_axis_vbox.set_name (controls_base_unselected_name);
720 controls_vbox.set_name (controls_base_unselected_name);
721 hide_selection ();
723 /* children will be set for the yn=true case. but when deselecting
724 the editor only has a list of top-level trackviews, so we
725 have to do this here.
728 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
729 (*i)->set_selected (false);
734 void
735 TimeAxisView::build_display_menu ()
737 using namespace Menu_Helpers;
739 delete display_menu;
741 display_menu = new Menu;
742 display_menu->set_name ("ArdourContextMenu");
744 // Just let implementing classes define what goes into the manu
747 void
748 TimeAxisView::set_samples_per_unit (double spu)
750 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
751 (*i)->set_samples_per_unit (spu);
754 AnalysisFeatureList::const_iterator i;
755 list<ArdourCanvas::SimpleLine*>::iterator l;
758 void
759 TimeAxisView::show_timestretch (framepos_t start, framepos_t end)
761 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
762 (*i)->show_timestretch (start, end);
766 void
767 TimeAxisView::hide_timestretch ()
769 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
770 (*i)->hide_timestretch ();
774 void
775 TimeAxisView::show_selection (TimeSelection& ts)
777 double x1;
778 double x2;
779 double y2;
780 SelectionRect *rect;
782 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
783 (*i)->show_selection (ts);
786 if (canvas_item_visible (selection_group)) {
787 while (!used_selection_rects.empty()) {
788 free_selection_rects.push_front (used_selection_rects.front());
789 used_selection_rects.pop_front();
790 free_selection_rects.front()->rect->hide();
791 free_selection_rects.front()->start_trim->hide();
792 free_selection_rects.front()->end_trim->hide();
794 selection_group->hide();
797 selection_group->show();
798 selection_group->raise_to_top();
800 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
801 framepos_t start, end;
802 framecnt_t cnt;
804 start = (*i).start;
805 end = (*i).end;
806 cnt = end - start + 1;
808 rect = get_selection_rect ((*i).id);
810 x1 = _editor.frame_to_unit (start);
811 x2 = _editor.frame_to_unit (start + cnt - 1);
812 y2 = current_height();
814 rect->rect->property_x1() = x1;
815 rect->rect->property_y1() = 1.0;
816 rect->rect->property_x2() = x2;
817 rect->rect->property_y2() = y2;
819 // trim boxes are at the top for selections
821 if (x2 > x1) {
822 rect->start_trim->property_x1() = x1;
823 rect->start_trim->property_y1() = 1.0;
824 rect->start_trim->property_x2() = x1 + trim_handle_size;
825 rect->start_trim->property_y2() = y2;
827 rect->end_trim->property_x1() = x2 - trim_handle_size;
828 rect->end_trim->property_y1() = 1.0;
829 rect->end_trim->property_x2() = x2;
830 rect->end_trim->property_y2() = y2;
832 rect->start_trim->show();
833 rect->end_trim->show();
834 } else {
835 rect->start_trim->hide();
836 rect->end_trim->hide();
839 rect->rect->show ();
840 used_selection_rects.push_back (rect);
844 void
845 TimeAxisView::reshow_selection (TimeSelection& ts)
847 show_selection (ts);
849 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
850 (*i)->show_selection (ts);
854 void
855 TimeAxisView::hide_selection ()
857 if (canvas_item_visible (selection_group)) {
858 while (!used_selection_rects.empty()) {
859 free_selection_rects.push_front (used_selection_rects.front());
860 used_selection_rects.pop_front();
861 free_selection_rects.front()->rect->hide();
862 free_selection_rects.front()->start_trim->hide();
863 free_selection_rects.front()->end_trim->hide();
865 selection_group->hide();
868 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
869 (*i)->hide_selection ();
873 void
874 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
876 /* find the selection rect this is for. we have the item corresponding to one
877 of the trim handles.
880 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
881 if ((*i)->start_trim == item || (*i)->end_trim == item) {
883 /* make one trim handle be "above" the other so that if they overlap,
884 the top one is the one last used.
887 (*i)->rect->raise_to_top ();
888 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
889 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
891 break;
896 SelectionRect *
897 TimeAxisView::get_selection_rect (uint32_t id)
899 SelectionRect *rect;
901 /* check to see if we already have a visible rect for this particular selection ID */
903 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
904 if ((*i)->id == id) {
905 return (*i);
909 /* ditto for the free rect list */
911 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
912 if ((*i)->id == id) {
913 SelectionRect* ret = (*i);
914 free_selection_rects.erase (i);
915 return ret;
919 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
921 if (free_selection_rects.empty()) {
923 rect = new SelectionRect;
925 rect->rect = new SimpleRect (*selection_group);
926 rect->rect->property_outline_what() = 0x0;
927 rect->rect->property_x1() = 0.0;
928 rect->rect->property_y1() = 0.0;
929 rect->rect->property_x2() = 0.0;
930 rect->rect->property_y2() = 0.0;
931 rect->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
933 rect->start_trim = new SimpleRect (*selection_group);
934 rect->start_trim->property_outline_what() = 0x0;
935 rect->start_trim->property_x1() = 0.0;
936 rect->start_trim->property_x2() = 0.0;
938 rect->end_trim = new SimpleRect (*selection_group);
939 rect->end_trim->property_outline_what() = 0x0;
940 rect->end_trim->property_x1() = 0.0;
941 rect->end_trim->property_x2() = 0.0;
943 free_selection_rects.push_front (rect);
945 rect->rect->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
946 rect->start_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
947 rect->end_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
950 rect = free_selection_rects.front();
951 rect->id = id;
952 free_selection_rects.pop_front();
953 return rect;
956 struct null_deleter { void operator()(void const *) const {} };
958 bool
959 TimeAxisView::is_child (TimeAxisView* tav)
961 return find (children.begin(), children.end(), boost::shared_ptr<TimeAxisView>(tav, null_deleter())) != children.end();
964 void
965 TimeAxisView::add_child (boost::shared_ptr<TimeAxisView> child)
967 children.push_back (child);
970 void
971 TimeAxisView::remove_child (boost::shared_ptr<TimeAxisView> child)
973 Children::iterator i;
975 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
976 children.erase (i);
980 /** Get selectable things within a given range.
981 * @param start Start time in session frames.
982 * @param end End time in session frames.
983 * @param top Top y range, in trackview coordinates (ie 0 is the top of the track view)
984 * @param bot Bottom y range, in trackview coordinates (ie 0 is the top of the track view)
985 * @param result Filled in with selectable things.
987 void
988 TimeAxisView::get_selectables (framepos_t /*start*/, framepos_t /*end*/, double /*top*/, double /*bot*/, list<Selectable*>& /*result*/)
990 return;
993 void
994 TimeAxisView::get_inverted_selectables (Selection& /*sel*/, list<Selectable*>& /*result*/)
996 return;
999 void
1000 TimeAxisView::add_ghost (RegionView* rv)
1002 GhostRegion* gr = rv->add_ghost (*this);
1004 if (gr) {
1005 ghosts.push_back(gr);
1009 void
1010 TimeAxisView::remove_ghost (RegionView* rv)
1012 rv->remove_ghost_in (*this);
1015 void
1016 TimeAxisView::erase_ghost (GhostRegion* gr)
1018 if (in_destructor) {
1019 return;
1022 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1023 if ((*i) == gr) {
1024 ghosts.erase (i);
1025 break;
1030 bool
1031 TimeAxisView::touched (double top, double bot)
1033 /* remember: this is X Window - coordinate space starts in upper left and moves down.
1034 y_position is the "origin" or "top" of the track.
1037 double mybot = _y_position + current_height();
1039 return ((_y_position <= bot && _y_position >= top) ||
1040 ((mybot <= bot) && (top < mybot)) ||
1041 (mybot >= bot && _y_position < top));
1044 void
1045 TimeAxisView::set_parent (TimeAxisView& p)
1047 parent = &p;
1050 void
1051 TimeAxisView::reset_height ()
1053 set_height (height);
1055 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1056 (*i)->set_height ((*i)->height);
1060 void
1061 TimeAxisView::compute_heights ()
1063 Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
1064 Gtk::Table two_row_table (2, 8);
1065 Gtk::Table one_row_table (1, 8);
1066 Button* buttons[5];
1067 const int border_width = 2;
1069 extra_height = (2 * border_width);
1071 window.add (one_row_table);
1073 one_row_table.set_border_width (border_width);
1074 one_row_table.set_row_spacings (0);
1075 one_row_table.set_col_spacings (0);
1076 one_row_table.set_homogeneous (true);
1078 two_row_table.set_border_width (border_width);
1079 two_row_table.set_row_spacings (0);
1080 two_row_table.set_col_spacings (0);
1081 two_row_table.set_homogeneous (true);
1083 for (int i = 0; i < 5; ++i) {
1084 buttons[i] = manage (new Button (X_("f")));
1085 buttons[i]->set_name ("TrackMuteButton");
1088 one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1090 one_row_table.show_all ();
1091 Gtk::Requisition req(one_row_table.size_request ());
1093 // height required to show 1 row of buttons
1095 small_height = req.height + (2 * border_width);
1098 void
1099 TimeAxisView::show_name_label ()
1101 if (!(name_packing & NameLabelPacked)) {
1102 name_hbox.pack_start (name_label, true, true);
1103 name_packing = NamePackingBits (name_packing | NameLabelPacked);
1104 name_hbox.show ();
1105 name_label.show ();
1109 void
1110 TimeAxisView::show_name_entry ()
1112 if (!(name_packing & NameEntryPacked)) {
1113 name_hbox.pack_start (name_entry, true, true);
1114 name_packing = NamePackingBits (name_packing | NameEntryPacked);
1115 name_hbox.show ();
1116 name_entry.show ();
1120 void
1121 TimeAxisView::hide_name_label ()
1123 if (name_packing & NameLabelPacked) {
1124 name_hbox.remove (name_label);
1125 name_packing = NamePackingBits (name_packing & ~NameLabelPacked);
1129 void
1130 TimeAxisView::hide_name_entry ()
1132 if (name_packing & NameEntryPacked) {
1133 name_hbox.remove (name_entry);
1134 name_packing = NamePackingBits (name_packing & ~NameEntryPacked);
1138 void
1139 TimeAxisView::color_handler ()
1141 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); i++) {
1142 (*i)->set_colors();
1145 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
1147 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1148 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1150 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1151 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1153 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1154 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1157 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
1159 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1160 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1162 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1163 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1165 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1166 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1170 /** @return Pair: TimeAxisView, layer index.
1171 * TimeAxisView is non-0 if this object covers y, or one of its children does.
1172 * If the covering object is a child axis, then the child is returned.
1173 * TimeAxisView is 0 otherwise.
1174 * Layer index is the layer number if the TimeAxisView is valid and is in stacked
1175 * region display mode, otherwise 0.
1177 std::pair<TimeAxisView*, layer_t>
1178 TimeAxisView::covers_y_position (double y)
1180 if (hidden()) {
1181 return std::make_pair ((TimeAxisView *) 0, 0);
1184 if (_y_position <= y && y < (_y_position + height)) {
1186 /* work out the layer index if appropriate */
1187 layer_t l = 0;
1188 if (layer_display () == Stacked && view ()) {
1189 /* compute layer */
1190 l = layer_t ((_y_position + height - y) / (view()->child_height ()));
1191 /* clamp to max layers to be on the safe side; sometimes the above calculation
1192 returns a too-high value */
1193 if (l >= view()->layers ()) {
1194 l = view()->layers() - 1;
1198 return std::make_pair (this, l);
1201 for (Children::const_iterator i = children.begin(); i != children.end(); ++i) {
1203 std::pair<TimeAxisView*, int> const r = (*i)->covers_y_position (y);
1204 if (r.first) {
1205 return r;
1209 return std::make_pair ((TimeAxisView *) 0, 0);
1213 uint32_t
1214 TimeAxisView::preset_height (Height h)
1216 switch (h) {
1217 case HeightLargest:
1218 return extra_height + 48 + 250;
1219 case HeightLarger:
1220 return extra_height + 48 + 150;
1221 case HeightLarge:
1222 return extra_height + 48 + 50;
1223 case HeightNormal:
1224 return extra_height + 48;
1225 case HeightSmall:
1226 return small_height;
1229 /* NOTREACHED */
1230 return 0;
1233 /** @return Child time axis views that are not hidden */
1234 TimeAxisView::Children
1235 TimeAxisView::get_child_list ()
1237 Children c;
1239 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1240 if (!(*i)->hidden()) {
1241 c.push_back(*i);
1245 return c;
1248 void
1249 TimeAxisView::build_size_menu ()
1251 if (_size_menu && _size_menu->gobj ()) {
1252 return;
1255 delete _size_menu;
1257 using namespace Menu_Helpers;
1259 _size_menu = new Menu;
1260 _size_menu->set_name ("ArdourContextMenu");
1261 MenuList& items = _size_menu->items();
1263 items.push_back (MenuElem (_("Largest"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLargest, true)));
1264 items.push_back (MenuElem (_("Larger"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarger, true)));
1265 items.push_back (MenuElem (_("Large"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightLarge, true)));
1266 items.push_back (MenuElem (_("Normal"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightNormal, true)));
1267 items.push_back (MenuElem (_("Small"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_height_enum), HeightSmall, true)));
1270 void
1271 TimeAxisView::reset_visual_state ()
1273 /* this method is not required to trigger a global redraw */
1275 string str = gui_property ("height");
1277 if (!str.empty()) {
1278 set_height (atoi (str));
1279 } else {
1280 set_height (preset_height (HeightNormal));