2 Copyright (C) 2011-2013 Paul Davis
3 Author: Carl Hetherington <cth@carlh.net>
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.
22 #include <cairomm/cairomm.h>
24 #include "gtkmm2ext/utils.h"
26 #include "pbd/compose.h"
27 #include "pbd/signals.h"
28 #include "pbd/stacktrace.h"
30 #include "ardour/types.h"
31 #include "ardour/dB.h"
32 #include "ardour/audioregion.h"
34 #include "canvas/wave_view.h"
35 #include "canvas/utils.h"
36 #include "canvas/canvas.h"
37 #include "canvas/colors.h"
39 #include <gdkmm/general.h>
42 using namespace ARDOUR;
43 using namespace ArdourCanvas;
45 #define CACHE_HIGH_WATER (2)
47 std::map <boost::shared_ptr<AudioSource>, std::vector<WaveView::CacheEntry> > WaveView::_image_cache;
48 double WaveView::_global_gradient_depth = 0.6;
49 bool WaveView::_global_logscaled = false;
50 WaveView::Shape WaveView::_global_shape = WaveView::Normal;
51 bool WaveView::_global_show_waveform_clipping = true;
52 double WaveView::_clip_level = 0.98853;
54 PBD::Signal0<void> WaveView::VisualPropertiesChanged;
55 PBD::Signal0<void> WaveView::ClipLevelChanged;
57 WaveView::WaveView (Canvas* c, boost::shared_ptr<ARDOUR::AudioRegion> region)
61 , _samples_per_pixel (0)
64 , _zero_color (0xff0000ff)
65 , _clip_color (0xff0000ff)
66 , _logscaled (_global_logscaled)
67 , _shape (_global_shape)
68 , _gradient_depth (_global_gradient_depth)
69 , _shape_independent (false)
70 , _logscaled_independent (false)
71 , _gradient_depth_independent (false)
72 , _amplitude_above_axis (1.0)
73 , _region_amplitude (_region->scale_amplitude ())
75 , _region_start (region->start())
77 VisualPropertiesChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_visual_property_change, this));
78 ClipLevelChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_clip_level_change, this));
81 WaveView::WaveView (Item* parent, boost::shared_ptr<ARDOUR::AudioRegion> region)
85 , _samples_per_pixel (0)
88 , _zero_color (0xff0000ff)
89 , _clip_color (0xff0000ff)
90 , _logscaled (_global_logscaled)
91 , _shape (_global_shape)
92 , _gradient_depth (_global_gradient_depth)
93 , _shape_independent (false)
94 , _logscaled_independent (false)
95 , _gradient_depth_independent (false)
96 , _amplitude_above_axis (1.0)
97 , _region_amplitude (_region->scale_amplitude ())
98 , _region_start (region->start())
100 VisualPropertiesChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_visual_property_change, this));
101 ClipLevelChanged.connect_same_thread (invalidation_connection, boost::bind (&WaveView::handle_clip_level_change, this));
104 WaveView::~WaveView ()
106 invalidate_image_cache ();
110 WaveView::handle_visual_property_change ()
112 bool changed = false;
114 if (!_shape_independent && (_shape != global_shape())) {
115 _shape = global_shape();
119 if (!_logscaled_independent && (_logscaled != global_logscaled())) {
120 _logscaled = global_logscaled();
124 if (!_gradient_depth_independent && (_gradient_depth != global_gradient_depth())) {
125 _gradient_depth = global_gradient_depth();
130 begin_visual_change ();
131 invalidate_image_cache ();
132 end_visual_change ();
137 WaveView::handle_clip_level_change ()
139 begin_visual_change ();
140 invalidate_image_cache ();
141 end_visual_change ();
145 WaveView::set_fill_color (Color c)
147 if (c != _fill_color) {
148 begin_visual_change ();
149 invalidate_image_cache ();
150 Fill::set_fill_color (c);
151 end_visual_change ();
156 WaveView::set_outline_color (Color c)
158 if (c != _outline_color) {
159 begin_visual_change ();
160 invalidate_image_cache ();
161 Outline::set_outline_color (c);
162 end_visual_change ();
167 WaveView::set_samples_per_pixel (double samples_per_pixel)
169 if (samples_per_pixel != _samples_per_pixel) {
172 invalidate_image_cache ();
173 _samples_per_pixel = samples_per_pixel;
174 _bounding_box_dirty = true;
181 window_to_image (double wave_origin, double image_start)
183 return image_start - wave_origin;
187 _log_meter (float power, double lower_db, double upper_db, double non_linearity)
189 return (power < lower_db ? 0.0 : pow((power-lower_db)/(upper_db-lower_db), non_linearity));
193 alt_log_meter (float power)
195 return _log_meter (power, -192.0, 0.0, 8.0);
199 WaveView::set_clip_level (double dB)
201 const double clip_level = dB_to_coefficient (dB);
202 if (clip_level != _clip_level) {
203 _clip_level = clip_level;
209 WaveView::invalidate_image_cache ()
211 vector <uint32_t> deletion_list;
212 vector <CacheEntry> caches;
214 if (_image_cache.find (_region->audio_source ()) != _image_cache.end ()) {
215 caches = _image_cache.find (_region->audio_source ())->second;
220 for (uint32_t i = 0; i < caches.size (); ++i) {
222 if (_channel != caches[i].channel
223 || _height != caches[i].height
224 || _region_amplitude != caches[i].amplitude
225 || _fill_color != caches[i].fill_color) {
230 deletion_list.push_back (i);
234 while (deletion_list.size() > 0) {
235 caches[deletion_list.back ()].image.clear ();
236 caches.erase (caches.begin() + deletion_list.back());
237 deletion_list.pop_back();
240 if (caches.size () == 0) {
241 _image_cache.erase(_region->audio_source ());
243 _image_cache[_region->audio_source ()] = caches;
249 WaveView::consolidate_image_cache () const
251 list <uint32_t> deletion_list;
252 vector <CacheEntry> caches;
253 uint32_t other_entries = 0;
255 if (_image_cache.find (_region->audio_source ()) != _image_cache.end ()) {
256 caches = _image_cache.find (_region->audio_source ())->second;
259 for (uint32_t i = 0; i < caches.size (); ++i) {
261 if (_channel != caches[i].channel
262 || _height != caches[i].height
263 || _region_amplitude != caches[i].amplitude
264 || _fill_color != caches[i].fill_color) {
270 framepos_t segment_start = caches[i].start;
271 framepos_t segment_end = caches[i].end;
273 for (uint32_t j = i; j < caches.size (); ++j) {
275 if (i == j || _channel != caches[j].channel
276 || _height != caches[i].height
277 || _region_amplitude != caches[i].amplitude
278 || _fill_color != caches[i].fill_color) {
283 if (caches[j].start >= segment_start && caches[j].end <= segment_end) {
285 deletion_list.push_back (j);
290 deletion_list.sort ();
291 deletion_list.unique ();
293 while (deletion_list.size() > 0) {
294 caches[deletion_list.back ()].image.clear ();
295 caches.erase (caches.begin() + deletion_list.back ());
296 deletion_list.pop_back();
299 /* We don't care if this channel/height/amplitude has anything in the cache - just drop the Last Added entries
300 until we reach a size where there is a maximum of CACHE_HIGH_WATER + other entries.
303 while (caches.size() > CACHE_HIGH_WATER + other_entries) {
304 caches.front ().image.clear ();
305 caches.erase(caches.begin ());
308 if (caches.size () == 0) {
309 _image_cache.erase (_region->audio_source ());
311 _image_cache[_region->audio_source ()] = caches;
316 WaveView::y_extent (double s, bool /*round_to_lower_edge*/) const
318 /* it is important that this returns an integral value, so that we
319 * can ensure correct single pixel behaviour.
321 * we need (_height - max(wave_line_width))
322 * wave_line_width == 1 IFF top==bottom (1 sample per pixel or flat line)
323 * wave_line_width == 2 otherwise
324 * then round away from the zero line, towards peak
326 if (_shape == Rectified) {
327 // we only ever have 1 point and align to the bottom (not center)
328 return floor ((1.0 - s) * (_height - 2.0));
330 /* currently canvas rectangle is off-by-one and we
331 * cannot draw a pixel at 0 (-.5 .. +.5) without it being
332 * clipped. A value 1.0 (ideally one point at y=0) ends
333 * up a pixel down. and a value of -1.0 (ideally y = _height-1)
334 * currently is on the bottom separator line :(
335 * So to make the complete waveform appear centered in
336 * a region, we translate by +.5 (instead of -.5)
337 * and waste two pixel of height: -4 (instad of -2)
339 * This needs fixing in canvas/rectangle the intersect
340 * functions and probably a couple of other places as well...
344 pos = ceil ((1.0 - s) * .5 * (_height - 4.0));
346 pos = floor ((1.0 - s) * .5 * (_height - 4.0));
348 return min (_height - 4.0, (max (0.0, pos)));
359 LineTips() : top (0.0), bot (0.0), clip_max (false), clip_min (false) {}
363 Cairo::RefPtr<Cairo::ImageSurface> wave;
364 Cairo::RefPtr<Cairo::ImageSurface> outline;
365 Cairo::RefPtr<Cairo::ImageSurface> clip;
366 Cairo::RefPtr<Cairo::ImageSurface> zero;
369 wave (0), outline (0), clip (0), zero (0) {}
373 WaveView::draw_image (Cairo::RefPtr<Cairo::ImageSurface>& image, PeakData* _peaks, int n_peaks) const
378 images.wave = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, _height);
379 images.outline = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, _height);
380 images.clip = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, _height);
381 images.zero = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, _height);
383 Cairo::RefPtr<Cairo::Context> wave_context = Cairo::Context::create (images.wave);
384 Cairo::RefPtr<Cairo::Context> outline_context = Cairo::Context::create (images.outline);
385 Cairo::RefPtr<Cairo::Context> clip_context = Cairo::Context::create (images.clip);
386 Cairo::RefPtr<Cairo::Context> zero_context = Cairo::Context::create (images.zero);
388 boost::scoped_array<LineTips> tips (new LineTips[n_peaks]);
390 /* Clip level nominally set to -0.9dBFS to account for inter-sample
391 interpolation possibly clipping (value may be too low).
393 We adjust by the region's own gain (but note: not by any gain
394 automation or its gain envelope) so that clip indicators are closer
395 to providing data about on-disk data. This multiplication is
396 needed because the data we get from AudioRegion::read_peaks()
397 has been scaled by scale_amplitude() already.
400 const double clip_level = _clip_level * _region_amplitude;
402 if (_shape == WaveView::Rectified) {
404 /* each peak is a line from the bottom of the waveview
405 * to a point determined by max (_peaks[i].max,
410 for (int i = 0; i < n_peaks; ++i) {
412 tips[i].bot = height() - 1.0;
413 const double p = alt_log_meter (fast_coefficient_to_dB (max (fabs (_peaks[i].max), fabs (_peaks[i].min))));
414 tips[i].top = y_extent (p, false);
415 tips[i].spread = p * (_height - 1.0);
417 if (fabs (_peaks[i].max) >= clip_level) {
418 tips[i].clip_max = true;
421 if (fabs (_peaks[i].min) >= clip_level) {
422 tips[i].clip_max = true;
426 } else {for (int i = 0; i < n_peaks; ++i) {
428 tips[i].bot = height() - 1.0;
429 const double p = max(fabs (_peaks[i].max), fabs (_peaks[i].min));
430 tips[i].top = y_extent (p, false);
431 tips[i].spread = p * (_height - 2.0);
432 if (p >= clip_level) {
433 tips[i].clip_max = true;
442 for (int i = 0; i < n_peaks; ++i) {
443 double top = _peaks[i].max;
444 double bot = _peaks[i].min;
446 if (_peaks[i].max > 0 && _peaks[i].min > 0) {
447 if (fabs (_peaks[i].max) >= clip_level) {
448 tips[i].clip_max = true;
451 else if (_peaks[i].max < 0 && _peaks[i].min < 0) {
452 if (fabs (_peaks[i].min) >= clip_level) {
453 tips[i].clip_min = true;
456 if (fabs (_peaks[i].max) >= clip_level) {
457 tips[i].clip_max = true;
459 if (fabs (_peaks[i].min) >= clip_level) {
460 tips[i].clip_min = true;
465 top = alt_log_meter (fast_coefficient_to_dB (top));
466 } else if (top < 0.0) {
467 top =-alt_log_meter (fast_coefficient_to_dB (-top));
473 bot = alt_log_meter (fast_coefficient_to_dB (bot));
474 } else if (bot < 0.0) {
475 bot = -alt_log_meter (fast_coefficient_to_dB (-bot));
480 tips[i].top = y_extent (top, false);
481 tips[i].bot = y_extent (bot, true);
482 tips[i].spread = fabs (tips[i].top - tips[i].bot);
486 for (int i = 0; i < n_peaks; ++i) {
487 if (_peaks[i].max > 0 && _peaks[i].min > 0) {
488 if (fabs (_peaks[i].max) >= clip_level) {
489 tips[i].clip_max = true;
492 else if (_peaks[i].max < 0 && _peaks[i].min < 0) {
493 if (fabs (_peaks[i].min) >= clip_level) {
494 tips[i].clip_min = true;
497 if (fabs (_peaks[i].max) >= clip_level) {
498 tips[i].clip_max = true;
500 if (fabs (_peaks[i].min) >= clip_level) {
501 tips[i].clip_min = true;
505 tips[i].top = y_extent (_peaks[i].max, false);
506 tips[i].bot = y_extent (_peaks[i].min, true);
507 tips[i].spread = fabs (tips[i].top - tips[i].bot);
512 Color alpha_one = rgba_to_color (0, 0, 0, 1.0);
514 set_source_rgba (wave_context, alpha_one);
515 set_source_rgba (outline_context, alpha_one);
516 set_source_rgba (clip_context, alpha_one);
517 set_source_rgba (zero_context, alpha_one);
519 /* ensure single-pixel lines */
521 wave_context->set_line_width (1.0);
522 wave_context->translate (0.5, +0.5);
524 outline_context->set_line_cap (Cairo::LINE_CAP_ROUND);
525 outline_context->set_line_width (1.0);
526 outline_context->translate (0.5, +0.5);
528 clip_context->set_line_width (1.0);
529 clip_context->translate (0.5, +0.5);
531 zero_context->set_line_width (1.0);
532 zero_context->translate (0.5, +0.5);
534 /* the height of the clip-indicator should be at most 7 pixels,
535 * or 5% of the height of the waveview item.
538 const double clip_height = min (7.0, ceil (_height * 0.05));
540 /* There are 3 possible components to draw at each x-axis position: the
541 waveform "line", the zero line and an outline/clip indicator. We
542 have to decide which of the 3 to draw at each position, pixel by
543 pixel. This makes the rendering less efficient but it is the only
544 way I can see to do this correctly.
546 To avoid constant source swapping and stroking, we draw the components separately
547 onto four alpha only image surfaces for use as a mask.
549 With only 1 pixel of spread between the top and bottom of the line,
550 we just draw the upper outline/clip indicator.
552 With 2 pixels of spread, we draw the upper and lower outline clip
555 With 3 pixels of spread we draw the upper and lower outline/clip
556 indicators and at least 1 pixel of the waveform line.
558 With 5 pixels of spread, we draw all components.
560 We can do rectified as two separate passes because we have a much
561 easier decision regarding whether to draw the waveform line. We
562 always draw the clip/outline indicators.
565 if (_shape == WaveView::Rectified) {
567 for (int i = 0; i < n_peaks; ++i) {
571 if (tips[i].spread >= 1.0) {
572 wave_context->move_to (i, tips[i].top);
573 wave_context->line_to (i, tips[i].bot);
576 if (_global_show_waveform_clipping && (tips[i].clip_max)) {
577 clip_context->move_to (i, tips[i].top);
578 /* clip-indicating upper terminal line */
579 clip_context->rel_line_to (0, min (clip_height, ceil(tips[i].spread + .5)));
581 outline_context->move_to (i, tips[i].top);
582 /* normal upper terminal dot */
583 outline_context->close_path ();
587 wave_context->stroke ();
588 clip_context->stroke ();
589 outline_context->stroke ();
592 const double height_2 = (_height - 4.0) * .5;
594 for (int i = 0; i < n_peaks; ++i) {
598 if (tips[i].spread >= 2.0) {
599 wave_context->move_to (i, tips[i].top);
600 wave_context->line_to (i, tips[i].bot);
603 if (tips[i-1].top + 2 < tips[i].bot) {
604 wave_context->move_to (i-1, tips[i-1].top);
605 wave_context->line_to (i, tips[i].bot);
607 else if (tips[i-1].bot > tips[i].top + 2) {
608 wave_context->move_to (i-1, tips[i-1].bot);
609 wave_context->line_to (i, tips[i].top);
615 if (tips[i].spread >= 5.0 && show_zero_line()) {
616 zero_context->move_to (i, floor(height_2));
617 zero_context->rel_line_to (1.0, 0);
620 if (tips[i].spread > 1.0) {
621 /* lower outline/clip indicator */
622 if (_global_show_waveform_clipping && tips[i].clip_min) {
623 clip_context->move_to (i, tips[i].bot);
624 /* clip-indicating lower terminal line */
625 const double sign = tips[i].bot > height_2 ? -1 : 1;
626 clip_context->rel_line_to (0, sign * min (clip_height, ceil (tips[i].spread + .5)));
628 outline_context->move_to (i, tips[i].bot);
629 /* normal lower terminal dot */
630 outline_context->close_path ();
633 if (tips[i].clip_min) {
634 // make sure we draw the clip
635 tips[i].clip_max = true;
639 /* upper outline/clip indicator */
640 if (_global_show_waveform_clipping && tips[i].clip_max) {
641 clip_context->move_to (i, tips[i].top);
642 /* clip-indicating upper terminal line */
643 const double sign = tips[i].top > height_2 ? -1 : 1;
644 clip_context->rel_line_to (0, sign * min(clip_height, ceil(tips[i].spread + .5)));
646 outline_context->move_to (i, tips[i].top);
647 /* normal upper terminal dot */
648 outline_context->close_path ();
652 wave_context->stroke ();
653 outline_context->stroke ();
654 clip_context->stroke ();
655 zero_context->stroke ();
658 Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (image);
660 /* Here we set a source colour and use the various components as a mask. */
662 if (gradient_depth() != 0.0) {
664 Cairo::RefPtr<Cairo::LinearGradient> gradient (Cairo::LinearGradient::create (0, 0, 0, _height));
670 if (_shape == Rectified) {
680 color_to_rgba (_fill_color, r, g, b, a);
681 gradient->add_color_stop_rgba (stops[1], r, g, b, a);
682 /* generate a new color for the middle of the gradient */
684 color_to_hsv (_fill_color, h, s, v);
685 /* change v towards white */
686 v *= 1.0 - gradient_depth();
687 Color center = hsva_to_color (h, s, v, a);
688 color_to_rgba (center, r, g, b, a);
690 gradient->add_color_stop_rgba (stops[0], r, g, b, a);
691 gradient->add_color_stop_rgba (stops[2], r, g, b, a);
693 context->set_source (gradient);
695 set_source_rgba (context, _fill_color);
698 context->mask (images.wave, 0, 0);
701 set_source_rgba (context, _outline_color);
702 context->mask (images.outline, 0, 0);
705 set_source_rgba (context, _clip_color);
706 context->mask (images.clip, 0, 0);
709 set_source_rgba (context, _zero_color);
710 context->mask (images.zero, 0, 0);
716 WaveView::get_image (Cairo::RefPtr<Cairo::ImageSurface>& image, framepos_t start, framepos_t end, double& image_offset) const
718 vector <CacheEntry> caches;
720 if (_image_cache.find (_region->audio_source ()) != _image_cache.end ()) {
722 caches = _image_cache.find (_region->audio_source ())->second;
725 /* Find a suitable ImageSurface.
727 for (uint32_t i = 0; i < caches.size (); ++i) {
729 if (_channel != caches[i].channel
730 || _height != caches[i].height
731 || _region_amplitude != caches[i].amplitude
732 || _fill_color != caches[i].fill_color) {
737 framepos_t segment_start = caches[i].start;
738 framepos_t segment_end = caches[i].end;
740 if (end <= segment_end && start >= segment_start) {
741 image_offset = (segment_start - _region_start) / _samples_per_pixel;
742 image = caches[i].image;
748 consolidate_image_cache ();
750 /* sample position is canonical here, and we want to generate
751 * an image that spans about twice the canvas width
754 const framepos_t center = start + ((end - start) / 2);
755 const framecnt_t canvas_samples = _canvas->visible_area().width() * _samples_per_pixel; /* one canvas width */
757 /* we can request data from anywhere in the Source, between 0 and its length
760 framepos_t sample_start = max ((framepos_t) 0, (center - canvas_samples));
761 framepos_t sample_end = min (center + canvas_samples, _region->source_length (0));
763 const int n_peaks = llrintf ((sample_end - sample_start)/ (double) _samples_per_pixel);
765 boost::scoped_array<ARDOUR::PeakData> peaks (new PeakData[n_peaks]);
767 _region->read_peaks (peaks.get(), n_peaks,
768 sample_start, sample_end - sample_start,
772 image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, n_peaks, _height);
774 draw_image (image, peaks.get(), n_peaks);
776 _image_cache[_region->audio_source ()].push_back (CacheEntry (_channel, _height, _region_amplitude, _fill_color, sample_start, sample_end, image));
778 image_offset = (sample_start - _region->start()) / _samples_per_pixel;
780 //cerr << "_image_cache size is : " << _image_cache.size() << " entries for this audiosource : " << _image_cache.find (_region->audio_source ())->second.size() << endl;
786 WaveView::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
788 assert (_samples_per_pixel != 0);
794 Rect self = item_to_window (Rect (0.0, 0.0, _region->length() / _samples_per_pixel, _height));
795 boost::optional<Rect> d = self.intersection (area);
803 /* window coordinates - pixels where x=0 is the left edge of the canvas
804 * window. We round down in case we were asked to
805 * draw "between" pixels at the start and/or end.
808 double draw_start = floor (draw.x0);
809 const double draw_end = floor (draw.x1);
811 // cerr << "Need to draw " << draw_start << " .. " << draw_end << endl;
813 /* image coordnates: pixels where x=0 is the start of this waveview,
814 * wherever it may be positioned. thus image_start=N means "an image
815 * that beings N pixels after the start of region that this waveview is
819 const framepos_t image_start = window_to_image (self.x0, draw_start);
820 const framepos_t image_end = window_to_image (self.x0, draw_end);
822 // cerr << "Image/WV space: " << image_start << " .. " << image_end << endl;
824 /* sample coordinates - note, these are not subject to rounding error */
825 framepos_t sample_start = _region_start + (image_start * _samples_per_pixel);
826 framepos_t sample_end = _region_start + (image_end * _samples_per_pixel);
828 // cerr << "Sample space: " << sample_start << " .. " << sample_end << endl;
830 Cairo::RefPtr<Cairo::ImageSurface> image;
831 double image_offset = 0;
833 get_image (image, sample_start, sample_end, image_offset);
835 // cerr << "Offset into image to place at zero: " << image_offset << endl;
837 if (_start_shift && (sample_start == _region_start) && (self.x0 == draw.x0)) {
838 /* we are going to draw the first pixel for this region, but
839 we may not want this to overlap a border around the
840 waveform. If so, _start_shift will be set.
842 //cerr << name.substr (23) << " ss = " << sample_start << " rs = " << _region_start << " sf = " << _start_shift << " ds = " << draw_start << " self = " << self << " draw = " << draw << endl;
843 //draw_start += _start_shift;
844 //image_offset += _start_shift;
847 context->rectangle (draw_start, draw.y0, draw_end - draw_start, draw.height());
849 /* round image origin position to an exact pixel in device space to
853 double x = self.x0 + image_offset;
855 context->user_to_device (x, y);
858 context->device_to_user (x, y);
860 context->set_source (image, x, y);
866 WaveView::compute_bounding_box () const
869 _bounding_box = Rect (0.0, 0.0, _region->length() / _samples_per_pixel, _height);
871 _bounding_box = boost::optional<Rect> ();
874 _bounding_box_dirty = false;
878 WaveView::set_height (Distance height)
880 if (height != _height) {
883 invalidate_image_cache ();
886 _bounding_box_dirty = true;
892 WaveView::set_channel (int channel)
894 if (channel != _channel) {
897 invalidate_image_cache ();
900 _bounding_box_dirty = true;
906 WaveView::set_logscaled (bool yn)
908 if (_logscaled != yn) {
909 begin_visual_change ();
910 invalidate_image_cache ();
912 end_visual_change ();
917 WaveView::gain_changed ()
919 begin_visual_change ();
920 invalidate_image_cache ();
921 _region_amplitude = _region->scale_amplitude ();
922 end_visual_change ();
926 WaveView::set_zero_color (Color c)
928 if (_zero_color != c) {
929 begin_visual_change ();
930 invalidate_image_cache ();
932 end_visual_change ();
937 WaveView::set_clip_color (Color c)
939 if (_clip_color != c) {
940 begin_visual_change ();
941 invalidate_image_cache ();
943 end_visual_change ();
948 WaveView::set_show_zero_line (bool yn)
950 if (_show_zero != yn) {
951 begin_visual_change ();
952 invalidate_image_cache ();
954 end_visual_change ();
959 WaveView::set_shape (Shape s)
962 begin_visual_change ();
963 invalidate_image_cache ();
965 end_visual_change ();
970 WaveView::set_amplitude_above_axis (double a)
972 if (_amplitude_above_axis != a) {
973 begin_visual_change ();
974 invalidate_image_cache ();
975 _amplitude_above_axis = a;
976 end_visual_change ();
981 WaveView::set_global_shape (Shape s)
983 if (_global_shape != s) {
985 VisualPropertiesChanged (); /* EMIT SIGNAL */
990 WaveView::set_global_logscaled (bool yn)
992 if (_global_logscaled != yn) {
993 _global_logscaled = yn;
994 VisualPropertiesChanged (); /* EMIT SIGNAL */
999 WaveView::set_region_start (frameoffset_t start)
1005 if (_region_start == start) {
1010 _region_start = start;
1011 _bounding_box_dirty = true;
1016 WaveView::region_resized ()
1018 /* Called when the region start or end (thus length) has changed.
1026 _region_start = _region->start();
1027 _bounding_box_dirty = true;
1032 WaveView::set_global_gradient_depth (double depth)
1034 if (_global_gradient_depth != depth) {
1035 _global_gradient_depth = depth;
1036 VisualPropertiesChanged (); /* EMIT SIGNAL */
1041 WaveView::set_global_show_waveform_clipping (bool yn)
1043 if (_global_show_waveform_clipping != yn) {
1044 _global_show_waveform_clipping = yn;
1045 ClipLevelChanged ();
1050 WaveView::set_start_shift (double pixels)
1056 begin_visual_change ();
1057 _start_shift = pixels;
1058 end_visual_change ();