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