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>
35 #include <gtkmm2ext/stop_signal.h>
37 #include "ardour/session.h"
38 #include "ardour/utils.h"
39 #include "ardour/ladspa_plugin.h"
40 #include "ardour/processor.h"
41 #include "ardour/location.h"
43 #include "ardour_ui.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"
53 #include "rgb_macros.h"
55 #include "streamview.h"
62 using namespace ARDOUR;
64 using namespace Editing;
65 using namespace ArdourCanvas;
66 using Gtkmm2ext::Keyboard;
68 const double trim_handle_size = 6.0; /* pixels */
70 uint32_t TimeAxisView::hLargest = 0;
71 uint32_t TimeAxisView::hLarge = 0;
72 uint32_t TimeAxisView::hLarger = 0;
73 uint32_t TimeAxisView::hNormal = 0;
74 uint32_t TimeAxisView::hSmaller = 0;
75 uint32_t TimeAxisView::hSmall = 0;
76 bool TimeAxisView::need_size_info = true;
77 int const TimeAxisView::_max_order = 512;
78 PBD::Signal1<void,TimeAxisView*> TimeAxisView::CatchDeletion;
80 TimeAxisView::TimeAxisView (ARDOUR::Session* sess, PublicEditor& ed, TimeAxisView* rent, Canvas& /*canvas*/)
82 controls_table (2, 8),
88 compute_controls_size_info ();
89 need_size_info = false;
91 _canvas_background = new Group (*ed.get_background_group (), 0.0, 0.0);
92 _canvas_display = new Group (*ed.get_trackview_group (), 0.0, 0.0);
93 _canvas_display->hide(); // reveal as needed
95 selection_group = new Group (*_canvas_display);
96 selection_group->hide();
98 _ghost_group = new Group (*_canvas_display);
99 _ghost_group->lower_to_bottom();
100 _ghost_group->show();
106 in_destructor = false;
108 _effective_height = 0;
111 last_name_entry_key_press_event = 0;
112 name_packing = NamePackingBits (0);
113 _resize_drag_start = -1;
116 Create the standard LHS Controls
117 We create the top-level container and name add the name label here,
118 subclasses can add to the layout as required
121 name_entry.set_name ("EditorTrackNameDisplay");
122 name_entry.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_release));
123 name_entry.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_button_press));
124 name_entry.signal_key_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_release));
125 name_entry.signal_activate().connect (sigc::mem_fun(*this, &TimeAxisView::name_entry_activated));
126 name_entry.signal_focus_in_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_in));
127 name_entry.signal_focus_out_event().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_focus_out));
128 Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
130 name_label.set_name ("TrackLabel");
131 name_label.set_alignment (0.0, 0.5);
133 /* typically, either name_label OR name_entry are visible,
134 but not both. its up to derived classes to show/hide them as they
140 controls_table.set_size_request (200);
141 controls_table.set_border_width (2);
142 controls_table.set_row_spacings (0);
143 controls_table.set_col_spacings (0);
144 controls_table.set_homogeneous (true);
146 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 3, 0);
147 controls_table.show_all ();
148 controls_table.set_no_show_all ();
150 resizer.set_size_request (10, 10);
151 resizer.set_name ("ResizeHandle");
152 resizer.signal_expose_event().connect (sigc::mem_fun (*this, &TimeAxisView::resizer_expose));
153 resizer.signal_button_press_event().connect (sigc::mem_fun (*this, &TimeAxisView::resizer_button_press));
154 resizer.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::resizer_button_release));
155 resizer.signal_motion_notify_event().connect (sigc::mem_fun (*this, &TimeAxisView::resizer_motion));
157 resizer.set_events (Gdk::BUTTON_PRESS_MASK|
158 Gdk::BUTTON_RELEASE_MASK|
159 Gdk::POINTER_MOTION_MASK|
162 resizer_box.pack_start (resizer, false, false);
166 HSeparator* separator = manage (new HSeparator());
168 controls_vbox.pack_start (controls_table, false, false);
169 controls_vbox.pack_end (*separator, false, false);
170 controls_vbox.pack_end (resizer_box, false, true);
171 controls_vbox.show ();
173 //controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
174 controls_ebox.add (controls_vbox);
175 controls_ebox.add_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK|SCROLL_MASK);
176 controls_ebox.set_flags (CAN_FOCUS);
178 controls_ebox.signal_button_release_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
179 controls_ebox.signal_scroll_event().connect (sigc::mem_fun (*this, &TimeAxisView::controls_ebox_scroll), true);
181 controls_hbox.pack_start (controls_ebox,true,true);
182 controls_hbox.show ();
184 ColorsChanged.connect (sigc::mem_fun (*this, &TimeAxisView::color_handler));
186 GhostRegion::CatchDeletion.connect (*this, invalidator (*this), ui_bind (&TimeAxisView::erase_ghost, this, _1), gui_context());
189 TimeAxisView::~TimeAxisView()
191 in_destructor = true;
193 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
197 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
199 delete (*i)->start_trim;
200 delete (*i)->end_trim;
204 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
206 delete (*i)->start_trim;
207 delete (*i)->end_trim;
210 for (list<SimpleLine*>::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
214 delete selection_group;
217 delete _canvas_background;
218 _canvas_background = 0;
220 delete _canvas_display;
227 /** Display this TimeAxisView as the nth component of the parent box, at y.
229 * @param y y position.
230 * @param nth index for this TimeAxisView, increased if this view has children.
231 * @param parent parent component.
232 * @return height of this TimeAxisView.
235 TimeAxisView::show_at (double y, int& nth, VBox *parent)
237 if (control_parent) {
238 control_parent->reorder_child (controls_hbox, nth);
240 control_parent = parent;
241 parent->pack_start (controls_hbox, false, false);
242 parent->reorder_child (controls_hbox, nth);
247 if (_y_position != y) {
248 _canvas_display->property_y () = y;
249 _canvas_background->property_y () = y;
251 _canvas_display->move (0.0, 0.0);
252 _canvas_background->move (0.0, 0.0);
257 _canvas_background->raise_to_top ();
258 _canvas_display->raise_to_top ();
260 if (_marked_for_display) {
261 controls_hbox.show ();
262 controls_ebox.show ();
263 _canvas_background->show ();
268 _effective_height = current_height ();
270 /* now show children */
272 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
273 if (canvas_item_visible ((*i)->_canvas_display)) {
275 _effective_height += (*i)->show_at (y + _effective_height, nth, parent);
279 return _effective_height;
283 TimeAxisView::clip_to_viewport ()
285 if (_marked_for_display) {
286 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()) {
287 _canvas_background->hide ();
288 _canvas_display->hide ();
291 _canvas_background->show ();
292 _canvas_display->show ();
298 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
300 if (Keyboard::some_magic_widget_has_focus()) {
304 switch (ev->direction) {
306 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
309 } else if (Keyboard::no_modifiers_active (ev->state)) {
310 _editor.scroll_tracks_up_line();
315 case GDK_SCROLL_DOWN:
316 if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
319 } else if (Keyboard::no_modifiers_active (ev->state)) {
320 _editor.scroll_tracks_down_line();
326 /* no handling for left/right, yet */
334 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
336 switch (ev->button) {
338 selection_click (ev);
342 popup_display_menu (ev->time);
350 TimeAxisView::selection_click (GdkEventButton* ev)
352 Selection::Operation op = ArdourKeyboard::selection_type (ev->state);
353 _editor.set_selected_track (*this, op, false);
357 TimeAxisView::hide ()
363 _canvas_display->hide ();
364 _canvas_background->hide ();
366 if (control_parent) {
367 control_parent->remove (controls_hbox);
374 /* now hide children */
376 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
380 /* if its hidden, it cannot be selected */
382 _editor.get_selection().remove (this);
388 TimeAxisView::step_height (bool bigger)
390 static const uint32_t step = 20;
393 set_height (height + step);
396 set_height (std::max (height - step, hSmall));
397 } else if (height != hSmall) {
404 TimeAxisView::set_heights (uint32_t h)
406 TrackSelection& ts (_editor.get_selection().tracks);
408 for (TrackSelection::iterator i = ts.begin(); i != ts.end(); ++i) {
409 (*i)->set_height (h);
414 TimeAxisView::set_height(uint32_t h)
416 controls_ebox.property_height_request () = h;
419 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
423 if (canvas_item_visible (selection_group)) {
424 /* resize the selection rect */
425 show_selection (_editor.get_selection().time);
428 reshow_feature_lines ();
432 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
434 TrackViewList::iterator i;
436 switch (ev->keyval) {
438 name_entry.select_region (0,0);
439 controls_ebox.grab_focus ();
440 name_entry_changed ();
443 /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
444 * generates a different ev->keyval, rather than setting
447 case GDK_ISO_Left_Tab:
450 name_entry_changed ();
451 TrackViewList const & allviews = _editor.get_track_views ();
452 TrackViewList::const_iterator i = find (allviews.begin(), allviews.end(), this);
453 if (ev->keyval == GDK_Tab) {
454 if (i != allviews.end()) {
456 if (++i == allviews.end()) {
459 } while((*i)->hidden());
462 if (i != allviews.begin()) {
464 if (i == allviews.begin()) {
468 } while ((*i)->hidden());
473 /* resize to show editable name display */
475 if ((*i)->current_height() <= hSmaller) {
476 (*i)->set_height (hSmaller);
479 (*i)->name_entry.grab_focus();
485 name_entry_changed ();
492 #ifdef TIMEOUT_NAME_EDIT
493 /* adapt the timeout to reflect the user's typing speed */
495 guint32 name_entry_timeout;
497 if (last_name_entry_key_press_event) {
498 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
499 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
501 /* start with a 1 second timeout */
502 name_entry_timeout = 1000;
505 last_name_entry_key_press_event = ev->time;
507 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
509 name_entry_key_timeout.disconnect();
510 name_entry_key_timeout = Glib::signal_timeout().connect (sigc::mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
517 TimeAxisView::name_entry_focus_in (GdkEventFocus*)
519 name_entry.select_region (0, -1);
520 name_entry.set_name ("EditorActiveTrackNameDisplay");
525 TimeAxisView::name_entry_focus_out (GdkEventFocus*)
529 last_name_entry_key_press_event = 0;
530 name_entry_key_timeout.disconnect ();
531 name_entry.set_name ("EditorTrackNameDisplay");
532 name_entry.select_region (0,0);
534 /* do the real stuff */
536 name_entry_changed ();
542 TimeAxisView::name_entry_key_timed_out ()
544 name_entry_activated();
549 TimeAxisView::name_entry_activated ()
551 controls_ebox.grab_focus();
555 TimeAxisView::name_entry_changed ()
560 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
562 if (ev->button == 3) {
569 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
571 if (ev->button == 3) {
572 popup_display_menu (ev->time);
579 TimeAxisView::conditionally_add_to_selection ()
581 Selection& s (_editor.get_selection ());
583 if (!s.selected (this)) {
584 _editor.set_selected_track (*this, Selection::Set);
589 TimeAxisView::popup_display_menu (guint32 when)
591 if (display_menu == 0) {
592 build_display_menu ();
595 conditionally_add_to_selection ();
596 display_menu->popup (1, when);
600 TimeAxisView::size_click (GdkEventButton *ev)
602 conditionally_add_to_selection ();
603 popup_size_menu (ev->time);
608 TimeAxisView::popup_size_menu (guint32 when)
610 if (size_menu == 0) {
613 size_menu->popup (1, when);
617 TimeAxisView::set_selected (bool yn)
619 if (yn == _selected) {
623 Selectable::set_selected (yn);
626 controls_ebox.set_name (controls_base_selected_name);
627 controls_hbox.set_name (controls_base_selected_name);
628 controls_vbox.set_name (controls_base_selected_name);
630 controls_ebox.set_name (controls_base_unselected_name);
631 controls_hbox.set_name (controls_base_unselected_name);
632 controls_vbox.set_name (controls_base_unselected_name);
635 /* children will be set for the yn=true case. but when deselecting
636 the editor only has a list of top-level trackviews, so we
637 have to do this here.
640 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
641 (*i)->set_selected (false);
645 resizer.queue_draw ();
649 TimeAxisView::build_size_menu ()
651 using namespace Menu_Helpers;
653 size_menu = new Menu;
654 size_menu->set_name ("ArdourContextMenu");
655 MenuList& items = size_menu->items();
657 items.push_back (MenuElem (_("Largest"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_heights), hLargest)));
658 items.push_back (MenuElem (_("Large"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_heights), hLarge)));
659 items.push_back (MenuElem (_("Larger"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_heights), hLarger)));
660 items.push_back (MenuElem (_("Normal"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_heights), hNormal)));
661 items.push_back (MenuElem (_("Smaller"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_heights),hSmaller)));
662 items.push_back (MenuElem (_("Small"), sigc::bind (sigc::mem_fun (*this, &TimeAxisView::set_heights), hSmall)));
666 TimeAxisView::build_display_menu ()
668 using namespace Menu_Helpers;
672 display_menu = new Menu;
673 display_menu->set_name ("ArdourContextMenu");
675 // Just let implementing classes define what goes into the manu
679 TimeAxisView::set_samples_per_unit (double spu)
681 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
682 (*i)->set_samples_per_unit (spu);
685 AnalysisFeatureList::const_iterator i;
686 list<ArdourCanvas::SimpleLine*>::iterator l;
688 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
689 (*l)->property_x1() = _editor.frame_to_pixel (*i);
690 (*l)->property_x2() = _editor.frame_to_pixel (*i);
695 TimeAxisView::show_timestretch (nframes_t start, nframes_t end)
697 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
698 (*i)->show_timestretch (start, end);
703 TimeAxisView::hide_timestretch ()
705 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
706 (*i)->hide_timestretch ();
711 TimeAxisView::show_selection (TimeSelection& ts)
718 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
719 (*i)->show_selection (ts);
722 if (canvas_item_visible (selection_group)) {
723 while (!used_selection_rects.empty()) {
724 free_selection_rects.push_front (used_selection_rects.front());
725 used_selection_rects.pop_front();
726 free_selection_rects.front()->rect->hide();
727 free_selection_rects.front()->start_trim->hide();
728 free_selection_rects.front()->end_trim->hide();
730 selection_group->hide();
733 selection_group->show();
734 selection_group->raise_to_top();
736 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
737 nframes_t start, end, cnt;
741 cnt = end - start + 1;
743 rect = get_selection_rect ((*i).id);
745 x1 = _editor.frame_to_unit (start);
746 x2 = _editor.frame_to_unit (start + cnt - 1);
747 y2 = current_height();
749 rect->rect->property_x1() = x1;
750 rect->rect->property_y1() = 1.0;
751 rect->rect->property_x2() = x2;
752 rect->rect->property_y2() = y2;
754 // trim boxes are at the top for selections
757 rect->start_trim->property_x1() = x1;
758 rect->start_trim->property_y1() = 1.0;
759 rect->start_trim->property_x2() = x1 + trim_handle_size;
760 rect->start_trim->property_y2() = 1.0 + trim_handle_size;
762 rect->end_trim->property_x1() = x2 - trim_handle_size;
763 rect->end_trim->property_y1() = 1.0;
764 rect->end_trim->property_x2() = x2;
765 rect->end_trim->property_y2() = 1.0 + trim_handle_size;
767 rect->start_trim->show();
768 rect->end_trim->show();
770 rect->start_trim->hide();
771 rect->end_trim->hide();
775 used_selection_rects.push_back (rect);
780 TimeAxisView::reshow_selection (TimeSelection& ts)
784 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
785 (*i)->show_selection (ts);
790 TimeAxisView::hide_selection ()
792 if (canvas_item_visible (selection_group)) {
793 while (!used_selection_rects.empty()) {
794 free_selection_rects.push_front (used_selection_rects.front());
795 used_selection_rects.pop_front();
796 free_selection_rects.front()->rect->hide();
797 free_selection_rects.front()->start_trim->hide();
798 free_selection_rects.front()->end_trim->hide();
800 selection_group->hide();
803 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
804 (*i)->hide_selection ();
809 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
811 /* find the selection rect this is for. we have the item corresponding to one
815 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
816 if ((*i)->start_trim == item || (*i)->end_trim == item) {
818 /* make one trim handle be "above" the other so that if they overlap,
819 the top one is the one last used.
822 (*i)->rect->raise_to_top ();
823 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
824 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
832 TimeAxisView::get_selection_rect (uint32_t id)
836 /* check to see if we already have a visible rect for this particular selection ID */
838 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
839 if ((*i)->id == id) {
844 /* ditto for the free rect list */
846 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
847 if ((*i)->id == id) {
848 SelectionRect* ret = (*i);
849 free_selection_rects.erase (i);
854 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
856 if (free_selection_rects.empty()) {
858 rect = new SelectionRect;
860 rect->rect = new SimpleRect (*selection_group);
861 rect->rect->property_x1() = 0.0;
862 rect->rect->property_y1() = 0.0;
863 rect->rect->property_x2() = 0.0;
864 rect->rect->property_y2() = 0.0;
865 rect->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
866 rect->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
868 rect->start_trim = new SimpleRect (*selection_group);
869 rect->start_trim->property_x1() = 0.0;
870 rect->start_trim->property_x2() = 0.0;
871 rect->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
872 rect->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
874 rect->end_trim = new SimpleRect (*selection_group);
875 rect->end_trim->property_x1() = 0.0;
876 rect->end_trim->property_x2() = 0.0;
877 rect->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
878 rect->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
880 free_selection_rects.push_front (rect);
882 rect->rect->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
883 rect->start_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
884 rect->end_trim->signal_event().connect (sigc::bind (sigc::mem_fun (_editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
887 rect = free_selection_rects.front();
889 free_selection_rects.pop_front();
893 struct null_deleter { void operator()(void const *) const {} };
896 TimeAxisView::is_child (TimeAxisView* tav)
898 return find (children.begin(), children.end(), boost::shared_ptr<TimeAxisView>(tav, null_deleter())) != children.end();
902 TimeAxisView::add_child (boost::shared_ptr<TimeAxisView> child)
904 children.push_back (child);
908 TimeAxisView::remove_child (boost::shared_ptr<TimeAxisView> child)
910 Children::iterator i;
912 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
918 TimeAxisView::get_selectables (nframes_t /*start*/, nframes_t /*end*/, double /*top*/, double /*bot*/, list<Selectable*>& /*result*/)
924 TimeAxisView::get_inverted_selectables (Selection& /*sel*/, list<Selectable*>& /*result*/)
930 TimeAxisView::add_ghost (RegionView* rv)
932 GhostRegion* gr = rv->add_ghost (*this);
935 ghosts.push_back(gr);
940 TimeAxisView::remove_ghost (RegionView* rv)
942 rv->remove_ghost_in (*this);
946 TimeAxisView::erase_ghost (GhostRegion* gr)
952 for (list<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
961 TimeAxisView::touched (double top, double bot)
963 /* remember: this is X Window - coordinate space starts in upper left and moves down.
964 y_position is the "origin" or "top" of the track.
967 double mybot = _y_position + current_height();
969 return ((_y_position <= bot && _y_position >= top) ||
970 ((mybot <= bot) && (top < mybot)) ||
971 (mybot >= bot && _y_position < top));
975 TimeAxisView::set_parent (TimeAxisView& p)
981 TimeAxisView::has_state () const
987 TimeAxisView::get_parent_with_state ()
993 if (parent->has_state()) {
997 return parent->get_parent_with_state ();
1002 TimeAxisView::get_state ()
1004 XMLNode* node = new XMLNode ("TAV-" + name());
1007 snprintf (buf, sizeof(buf), "%u", height);
1008 node->add_property ("height", buf);
1009 node->add_property ("marked-for-display", (_marked_for_display ? "1" : "0"));
1014 TimeAxisView::set_state (const XMLNode& node, int /*version*/)
1016 const XMLProperty *prop;
1018 if ((prop = node.property ("marked-for-display")) != 0) {
1019 _marked_for_display = (prop->value() == "1");
1022 if ((prop = node.property ("track-height")) != 0) {
1024 if (prop->value() == "largest") {
1025 set_height (hLargest);
1026 } else if (prop->value() == "large") {
1027 set_height (hLarge);
1028 } else if (prop->value() == "larger") {
1029 set_height (hLarger);
1030 } else if (prop->value() == "normal") {
1031 set_height (hNormal);
1032 } else if (prop->value() == "smaller") {
1033 set_height (hSmaller);
1034 } else if (prop->value() == "small") {
1035 set_height (hSmall);
1037 error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
1038 set_height (Normal);
1041 } else if ((prop = node.property ("height")) != 0) {
1043 set_height (atoi (prop->value()));
1047 set_height (hNormal);
1054 TimeAxisView::reset_height()
1056 set_height (height);
1058 for (Children::iterator i = children.begin(); i != children.end(); ++i) {
1059 (*i)->set_height ((*i)->height);
1064 TimeAxisView::compute_controls_size_info ()
1066 Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
1067 Gtk::Table two_row_table (2, 8);
1068 Gtk::Table one_row_table (1, 8);
1070 const int border_width = 2;
1071 const int extra_height = (2 * border_width)
1072 //+ 2 // 2 pixels for the hseparator between TimeAxisView control areas
1073 + 10; // resizer button (3 x 2 pixel elements + 2 x 2 pixel gaps)
1075 window.add (one_row_table);
1077 one_row_table.set_border_width (border_width);
1078 one_row_table.set_row_spacings (0);
1079 one_row_table.set_col_spacings (0);
1080 one_row_table.set_homogeneous (true);
1082 two_row_table.set_border_width (border_width);
1083 two_row_table.set_row_spacings (0);
1084 two_row_table.set_col_spacings (0);
1085 two_row_table.set_homogeneous (true);
1087 for (int i = 0; i < 5; ++i) {
1088 buttons[i] = manage (new Button (X_("f")));
1089 buttons[i]->set_name ("TrackMuteButton");
1092 one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1094 one_row_table.show_all ();
1095 Gtk::Requisition req(one_row_table.size_request ());
1098 // height required to show 1 row of buttons
1100 hSmaller = req.height + extra_height;
1103 window.add (two_row_table);
1105 two_row_table.attach (*buttons[1], 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1106 two_row_table.attach (*buttons[2], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1107 two_row_table.attach (*buttons[3], 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1108 two_row_table.attach (*buttons[4], 8, 9, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
1110 two_row_table.show_all ();
1111 req = two_row_table.size_request ();
1113 // height required to show all normal buttons
1115 hNormal = /*req.height*/ 48 + extra_height;
1117 // these heights are all just larger than normal. no more
1118 // elements are visible (yet).
1120 hLarger = hNormal + 50;
1121 hLarge = hNormal + 150;
1122 hLargest = hNormal + 250;
1124 // height required to show track name
1130 TimeAxisView::show_name_label ()
1132 if (!(name_packing & NameLabelPacked)) {
1133 name_hbox.pack_start (name_label, true, true);
1134 name_packing = NamePackingBits (name_packing | NameLabelPacked);
1141 TimeAxisView::show_name_entry ()
1143 if (!(name_packing & NameEntryPacked)) {
1144 name_hbox.pack_start (name_entry, true, true);
1145 name_packing = NamePackingBits (name_packing | NameEntryPacked);
1152 TimeAxisView::hide_name_label ()
1154 if (name_packing & NameLabelPacked) {
1155 name_hbox.remove (name_label);
1156 name_packing = NamePackingBits (name_packing & ~NameLabelPacked);
1161 TimeAxisView::hide_name_entry ()
1163 if (name_packing & NameEntryPacked) {
1164 name_hbox.remove (name_entry);
1165 name_packing = NamePackingBits (name_packing & ~NameEntryPacked);
1170 TimeAxisView::color_handler ()
1172 for (list<GhostRegion*>::iterator i=ghosts.begin(); i != ghosts.end(); i++ ) {
1176 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_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();
1188 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
1190 (*i)->rect->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SelectionRect.get();
1191 (*i)->rect->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1193 (*i)->start_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1194 (*i)->start_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1196 (*i)->end_trim->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1197 (*i)->end_trim->property_outline_color_rgba() = ARDOUR_UI::config()->canvasvar_Selection.get();
1201 /** @return Pair: TimeAxisView, layer index.
1202 * TimeAxisView is non-0 if this object covers y, or one of its children does.
1203 * If the covering object is a child axis, then the child is returned.
1204 * TimeAxisView is 0 otherwise.
1205 * Layer index is the layer number if the TimeAxisView is valid and is in stacked
1206 * region display mode, otherwise 0.
1208 std::pair<TimeAxisView*, layer_t>
1209 TimeAxisView::covers_y_position (double y)
1212 return std::make_pair ( (TimeAxisView *) 0, 0);
1215 if (_y_position <= y && y < (_y_position + height)) {
1217 /* work out the layer index if appropriate */
1219 if (layer_display () == Stacked && view ()) {
1221 l = layer_t ((_y_position + height - y) / (view()->child_height ()));
1222 /* clamp to max layers to be on the safe side; sometimes the above calculation
1223 returns a too-high value */
1224 if (l >= view()->layers ()) {
1225 l = view()->layers() - 1;
1229 return std::make_pair (this, l);
1232 for (Children::const_iterator i = children.begin(); i != children.end(); ++i) {
1234 std::pair<TimeAxisView*, int> const r = (*i)->covers_y_position (y);
1240 return std::make_pair ( (TimeAxisView *) 0, 0);
1244 TimeAxisView::show_feature_lines (const AnalysisFeatureList& pos)
1246 analysis_features = pos;
1247 reshow_feature_lines ();
1252 TimeAxisView::hide_feature_lines ()
1254 list<ArdourCanvas::SimpleLine*>::iterator l;
1256 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1262 TimeAxisView::reshow_feature_lines ()
1264 while (feature_lines.size()< analysis_features.size()) {
1265 ArdourCanvas::SimpleLine* l = new ArdourCanvas::SimpleLine (*_canvas_display);
1266 l->property_color_rgba() = (guint) ARDOUR_UI::config()->canvasvar_ZeroLine.get();
1267 feature_lines.push_back (l);
1270 while (feature_lines.size() > analysis_features.size()) {
1271 ArdourCanvas::SimpleLine *line = feature_lines.back();
1272 feature_lines.pop_back ();
1276 AnalysisFeatureList::const_iterator i;
1277 list<ArdourCanvas::SimpleLine*>::iterator l;
1279 for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1280 (*l)->property_x1() = _editor.frame_to_pixel (*i);
1281 (*l)->property_x2() = _editor.frame_to_pixel (*i);
1282 (*l)->property_y1() = 0;
1283 (*l)->property_y2() = current_height();
1289 TimeAxisView::resizer_button_press (GdkEventButton* event)
1291 _resize_drag_start = event->y_root;
1296 TimeAxisView::resizer_button_release (GdkEventButton*)
1298 _resize_drag_start = -1;
1303 TimeAxisView::idle_resize (uint32_t h)
1309 TimeAxisView::resizer_motion (GdkEventMotion* ev)
1311 if (_resize_drag_start >= 0) {
1312 int32_t const delta = (int32_t) floor (ev->y_root - _resize_drag_start);
1313 _editor.add_to_idle_resize (this, delta);
1314 _resize_drag_start = ev->y_root;
1321 TimeAxisView::resizer_expose (GdkEventExpose* event)
1324 Glib::RefPtr<Gdk::Window> win (resizer.get_window());
1325 Glib::RefPtr<Gdk::GC> dark (resizer.get_style()->get_fg_gc (STATE_NORMAL));
1326 Glib::RefPtr<Gdk::GC> light (resizer.get_style()->get_bg_gc (STATE_NORMAL));
1328 win->draw_rectangle (controls_ebox.get_style()->get_bg_gc(STATE_NORMAL),
1333 event->area.height);
1335 win->get_geometry (x, y, w, h, d);
1337 /* handle/line #1 */
1339 win->draw_line (dark, 0, 0, w - 2, 0);
1340 win->draw_point (dark, 0, 1);
1341 win->draw_line (light, 1, 1, w - 1, 1);
1342 win->draw_point (light, w - 1, 0);
1344 /* handle/line #2 */
1346 win->draw_line (dark, 0, 4, w - 2, 4);
1347 win->draw_point (dark, 0, 5);
1348 win->draw_line (light, 1, 5, w - 1, 5);
1349 win->draw_point (light, w - 1, 4);
1351 /* handle/line #3 */
1353 win->draw_line (dark, 0, 8, w - 2, 8);
1354 win->draw_point (dark, 0, 9);
1355 win->draw_line (light, 1, 9, w - 1, 9);
1356 win->draw_point (light, w - 1, 8);
1358 /* use vertical resize mouse cursor */
1359 win->set_cursor(Gdk::Cursor(Gdk::SB_V_DOUBLE_ARROW));
1365 TimeAxisView::set_visibility (bool yn)
1367 if (yn != marked_for_display()) {
1369 set_marked_for_display (true);
1370 canvas_display()->show();
1372 set_marked_for_display (false);
1375 return true; // things changed