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 Gtkmm2ext::set_size_request_to_display_given_text (name_entry, N_("gTortnam"), 10, 10); // just represents a short name
93 name_label.set_name ("TrackLabel");
94 name_label.set_alignment (0.0, 0.5);
96 // name_hbox.set_border_width (2);
97 // name_hbox.set_spacing (5);
99 /* typically, either name_label OR name_entry are visible,
100 but not both. its up to derived classes to show/hide them as they
104 name_hbox.pack_start (name_label, true, true);
105 name_hbox.pack_start (name_entry, true, true);
108 controls_table.set_border_width (2);
109 controls_table.set_row_spacings (0);
110 controls_table.set_col_spacings (0);
111 controls_table.set_homogeneous (true);
112 controls_table.show ();
114 controls_table.attach (name_hbox, 0, 5, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND);
116 controls_table.show ();
118 controls_vbox.pack_start (controls_table, false, false);
119 controls_vbox.show ();
121 controls_ebox.set_name ("TimeAxisViewControlsBaseUnselected");
122 controls_ebox.add (controls_vbox);
123 controls_ebox.set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
124 controls_ebox.set_flags (Gtk::CAN_FOCUS);
126 controls_ebox.signal_button_release_event().connect (mem_fun (*this, &TimeAxisView::controls_ebox_button_release));
128 controls_lhs_pad.set_name ("TimeAxisViewControlsPadding");
129 controls_hbox.pack_start (controls_lhs_pad,false,false);
130 controls_hbox.pack_start (controls_ebox,true,true);
131 controls_hbox.show ();
133 controls_frame.add (controls_hbox);
134 controls_frame.set_name ("TimeAxisViewControlsBaseUnselected");
135 controls_frame.set_shadow_type (Gtk::SHADOW_OUT);
138 TimeAxisView::~TimeAxisView()
140 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
144 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
145 gtk_object_destroy (GTK_OBJECT((*i)->rect));
146 gtk_object_destroy (GTK_OBJECT((*i)->start_trim));
147 gtk_object_destroy (GTK_OBJECT((*i)->end_trim));
150 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
151 gtk_object_destroy (GTK_OBJECT((*i)->rect));
152 gtk_object_destroy (GTK_OBJECT((*i)->start_trim));
153 gtk_object_destroy (GTK_OBJECT((*i)->end_trim));
156 if (selection_group) {
157 delete selection_group;
161 if (canvas_display) {
162 delete canvas_display;
178 TimeAxisView::show_at (double y, int& nth, VBox *parent)
180 gdouble ix1, ix2, iy1, iy2;
181 effective_height = 0;
183 if (control_parent) {
184 control_parent->reorder_child (controls_frame, nth);
186 control_parent = parent;
187 parent->pack_start (controls_frame, false, false);
188 parent->reorder_child (controls_frame, nth);
191 controls_frame.show ();
192 controls_ebox.show ();
194 /* the coordinates used here are in the system of the
198 canvas_display->get_bounds (ix1, iy1, ix2, iy2);
199 Group* pg = canvas_display->property_parent();
206 canvas_display->move (0.0, y - iy1);
207 canvas_display->show();/* XXX not necessary */
212 effective_height = height;
214 /* now show children */
216 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
218 if ((*i)->marked_for_display()) {
219 (*i)->canvas_display->show();
222 if (GTK_OBJECT_FLAGS(GTK_OBJECT((*i)->canvas_display)) & GNOME_CANVAS_ITEM_VISIBLE) {
224 effective_height += (*i)->show_at (y + effective_height, nth, parent);
228 return effective_height;
232 TimeAxisView::controls_ebox_button_release (GdkEventButton* ev)
234 switch (ev->button) {
236 selection_click (ev);
240 popup_display_menu (ev->time);
244 if (Keyboard::no_modifier_keys_pressed (ev)) {
245 editor.scroll_tracks_up_line ();
246 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
252 if (Keyboard::no_modifier_keys_pressed (ev)) {
253 editor.scroll_tracks_down_line ();
254 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
266 TimeAxisView::selection_click (GdkEventButton* ev)
268 if (Keyboard::modifier_state_contains (ev->state, Keyboard::Shift)) {
270 if (editor.get_selection().selected (this)) {
271 editor.get_selection().remove (this);
273 editor.get_selection().add (this);
278 editor.get_selection().set (this);
283 TimeAxisView::hide ()
289 canvas_display->hide();
290 controls_frame.hide ();
292 if (control_parent) {
293 control_parent->remove (controls_frame);
300 /* now hide children */
302 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
310 TimeAxisView::step_height (bool bigger)
314 if (!bigger) set_height (Large);
317 if (bigger) set_height (Largest);
318 else set_height (Larger);
321 if (bigger) set_height (Large);
322 else set_height (Normal);
325 if (bigger) set_height (Larger);
326 else set_height (Smaller);
329 if (bigger) set_height (Normal);
330 else set_height (Small);
333 if (bigger) set_height (Smaller);
340 TimeAxisView::set_height (TrackHeight h)
342 height = (guint32) h;
343 controls_frame.set_size_request (-1, height);
345 if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
346 /* resize the selection rect */
347 show_selection (editor.get_selection().time);
350 // for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
351 // (*i)->set_height (h);
357 TimeAxisView::name_entry_button_press (GdkEventButton *ev)
359 if (ev->button == 3) {
366 TimeAxisView::name_entry_button_release (GdkEventButton *ev)
368 if (ev->button == 3) {
369 popup_display_menu (ev->time);
376 TimeAxisView::popup_display_menu (guint32 when)
378 if (display_menu == 0) {
379 build_display_menu ();
381 display_menu->popup (1, when);
385 TimeAxisView::size_click (GdkEventButton *ev)
387 popup_size_menu (ev->time);
392 TimeAxisView::popup_size_menu (guint32 when)
394 if (size_menu == 0) {
397 size_menu->popup (1, when);
401 TimeAxisView::set_selected (bool yn)
403 AxisView::set_selected (yn);
406 controls_ebox.set_name (controls_base_selected_name);
407 controls_frame.set_name (controls_base_selected_name);
409 /* propagate any existing selection, if the mode is right */
411 if (editor.current_mouse_mode() == Editing::MouseRange && !editor.get_selection().time.empty()) {
412 show_selection (editor.get_selection().time);
416 controls_ebox.set_name (controls_base_unselected_name);
417 controls_frame.set_name (controls_base_unselected_name);
421 /* children will be set for the yn=true case. but when deselecting
422 the editor only has a list of top-level trackviews, so we
423 have to do this here.
426 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
427 (*i)->set_selected (false);
435 TimeAxisView::build_size_menu ()
437 using namespace Menu_Helpers;
439 size_menu = new Menu;
440 size_menu->set_name ("ArdourContextMenu");
441 MenuList& items = size_menu->items();
443 items.push_back (MenuElem (_("Largest"), bind (mem_fun (*this, &TimeAxisView::set_height), Largest)));
444 items.push_back (MenuElem (_("Large"), bind (mem_fun (*this, &TimeAxisView::set_height), Large)));
445 items.push_back (MenuElem (_("Larger"), bind (mem_fun (*this, &TimeAxisView::set_height), Larger)));
446 items.push_back (MenuElem (_("Normal"), bind (mem_fun (*this, &TimeAxisView::set_height), Normal)));
447 items.push_back (MenuElem (_("Smaller"), bind (mem_fun (*this, &TimeAxisView::set_height), Smaller)));
448 items.push_back (MenuElem (_("Small"), bind (mem_fun (*this, &TimeAxisView::set_height), Small)));
452 TimeAxisView::build_display_menu ()
454 using namespace Menu_Helpers;
456 display_menu = new Menu;
457 display_menu->set_name ("ArdourContextMenu");
459 // Just let implementing classes define what goes into the manu
463 TimeAxisView::set_samples_per_unit (double spu)
465 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
466 (*i)->set_samples_per_unit (spu);
471 TimeAxisView::show_timestretch (jack_nframes_t start, jack_nframes_t end)
473 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
474 (*i)->show_timestretch (start, end);
479 TimeAxisView::hide_timestretch ()
481 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
482 (*i)->hide_timestretch ();
487 TimeAxisView::show_selection (TimeSelection& ts)
494 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
495 (*i)->show_selection (ts);
498 if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
499 while (!used_selection_rects.empty()) {
500 free_selection_rects.push_front (used_selection_rects.front());
501 used_selection_rects.pop_front();
502 free_selection_rects.front()->rect->hide();
503 free_selection_rects.front()->start_trim->hide();
504 free_selection_rects.front()->end_trim->hide();
506 selection_group->hide();
509 selection_group->show();
510 selection_group->raise_to_top();
512 for (list<AudioRange>::iterator i = ts.begin(); i != ts.end(); ++i) {
513 jack_nframes_t start, end, cnt;
517 cnt = end - start + 1;
519 rect = get_selection_rect ((*i).id);
521 x1 = start / editor.get_current_zoom();
522 x2 = (start + cnt - 1) / editor.get_current_zoom();
525 gtk_object_set (GTK_OBJECT(rect->rect),
532 // trim boxes are at the top for selections
535 gtk_object_set (GTK_OBJECT(rect->start_trim),
538 "x2", x1 + trim_handle_size,
539 "y2", 1.0 + trim_handle_size,
541 gtk_object_set (GTK_OBJECT(rect->end_trim),
542 "x1", x2 - trim_handle_size,
545 "y2", 1.0 + trim_handle_size,
547 rect->start_trim->show();
548 rect->end_trim->show();
550 rect->start_trim->hide();
551 rect->end_trim->hide();
555 used_selection_rects.push_back (rect);
560 TimeAxisView::reshow_selection (TimeSelection& ts)
564 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
565 (*i)->show_selection (ts);
570 TimeAxisView::hide_selection ()
572 if (GTK_OBJECT_FLAGS(GTK_OBJECT(selection_group)) & GNOME_CANVAS_ITEM_VISIBLE) {
573 while (!used_selection_rects.empty()) {
574 free_selection_rects.push_front (used_selection_rects.front());
575 used_selection_rects.pop_front();
576 free_selection_rects.front()->rect->hide();
577 free_selection_rects.front()->start_trim->hide();
578 free_selection_rects.front()->end_trim->hide();
580 selection_group->hide();
583 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
584 (*i)->hide_selection ();
589 TimeAxisView::order_selection_trims (ArdourCanvas::Item *item, bool put_start_on_top)
591 /* find the selection rect this is for. we have the item corresponding to one
595 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
596 if ((*i)->start_trim == item || (*i)->end_trim == item) {
598 /* make one trim handle be "above" the other so that if they overlap,
599 the top one is the one last used.
602 (*i)->rect->raise_to_top ();
603 (put_start_on_top ? (*i)->start_trim : (*i)->end_trim)->raise_to_top ();
604 (put_start_on_top ? (*i)->end_trim : (*i)->start_trim)->raise_to_top ();
612 TimeAxisView::get_selection_rect (uint32_t id)
616 /* check to see if we already have a visible rect for this particular selection ID */
618 for (list<SelectionRect*>::iterator i = used_selection_rects.begin(); i != used_selection_rects.end(); ++i) {
619 if ((*i)->id == id) {
624 /* ditto for the free rect list */
626 for (list<SelectionRect*>::iterator i = free_selection_rects.begin(); i != free_selection_rects.end(); ++i) {
627 if ((*i)->id == id) {
628 free_selection_rects.erase (i);
633 /* no existing matching rect, so go get a new one from the free list, or create one if there are none */
635 if (free_selection_rects.empty()) {
637 rect = new SelectionRect;
639 rect->rect = new SimpleRect (*selection_group);
640 rect->rect->property_x1() = 0.0;
641 rect->rect->property_y1() = 0.0;
642 rect->rect->property_x2() = 0.0;
643 rect->rect->property_y2() = 0.0;
644 rect->rect->property_fill_color_rgba() = color_map[cSelectionRectFill];
645 rect->rect->property_outline_color_rgba() = color_map[cSelectionRectOutline];
647 rect->start_trim = new SimpleRect (*selection_group);
648 rect->start_trim->property_x1() = 0.0;
649 rect->start_trim->property_x2() = 0.0;
650 rect->start_trim->property_fill_color_rgba() = color_map[cSelectionStartFill];
651 rect->start_trim->property_outline_color_rgba() = color_map[cSelectionStartOutline];
653 rect->end_trim = new SimpleRect (*selection_group);
654 rect->end_trim->property_x1() = 0.0;
655 rect->end_trim->property_x2() = 0.0;
656 rect->end_trim->property_fill_color_rgba() = color_map[cSelectionEndFill];
657 rect->end_trim->property_outline_color_rgba() = color_map[cSelectionEndOutline];
659 free_selection_rects.push_front (rect);
661 rect->rect->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_rect_event), rect->rect, rect));
662 rect->start_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_start_trim_event), rect->rect, rect));
663 rect->end_trim->signal_event().connect (bind (mem_fun (editor, &PublicEditor::canvas_selection_end_trim_event), rect->rect, rect));
666 rect = free_selection_rects.front();
668 free_selection_rects.pop_front();
673 TimeAxisView::is_child (TimeAxisView* tav)
675 return find (children.begin(), children.end(), tav) != children.end();
679 TimeAxisView::add_child (TimeAxisView* child)
681 children.push_back (child);
685 TimeAxisView::remove_child (TimeAxisView* child)
687 vector<TimeAxisView*>::iterator i;
689 if ((i = find (children.begin(), children.end(), child)) != children.end()) {
695 TimeAxisView::get_selectables (jack_nframes_t start, jack_nframes_t end, double top, double bot, list<Selectable*>& result)
701 TimeAxisView::get_inverted_selectables (Selection& sel, list<Selectable*>& result)
707 TimeAxisView::touched (double top, double bot)
709 /* remember: this is X Window - coordinate space starts in upper left and moves down.
710 y_position is the "origin" or "top" of the track.
713 double mybot = y_position + height; // XXX need to include Editor::track_spacing;
715 return ((y_position <= bot && y_position >= top) ||
716 ((mybot <= bot) && (top < mybot)) ||
717 (mybot >= bot && y_position < top));
721 TimeAxisView::set_parent (TimeAxisView& p)
727 TimeAxisView::has_state () const
733 TimeAxisView::get_parent_with_state ()
739 if (parent->has_state()) {
743 return parent->get_parent_with_state ();
747 TimeAxisView::set_state (const XMLNode& node)
749 const XMLProperty *prop;
751 if ((prop = node.property ("track_height")) != 0) {
753 if (prop->value() == "largest") {
754 set_height (Largest);
755 } else if (prop->value() == "large") {
757 } else if (prop->value() == "larger") {
759 } else if (prop->value() == "normal") {
761 } else if (prop->value() == "smaller") {
762 set_height (Smaller);
763 } else if (prop->value() == "small") {
766 error << string_compose(_("unknown track height name \"%1\" in XML GUI information"), prop->value()) << endmsg;
776 TimeAxisView::reset_height()
778 set_height ((TrackHeight) height);
780 for (vector<TimeAxisView*>::iterator i = children.begin(); i != children.end(); ++i) {
781 (*i)->set_height ((TrackHeight)(*i)->height);