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);
196 controls_frame.show ();
197 controls_ebox.show ();
199 /* the coordinates used here are in the system of the
203 canvas_display->get_bounds (ix1, iy1, ix2, iy2);
204 Group* pg = canvas_display->property_parent();
211 canvas_display->move (0.0, y - iy1);
212 canvas_display->show();/* XXX not necessary */
217 effective_height = height;
219 /* now show children */
221 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
223 if ((*i)->marked_for_display()) {
224 (*i)->canvas_display->show();
227 if (canvas_item_visible ((*i)->canvas_display)) {
229 effective_height += (*i)->show_at (y + effective_height, nth, parent);
233 return effective_height;
237 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
239 switch (ev->button) {
241 selection_click (ev);
245 popup_display_menu (ev->time);
249 if (Keyboard::no_modifier_keys_pressed (ev)) {
250 editor.scroll_tracks_up_line ();
251 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
257 if (Keyboard::no_modifier_keys_pressed (ev)) {
258 editor.scroll_tracks_down_line ();
259 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
271 TimeAxisView::selection_click (GdkEventButton* ev)
273 if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
275 if (editor.get_selection().selected (this)) {
276 editor.get_selection().remove (this);
278 editor.get_selection().add (this);
283 editor.get_selection().set (this);
288 TimeAxisView::hide ()
294 canvas_display->hide();
295 controls_frame.hide ();
297 if (control_parent) {
298 control_parent->remove (controls_frame);
305 /* now hide children */
307 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
315 TimeAxisView::step_height (bool bigger)
319 if (!bigger) set_height (Large);
322 if (bigger) set_height (Largest);
323 else set_height (Larger);
326 if (bigger) set_height (Large);
327 else set_height (Normal);
330 if (bigger) set_height (Larger);
331 else set_height (Smaller);
334 if (bigger) set_height (Normal);
335 else set_height (Small);
338 if (bigger) set_height (Smaller);
345 TimeAxisView::set_height (TrackHeight h)
347 height = (guint32) h;
348 controls_frame.set_size_request (-1, height);
350 if (canvas_item_visible (selection_group)) {
351 /* resize the selection rect */
352 show_selection (editor.get_selection().time);
355 // for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
356 // (*i)->set_height (h);
362 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
364 switch (ev->keyval) {
368 name_entry_changed ();
375 #ifdef TIMEOUT_NAME_EDIT
376 /* adapt the timeout to reflect the user's typing speed */
378 guint32 name_entry_timeout;
380 if (last_name_entry_key_press_event) {
381 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
382 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
384 /* start with a 1 second timeout */
385 name_entry_timeout = 1000;
388 last_name_entry_key_press_event = ev->time;
390 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
392 name_entry_key_timeout.disconnect();
393 name_entry_key_timeout = Glib::signal_timeout().connect (mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
400 TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
402 name_entry.select_region (0, -1);
403 name_entry.set_name ("EditorActiveTrackNameDisplay");
408 TimeAxisView::name_entry_focus_out (GdkEventFocus* ev)
412 last_name_entry_key_press_event = 0;
413 name_entry_key_timeout.disconnect ();
414 name_entry.set_name ("EditorTrackNameDisplay");
416 /* do the real stuff */
418 name_entry_changed ();
424 TimeAxisView::name_entry_key_timed_out ()
426 name_entry_activated();
431 TimeAxisView::name_entry_activated ()
433 controls_ebox.grab_focus();
437 TimeAxisView::name_entry_changed ()
442 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
444 if (ev->button == 3) {
451 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
453 if (ev->button == 3) {
454 popup_display_menu (ev->time);
461 TimeAxisView::popup_display_menu (guint32 when)
463 if (display_menu == 0) {
464 build_display_menu ();
466 display_menu->popup (1, when);
470 TimeAxisView::size_click (GdkEventButton *ev)
472 popup_size_menu (ev->time);
477 TimeAxisView::popup_size_menu (guint32 when)
479 if (size_menu == 0) {
482 size_menu->popup (1, when);
486 TimeAxisView::set_selected (bool yn)
488 AxisView::set_selected (yn);
491 controls_ebox.set_name (controls_base_selected_name);
492 controls_frame.set_name (controls_base_selected_name);
494 /* propagate any existing selection, if the mode is right */
496 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
497 show_selection (editor.get_selection().time);
501 controls_ebox.set_name (controls_base_unselected_name);
502 controls_frame.set_name (controls_base_unselected_name);
506 /* children will be set for the yn=true case. but when deselecting
507 the editor only has a list of top-level trackviews, so we
508 have to do this here.
511 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
512 (*i)->set_selected (false);
520 TimeAxisView::build_size_menu ()
522 using namespace Menu_Helpers;
524 size_menu = new Menu;
525 size_menu->set_name ("ArdourContextMenu");
526 MenuList& items = size_menu->items();
528 items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
529 items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
530 items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
531 items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
532 items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height), Smaller)));
533 items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
537 TimeAxisView::build_display_menu ()
539 using namespace Menu_Helpers;
541 display_menu = new Menu;
542 display_menu->set_name ("ArdourContextMenu");
544 // Just let implementing classes define what goes into the manu
548 TimeAxisView::set_samples_per_unit (double spu)
550 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
551 (*i)->set_samples_per_unit (spu);
556 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
558 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
559 (*i)->show_timestretch (start, end);
564 TimeAxisView::hide_timestretch ()
566 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
567 (*i)->hide_timestretch ();
572 TimeAxisView::show_selection (TimeSelection& ts)
579 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
580 (*i)->show_selection (ts);
583 if (canvas_item_visible (selection_group)) {
584 while (!used_selection_rects.empty()) {
585 free_selection_rects.push_front (used_selection_rects.front());
586 used_selection_rects.pop_front();
587 free_selection_rects.front()->rect->hide();
588 free_selection_rects.front()->start_trim->hide();
589 free_selection_rects.front()->end_trim->hide();
591 selection_group->hide();
594 selection_group->show();
595 selection_group->raise_to_top();
597 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
598 jack_nframes_t start, end, cnt;
602 cnt = end - start + 1;
604 rect = get_selection_rect ((*i).id);
606 x1 = start / editor.get_current_zoom();
607 x2 = (start + cnt - 1) / editor.get_current_zoom();
610 rect->rect->property_x1() = x1;
611 rect->rect->property_y1() = 1.0;
612 rect->rect->property_x2() = x2;
613 rect->rect->property_y2() = y2;
615 // trim boxes are at the top for selections
618 rect->start_trim->property_x1() = x1;
619 rect->start_trim->property_y1() = 1.0;
620 rect->start_trim->property_x2() = x1 + trim_handle_size;
621 rect->start_trim->property_y2() = 1.0 + trim_handle_size;
623 rect->end_trim->property_x1() = x2 - trim_handle_size;
624 rect->end_trim->property_y1() = 1.0;
625 rect->end_trim->property_x2() = x2;
626 rect->end_trim->property_y2() = 1.0 + trim_handle_size;
628 rect->start_trim->show();
629 rect->end_trim->show();
631 rect->start_trim->hide();
632 rect->end_trim->hide();
636 used_selection_rects.push_back (rect);
641 TimeAxisView::reshow_selection (TimeSelection& ts)
645 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
646 (*i)->show_selection (ts);
651 TimeAxisView::hide_selection ()
653 if (canvas_item_visible (selection_group)) {
654 while (!used_selection_rects.empty()) {
655 free_selection_rects.push_front (used_selection_rects.front());
656 used_selection_rects.pop_front();
657 free_selection_rects.front()->rect->hide();
658 free_selection_rects.front()->start_trim->hide();
659 free_selection_rects.front()->end_trim->hide();
661 selection_group->hide();
664 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
665 (*i)->hide_selection ();
670 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
672 /* find the selection rect this is for. we have the item corresponding to one
676 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
677 if ((*i)->start_trim == item || (*i)->end_trim == item) {
679 /* make one trim handle be "above" the other so that if they overlap,
680 the top one is the one last used.
683 (*i)->rect->raise_to_top ();
684 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
685 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
693 TimeAxisView::get_selection_rect (uint32_t id)
697 /* check to see if we already have a visible rect for this particular selection ID */
699 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
700 if ((*i)->id == id) {
705 /* ditto for the free rect list */
707 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
708 if ((*i)->id == id) {
709 free_selection_rects.erase (i);
714 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
716 if (free_selection_rects.empty()) {
718 rect = new SelectionRect;
720 rect->rect = new SimpleRect (*selection_group);
721 rect->rect->property_x1() = 0.0;
722 rect->rect->property_y1() = 0.0;
723 rect->rect->property_x2() = 0.0;
724 rect->rect->property_y2() = 0.0;
725 rect->rect->property_fill_color_rgba() = color_map[cSelectionRectFill];
726 rect->rect->property_outline_color_rgba() = color_map[cSelectionRectOutline];
728 rect->start_trim = new SimpleRect (*selection_group);
729 rect->start_trim->property_x1() = 0.0;
730 rect->start_trim->property_x2() = 0.0;
731 rect->start_trim->property_fill_color_rgba() = color_map[cSelectionStartFill];
732 rect->start_trim->property_outline_color_rgba() = color_map[cSelectionStartOutline];
734 rect->end_trim = new SimpleRect (*selection_group);
735 rect->end_trim->property_x1() = 0.0;
736 rect->end_trim->property_x2() = 0.0;
737 rect->end_trim->property_fill_color_rgba() = color_map[cSelectionEndFill];
738 rect->end_trim->property_outline_color_rgba() = color_map[cSelectionEndOutline];
740 free_selection_rects.push_front (rect);
742 rect->rect->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
743 rect->start_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
744 rect->end_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
747 rect = free_selection_rects.front();
749 free_selection_rects.pop_front();
754 TimeAxisView::is_child (TimeAxisView* tav)
756 return find (children.begin(), children.end(), tav) != children.end();
760 TimeAxisView::add_child (TimeAxisView* child)
762 children.push_back (child);
766 TimeAxisView::remove_child (TimeAxisView* child)
768 vector<TimeAxisView*>::iterator i;
770 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
776 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
782 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
788 TimeAxisView::touched (double top, double bot)
790 /* remember: this is X Window - coordinate space starts in upper left and moves down.
791 y_position is the "origin" or "top" of the track.
794 double mybot = y_position + height; // XXX need to include Editor::track_spacing;
796 return ((y_position <= bot && y_position >= top) ||
797 ((mybot <= bot) && (top < mybot)) ||
798 (mybot >= bot && y_position < top));
802 TimeAxisView::set_parent (TimeAxisView& p)
808 TimeAxisView::has_state () const
814 TimeAxisView::get_parent_with_state ()
820 if (parent->has_state()) {
824 return parent->get_parent_with_state ();
828 TimeAxisView::set_state (const XMLNode& node)
830 const XMLProperty *prop;
832 if ((prop = node.property ("track_height")) != 0) {
834 if (prop->value() == "largest") {
835 set_height (Largest);
836 } else if (prop->value() == "large") {
838 } else if (prop->value() == "larger") {
840 } else if (prop->value() == "normal") {
842 } else if (prop->value() == "smaller") {
843 set_height (Smaller);
844 } else if (prop->value() == "small") {
847 error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
857 TimeAxisView::reset_height()
859 set_height ((TrackHeight) height);
861 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
862 (*i)->set_height ((TrackHeight)(*i)->height);