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