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;
83 Create the standard LHS Controls
84 We create the top-level container and name add the name label here,
85 subclasses can add to the layout as required
88 name_entry.set_name ("EditorTrackNameDisplay");
89 name_entry.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::name_entry_button_release));
90 name_entry.signal_button_press_event().connect (mem_fun (*this, &TimeAxisView::name_entry_button_press));
92 Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
94 name_label.set_name ("TrackLabel");
95 name_label.set_alignment (0.0, 0.5);
97 // name_hbox.set_border_width (2);
98 // name_hbox.set_spacing (5);
100 /* typically, either name_label OR name_entry are visible,
101 but not both. its up to derived classes to show/hide them as they
105 name_hbox.pack_start (name_label, true, true);
106 name_hbox.pack_start (name_entry, true, true);
109 controls_table.set_border_width (2);
110 controls_table.set_row_spacings (0);
111 controls_table.set_col_spacings (0);
112 controls_table.set_homogeneous (true);
113 controls_table.show ();
115 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
117 controls_table.show ();
119 controls_vbox.pack_start (controls_table, false, false);
120 controls_vbox.show ();
122 controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
123 controls_ebox.add (controls_vbox);
124 controls_ebox.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
125 controls_ebox.set_flags (Gtk::CAN_FOCUS);
127 controls_ebox.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
129 controls_lhs_pad.set_name ("TimeAxisViewControlsPadding");
130 controls_hbox.pack_start (controls_lhs_pad,false,false);
131 controls_hbox.pack_start (controls_ebox,true,true);
132 controls_hbox.show ();
134 controls_frame.add (controls_hbox);
135 controls_frame.set_name ("TimeAxisViewControlsBaseUnselected");
136 controls_frame.set_shadow_type (Gtk::SHADOW_OUT);
139 TimeAxisView::~TimeAxisView()
141 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
145 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
147 delete (*i)->start_trim;
148 delete (*i)->end_trim;
152 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
154 delete (*i)->start_trim;
155 delete (*i)->end_trim;
158 if (selection_group) {
159 delete selection_group;
163 if (canvas_display) {
164 delete canvas_display;
180 TimeAxisView::show_at (double y, int& nth, VBox *parent)
182 gdouble ix1, ix2, iy1, iy2;
183 effective_height = 0;
185 if (control_parent) {
186 control_parent->reorder_child (controls_frame, nth);
188 control_parent = parent;
189 parent->pack_start (controls_frame, false, false);
190 parent->reorder_child (controls_frame, nth);
193 controls_frame.show ();
194 controls_ebox.show ();
196 /* the coordinates used here are in the system of the
200 canvas_display->get_bounds (ix1, iy1, ix2, iy2);
201 Group* pg = canvas_display->property_parent();
208 canvas_display->move (0.0, y - iy1);
209 canvas_display->show();/* XXX not necessary */
214 effective_height = height;
216 /* now show children */
218 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
220 if ((*i)->marked_for_display()) {
221 (*i)->canvas_display->show();
224 if (canvas_item_visible ((*i)->canvas_display)) {
226 effective_height += (*i)->show_at (y + effective_height, nth, parent);
230 return effective_height;
234 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
236 switch (ev->button) {
238 selection_click (ev);
242 popup_display_menu (ev->time);
246 if (Keyboard::no_modifier_keys_pressed (ev)) {
247 editor.scroll_tracks_up_line ();
248 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
254 if (Keyboard::no_modifier_keys_pressed (ev)) {
255 editor.scroll_tracks_down_line ();
256 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
268 TimeAxisView::selection_click (GdkEventButton* ev)
270 if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
272 if (editor.get_selection().selected (this)) {
273 editor.get_selection().remove (this);
275 editor.get_selection().add (this);
280 editor.get_selection().set (this);
285 TimeAxisView::hide ()
291 canvas_display->hide();
292 controls_frame.hide ();
294 if (control_parent) {
295 control_parent->remove (controls_frame);
302 /* now hide children */
304 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
312 TimeAxisView::step_height (bool bigger)
316 if (!bigger) set_height (Large);
319 if (bigger) set_height (Largest);
320 else set_height (Larger);
323 if (bigger) set_height (Large);
324 else set_height (Normal);
327 if (bigger) set_height (Larger);
328 else set_height (Smaller);
331 if (bigger) set_height (Normal);
332 else set_height (Small);
335 if (bigger) set_height (Smaller);
342 TimeAxisView::set_height (TrackHeight h)
344 height = (guint32) h;
345 controls_frame.set_size_request (-1, height);
347 if (canvas_item_visible (selection_group)) {
348 /* resize the selection rect */
349 show_selection (editor.get_selection().time);
352 // for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
353 // (*i)->set_height (h);
359 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
361 if (ev->button == 3) {
368 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
370 if (ev->button == 3) {
371 popup_display_menu (ev->time);
378 TimeAxisView::popup_display_menu (guint32 when)
380 if (display_menu == 0) {
381 build_display_menu ();
383 display_menu->popup (1, when);
387 TimeAxisView::size_click (GdkEventButton *ev)
389 popup_size_menu (ev->time);
394 TimeAxisView::popup_size_menu (guint32 when)
396 if (size_menu == 0) {
399 size_menu->popup (1, when);
403 TimeAxisView::set_selected (bool yn)
405 AxisView::set_selected (yn);
408 controls_ebox.set_name (controls_base_selected_name);
409 controls_frame.set_name (controls_base_selected_name);
411 /* propagate any existing selection, if the mode is right */
413 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
414 show_selection (editor.get_selection().time);
418 controls_ebox.set_name (controls_base_unselected_name);
419 controls_frame.set_name (controls_base_unselected_name);
423 /* children will be set for the yn=true case. but when deselecting
424 the editor only has a list of top-level trackviews, so we
425 have to do this here.
428 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
429 (*i)->set_selected (false);
437 TimeAxisView::build_size_menu ()
439 using namespace Menu_Helpers;
441 size_menu = new Menu;
442 size_menu->set_name ("ArdourContextMenu");
443 MenuList& items = size_menu->items();
445 items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
446 items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
447 items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
448 items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
449 items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height), Smaller)));
450 items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
454 TimeAxisView::build_display_menu ()
456 using namespace Menu_Helpers;
458 display_menu = new Menu;
459 display_menu->set_name ("ArdourContextMenu");
461 // Just let implementing classes define what goes into the manu
465 TimeAxisView::set_samples_per_unit (double spu)
467 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
468 (*i)->set_samples_per_unit (spu);
473 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
475 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
476 (*i)->show_timestretch (start, end);
481 TimeAxisView::hide_timestretch ()
483 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
484 (*i)->hide_timestretch ();
489 TimeAxisView::show_selection (TimeSelection& ts)
496 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
497 (*i)->show_selection (ts);
500 if (canvas_item_visible (selection_group)) {
501 while (!used_selection_rects.empty()) {
502 free_selection_rects.push_front (used_selection_rects.front());
503 used_selection_rects.pop_front();
504 free_selection_rects.front()->rect->hide();
505 free_selection_rects.front()->start_trim->hide();
506 free_selection_rects.front()->end_trim->hide();
508 selection_group->hide();
511 selection_group->show();
512 selection_group->raise_to_top();
514 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
515 jack_nframes_t start, end, cnt;
519 cnt = end - start + 1;
521 rect = get_selection_rect ((*i).id);
523 x1 = start / editor.get_current_zoom();
524 x2 = (start + cnt - 1) / editor.get_current_zoom();
527 rect->rect->property_x1() = x1;
528 rect->rect->property_y1() = 1.0;
529 rect->rect->property_x2() = x2;
530 rect->rect->property_y2() = y2;
532 // trim boxes are at the top for selections
535 rect->start_trim->property_x1() = x1;
536 rect->start_trim->property_y1() = 1.0;
537 rect->start_trim->property_x2() = x1 + trim_handle_size;
538 rect->start_trim->property_y2() = 1.0 + trim_handle_size;
540 rect->end_trim->property_x1() = x2 - trim_handle_size;
541 rect->end_trim->property_y1() = 1.0;
542 rect->end_trim->property_x2() = x2;
543 rect->end_trim->property_y2() = 1.0 + trim_handle_size;
545 rect->start_trim->show();
546 rect->end_trim->show();
548 rect->start_trim->hide();
549 rect->end_trim->hide();
553 used_selection_rects.push_back (rect);
558 TimeAxisView::reshow_selection (TimeSelection& ts)
562 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
563 (*i)->show_selection (ts);
568 TimeAxisView::hide_selection ()
570 if (canvas_item_visible (selection_group)) {
571 while (!used_selection_rects.empty()) {
572 free_selection_rects.push_front (used_selection_rects.front());
573 used_selection_rects.pop_front();
574 free_selection_rects.front()->rect->hide();
575 free_selection_rects.front()->start_trim->hide();
576 free_selection_rects.front()->end_trim->hide();
578 selection_group->hide();
581 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
582 (*i)->hide_selection ();
587 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
589 /* find the selection rect this is for. we have the item corresponding to one
593 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
594 if ((*i)->start_trim == item || (*i)->end_trim == item) {
596 /* make one trim handle be "above" the other so that if they overlap,
597 the top one is the one last used.
600 (*i)->rect->raise_to_top ();
601 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
602 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
610 TimeAxisView::get_selection_rect (uint32_t id)
614 /* check to see if we already have a visible rect for this particular selection ID */
616 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
617 if ((*i)->id == id) {
622 /* ditto for the free rect list */
624 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
625 if ((*i)->id == id) {
626 free_selection_rects.erase (i);
631 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
633 if (free_selection_rects.empty()) {
635 rect = new SelectionRect;
637 rect->rect = new SimpleRect (*selection_group);
638 rect->rect->property_x1() = 0.0;
639 rect->rect->property_y1() = 0.0;
640 rect->rect->property_x2() = 0.0;
641 rect->rect->property_y2() = 0.0;
642 rect->rect->property_fill_color_rgba() = color_map[cSelectionRectFill];
643 rect->rect->property_outline_color_rgba() = color_map[cSelectionRectOutline];
645 rect->start_trim = new SimpleRect (*selection_group);
646 rect->start_trim->property_x1() = 0.0;
647 rect->start_trim->property_x2() = 0.0;
648 rect->start_trim->property_fill_color_rgba() = color_map[cSelectionStartFill];
649 rect->start_trim->property_outline_color_rgba() = color_map[cSelectionStartOutline];
651 rect->end_trim = new SimpleRect (*selection_group);
652 rect->end_trim->property_x1() = 0.0;
653 rect->end_trim->property_x2() = 0.0;
654 rect->end_trim->property_fill_color_rgba() = color_map[cSelectionEndFill];
655 rect->end_trim->property_outline_color_rgba() = color_map[cSelectionEndOutline];
657 free_selection_rects.push_front (rect);
659 rect->rect->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
660 rect->start_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
661 rect->end_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
664 rect = free_selection_rects.front();
666 free_selection_rects.pop_front();
671 TimeAxisView::is_child (TimeAxisView* tav)
673 return find (children.begin(), children.end(), tav) != children.end();
677 TimeAxisView::add_child (TimeAxisView* child)
679 children.push_back (child);
683 TimeAxisView::remove_child (TimeAxisView* child)
685 vector<TimeAxisView*>::iterator i;
687 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
693 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
699 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
705 TimeAxisView::touched (double top, double bot)
707 /* remember: this is X Window - coordinate space starts in upper left and moves down.
708 y_position is the "origin" or "top" of the track.
711 double mybot = y_position + height; // XXX need to include Editor::track_spacing;
713 return ((y_position <= bot && y_position >= top) ||
714 ((mybot <= bot) && (top < mybot)) ||
715 (mybot >= bot && y_position < top));
719 TimeAxisView::set_parent (TimeAxisView& p)
725 TimeAxisView::has_state () const
731 TimeAxisView::get_parent_with_state ()
737 if (parent->has_state()) {
741 return parent->get_parent_with_state ();
745 TimeAxisView::set_state (const XMLNode& node)
747 const XMLProperty *prop;
749 if ((prop = node.property ("track_height")) != 0) {
751 if (prop->value() == "largest") {
752 set_height (Largest);
753 } else if (prop->value() == "large") {
755 } else if (prop->value() == "larger") {
757 } else if (prop->value() == "normal") {
759 } else if (prop->value() == "smaller") {
760 set_height (Smaller);
761 } else if (prop->value() == "small") {
764 error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
774 TimeAxisView::reset_height()
776 set_height ((TrackHeight) height);
778 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
779 (*i)->set_height ((TrackHeight)(*i)->height);