- /*
+/*
Copyright (C) 2000-2002 Paul Davis
This program is free software; you can redistribute it and/or modify
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id$
- */
+*/
+
+#include <stdio.h>
+#include <math.h>
+#include <libgnomecanvas/libgnomecanvas.h>
+#include <string.h>
+#include <limits.h>
- #include <stdio.h>
- #include <math.h>
- #include <libgnomecanvas/libgnomecanvas.h>
- #include <string.h>
- #include <limits.h>
+#include <ardour/dB.h>
- #include <ardour/dB.h>
+#include "logmeter.h"
+#include "canvas-waveview.h"
+#include "rgb_macros.h"
- #include "canvas-waveview.h"
- #include "rgb_macros.h"
+extern void c_stacktrace();
- enum {
+enum {
PROP_0,
PROP_DATA_SRC,
PROP_CHANNEL,
PROP_HEIGHT,
PROP_WAVE_COLOR,
PROP_RECTIFIED,
- PROP_REGION_START
- };
+ PROP_REGION_START,
+ PROP_LOGSCALED,
+};
- static void gnome_canvas_waveview_class_init (GnomeCanvasWaveViewClass *class);
+static void gnome_canvas_waveview_class_init (GnomeCanvasWaveViewClass *class);
- static void gnome_canvas_waveview_init (GnomeCanvasWaveView *waveview);
+static void gnome_canvas_waveview_init (GnomeCanvasWaveView *waveview);
- static void gnome_canvas_waveview_destroy (GtkObject *object);
+static void gnome_canvas_waveview_destroy (GtkObject *object);
- static void gnome_canvas_waveview_set_property (GObject *object,
+static void gnome_canvas_waveview_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
- static void gnome_canvas_waveview_get_property (GObject *object,
+static void gnome_canvas_waveview_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
- static void gnome_canvas_waveview_update (GnomeCanvasItem *item,
+static void gnome_canvas_waveview_update (GnomeCanvasItem *item,
double *affine,
ArtSVP *clip_path,
int flags);
- static void gnome_canvas_waveview_bounds (GnomeCanvasItem *item,
+static void gnome_canvas_waveview_bounds (GnomeCanvasItem *item,
double *x1,
double *y1,
double *x2,
double *y2);
- static double gnome_canvas_waveview_point (GnomeCanvasItem *item,
+static double gnome_canvas_waveview_point (GnomeCanvasItem *item,
double x,
double y,
int cx,
int cy,
GnomeCanvasItem **actual_item);
- static void gnome_canvas_waveview_render (GnomeCanvasItem *item,
+static void gnome_canvas_waveview_render (GnomeCanvasItem *item,
GnomeCanvasBuf *buf);
- static void gnome_canvas_waveview_draw (GnomeCanvasItem *item,
+static void gnome_canvas_waveview_draw (GnomeCanvasItem *item,
GdkDrawable *drawable,
int x,
int y,
int w,
int h);
- static void gnome_canvas_waveview_set_data_src (GnomeCanvasWaveView *,
+static void gnome_canvas_waveview_set_data_src (GnomeCanvasWaveView *,
void *);
- static void gnome_canvas_waveview_set_channel (GnomeCanvasWaveView *,
+static void gnome_canvas_waveview_set_channel (GnomeCanvasWaveView *,
guint32);
- static gint32 gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview,
+static gint32 gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview,
gulong start_sample,
gulong end_sample);
- static GnomeCanvasItemClass *parent_class;
+static GnomeCanvasItemClass *parent_class;
- GType
- gnome_canvas_waveview_get_type (void)
- {
+GType
+gnome_canvas_waveview_get_type (void)
+{
static GType waveview_type;
if (!waveview_type) {
return waveview_type;
}
- static void
- gnome_canvas_waveview_class_init (GnomeCanvasWaveViewClass *class)
- {
+static void
+gnome_canvas_waveview_class_init (GnomeCanvasWaveViewClass *class)
+{
GObjectClass *gobject_class;
GtkObjectClass *object_class;
GnomeCanvasItemClass *item_class;
g_param_spec_boolean ("rectified", NULL, NULL,
FALSE,
(G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
+ g_object_class_install_property
+ (gobject_class,
+ PROP_LOGSCALED,
+ g_param_spec_boolean ("logscaled", NULL, NULL,
+ FALSE,
+ (G_PARAM_READABLE | G_PARAM_WRITABLE)));
g_object_class_install_property
(gobject_class,
item_class->point = gnome_canvas_waveview_point;
item_class->render = gnome_canvas_waveview_render;
item_class->draw = gnome_canvas_waveview_draw;
- }
+}
GnomeCanvasWaveViewCache*
gnome_canvas_waveview_cache_new ()
waveview->gain_curve_function = NULL;
waveview->gain_src = NULL;
waveview->rectified = FALSE;
+ waveview->logscaled = FALSE;
waveview->region_start = 0;
waveview->samples_per_unit = 1.0;
waveview->amplitude_above_axis = 1.0;
waveview->reload_cache_in_render = FALSE;
waveview->wave_color = RGBA_TO_UINT(44,35,126,255);
-
- // GTK2FIX
- // GNOME_CANVAS_ITEM(waveview)->object.flags |= GNOME_CANVAS_ITEM_NO_AUTO_REDRAW;
}
static void
waveview = GNOME_CANVAS_WAVEVIEW (object);
- gnome_canvas_waveview_cache_destroy (waveview->cache);
-
if (GTK_OBJECT_CLASS (parent_class)->destroy)
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
#define DEBUG_CACHE 0
+#undef CACHE_MEMMOVE_OPTIMIZATION
static gint32
gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_sample, gulong end_sample)
gulong copied;
GnomeCanvasWaveViewCache *cache;
float* gain;
+#ifdef CACHE_MEMMOVE_OPTIMIZATION
+ gulong present_frames;
+ gulong present_entries;
+#endif
cache = waveview->cache;
/* but make sure it doesn't extend beyond the end of the source material */
- rf3 = (gulong) (waveview->sourcefile_length_function (waveview->data_src)) + 1;
- rf3 -= new_cache_start;
+ rf3 = (gulong) (waveview->sourcefile_length_function (waveview->data_src, waveview->samples_per_unit)) + 1;
+ if (rf3 < new_cache_start) {
+ rf3 = 0;
+ } else {
+ rf3 -= new_cache_start;
+ }
#if DEBUG_CACHE
fprintf (stderr, "\n\nAVAILABLE FRAMES = %lu of %lu, start = %lu, sstart = %lu, cstart = %lu\n",
- rf3, waveview->sourcefile_length_function (waveview->data_src),
+ rf3, waveview->sourcefile_length_function (waveview->data_src, waveview->samples_per_unit),
waveview->region_start, start_sample, new_cache_start);
#endif
#if DEBUG_CACHE
fprintf (stderr, "new cache = %lu - %lu\n", new_cache_start, new_cache_end);
- fprintf(stderr,"required_cach_entries = %lu, samples_per_unit = %f\n",
- required_cache_entries,waveview->samples_per_unit);
+ fprintf(stderr,"required_cach_entries = %lu, samples_per_unit = %f req frames = %lu\n",
+ required_cache_entries,waveview->samples_per_unit, required_frames);
#endif
if (required_cache_entries > cache->allocated) {
ostart = new_cache_start;
-#undef CACHE_MEMMOVE_OPTIMIZATION
#ifdef CACHE_MEMMOVE_OPTIMIZATION
/* data is not entirely in the cache, so go fetch it, making sure to fill the cache */
// fprintf(stderr,"length == %lu\n",waveview->length_function (waveview->data_src));
// required_frames = MIN (waveview->length_function (waveview->data_src) - new_cache_start, required_frames);
+
npeaks = (gulong) floor (required_frames / waveview->samples_per_unit);
- npeaks = MAX (1, npeaks);
required_frames = npeaks * waveview->samples_per_unit;
#if DEBUG_CACHE
// start_sample, end_sample);
#endif
- waveview->peak_function (waveview->data_src, npeaks, new_cache_start, required_frames, cache->data + offset, waveview->channel,waveview->samples_per_unit);
-
- /* take into account any copied peaks */
+ if (required_frames) {
+ waveview->peak_function (waveview->data_src, npeaks, new_cache_start, required_frames, cache->data + offset, waveview->channel,waveview->samples_per_unit);
- npeaks += copied;
+ /* take into account any copied peaks */
+
+ npeaks += copied;
+ } else {
+ npeaks = copied;
+ }
if (npeaks < cache->allocated) {
#if DEBUG_CACHE
free (gain);
}
+
+ /* do optional log scaling. this implementation is not particularly efficient */
+ if (waveview->logscaled) {
+ guint32 n;
+ GnomeCanvasWaveViewCacheEntry* buf = cache->data;
+
+ for (n = 0; n < cache->data_size; ++n) {
+
+ if (buf[n].max > 0.0f) {
+ buf[n].max = alt_log_meter(coefficient_to_dB(buf[n].max));
+ } else if (buf[n].max < 0.0f) {
+ buf[n].max = -alt_log_meter(coefficient_to_dB(-buf[n].max));
+ }
+
+ if (buf[n].min > 0.0f) {
+ buf[n].min = alt_log_meter(coefficient_to_dB(buf[n].min));
+ } else if (buf[n].min < 0.0f) {
+ buf[n].min = -alt_log_meter(coefficient_to_dB(-buf[n].min));
+ }
+ }
+ }
+
cache->start = ostart;
cache->end = new_cache_end;
redraw = TRUE;
}
break;
+ case PROP_LOGSCALED:
+ if (waveview->logscaled != g_value_get_boolean(value)) {
+ waveview->logscaled = g_value_get_boolean(value);
+ if (waveview->cache_updater) {
+ waveview->cache->start = 0;
+ waveview->cache->end = 0;
+ }
+ redraw = TRUE;
+ calc_bounds = TRUE;
+ }
+ break;
case PROP_REGION_START:
waveview->region_start = g_value_get_uint(value);
redraw = TRUE;
case PROP_RECTIFIED:
g_value_set_boolean (value, waveview->rectified);
+ break;
+
+ case PROP_LOGSCALED:
+ g_value_set_boolean (value, waveview->logscaled);
+ break;
case PROP_REGION_START:
g_value_set_uint (value, waveview->region_start);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
#if 0
printf ("0x%x r (%d..%d)(%d..%d) bbox (%d..%d)(%d..%d)"
- " b/e %d..%d s= %lu..%lu\n",
+ " b/e %d..%d s= %lu..%lu @ %f\n",
waveview,
buf->rect.x0,
buf->rect.x1,
waveview->bbox_lrx,
waveview->bbox_uly,
waveview->bbox_lry,
- begin, end, s1, s2);
+ begin, end, s1, s2,
+ waveview->samples_per_unit);
#endif
/* now ensure that the cache is full and properly