2 Copyright (C) 2001-2007 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.
25 #include "gtkmm2ext/gtk_ui.h"
27 #include "pbd/compose.h"
28 #include "canvas/debug.h"
30 #include "ardour/midi_region.h"
31 #include "ardour/midi_source.h"
33 #include "automation_region_view.h"
34 #include "automation_streamview.h"
35 #include "automation_time_axis.h"
36 #include "gui_thread.h"
37 #include "public_editor.h"
38 #include "region_selection.h"
39 #include "region_view.h"
40 #include "rgb_macros.h"
41 #include "selection.h"
42 #include "ui_config.h"
47 using namespace ARDOUR;
48 using namespace ARDOUR_UI_UTILS;
50 using namespace Editing;
52 AutomationStreamView::AutomationStreamView (AutomationTimeAxisView& tv)
53 : StreamView (*dynamic_cast<RouteTimeAxisView*>(tv.get_parent()),
55 , _automation_view(tv)
56 , _pending_automation_state (Off)
58 CANVAS_DEBUG_NAME (_canvas_group, string_compose ("SV canvas group auto %1", tv.name()));
59 CANVAS_DEBUG_NAME (canvas_rect, string_compose ("SV canvas rectangle auto %1", tv.name()));
63 UIConfiguration::instance().ColorsChanged.connect(sigc::mem_fun(*this, &AutomationStreamView::color_handler));
66 AutomationStreamView::~AutomationStreamView ()
72 AutomationStreamView::add_region_view_internal (boost::shared_ptr<Region> region, bool wait_for_data, bool /*recording*/)
79 boost::shared_ptr<MidiRegion> mr = boost::dynamic_pointer_cast<MidiRegion>(region);
81 Source::Lock lock(mr->midi_source()->mutex());
82 mr->midi_source()->load_model(lock);
86 const boost::shared_ptr<AutomationControl> control = boost::dynamic_pointer_cast<AutomationControl> (
87 region->control (_automation_view.parameter(), true)
90 boost::shared_ptr<AutomationList> list;
92 list = boost::dynamic_pointer_cast<AutomationList>(control->list());
93 if (control->list() && !list) {
94 error << _("unable to display automation region for control without list") << endmsg;
99 AutomationRegionView *region_view;
100 std::list<RegionView *>::iterator i;
102 for (i = region_views.begin(); i != region_views.end(); ++i) {
103 if ((*i)->region() == region) {
105 /* great. we already have an AutomationRegionView for this Region. use it again. */
106 AutomationRegionView* arv = dynamic_cast<AutomationRegionView*>(*i);;
109 arv->line()->set_list (list);
111 (*i)->set_valid (true);
112 (*i)->enable_display (wait_for_data);
119 region_view = new AutomationRegionView (
120 _canvas_group, _automation_view, region,
121 _automation_view.parameter (), list,
122 _samples_per_pixel, region_color
125 region_view->init (false);
126 region_views.push_front (region_view);
128 /* follow global waveform setting */
131 region_view->enable_display(true);
132 // region_view->midi_region()->midi_source(0)->load_model();
135 display_region (region_view);
137 /* catch regionview going away */
138 region->DropReferences.connect (*this, invalidator (*this), boost::bind (&AutomationStreamView::remove_region_view, this, boost::weak_ptr<Region>(region)), gui_context());
140 /* setup automation state for this region */
141 boost::shared_ptr<AutomationLine> line = region_view->line ();
142 if (line && line->the_list()) {
143 line->the_list()->set_automation_state (automation_state ());
146 RegionViewAdded (region_view);
152 AutomationStreamView::display_region(AutomationRegionView* region_view)
154 region_view->line().reset();
158 AutomationStreamView::set_automation_state (AutoState state)
160 /* Setting the automation state for this view sets the state of all regions' lists to the same thing */
162 if (region_views.empty()) {
163 _pending_automation_state = state;
165 list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
167 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
168 if ((*i)->the_list()) {
169 (*i)->the_list()->set_automation_state (state);
176 AutomationStreamView::redisplay_track ()
178 // Flag region views as invalid and disable drawing
179 for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
180 (*i)->set_valid (false);
181 (*i)->enable_display(false);
184 // Add and display region views, and flag them as valid
185 if (_trackview.is_track()) {
186 _trackview.track()->playlist()->foreach_region (
187 sigc::hide_return (sigc::mem_fun (*this, &StreamView::add_region_view))
191 // Stack regions by layer, and remove invalid regions
197 AutomationStreamView::setup_rec_box ()
202 AutomationStreamView::color_handler ()
204 if (_trackview.is_midi_track()) {
205 canvas_rect->set_fill_color (UIConfiguration::instance().color_mod ("midi track base", "midi track base"));
207 canvas_rect->set_fill_color (UIConfiguration::instance().color ("midi bus base"));
212 AutomationStreamView::automation_state () const
214 if (region_views.empty()) {
215 return _pending_automation_state;
218 boost::shared_ptr<AutomationLine> line = ((AutomationRegionView*) region_views.front())->line ();
219 if (!line || !line->the_list()) {
223 return line->the_list()->automation_state ();
227 AutomationStreamView::has_automation () const
229 list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
231 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
232 if ((*i)->npoints() > 0) {
240 /** Our parent AutomationTimeAxisView calls this when the user requests a particular
241 * InterpolationStyle; tell the AutomationLists in our regions.
244 AutomationStreamView::set_interpolation (AutomationList::InterpolationStyle s)
246 list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
248 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
249 (*i)->the_list()->set_interpolation (s);
253 AutomationList::InterpolationStyle
254 AutomationStreamView::interpolation () const
256 if (region_views.empty()) {
257 return AutomationList::Linear;
260 AutomationRegionView* v = dynamic_cast<AutomationRegionView*> (region_views.front());
262 return v->line()->the_list()->interpolation ();
264 return AutomationList::Linear;
267 /** Clear all automation displayed in this view */
269 AutomationStreamView::clear ()
271 list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
273 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
278 /** @param start Start position in session frames.
279 * @param end End position in session frames.
280 * @param bot Bottom position expressed as a fraction of track height where 0 is the bottom of the track.
281 * @param top Top position expressed as a fraction of track height where 0 is the bottom of the track.
282 * NOTE: this y system is different to that for the StreamView method that this overrides, which is a little
286 AutomationStreamView::get_selectables (framepos_t start, framepos_t end, double botfrac, double topfrac, list<Selectable*>& results, bool /*within*/)
288 for (list<RegionView*>::iterator i = region_views.begin(); i != region_views.end(); ++i) {
289 AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*i);
291 arv->line()->get_selectables (start, end, botfrac, topfrac, results);
297 AutomationStreamView::set_selected_points (PointSelection& ps)
299 list<boost::shared_ptr<AutomationLine> > lines = get_lines ();
301 for (list<boost::shared_ptr<AutomationLine> >::iterator i = lines.begin(); i != lines.end(); ++i) {
302 (*i)->set_selected_points (ps);
306 list<boost::shared_ptr<AutomationLine> >
307 AutomationStreamView::get_lines () const
309 list<boost::shared_ptr<AutomationLine> > lines;
311 for (list<RegionView*>::const_iterator i = region_views.begin(); i != region_views.end(); ++i) {
312 AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*i);
314 lines.push_back (arv->line());
322 AutomationStreamView::paste (framepos_t pos,
323 unsigned paste_count,
325 boost::shared_ptr<ARDOUR::AutomationList> alist)
327 /* XXX: not sure how best to pick this; for now, just use the last region which starts before pos */
329 if (region_views.empty()) {
333 region_views.sort (RegionView::PositionOrder());
335 list<RegionView*>::const_iterator prev = region_views.begin ();
337 for (list<RegionView*>::const_iterator i = region_views.begin(); i != region_views.end(); ++i) {
338 if ((*i)->region()->position() > pos) {
344 boost::shared_ptr<Region> r = (*prev)->region ();
346 /* If *prev doesn't cover pos, it's no good */
347 if (r->position() > pos || ((r->position() + r->length()) < pos)) {
351 AutomationRegionView* arv = dynamic_cast<AutomationRegionView*> (*prev);
352 return arv ? arv->paste(pos, paste_count, times, alist) : false;