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"
56 using namespace ARDOUR;
57 using namespace Editing;
58 using namespace ArdourCanvas;
60 const double trim_handle_size = 6.0; /* pixels */
62 TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Canvas& canvas)
67 canvas_display = new Group (*canvas.root(), 0.0, 0.0);
69 selection_group = new Group (*canvas_display);
70 selection_group->hide();
75 _marked_for_display = false;
81 last_name_entry_key_press_event = 0;
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
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
98 name_label.set_name ("TrackLabel");
99 name_label.set_alignment (0.0, 0.5);
101 // name_hbox.set_border_width (2);
102 // name_hbox.set_spacing (5);
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
109 name_hbox.pack_start (name_label, true, true);
110 name_hbox.pack_start (name_entry, true, true);
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 ();
119 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
121 controls_table.show ();
123 controls_vbox.pack_start (controls_table, false, false);
124 controls_vbox.show ();
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);
131 controls_ebox.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
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 ();
138 controls_frame.add (controls_hbox);
139 controls_frame.set_name ("TimeAxisViewControlsBaseUnselected");
140 controls_frame.set_shadow_type (Gtk::SHADOW_OUT);
143 TimeAxisView::~TimeAxisView()
145 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
149 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
151 delete (*i)->start_trim;
152 delete (*i)->end_trim;
156 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
158 delete (*i)->start_trim;
159 delete (*i)->end_trim;
162 if (selection_group) {
163 delete selection_group;
167 if (canvas_display) {
168 delete canvas_display;
184 TimeAxisView::show_at (double y, int& nth, VBox *parent)
186 gdouble ix1, ix2, iy1, iy2;
187 effective_height = 0;
189 if (control_parent) {
190 control_parent->reorder_child (controls_frame, nth);
192 control_parent = parent;
193 parent->pack_start (controls_frame, false, false);
194 parent->reorder_child (controls_frame, nth);
197 controls_frame.show ();
198 controls_ebox.show ();
200 /* the coordinates used here are in the system of the
204 canvas_display->get_bounds (ix1, iy1, ix2, iy2);
205 Group* pg = canvas_display->property_parent();
212 canvas_display->move (0.0, y - iy1);
213 canvas_display->show();/* XXX not necessary */
218 effective_height = height;
220 /* now show children */
222 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
224 if ((*i)->marked_for_display()) {
225 (*i)->canvas_display->show();
228 if (canvas_item_visible ((*i)->canvas_display)) {
230 effective_height += (*i)->show_at (y + effective_height, nth, parent);
234 return effective_height;
238 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
240 switch (ev->button) {
242 selection_click (ev);
246 popup_display_menu (ev->time);
250 if (Keyboard::no_modifier_keys_pressed (ev)) {
251 editor.scroll_tracks_up_line ();
252 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
258 if (Keyboard::no_modifier_keys_pressed (ev)) {
259 editor.scroll_tracks_down_line ();
260 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
272 TimeAxisView::selection_click (GdkEventButton* ev)
274 if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
276 if (editor.get_selection().selected (this)) {
277 editor.get_selection().remove (this);
279 editor.get_selection().add (this);
284 editor.get_selection().set (this);
289 TimeAxisView::hide ()
295 canvas_display->hide();
296 controls_frame.hide ();
298 if (control_parent) {
299 control_parent->remove (controls_frame);
306 /* now hide children */
308 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
316 TimeAxisView::step_height (bool bigger)
320 if (!bigger) set_height (Large);
323 if (bigger) set_height (Largest);
324 else set_height (Larger);
327 if (bigger) set_height (Large);
328 else set_height (Normal);
331 if (bigger) set_height (Larger);
332 else set_height (Smaller);
335 if (bigger) set_height (Normal);
336 else set_height (Small);
339 if (bigger) set_height (Smaller);
346 TimeAxisView::set_height (TrackHeight h)
348 height = (guint32) h;
349 controls_frame.set_size_request (-1, height);
351 if (canvas_item_visible (selection_group)) {
352 /* resize the selection rect */
353 show_selection (editor.get_selection().time);
356 // for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
357 // (*i)->set_height (h);
363 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
365 switch (ev->keyval) {
369 name_entry_changed ();
376 #ifdef TIMEOUT_NAME_EDIT
377 /* adapt the timeout to reflect the user's typing speed */
379 guint32 name_entry_timeout;
381 if (last_name_entry_key_press_event) {
382 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
383 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
385 /* start with a 1 second timeout */
386 name_entry_timeout = 1000;
389 last_name_entry_key_press_event = ev->time;
391 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
393 name_entry_key_timeout.disconnect();
394 name_entry_key_timeout = Glib::signal_timeout().connect (mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
401 TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
403 name_entry.select_region (0, -1);
404 name_entry.set_name ("EditorActiveTrackNameDisplay");
409 TimeAxisView::name_entry_focus_out (GdkEventFocus* ev)
413 last_name_entry_key_press_event = 0;
414 name_entry_key_timeout.disconnect ();
415 name_entry.set_name ("EditorTrackNameDisplay");
417 /* do the real stuff */
419 name_entry_changed ();
425 TimeAxisView::name_entry_key_timed_out ()
427 name_entry_activated();
432 TimeAxisView::name_entry_activated ()
434 controls_ebox.grab_focus();
438 TimeAxisView::name_entry_changed ()
443 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
445 if (ev->button == 3) {
452 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
454 if (ev->button == 3) {
455 popup_display_menu (ev->time);
462 TimeAxisView::popup_display_menu (guint32 when)
464 if (display_menu == 0) {
465 build_display_menu ();
467 display_menu->popup (1, when);
471 TimeAxisView::size_click (GdkEventButton *ev)
473 popup_size_menu (ev->time);
478 TimeAxisView::popup_size_menu (guint32 when)
480 if (size_menu == 0) {
483 size_menu->popup (1, when);
487 TimeAxisView::set_selected (bool yn)
489 AxisView::set_selected (yn);
492 controls_ebox.set_name (controls_base_selected_name);
493 controls_frame.set_name (controls_base_selected_name);
495 /* propagate any existing selection, if the mode is right */
497 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
498 show_selection (editor.get_selection().time);
502 controls_ebox.set_name (controls_base_unselected_name);
503 controls_frame.set_name (controls_base_unselected_name);
507 /* children will be set for the yn=true case. but when deselecting
508 the editor only has a list of top-level trackviews, so we
509 have to do this here.
512 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
513 (*i)->set_selected (false);
521 TimeAxisView::build_size_menu ()
523 using namespace Menu_Helpers;
525 size_menu = new Menu;
526 size_menu->set_name ("ArdourContextMenu");
527 MenuList& items = size_menu->items();
529 items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
530 items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
531 items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
532 items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
533 items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height), Smaller)));
534 items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
538 TimeAxisView::build_display_menu ()
540 using namespace Menu_Helpers;
542 display_menu = new Menu;
543 display_menu->set_name ("ArdourContextMenu");
545 // Just let implementing classes define what goes into the manu
549 TimeAxisView::set_samples_per_unit (double spu)
551 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
552 (*i)->set_samples_per_unit (spu);
557 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
559 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
560 (*i)->show_timestretch (start, end);
565 TimeAxisView::hide_timestretch ()
567 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
568 (*i)->hide_timestretch ();
573 TimeAxisView::show_selection (TimeSelection& ts)
580 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
581 (*i)->show_selection (ts);
584 if (canvas_item_visible (selection_group)) {
585 while (!used_selection_rects.empty()) {
586 free_selection_rects.push_front (used_selection_rects.front());
587 used_selection_rects.pop_front();
588 free_selection_rects.front()->rect->hide();
589 free_selection_rects.front()->start_trim->hide();
590 free_selection_rects.front()->end_trim->hide();
592 selection_group->hide();
595 selection_group->show();
596 selection_group->raise_to_top();
598 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
599 jack_nframes_t start, end, cnt;
603 cnt = end - start + 1;
605 rect = get_selection_rect ((*i).id);
607 x1 = start / editor.get_current_zoom();
608 x2 = (start + cnt - 1) / editor.get_current_zoom();
611 rect->rect->property_x1() = x1;
612 rect->rect->property_y1() = 1.0;
613 rect->rect->property_x2() = x2;
614 rect->rect->property_y2() = y2;
616 // trim boxes are at the top for selections
619 rect->start_trim->property_x1() = x1;
620 rect->start_trim->property_y1() = 1.0;
621 rect->start_trim->property_x2() = x1 + trim_handle_size;
622 rect->start_trim->property_y2() = 1.0 + trim_handle_size;
624 rect->end_trim->property_x1() = x2 - trim_handle_size;
625 rect->end_trim->property_y1() = 1.0;
626 rect->end_trim->property_x2() = x2;
627 rect->end_trim->property_y2() = 1.0 + trim_handle_size;
629 rect->start_trim->show();
630 rect->end_trim->show();
632 rect->start_trim->hide();
633 rect->end_trim->hide();
637 used_selection_rects.push_back (rect);
642 TimeAxisView::reshow_selection (TimeSelection& ts)
646 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
647 (*i)->show_selection (ts);
652 TimeAxisView::hide_selection ()
654 if (canvas_item_visible (selection_group)) {
655 while (!used_selection_rects.empty()) {
656 free_selection_rects.push_front (used_selection_rects.front());
657 used_selection_rects.pop_front();
658 free_selection_rects.front()->rect->hide();
659 free_selection_rects.front()->start_trim->hide();
660 free_selection_rects.front()->end_trim->hide();
662 selection_group->hide();
665 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
666 (*i)->hide_selection ();
671 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
673 /* find the selection rect this is for. we have the item corresponding to one
677 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
678 if ((*i)->start_trim == item || (*i)->end_trim == item) {
680 /* make one trim handle be "above" the other so that if they overlap,
681 the top one is the one last used.
684 (*i)->rect->raise_to_top ();
685 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
686 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
694 TimeAxisView::get_selection_rect (uint32_t id)
698 /* check to see if we already have a visible rect for this particular selection ID */
700 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
701 if ((*i)->id == id) {
706 /* ditto for the free rect list */
708 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
709 if ((*i)->id == id) {
710 free_selection_rects.erase (i);
715 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
717 if (free_selection_rects.empty()) {
719 rect = new SelectionRect;
721 rect->rect = new SimpleRect (*selection_group);
722 rect->rect->property_x1() = 0.0;
723 rect->rect->property_y1() = 0.0;
724 rect->rect->property_x2() = 0.0;
725 rect->rect->property_y2() = 0.0;
726 rect->rect->property_fill_color_rgba() = color_map[cSelectionRectFill];
727 rect->rect->property_outline_color_rgba() = color_map[cSelectionRectOutline];
729 rect->start_trim = new SimpleRect (*selection_group);
730 rect->start_trim->property_x1() = 0.0;
731 rect->start_trim->property_x2() = 0.0;
732 rect->start_trim->property_fill_color_rgba() = color_map[cSelectionStartFill];
733 rect->start_trim->property_outline_color_rgba() = color_map[cSelectionStartOutline];
735 rect->end_trim = new SimpleRect (*selection_group);
736 rect->end_trim->property_x1() = 0.0;
737 rect->end_trim->property_x2() = 0.0;
738 rect->end_trim->property_fill_color_rgba() = color_map[cSelectionEndFill];
739 rect->end_trim->property_outline_color_rgba() = color_map[cSelectionEndOutline];
741 free_selection_rects.push_front (rect);
743 rect->rect->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
744 rect->start_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
745 rect->end_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
748 rect = free_selection_rects.front();
750 free_selection_rects.pop_front();
755 TimeAxisView::is_child (TimeAxisView* tav)
757 return find (children.begin(), children.end(), tav) != children.end();
761 TimeAxisView::add_child (TimeAxisView* child)
763 children.push_back (child);
767 TimeAxisView::remove_child (TimeAxisView* child)
769 vector<TimeAxisView*>::iterator i;
771 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
777 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
783 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
789 TimeAxisView::touched (double top, double bot)
791 /* remember: this is X Window - coordinate space starts in upper left and moves down.
792 y_position is the "origin" or "top" of the track.
795 double mybot = y_position + height; // XXX need to include Editor::track_spacing;
797 return ((y_position <= bot && y_position >= top) ||
798 ((mybot <= bot) && (top < mybot)) ||
799 (mybot >= bot && y_position < top));
803 TimeAxisView::set_parent (TimeAxisView& p)
809 TimeAxisView::has_state () const
815 TimeAxisView::get_parent_with_state ()
821 if (parent->has_state()) {
825 return parent->get_parent_with_state ();
829 TimeAxisView::set_state (const XMLNode& node)
831 const XMLProperty *prop;
833 if ((prop = node.property ("track_height")) != 0) {
835 if (prop->value() == "largest") {
836 set_height (Largest);
837 } else if (prop->value() == "large") {
839 } else if (prop->value() == "larger") {
841 } else if (prop->value() == "normal") {
843 } else if (prop->value() == "smaller") {
844 set_height (Smaller);
845 } else if (prop->value() == "small") {
848 error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
858 TimeAxisView::reset_height()
860 set_height ((TrackHeight) height);
862 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
863 (*i)->set_height ((TrackHeight)(*i)->height);