From 69a6c4d747bb6f5d673f2c7505d393d20a75748a Mon Sep 17 00:00:00 2001 From: nick_m Date: Sun, 22 Mar 2015 00:31:32 +1100 Subject: [PATCH] Provide an image if there are no peaks. --- libs/canvas/canvas/wave_view.h | 1 + libs/canvas/wave_view.cc | 41 ++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/libs/canvas/canvas/wave_view.h b/libs/canvas/canvas/wave_view.h index 4820a3696e..4b6d6c5627 100644 --- a/libs/canvas/canvas/wave_view.h +++ b/libs/canvas/canvas/wave_view.h @@ -203,6 +203,7 @@ private: void get_image (Cairo::RefPtr& image, framepos_t start, framepos_t end, double& image_offset) const; ArdourCanvas::Coord y_extent (double, bool) const; + void draw_absent_image (Cairo::RefPtr&, ARDOUR::PeakData*, int) const; void draw_image (Cairo::RefPtr&, ARDOUR::PeakData*, int) const; }; diff --git a/libs/canvas/wave_view.cc b/libs/canvas/wave_view.cc index e559756e68..64b5975700 100644 --- a/libs/canvas/wave_view.cc +++ b/libs/canvas/wave_view.cc @@ -349,6 +349,38 @@ WaveView::y_extent (double s, bool /*round_to_lower_edge*/) const } } +void +WaveView::draw_absent_image (Cairo::RefPtr& image, PeakData* _peaks, int n_peaks) const +{ + Cairo::RefPtr stripe = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, _height); + + Cairo::RefPtr stripe_context = Cairo::Context::create (stripe); + stripe_context->set_antialias (Cairo::ANTIALIAS_NONE); + + uint32_t stripe_separation = 150; + double start = - floor (_height / stripe_separation) * stripe_separation; + int stripe_x = 0; + + while (start < n_peaks) { + + stripe_context->move_to (start, 0); + stripe_x = start + _height; + stripe_context->line_to (stripe_x, _height); + start += stripe_separation; + } + + stripe_context->set_source_rgba (1.0, 1.0, 1.0, 1.0); + stripe_context->set_line_cap (Cairo::LINE_CAP_SQUARE); + stripe_context->set_line_width(50); + stripe_context->stroke(); + + Cairo::RefPtr context = Cairo::Context::create (image); + + context->set_source_rgba (1.0, 1.0, 0.0, 0.3); + context->mask (stripe, 0, 0); + context->fill (); +} + struct LineTips { double top; double bot; @@ -761,14 +793,19 @@ WaveView::get_image (Cairo::RefPtr& image, framepos_t start boost::scoped_array peaks (new PeakData[n_peaks]); - _region->read_peaks (peaks.get(), n_peaks, + framecnt_t peaks_read; + peaks_read = _region->read_peaks (peaks.get(), n_peaks, sample_start, sample_end - sample_start, _channel, _samples_per_pixel); image = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, n_peaks, _height); - draw_image (image, peaks.get(), n_peaks); + if (peaks_read > 0) { + draw_image (image, peaks.get(), n_peaks); + } else { + draw_absent_image (image, peaks.get(), n_peaks); + } _image_cache[_region->audio_source ()].push_back (CacheEntry (_channel, _height, _region_amplitude, _fill_color, sample_start, sample_end, image));