make F11 take us fullscreen (bug remains in edit pane position restore); reduce track...
[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 uint32_t TimeAxisView::hLargest = 0;
64 uint32_t TimeAxisView::hLarge = 0;
65 uint32_t TimeAxisView::hLarger = 0;
66 uint32_t TimeAxisView::hNormal = 0;
67 uint32_t TimeAxisView::hSmaller = 0;
68 uint32_t TimeAxisView::hSmall = 0;
69 bool TimeAxisView::need_size_info = true;
70
71 TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Canvas& canvas) 
72         : AxisView (sess), 
73           editor (ed),
74           controls_table (2, 8)
75 {
76         if (need_size_info) {
77                 compute_controls_size_info ();
78                 need_size_info = false;
79         }
80
81         canvas_display = new Group (*canvas.root(), 0.0, 0.0);
82         
83         selection_group = new Group (*canvas_display);
84         selection_group->hide();
85         
86         control_parent = 0;
87         display_menu = 0;
88         size_menu = 0;
89         _marked_for_display = false;
90         _hidden = false;
91         height = 0;
92         effective_height = 0;
93         parent = rent;
94         _has_state = false;
95         last_name_entry_key_press_event = 0;
96         name_packing = NamePackingBits (0);
97
98         /*
99           Create the standard LHS Controls
100           We create the top-level container and name add the name label here,
101           subclasses can add to the layout as required
102         */
103
104         name_entry.set_name ("EditorTrackNameDisplay");
105         name_entry.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::name_entry_button_release));
106         name_entry.signal_button_press_event().connect (mem_fun (*this, &TimeAxisView::name_entry_button_press));
107         name_entry.signal_key_release_event().connect (mem_fun (*this, &TimeAxisView::name_entry_key_release));
108         name_entry.signal_activate().connect (mem_fun(*this, &TimeAxisView::name_entry_activated));
109         name_entry.signal_focus_in_event().connect (mem_fun (*this, &TimeAxisView::name_entry_focus_in));
110         name_entry.signal_focus_out_event().connect (mem_fun (*this, &TimeAxisView::name_entry_focus_out));
111         Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
112
113         name_label.set_name ("TrackLabel");
114         name_label.set_alignment (0.0, 0.5);
115
116         /* typically, either name_label OR name_entry are visible,
117            but not both. its up to derived classes to show/hide them as they
118            wish.
119         */
120
121         name_hbox.show ();
122
123         controls_table.set_border_width (2);
124         controls_table.set_row_spacings (0);
125         controls_table.set_col_spacings (0);
126         controls_table.set_homogeneous (true);
127
128         controls_table.attach (name_hbox, 0, 4, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
129         controls_table.show_all ();
130
131         controls_vbox.pack_start (controls_table, false, false);
132         controls_vbox.show ();
133
134         controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
135         controls_ebox.add (controls_vbox);
136         controls_ebox.add_events (BUTTON_PRESS_MASK|BUTTON_RELEASE_MASK|SCROLL_MASK);
137         controls_ebox.set_flags (CAN_FOCUS);
138
139         controls_ebox.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
140         controls_ebox.signal_scroll_event().connect (mem_fun (*this, &TimeAxisView::controls_ebox_scroll), true);
141
142         controls_lhs_pad.set_name ("TimeAxisViewControlsPadding");
143         controls_hbox.pack_start (controls_lhs_pad,false,false);
144         controls_hbox.pack_start (controls_ebox,true,true);
145         controls_hbox.show ();
146
147         controls_frame.add (controls_hbox);
148         controls_frame.set_name ("TimeAxisViewControlsBaseUnselected");
149         controls_frame.set_shadow_type (Gtk::SHADOW_OUT);
150 }
151
152 TimeAxisView::~TimeAxisView()
153 {
154         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
155                 delete *i;
156         }
157
158         for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
159                 delete (*i)->rect;
160                 delete (*i)->start_trim;
161                 delete (*i)->end_trim;
162
163         }
164
165         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
166                 delete (*i)->rect;
167                 delete (*i)->start_trim;
168                 delete (*i)->end_trim;
169         }
170
171         if (selection_group) {
172                 delete selection_group;
173                 selection_group = 0;
174         }
175
176         if (canvas_display) {
177                 delete canvas_display;
178                 canvas_display = 0;
179         }
180
181         if (display_menu) {
182                 delete display_menu;
183                 display_menu = 0;
184         }
185 }
186
187 guint32
188 TimeAxisView::show_at (double y, int& nth, VBox *parent)
189 {
190         gdouble ix1, ix2, iy1, iy2;
191         effective_height = 0;
192         
193         if (control_parent) {
194                 control_parent->reorder_child (controls_frame, nth);
195         } else {
196                 control_parent = parent;
197                 parent->pack_start (controls_frame, false, false);
198                 parent->reorder_child (controls_frame, nth);
199         }
200         controls_frame.show ();
201         controls_ebox.show ();
202         
203         /* the coordinates used here are in the system of the
204            item's parent ...
205         */
206
207         canvas_display->get_bounds (ix1, iy1, ix2, iy2);
208         Group* pg = canvas_display->property_parent();
209         pg->i2w (ix1, iy1);
210
211         if (iy1 < 0) {
212                 iy1 = 0;
213         }
214
215         canvas_display->move (0.0, y - iy1);
216         canvas_display->show();/* XXX not necessary */
217         y_position = y;
218         order = nth;
219         _hidden = false;
220         
221         effective_height = height;
222
223         /* now show children */
224         
225         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
226                 
227                 if ((*i)->marked_for_display()) {
228                         (*i)->canvas_display->show();
229                 }
230                 
231                 if (canvas_item_visible ((*i)->canvas_display)) {
232                         ++nth;
233                         effective_height += (*i)->show_at (y + effective_height, nth, parent);
234                 }
235         }
236
237         return effective_height;
238 }
239
240 bool
241 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
242 {
243         switch (ev->direction) {
244         case GDK_SCROLL_UP:
245                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
246                         step_height (true);
247                         return true;
248                 }
249                 break;
250                 
251         case GDK_SCROLL_DOWN:
252                 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
253                         step_height (false);
254                         return true;
255                 }
256                 break;
257
258         default:
259                 /* no handling for left/right, yet */
260                 break;
261         }
262
263         return false;
264 }
265
266 bool
267 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
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 void
356 TimeAxisView::set_height (TrackHeight h)
357 {
358         height_style = h;
359         set_height_pixels (height_to_pixels (h));
360 }
361
362 void
363 TimeAxisView::set_height_pixels (uint32_t h)
364 {
365         height = h;
366         controls_frame.set_size_request (-1, height);
367
368         if (canvas_item_visible (selection_group)) {
369                 /* resize the selection rect */
370                 show_selection (editor.get_selection().time);
371         }
372 }
373
374 bool
375 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
376 {
377         switch (ev->keyval) {
378         case GDK_Tab:
379         case GDK_Up:
380         case GDK_Down:
381                 name_entry_changed ();
382                 return true;
383
384         default:
385                 break;
386         }
387
388 #ifdef TIMEOUT_NAME_EDIT        
389         /* adapt the timeout to reflect the user's typing speed */
390
391         guint32 name_entry_timeout;
392
393         if (last_name_entry_key_press_event) {
394                 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
395                 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
396         } else {
397                 /* start with a 1 second timeout */
398                 name_entry_timeout = 1000;
399         }
400
401         last_name_entry_key_press_event = ev->time;
402
403         /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
404
405         name_entry_key_timeout.disconnect();
406         name_entry_key_timeout = Glib::signal_timeout().connect (mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
407 #endif
408
409         return false;
410 }
411
412 bool
413 TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
414 {
415         name_entry.select_region (0, -1);
416         name_entry.set_name ("EditorActiveTrackNameDisplay");
417         return false;
418 }
419
420 bool
421 TimeAxisView::name_entry_focus_out (GdkEventFocus* ev)
422 {
423         /* clean up */
424
425         last_name_entry_key_press_event = 0;
426         name_entry_key_timeout.disconnect ();
427         name_entry.set_name ("EditorTrackNameDisplay");
428         
429         /* do the real stuff */
430
431         name_entry_changed ();
432
433         return false;
434 }
435
436 bool
437 TimeAxisView::name_entry_key_timed_out ()
438 {
439         name_entry_activated();
440         return false;
441 }
442
443 void
444 TimeAxisView::name_entry_activated ()
445 {
446         controls_ebox.grab_focus();
447 }
448
449 void
450 TimeAxisView::name_entry_changed ()
451 {
452 }
453
454 bool
455 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
456 {
457         if (ev->button == 3) {
458                 return true;
459         }
460         return false;
461 }
462
463 bool
464 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
465 {
466         if (ev->button == 3) {
467                 popup_display_menu (ev->time);
468                 return true;
469         }
470         return false;
471 }
472
473 void
474 TimeAxisView::popup_display_menu (guint32 when)
475 {
476         if (display_menu == 0) {
477                 build_display_menu ();
478         }
479         display_menu->popup (1, when);  
480 }
481
482 gint
483 TimeAxisView::size_click (GdkEventButton *ev)
484 {
485         popup_size_menu (ev->time);
486         return TRUE;
487 }
488
489 void
490 TimeAxisView::popup_size_menu (guint32 when)
491 {
492         if (size_menu == 0) {
493                 build_size_menu ();
494         }
495         size_menu->popup (1, when);
496 }
497
498 void
499 TimeAxisView::set_selected (bool yn)
500 {
501         AxisView::set_selected (yn);
502
503         if (_selected) {
504                 controls_ebox.set_name (controls_base_selected_name);
505                 controls_frame.set_name (controls_base_selected_name);
506
507                 /* propagate any existing selection, if the mode is right */
508
509                 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
510                         show_selection (editor.get_selection().time);
511                 }
512
513         } else {
514                 controls_ebox.set_name (controls_base_unselected_name);
515                 controls_frame.set_name (controls_base_unselected_name);
516
517                 hide_selection ();
518
519                 /* children will be set for the yn=true case. but when deselecting
520                    the editor only has a list of top-level trackviews, so we
521                    have to do this here.
522                 */
523
524                 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
525                         (*i)->set_selected (false);
526                 }
527
528                 
529         }
530 }
531
532 void
533 TimeAxisView::build_size_menu ()
534 {
535         using namespace Menu_Helpers;
536
537         size_menu = new Menu;
538         size_menu->set_name ("ArdourContextMenu");
539         MenuList& items = size_menu->items();
540         
541         items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
542         items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
543         items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
544         items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
545         items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height),Smaller)));
546         items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
547 }
548
549 void
550 TimeAxisView::build_display_menu ()
551 {
552         using namespace Menu_Helpers;
553
554         display_menu = new Menu;
555         display_menu->set_name ("ArdourContextMenu");
556
557         // Just let implementing classes define what goes into the manu
558 }
559
560 void
561 TimeAxisView::set_samples_per_unit (double spu)
562 {
563         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
564                 (*i)->set_samples_per_unit (spu);
565         }
566 }
567
568 void
569 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
570 {
571         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
572                 (*i)->show_timestretch (start, end);
573         }
574 }
575
576 void
577 TimeAxisView::hide_timestretch ()
578 {
579         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
580                 (*i)->hide_timestretch ();
581         }
582 }
583
584 void
585 TimeAxisView::show_selection (TimeSelection& ts)
586 {
587         double x1;
588         double x2;
589         double y2;
590         SelectionRect *rect;
591
592         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
593                 (*i)->show_selection (ts);
594         }
595
596         if (canvas_item_visible (selection_group)) {
597                 while (!used_selection_rects.empty()) {
598                         free_selection_rects.push_front (used_selection_rects.front());
599                         used_selection_rects.pop_front();
600                         free_selection_rects.front()->rect->hide();
601                         free_selection_rects.front()->start_trim->hide();
602                         free_selection_rects.front()->end_trim->hide();
603                 }
604                 selection_group->hide();
605         }
606
607         selection_group->show();
608         selection_group->raise_to_top();
609         
610         for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
611                 jack_nframes_t start, end, cnt;
612
613                 start = (*i).start;
614                 end = (*i).end;
615                 cnt = end - start + 1;
616
617                 rect = get_selection_rect ((*i).id);
618                 
619                 x1 = start / editor.get_current_zoom();
620                 x2 = (start + cnt - 1) / editor.get_current_zoom();
621                 y2 = height;
622
623                 rect->rect->property_x1() = x1;
624                 rect->rect->property_y1() = 1.0;
625                 rect->rect->property_x2() = x2;
626                 rect->rect->property_y2() = y2;
627                 
628                 // trim boxes are at the top for selections
629                 
630                 if (x2 > x1) {
631                         rect->start_trim->property_x1() = x1;
632                         rect->start_trim->property_y1() = 1.0;
633                         rect->start_trim->property_x2() = x1 + trim_handle_size;
634                         rect->start_trim->property_y2() = 1.0 + trim_handle_size;
635
636                         rect->end_trim->property_x1() = x2 - trim_handle_size;
637                         rect->end_trim->property_y1() = 1.0;
638                         rect->end_trim->property_x2() = x2;
639                         rect->end_trim->property_y2() = 1.0 + trim_handle_size;
640
641                         rect->start_trim->show();
642                         rect->end_trim->show();
643                 } else {
644                         rect->start_trim->hide();
645                         rect->end_trim->hide();
646                 }
647
648                 rect->rect->show ();
649                 used_selection_rects.push_back (rect);
650         }
651 }
652
653 void
654 TimeAxisView::reshow_selection (TimeSelection& ts)
655 {
656         show_selection (ts);
657
658         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
659                 (*i)->show_selection (ts);
660         }
661 }
662
663 void
664 TimeAxisView::hide_selection ()
665 {
666         if (canvas_item_visible (selection_group)) {
667                 while (!used_selection_rects.empty()) {
668                         free_selection_rects.push_front (used_selection_rects.front());
669                         used_selection_rects.pop_front();
670                         free_selection_rects.front()->rect->hide();
671                         free_selection_rects.front()->start_trim->hide();
672                         free_selection_rects.front()->end_trim->hide();
673                 }
674                 selection_group->hide();
675         }
676         
677         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
678                 (*i)->hide_selection ();
679         }
680 }
681
682 void
683 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
684 {
685         /* find the selection rect this is for. we have the item corresponding to one
686            of the trim handles.
687          */
688
689         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
690                 if ((*i)->start_trim == item || (*i)->end_trim == item) {
691                         
692                         /* make one trim handle be "above" the other so that if they overlap,
693                            the top one is the one last used.
694                         */
695                         
696                         (*i)->rect->raise_to_top ();
697                         (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
698                         (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
699                         
700                         break;
701                 }
702         }
703 }
704
705 SelectionRect *
706 TimeAxisView::get_selection_rect (uint32_t id)
707 {
708         SelectionRect *rect;
709
710         /* check to see if we already have a visible rect for this particular selection ID */
711
712         for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
713                 if ((*i)->id == id) {
714                         return (*i);
715                 }
716         }
717
718         /* ditto for the free rect list */
719
720         for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
721                 if ((*i)->id == id) {
722                         free_selection_rects.erase (i);
723                         return (*i);
724                 }
725         }
726
727         /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
728         
729         if (free_selection_rects.empty()) {
730
731                 rect = new SelectionRect;
732
733                 rect->rect = new SimpleRect (*selection_group);
734                 rect->rect->property_x1() = 0.0;
735                 rect->rect->property_y1() = 0.0;
736                 rect->rect->property_x2() = 0.0;
737                 rect->rect->property_y2() = 0.0;
738                 rect->rect->property_fill_color_rgba() = color_map[cSelectionRectFill];
739                 rect->rect->property_outline_color_rgba() = color_map[cSelectionRectOutline];
740                 
741                 rect->start_trim = new SimpleRect (*selection_group);
742                 rect->start_trim->property_x1() = 0.0;
743                 rect->start_trim->property_x2() = 0.0;
744                 rect->start_trim->property_fill_color_rgba() = color_map[cSelectionStartFill];
745                 rect->start_trim->property_outline_color_rgba() = color_map[cSelectionStartOutline];
746                 
747                 rect->end_trim = new SimpleRect (*selection_group);
748                 rect->end_trim->property_x1() = 0.0;
749                 rect->end_trim->property_x2() = 0.0;
750                 rect->end_trim->property_fill_color_rgba() = color_map[cSelectionEndFill];
751                 rect->end_trim->property_outline_color_rgba() = color_map[cSelectionEndOutline];
752
753                 free_selection_rects.push_front (rect);
754
755                 rect->rect->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
756                 rect->start_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
757                 rect->end_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
758         } 
759
760         rect = free_selection_rects.front();
761         rect->id = id;
762         free_selection_rects.pop_front();
763         return rect;
764 }
765
766 bool
767 TimeAxisView::is_child (TimeAxisView* tav)
768 {
769         return find (children.begin(), children.end(), tav) != children.end();
770 }
771
772 void
773 TimeAxisView::add_child (TimeAxisView* child)
774 {
775         children.push_back (child);
776 }
777
778 void
779 TimeAxisView::remove_child (TimeAxisView* child)
780 {
781         vector<TimeAxisView*>::iterator i;
782
783         if ((i = find (children.begin(), children.end(), child)) != children.end()) {
784                 children.erase (i);
785         }
786 }
787
788 void
789 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
790 {
791         return;
792 }
793
794 void
795 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
796 {
797         return;
798 }
799
800 bool
801 TimeAxisView::touched (double top, double bot)
802 {
803         /* remember: this is X Window - coordinate space starts in upper left and moves down.
804            y_position is the "origin" or "top" of the track.
805          */
806
807         double mybot = y_position + height; // XXX need to include Editor::track_spacing; 
808         
809         return ((y_position <= bot && y_position >= top) || 
810                 ((mybot <= bot) && (top < mybot)) || 
811                 (mybot >= bot && y_position < top));
812 }               
813
814 void
815 TimeAxisView::set_parent (TimeAxisView& p)
816 {
817         parent = &p;
818 }
819
820 bool
821 TimeAxisView::has_state () const
822 {
823         return _has_state;
824 }
825
826 TimeAxisView*
827 TimeAxisView::get_parent_with_state ()
828 {
829         if (parent == 0) {
830                 return 0;
831         }
832
833         if (parent->has_state()) {
834                 return parent;
835         } 
836
837         return parent->get_parent_with_state ();
838 }               
839
840 void
841 TimeAxisView::set_state (const XMLNode& node)
842 {
843         const XMLProperty *prop;
844
845         if ((prop = node.property ("track_height")) != 0) {
846
847                 if (prop->value() == "largest") {
848                         set_height (Largest);
849                 } else if (prop->value() == "large") {
850                         set_height (Large);
851                 } else if (prop->value() == "larger") {
852                         set_height (Larger);
853                 } else if (prop->value() == "normal") {
854                         set_height (Normal);
855                 } else if (prop->value() == "smaller") {
856                         set_height (Smaller);
857                 } else if (prop->value() == "small") {
858                         set_height (Small);
859                 } else {
860                         error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
861                         set_height (Normal);
862                 }
863
864         } else {
865                 set_height (Normal);
866         }
867 }
868
869 void
870 TimeAxisView::reset_height()
871 {
872         set_height_pixels (height);
873
874         for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
875                 (*i)->set_height ((TrackHeight)(*i)->height);
876         }
877 }
878         
879 uint32_t
880 TimeAxisView::height_to_pixels (TrackHeight h)
881 {
882         switch (h) {
883         case Largest:
884                 return hLargest;
885         case Large:
886                 return hLarge;
887         case Larger:
888                 return hLarger;
889         case Normal:
890                 return hNormal;
891         case Smaller:
892                 return hSmaller;
893         case Small:
894                 return hSmall;
895         }
896         
897         // what is wrong with gcc ?
898         
899         return hNormal;
900 }
901                         
902 void
903 TimeAxisView::compute_controls_size_info ()
904 {
905         Gtk::Window window (Gtk::WINDOW_TOPLEVEL);
906         Gtk::Table two_row_table (2, 8);
907         Gtk::Table one_row_table (1, 8);
908         Button* buttons[5];
909
910         window.add (one_row_table);
911
912         one_row_table.set_border_width (2);
913         one_row_table.set_row_spacings (0);
914         one_row_table.set_col_spacings (0);
915         one_row_table.set_homogeneous (true);
916
917         two_row_table.set_border_width (2);
918         two_row_table.set_row_spacings (0);
919         two_row_table.set_col_spacings (0);
920         two_row_table.set_homogeneous (true);
921
922         for (int i = 0; i < 5; ++i) {
923                 buttons[i] = manage (new Button (X_("f")));
924                 buttons[i]->set_name ("TrackMuteButton");
925         }
926
927         Gtk::Requisition req;
928
929         one_row_table.attach (*buttons[0], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
930         
931         one_row_table.show_all ();
932         one_row_table.size_request (req);
933
934         // height required to show 1 row of buttons
935
936         hSmaller = req.height + 3;
937
938         window.remove ();
939         window.add (two_row_table);
940
941         two_row_table.attach (*buttons[1], 5, 6, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
942         two_row_table.attach (*buttons[2], 6, 7, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
943         two_row_table.attach (*buttons[3], 7, 8, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
944         two_row_table.attach (*buttons[4], 8, 9, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND, 0, 0);
945
946         two_row_table.show_all ();
947         two_row_table.size_request (req);
948
949         // height required to show all normal buttons
950
951         hNormal = req.height + 3;
952
953         // these heights are all just larger than normal. no more 
954         // elements are visible (yet).
955
956         hLarger = hNormal + 50;
957         hLarge = hNormal + 150;
958         hLargest = hNormal + 250;
959
960         // height required to show track name
961
962         hSmall = 27;
963 }
964
965 void
966 TimeAxisView::show_name_label ()
967 {
968         if (!(name_packing & NameLabelPacked)) {
969                 name_hbox.pack_start (name_label, true, true);
970                 name_packing = NamePackingBits (name_packing | NameLabelPacked);
971                 name_hbox.show ();
972                 name_label.show ();
973         }
974 }
975
976 void
977 TimeAxisView::show_name_entry ()
978 {
979         if (!(name_packing & NameEntryPacked)) {
980                 name_hbox.pack_start (name_entry, true, true);
981                 name_packing = NamePackingBits (name_packing | NameEntryPacked);
982                 name_hbox.show ();
983                 name_entry.show ();
984         }
985 }
986
987 void
988 TimeAxisView::hide_name_label ()
989 {
990         if (name_packing & NameLabelPacked) {
991                 name_hbox.remove (name_label);
992                 name_packing = NamePackingBits (name_packing & ~NameLabelPacked);
993         }
994 }
995
996 void
997 TimeAxisView::hide_name_entry ()
998 {
999         if (name_packing & NameEntryPacked) {
1000                 name_hbox.remove (name_entry);
1001                 name_packing = NamePackingBits (name_packing & ~NameEntryPacked);
1002         }
1003 }