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"
55 using namespace ARDOUR;
56 using namespace Editing;
57 using namespace ArdourCanvas;
59 const double trim_handle_size = 6.0; /* pixels */
61 TimeAxisView::TimeAxisView (ARDOUR::Session& sess, PublicEditor& ed, TimeAxisView* rent, Canvas& canvas)
66 canvas_display = new Group (*canvas.root(), 0.0, 0.0);
68 selection_group = new Group (*canvas_display);
69 selection_group->hide();
74 _marked_for_display = false;
82 Create the standard LHS Controls
83 We create the top-level container and name add the name label here,
84 subclasses can add to the layout as required
87 name_entry.set_name ("EditorTrackNameDisplay");
88 name_entry.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::name_entry_button_release));
89 name_entry.signal_button_press_event().connect (mem_fun (*this, &TimeAxisView::name_entry_button_press));
91 name_entry.signal_focus_in_event().connect (sigc::ptr_fun (ARDOUR_UI::generic_focus_in_event));
92 name_entry.signal_focus_out_event().connect (sigc::ptr_fun (ARDOUR_UI::generic_focus_out_event));
94 Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
96 name_label.set_name ("TrackLabel");
97 name_label.set_alignment (0.0, 0.5);
99 // name_hbox.set_border_width (2);
100 // name_hbox.set_spacing (5);
102 /* typically, either name_label OR name_entry are visible,
103 but not both. its up to derived classes to show/hide them as they
107 name_hbox.pack_start (name_label, true, true);
108 name_hbox.pack_start (name_entry, true, true);
111 controls_table.set_border_width (2);
112 controls_table.set_row_spacings (0);
113 controls_table.set_col_spacings (0);
114 controls_table.set_homogeneous (true);
115 controls_table.show ();
117 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
119 controls_table.show ();
121 controls_vbox.pack_start (controls_table, false, false);
122 controls_vbox.show ();
124 controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
125 controls_ebox.add (controls_vbox);
126 controls_ebox.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
127 controls_ebox.set_flags (Gtk::CAN_FOCUS);
129 controls_ebox.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
131 controls_lhs_pad.set_name ("TimeAxisViewControlsPadding");
132 controls_hbox.pack_start (controls_lhs_pad,false,false);
133 controls_hbox.pack_start (controls_ebox,true,true);
134 controls_hbox.show ();
136 controls_frame.add (controls_hbox);
137 controls_frame.set_name ("TimeAxisViewControlsBaseUnselected");
138 controls_frame.set_shadow_type (Gtk::SHADOW_OUT);
141 TimeAxisView::~TimeAxisView()
143 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
147 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
148 gtk_object_destroy (GTK_OBJECT((*i)->rect));
149 gtk_object_destroy (GTK_OBJECT((*i)->start_trim));
150 gtk_object_destroy (GTK_OBJECT((*i)->end_trim));
153 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
154 gtk_object_destroy (GTK_OBJECT((*i)->rect));
155 gtk_object_destroy (GTK_OBJECT((*i)->start_trim));
156 gtk_object_destroy (GTK_OBJECT((*i)->end_trim));
159 if (selection_group) {
160 delete selection_group;
164 if (canvas_display) {
165 delete canvas_display;
181 TimeAxisView::show_at (double y, int& nth, VBox *parent)
183 gdouble ix1, ix2, iy1, iy2;
184 effective_height = 0;
186 if (control_parent) {
187 control_parent->reorder_child (controls_frame, nth);
189 control_parent = parent;
190 parent->pack_start (controls_frame, false, false);
191 parent->reorder_child (controls_frame, nth);
194 controls_frame.show ();
195 controls_ebox.show ();
197 /* the coordinates used here are in the system of the
201 canvas_display->get_bounds (ix1, iy1, ix2, iy2);
202 Group* pg = canvas_display->property_parent();
209 canvas_display->move (0.0, y - iy1);
210 canvas_display->show();/* XXX not necessary */
215 effective_height = height;
217 /* now show children */
219 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
221 if ((*i)->marked_for_display()) {
222 (*i)->canvas_display->show();
225 if (GTK_OBJECT_FLAGS(GTK_OBJECT((*i)->canvas_display)) & GNOME_CANVAS_ITEM_VISIBLE) {
227 effective_height += (*i)->show_at (y + effective_height, nth, parent);
231 return effective_height;
235 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
237 switch (ev->button) {
239 selection_click (ev);
243 popup_display_menu (ev->time);
247 if (Keyboard::no_modifier_keys_pressed (ev)) {
248 editor.scroll_tracks_up_line ();
249 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
255 if (Keyboard::no_modifier_keys_pressed (ev)) {
256 editor.scroll_tracks_down_line ();
257 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
269 TimeAxisView::selection_click (GdkEventButton* ev)
271 if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
273 if (editor.get_selection().selected (this)) {
274 editor.get_selection().remove (this);
276 editor.get_selection().add (this);
281 editor.get_selection().set (this);
286 TimeAxisView::hide ()
292 canvas_display->hide();
293 controls_frame.hide ();
295 if (control_parent) {
296 control_parent->remove (controls_frame);
303 /* now hide children */
305 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
313 TimeAxisView::step_height (bool bigger)
317 if (!bigger) set_height (Large);
320 if (bigger) set_height (Largest);
321 else set_height (Larger);
324 if (bigger) set_height (Large);
325 else set_height (Normal);
328 if (bigger) set_height (Larger);
329 else set_height (Smaller);
332 if (bigger) set_height (Normal);
333 else set_height (Small);
336 if (bigger) set_height (Smaller);
343 TimeAxisView::set_height (TrackHeight h)
345 height = (guint32) h;
346 controls_frame.set_size_request (-1, height);
348 if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
349 /* resize the selection rect */
350 show_selection (editor.get_selection().time);
353 // for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
354 // (*i)->set_height (h);
360 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
362 if (ev->button == 3) {
369 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
371 if (ev->button == 3) {
372 popup_display_menu (ev->time);
379 TimeAxisView::popup_display_menu (guint32 when)
381 if (display_menu == 0) {
382 build_display_menu ();
384 display_menu->popup (1, when);
388 TimeAxisView::size_click (GdkEventButton *ev)
390 popup_size_menu (ev->time);
395 TimeAxisView::popup_size_menu (guint32 when)
397 if (size_menu == 0) {
400 size_menu->popup (1, when);
404 TimeAxisView::set_selected (bool yn)
406 AxisView::set_selected (yn);
409 controls_ebox.set_name (controls_base_selected_name);
410 controls_frame.set_name (controls_base_selected_name);
412 /* propagate any existing selection, if the mode is right */
414 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
415 show_selection (editor.get_selection().time);
419 controls_ebox.set_name (controls_base_unselected_name);
420 controls_frame.set_name (controls_base_unselected_name);
424 /* children will be set for the yn=true case. but when deselecting
425 the editor only has a list of top-level trackviews, so we
426 have to do this here.
429 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
430 (*i)->set_selected (false);
438 TimeAxisView::build_size_menu ()
440 using namespace Menu_Helpers;
442 size_menu = new Menu;
443 size_menu->set_name ("ArdourContextMenu");
444 MenuList& items = size_menu->items();
446 items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
447 items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
448 items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
449 items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
450 items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height), Smaller)));
451 items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
455 TimeAxisView::build_display_menu ()
457 using namespace Menu_Helpers;
459 display_menu = new Menu;
460 display_menu->set_name ("ArdourContextMenu");
462 // Just let implementing classes define what goes into the manu
466 TimeAxisView::set_samples_per_unit (double spu)
468 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
469 (*i)->set_samples_per_unit (spu);
474 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
476 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
477 (*i)->show_timestretch (start, end);
482 TimeAxisView::hide_timestretch ()
484 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
485 (*i)->hide_timestretch ();
490 TimeAxisView::show_selection (TimeSelection& ts)
497 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
498 (*i)->show_selection (ts);
501 if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
502 while (!used_selection_rects.empty()) {
503 free_selection_rects.push_front (used_selection_rects.front());
504 used_selection_rects.pop_front();
505 free_selection_rects.front()->rect->hide();
506 free_selection_rects.front()->start_trim->hide();
507 free_selection_rects.front()->end_trim->hide();
509 selection_group->hide();
512 selection_group->show();
513 selection_group->raise_to_top();
515 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
516 jack_nframes_t start, end, cnt;
520 cnt = end - start + 1;
522 rect = get_selection_rect ((*i).id);
524 x1 = start / editor.get_current_zoom();
525 x2 = (start + cnt - 1) / editor.get_current_zoom();
528 gtk_object_set (GTK_OBJECT(rect->rect),
535 // trim boxes are at the top for selections
538 gtk_object_set (GTK_OBJECT(rect->start_trim),
541 "x2", x1 + trim_handle_size,
542 "y2", 1.0 + trim_handle_size,
544 gtk_object_set (GTK_OBJECT(rect->end_trim),
545 "x1", x2 - trim_handle_size,
548 "y2", 1.0 + trim_handle_size,
550 rect->start_trim->show();
551 rect->end_trim->show();
553 rect->start_trim->hide();
554 rect->end_trim->hide();
558 used_selection_rects.push_back (rect);
563 TimeAxisView::reshow_selection (TimeSelection& ts)
567 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
568 (*i)->show_selection (ts);
573 TimeAxisView::hide_selection ()
575 if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
576 while (!used_selection_rects.empty()) {
577 free_selection_rects.push_front (used_selection_rects.front());
578 used_selection_rects.pop_front();
579 free_selection_rects.front()->rect->hide();
580 free_selection_rects.front()->start_trim->hide();
581 free_selection_rects.front()->end_trim->hide();
583 selection_group->hide();
586 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
587 (*i)->hide_selection ();
592 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
594 /* find the selection rect this is for. we have the item corresponding to one
598 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
599 if ((*i)->start_trim == item || (*i)->end_trim == item) {
601 /* make one trim handle be "above" the other so that if they overlap,
602 the top one is the one last used.
605 (*i)->rect->raise_to_top ();
606 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
607 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
615 TimeAxisView::get_selection_rect (uint32_t id)
619 /* check to see if we already have a visible rect for this particular selection ID */
621 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
622 if ((*i)->id == id) {
627 /* ditto for the free rect list */
629 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
630 if ((*i)->id == id) {
631 free_selection_rects.erase (i);
636 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
638 if (free_selection_rects.empty()) {
640 rect = new SelectionRect;
642 rect->rect = new SimpleRect (*selection_group);
643 rect->rect->property_x1() = 0.0;
644 rect->rect->property_y1() = 0.0;
645 rect->rect->property_x2() = 0.0;
646 rect->rect->property_y2() = 0.0;
647 rect->rect->property_fill_color_rgba() = color_map[cSelectionRectFill];
648 rect->rect->property_outline_color_rgba() = color_map[cSelectionRectOutline];
650 rect->start_trim = new SimpleRect (*selection_group);
651 rect->start_trim->property_x1() = 0.0;
652 rect->start_trim->property_x2() = 0.0;
653 rect->start_trim->property_fill_color_rgba() = color_map[cSelectionStartFill];
654 rect->start_trim->property_outline_color_rgba() = color_map[cSelectionStartOutline];
656 rect->end_trim = new SimpleRect (*selection_group);
657 rect->end_trim->property_x1() = 0.0;
658 rect->end_trim->property_x2() = 0.0;
659 rect->end_trim->property_fill_color_rgba() = color_map[cSelectionEndFill];
660 rect->end_trim->property_outline_color_rgba() = color_map[cSelectionEndOutline];
662 free_selection_rects.push_front (rect);
664 rect->rect->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
665 rect->start_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
666 rect->end_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
669 rect = free_selection_rects.front();
671 free_selection_rects.pop_front();
676 TimeAxisView::is_child (TimeAxisView* tav)
678 return find (children.begin(), children.end(), tav) != children.end();
682 TimeAxisView::add_child (TimeAxisView* child)
684 children.push_back (child);
688 TimeAxisView::remove_child (TimeAxisView* child)
690 vector<TimeAxisView*>::iterator i;
692 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
698 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
704 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
710 TimeAxisView::touched (double top, double bot)
712 /* remember: this is X Window - coordinate space starts in upper left and moves down.
713 y_position is the "origin" or "top" of the track.
716 double mybot = y_position + height; // XXX need to include Editor::track_spacing;
718 return ((y_position <= bot && y_position >= top) ||
719 ((mybot <= bot) && (top < mybot)) ||
720 (mybot >= bot && y_position < top));
724 TimeAxisView::set_parent (TimeAxisView& p)
730 TimeAxisView::has_state () const
736 TimeAxisView::get_parent_with_state ()
742 if (parent->has_state()) {
746 return parent->get_parent_with_state ();
750 TimeAxisView::set_state (const XMLNode& node)
752 const XMLProperty *prop;
754 if ((prop = node.property ("track_height")) != 0) {
756 if (prop->value() == "largest") {
757 set_height (Largest);
758 } else if (prop->value() == "large") {
760 } else if (prop->value() == "larger") {
762 } else if (prop->value() == "normal") {
764 } else if (prop->value() == "smaller") {
765 set_height (Smaller);
766 } else if (prop->value() == "small") {
769 error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
779 TimeAxisView::reset_height()
781 set_height ((TrackHeight) height);
783 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
784 (*i)->set_height ((TrackHeight)(*i)->height);