WaveViewCache* WaveView::images = 0;
gint WaveView::drawing_thread_should_quit = 0;
Glib::Threads::Mutex WaveView::request_queue_lock;
WaveViewCache* WaveView::images = 0;
gint WaveView::drawing_thread_should_quit = 0;
Glib::Threads::Mutex WaveView::request_queue_lock;
Glib::Threads::Cond WaveView::request_cond;
Glib::Threads::Thread* WaveView::_drawing_thread = 0;
WaveView::DrawingRequestQueue WaveView::request_queue;
Glib::Threads::Cond WaveView::request_cond;
Glib::Threads::Thread* WaveView::_drawing_thread = 0;
WaveView::DrawingRequestQueue WaveView::request_queue;
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("queue draw for %1 at %2 (vis = %3 CR %4)\n", this, g_get_monotonic_time(), visible(), current_request));
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("queue draw for %1 at %2 (vis = %3 CR %4)\n", this, g_get_monotonic_time(), visible(), current_request));
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 invalidates image cache and cancels current request\n", this));
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 invalidates image cache and cancels current request\n", this));
So, a sample value of 1.0 (0dbFS) will be computed as:
(1.0 - 1.0) * 0.5 * effective_height
So, a sample value of 1.0 (0dbFS) will be computed as:
(1.0 - 1.0) * 0.5 * effective_height
tips.top = min (effective_height, max (0.0, tips.top));
tips.bot = min (effective_height, max (0.0, tips.bot));
}
tips.top = min (effective_height, max (0.0, tips.top));
tips.bot = min (effective_height, max (0.0, tips.bot));
}
compute_tips (p, tips[i]);
tips[i].spread = tips[i].bot - tips[i].top;
}
compute_tips (p, tips[i]);
tips[i].spread = tips[i].bot - tips[i].top;
}
Color alpha_one = rgba_to_color (0, 0, 0, 1.0);
set_source_rgba (wave_context, alpha_one);
Color alpha_one = rgba_to_color (0, 0, 0, 1.0);
set_source_rgba (wave_context, alpha_one);
wave_context->move_to (i, tips[i].top);
wave_context->line_to (i, tips[i].bot);
}
wave_context->move_to (i, tips[i].top);
wave_context->line_to (i, tips[i].bot);
}
/* draw square waves and other discontiguous points clearly */
if (i > 0) {
if (tips[i-1].top + 2 < tips[i].top) {
/* draw square waves and other discontiguous points clearly */
if (i > 0) {
if (tips[i-1].top + 2 < tips[i].top) {
or the waveform line does not cross zero line */
if (show_zero_line() && ((tips[i].spread >= 5.0) || (tips[i].top > height_zero ) || (tips[i].bot < height_zero)) ) {
or the waveform line does not cross zero line */
if (show_zero_line() && ((tips[i].spread >= 5.0) || (tips[i].top > height_zero ) || (tips[i].bot < height_zero)) ) {
Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (image);
/* Here we set a source colour and use the various components as a mask. */
Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (image);
/* Here we set a source colour and use the various components as a mask. */
boost::shared_ptr<WaveViewCache::Entry>
WaveView::cache_request_result (boost::shared_ptr<WaveViewThreadRequest> req) const
{
boost::shared_ptr<WaveViewCache::Entry>
WaveView::cache_request_result (boost::shared_ptr<WaveViewThreadRequest> req) const
{
images->consolidate_image_cache (_region->audio_source (_channel),
req->channel, req->height, req->amplitude,
req->fill_color, req->samples_per_pixel);
images->consolidate_image_cache (_region->audio_source (_channel),
req->channel, req->height, req->amplitude,
req->fill_color, req->samples_per_pixel);
/* this is called from a ::render() call, when we need an image to
draw with.
*/
DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 needs image from %2 .. %3\n", name, start, end));
/* this is called from a ::render() call, when we need an image to
draw with.
*/
DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 needs image from %2 .. %3\n", name, start, end));
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 CR %2 stop? %3 image %4\n", this, current_request,
- (current_request ? current_request->should_stop() : false),
- (current_request ? current_request->image : 0)));
-
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 CR %2 stop? %3 image %4\n", this, current_request,
+ (current_request ? current_request->should_stop() : false),
+ (current_request ? current_request->image : 0)));
+
if (current_request && !current_request->should_stop() && current_request->image) {
/* put the image into the cache so that other
if (current_request && !current_request->should_stop() && current_request->image) {
/* put the image into the cache so that other
ret.reset (new WaveViewCache::Entry (current_request->channel,
current_request->height,
current_request->amplitude,
ret.reset (new WaveViewCache::Entry (current_request->channel,
current_request->height,
current_request->amplitude,
cache_request_result (current_request);
DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1: got image from completed request, spans %2..%3\n",
name, current_request->start, current_request->end));
cache_request_result (current_request);
DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1: got image from completed request, spans %2..%3\n",
name, current_request->start, current_request->end));
ret = get_image_from_cache (start, end, full_image);
DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1: lookup from cache gave %2 (full %3)\n",
name, ret, full_image));
}
ret = get_image_from_cache (start, end, full_image);
DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1: lookup from cache gave %2 (full %3)\n",
name, ret, full_image));
}
boost::shared_ptr<WaveViewThreadRequest> req (new WaveViewThreadRequest);
req->type = WaveViewThreadRequest::Draw;
boost::shared_ptr<WaveViewThreadRequest> req (new WaveViewThreadRequest);
req->type = WaveViewThreadRequest::Draw;
- /* compute how wide the image should be, in samples.
- *
- * We want at least 1 canvas width's worth, but if that
- * represents less than 1/10th of a second, use 1/10th of
- * a second instead.
- */
-
- framecnt_t canvas_width_samples = _canvas->visible_area().width() * _samples_per_pixel;
- const framecnt_t one_tenth_of_second = _region->session().frame_rate() / 10;
-
- if (canvas_width_samples > one_tenth_of_second) {
- return canvas_width_samples;
- }
-
- return one_tenth_of_second;
+ /* compute how wide the image should be, in samples.
+ *
+ * We want at least 1 canvas width's worth, but if that
+ * represents less than 1/10th of a second, use 1/10th of
+ * a second instead.
+ */
+
+ framecnt_t canvas_width_samples = _canvas->visible_area().width() * _samples_per_pixel;
+ const framecnt_t one_tenth_of_second = _region->session().frame_rate() / 10;
+
+ if (canvas_width_samples > one_tenth_of_second) {
+ return canvas_width_samples;
+ }
+
+ return one_tenth_of_second;
if (current_request) {
/* this will stop rendering in progress (which might otherwise
be long lived) for any current request.
*/
if (current_request) {
/* this will stop rendering in progress (which might otherwise
be long lived) for any current request.
*/
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 now has current request %2\n", this, req));
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 now has current request %2\n", this, req));
- if (request_queue.insert (this).second) {
- /* this waveview was not already in the request queue, make sure we wake
- the rendering thread in case it is asleep.
- */
- request_cond.signal ();
- }
+ if (request_queue.insert (this).second) {
+ /* this waveview was not already in the request queue, make sure we wake
+ the rendering thread in case it is asleep.
+ */
+ request_cond.signal ();
+ }
if (!req->should_stop()) {
/* sample position is canonical here, and we want to generate
if (!req->should_stop()) {
/* sample position is canonical here, and we want to generate
- * an image that spans about 3x the canvas width. We get to that
- * width by using an image sample count of the screen width added
- * on each side of the desired image center.
+ * an image that spans about 3x the canvas width. We get to that
+ * width by using an image sample count of the screen width added
+ * on each side of the desired image center.
const framepos_t center = req->start + ((req->end - req->start) / 2);
const framecnt_t image_samples = req->width;
const framepos_t center = req->start + ((req->end - req->start) / 2);
const framecnt_t image_samples = req->width;
framepos_t sample_start = max (_region_start, (center - image_samples));
framepos_t sample_end = min (center + image_samples, region_end());
framepos_t sample_start = max (_region_start, (center - image_samples));
framepos_t sample_end = min (center + image_samples, region_end());
boost::scoped_array<ARDOUR::PeakData> peaks (new PeakData[n_peaks]);
/* Note that Region::read_peaks() takes a start position based on an
offset into the Region's **SOURCE**, rather than an offset into
the Region itself.
*/
boost::scoped_array<ARDOUR::PeakData> peaks (new PeakData[n_peaks]);
/* Note that Region::read_peaks() takes a start position based on an
offset into the Region's **SOURCE**, rather than an offset into
the Region itself.
*/
framecnt_t peaks_read = _region->read_peaks (peaks.get(), n_peaks,
sample_start, sample_end - sample_start,
req->channel,
req->samples_per_pixel);
framecnt_t peaks_read = _region->read_peaks (peaks.get(), n_peaks,
sample_start, sample_end - sample_start,
req->channel,
req->samples_per_pixel);
+
+ // http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-image-surface-create
+ // This function always returns a valid pointer, but it will return a pointer to a "nil" surface..
+ // but there's some evidence that req->image can be NULL.
+ // http://tracker.ardour.org/view.php?id=6478
+ assert (req->image);
+
if (_amplitude_above_axis != 1.0) {
for (framecnt_t i = 0; i < n_peaks; ++i) {
peaks[i].max *= _amplitude_above_axis;
if (_amplitude_above_axis != 1.0) {
for (framecnt_t i = 0; i < n_peaks; ++i) {
peaks[i].max *= _amplitude_above_axis;
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("done with request for %1 at %2 CR %3 req %4 range %5 .. %6\n", this, g_get_monotonic_time(), current_request, req, req->start, req->end));
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("done with request for %1 at %2 CR %3 req %4 range %5 .. %6\n", this, g_get_monotonic_time(), current_request, req, req->start, req->end));
WaveView::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
{
assert (_samples_per_pixel != 0);
WaveView::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
{
assert (_samples_per_pixel != 0);
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("render %1 at %2\n", this, g_get_monotonic_time()));
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("render %1 at %2\n", this, g_get_monotonic_time()));
/* a WaveView is intimately connected to an AudioRegion. It will
* display the waveform within the region, anywhere from the start of
/* a WaveView is intimately connected to an AudioRegion. It will
* display the waveform within the region, anywhere from the start of
* window coordinates. It begins at zero (in item coordinates for this
* waveview, and extends to region_length() / _samples_per_pixel.
*/
* window coordinates. It begins at zero (in item coordinates for this
* waveview, and extends to region_length() / _samples_per_pixel.
*/
Rect self = item_to_window (Rect (0.0, 0.0, region_length() / _samples_per_pixel, _height));
// cerr << name << " RENDER " << area << " self = " << self << endl;
Rect self = item_to_window (Rect (0.0, 0.0, region_length() / _samples_per_pixel, _height));
// cerr << name << " RENDER " << area << " self = " << self << endl;
/* Now lets get the intersection with the area we've been asked to draw */
boost::optional<Rect> d = self.intersection (area);
/* Now lets get the intersection with the area we've been asked to draw */
boost::optional<Rect> d = self.intersection (area);
/* "draw" is now a rectangle that defines the rectangle we need to
* update/render the waveview into, in window coordinate space.
*/
/* "draw" is now a rectangle that defines the rectangle we need to
* update/render the waveview into, in window coordinate space.
*/
/* window coordinates - pixels where x=0 is the left edge of the canvas
* window. We round down in case we were asked to
* draw "between" pixels at the start and/or end.
*/
/* window coordinates - pixels where x=0 is the left edge of the canvas
* window. We round down in case we were asked to
* draw "between" pixels at the start and/or end.
*/
double draw_start = floor (draw.x0);
const double draw_end = floor (draw.x1);
// cerr << "Need to draw " << draw_start << " .. " << draw_end << " vs. " << area << " and self = " << self << endl;
double draw_start = floor (draw.x0);
const double draw_end = floor (draw.x1);
// cerr << "Need to draw " << draw_start << " .. " << draw_end << " vs. " << area << " and self = " << self << endl;
/* image coordnates: pixels where x=0 is the start of this waveview,
* wherever it may be positioned. thus image_start=N means "an image
* that begins N pixels after the start of region that this waveview is
/* image coordnates: pixels where x=0 is the start of this waveview,
* wherever it may be positioned. thus image_start=N means "an image
* that begins N pixels after the start of region that this waveview is
const framepos_t image_start = window_to_image (self.x0, draw_start);
const framepos_t image_end = window_to_image (self.x0, draw_end);
const framepos_t image_start = window_to_image (self.x0, draw_start);
const framepos_t image_end = window_to_image (self.x0, draw_end);
*
* "sample_start = N" means "the first sample we need to represent is N
* samples after the first sample of the region"
*/
*
* "sample_start = N" means "the first sample we need to represent is N
* samples after the first sample of the region"
*/
framepos_t sample_start = _region_start + (image_start * _samples_per_pixel);
framepos_t sample_end = _region_start + (image_end * _samples_per_pixel);
framepos_t sample_start = _region_start + (image_start * _samples_per_pixel);
framepos_t sample_end = _region_start + (image_end * _samples_per_pixel);
// cerr << "Sample space: " << sample_start << " .. " << sample_end << " @ " << _samples_per_pixel << " rs = " << _region_start << endl;
/* sample_start and sample_end are bounded by the region
// cerr << "Sample space: " << sample_start << " .. " << sample_end << " @ " << _samples_per_pixel << " rs = " << _region_start << endl;
/* sample_start and sample_end are bounded by the region
// cerr << debug_name() << " will need image spanning " << sample_start << " .. " << sample_end << " region spans " << _region_start << " .. " << region_end() << endl;
double image_origin_in_self_coordinates;
boost::shared_ptr<WaveViewCache::Entry> image_to_draw;
// cerr << debug_name() << " will need image spanning " << sample_start << " .. " << sample_end << " region spans " << _region_start << " .. " << region_end() << endl;
double image_origin_in_self_coordinates;
boost::shared_ptr<WaveViewCache::Entry> image_to_draw;
if (_current_image->start > sample_start || _current_image->end < sample_end) {
/* doesn't cover the area we need ... reset */
_current_image.reset ();
if (_current_image->start > sample_start || _current_image->end < sample_end) {
/* doesn't cover the area we need ... reset */
_current_image.reset ();
image_to_draw = get_image (sample_start, sample_end, full_image);
DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 image to draw = %2 (full? %3)\n", name, image_to_draw, full_image));
image_to_draw = get_image (sample_start, sample_end, full_image);
DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 image to draw = %2 (full? %3)\n", name, image_to_draw, full_image));
we may not want this to overlap a border around the
waveform. If so, _start_shift will be set.
*/
we may not want this to overlap a border around the
waveform. If so, _start_shift will be set.
*/
/* the image may only be a best-effort ... it may not span the entire
* range requested, though it is guaranteed to cover the start. So
* determine how many pixels we can actually draw.
*/
double draw_width;
/* the image may only be a best-effort ... it may not span the entire
* range requested, though it is guaranteed to cover the start. So
* determine how many pixels we can actually draw.
*/
double draw_width;
/* the image is guaranteed to start at or before
* draw_start. But if it starts before draw_start, that reduces
/* the image is guaranteed to start at or before
* draw_start. But if it starts before draw_start, that reduces
- draw_width = min ((double) image_to_draw->image->get_width() - (draw_start - image_to_draw->start),
- (draw_end - draw_start));
+ draw_width = min ((double) image_to_draw->image->get_width(), (draw_end - draw_start));
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 draw just %2 of %3 (iwidth %4 off %5 img @ %6 rs @ %7)\n", name, draw_width, (draw_end - draw_start),
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("%1 draw just %2 of %3 @ %8 (iwidth %4 off %5 img @ %6 rs @ %7)\n", name, draw_width, (draw_end - draw_start),
} else {
draw_width = draw_end - draw_start;
DEBUG_TRACE (DEBUG::WaveView, string_compose ("use current image, span entire render width %1..%2\n", draw_start, draw_end));
} else {
draw_width = draw_end - draw_start;
DEBUG_TRACE (DEBUG::WaveView, string_compose ("use current image, span entire render width %1..%2\n", draw_start, draw_end));
* will appear. So specifying (10,10) will put the upper left corner of
* the image at (10,10) in user space.
*/
* will appear. So specifying (10,10) will put the upper left corner of
* the image at (10,10) in user space.
*/
/* now remove it from the queue and reset our request pointer so that
have no outstanding request (that we know about)
*/
/* now remove it from the queue and reset our request pointer so that
have no outstanding request (that we know about)
*/
Glib::Threads::Mutex::Lock lm (request_queue_lock);
g_atomic_int_set (&drawing_thread_should_quit, 1);
request_cond.signal ();
Glib::Threads::Mutex::Lock lm (request_queue_lock);
g_atomic_int_set (&drawing_thread_should_quit, 1);
request_cond.signal ();
/* remove the request from the queue (remember: the "request"
* is just a pointer to a WaveView object)
*/
/* remove the request from the queue (remember: the "request"
* is just a pointer to a WaveView object)
*/
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("start request for %1 at %2\n", requestor, g_get_monotonic_time()));
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("start request for %1 at %2\n", requestor, g_get_monotonic_time()));
if ((x = cache_map.find (src)) == cache_map.end ()) {
/* nothing in the cache for this audio source at all */
return boost::shared_ptr<WaveViewCache::Entry> ();
if ((x = cache_map.find (src)) == cache_map.end ()) {
/* nothing in the cache for this audio source at all */
return boost::shared_ptr<WaveViewCache::Entry> ();
CacheLine& caches = x->second;
boost::shared_ptr<Entry> best_partial;
framecnt_t max_coverage = 0;
CacheLine& caches = x->second;
boost::shared_ptr<Entry> best_partial;
framecnt_t max_coverage = 0;
/* Find a suitable ImageSurface, if it exists.
*/
for (CacheLine::iterator c = caches.begin(); c != caches.end(); ++c) {
boost::shared_ptr<Entry> e (*c);
/* Find a suitable ImageSurface, if it exists.
*/
for (CacheLine::iterator c = caches.begin(); c != caches.end(); ++c) {
boost::shared_ptr<Entry> e (*c);
- switch (Evoral::coverage (start, end, e->start, e->end)) {
- case Evoral::OverlapExternal: /* required range is inside image range */
- DEBUG_TRACE (DEBUG::WaveView, string_compose ("found image spanning %1..%2 covers %3..%4\n",
- e->start, e->end, start, end));
- use (src, e);
- full_coverage = true;
- return e;
-
- case Evoral::OverlapStart: /* required range start is covered by image range */
- if ((e->end - start) > max_coverage) {
- best_partial = e;
- max_coverage = e->end - start;
- }
- break;
-
- case Evoral::OverlapNone:
- case Evoral::OverlapEnd:
- case Evoral::OverlapInternal:
- break;
+ switch (Evoral::coverage (start, end, e->start, e->end)) {
+ case Evoral::OverlapExternal: /* required range is inside image range */
+ DEBUG_TRACE (DEBUG::WaveView, string_compose ("found image spanning %1..%2 covers %3..%4\n",
+ e->start, e->end, start, end));
+ use (src, e);
+ full_coverage = true;
+ return e;
+
+ case Evoral::OverlapStart: /* required range start is covered by image range */
+ if ((e->end - start) > max_coverage) {
+ best_partial = e;
+ max_coverage = e->end - start;
+ }
+ break;
+
+ case Evoral::OverlapNone:
+ case Evoral::OverlapEnd:
+ case Evoral::OverlapInternal:
+ break;
/* c1 now points to a cached image entry that matches current
* properties. Check all subsequent cached imaged entries to
* see if there are others that also match but represent
/* c1 now points to a cached image entry that matches current
* properties. Check all subsequent cached imaged entries to
* see if there are others that also match but represent
if (e2->start >= e1->start && e2->end <= e1->end) {
/* c2 is fully contained by c1, so delete it */
caches.erase (c2);
if (e2->start >= e1->start && e2->end <= e1->end) {
/* c2 is fully contained by c1, so delete it */
caches.erase (c2);
WaveViewCache::add (boost::shared_ptr<ARDOUR::AudioSource> src, boost::shared_ptr<Entry> ce)
{
/* MUST BE CALLED FROM (SINGLE) GUI THREAD */
WaveViewCache::add (boost::shared_ptr<ARDOUR::AudioSource> src, boost::shared_ptr<Entry> ce)
{
/* MUST BE CALLED FROM (SINGLE) GUI THREAD */
Cairo::RefPtr<Cairo::ImageSurface> img (ce->image);
image_cache_size += img->get_height() * img->get_width () * 4; /* 4 = bytes per FORMAT_ARGB32 pixel */
Cairo::RefPtr<Cairo::ImageSurface> img (ce->image);
image_cache_size += img->get_height() * img->get_width () * 4; /* 4 = bytes per FORMAT_ARGB32 pixel */
/* sort list in LRU order */
SortByTimestamp sorter;
sort (cache_list.begin(), cache_list.end(), sorter);
/* sort list in LRU order */
SortByTimestamp sorter;
sort (cache_list.begin(), cache_list.end(), sorter);
if (*c == le.second) {
DEBUG_TRACE (DEBUG::WaveView, string_compose ("Removing cache line entry for %1\n", x->first->name()));
if (*c == le.second) {
DEBUG_TRACE (DEBUG::WaveView, string_compose ("Removing cache line entry for %1\n", x->first->name()));
Cairo::RefPtr<Cairo::ImageSurface> img (le.second->image);
uint64_t size = img->get_height() * img->get_width() * 4; /* 4 = bytes per FORMAT_ARGB32 pixel */
Cairo::RefPtr<Cairo::ImageSurface> img (le.second->image);
uint64_t size = img->get_height() * img->get_width() * 4; /* 4 = bytes per FORMAT_ARGB32 pixel */