2013-04-10 15:27:55 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2011-2013 Paul Davis
|
2017-03-16 00:12:05 -04:00
|
|
|
Copyright (C) 2017 Tim Mayberry
|
2013-04-10 15:27:55 -04:00
|
|
|
Author: Carl Hetherington <cth@carlh.net>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2013-04-16 15:38:18 -04:00
|
|
|
#include <cmath>
|
2017-03-16 00:12:05 -04:00
|
|
|
|
|
|
|
#include <boost/scoped_array.hpp>
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
#include <cairomm/cairomm.h>
|
|
|
|
|
2015-06-01 14:45:32 -04:00
|
|
|
#include <glibmm/threads.h>
|
2017-07-17 14:12:33 -04:00
|
|
|
#include <gdkmm/general.h>
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2015-06-01 14:45:32 -04:00
|
|
|
#include "pbd/base_ui.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "pbd/compose.h"
|
2015-06-01 14:45:32 -04:00
|
|
|
#include "pbd/convert.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "pbd/signals.h"
|
2013-04-24 15:42:14 -04:00
|
|
|
#include "pbd/stacktrace.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
|
|
|
|
#include "ardour/types.h"
|
2013-04-16 15:38:18 -04:00
|
|
|
#include "ardour/dB.h"
|
2015-03-31 10:05:15 -04:00
|
|
|
#include "ardour/lmath.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
#include "ardour/audioregion.h"
|
2015-06-01 14:45:32 -04:00
|
|
|
#include "ardour/audiosource.h"
|
2015-06-23 14:26:10 -04:00
|
|
|
#include "ardour/session.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2017-07-17 12:34:35 -04:00
|
|
|
#include "gtkmm2ext/colors.h"
|
2017-07-17 14:12:33 -04:00
|
|
|
#include "gtkmm2ext/gui_thread.h"
|
|
|
|
#include "gtkmm2ext/utils.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2017-07-17 14:12:33 -04:00
|
|
|
#include "canvas/canvas.h"
|
|
|
|
#include "canvas/debug.h"
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2017-07-17 14:12:33 -04:00
|
|
|
#include "waveview/wave_view.h"
|
|
|
|
#include "waveview/wave_view_private.h"
|
2015-03-28 11:13:40 -04:00
|
|
|
|
2017-07-18 12:29:22 -04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#define Rect ArdourCanvas::Rect
|
|
|
|
#endif
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
using namespace std;
|
2015-06-10 18:48:01 -04:00
|
|
|
using namespace PBD;
|
2017-07-17 14:12:33 -04:00
|
|
|
using namespace ARDOUR;
|
2017-07-17 12:34:35 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2017-07-17 14:12:33 -04:00
|
|
|
using namespace ArdourCanvas;
|
|
|
|
using namespace ArdourWaveView;
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2013-04-16 21:23:50 -04:00
|
|
|
double WaveView::_global_gradient_depth = 0.6;
|
2013-04-16 18:02:12 -04:00
|
|
|
bool WaveView::_global_logscaled = false;
|
|
|
|
WaveView::Shape WaveView::_global_shape = WaveView::Normal;
|
2013-06-28 20:21:30 -04:00
|
|
|
bool WaveView::_global_show_waveform_clipping = true;
|
2017-03-16 00:12:05 -04:00
|
|
|
double WaveView::_global_clip_level = 0.98853;
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2013-04-16 18:02:12 -04:00
|
|
|
PBD::Signal0<void> WaveView::VisualPropertiesChanged;
|
2013-12-30 15:54:09 -05:00
|
|
|
PBD::Signal0<void> WaveView::ClipLevelChanged;
|
2013-04-16 14:04:59 -04:00
|
|
|
|
2016-02-21 12:34:10 -05:00
|
|
|
/* NO_THREAD_WAVEVIEWS is defined by the top level wscript
|
|
|
|
* if --no-threaded-waveviws is provided at the configure step.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NO_THREADED_WAVEVIEWS
|
2016-02-19 15:13:29 -05:00
|
|
|
#define ENABLE_THREADED_WAVEFORM_RENDERING
|
2016-02-21 12:34:10 -05:00
|
|
|
#endif
|
2015-12-16 10:28:17 -05:00
|
|
|
|
2014-06-12 14:53:44 -04:00
|
|
|
WaveView::WaveView (Canvas* c, boost::shared_ptr<ARDOUR::AudioRegion> region)
|
|
|
|
: Item (c)
|
|
|
|
, _region (region)
|
2017-03-16 00:12:05 -04:00
|
|
|
, _props (new WaveViewProperties (region))
|
2014-06-12 14:53:44 -04:00
|
|
|
, _shape_independent (false)
|
|
|
|
, _logscaled_independent (false)
|
|
|
|
, _gradient_depth_independent (false)
|
2017-03-16 00:12:05 -04:00
|
|
|
, _draw_image_in_gui_thread (false)
|
|
|
|
, _always_draw_image_in_gui_thread (false)
|
2014-06-12 14:53:44 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
init ();
|
2014-06-12 14:53:44 -04:00
|
|
|
}
|
|
|
|
|
2014-06-21 11:43:42 -04:00
|
|
|
WaveView::WaveView (Item* parent, boost::shared_ptr<ARDOUR::AudioRegion> region)
|
|
|
|
: Item (parent)
|
2013-04-04 00:32:52 -04:00
|
|
|
, _region (region)
|
2017-03-16 00:12:05 -04:00
|
|
|
, _props (new WaveViewProperties (region))
|
2013-04-16 18:02:12 -04:00
|
|
|
, _shape_independent (false)
|
|
|
|
, _logscaled_independent (false)
|
2013-04-16 21:23:50 -04:00
|
|
|
, _gradient_depth_independent (false)
|
2017-03-16 00:12:05 -04:00
|
|
|
, _draw_image_in_gui_thread (false)
|
|
|
|
, _always_draw_image_in_gui_thread (false)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
init ();
|
|
|
|
}
|
2015-06-23 08:17:48 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
void
|
|
|
|
WaveView::init ()
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_THREADED_WAVEFORM_RENDERING
|
|
|
|
WaveViewThreads::initialize ();
|
|
|
|
#endif
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->fill_color = _fill_color;
|
|
|
|
_props->outline_color = _outline_color;
|
|
|
|
|
|
|
|
VisualPropertiesChanged.connect_same_thread (
|
|
|
|
invalidation_connection, boost::bind (&WaveView::handle_visual_property_change, this));
|
|
|
|
ClipLevelChanged.connect_same_thread (invalidation_connection,
|
|
|
|
boost::bind (&WaveView::handle_clip_level_change, this));
|
2013-04-16 14:04:59 -04:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:37:31 -04:00
|
|
|
WaveView::~WaveView ()
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
#ifdef ENABLE_THREADED_WAVEFORM_RENDERING
|
|
|
|
WaveViewThreads::deinitialize ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
reset_cache_group ();
|
2013-06-20 14:37:31 -04:00
|
|
|
}
|
|
|
|
|
2015-06-01 14:45:32 -04:00
|
|
|
string
|
|
|
|
WaveView::debug_name() const
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
return _region->name () + string (":") + PBD::to_string (_props->channel + 1);
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
|
|
|
|
2015-06-04 17:45:58 -04:00
|
|
|
void
|
|
|
|
WaveView::set_always_get_image_in_thread (bool yn)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
_always_draw_image_in_gui_thread = yn;
|
2015-06-04 17:45:58 -04:00
|
|
|
}
|
|
|
|
|
2013-04-16 14:04:59 -04:00
|
|
|
void
|
2013-04-16 18:02:12 -04:00
|
|
|
WaveView::handle_visual_property_change ()
|
2013-04-16 14:04:59 -04:00
|
|
|
{
|
2013-04-16 18:02:12 -04:00
|
|
|
bool changed = false;
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!_shape_independent && (_props->shape != global_shape())) {
|
|
|
|
_props->shape = global_shape();
|
2013-04-16 18:02:12 -04:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!_logscaled_independent && (_props->logscaled != global_logscaled())) {
|
|
|
|
_props->logscaled = global_logscaled();
|
2013-04-16 18:02:12 -04:00
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!_gradient_depth_independent && (_props->gradient_depth != global_gradient_depth())) {
|
|
|
|
_props->gradient_depth = global_gradient_depth();
|
2013-04-16 21:23:50 -04:00
|
|
|
changed = true;
|
|
|
|
}
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2013-04-16 18:02:12 -04:00
|
|
|
if (changed) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
|
|
|
end_visual_change ();
|
2013-04-16 18:02:12 -04:00
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2014-05-26 18:33:15 -04:00
|
|
|
void
|
|
|
|
WaveView::handle_clip_level_change ()
|
|
|
|
{
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
|
|
|
end_visual_change ();
|
2014-05-26 18:33:15 -04:00
|
|
|
}
|
|
|
|
|
2013-04-16 20:38:10 -04:00
|
|
|
void
|
|
|
|
WaveView::set_fill_color (Color c)
|
|
|
|
{
|
2013-04-24 15:42:14 -04:00
|
|
|
if (c != _fill_color) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2013-04-24 15:42:14 -04:00
|
|
|
Fill::set_fill_color (c);
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->fill_color = _fill_color; // ugh
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-24 15:42:14 -04:00
|
|
|
}
|
2013-04-16 20:38:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::set_outline_color (Color c)
|
|
|
|
{
|
2013-04-24 15:42:14 -04:00
|
|
|
if (c != _outline_color) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2013-04-24 15:42:14 -04:00
|
|
|
Outline::set_outline_color (c);
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->outline_color = c;
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-24 15:42:14 -04:00
|
|
|
}
|
2013-04-16 20:38:10 -04:00
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
void
|
2013-04-12 11:31:17 -04:00
|
|
|
WaveView::set_samples_per_pixel (double samples_per_pixel)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->samples_per_pixel != samples_per_pixel) {
|
2013-04-24 15:42:14 -04:00
|
|
|
begin_change ();
|
2013-04-26 11:10:19 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->samples_per_pixel = samples_per_pixel;
|
2013-04-24 15:42:14 -04:00
|
|
|
_bounding_box_dirty = true;
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2013-04-24 15:42:14 -04:00
|
|
|
end_change ();
|
|
|
|
}
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
|
2013-06-27 17:23:34 -04:00
|
|
|
static inline float
|
|
|
|
_log_meter (float power, double lower_db, double upper_db, double non_linearity)
|
|
|
|
{
|
|
|
|
return (power < lower_db ? 0.0 : pow((power-lower_db)/(upper_db-lower_db), non_linearity));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline float
|
|
|
|
alt_log_meter (float power)
|
|
|
|
{
|
|
|
|
return _log_meter (power, -192.0, 0.0, 8.0);
|
|
|
|
}
|
|
|
|
|
2013-12-30 15:46:44 -05:00
|
|
|
void
|
|
|
|
WaveView::set_clip_level (double dB)
|
|
|
|
{
|
2014-05-26 18:33:15 -04:00
|
|
|
const double clip_level = dB_to_coefficient (dB);
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_global_clip_level != clip_level) {
|
|
|
|
_global_clip_level = clip_level;
|
2014-05-26 18:33:15 -04:00
|
|
|
ClipLevelChanged ();
|
|
|
|
}
|
2013-12-30 15:46:44 -05:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
boost::shared_ptr<WaveViewDrawRequest>
|
|
|
|
WaveView::create_draw_request (WaveViewProperties const& props) const
|
|
|
|
{
|
|
|
|
assert (props.is_valid());
|
|
|
|
|
|
|
|
boost::shared_ptr<WaveViewDrawRequest> request (new WaveViewDrawRequest);
|
|
|
|
|
|
|
|
request->image = boost::shared_ptr<WaveViewImage> (new WaveViewImage (_region, props));
|
|
|
|
return request;
|
|
|
|
}
|
|
|
|
|
2015-03-28 11:13:40 -04:00
|
|
|
void
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveView::prepare_for_render (Rect const& area) const
|
|
|
|
{
|
|
|
|
if (draw_image_in_gui_thread()) {
|
|
|
|
// Drawing image in GUI thread in WaveView::render
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect draw_rect;
|
|
|
|
Rect self_rect;
|
|
|
|
|
|
|
|
// all in window coordinate space
|
|
|
|
if (!get_item_and_draw_rect_in_window_coords (area, self_rect, draw_rect)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
double const image_start_pixel_offset = draw_rect.x0 - self_rect.x0;
|
|
|
|
double const image_end_pixel_offset = draw_rect.x1 - self_rect.x0;
|
|
|
|
|
|
|
|
WaveViewProperties required_props = *_props;
|
|
|
|
|
|
|
|
required_props.set_sample_positions_from_pixel_offsets (image_start_pixel_offset,
|
|
|
|
image_end_pixel_offset);
|
|
|
|
|
|
|
|
if (!required_props.is_valid ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_image) {
|
|
|
|
if (_image->props.is_equivalent (required_props)) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Image does not contain sample area required
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<WaveViewDrawRequest> request = create_draw_request (required_props);
|
|
|
|
|
|
|
|
queue_draw_request (request);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
WaveView::get_item_and_draw_rect_in_window_coords (Rect const& canvas_rect, Rect& item_rect,
|
|
|
|
Rect& draw_rect) const
|
2015-03-28 11:13:40 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
/* a WaveView is intimately connected to an AudioRegion. It will
|
|
|
|
* display the waveform within the region, anywhere from the start of
|
|
|
|
* the region to its end.
|
|
|
|
*
|
|
|
|
* the area we've been asked to render may overlap with area covered
|
|
|
|
* by the region in any of the normal ways:
|
|
|
|
*
|
|
|
|
* - it may begin and end within the area covered by the region
|
|
|
|
* - it may start before and end after the area covered by region
|
|
|
|
* - it may start before and end within the area covered by the region
|
|
|
|
* - it may start within and end after the area covered by the region
|
|
|
|
* - it may be precisely coincident with the area covered by region.
|
|
|
|
*
|
|
|
|
* So let's start by determining the area covered by the region, in
|
|
|
|
* window coordinates. It begins at zero (in item coordinates for this
|
|
|
|
* waveview, and extends to region_length() / _samples_per_pixel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
double const width = region_length() / _props->samples_per_pixel;
|
|
|
|
item_rect = item_to_window (Rect (0.0, 0.0, width, _props->height));
|
|
|
|
|
|
|
|
/* Now lets get the intersection with the area we've been asked to draw */
|
|
|
|
|
|
|
|
draw_rect = item_rect.intersection (canvas_rect);
|
|
|
|
|
|
|
|
if (!draw_rect) {
|
|
|
|
// No intersection with drawing area
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw_rect now defines the rectangle we need to update/render the waveview
|
|
|
|
* into, in window coordinate space.
|
|
|
|
*
|
|
|
|
* We round down in case we were asked to draw "between" pixels at the start
|
|
|
|
* and/or end.
|
|
|
|
*/
|
|
|
|
draw_rect.x0 = floor (draw_rect.x0);
|
|
|
|
draw_rect.x1 = floor (draw_rect.x1);
|
|
|
|
|
|
|
|
return true;
|
2014-06-07 11:47:38 -04:00
|
|
|
}
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2015-06-19 08:14:02 -04:00
|
|
|
void
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveView::queue_draw_request (boost::shared_ptr<WaveViewDrawRequest> const& request) const
|
2014-06-23 14:57:55 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
// Don't enqueue any requests without a thread to dequeue them.
|
|
|
|
assert (WaveViewThreads::enabled());
|
|
|
|
|
|
|
|
if (!request || !request->is_valid()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_request) {
|
|
|
|
current_request->cancel ();
|
|
|
|
}
|
|
|
|
|
|
|
|
boost::shared_ptr<WaveViewImage> cached_image =
|
|
|
|
get_cache_group ()->lookup_image (request->image->props);
|
|
|
|
|
|
|
|
if (cached_image) {
|
|
|
|
// The image may not be finished at this point but that is fine, great in
|
|
|
|
// fact as it means it should only need to be drawn once.
|
|
|
|
request->image = cached_image;
|
|
|
|
current_request = request;
|
|
|
|
} else {
|
|
|
|
// now we can finally set an optimal image now that we are not using the
|
|
|
|
// properties for comparisons.
|
|
|
|
request->image->props.set_width_samples (optimal_image_width_samples ());
|
|
|
|
|
|
|
|
current_request = request;
|
2015-06-19 08:14:02 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
// Add it to the cache so that other WaveViews can refer to the same image
|
|
|
|
get_cache_group()->add_image (current_request->image);
|
|
|
|
|
|
|
|
WaveViewThreads::enqueue_draw_request (current_request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::compute_tips (ARDOUR::PeakData const& peak, WaveView::LineTips& tips,
|
|
|
|
double const effective_height)
|
|
|
|
{
|
2015-10-04 14:51:05 -04:00
|
|
|
/* remember: canvas (and cairo) coordinate space puts the origin at the upper left.
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-06-19 08:14:02 -04:00
|
|
|
So, a sample value of 1.0 (0dbFS) will be computed as:
|
|
|
|
|
|
|
|
(1.0 - 1.0) * 0.5 * effective_height
|
|
|
|
|
|
|
|
which evaluates to 0, or the top of the image.
|
|
|
|
|
|
|
|
A sample value of -1.0 will be computed as
|
|
|
|
|
|
|
|
(1.0 + 1.0) * 0.5 * effective height
|
|
|
|
|
|
|
|
which evaluates to effective height, or the bottom of the image.
|
|
|
|
*/
|
|
|
|
|
|
|
|
const double pmax = (1.0 - peak.max) * 0.5 * effective_height;
|
|
|
|
const double pmin = (1.0 - peak.min) * 0.5 * effective_height;
|
|
|
|
|
|
|
|
/* remember that the bottom of the image (pmin) has larger y-coordinates
|
|
|
|
than the top (pmax).
|
|
|
|
*/
|
|
|
|
|
|
|
|
double spread = (pmin - pmax) * 0.5;
|
|
|
|
|
|
|
|
/* find the nearest pixel to the nominal center. */
|
|
|
|
const double center = round (pmin - spread);
|
|
|
|
|
|
|
|
if (spread < 1.0) {
|
|
|
|
/* minimum distance between line ends is 1 pixel, and we want it "centered" on a pixel,
|
|
|
|
as per cairo single-pixel line issues.
|
|
|
|
|
|
|
|
NOTE: the caller will not draw a line between these two points if the spread is
|
|
|
|
less than 2 pixels. So only the tips.top value matters, which is where we will
|
|
|
|
draw a single pixel as part of the outline.
|
2014-09-12 19:34:27 -04:00
|
|
|
*/
|
2015-06-19 08:14:02 -04:00
|
|
|
tips.top = center;
|
|
|
|
tips.bot = center + 1.0;
|
|
|
|
} else {
|
|
|
|
/* round spread above and below center to an integer number of pixels */
|
|
|
|
spread = round (spread);
|
|
|
|
/* top and bottom are located equally either side of the center */
|
|
|
|
tips.top = center - spread;
|
|
|
|
tips.bot = center + spread;
|
2014-06-23 14:57:55 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-06-19 08:14:02 -04:00
|
|
|
tips.top = min (effective_height, max (0.0, tips.top));
|
|
|
|
tips.bot = min (effective_height, max (0.0, tips.bot));
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-06-19 08:14:02 -04:00
|
|
|
|
|
|
|
Coord
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveView::y_extent (double s, Shape const shape, double const height)
|
2015-06-19 08:14:02 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
assert (shape == Rectified);
|
|
|
|
return floor ((1.0 - s) * height);
|
2014-06-23 14:57:55 -04:00
|
|
|
}
|
|
|
|
|
2015-03-21 09:31:32 -04:00
|
|
|
void
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveView::draw_absent_image (Cairo::RefPtr<Cairo::ImageSurface>& image, PeakData* peaks, int n_peaks)
|
2015-03-21 09:31:32 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
const double height = image->get_height();
|
|
|
|
|
|
|
|
Cairo::RefPtr<Cairo::ImageSurface> stripe = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, height);
|
2015-03-21 09:31:32 -04:00
|
|
|
|
|
|
|
Cairo::RefPtr<Cairo::Context> stripe_context = Cairo::Context::create (stripe);
|
|
|
|
stripe_context->set_antialias (Cairo::ANTIALIAS_NONE);
|
|
|
|
|
|
|
|
uint32_t stripe_separation = 150;
|
2017-03-16 00:12:05 -04:00
|
|
|
double start = - floor (height / stripe_separation) * stripe_separation;
|
2015-03-21 09:31:32 -04:00
|
|
|
int stripe_x = 0;
|
|
|
|
|
|
|
|
while (start < n_peaks) {
|
|
|
|
|
|
|
|
stripe_context->move_to (start, 0);
|
2017-03-16 00:12:05 -04:00
|
|
|
stripe_x = start + height;
|
|
|
|
stripe_context->line_to (stripe_x, height);
|
2015-03-21 09:31:32 -04:00
|
|
|
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<Cairo::Context> context = Cairo::Context::create (image);
|
|
|
|
|
|
|
|
context->set_source_rgba (1.0, 1.0, 0.0, 0.3);
|
|
|
|
context->mask (stripe, 0, 0);
|
|
|
|
context->fill ();
|
|
|
|
}
|
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
struct ImageSet {
|
|
|
|
Cairo::RefPtr<Cairo::ImageSurface> wave;
|
|
|
|
Cairo::RefPtr<Cairo::ImageSurface> outline;
|
|
|
|
Cairo::RefPtr<Cairo::ImageSurface> clip;
|
|
|
|
Cairo::RefPtr<Cairo::ImageSurface> zero;
|
|
|
|
|
2014-09-12 19:44:05 -04:00
|
|
|
ImageSet() :
|
|
|
|
wave (0), outline (0), clip (0), zero (0) {}
|
2014-07-15 07:59:22 -04:00
|
|
|
};
|
|
|
|
|
2014-06-07 11:47:38 -04:00
|
|
|
void
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveView::draw_image (Cairo::RefPtr<Cairo::ImageSurface>& image, PeakData* peaks, int n_peaks,
|
|
|
|
boost::shared_ptr<WaveViewDrawRequest> req)
|
2014-06-07 11:47:38 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
const double height = image->get_height();
|
2014-07-15 07:59:22 -04:00
|
|
|
|
|
|
|
ImageSet images;
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
images.wave = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, height);
|
|
|
|
images.outline = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, height);
|
|
|
|
images.clip = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, height);
|
|
|
|
images.zero = Cairo::ImageSurface::create (Cairo::FORMAT_A8, n_peaks, height);
|
2014-07-15 07:59:22 -04:00
|
|
|
|
|
|
|
Cairo::RefPtr<Cairo::Context> wave_context = Cairo::Context::create (images.wave);
|
|
|
|
Cairo::RefPtr<Cairo::Context> outline_context = Cairo::Context::create (images.outline);
|
|
|
|
Cairo::RefPtr<Cairo::Context> clip_context = Cairo::Context::create (images.clip);
|
|
|
|
Cairo::RefPtr<Cairo::Context> zero_context = Cairo::Context::create (images.zero);
|
2015-03-10 08:35:53 -04:00
|
|
|
wave_context->set_antialias (Cairo::ANTIALIAS_NONE);
|
|
|
|
outline_context->set_antialias (Cairo::ANTIALIAS_NONE);
|
|
|
|
clip_context->set_antialias (Cairo::ANTIALIAS_NONE);
|
|
|
|
zero_context->set_antialias (Cairo::ANTIALIAS_NONE);
|
2014-07-15 07:59:22 -04:00
|
|
|
|
2013-06-27 17:23:34 -04:00
|
|
|
boost::scoped_array<LineTips> tips (new LineTips[n_peaks]);
|
2013-06-28 20:21:30 -04:00
|
|
|
|
|
|
|
/* Clip level nominally set to -0.9dBFS to account for inter-sample
|
|
|
|
interpolation possibly clipping (value may be too low).
|
|
|
|
|
|
|
|
We adjust by the region's own gain (but note: not by any gain
|
|
|
|
automation or its gain envelope) so that clip indicators are closer
|
|
|
|
to providing data about on-disk data. This multiplication is
|
|
|
|
needed because the data we get from AudioRegion::read_peaks()
|
|
|
|
has been scaled by scale_amplitude() already.
|
|
|
|
*/
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
const double clip_level = _global_clip_level * req->image->props.amplitude;
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
const Shape shape = req->image->props.shape;
|
|
|
|
const bool logscaled = req->image->props.logscaled;
|
|
|
|
|
|
|
|
if (req->image->props.shape == WaveView::Rectified) {
|
2013-06-27 17:23:34 -04:00
|
|
|
|
|
|
|
/* each peak is a line from the bottom of the waveview
|
2017-03-16 00:12:05 -04:00
|
|
|
* to a point determined by max (peaks[i].max,
|
|
|
|
* peaks[i].min)
|
2013-06-27 17:23:34 -04:00
|
|
|
*/
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (logscaled) {
|
2013-06-27 17:23:34 -04:00
|
|
|
for (int i = 0; i < n_peaks; ++i) {
|
2014-06-23 14:57:55 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
tips[i].bot = height - 1.0;
|
|
|
|
const double p = alt_log_meter (fast_coefficient_to_dB (max (fabs (peaks[i].max), fabs (peaks[i].min))));
|
|
|
|
tips[i].top = y_extent (p, shape, height);
|
|
|
|
tips[i].spread = p * height;
|
2013-06-28 13:40:51 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (peaks[i].max >= clip_level) {
|
2013-06-28 13:40:51 -04:00
|
|
|
tips[i].clip_max = true;
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (-(peaks[i].min) >= clip_level) {
|
2015-02-20 07:30:48 -05:00
|
|
|
tips[i].clip_min = true;
|
2013-06-28 13:40:51 -04:00
|
|
|
}
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
2014-06-23 14:57:55 -04:00
|
|
|
|
2015-03-10 08:35:53 -04:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < n_peaks; ++i) {
|
2014-06-23 14:57:55 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
tips[i].bot = height - 1.0;
|
|
|
|
const double p = max(fabs (peaks[i].max), fabs (peaks[i].min));
|
|
|
|
tips[i].top = y_extent (p, shape, height);
|
|
|
|
tips[i].spread = p * height;
|
2014-09-12 19:34:27 -04:00
|
|
|
if (p >= clip_level) {
|
2013-06-28 13:40:51 -04:00
|
|
|
tips[i].clip_max = true;
|
|
|
|
}
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
2014-09-12 19:34:27 -04:00
|
|
|
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (logscaled) {
|
2013-06-27 17:23:34 -04:00
|
|
|
for (int i = 0; i < n_peaks; ++i) {
|
2015-06-19 08:14:02 -04:00
|
|
|
PeakData p;
|
2017-03-16 00:12:05 -04:00
|
|
|
p.max = peaks[i].max;
|
|
|
|
p.min = peaks[i].min;
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (peaks[i].max >= clip_level) {
|
2015-06-19 08:14:02 -04:00
|
|
|
tips[i].clip_max = true;
|
2013-06-28 13:40:51 -04:00
|
|
|
}
|
2017-03-16 00:12:05 -04:00
|
|
|
if (-(peaks[i].min) >= clip_level) {
|
2015-03-10 08:35:53 -04:00
|
|
|
tips[i].clip_min = true;
|
2013-06-28 13:40:51 -04:00
|
|
|
}
|
|
|
|
|
2015-06-19 08:14:02 -04:00
|
|
|
if (p.max > 0.0) {
|
|
|
|
p.max = alt_log_meter (fast_coefficient_to_dB (p.max));
|
|
|
|
} else if (p.max < 0.0) {
|
|
|
|
p.max =-alt_log_meter (fast_coefficient_to_dB (-p.max));
|
2013-06-27 17:23:34 -04:00
|
|
|
} else {
|
2015-06-19 08:14:02 -04:00
|
|
|
p.max = 0.0;
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
|
|
|
|
2015-06-19 08:14:02 -04:00
|
|
|
if (p.min > 0.0) {
|
|
|
|
p.min = alt_log_meter (fast_coefficient_to_dB (p.min));
|
|
|
|
} else if (p.min < 0.0) {
|
|
|
|
p.min = -alt_log_meter (fast_coefficient_to_dB (-p.min));
|
2013-06-27 17:23:34 -04:00
|
|
|
} else {
|
2015-06-19 08:14:02 -04:00
|
|
|
p.min = 0.0;
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
compute_tips (p, tips[i], height);
|
2015-03-10 08:35:53 -04:00
|
|
|
tips[i].spread = tips[i].bot - tips[i].top;
|
2014-09-12 19:44:05 -04:00
|
|
|
}
|
2013-06-27 17:23:34 -04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i < n_peaks; ++i) {
|
2017-03-16 00:12:05 -04:00
|
|
|
if (peaks[i].max >= clip_level) {
|
2015-03-10 08:35:53 -04:00
|
|
|
tips[i].clip_max = true;
|
2013-06-28 13:40:51 -04:00
|
|
|
}
|
2017-03-16 00:12:05 -04:00
|
|
|
if (-(peaks[i].min) >= clip_level) {
|
2015-03-10 08:35:53 -04:00
|
|
|
tips[i].clip_min = true;
|
2013-06-28 13:40:51 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
compute_tips (peaks[i], tips[i], height);
|
2015-03-10 08:35:53 -04:00
|
|
|
tips[i].spread = tips[i].bot - tips[i].top;
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
|
|
|
}
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (req->stopped()) {
|
2015-06-01 14:45:32 -04:00
|
|
|
return;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
Color alpha_one = rgba_to_color (0, 0, 0, 1.0);
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
set_source_rgba (wave_context, alpha_one);
|
|
|
|
set_source_rgba (outline_context, alpha_one);
|
|
|
|
set_source_rgba (clip_context, alpha_one);
|
|
|
|
set_source_rgba (zero_context, alpha_one);
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
/* ensure single-pixel lines */
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2014-09-12 10:43:20 -04:00
|
|
|
wave_context->set_line_width (1.0);
|
2015-06-19 08:14:02 -04:00
|
|
|
wave_context->translate (0.5, 0.5);
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2014-09-12 10:43:20 -04:00
|
|
|
outline_context->set_line_width (1.0);
|
2015-06-19 08:14:02 -04:00
|
|
|
outline_context->translate (0.5, 0.5);
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2014-09-12 10:43:20 -04:00
|
|
|
clip_context->set_line_width (1.0);
|
2015-06-19 08:14:02 -04:00
|
|
|
clip_context->translate (0.5, 0.5);
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2014-09-12 10:43:20 -04:00
|
|
|
zero_context->set_line_width (1.0);
|
2015-06-19 08:14:02 -04:00
|
|
|
zero_context->translate (0.5, 0.5);
|
2013-06-27 17:23:34 -04:00
|
|
|
|
2014-06-23 14:57:55 -04:00
|
|
|
/* the height of the clip-indicator should be at most 7 pixels,
|
2014-06-08 13:13:44 -04:00
|
|
|
* or 5% of the height of the waveview item.
|
2013-06-27 17:23:34 -04:00
|
|
|
*/
|
2014-06-23 15:12:30 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
const double clip_height = min (7.0, ceil (height * 0.05));
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2014-06-23 15:12:30 -04:00
|
|
|
/* There are 3 possible components to draw at each x-axis position: the
|
|
|
|
waveform "line", the zero line and an outline/clip indicator. We
|
|
|
|
have to decide which of the 3 to draw at each position, pixel by
|
|
|
|
pixel. This makes the rendering less efficient but it is the only
|
|
|
|
way I can see to do this correctly.
|
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
To avoid constant source swapping and stroking, we draw the components separately
|
|
|
|
onto four alpha only image surfaces for use as a mask.
|
|
|
|
|
2014-06-23 15:12:30 -04:00
|
|
|
With only 1 pixel of spread between the top and bottom of the line,
|
|
|
|
we just draw the upper outline/clip indicator.
|
|
|
|
|
|
|
|
With 2 pixels of spread, we draw the upper and lower outline clip
|
2014-09-12 19:44:05 -04:00
|
|
|
indicators.
|
|
|
|
|
|
|
|
With 3 pixels of spread we draw the upper and lower outline/clip
|
2014-06-23 15:12:30 -04:00
|
|
|
indicators and at least 1 pixel of the waveform line.
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2014-06-23 15:12:30 -04:00
|
|
|
With 5 pixels of spread, we draw all components.
|
|
|
|
|
|
|
|
We can do rectified as two separate passes because we have a much
|
|
|
|
easier decision regarding whether to draw the waveform line. We
|
|
|
|
always draw the clip/outline indicators.
|
|
|
|
*/
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (shape == WaveView::Rectified) {
|
2014-06-08 12:50:14 -04:00
|
|
|
|
2014-06-23 14:57:55 -04:00
|
|
|
for (int i = 0; i < n_peaks; ++i) {
|
2014-06-23 10:06:52 -04:00
|
|
|
|
2014-06-23 15:12:30 -04:00
|
|
|
/* waveform line */
|
|
|
|
|
2014-09-12 19:34:27 -04:00
|
|
|
if (tips[i].spread >= 1.0) {
|
2014-07-15 07:59:22 -04:00
|
|
|
wave_context->move_to (i, tips[i].top);
|
|
|
|
wave_context->line_to (i, tips[i].bot);
|
2014-06-23 14:57:55 -04:00
|
|
|
}
|
2014-06-23 15:12:30 -04:00
|
|
|
|
2015-04-16 15:26:57 -04:00
|
|
|
/* clip indicator */
|
2015-04-16 15:36:13 -04:00
|
|
|
|
2015-04-16 15:26:57 -04:00
|
|
|
if (_global_show_waveform_clipping && (tips[i].clip_max || tips[i].clip_min)) {
|
2014-07-15 07:59:22 -04:00
|
|
|
clip_context->move_to (i, tips[i].top);
|
2014-06-23 14:57:55 -04:00
|
|
|
/* clip-indicating upper terminal line */
|
2014-09-12 19:34:27 -04:00
|
|
|
clip_context->rel_line_to (0, min (clip_height, ceil(tips[i].spread + .5)));
|
2015-04-16 15:36:13 -04:00
|
|
|
} else {
|
2014-07-15 07:59:22 -04:00
|
|
|
outline_context->move_to (i, tips[i].top);
|
2014-06-23 14:57:55 -04:00
|
|
|
/* normal upper terminal dot */
|
2015-04-16 15:26:57 -04:00
|
|
|
outline_context->rel_line_to (0, -1.0);
|
2014-06-23 14:57:55 -04:00
|
|
|
}
|
2014-06-08 13:13:44 -04:00
|
|
|
}
|
2014-06-23 15:12:30 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
wave_context->stroke ();
|
|
|
|
clip_context->stroke ();
|
|
|
|
outline_context->stroke ();
|
|
|
|
|
|
|
|
} else {
|
2017-03-16 00:12:05 -04:00
|
|
|
const int height_zero = floor(height * .5);
|
2014-06-23 15:12:30 -04:00
|
|
|
|
2014-06-23 14:57:55 -04:00
|
|
|
for (int i = 0; i < n_peaks; ++i) {
|
2013-06-28 20:21:30 -04:00
|
|
|
|
2014-06-23 15:12:30 -04:00
|
|
|
/* waveform line */
|
|
|
|
|
2014-09-12 19:34:27 -04:00
|
|
|
if (tips[i].spread >= 2.0) {
|
2014-07-15 07:59:22 -04:00
|
|
|
wave_context->move_to (i, tips[i].top);
|
|
|
|
wave_context->line_to (i, tips[i].bot);
|
2014-06-23 14:57:55 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-03-10 08:35:53 -04:00
|
|
|
/* draw square waves and other discontiguous points clearly */
|
2014-09-12 10:42:55 -04:00
|
|
|
if (i > 0) {
|
2015-03-10 08:35:53 -04:00
|
|
|
if (tips[i-1].top + 2 < tips[i].top) {
|
2014-09-12 10:42:55 -04:00
|
|
|
wave_context->move_to (i-1, tips[i-1].top);
|
2015-03-10 08:35:53 -04:00
|
|
|
wave_context->line_to (i-1, (tips[i].bot + tips[i-1].top)/2);
|
|
|
|
wave_context->move_to (i, (tips[i].bot + tips[i-1].top)/2);
|
2014-09-12 10:42:55 -04:00
|
|
|
wave_context->line_to (i, tips[i].top);
|
2015-03-10 08:35:53 -04:00
|
|
|
} else if (tips[i-1].bot > tips[i].bot + 2) {
|
|
|
|
wave_context->move_to (i-1, tips[i-1].bot);
|
|
|
|
wave_context->line_to (i-1, (tips[i].top + tips[i-1].bot)/2);
|
|
|
|
wave_context->move_to (i, (tips[i].top + tips[i-1].bot)/2);
|
|
|
|
wave_context->line_to (i, tips[i].bot);
|
2014-09-12 10:42:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* zero line, show only if there is enough spread
|
2015-06-24 14:12:13 -04:00
|
|
|
or the waveform line does not cross zero line */
|
2017-03-16 00:12:05 -04:00
|
|
|
bool const show_zero_line = req->image->props.show_zero;
|
2014-06-23 15:12:30 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (show_zero_line && ((tips[i].spread >= 5.0) || (tips[i].top > height_zero ) || (tips[i].bot < height_zero)) ) {
|
2015-06-24 14:12:13 -04:00
|
|
|
zero_context->move_to (i, height_zero);
|
2014-09-12 19:34:27 -04:00
|
|
|
zero_context->rel_line_to (1.0, 0);
|
2014-06-23 14:57:55 -04:00
|
|
|
}
|
|
|
|
|
2014-09-12 19:34:27 -04:00
|
|
|
if (tips[i].spread > 1.0) {
|
2015-04-16 15:03:51 -04:00
|
|
|
bool clipped = false;
|
|
|
|
/* outline/clip indicators */
|
|
|
|
if (_global_show_waveform_clipping && tips[i].clip_max) {
|
|
|
|
clip_context->move_to (i, tips[i].top);
|
|
|
|
/* clip-indicating upper terminal line */
|
|
|
|
clip_context->rel_line_to (0, min (clip_height, ceil(tips[i].spread + 0.5)));
|
|
|
|
clipped = true;
|
|
|
|
}
|
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
if (_global_show_waveform_clipping && tips[i].clip_min) {
|
|
|
|
clip_context->move_to (i, tips[i].bot);
|
2014-06-23 14:57:55 -04:00
|
|
|
/* clip-indicating lower terminal line */
|
2015-04-16 15:03:51 -04:00
|
|
|
clip_context->rel_line_to (0, - min (clip_height, ceil(tips[i].spread + 0.5)));
|
|
|
|
clipped = true;
|
|
|
|
}
|
|
|
|
|
2015-06-23 17:12:52 -04:00
|
|
|
if (!clipped && tips[i].spread > 2.0) {
|
|
|
|
/* only draw the outline if the spread
|
|
|
|
implies 3 or more pixels (so that we see 1
|
|
|
|
white pixel in the middle).
|
|
|
|
*/
|
2015-06-19 08:14:02 -04:00
|
|
|
outline_context->move_to (i, tips[i].bot);
|
|
|
|
/* normal lower terminal dot; line moves up */
|
2015-04-16 15:03:51 -04:00
|
|
|
outline_context->rel_line_to (0, -1.0);
|
|
|
|
|
2015-06-19 08:14:02 -04:00
|
|
|
outline_context->move_to (i, tips[i].top);
|
|
|
|
/* normal upper terminal dot, line moves down */
|
2015-04-16 15:03:51 -04:00
|
|
|
outline_context->rel_line_to (0, 1.0);
|
2014-09-12 19:34:27 -04:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-16 15:03:51 -04:00
|
|
|
bool clipped = false;
|
|
|
|
/* outline/clip indicator */
|
|
|
|
if (_global_show_waveform_clipping && (tips[i].clip_max || tips[i].clip_min)) {
|
|
|
|
clip_context->move_to (i, tips[i].top);
|
|
|
|
/* clip-indicating upper / lower terminal line */
|
|
|
|
clip_context->rel_line_to (0, 1.0);
|
|
|
|
clipped = true;
|
2014-06-23 14:57:55 -04:00
|
|
|
}
|
2014-09-12 19:34:27 -04:00
|
|
|
|
2015-04-16 15:03:51 -04:00
|
|
|
if (!clipped) {
|
2015-06-23 17:12:52 -04:00
|
|
|
/* special case where only 1 pixel of
|
|
|
|
* the waveform line is drawn (and
|
|
|
|
* nothing else).
|
|
|
|
*
|
|
|
|
* we draw a 1px "line", pretending
|
|
|
|
* that the span is 1.0 (whether it is
|
|
|
|
* zero or 1.0)
|
|
|
|
*/
|
2015-04-16 15:03:51 -04:00
|
|
|
wave_context->move_to (i, tips[i].top);
|
|
|
|
wave_context->rel_line_to (0, 1.0);
|
2015-03-10 08:35:53 -04:00
|
|
|
}
|
2014-09-12 19:34:27 -04:00
|
|
|
}
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
2014-07-15 07:59:22 -04:00
|
|
|
|
|
|
|
wave_context->stroke ();
|
|
|
|
outline_context->stroke ();
|
|
|
|
clip_context->stroke ();
|
|
|
|
zero_context->stroke ();
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
2014-07-15 07:59:22 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (req->stopped()) {
|
2015-06-01 14:45:32 -04:00
|
|
|
return;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
Cairo::RefPtr<Cairo::Context> context = Cairo::Context::create (image);
|
|
|
|
|
|
|
|
/* Here we set a source colour and use the various components as a mask. */
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
const Color fill_color = req->image->props.fill_color;
|
|
|
|
const double gradient_depth = req->image->props.gradient_depth;
|
|
|
|
|
|
|
|
if (gradient_depth != 0.0) {
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
Cairo::RefPtr<Cairo::LinearGradient> gradient (Cairo::LinearGradient::create (0, 0, 0, height));
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
double stops[3];
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
double r, g, b, a;
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
|
|
|
|
if (shape == Rectified) {
|
2014-07-15 07:59:22 -04:00
|
|
|
stops[0] = 0.1;
|
|
|
|
stops[1] = 0.3;
|
|
|
|
stops[2] = 0.9;
|
|
|
|
} else {
|
|
|
|
stops[0] = 0.1;
|
|
|
|
stops[1] = 0.5;
|
|
|
|
stops[2] = 0.9;
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
color_to_rgba (fill_color, r, g, b, a);
|
2014-07-15 07:59:22 -04:00
|
|
|
gradient->add_color_stop_rgba (stops[1], r, g, b, a);
|
|
|
|
/* generate a new color for the middle of the gradient */
|
|
|
|
double h, s, v;
|
2017-03-16 00:12:05 -04:00
|
|
|
color_to_hsv (fill_color, h, s, v);
|
2014-07-15 07:59:22 -04:00
|
|
|
/* change v towards white */
|
2017-03-16 00:12:05 -04:00
|
|
|
v *= 1.0 - gradient_depth;
|
2014-11-19 13:14:26 -05:00
|
|
|
Color center = hsva_to_color (h, s, v, a);
|
2014-07-15 07:59:22 -04:00
|
|
|
color_to_rgba (center, r, g, b, a);
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
gradient->add_color_stop_rgba (stops[0], r, g, b, a);
|
|
|
|
gradient->add_color_stop_rgba (stops[2], r, g, b, a);
|
|
|
|
|
|
|
|
context->set_source (gradient);
|
|
|
|
} else {
|
2017-03-16 00:12:05 -04:00
|
|
|
set_source_rgba (context, fill_color);
|
2014-07-15 07:59:22 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (req->stopped()) {
|
2015-06-01 14:45:32 -04:00
|
|
|
return;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-07-15 07:59:22 -04:00
|
|
|
context->mask (images.wave, 0, 0);
|
2014-09-12 19:44:05 -04:00
|
|
|
context->fill ();
|
2014-07-15 07:59:22 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
set_source_rgba (context, req->image->props.outline_color);
|
2014-07-15 07:59:22 -04:00
|
|
|
context->mask (images.outline, 0, 0);
|
|
|
|
context->fill ();
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
set_source_rgba (context, req->image->props.clip_color);
|
2014-07-15 07:59:22 -04:00
|
|
|
context->mask (images.clip, 0, 0);
|
|
|
|
context->fill ();
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
set_source_rgba (context, req->image->props.zero_color);
|
2014-07-15 07:59:22 -04:00
|
|
|
context->mask (images.zero, 0, 0);
|
|
|
|
context->fill ();
|
2013-06-27 17:23:34 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
framecnt_t
|
|
|
|
WaveView::optimal_image_width_samples () const
|
2013-06-27 17:23:34 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
/* Compute how wide the image should be in samples.
|
|
|
|
*
|
|
|
|
* The resulting image should be wider than the canvas width so that the
|
|
|
|
* image does not have to be redrawn each time the canvas offset changes, but
|
|
|
|
* drawing too much unnecessarily, for instance when zooming into the canvas
|
|
|
|
* the part of the image that is outside of the visible canvas area may never
|
|
|
|
* be displayed and will just increase apparent render time and reduce
|
|
|
|
* responsiveness in non-threaded rendering and cause "flashing" waveforms in
|
|
|
|
* threaded rendering mode.
|
|
|
|
*
|
|
|
|
* Another thing to consider is that if there are a number of waveforms on
|
|
|
|
* the canvas that are the width of the canvas then we don't want to have to
|
|
|
|
* draw the images for them all at once as it will cause a spike in render
|
|
|
|
* time, or in threaded rendering mode it will mean all the draw requests will
|
|
|
|
* the queued during the same frame/expose event. This issue can be
|
|
|
|
* alleviated by using an element of randomness in selecting the image width.
|
|
|
|
*
|
|
|
|
* If the value of samples per pixel is less than 1/10th of a second, use
|
|
|
|
* 1/10th of a second instead.
|
2015-06-01 14:45:32 -04:00
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
framecnt_t canvas_width_samples = _canvas->visible_area().width() * _props->samples_per_pixel;
|
|
|
|
const framecnt_t one_tenth_of_second = _region->session().frame_rate() / 10;
|
2015-06-23 14:26:10 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
/* If zoomed in where a canvas item interects with the canvas area but
|
|
|
|
* stretches for many pages either side, to avoid having draw all images when
|
|
|
|
* the canvas scrolls by a page width the multiplier would have to be a
|
|
|
|
* randomized amount centered around 3 times the visible canvas width, but
|
|
|
|
* for other operations like zooming or even with a stationary playhead it is
|
|
|
|
* a lot of extra drawing that can affect performance.
|
2016-03-01 08:43:44 -05:00
|
|
|
*
|
2017-03-16 00:12:05 -04:00
|
|
|
* So without making things too complicated with different widths for
|
|
|
|
* different operations, try to use a width that is a balance and will work
|
|
|
|
* well for scrolling(non-page width) so all the images aren't redrawn at the
|
|
|
|
* same time but also faster for sequential zooming operations.
|
2017-05-14 14:37:58 -04:00
|
|
|
*
|
2017-03-16 00:12:05 -04:00
|
|
|
* Canvas items that don't intersect with the edges of the visible canvas
|
|
|
|
* will of course only draw images that are the pixel width of the item.
|
|
|
|
*
|
|
|
|
* It is a perhaps a coincidence that these values are centered roughly
|
|
|
|
* around the golden ratio but they did work well in my testing.
|
2016-03-01 08:43:44 -05:00
|
|
|
*/
|
2017-03-16 00:12:05 -04:00
|
|
|
const double min_multiplier = 1.4;
|
|
|
|
const double max_multiplier = 1.8;
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
/**
|
|
|
|
* A combination of high resolution screens, high samplerates and high
|
|
|
|
* zoom levels(1 sample per pixel) can cause 1/10 of a second(in
|
|
|
|
* pixels) to exceed the cairo image size limit.
|
|
|
|
*/
|
|
|
|
const double cairo_image_limit = 32767.0;
|
|
|
|
const double max_image_width = cairo_image_limit / max_multiplier;
|
2017-05-14 14:37:58 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
framecnt_t max_width_samples = floor (max_image_width / _props->samples_per_pixel);
|
2015-06-23 14:26:10 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
const framecnt_t one_tenth_of_second_limited = std::min (one_tenth_of_second, max_width_samples);
|
2015-06-23 14:26:10 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
framecnt_t new_sample_count = std::max (canvas_width_samples, one_tenth_of_second_limited);
|
|
|
|
|
|
|
|
const double multiplier = g_random_double_range (min_multiplier, max_multiplier);
|
|
|
|
|
|
|
|
return new_sample_count * multiplier;
|
2015-06-23 14:26:10 -04:00
|
|
|
}
|
|
|
|
|
2015-06-01 14:45:32 -04:00
|
|
|
void
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveView::set_image (boost::shared_ptr<WaveViewImage> img) const
|
2015-06-01 14:45:32 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
get_cache_group ()->add_image (img);
|
|
|
|
_image = img;
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveView::process_draw_request (boost::shared_ptr<WaveViewDrawRequest> req)
|
2015-06-01 14:45:32 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
boost::shared_ptr<const ARDOUR::AudioRegion> region = req->image->region.lock();
|
2014-06-07 11:47:38 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!region) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (req->stopped()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveViewProperties const& props = req->image->props;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
const int n_peaks = props.get_width_pixels ();
|
2017-05-14 14:37:58 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
assert (n_peaks > 0 && n_peaks < 32767);
|
2016-02-27 17:16:05 -05:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
boost::scoped_array<ARDOUR::PeakData> peaks (new PeakData[n_peaks]);
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
/* 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.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
framecnt_t peaks_read =
|
|
|
|
region->read_peaks (peaks.get (), n_peaks, props.get_sample_start (),
|
|
|
|
props.get_length_samples (), props.channel, props.samples_per_pixel);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (req->stopped()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-01 08:43:28 -05:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
Cairo::RefPtr<Cairo::ImageSurface> cairo_image =
|
|
|
|
Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, n_peaks, req->image->props.height);
|
2016-02-27 17:16:05 -05:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
// 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 (cairo_image);
|
2016-02-27 17:16:05 -05:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (peaks_read > 0) {
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
/* region amplitude will have been used to generate the
|
|
|
|
* peak values already, but not the visual-only
|
|
|
|
* amplitude_above_axis. So apply that here before
|
|
|
|
* rendering.
|
|
|
|
*/
|
2015-06-01 21:08:42 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
const double amplitude_above_axis = props.amplitude_above_axis;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (amplitude_above_axis != 1.0) {
|
|
|
|
for (framecnt_t i = 0; i < n_peaks; ++i) {
|
|
|
|
peaks[i].max *= amplitude_above_axis;
|
|
|
|
peaks[i].min *= amplitude_above_axis;
|
2015-06-01 21:08:42 -04:00
|
|
|
}
|
|
|
|
}
|
2017-03-16 00:12:05 -04:00
|
|
|
|
|
|
|
draw_image (cairo_image, peaks.get(), n_peaks, req);
|
|
|
|
|
2015-09-02 12:24:37 -04:00
|
|
|
} else {
|
2017-03-16 00:12:05 -04:00
|
|
|
draw_absent_image (cairo_image, peaks.get(), n_peaks);
|
2015-10-05 10:17:49 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (req->stopped ()) {
|
|
|
|
return;
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
2015-09-02 12:24:37 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
// Assign now that we are sure all drawing is complete as that is what
|
|
|
|
// determines whether a request was finished.
|
|
|
|
req->image->cairo_image = cairo_image;
|
2013-06-20 14:37:31 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
bool
|
|
|
|
WaveView::draw_image_in_gui_thread () const
|
2015-06-01 14:45:32 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
return _draw_image_in_gui_thread || _always_draw_image_in_gui_thread || !rendered () ||
|
|
|
|
!WaveViewThreads::enabled ();
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
void
|
|
|
|
WaveView::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
assert (_props->samples_per_pixel != 0);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!_region) { // assert?
|
2013-04-04 00:32:52 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
Rect draw;
|
|
|
|
Rect self;
|
2015-06-23 14:26:10 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!get_item_and_draw_rect_in_window_coords (area, self, draw)) {
|
|
|
|
assert(true);
|
|
|
|
return;
|
|
|
|
}
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
double const image_start_pixel_offset = draw.x0 - self.x0;
|
|
|
|
double const image_end_pixel_offset = draw.x1 - self.x0;
|
2013-06-18 08:23:06 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (image_start_pixel_offset == image_end_pixel_offset) {
|
|
|
|
// this may happen if zoomed very far out with a small region
|
2013-06-18 08:23:06 -04:00
|
|
|
return;
|
|
|
|
}
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveViewProperties required_props = *_props;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
required_props.set_sample_positions_from_pixel_offsets (image_start_pixel_offset,
|
|
|
|
image_end_pixel_offset);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
assert (required_props.is_valid());
|
2013-06-20 23:12:19 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
boost::shared_ptr<WaveViewImage> image_to_draw;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (current_request) {
|
|
|
|
if (!current_request->image->props.is_equivalent (required_props)) {
|
|
|
|
// The WaveView properties may have been updated during recording between
|
|
|
|
// prepare_for_render and render calls and the new required props have
|
|
|
|
// different end sample value.
|
|
|
|
current_request->cancel ();
|
|
|
|
current_request.reset ();
|
|
|
|
} else if (current_request->finished ()) {
|
|
|
|
image_to_draw = current_request->image;
|
|
|
|
current_request.reset ();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No current Request
|
|
|
|
}
|
2013-06-20 23:12:19 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!image_to_draw && _image) {
|
|
|
|
if (_image->props.is_equivalent (required_props)) {
|
|
|
|
// Image contains required properties
|
|
|
|
image_to_draw = _image;
|
|
|
|
} else {
|
|
|
|
// Image does not contain properties required
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!image_to_draw) {
|
|
|
|
image_to_draw = get_cache_group ()->lookup_image (required_props);
|
|
|
|
if (image_to_draw && !image_to_draw->finished ()) {
|
|
|
|
// Found equivalent but unfinished Image in cache
|
|
|
|
image_to_draw.reset ();
|
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (!image_to_draw) {
|
|
|
|
// No existing image to draw
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
boost::shared_ptr<WaveViewDrawRequest> const request = create_draw_request (required_props);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (draw_image_in_gui_thread ()) {
|
|
|
|
// now that we have to draw something, draw more than required.
|
|
|
|
request->image->props.set_width_samples (optimal_image_width_samples ());
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
process_draw_request (request);
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
image_to_draw = request->image;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
} else if (current_request) {
|
|
|
|
if (current_request->finished ()) {
|
|
|
|
// There is a chance the request is now finished since checking above
|
|
|
|
image_to_draw = current_request->image;
|
|
|
|
current_request.reset ();
|
|
|
|
} else if (_canvas->get_microseconds_since_render_start () < 15000) {
|
|
|
|
current_request->cancel ();
|
|
|
|
current_request.reset ();
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
// Drawing image in GUI thread as we have time
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
// now that we have to draw something, draw more than required.
|
|
|
|
request->image->props.set_width_samples (optimal_image_width_samples ());
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
process_draw_request (request);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
image_to_draw = request->image;
|
|
|
|
} else {
|
|
|
|
// Waiting for current request to finish
|
|
|
|
redraw ();
|
|
|
|
return;
|
|
|
|
}
|
2015-06-01 14:45:32 -04:00
|
|
|
} else {
|
2017-03-16 00:12:05 -04:00
|
|
|
// Defer the rendering to another thread or perhaps render pass if
|
|
|
|
// a thread cannot generate it in time.
|
|
|
|
queue_draw_request (request);
|
|
|
|
redraw ();
|
|
|
|
return;
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
/* reset this so that future missing images can be generated in a worker thread. */
|
|
|
|
_draw_image_in_gui_thread = false;
|
2013-06-20 23:12:19 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
assert (image_to_draw);
|
2013-06-20 23:12:19 -04:00
|
|
|
|
2015-06-04 17:45:58 -04:00
|
|
|
/* compute the first pixel of the image that should be used when we
|
2015-10-04 14:51:05 -04:00
|
|
|
* render the specified range.
|
2015-06-04 17:45:58 -04:00
|
|
|
*/
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
double image_origin_in_self_coordinates =
|
|
|
|
(image_to_draw->props.get_sample_start () - _props->region_start) / _props->samples_per_pixel;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-06-04 17:45:58 -04:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
const double draw_start_pixel = draw.x0;
|
|
|
|
const double draw_end_pixel = draw.x1;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
double draw_width_pixels = draw_end_pixel - draw_start_pixel;
|
|
|
|
|
|
|
|
if (image_to_draw != _image) {
|
2015-06-10 18:48:01 -04:00
|
|
|
|
|
|
|
/* the image is guaranteed to start at or before
|
|
|
|
* draw_start. But if it starts before draw_start, that reduces
|
|
|
|
* the maximum available width we can render with.
|
|
|
|
*
|
|
|
|
* so .. clamp the draw width to the smaller of what we need to
|
|
|
|
* draw or the available width of the image.
|
|
|
|
*/
|
2017-03-16 00:12:05 -04:00
|
|
|
draw_width_pixels = min ((double)image_to_draw->cairo_image->get_width (), draw_width_pixels);
|
2015-06-10 18:48:01 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
set_image (image_to_draw);
|
2015-06-04 17:45:58 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
context->rectangle (draw_start_pixel, draw.y0, draw_width_pixels, draw.height());
|
2013-06-24 16:28:53 -04:00
|
|
|
|
|
|
|
/* round image origin position to an exact pixel in device space to
|
|
|
|
* avoid blurring
|
|
|
|
*/
|
|
|
|
|
2015-06-10 18:48:01 -04:00
|
|
|
double x = self.x0 + image_origin_in_self_coordinates;
|
2013-06-24 16:28:53 -04:00
|
|
|
double y = self.y0;
|
|
|
|
context->user_to_device (x, y);
|
|
|
|
x = round (x);
|
|
|
|
y = round (y);
|
|
|
|
context->device_to_user (x, y);
|
|
|
|
|
2015-06-04 17:45:58 -04:00
|
|
|
/* the coordinates specify where in "user coordinates" (i.e. what we
|
|
|
|
* generally call "canvas coordinates" in this code) the image origin
|
|
|
|
* will appear. So specifying (10,10) will put the upper left corner of
|
|
|
|
* the image at (10,10) in user space.
|
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
context->set_source (image_to_draw->cairo_image, x, y);
|
2013-06-20 14:37:31 -04:00
|
|
|
context->fill ();
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::compute_bounding_box () const
|
|
|
|
{
|
|
|
|
if (_region) {
|
2017-03-16 00:12:05 -04:00
|
|
|
_bounding_box = Rect (0.0, 0.0, region_length() / _props->samples_per_pixel, _props->height);
|
2013-04-04 00:32:52 -04:00
|
|
|
} else {
|
2017-01-19 14:54:24 -05:00
|
|
|
_bounding_box = Rect ();
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
_bounding_box_dirty = false;
|
|
|
|
}
|
2014-09-12 19:44:05 -04:00
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
void
|
|
|
|
WaveView::set_height (Distance height)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->height != height) {
|
2013-04-24 15:42:14 -04:00
|
|
|
begin_change ();
|
2014-06-07 11:47:38 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->height = height;
|
|
|
|
_draw_image_in_gui_thread = true;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-04-24 15:42:14 -04:00
|
|
|
_bounding_box_dirty = true;
|
|
|
|
end_change ();
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::set_channel (int channel)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->channel != channel) {
|
2013-04-24 15:42:14 -04:00
|
|
|
begin_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->channel = channel;
|
|
|
|
reset_cache_group ();
|
2013-04-24 15:42:14 -04:00
|
|
|
_bounding_box_dirty = true;
|
|
|
|
end_change ();
|
|
|
|
}
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2013-04-16 10:07:52 -04:00
|
|
|
void
|
|
|
|
WaveView::set_logscaled (bool yn)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->logscaled != yn) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->logscaled = yn;
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-16 10:07:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
void
|
|
|
|
WaveView::set_gradient_depth (double)
|
|
|
|
{
|
|
|
|
// TODO ??
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
WaveView::gradient_depth () const
|
|
|
|
{
|
|
|
|
return _props->gradient_depth;
|
|
|
|
}
|
|
|
|
|
2013-04-16 10:07:52 -04:00
|
|
|
void
|
2013-04-17 15:22:09 -04:00
|
|
|
WaveView::gain_changed ()
|
2013-04-16 10:07:52 -04:00
|
|
|
{
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->amplitude = _region->scale_amplitude ();
|
|
|
|
_draw_image_in_gui_thread = true;
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-16 10:07:52 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::set_zero_color (Color c)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->zero_color != c) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->zero_color = c;
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-16 10:07:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::set_clip_color (Color c)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->clip_color != c) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->clip_color = c;
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-16 10:07:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::set_show_zero_line (bool yn)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->show_zero != yn) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->show_zero = yn;
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-16 10:07:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
bool
|
|
|
|
WaveView::show_zero_line () const
|
|
|
|
{
|
|
|
|
return _props->show_zero;
|
|
|
|
}
|
|
|
|
|
2013-04-16 10:07:52 -04:00
|
|
|
void
|
|
|
|
WaveView::set_shape (Shape s)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->shape != s) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->shape = s;
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-16 18:02:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-17 15:22:09 -04:00
|
|
|
void
|
|
|
|
WaveView::set_amplitude_above_axis (double a)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (fabs (_props->amplitude_above_axis - a) > 0.01) {
|
2014-06-07 11:47:38 -04:00
|
|
|
begin_visual_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->amplitude_above_axis = a;
|
|
|
|
_draw_image_in_gui_thread = true;
|
2014-06-07 11:47:38 -04:00
|
|
|
end_visual_change ();
|
2013-04-17 15:22:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
double
|
|
|
|
WaveView::amplitude_above_axis () const
|
|
|
|
{
|
|
|
|
return _props->amplitude_above_axis;
|
|
|
|
}
|
|
|
|
|
2013-04-16 18:02:12 -04:00
|
|
|
void
|
|
|
|
WaveView::set_global_shape (Shape s)
|
|
|
|
{
|
|
|
|
if (_global_shape != s) {
|
|
|
|
_global_shape = s;
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveViewCache::get_instance()->clear_cache ();
|
2013-04-16 18:02:12 -04:00
|
|
|
VisualPropertiesChanged (); /* EMIT SIGNAL */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::set_global_logscaled (bool yn)
|
|
|
|
{
|
|
|
|
if (_global_logscaled != yn) {
|
|
|
|
_global_logscaled = yn;
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveViewCache::get_instance()->clear_cache ();
|
2013-04-16 18:02:12 -04:00
|
|
|
VisualPropertiesChanged (); /* EMIT SIGNAL */
|
2013-04-16 10:07:52 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-01 14:45:32 -04:00
|
|
|
framecnt_t
|
|
|
|
WaveView::region_length() const
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
return _region->length() - (_props->region_start - _region->start());
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
framepos_t
|
|
|
|
WaveView::region_end() const
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
return _props->region_start + region_length();
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
|
|
|
|
2013-04-04 00:32:52 -04:00
|
|
|
void
|
2014-07-03 10:00:12 -04:00
|
|
|
WaveView::set_region_start (frameoffset_t start)
|
2013-04-04 00:32:52 -04:00
|
|
|
{
|
2013-04-24 15:42:14 -04:00
|
|
|
if (!_region) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_props->region_start == start) {
|
2014-07-03 10:00:12 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
begin_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->region_start = start;
|
2014-07-03 10:00:12 -04:00
|
|
|
_bounding_box_dirty = true;
|
|
|
|
end_change ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::region_resized ()
|
|
|
|
{
|
|
|
|
/* Called when the region start or end (thus length) has changed.
|
2013-04-24 15:42:14 -04:00
|
|
|
*/
|
|
|
|
|
2014-07-03 10:00:12 -04:00
|
|
|
if (!_region) {
|
|
|
|
return;
|
|
|
|
}
|
2013-04-24 15:42:14 -04:00
|
|
|
|
2014-07-03 10:00:12 -04:00
|
|
|
begin_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
_props->region_start = _region->start();
|
|
|
|
_props->region_end = _region->start() + _region->length();
|
2013-04-04 00:32:52 -04:00
|
|
|
_bounding_box_dirty = true;
|
2013-04-24 15:42:14 -04:00
|
|
|
end_change ();
|
2013-04-04 00:32:52 -04:00
|
|
|
}
|
|
|
|
|
2013-04-16 14:04:59 -04:00
|
|
|
void
|
2013-04-16 21:23:50 -04:00
|
|
|
WaveView::set_global_gradient_depth (double depth)
|
2013-04-16 14:04:59 -04:00
|
|
|
{
|
2013-04-16 21:23:50 -04:00
|
|
|
if (_global_gradient_depth != depth) {
|
|
|
|
_global_gradient_depth = depth;
|
2013-04-16 18:02:12 -04:00
|
|
|
VisualPropertiesChanged (); /* EMIT SIGNAL */
|
2013-04-16 14:04:59 -04:00
|
|
|
}
|
|
|
|
}
|
2013-06-28 20:21:30 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::set_global_show_waveform_clipping (bool yn)
|
|
|
|
{
|
|
|
|
if (_global_show_waveform_clipping != yn) {
|
|
|
|
_global_show_waveform_clipping = yn;
|
2015-01-21 13:35:04 -05:00
|
|
|
ClipLevelChanged ();
|
2013-06-28 20:21:30 -04:00
|
|
|
}
|
|
|
|
}
|
2015-02-09 17:55:05 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
WaveView::set_start_shift (double pixels)
|
|
|
|
{
|
|
|
|
if (pixels < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
begin_visual_change ();
|
2017-03-16 00:12:05 -04:00
|
|
|
//_start_shift = pixels;
|
2015-02-09 17:55:05 -05:00
|
|
|
end_visual_change ();
|
|
|
|
}
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2015-06-23 08:17:48 -04:00
|
|
|
void
|
|
|
|
WaveView::set_image_cache_size (uint64_t sz)
|
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveViewCache::get_instance()->set_image_cache_threshold (sz);
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
boost::shared_ptr<WaveViewCacheGroup>
|
|
|
|
WaveView::get_cache_group () const
|
2015-06-01 14:45:32 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
if (_cache_group) {
|
|
|
|
return _cache_group;
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
boost::shared_ptr<AudioSource> source = _region->audio_source (_props->channel);
|
|
|
|
assert (source);
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
_cache_group = WaveViewCache::get_instance ()->get_cache_group (source);
|
2015-06-01 14:45:32 -04:00
|
|
|
|
2017-03-16 00:12:05 -04:00
|
|
|
return _cache_group;
|
2015-08-19 21:01:51 -04:00
|
|
|
}
|
|
|
|
|
2015-06-01 14:45:32 -04:00
|
|
|
void
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveView::reset_cache_group ()
|
2015-06-01 14:45:32 -04:00
|
|
|
{
|
2017-03-16 00:12:05 -04:00
|
|
|
WaveViewCache::get_instance()->reset_cache_group (_cache_group);
|
2015-06-01 14:45:32 -04:00
|
|
|
}
|