maybe fix wine/windows vst support build
[ardour.git] / gtk2_ardour / audio_region_view.cc
1 /*
2     Copyright (C) 2001-2006 Paul Davis
3
4     This program is free software; you can r>edistribute 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.
8
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.
13
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.
17 */
18
19 #include <cmath>
20 #include <cassert>
21 #include <algorithm>
22
23 #include <gtkmm.h>
24
25 #include <gtkmm2ext/gtk_ui.h>
26
27 #include "ardour/playlist.h"
28 #include "ardour/audioregion.h"
29 #include "ardour/audiosource.h"
30 #include "ardour/profile.h"
31 #include "ardour/session.h"
32
33 #include "pbd/memento_command.h"
34 #include "pbd/stacktrace.h"
35
36 #include "evoral/Curve.hpp"
37
38 #include "streamview.h"
39 #include "audio_region_view.h"
40 #include "audio_time_axis.h"
41 #include "simplerect.h"
42 #include "simpleline.h"
43 #include "waveview.h"
44 #include "public_editor.h"
45 #include "audio_region_editor.h"
46 #include "region_gain_line.h"
47 #include "control_point.h"
48 #include "ghostregion.h"
49 #include "audio_time_axis.h"
50 #include "utils.h"
51 #include "rgb_macros.h"
52 #include "gui_thread.h"
53 #include "ardour_ui.h"
54
55 #include "i18n.h"
56
57 #define MUTED_ALPHA 10
58
59 using namespace std;
60 using namespace ARDOUR;
61 using namespace PBD;
62 using namespace Editing;
63 using namespace ArdourCanvas;
64
65 static const int32_t sync_mark_width = 9;
66
67 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
68                                   Gdk::Color const & basic_color)
69         : RegionView (parent, tv, r, spu, basic_color)
70         , sync_mark(0)
71         , fade_in_shape(0)
72         , fade_out_shape(0)
73         , fade_in_handle(0)
74         , fade_out_handle(0)
75         , fade_position_line(0)
76         , gain_line(0)
77         , _amplitude_above_axis(1.0)
78         , _flags(0)
79         , fade_color(0)
80 {
81 }
82
83
84 AudioRegionView::AudioRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, boost::shared_ptr<AudioRegion> r, double spu,
85                                   Gdk::Color const & basic_color, bool recording, TimeAxisViewItem::Visibility visibility)
86         : RegionView (parent, tv, r, spu, basic_color, recording, visibility)
87         , sync_mark(0)
88         , fade_in_shape(0)
89         , fade_out_shape(0)
90         , fade_in_handle(0)
91         , fade_out_handle(0)
92         , fade_position_line(0)
93         , gain_line(0)
94         , _amplitude_above_axis(1.0)
95         , _flags(0)
96         , fade_color(0)
97 {
98 }
99
100 AudioRegionView::AudioRegionView (const AudioRegionView& other, boost::shared_ptr<AudioRegion> other_region)
101         : RegionView (other, boost::shared_ptr<Region> (other_region))
102         , fade_in_shape(0)
103         , fade_out_shape(0)
104         , fade_in_handle(0)
105         , fade_out_handle(0)
106         , fade_position_line(0)
107         , gain_line(0)
108         , _amplitude_above_axis (other._amplitude_above_axis)
109         , _flags (other._flags)
110         , fade_color(0)
111 {
112         Gdk::Color c;
113         int r,g,b,a;
114
115         UINT_TO_RGBA (other.fill_color, &r, &g, &b, &a);
116         c.set_rgb_p (r/255.0, g/255.0, b/255.0);
117
118         init (c, true);
119 }
120
121 void
122 AudioRegionView::init (Gdk::Color const & basic_color, bool wfd)
123 {
124         // FIXME: Some redundancy here with RegionView::init.  Need to figure out
125         // where order is important and where it isn't...
126
127         RegionView::init (basic_color, wfd);
128
129         XMLNode *node;
130
131         _amplitude_above_axis = 1.0;
132         _flags                = 0;
133
134         if ((node = _region->extra_xml ("GUI")) != 0) {
135                 set_flags (node);
136         } else {
137                 _flags = WaveformVisible;
138                 store_flags ();
139         }
140
141         compute_colors (basic_color);
142
143         create_waves ();
144
145         fade_in_shape = new ArdourCanvas::Polygon (*group);
146         fade_in_shape->property_fill_color_rgba() = fade_color;
147         fade_in_shape->set_data ("regionview", this);
148
149         fade_out_shape = new ArdourCanvas::Polygon (*group);
150         fade_out_shape->property_fill_color_rgba() = fade_color;
151         fade_out_shape->set_data ("regionview", this);
152
153         if (!_recregion) {
154                 fade_in_handle = new ArdourCanvas::SimpleRect (*group);
155                 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fill_color, 0);
156                 fade_in_handle->property_outline_pixels() = 0;
157
158                 fade_in_handle->set_data ("regionview", this);
159
160                 fade_out_handle = new ArdourCanvas::SimpleRect (*group);
161                 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fill_color, 0);
162                 fade_out_handle->property_outline_pixels() = 0;
163
164                 fade_out_handle->set_data ("regionview", this);
165
166                 fade_position_line = new ArdourCanvas::SimpleLine (*group);
167                 fade_position_line->property_color_rgba() = 0xBBBBBBAA;
168                 fade_position_line->property_y1() = 7;
169                 fade_position_line->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
170
171                 fade_position_line->hide();
172         }
173
174         setup_fade_handle_positions ();
175
176         if (!trackview.session()->config.get_show_region_fades()) {
177                 set_fade_visibility (false);
178         }
179
180         const string line_name = _region->name() + ":gain";
181
182         if (!Profile->get_sae()) {
183                 gain_line = new AudioRegionGainLine (line_name, *this, *group, audio_region()->envelope());
184         }
185
186         if (Config->get_show_region_gain()) {
187                 gain_line->show ();
188         } else {
189                 gain_line->hide ();
190         }
191
192         gain_line->reset ();
193
194         set_height (trackview.current_height());
195
196         region_muted ();
197         region_sync_changed ();
198
199         region_resized (ARDOUR::bounds_change);
200         set_waveview_data_src();
201         region_locked ();
202         envelope_active_changed ();
203         fade_in_active_changed ();
204         fade_out_active_changed ();
205
206         reset_width_dependent_items (_pixel_width);
207
208         fade_in_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_event), fade_in_shape, this));
209         if (fade_in_handle) {
210                 fade_in_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_in_handle_event), fade_in_handle, this));
211         }
212
213         fade_out_shape->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_event), fade_out_shape, this));
214
215         if (fade_out_handle) {
216                 fade_out_handle->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_fade_out_handle_event), fade_out_handle, this));
217         }
218
219         set_colors ();
220
221         /* XXX sync mark drag? */
222 }
223
224 AudioRegionView::~AudioRegionView ()
225 {
226         in_destructor = true;
227
228         RegionViewGoingAway (this); /* EMIT_SIGNAL */
229
230         for (vector<GnomeCanvasWaveViewCache *>::iterator cache = wave_caches.begin(); cache != wave_caches.end() ; ++cache) {
231                 gnome_canvas_waveview_cache_destroy (*cache);
232         }
233
234         for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
235                 delete *i;
236         }
237
238         for (list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator i = feature_lines.begin(); i != feature_lines.end(); ++i) {
239                 delete ((*i).second);
240         }
241
242         /* all waveviews etc will be destroyed when the group is destroyed */
243
244         delete gain_line;
245 }
246
247 boost::shared_ptr<ARDOUR::AudioRegion>
248 AudioRegionView::audio_region() const
249 {
250         // "Guaranteed" to succeed...
251         return boost::dynamic_pointer_cast<AudioRegion>(_region);
252 }
253
254 void
255 AudioRegionView::region_changed (const PropertyChange& what_changed)
256 {
257         ENSURE_GUI_THREAD (*this, &AudioRegionView::region_changed, what_changed);
258         // cerr << "AudioRegionView::region_changed() called" << endl;
259
260         RegionView::region_changed (what_changed);
261
262         if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
263                 region_scale_amplitude_changed ();
264         }
265         if (what_changed.contains (ARDOUR::Properties::fade_in)) {
266                 fade_in_changed ();
267         }
268         if (what_changed.contains (ARDOUR::Properties::fade_out)) {
269                 fade_out_changed ();
270         }
271         if (what_changed.contains (ARDOUR::Properties::fade_in_active)) {
272                 fade_in_active_changed ();
273         }
274         if (what_changed.contains (ARDOUR::Properties::fade_out_active)) {
275                 fade_out_active_changed ();
276         }
277         if (what_changed.contains (ARDOUR::Properties::envelope_active)) {
278                 envelope_active_changed ();
279         }
280         if (what_changed.contains (ARDOUR::Properties::valid_transients)) {
281                 transients_changed ();
282         }
283 }
284
285 void
286 AudioRegionView::fade_in_changed ()
287 {
288         reset_fade_in_shape ();
289 }
290
291 void
292 AudioRegionView::fade_out_changed ()
293 {
294         reset_fade_out_shape ();
295 }
296 void
297 AudioRegionView::fade_in_active_changed ()
298 {
299         if (audio_region()->fade_in_active()) {
300                 fade_in_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90);                          // FIXME make a themeable colour
301                 fade_in_shape->property_width_pixels() = 1;
302         } else {
303                 fade_in_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20);                          // FIXME make a themeable colour
304                 fade_in_shape->property_width_pixels() = 1;
305         }
306 }
307
308 void
309 AudioRegionView::fade_out_active_changed ()
310 {
311         if (audio_region()->fade_out_active()) {
312                 fade_out_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,90);                         // FIXME make a themeable colour
313                 fade_out_shape->property_width_pixels() = 1;
314         } else {
315                 fade_out_shape->property_fill_color_rgba() = RGBA_TO_UINT(45,45,45,20);                         // FIXME make a themeable colour
316                 fade_out_shape->property_width_pixels() = 1;
317         }
318 }
319
320
321 void
322 AudioRegionView::region_scale_amplitude_changed ()
323 {
324         ENSURE_GUI_THREAD (*this, &AudioRegionView::region_scale_amplitude_changed)
325
326         for (uint32_t n = 0; n < waves.size(); ++n) {
327                 // force a reload of the cache
328                 waves[n]->property_data_src() = _region.get();
329         }
330 }
331
332 void
333 AudioRegionView::region_renamed ()
334 {
335         std::string str = RegionView::make_name ();
336
337         if (audio_region()->speed_mismatch (trackview.session()->frame_rate())) {
338                 str = string ("*") + str;
339         }
340
341         if (_region->muted()) {
342                 str = string ("!") + str;
343         }
344
345         set_item_name (str, this);
346         set_name_text (str);
347 }
348
349 void
350 AudioRegionView::region_resized (const PropertyChange& what_changed)
351 {
352         AudioGhostRegion* agr;
353
354         RegionView::region_resized(what_changed);
355         PropertyChange interesting_stuff;
356
357         interesting_stuff.add (ARDOUR::Properties::start);
358         interesting_stuff.add (ARDOUR::Properties::length);
359
360         if (what_changed.contains (interesting_stuff)) {
361
362                 for (uint32_t n = 0; n < waves.size(); ++n) {
363                         waves[n]->property_region_start() = _region->start();
364                 }
365
366                 for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
367                         if ((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
368
369                                 for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
370                                         (*w)->property_region_start() = _region->start();
371                                 }
372                         }
373                 }
374
375                 /* hide transient lines that extend beyond the region end */
376
377                 list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
378
379                 for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
380                         if (l->first > _region->length() - 1) {
381                                 l->second->hide();
382                         } else {
383                                 l->second->show();
384                         }
385                 }
386         }
387 }
388
389 void
390 AudioRegionView::reset_width_dependent_items (double pixel_width)
391 {
392         RegionView::reset_width_dependent_items(pixel_width);
393         assert(_pixel_width == pixel_width);
394
395         if (fade_in_handle) {
396                 if (pixel_width <= 6.0 || _height < 5.0 || !trackview.session()->config.get_show_region_fades()) {
397                         fade_in_handle->hide();
398                         fade_out_handle->hide();
399                 }
400                 else {
401                         fade_in_handle->show();
402                         fade_out_handle->show();
403                 }
404         }
405
406         AnalysisFeatureList analysis_features = _region->transients();
407         AnalysisFeatureList::const_iterator i;
408
409         list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
410
411         for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
412
413                 float x_pos = trackview.editor().frame_to_pixel (*i);
414
415                 ArdourCanvas::Points points;
416                 points.push_back(Gnome::Art::Point(x_pos, 2.0)); // first x-coord needs to be a non-normal value
417                 points.push_back(Gnome::Art::Point(x_pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
418
419                 (*l).first = *i;
420                 (*l).second->property_points() = points;
421         }
422
423         reset_fade_shapes ();
424 }
425
426 void
427 AudioRegionView::region_muted ()
428 {
429         RegionView::region_muted();
430
431         for (uint32_t n=0; n < waves.size(); ++n) {
432                 if (_region->muted()) {
433                         waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
434                 } else {
435                         waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
436                 }
437         }
438 }
439
440 void
441 AudioRegionView::setup_fade_handle_positions()
442 {
443         /* position of fade handle offset from the top of the region view */
444         double const handle_pos = 2;
445         /* height of fade handles */
446         double const handle_height = 5;
447
448         if (fade_in_handle) {
449                 fade_in_handle->property_y1() = handle_pos;
450                 fade_in_handle->property_y2() = handle_pos + handle_height;
451         }
452
453         if (fade_out_handle) {
454                 fade_out_handle->property_y1() = handle_pos;
455                 fade_out_handle->property_y2() = handle_pos + handle_height;
456         }
457 }
458
459 void
460 AudioRegionView::set_height (gdouble height)
461 {
462         RegionView::set_height (height);
463
464         uint32_t wcnt = waves.size();
465
466         for (uint32_t n = 0; n < wcnt; ++n) {
467                 gdouble ht;
468
469                 if (height < NAME_HIGHLIGHT_THRESH) {
470                         ht = ((height - 2 * wcnt) / (double) wcnt);
471                 } else {
472                         ht = (((height - 2 * wcnt) - NAME_HIGHLIGHT_SIZE) / (double) wcnt);
473                 }
474
475                 gdouble yoff = n * (ht + 1);
476
477                 waves[n]->property_height() = ht;
478                 waves[n]->property_y() = yoff + 2;
479         }
480
481         if (gain_line) {
482
483                 if ((height/wcnt) < NAME_HIGHLIGHT_THRESH) {
484                         gain_line->hide ();
485                 } else {
486                         if (Config->get_show_region_gain ()) {
487                                 gain_line->show ();
488                         }
489                 }
490
491                 gain_line->set_height ((uint32_t) rint (height - NAME_HIGHLIGHT_SIZE) - 2);
492         }
493
494         reset_fade_shapes ();
495
496         /* Update hights for any active feature lines */
497         list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
498
499         for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
500
501                 float pos_x = trackview.editor().frame_to_pixel((*l).first);
502
503                 ArdourCanvas::Points points;
504
505                 points.push_back(Gnome::Art::Point(pos_x, 2.0)); // first x-coord needs to be a non-normal value
506                 points.push_back(Gnome::Art::Point(pos_x, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
507
508                 (*l).second->property_points() = points;
509         }
510
511         if (fade_position_line) {
512
513                 if (height < NAME_HIGHLIGHT_THRESH) {
514                         fade_position_line->property_y2() = _height - 1;
515                 }
516                 else {
517                         fade_position_line->property_y2() = _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1;
518                 }
519         }
520
521         if (name_pixbuf) {
522                 name_pixbuf->raise_to_top();
523         }
524 }
525
526 void
527 AudioRegionView::reset_fade_shapes ()
528 {
529         reset_fade_in_shape ();
530         reset_fade_out_shape ();
531 }
532
533 void
534 AudioRegionView::reset_fade_in_shape ()
535 {
536         reset_fade_in_shape_width ((framecnt_t) audio_region()->fade_in()->back()->when);
537 }
538
539 void
540 AudioRegionView::reset_fade_in_shape_width (framecnt_t width)
541 {
542         if (fade_in_handle == 0) {
543                 return;
544         }
545
546         /* smallest size for a fade is 64 frames */
547
548         width = std::max ((framecnt_t) 64, width);
549
550         Points* points;
551
552         /* round here to prevent little visual glitches with sub-pixel placement */
553         double const pwidth = rint (width / samples_per_unit);
554         uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
555         double h;
556
557         if (_height < 5) {
558                 fade_in_shape->hide();
559                 fade_in_handle->hide();
560                 return;
561         }
562
563         double const handle_center = pwidth;
564
565         /* Put the fade in handle so that its left side is at the end-of-fade line */
566         fade_in_handle->property_x1() = handle_center;
567         fade_in_handle->property_x2() = handle_center + 6;
568
569         if (pwidth < 5) {
570                 fade_in_shape->hide();
571                 return;
572         }
573
574         if (trackview.session()->config.get_show_region_fades()) {
575                 fade_in_shape->show();
576         }
577
578         float curve[npoints];
579         audio_region()->fade_in()->curve().get_vector (0, audio_region()->fade_in()->back()->when, curve, npoints);
580
581         points = get_canvas_points ("fade in shape", npoints + 3);
582
583         if (_height >= NAME_HIGHLIGHT_THRESH) {
584                 h = _height - NAME_HIGHLIGHT_SIZE - 2;
585         } else {
586                 h = _height;
587         }
588
589         /* points *MUST* be in anti-clockwise order */
590
591         uint32_t pi, pc;
592         double xdelta = pwidth/npoints;
593
594         for (pi = 0, pc = 0; pc < npoints; ++pc) {
595                 (*points)[pi].set_x(1 + (pc * xdelta));
596                 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
597         }
598
599         /* fold back */
600
601         (*points)[pi].set_x(pwidth);
602         (*points)[pi++].set_y(2);
603
604         (*points)[pi].set_x(1);
605         (*points)[pi++].set_y(2);
606
607         /* connect the dots ... */
608
609         (*points)[pi] = (*points)[0];
610
611         fade_in_shape->property_points() = *points;
612         delete points;
613
614         /* ensure trim handle stays on top */
615         if (frame_handle_start) {
616                 frame_handle_start->raise_to_top();
617         }
618 }
619
620 void
621 AudioRegionView::reset_fade_out_shape ()
622 {
623         reset_fade_out_shape_width ((framecnt_t) audio_region()->fade_out()->back()->when);
624 }
625
626 void
627 AudioRegionView::reset_fade_out_shape_width (framecnt_t width)
628 {
629         if (fade_out_handle == 0) {
630                 return;
631         }
632
633         /* smallest size for a fade is 64 frames */
634
635         width = std::max ((framecnt_t) 64, width);
636
637         Points* points;
638
639         /* round here to prevent little visual glitches with sub-pixel placement */
640         double const pwidth = rint (width / samples_per_unit);
641         uint32_t npoints = std::min (gdk_screen_width(), (int) pwidth);
642         double h;
643
644         if (_height < 5) {
645                 fade_out_shape->hide();
646                 fade_out_handle->hide();
647                 return;
648         }
649
650         double const handle_center = (_region->length() - width) / samples_per_unit;
651
652         /* Put the fade out handle so that its right side is at the end-of-fade line;
653          * it's `one out' for precise pixel accuracy.
654          */
655         fade_out_handle->property_x1() = handle_center - 5;
656         fade_out_handle->property_x2() = handle_center + 1;
657
658         /* don't show shape if its too small */
659
660         if (pwidth < 5) {
661                 fade_out_shape->hide();
662                 return;
663         }
664
665         if (trackview.session()->config.get_show_region_fades()) {
666                 fade_out_shape->show();
667         }
668
669         float curve[npoints];
670         audio_region()->fade_out()->curve().get_vector (0, audio_region()->fade_out()->back()->when, curve, npoints);
671
672         if (_height >= NAME_HIGHLIGHT_THRESH) {
673                 h = _height - NAME_HIGHLIGHT_SIZE - 2;
674         } else {
675                 h = _height;
676         }
677
678         /* points *MUST* be in anti-clockwise order */
679
680         points = get_canvas_points ("fade out shape", npoints + 3);
681
682         uint32_t pi, pc;
683         double xdelta = pwidth/npoints;
684
685         for (pi = 0, pc = 0; pc < npoints; ++pc) {
686                 (*points)[pi].set_x(_pixel_width - pwidth + (pc * xdelta));
687                 (*points)[pi++].set_y(2 + (h - (curve[pc] * h)));
688         }
689
690         /* fold back */
691
692         (*points)[pi].set_x(_pixel_width);
693         (*points)[pi++].set_y(h);
694
695         (*points)[pi].set_x(_pixel_width);
696         (*points)[pi++].set_y(2);
697
698         /* connect the dots ... */
699
700         (*points)[pi] = (*points)[0];
701
702         fade_out_shape->property_points() = *points;
703         delete points;
704
705         /* ensure trim handle stays on top */
706         if (frame_handle_end) {
707                 frame_handle_end->raise_to_top();
708         }
709 }
710
711 void
712 AudioRegionView::set_samples_per_unit (gdouble spu)
713 {
714         RegionView::set_samples_per_unit (spu);
715
716         if (_flags & WaveformVisible) {
717                 for (uint32_t n=0; n < waves.size(); ++n) {
718                         waves[n]->property_samples_per_unit() = spu;
719                 }
720         }
721
722         if (gain_line) {
723                 gain_line->reset ();
724         }
725
726         reset_fade_shapes ();
727 }
728
729 void
730 AudioRegionView::set_amplitude_above_axis (gdouble spp)
731 {
732         for (uint32_t n=0; n < waves.size(); ++n) {
733                 waves[n]->property_amplitude_above_axis() = spp;
734         }
735 }
736
737 void
738 AudioRegionView::compute_colors (Gdk::Color const & basic_color)
739 {
740         RegionView::compute_colors (basic_color);
741
742         /* gain color computed in envelope_active_changed() */
743
744         fade_color = UINT_RGBA_CHANGE_A (fill_color, 120);
745 }
746
747 void
748 AudioRegionView::set_colors ()
749 {
750         RegionView::set_colors();
751
752         if (gain_line) {
753                 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
754         }
755
756         for (uint32_t n=0; n < waves.size(); ++n) {
757                 if (_region->muted()) {
758                         waves[n]->property_wave_color() = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
759                 } else {
760                         waves[n]->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
761                 }
762
763                 waves[n]->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
764                 waves[n]->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
765         }
766 }
767
768 void
769 AudioRegionView::set_waveform_visible (bool yn)
770 {
771         if (((_flags & WaveformVisible) != yn)) {
772                 if (yn) {
773                         for (uint32_t n=0; n < waves.size(); ++n) {
774                                 /* make sure the zoom level is correct, since we don't update
775                                    this when waveforms are hidden.
776                                 */
777                                 waves[n]->property_samples_per_unit() = samples_per_unit;
778                                 waves[n]->show();
779                         }
780                         _flags |= WaveformVisible;
781                 } else {
782                         for (uint32_t n=0; n < waves.size(); ++n) {
783                                 waves[n]->hide();
784                         }
785                         _flags &= ~WaveformVisible;
786                 }
787                 store_flags ();
788         }
789 }
790
791 void
792 AudioRegionView::temporarily_hide_envelope ()
793 {
794         if (gain_line) {
795                 gain_line->hide ();
796         }
797 }
798
799 void
800 AudioRegionView::unhide_envelope ()
801 {
802         if (gain_line) {
803                 gain_line->show ();
804         }
805 }
806
807 void
808 AudioRegionView::set_envelope_visible (bool yn)
809 {
810         if (gain_line) {
811                 if (yn) {
812                         gain_line->show ();
813                 } else {
814                         gain_line->hide ();
815                 }
816         }
817 }
818
819 void
820 AudioRegionView::create_waves ()
821 {
822         // cerr << "AudioRegionView::create_waves() called on " << this << endl;//DEBUG
823         RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
824
825         if (!atv.track()) {
826                 return;
827         }
828
829         ChanCount nchans = atv.track()->n_channels();
830
831         // cerr << "creating waves for " << _region->name() << " with wfd = " << wait_for_data
832         //              << " and channels = " << nchans.n_audio() << endl;
833
834         /* in tmp_waves, set up null pointers for each channel so the vector is allocated */
835         for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
836                 tmp_waves.push_back (0);
837         }
838
839         for (vector<ScopedConnection*>::iterator i = _data_ready_connections.begin(); i != _data_ready_connections.end(); ++i) {
840                 delete *i;
841         }
842
843         _data_ready_connections.clear ();
844
845         for (uint32_t i = 0; i < nchans.n_audio(); ++i) {
846                 _data_ready_connections.push_back (0);
847         }
848
849         for (uint32_t n = 0; n < nchans.n_audio(); ++n) {
850
851                 if (n >= audio_region()->n_channels()) {
852                         break;
853                 }
854
855                 wave_caches.push_back (WaveView::create_cache ());
856
857                 // cerr << "\tchannel " << n << endl;
858
859                 if (wait_for_data) {
860                         if (audio_region()->audio_source(n)->peaks_ready (boost::bind (&AudioRegionView::peaks_ready_handler, this, n), &_data_ready_connections[n], gui_context())) {
861                                 // cerr << "\tData is ready\n";
862                                 create_one_wave (n, true);
863                         } else {
864                                 // cerr << "\tdata is not ready\n";
865                                 // we'll get a PeaksReady signal from the source in the future
866                                 // and will call create_one_wave(n) then.
867                         }
868
869                 } else {
870                         // cerr << "\tdon't delay, display today!\n";
871                         create_one_wave (n, true);
872                 }
873
874         }
875 }
876
877 void
878 AudioRegionView::create_one_wave (uint32_t which, bool /*direct*/)
879 {
880         //cerr << "AudioRegionView::create_one_wave() called which: " << which << " this: " << this << endl;//DEBUG
881         RouteTimeAxisView& atv (*(dynamic_cast<RouteTimeAxisView*>(&trackview))); // ick
882         uint32_t nchans = atv.track()->n_channels().n_audio();
883         uint32_t n;
884         uint32_t nwaves = std::min (nchans, audio_region()->n_channels());
885         gdouble ht;
886
887         if (trackview.current_height() < NAME_HIGHLIGHT_THRESH) {
888                 ht = ((trackview.current_height()) / (double) nchans);
889         } else {
890                 ht = ((trackview.current_height() - NAME_HIGHLIGHT_SIZE) / (double) nchans);
891         }
892
893         gdouble yoff = which * ht;
894
895         WaveView *wave = new WaveView(*group);
896
897         wave->property_data_src() = (gpointer) _region.get();
898         wave->property_cache() =  wave_caches[which];
899         wave->property_cache_updater() = true;
900         wave->property_channel() =  which;
901         wave->property_length_function() = (gpointer) region_length_from_c;
902         wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
903         wave->property_peak_function() =  (gpointer) region_read_peaks_from_c;
904         wave->property_x() =  0.0;
905         wave->property_y() =  yoff;
906         wave->property_height() =  (double) ht;
907         wave->property_samples_per_unit() =  samples_per_unit;
908         wave->property_amplitude_above_axis() =  _amplitude_above_axis;
909
910         if (_recregion) {
911                 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
912                 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
913         } else {
914                 wave->property_wave_color() = _region->muted() ? UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA) : ARDOUR_UI::config()->canvasvar_WaveForm.get();
915                 wave->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
916         }
917
918         wave->property_clip_color() = ARDOUR_UI::config()->canvasvar_WaveFormClip.get();
919         wave->property_zero_color() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
920         wave->property_zero_line() = true;
921         wave->property_region_start() = _region->start();
922         wave->property_rectified() = (bool) (_flags & WaveformRectified);
923         wave->property_logscaled() = (bool) (_flags & WaveformLogScaled);
924
925         if (!(_flags & WaveformVisible)) {
926                 wave->hide();
927         }
928
929         /* note: calling this function is serialized by the lock
930            held in the peak building thread that signals that
931            peaks are ready for use *or* by the fact that it is
932            called one by one from the GUI thread.
933         */
934
935         if (which < nchans) {
936                 tmp_waves[which] = wave;
937         } else {
938                 /* n-channel track, >n-channel source */
939         }
940
941         /* see if we're all ready */
942
943         for (n = 0; n < nchans; ++n) {
944                 if (tmp_waves[n] == 0) {
945                         break;
946                 }
947         }
948
949         if (n == nwaves && waves.empty()) {
950                 /* all waves are ready */
951                 tmp_waves.resize(nwaves);
952
953                 waves = tmp_waves;
954                 tmp_waves.clear ();
955
956                 /* all waves created, don't hook into peaks ready anymore */
957                 delete _data_ready_connections[which];
958                 _data_ready_connections[which] = 0;
959         }
960 }
961
962 void
963 AudioRegionView::peaks_ready_handler (uint32_t which)
964 {
965         Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AudioRegionView::create_one_wave, this, which, false));
966         // cerr << "AudioRegionView::peaks_ready_handler() called on " << which << " this: " << this << endl;
967 }
968
969 void
970 AudioRegionView::add_gain_point_event (ArdourCanvas::Item *item, GdkEvent *ev)
971 {
972         if (gain_line == 0) {
973                 return;
974         }
975
976         double x, y;
977
978         /* don't create points that can't be seen */
979
980         set_envelope_visible (true);
981
982         x = ev->button.x;
983         y = ev->button.y;
984
985         item->w2i (x, y);
986
987         framepos_t fx = trackview.editor().pixel_to_frame (x);
988
989         if (fx > _region->length()) {
990                 return;
991         }
992
993         /* compute vertical fractional position */
994
995         y = 1.0 - (y / (_height - NAME_HIGHLIGHT_SIZE));
996
997         /* map using gain line */
998
999         gain_line->view_to_model_coord (x, y);
1000
1001         /* XXX STATEFUL: can't convert to stateful diff until we
1002            can represent automation data with it.
1003         */
1004
1005         trackview.session()->begin_reversible_command (_("add gain control point"));
1006         XMLNode &before = audio_region()->envelope()->get_state();
1007
1008         if (!audio_region()->envelope_active()) {
1009                 XMLNode &region_before = audio_region()->get_state();
1010                 audio_region()->set_envelope_active(true);
1011                 XMLNode &region_after = audio_region()->get_state();
1012                 trackview.session()->add_command (new MementoCommand<AudioRegion>(*(audio_region().get()), &region_before, &region_after));
1013         }
1014
1015         audio_region()->envelope()->add (fx, y);
1016
1017         XMLNode &after = audio_region()->envelope()->get_state();
1018         trackview.session()->add_command (new MementoCommand<AutomationList>(*audio_region()->envelope().get(), &before, &after));
1019         trackview.session()->commit_reversible_command ();
1020 }
1021
1022 void
1023 AudioRegionView::remove_gain_point_event (ArdourCanvas::Item *item, GdkEvent */*ev*/)
1024 {
1025         ControlPoint *cp = reinterpret_cast<ControlPoint *> (item->get_data ("control_point"));
1026         audio_region()->envelope()->erase (cp->model());
1027 }
1028
1029 void
1030 AudioRegionView::store_flags()
1031 {
1032         XMLNode *node = new XMLNode ("GUI");
1033
1034         node->add_property ("waveform-visible", (_flags & WaveformVisible) ? "yes" : "no");
1035         node->add_property ("waveform-rectified", (_flags & WaveformRectified) ? "yes" : "no");
1036         node->add_property ("waveform-logscaled", (_flags & WaveformLogScaled) ? "yes" : "no");
1037
1038         _region->add_extra_xml (*node);
1039 }
1040
1041 void
1042 AudioRegionView::set_flags (XMLNode* node)
1043 {
1044         XMLProperty *prop;
1045
1046         if ((prop = node->property ("waveform-visible")) != 0) {
1047                 if (string_is_affirmative (prop->value())) {
1048                         _flags |= WaveformVisible;
1049                 }
1050         }
1051
1052         if ((prop = node->property ("waveform-rectified")) != 0) {
1053                 if (string_is_affirmative (prop->value())) {
1054                         _flags |= WaveformRectified;
1055                 }
1056         }
1057
1058         if ((prop = node->property ("waveform-logscaled")) != 0) {
1059                 if (string_is_affirmative (prop->value())) {
1060                         _flags |= WaveformLogScaled;
1061                 }
1062         }
1063 }
1064
1065 void
1066 AudioRegionView::set_waveform_shape (WaveformShape shape)
1067 {
1068         bool yn;
1069
1070         /* this slightly odd approach is to leave the door open to
1071            other "shapes" such as spectral displays, etc.
1072         */
1073
1074         switch (shape) {
1075         case Rectified:
1076                 yn = true;
1077                 break;
1078
1079         default:
1080                 yn = false;
1081                 break;
1082         }
1083
1084         if (yn != (bool) (_flags & WaveformRectified)) {
1085                 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1086                         (*wave)->property_rectified() = yn;
1087                 }
1088
1089                 if (yn) {
1090                         _flags |= WaveformRectified;
1091                 } else {
1092                         _flags &= ~WaveformRectified;
1093                 }
1094                 store_flags ();
1095         }
1096 }
1097
1098 void
1099 AudioRegionView::set_waveform_scale (WaveformScale scale)
1100 {
1101         bool yn = (scale == Logarithmic);
1102
1103         if (yn != (bool) (_flags & WaveformLogScaled)) {
1104                 for (vector<WaveView *>::iterator wave = waves.begin(); wave != waves.end() ; ++wave) {
1105                         (*wave)->property_logscaled() = yn;
1106                 }
1107
1108                 if (yn) {
1109                         _flags |= WaveformLogScaled;
1110                 } else {
1111                         _flags &= ~WaveformLogScaled;
1112                 }
1113                 store_flags ();
1114         }
1115 }
1116
1117
1118 GhostRegion*
1119 AudioRegionView::add_ghost (TimeAxisView& tv)
1120 {
1121         RouteTimeAxisView* rtv = dynamic_cast<RouteTimeAxisView*>(&trackview);
1122         assert(rtv);
1123
1124         double unit_position = _region->position () / samples_per_unit;
1125         AudioGhostRegion* ghost = new AudioGhostRegion (tv, trackview, unit_position);
1126         uint32_t nchans;
1127
1128         nchans = rtv->track()->n_channels().n_audio();
1129
1130         for (uint32_t n = 0; n < nchans; ++n) {
1131
1132                 if (n >= audio_region()->n_channels()) {
1133                         break;
1134                 }
1135
1136                 WaveView *wave = new WaveView(*ghost->group);
1137
1138                 wave->property_data_src() = _region.get();
1139                 wave->property_cache() =  wave_caches[n];
1140                 wave->property_cache_updater() = false;
1141                 wave->property_channel() = n;
1142                 wave->property_length_function() = (gpointer)region_length_from_c;
1143                 wave->property_sourcefile_length_function() = (gpointer) sourcefile_length_from_c;
1144                 wave->property_peak_function() =  (gpointer) region_read_peaks_from_c;
1145                 wave->property_x() =  0.0;
1146                 wave->property_samples_per_unit() =  samples_per_unit;
1147                 wave->property_amplitude_above_axis() =  _amplitude_above_axis;
1148
1149                 wave->property_region_start() = _region->start();
1150
1151                 ghost->waves.push_back(wave);
1152         }
1153
1154         ghost->set_height ();
1155         ghost->set_duration (_region->length() / samples_per_unit);
1156         ghost->set_colors();
1157         ghosts.push_back (ghost);
1158
1159         return ghost;
1160 }
1161
1162 void
1163 AudioRegionView::entered (bool internal_editing)
1164 {
1165         trackview.editor().set_current_trimmable (_region);
1166         trackview.editor().set_current_movable (_region);
1167
1168         if (gain_line && Config->get_show_region_gain ()) {
1169                 gain_line->show_all_control_points ();
1170         }
1171
1172         if (fade_in_handle && !internal_editing) {
1173                 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 255);
1174                 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 255);
1175         }
1176 }
1177
1178 void
1179 AudioRegionView::exited ()
1180 {
1181         trackview.editor().set_current_trimmable (boost::shared_ptr<Trimmable>());
1182         trackview.editor().set_current_movable (boost::shared_ptr<Movable>());
1183
1184         if (gain_line) {
1185                 gain_line->hide_all_but_selected_control_points ();
1186         }
1187
1188         if (fade_in_handle) {
1189                 fade_in_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 0);
1190                 fade_out_handle->property_fill_color_rgba() = UINT_RGBA_CHANGE_A (fade_color, 0);
1191         }
1192 }
1193
1194 void
1195 AudioRegionView::envelope_active_changed ()
1196 {
1197         if (gain_line) {
1198                 gain_line->set_line_color (audio_region()->envelope_active() ? ARDOUR_UI::config()->canvasvar_GainLine.get() : ARDOUR_UI::config()->canvasvar_GainLineInactive.get());
1199         }
1200 }
1201
1202 void
1203 AudioRegionView::set_waveview_data_src()
1204 {
1205         AudioGhostRegion* agr;
1206         double unit_length= _region->length() / samples_per_unit;
1207
1208         for (uint32_t n = 0; n < waves.size(); ++n) {
1209                 // TODO: something else to let it know the channel
1210                 waves[n]->property_data_src() = _region.get();
1211         }
1212
1213         for (vector<GhostRegion*>::iterator i = ghosts.begin(); i != ghosts.end(); ++i) {
1214
1215                 (*i)->set_duration (unit_length);
1216
1217                 if((agr = dynamic_cast<AudioGhostRegion*>(*i)) != 0) {
1218                         for (vector<WaveView*>::iterator w = agr->waves.begin(); w != agr->waves.end(); ++w) {
1219                                 (*w)->property_data_src() = _region.get();
1220                         }
1221                 }
1222         }
1223
1224 }
1225
1226 void
1227 AudioRegionView::color_handler ()
1228 {
1229         //case cMutedWaveForm:
1230         //case cWaveForm:
1231         //case cWaveFormClip:
1232         //case cZeroLine:
1233         set_colors ();
1234
1235         //case cGainLineInactive:
1236         //case cGainLine:
1237         envelope_active_changed();
1238
1239 }
1240
1241 void
1242 AudioRegionView::set_frame_color ()
1243 {
1244         if (!frame) {
1245                 return;
1246         }
1247
1248         if (_region->opaque()) {
1249                 fill_opacity = 130;
1250         } else {
1251                 fill_opacity = 0;
1252         }
1253
1254         TimeAxisViewItem::set_frame_color ();
1255
1256         uint32_t wc;
1257         uint32_t fc;
1258
1259         if (_selected) {
1260                 if (_region->muted()) {
1261                         wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get(), MUTED_ALPHA);
1262                 } else {
1263                         wc = ARDOUR_UI::config()->canvasvar_SelectedWaveForm.get();
1264                 }
1265                 fc = ARDOUR_UI::config()->canvasvar_SelectedWaveFormFill.get();
1266         } else {
1267                 if (_recregion) {
1268                         if (_region->muted()) {
1269                                 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_RecWaveForm.get(), MUTED_ALPHA);
1270                         } else {
1271                                 wc = ARDOUR_UI::config()->canvasvar_RecWaveForm.get();
1272                         }
1273                         fc = ARDOUR_UI::config()->canvasvar_RecWaveFormFill.get();
1274                 } else {
1275                         if (_region->muted()) {
1276                                 wc = UINT_RGBA_CHANGE_A(ARDOUR_UI::config()->canvasvar_WaveForm.get(), MUTED_ALPHA);
1277                         } else {
1278                                 wc = ARDOUR_UI::config()->canvasvar_WaveForm.get();
1279                         }
1280                         fc = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
1281                 }
1282         }
1283
1284         for (vector<ArdourCanvas::WaveView*>::iterator w = waves.begin(); w != waves.end(); ++w) {
1285                 if (_region->muted()) {
1286                         (*w)->property_wave_color() = wc;
1287                 } else {
1288                         (*w)->property_wave_color() = wc;
1289                         (*w)->property_fill_color() = fc;
1290                 }
1291         }
1292 }
1293
1294 void
1295 AudioRegionView::set_fade_visibility (bool yn)
1296 {
1297         if (yn) {
1298                 if (fade_in_shape) {
1299                         fade_in_shape->show();
1300                 }
1301                 if (fade_out_shape) {
1302                         fade_out_shape->show ();
1303                 }
1304                 if (fade_in_handle) {
1305                         fade_in_handle->show ();
1306                 }
1307                 if (fade_out_handle) {
1308                         fade_out_handle->show ();
1309                 }
1310         } else {
1311                 if (fade_in_shape) {
1312                         fade_in_shape->hide();
1313                 }
1314                 if (fade_out_shape) {
1315                         fade_out_shape->hide ();
1316                 }
1317                 if (fade_in_handle) {
1318                         fade_in_handle->hide ();
1319                 }
1320                 if (fade_out_handle) {
1321                         fade_out_handle->hide ();
1322                 }
1323         }
1324 }
1325
1326 void
1327 AudioRegionView::update_coverage_frames (LayerDisplay d)
1328 {
1329         RegionView::update_coverage_frames (d);
1330
1331         if (fade_in_handle) {
1332                 fade_in_handle->raise_to_top ();
1333                 fade_out_handle->raise_to_top ();
1334         }
1335 }
1336
1337 void
1338 AudioRegionView::show_region_editor ()
1339 {
1340         if (editor == 0) {
1341                 editor = new AudioRegionEditor (trackview.session(), audio_region());
1342         }
1343
1344         editor->present ();
1345         editor->set_position (Gtk::WIN_POS_MOUSE);
1346         editor->show_all();
1347 }
1348
1349
1350 void
1351 AudioRegionView::show_fade_line (framepos_t pos)
1352 {
1353         fade_position_line->property_x1() = trackview.editor().frame_to_pixel (pos);
1354         fade_position_line->property_x2() = trackview.editor().frame_to_pixel (pos);
1355         fade_position_line->show ();
1356         fade_position_line->raise_to_top ();
1357 }
1358
1359 void
1360 AudioRegionView::hide_fade_line ()
1361 {
1362         fade_position_line->hide ();
1363 }
1364
1365
1366 void
1367 AudioRegionView::transients_changed ()
1368 {
1369         AnalysisFeatureList analysis_features = _region->transients();
1370
1371         while (feature_lines.size() < analysis_features.size()) {
1372
1373                 ArdourCanvas::Line* canvas_item = new ArdourCanvas::Line(*group);
1374
1375                 ArdourCanvas::Points points;
1376
1377                 points.push_back(Gnome::Art::Point(-1.0, 2.0)); // first x-coord needs to be a non-normal value
1378                 points.push_back(Gnome::Art::Point(1.0, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1379
1380                 canvas_item->property_points() = points;
1381                 canvas_item->property_width_pixels() = 1;
1382                 canvas_item->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ZeroLine.get();
1383                 canvas_item->property_first_arrowhead() = TRUE;
1384                 canvas_item->property_last_arrowhead() = TRUE;
1385                 canvas_item->property_arrow_shape_a() = 11.0;
1386                 canvas_item->property_arrow_shape_b() = 0.0;
1387                 canvas_item->property_arrow_shape_c() = 4.0;
1388
1389                 canvas_item->raise_to_top ();
1390                 canvas_item->show ();
1391
1392                 canvas_item->set_data ("regionview", this);
1393                 canvas_item->signal_event().connect (sigc::bind (sigc::mem_fun (PublicEditor::instance(), &PublicEditor::canvas_feature_line_event), canvas_item, this));
1394
1395                 feature_lines.push_back (make_pair(0, canvas_item));
1396         }
1397
1398         while (feature_lines.size() > analysis_features.size()) {
1399                 ArdourCanvas::Line* line = feature_lines.back().second;
1400                 feature_lines.pop_back ();
1401                 delete line;
1402         }
1403
1404         AnalysisFeatureList::const_iterator i;
1405         list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1406
1407         for (i = analysis_features.begin(), l = feature_lines.begin(); i != analysis_features.end() && l != feature_lines.end(); ++i, ++l) {
1408
1409                 ArdourCanvas::Points points;
1410
1411                 float *pos = new float;
1412                 *pos = trackview.editor().frame_to_pixel (*i);
1413
1414                 points.push_back(Gnome::Art::Point(*pos, 2.0)); // first x-coord needs to be a non-normal value
1415                 points.push_back(Gnome::Art::Point(*pos, _height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 1));
1416
1417                 (*l).second->property_points() = points;
1418                 (*l).second->set_data ("position", pos);
1419
1420                 (*l).first = *i;
1421         }
1422 }
1423
1424 void
1425 AudioRegionView::update_transient(float /*old_pos*/, float new_pos)
1426 {
1427         /* Find frame at old pos, calulate new frame then update region transients*/
1428         list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1429
1430         for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1431
1432                 /* Line has been updated in drag so we compare to new_pos */
1433
1434                 float* pos = (float*) (*l).second->get_data ("position");
1435
1436                 if (rint(new_pos) == rint(*pos)) {
1437
1438                     framepos_t old_frame = (*l).first;
1439                     framepos_t new_frame = trackview.editor().pixel_to_frame (new_pos);
1440
1441                     _region->update_transient (old_frame, new_frame);
1442
1443                     break;
1444                 }
1445         }
1446 }
1447
1448 void
1449 AudioRegionView::remove_transient(float pos)
1450 {
1451         /* Find frame at old pos, calulate new frame then update region transients*/
1452         list<std::pair<framepos_t, ArdourCanvas::Line*> >::iterator l;
1453
1454         for (l = feature_lines.begin(); l != feature_lines.end(); ++l) {
1455
1456                 /* Line has been updated in drag so we compare to new_pos */
1457                 float *line_pos = (float*) (*l).second->get_data ("position");
1458
1459                 if (rint(pos) == rint(*line_pos)) {
1460                     _region->remove_transient ((*l).first);
1461                     break;
1462                 }
1463         }
1464 }
1465
1466 void
1467 AudioRegionView::thaw_after_trim ()
1468 {
1469         RegionView::thaw_after_trim ();
1470
1471         unhide_envelope ();
1472 }