use scroll handling instead of button 4/5 (incomplete)
[ardour.git] / gtk2_ardour / time_axis_view.cc
1 /*
2     Copyright (C) 2000 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #include <cstdlib>
22 #include <cmath>
23 #include <algorithm>
24 #include <string>
25 #include <list>
26
27 #include <libgnomecanvasmm/libgnomecanvasmm.h>
28 #include <libgnomecanvasmm/canvas.h>
29 #include <libgnomecanvasmm/item.h>
30
31 #include <pbd/error.h>
32
33 #include <gtkmm2ext/utils.h>
34 #include <gtkmm2ext/selector.h>
35 #include <gtkmm2ext/stop_signal.h>
36
37 #include <ardour/session.h>
38 #include <ardour/utils.h>
39 #include <ardour/ladspa_plugin.h>
40 #include <ardour/insert.h>
41 #include <ardour/location.h>
42
43 #include "ardour_ui.h"
44 #include "public_editor.h"
45 #include "time_axis_view.h"
46 #include "simplerect.h"
47 #include "selection.h"
48 #include "keyboard.h"
49 #include "rgb_macros.h"
50 #include "utils.h"
51
52 #include "i18n.h"
53
54 using namespace Gtk;
55 using namespace Gdk;
56 using namespace sigc; 
57 using namespace ARDOUR;
58 using namespace Editing;
59 using namespace ArdourCanvas;
60
61 const double trim_handle_size = 6.0; /* pixels */
62
63 TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Canvas& canvas) 
64         : AxisView (sess), 
65           editor (ed),
66           controls_table (2, 9)
67 {
68         canvas_display = new Group (*canvas.root(), 0.0, 0.0);
69         
70         selection_group = new Group (*canvas_display);
71         selection_group->hide();
72         
73         control_parent = 0;
74         display_menu = 0;
75         size_menu = 0;
76         _marked_for_display = false;
77         _hidden = false;
78         height = 0;
79         effective_height = 0;
80         parent = rent;
81         _has_state = false;
82         last_name_entry_key_press_event = 0;
83
84         /*
85           Create the standard LHS Controls
86           We create the top-level container and name add the name label here,
87           subclasses can add to the layout as required
88         */
89
90         name_entry.set_name ("EditorTrackNameDisplay");
91         name_entry.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::name_entry_button_release));
92         name_entry.signal_button_press_event().connect (mem_fun (*this, &TimeAxisView::name_entry_button_press));
93         name_entry.signal_key_release_event().connect (mem_fun (*this, &TimeAxisView::name_entry_key_release));
94         name_entry.signal_activate().connect (mem_fun(*this, &TimeAxisView::name_entry_activated));
95         name_entry.signal_focus_in_event().connect (mem_fun (*this, &TimeAxisView::name_entry_focus_in));
96         name_entry.signal_focus_out_event().connect (mem_fun (*this, &TimeAxisView::name_entry_focus_out));
97         Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
98
99         name_label.set_name ("TrackLabel");
100         name_label.set_alignment (0.0, 0.5);
101
102         // name_hbox.set_border_width (2);
103         // name_hbox.set_spacing (5);
104
105         /* typically, either name_label OR name_entry are visible,
106            but not both. its up to derived classes to show/hide them as they
107            wish.
108         */
109
110         name_hbox.pack_start (name_label, true, true);
111         name_hbox.pack_start (name_entry, true, true);
112         name_hbox.show ();
113
114         controls_table.set_border_width (2);
115         controls_table.set_row_spacings (0);
116         controls_table.set_col_spacings (0);
117         controls_table.set_homogeneous (true);
118         controls_table.show ();
119
120         controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
121
122         controls_table.show ();
123
124         controls_vbox.pack_start (controls_table, false, false);
125         controls_vbox.show ();
126
127         controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
128         controls_ebox.add (controls_vbox);
129         controls_ebox.add_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK|SCROLL_MASK);
130         controls_ebox.set_flags (CAN_FOCUS);
131
132         controls_ebox.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
133         controls_ebox.signal_scroll_event().connect (mem_fun (*this, &TimeAxisView::controls_ebox_scroll));
134
135         controls_lhs_pad.set_name ("TimeAxisViewControlsPadding");
136         controls_hbox.pack_start (controls_lhs_pad,false,false);
137         controls_hbox.pack_start (controls_ebox,true,true);
138         controls_hbox.show ();
139
140         controls_frame.add (controls_hbox);
141         controls_frame.set_name ("TimeAxisViewControlsBaseUnselected");
142         controls_frame.set_shadow_type (Gtk::SHADOW_IN);
143 }
144
145 TimeAxisView::~TimeAxisView()
146 {
147         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
148                 delete *i;
149         }
150
151         for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
152                 delete (*i)->rect;
153                 delete (*i)->start_trim;
154                 delete (*i)->end_trim;
155
156         }
157
158         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
159                 delete (*i)->rect;
160                 delete (*i)->start_trim;
161                 delete (*i)->end_trim;
162         }
163
164         if (selection_group) {
165                 delete selection_group;
166                 selection_group = 0;
167         }
168
169         if (canvas_display) {
170                 delete canvas_display;
171                 canvas_display = 0;
172         }
173
174         if (display_menu) {
175                 delete display_menu;
176                 display_menu = 0;
177         }
178
179         if (size_menu) {
180                 delete size_menu;
181                 size_menu = 0;
182         }
183 }
184
185 guint32
186 TimeAxisView::show_at (double y, int& nth, VBox *parent)
187 {
188         gdouble ix1, ix2, iy1, iy2;
189         effective_height = 0;
190         
191         if (control_parent) {
192                 control_parent->reorder_child (controls_frame, nth);
193         } else {
194                 control_parent = parent;
195                 parent->pack_start (controls_frame, false, false);
196                 parent->reorder_child (controls_frame, nth);
197         }
198         controls_frame.show ();
199         controls_ebox.show ();
200         
201         /* the coordinates used here are in the system of the
202            item's parent ...
203         */
204
205         canvas_display->get_bounds (ix1, iy1, ix2, iy2);
206         Group* pg = canvas_display->property_parent();
207         pg->i2w (ix1, iy1);
208
209         if (iy1 < 0) {
210                 iy1 = 0;
211         }
212
213         canvas_display->move (0.0, y - iy1);
214         canvas_display->show();/* XXX not necessary */
215         y_position = y;
216         order = nth;
217         _hidden = false;
218         
219         effective_height = height;
220
221         /* now show children */
222         
223         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
224                 
225                 if ((*i)->marked_for_display()) {
226                         (*i)->canvas_display->show();
227                 }
228                 
229                 if (canvas_item_visible ((*i)->canvas_display)) {
230                         ++nth;
231                         effective_height += (*i)->show_at (y + effective_height, nth, parent);
232                 }
233         }
234
235         return effective_height;
236 }
237
238 bool
239 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
240 {
241         switch (ev->direction) {
242         case GDK_SCROLL_UP:
243                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
244                         step_height (true);
245                         return true;
246                 }
247                 break;
248                 
249         case GDK_SCROLL_DOWN:
250                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
251                         step_height (false);
252                         return true;
253                 }
254                 break;
255
256         default:
257                 /* no handling for left/right, yet */
258                 break;
259         }
260
261         return false;
262 }
263
264 bool
265 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
266 {
267         cerr << "controls ebox button release button " << ev->button << endl;
268
269         switch (ev->button) {
270         case 1:
271                 selection_click (ev);
272                 break;
273
274         case 3:
275                 popup_display_menu (ev->time);
276                 break;
277         }
278
279         return true;
280 }
281
282 void
283 TimeAxisView::selection_click (GdkEventButton* ev)
284 {
285         if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
286
287                 if (editor.get_selection().selected (this)) {
288                         editor.get_selection().remove (this);
289                 } else {
290                         editor.get_selection().add (this);
291                 }
292
293         } else {
294
295                 editor.get_selection().set (this);
296         }
297 }
298
299 void
300 TimeAxisView::hide ()
301 {
302         if (_hidden) {
303                 return;
304         }
305
306         canvas_display->hide();
307         controls_frame.hide ();
308
309         if (control_parent) {
310                 control_parent->remove (controls_frame);
311                 control_parent = 0;
312         }
313
314         y_position = -1;
315         _hidden = true;
316         
317         /* now hide children */
318         
319         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
320                 (*i)->hide ();
321         }
322         
323         Hiding ();
324 }
325
326 void
327 TimeAxisView::step_height (bool bigger)
328 {
329         switch (height) {
330         case Largest:
331                 if (!bigger) set_height (Large);
332                 break;
333         case Large:
334                 if (bigger) set_height (Largest);
335                 else set_height (Larger);
336                 break;
337         case Larger:
338                 if (bigger) set_height (Large);
339                 else set_height (Normal);
340                 break;
341         case Normal:
342                 if (bigger) set_height (Larger);
343                 else set_height (Smaller);
344                 break;
345         case Smaller:
346                 if (bigger) set_height (Normal);
347                 else set_height (Small);
348                 break;
349         case Small:
350                 if (bigger) set_height (Smaller);
351                 break;
352         }
353 }
354
355
356 void
357 TimeAxisView::set_height (TrackHeight h)
358 {
359         height = (guint32) h;
360         controls_frame.set_size_request (-1, height);
361
362         if (canvas_item_visible (selection_group)) {
363                 /* resize the selection rect */
364                 show_selection (editor.get_selection().time);
365         }
366
367 //      for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
368 //              (*i)->set_height (h);
369 //      }
370
371 }
372
373 bool
374 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
375 {
376         switch (ev->keyval) {
377         case GDK_Tab:
378         case GDK_Up:
379         case GDK_Down:
380                 name_entry_changed ();
381                 return true;
382
383         default:
384                 break;
385         }
386
387 #ifdef TIMEOUT_NAME_EDIT        
388         /* adapt the timeout to reflect the user's typing speed */
389
390         guint32 name_entry_timeout;
391
392         if (last_name_entry_key_press_event) {
393                 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
394                 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
395         } else {
396                 /* start with a 1 second timeout */
397                 name_entry_timeout = 1000;
398         }
399
400         last_name_entry_key_press_event = ev->time;
401
402         /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
403
404         name_entry_key_timeout.disconnect();
405         name_entry_key_timeout = Glib::signal_timeout().connect (mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
406 #endif
407
408         return false;
409 }
410
411 bool
412 TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
413 {
414         name_entry.select_region (0, -1);
415         name_entry.set_name ("EditorActiveTrackNameDisplay");
416         return false;
417 }
418
419 bool
420 TimeAxisView::name_entry_focus_out (GdkEventFocus* ev)
421 {
422         /* clean up */
423
424         last_name_entry_key_press_event = 0;
425         name_entry_key_timeout.disconnect ();
426         name_entry.set_name ("EditorTrackNameDisplay");
427         
428         /* do the real stuff */
429
430         name_entry_changed ();
431
432         return false;
433 }
434
435 bool
436 TimeAxisView::name_entry_key_timed_out ()
437 {
438         name_entry_activated();
439         return false;
440 }
441
442 void
443 TimeAxisView::name_entry_activated ()
444 {
445         controls_ebox.grab_focus();
446 }
447
448 void
449 TimeAxisView::name_entry_changed ()
450 {
451 }
452
453 bool
454 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
455 {
456         if (ev->button == 3) {
457                 return true;
458         }
459         return false;
460 }
461
462 bool
463 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
464 {
465         if (ev->button == 3) {
466                 popup_display_menu (ev->time);
467                 return true;
468         }
469         return false;
470 }
471
472 void
473 TimeAxisView::popup_display_menu (guint32 when)
474 {
475         if (display_menu == 0) {
476                 build_display_menu ();
477         }
478         display_menu->popup (1, when);  
479 }
480
481 gint
482 TimeAxisView::size_click (GdkEventButton *ev)
483 {
484         popup_size_menu (ev->time);
485         return TRUE;
486 }
487
488 void
489 TimeAxisView::popup_size_menu (guint32 when)
490 {
491         if (size_menu == 0) {
492                 build_size_menu ();
493         }
494         size_menu->popup (1, when);
495 }
496
497 void
498 TimeAxisView::set_selected (bool yn)
499 {
500         AxisView::set_selected (yn);
501
502         if (_selected) {
503                 controls_ebox.set_name (controls_base_selected_name);
504                 controls_frame.set_name (controls_base_selected_name);
505
506                 /* propagate any existing selection, if the mode is right */
507
508                 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
509                         show_selection (editor.get_selection().time);
510                 }
511
512         } else {
513                 controls_ebox.set_name (controls_base_unselected_name);
514                 controls_frame.set_name (controls_base_unselected_name);
515
516                 hide_selection ();
517
518                 /* children will be set for the yn=true case. but when deselecting
519                    the editor only has a list of top-level trackviews, so we
520                    have to do this here.
521                 */
522
523                 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
524                         (*i)->set_selected (false);
525                 }
526
527                 
528         }
529 }
530
531 void
532 TimeAxisView::build_size_menu ()
533 {
534         using namespace Menu_Helpers;
535
536         size_menu = new Menu;
537         size_menu->set_name ("ArdourContextMenu");
538         MenuList& items = size_menu->items();
539         
540         items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
541         items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
542         items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
543         items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
544         items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height), Smaller)));
545         items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
546 }
547
548 void
549 TimeAxisView::build_display_menu ()
550 {
551         using namespace Menu_Helpers;
552
553         display_menu = new Menu;
554         display_menu->set_name ("ArdourContextMenu");
555
556         // Just let implementing classes define what goes into the manu
557 }
558
559 void
560 TimeAxisView::set_samples_per_unit (double spu)
561 {
562         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
563                 (*i)->set_samples_per_unit (spu);
564         }
565 }
566
567 void
568 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
569 {
570         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
571                 (*i)->show_timestretch (start, end);
572         }
573 }
574
575 void
576 TimeAxisView::hide_timestretch ()
577 {
578         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
579                 (*i)->hide_timestretch ();
580         }
581 }
582
583 void
584 TimeAxisView::show_selection (TimeSelection& ts)
585 {
586         double x1;
587         double x2;
588         double y2;
589         SelectionRect *rect;
590
591         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
592                 (*i)->show_selection (ts);
593         }
594
595         if (canvas_item_visible (selection_group)) {
596                 while (!used_selection_rects.empty()) {
597                         free_selection_rects.push_front (used_selection_rects.front());
598                         used_selection_rects.pop_front();
599                         free_selection_rects.front()->rect->hide();
600                         free_selection_rects.front()->start_trim->hide();
601                         free_selection_rects.front()->end_trim->hide();
602                 }
603                 selection_group->hide();
604         }
605
606         selection_group->show();
607         selection_group->raise_to_top();
608         
609         for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
610                 jack_nframes_t start, end, cnt;
611
612                 start = (*i).start;
613                 end = (*i).end;
614                 cnt = end - start + 1;
615
616                 rect = get_selection_rect ((*i).id);
617                 
618                 x1 = start / editor.get_current_zoom();
619                 x2 = (start + cnt - 1) / editor.get_current_zoom();
620                 y2 = height;
621
622                 rect->rect->property_x1() = x1;
623                 rect->rect->property_y1() = 1.0;
624                 rect->rect->property_x2() = x2;
625                 rect->rect->property_y2() = y2;
626                 
627                 // trim boxes are at the top for selections
628                 
629                 if (x2 > x1) {
630                         rect->start_trim->property_x1() = x1;
631                         rect->start_trim->property_y1() = 1.0;
632                         rect->start_trim->property_x2() = x1 + trim_handle_size;
633                         rect->start_trim->property_y2() = 1.0 + trim_handle_size;
634
635                         rect->end_trim->property_x1() = x2 - trim_handle_size;
636                         rect->end_trim->property_y1() = 1.0;
637                         rect->end_trim->property_x2() = x2;
638                         rect->end_trim->property_y2() = 1.0 + trim_handle_size;
639
640                         rect->start_trim->show();
641                         rect->end_trim->show();
642                 } else {
643                         rect->start_trim->hide();
644                         rect->end_trim->hide();
645                 }
646
647                 rect->rect->show ();
648                 used_selection_rects.push_back (rect);
649         }
650 }
651
652 void
653 TimeAxisView::reshow_selection (TimeSelection& ts)
654 {
655         show_selection (ts);
656
657         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
658                 (*i)->show_selection (ts);
659         }
660 }
661
662 void
663 TimeAxisView::hide_selection ()
664 {
665         if (canvas_item_visible (selection_group)) {
666                 while (!used_selection_rects.empty()) {
667                         free_selection_rects.push_front (used_selection_rects.front());
668                         used_selection_rects.pop_front();
669                         free_selection_rects.front()->rect->hide();
670                         free_selection_rects.front()->start_trim->hide();
671                         free_selection_rects.front()->end_trim->hide();
672                 }
673                 selection_group->hide();
674         }
675         
676         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
677                 (*i)->hide_selection ();
678         }
679 }
680
681 void
682 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
683 {
684         /* find the selection rect this is for. we have the item corresponding to one
685            of the trim handles.
686          */
687
688         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
689                 if ((*i)->start_trim == item || (*i)->end_trim == item) {
690                         
691                         /* make one trim handle be "above" the other so that if they overlap,
692                            the top one is the one last used.
693                         */
694                         
695                         (*i)->rect->raise_to_top ();
696                         (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
697                         (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
698                         
699                         break;
700                 }
701         }
702 }
703
704 SelectionRect *
705 TimeAxisView::get_selection_rect (uint32_t id)
706 {
707         SelectionRect *rect;
708
709         /* check to see if we already have a visible rect for this particular selection ID */
710
711         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
712                 if ((*i)->id == id) {
713                         return (*i);
714                 }
715         }
716
717         /* ditto for the free rect list */
718
719         for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
720                 if ((*i)->id == id) {
721                         free_selection_rects.erase (i);
722                         return (*i);
723                 }
724         }
725
726         /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
727         
728         if (free_selection_rects.empty()) {
729
730                 rect = new SelectionRect;
731
732                 rect->rect = new SimpleRect (*selection_group);
733                 rect->rect->property_x1() = 0.0;
734                 rect->rect->property_y1() = 0.0;
735                 rect->rect->property_x2() = 0.0;
736                 rect->rect->property_y2() = 0.0;
737                 rect->rect->property_fill_color_rgba() = color_map[cSelectionRectFill];
738                 rect->rect->property_outline_color_rgba() = color_map[cSelectionRectOutline];
739                 
740                 rect->start_trim = new SimpleRect (*selection_group);
741                 rect->start_trim->property_x1() = 0.0;
742                 rect->start_trim->property_x2() = 0.0;
743                 rect->start_trim->property_fill_color_rgba() = color_map[cSelectionStartFill];
744                 rect->start_trim->property_outline_color_rgba() = color_map[cSelectionStartOutline];
745                 
746                 rect->end_trim = new SimpleRect (*selection_group);
747                 rect->end_trim->property_x1() = 0.0;
748                 rect->end_trim->property_x2() = 0.0;
749                 rect->end_trim->property_fill_color_rgba() = color_map[cSelectionEndFill];
750                 rect->end_trim->property_outline_color_rgba() = color_map[cSelectionEndOutline];
751
752                 free_selection_rects.push_front (rect);
753
754                 rect->rect->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
755                 rect->start_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
756                 rect->end_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
757         } 
758
759         rect = free_selection_rects.front();
760         rect->id = id;
761         free_selection_rects.pop_front();
762         return rect;
763 }
764
765 bool
766 TimeAxisView::is_child (TimeAxisView* tav)
767 {
768         return find (children.begin(), children.end(), tav) != children.end();
769 }
770
771 void
772 TimeAxisView::add_child (TimeAxisView* child)
773 {
774         children.push_back (child);
775 }
776
777 void
778 TimeAxisView::remove_child (TimeAxisView* child)
779 {
780         vector<TimeAxisView*>::iterator i;
781
782         if ((i = find (children.begin(), children.end(), child)) != children.end()) {
783                 children.erase (i);
784         }
785 }
786
787 void
788 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
789 {
790         return;
791 }
792
793 void
794 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
795 {
796         return;
797 }
798
799 bool
800 TimeAxisView::touched (double top, double bot)
801 {
802         /* remember: this is X Window - coordinate space starts in upper left and moves down.
803            y_position is the "origin" or "top" of the track.
804          */
805
806         double mybot = y_position + height; // XXX need to include Editor::track_spacing; 
807         
808         return ((y_position <= bot && y_position >= top) || 
809                 ((mybot <= bot) && (top < mybot)) || 
810                 (mybot >= bot && y_position < top));
811 }               
812
813 void
814 TimeAxisView::set_parent (TimeAxisView& p)
815 {
816         parent = &p;
817 }
818
819 bool
820 TimeAxisView::has_state () const
821 {
822         return _has_state;
823 }
824
825 TimeAxisView*
826 TimeAxisView::get_parent_with_state ()
827 {
828         if (parent == 0) {
829                 return 0;
830         }
831
832         if (parent->has_state()) {
833                 return parent;
834         } 
835
836         return parent->get_parent_with_state ();
837 }               
838
839 void
840 TimeAxisView::set_state (const XMLNode& node)
841 {
842         const XMLProperty *prop;
843
844         if ((prop = node.property ("track_height")) != 0) {
845
846                 if (prop->value() == "largest") {
847                         set_height (Largest);
848                 } else if (prop->value() == "large") {
849                         set_height (Large);
850                 } else if (prop->value() == "larger") {
851                         set_height (Larger);
852                 } else if (prop->value() == "normal") {
853                         set_height (Normal);
854                 } else if (prop->value() == "smaller") {
855                         set_height (Smaller);
856                 } else if (prop->value() == "small") {
857                         set_height (Small);
858                 } else {
859                         error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
860                         set_height (Normal);
861                 }
862
863         } else {
864                 set_height (Normal);
865         }
866 }
867
868 void
869 TimeAxisView::reset_height()
870 {
871         set_height ((TrackHeight) height);
872
873         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
874                 (*i)->set_height ((TrackHeight)(*i)->height);
875         }
876 }
877