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));
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_IN);
145 TimeAxisView::~TimeAxisView()
147 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
151 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
153 delete (*i)->start_trim;
154 delete (*i)->end_trim;
158 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
160 delete (*i)->start_trim;
161 delete (*i)->end_trim;
164 if (selection_group) {
165 delete selection_group;
169 if (canvas_display) {
170 delete canvas_display;
186 TimeAxisView::show_at (double y, int& nth, VBox *parent)
188 gdouble ix1, ix2, iy1, iy2;
189 effective_height = 0;
191 if (control_parent) {
192 control_parent->reorder_child (controls_frame, nth);
194 control_parent = parent;
195 parent->pack_start (controls_frame, false, false);
196 parent->reorder_child (controls_frame, nth);
198 controls_frame.show ();
199 controls_ebox.show ();
201 /* the coordinates used here are in the system of the
205 canvas_display->get_bounds (ix1, iy1, ix2, iy2);
206 Group* pg = canvas_display->property_parent();
213 canvas_display->move (0.0, y - iy1);
214 canvas_display->show();/* XXX not necessary */
219 effective_height = height;
221 /* now show children */
223 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
225 if ((*i)->marked_for_display()) {
226 (*i)->canvas_display->show();
229 if (canvas_item_visible ((*i)->canvas_display)) {
231 effective_height += (*i)->show_at (y + effective_height, nth, parent);
235 return effective_height;
239 TimeAxisView::controls_ebox_scroll (GdkEventScroll* ev)
241 switch (ev->direction) {
243 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
249 case GDK_SCROLL_DOWN:
250 if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
257 /* no handling for left/right, yet */
265 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
267 cerr << "controls ebox button release button " << ev->button << endl;
269 switch (ev->button) {
271 selection_click (ev);
275 popup_display_menu (ev->time);
283 TimeAxisView::selection_click (GdkEventButton* ev)
285 if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
287 if (editor.get_selection().selected (this)) {
288 editor.get_selection().remove (this);
290 editor.get_selection().add (this);
295 editor.get_selection().set (this);
300 TimeAxisView::hide ()
306 canvas_display->hide();
307 controls_frame.hide ();
309 if (control_parent) {
310 control_parent->remove (controls_frame);
317 /* now hide children */
319 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
327 TimeAxisView::step_height (bool bigger)
331 if (!bigger) set_height (Large);
334 if (bigger) set_height (Largest);
335 else set_height (Larger);
338 if (bigger) set_height (Large);
339 else set_height (Normal);
342 if (bigger) set_height (Larger);
343 else set_height (Smaller);
346 if (bigger) set_height (Normal);
347 else set_height (Small);
350 if (bigger) set_height (Smaller);
357 TimeAxisView::set_height (TrackHeight h)
359 height = (guint32) h;
360 controls_frame.set_size_request (-1, height);
362 if (canvas_item_visible (selection_group)) {
363 /* resize the selection rect */
364 show_selection (editor.get_selection().time);
367 // for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
368 // (*i)->set_height (h);
374 TimeAxisView::name_entry_key_release (GdkEventKey* ev)
376 switch (ev->keyval) {
380 name_entry_changed ();
387 #ifdef TIMEOUT_NAME_EDIT
388 /* adapt the timeout to reflect the user's typing speed */
390 guint32 name_entry_timeout;
392 if (last_name_entry_key_press_event) {
393 /* timeout is 1/2 second or 5 times their current inter-char typing speed */
394 name_entry_timeout = std::max (500U, (5 * (ev->time - last_name_entry_key_press_event)));
396 /* start with a 1 second timeout */
397 name_entry_timeout = 1000;
400 last_name_entry_key_press_event = ev->time;
402 /* wait 1 seconds and if no more keys are pressed, act as if they pressed enter */
404 name_entry_key_timeout.disconnect();
405 name_entry_key_timeout = Glib::signal_timeout().connect (mem_fun (*this, &TimeAxisView::name_entry_key_timed_out), name_entry_timeout);
412 TimeAxisView::name_entry_focus_in (GdkEventFocus* ev)
414 name_entry.select_region (0, -1);
415 name_entry.set_name ("EditorActiveTrackNameDisplay");
420 TimeAxisView::name_entry_focus_out (GdkEventFocus* ev)
424 last_name_entry_key_press_event = 0;
425 name_entry_key_timeout.disconnect ();
426 name_entry.set_name ("EditorTrackNameDisplay");
428 /* do the real stuff */
430 name_entry_changed ();
436 TimeAxisView::name_entry_key_timed_out ()
438 name_entry_activated();
443 TimeAxisView::name_entry_activated ()
445 controls_ebox.grab_focus();
449 TimeAxisView::name_entry_changed ()
454 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
456 if (ev->button == 3) {
463 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
465 if (ev->button == 3) {
466 popup_display_menu (ev->time);
473 TimeAxisView::popup_display_menu (guint32 when)
475 if (display_menu == 0) {
476 build_display_menu ();
478 display_menu->popup (1, when);
482 TimeAxisView::size_click (GdkEventButton *ev)
484 popup_size_menu (ev->time);
489 TimeAxisView::popup_size_menu (guint32 when)
491 if (size_menu == 0) {
494 size_menu->popup (1, when);
498 TimeAxisView::set_selected (bool yn)
500 AxisView::set_selected (yn);
503 controls_ebox.set_name (controls_base_selected_name);
504 controls_frame.set_name (controls_base_selected_name);
506 /* propagate any existing selection, if the mode is right */
508 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
509 show_selection (editor.get_selection().time);
513 controls_ebox.set_name (controls_base_unselected_name);
514 controls_frame.set_name (controls_base_unselected_name);
518 /* children will be set for the yn=true case. but when deselecting
519 the editor only has a list of top-level trackviews, so we
520 have to do this here.
523 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
524 (*i)->set_selected (false);
532 TimeAxisView::build_size_menu ()
534 using namespace Menu_Helpers;
536 size_menu = new Menu;
537 size_menu->set_name ("ArdourContextMenu");
538 MenuList& items = size_menu->items();
540 items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
541 items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
542 items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
543 items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
544 items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height), Smaller)));
545 items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
549 TimeAxisView::build_display_menu ()
551 using namespace Menu_Helpers;
553 display_menu = new Menu;
554 display_menu->set_name ("ArdourContextMenu");
556 // Just let implementing classes define what goes into the manu
560 TimeAxisView::set_samples_per_unit (double spu)
562 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
563 (*i)->set_samples_per_unit (spu);
568 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
570 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
571 (*i)->show_timestretch (start, end);
576 TimeAxisView::hide_timestretch ()
578 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
579 (*i)->hide_timestretch ();
584 TimeAxisView::show_selection (TimeSelection& ts)
591 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
592 (*i)->show_selection (ts);
595 if (canvas_item_visible (selection_group)) {
596 while (!used_selection_rects.empty()) {
597 free_selection_rects.push_front (used_selection_rects.front());
598 used_selection_rects.pop_front();
599 free_selection_rects.front()->rect->hide();
600 free_selection_rects.front()->start_trim->hide();
601 free_selection_rects.front()->end_trim->hide();
603 selection_group->hide();
606 selection_group->show();
607 selection_group->raise_to_top();
609 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
610 jack_nframes_t start, end, cnt;
614 cnt = end - start + 1;
616 rect = get_selection_rect ((*i).id);
618 x1 = start / editor.get_current_zoom();
619 x2 = (start + cnt - 1) / editor.get_current_zoom();
622 rect->rect->property_x1() = x1;
623 rect->rect->property_y1() = 1.0;
624 rect->rect->property_x2() = x2;
625 rect->rect->property_y2() = y2;
627 // trim boxes are at the top for selections
630 rect->start_trim->property_x1() = x1;
631 rect->start_trim->property_y1() = 1.0;
632 rect->start_trim->property_x2() = x1 + trim_handle_size;
633 rect->start_trim->property_y2() = 1.0 + trim_handle_size;
635 rect->end_trim->property_x1() = x2 - trim_handle_size;
636 rect->end_trim->property_y1() = 1.0;
637 rect->end_trim->property_x2() = x2;
638 rect->end_trim->property_y2() = 1.0 + trim_handle_size;
640 rect->start_trim->show();
641 rect->end_trim->show();
643 rect->start_trim->hide();
644 rect->end_trim->hide();
648 used_selection_rects.push_back (rect);
653 TimeAxisView::reshow_selection (TimeSelection& ts)
657 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
658 (*i)->show_selection (ts);
663 TimeAxisView::hide_selection ()
665 if (canvas_item_visible (selection_group)) {
666 while (!used_selection_rects.empty()) {
667 free_selection_rects.push_front (used_selection_rects.front());
668 used_selection_rects.pop_front();
669 free_selection_rects.front()->rect->hide();
670 free_selection_rects.front()->start_trim->hide();
671 free_selection_rects.front()->end_trim->hide();
673 selection_group->hide();
676 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
677 (*i)->hide_selection ();
682 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
684 /* find the selection rect this is for. we have the item corresponding to one
688 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
689 if ((*i)->start_trim == item || (*i)->end_trim == item) {
691 /* make one trim handle be "above" the other so that if they overlap,
692 the top one is the one last used.
695 (*i)->rect->raise_to_top ();
696 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
697 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
705 TimeAxisView::get_selection_rect (uint32_t id)
709 /* check to see if we already have a visible rect for this particular selection ID */
711 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
712 if ((*i)->id == id) {
717 /* ditto for the free rect list */
719 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
720 if ((*i)->id == id) {
721 free_selection_rects.erase (i);
726 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
728 if (free_selection_rects.empty()) {
730 rect = new SelectionRect;
732 rect->rect = new SimpleRect (*selection_group);
733 rect->rect->property_x1() = 0.0;
734 rect->rect->property_y1() = 0.0;
735 rect->rect->property_x2() = 0.0;
736 rect->rect->property_y2() = 0.0;
737 rect->rect->property_fill_color_rgba() = color_map[cSelectionRectFill];
738 rect->rect->property_outline_color_rgba() = color_map[cSelectionRectOutline];
740 rect->start_trim = new SimpleRect (*selection_group);
741 rect->start_trim->property_x1() = 0.0;
742 rect->start_trim->property_x2() = 0.0;
743 rect->start_trim->property_fill_color_rgba() = color_map[cSelectionStartFill];
744 rect->start_trim->property_outline_color_rgba() = color_map[cSelectionStartOutline];
746 rect->end_trim = new SimpleRect (*selection_group);
747 rect->end_trim->property_x1() = 0.0;
748 rect->end_trim->property_x2() = 0.0;
749 rect->end_trim->property_fill_color_rgba() = color_map[cSelectionEndFill];
750 rect->end_trim->property_outline_color_rgba() = color_map[cSelectionEndOutline];
752 free_selection_rects.push_front (rect);
754 rect->rect->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
755 rect->start_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
756 rect->end_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
759 rect = free_selection_rects.front();
761 free_selection_rects.pop_front();
766 TimeAxisView::is_child (TimeAxisView* tav)
768 return find (children.begin(), children.end(), tav) != children.end();
772 TimeAxisView::add_child (TimeAxisView* child)
774 children.push_back (child);
778 TimeAxisView::remove_child (TimeAxisView* child)
780 vector<TimeAxisView*>::iterator i;
782 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
788 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
794 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
800 TimeAxisView::touched (double top, double bot)
802 /* remember: this is X Window - coordinate space starts in upper left and moves down.
803 y_position is the "origin" or "top" of the track.
806 double mybot = y_position + height; // XXX need to include Editor::track_spacing;
808 return ((y_position <= bot && y_position >= top) ||
809 ((mybot <= bot) && (top < mybot)) ||
810 (mybot >= bot && y_position < top));
814 TimeAxisView::set_parent (TimeAxisView& p)
820 TimeAxisView::has_state () const
826 TimeAxisView::get_parent_with_state ()
832 if (parent->has_state()) {
836 return parent->get_parent_with_state ();
840 TimeAxisView::set_state (const XMLNode& node)
842 const XMLProperty *prop;
844 if ((prop = node.property ("track_height")) != 0) {
846 if (prop->value() == "largest") {
847 set_height (Largest);
848 } else if (prop->value() == "large") {
850 } else if (prop->value() == "larger") {
852 } else if (prop->value() == "normal") {
854 } else if (prop->value() == "smaller") {
855 set_height (Smaller);
856 } else if (prop->value() == "small") {
859 error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
869 TimeAxisView::reset_height()
871 set_height ((TrackHeight) height);
873 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
874 (*i)->set_height ((TrackHeight)(*i)->height);