2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <libgnomecanvasmm/libgnomecanvasmm.h>
28 #include <libgnomecanvasmm/canvas.h>
29 #include <libgnomecanvasmm/item.h>
31 #include <pbd/error.h>
33 #include <gtkmm2ext/utils.h>
34 #include <gtkmm2ext/selector.h>
35 #include <gtkmm2ext/stop_signal.h>
37 #include <ardour/session.h>
38 #include <ardour/utils.h>
39 #include <ardour/ladspa_plugin.h>
40 #include <ardour/insert.h>
41 #include <ardour/location.h>
43 #include "ardour_ui.h"
44 #include "public_editor.h"
45 #include "time_axis_view.h"
46 #include "simplerect.h"
47 #include "selection.h"
49 #include "rgb_macros.h"
57 using namespace ARDOUR;
58 using namespace Editing;
59 using namespace ArdourCanvas;
61 const double trim_handle_size = 6.0; /* pixels */
63 TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Canvas& canvas)
68 canvas_display = new Group (*canvas.root(), 0.0, 0.0);
70 selection_group = new Group (*canvas_display);
71 selection_group->hide();
76 _marked_for_display = false;
82 last_name_entry_key_press_event = 0;
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
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
99 name_label.set_name ("TrackLabel");
100 name_label.set_alignment (0.0, 0.5);
102 // name_hbox.set_border_width (2);
103 // name_hbox.set_spacing (5);
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
110 name_hbox.pack_start (name_label, true, true);
111 name_hbox.pack_start (name_entry, true, true);
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 ();
120 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
122 controls_table.show ();
124 controls_vbox.pack_start (controls_table, false, false);
125 controls_vbox.show ();
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);
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);
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 ();
140 controls_frame.add (controls_hbox);
141 controls_frame.set_name ("TimeAxisViewControlsBaseUnselected");
142 controls_frame.set_shadow_type (Gtk::SHADOW_OUT);
146 TimeAxisView::~TimeAxisView()
148 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
152 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
154 delete (*i)->start_trim;
155 delete (*i)->end_trim;
159 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
161 delete (*i)->start_trim;
162 delete (*i)->end_trim;
165 if (selection_group) {
166 delete selection_group;
170 if (canvas_display) {
171 delete canvas_display;
187 TimeAxisView::show_at (double y, int& nth, VBox *parent)
189 gdouble ix1, ix2, iy1, iy2;
190 effective_height = 0;
192 if (control_parent) {
193 control_parent->reorder_child (controls_frame, nth);
195 control_parent = parent;
196 parent->pack_start (controls_frame, false, false);
197 parent->reorder_child (controls_frame, nth);
199 controls_frame.show ();
200 controls_ebox.show ();
202 /* the coordinates used here are in the system of the
206 canvas_display->get_bounds (ix1, iy1, ix2, iy2);
207 Group* pg = canvas_display->property_parent();
214 canvas_display->move (0.0, y - iy1);
215 canvas_display->show();/* XXX not necessary */
220 effective_height = height;
222 /* now show children */
224 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
226 if ((*i)->marked_for_display()) {
227 (*i)->canvas_display->show();
230 if (canvas_item_visible ((*i)->canvas_display)) {
232 effective_height += (*i)->show_at (y + effective_height, nth, parent);
236 return effective_height;
240 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
242 switch (ev->direction) {
244 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
250 case GDK_SCROLL_DOWN:
251 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
258 /* no handling for left/right, yet */
266 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
268 switch (ev->button) {
270 selection_click (ev);
274 popup_display_menu (ev->time);
282 TimeAxisView::selection_click (GdkEventButton* ev)
284 if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
286 if (editor.get_selection().selected (this)) {
287 editor.get_selection().remove (this);
289 editor.get_selection().add (this);
294 editor.get_selection().set (this);
299 TimeAxisView::hide ()
305 canvas_display->hide();
306 controls_frame.hide ();
308 if (control_parent) {
309 control_parent->remove (controls_frame);
316 /* now hide children */
318 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
326 TimeAxisView::step_height (bool bigger)
330 if (!bigger) set_height (Large);
333 if (bigger) set_height (Largest);
334 else set_height (Larger);
337 if (bigger) set_height (Large);
338 else set_height (Normal);
341 if (bigger) set_height (Larger);
342 else set_height (Smaller);
345 if (bigger) set_height (Normal);
346 else set_height (Small);
349 if (bigger) set_height (Smaller);
355 TimeAxisView::set_height (TrackHeight h)
358 controls_frame.set_size_request (-1, height);
360 if (canvas_item_visible (selection_group)) {
361 /* resize the selection rect */
362 show_selection (editor.get_selection().time);
367 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
369 switch (ev->keyval) {
373 name_entry_changed ();
380 #ifdef TIMEOUT_NAME_EDIT
381 /* adapt the timeout to reflect the user's typing speed */
383 guint32 name_entry_timeout;
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)));
389 /* start with a 1 second timeout */
390 name_entry_timeout = 1000;
393 last_name_entry_key_press_event = ev->time;
395 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
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);
405 TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
407 name_entry.select_region (0, -1);
408 name_entry.set_name ("EditorActiveTrackNameDisplay");
413 TimeAxisView::name_entry_focus_out (GdkEventFocus* ev)
417 last_name_entry_key_press_event = 0;
418 name_entry_key_timeout.disconnect ();
419 name_entry.set_name ("EditorTrackNameDisplay");
421 /* do the real stuff */
423 name_entry_changed ();
429 TimeAxisView::name_entry_key_timed_out ()
431 name_entry_activated();
436 TimeAxisView::name_entry_activated ()
438 controls_ebox.grab_focus();
442 TimeAxisView::name_entry_changed ()
447 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
449 if (ev->button == 3) {
456 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
458 if (ev->button == 3) {
459 popup_display_menu (ev->time);
466 TimeAxisView::popup_display_menu (guint32 when)
468 if (display_menu == 0) {
469 build_display_menu ();
471 display_menu->popup (1, when);
475 TimeAxisView::size_click (GdkEventButton *ev)
477 popup_size_menu (ev->time);
482 TimeAxisView::popup_size_menu (guint32 when)
484 if (size_menu == 0) {
487 size_menu->popup (1, when);
491 TimeAxisView::set_selected (bool yn)
493 AxisView::set_selected (yn);
496 controls_ebox.set_name (controls_base_selected_name);
497 controls_frame.set_name (controls_base_selected_name);
499 /* propagate any existing selection, if the mode is right */
501 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
502 show_selection (editor.get_selection().time);
506 controls_ebox.set_name (controls_base_unselected_name);
507 controls_frame.set_name (controls_base_unselected_name);
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.
516 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
517 (*i)->set_selected (false);
525 TimeAxisView::build_size_menu ()
527 using namespace Menu_Helpers;
529 size_menu = new Menu;
530 size_menu->set_name ("ArdourContextMenu");
531 MenuList& items = size_menu->items();
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)));
542 TimeAxisView::build_display_menu ()
544 using namespace Menu_Helpers;
546 display_menu = new Menu;
547 display_menu->set_name ("ArdourContextMenu");
549 // Just let implementing classes define what goes into the manu
553 TimeAxisView::set_samples_per_unit (double spu)
555 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
556 (*i)->set_samples_per_unit (spu);
561 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
563 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
564 (*i)->show_timestretch (start, end);
569 TimeAxisView::hide_timestretch ()
571 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
572 (*i)->hide_timestretch ();
577 TimeAxisView::show_selection (TimeSelection& ts)
584 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
585 (*i)->show_selection (ts);
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();
596 selection_group->hide();
599 selection_group->show();
600 selection_group->raise_to_top();
602 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
603 jack_nframes_t start, end, cnt;
607 cnt = end - start + 1;
609 rect = get_selection_rect ((*i).id);
611 x1 = start / editor.get_current_zoom();
612 x2 = (start + cnt - 1) / editor.get_current_zoom();
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;
620 // trim boxes are at the top for selections
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;
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;
633 rect->start_trim->show();
634 rect->end_trim->show();
636 rect->start_trim->hide();
637 rect->end_trim->hide();
641 used_selection_rects.push_back (rect);
646 TimeAxisView::reshow_selection (TimeSelection& ts)
650 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
651 (*i)->show_selection (ts);
656 TimeAxisView::hide_selection ()
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();
666 selection_group->hide();
669 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
670 (*i)->hide_selection ();
675 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
677 /* find the selection rect this is for. we have the item corresponding to one
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) {
684 /* make one trim handle be "above" the other so that if they overlap,
685 the top one is the one last used.
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 ();
698 TimeAxisView::get_selection_rect (uint32_t id)
702 /* check to see if we already have a visible rect for this particular selection ID */
704 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
705 if ((*i)->id == id) {
710 /* ditto for the free rect list */
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);
719 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
721 if (free_selection_rects.empty()) {
723 rect = new SelectionRect;
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];
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];
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];
745 free_selection_rects.push_front (rect);
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));
752 rect = free_selection_rects.front();
754 free_selection_rects.pop_front();
759 TimeAxisView::is_child (TimeAxisView* tav)
761 return find (children.begin(), children.end(), tav) != children.end();
765 TimeAxisView::add_child (TimeAxisView* child)
767 children.push_back (child);
771 TimeAxisView::remove_child (TimeAxisView* child)
773 vector<TimeAxisView*>::iterator i;
775 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
781 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
787 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
793 TimeAxisView::touched (double top, double bot)
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.
799 double mybot = y_position + height; // XXX need to include Editor::track_spacing;
801 return ((y_position <= bot && y_position >= top) ||
802 ((mybot <= bot) && (top < mybot)) ||
803 (mybot >= bot && y_position < top));
807 TimeAxisView::set_parent (TimeAxisView& p)
813 TimeAxisView::has_state () const
819 TimeAxisView::get_parent_with_state ()
825 if (parent->has_state()) {
829 return parent->get_parent_with_state ();
833 TimeAxisView::set_state (const XMLNode& node)
835 const XMLProperty *prop;
837 if ((prop = node.property ("track_height")) != 0) {
839 if (prop->value() == "largest") {
840 set_height (Largest);
841 } else if (prop->value() == "large") {
843 } else if (prop->value() == "larger") {
845 } else if (prop->value() == "normal") {
847 } else if (prop->value() == "smaller") {
848 set_height (Smaller);
849 } else if (prop->value() == "small") {
852 error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
862 TimeAxisView::reset_height()
864 set_height ((TrackHeight) height);
866 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
867 (*i)->set_height ((TrackHeight)(*i)->height);
872 TimeAxisView::check_height (Gdk::Rectangle& r)