2 Copyright (C) 2007 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <pbd/memento_command.h>
21 #include "automation_region_view.h"
22 #include "public_editor.h"
26 AutomationRegionView::AutomationRegionView(ArdourCanvas::Group* parent,
27 AutomationTimeAxisView& time_axis,
28 boost::shared_ptr<ARDOUR::Region> region,
29 boost::shared_ptr<ARDOUR::AutomationList> list,
31 Gdk::Color& basic_color)
32 : RegionView(parent, time_axis, region, spu, basic_color)
35 _line = boost::shared_ptr<AutomationLine>(new AutomationLine(
36 list->parameter().to_string(), time_axis, *group, list));
39 _line->show_all_control_points();
42 group->signal_event().connect (mem_fun (this, &AutomationRegionView::canvas_event), false);
46 AutomationRegionView::init (Gdk::Color& basic_color, bool wfd)
48 _enable_display = false;
50 RegionView::init(basic_color, false);
52 compute_colors (basic_color);
54 reset_width_dependent_items ((double) _region->length() / samples_per_unit);
56 set_y_position_and_height (0, trackview.height);
58 _region->StateChanged.connect (mem_fun(*this, &AutomationRegionView::region_changed));
62 _enable_display = true;
66 AutomationRegionView::canvas_event(GdkEvent* ev)
68 if (ev->type == GDK_BUTTON_RELEASE) {
70 const nframes_t when = trackview.editor.pixel_to_frame((nframes_t)ev->button.x)
71 - _region->position();
72 add_automation_event(ev, when, ev->button.y);
79 AutomationRegionView::add_automation_event (GdkEvent* event, nframes_t when, double y)
82 cerr << "ERROR: AutomationRegionView::add_automation_event called without line" << endl;
87 AutomationTimeAxisView* const view = automation_view();
89 view->canvas_display->w2i (x, y);
91 /* compute vertical fractional position */
93 const double height = trackview.height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2;
94 y = 1.0 - (y / height);
98 _line->view_to_model_y (y);
100 view->session().begin_reversible_command (_("add automation event"));
101 XMLNode& before = _line->the_list()->get_state();
103 _line->the_list()->add (when, y);
105 XMLNode& after = _line->the_list()->get_state();
106 view->session().commit_reversible_command (new MementoCommand<ARDOUR::AutomationList>(
107 *_line->the_list(), &before, &after));
109 view->session().set_dirty ();
114 AutomationRegionView::set_y_position_and_height (double y, double h)
116 RegionView::set_y_position_and_height(y, h - 1);
119 _line->set_y_position_and_height ((uint32_t)y, (uint32_t) rint (h - NAME_HIGHLIGHT_SIZE));
123 AutomationRegionView::set_position (nframes_t pos, void* src, double* ignored)
125 // Do nothing, region parent will move us
128 return RegionView::set_position(pos, src, ignored); // FIXME: eventually...
133 AutomationRegionView::reset_width_dependent_items (double pixel_width)
135 RegionView::reset_width_dependent_items(pixel_width);
143 AutomationRegionView::region_resized (ARDOUR::Change what_changed)
145 RegionView::region_resized(what_changed);
153 AutomationRegionView::entered()
156 _line->track_entered();
161 AutomationRegionView::exited()
164 _line->track_exited();