Installer now handles i18n of the Desktop folder. Running the installer or uninstalle...
[ardour.git] / gtk2_ardour / canvas-waveview.c
index f929b3119759618a2213d38928de5ad9192e8e79..1e28a2733090f00863c221fa8173349125e3a30f 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
-     Copyright (C) 2000-2002 Paul Davis 
+     Copyright (C) 2000-2002 Paul Davis
 
      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
 
      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
 #include <cairo.h>
 #include <string.h>
 #include <limits.h>
 #include <cairo.h>
 #include <string.h>
 #include <limits.h>
+#include <unistd.h>
 
 
-#include <ardour/dB.h>
+#include "ardour/dB.h"
 
 #include "logmeter.h"
 #include "canvas-waveview.h"
 #include "rgb_macros.h"
 
 
 #include "logmeter.h"
 #include "canvas-waveview.h"
 #include "rgb_macros.h"
 
+/* POSIX guarantees casting between void* and function pointers, ISO C doesn't
+ * We can work around warnings by going one step deeper in our casts
+ */
+#ifdef _POSIX_VERSION
+#define POSIX_FUNC_PTR_CAST(type, object) *((type*) &(object))
+#endif // _POSIX_VERSION
 
 extern void c_stacktrace();
 
 
 extern void c_stacktrace();
 
@@ -110,7 +117,7 @@ static void gnome_canvas_waveview_set_data_src   (GnomeCanvasWaveView *,
 static void gnome_canvas_waveview_set_channel    (GnomeCanvasWaveView *,
                                                   guint32);
 
 static void gnome_canvas_waveview_set_channel    (GnomeCanvasWaveView *,
                                                   guint32);
 
-static gint32 gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview,
+static guint32 gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview,
                                                   gulong               start_sample,
                                                   gulong               end_sample);
 
                                                   gulong               start_sample,
                                                   gulong               end_sample);
 
@@ -163,106 +170,106 @@ gnome_canvas_waveview_class_init (GnomeCanvasWaveViewClass *class)
                  PROP_DATA_SRC,
                  g_param_spec_pointer ("data_src", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
                  PROP_DATA_SRC,
                  g_param_spec_pointer ("data_src", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_CHANNEL,
                  g_param_spec_uint ("channel", NULL, NULL,
                                     0, G_MAXUINT, 0,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_CHANNEL,
                  g_param_spec_uint ("channel", NULL, NULL,
                                     0, G_MAXUINT, 0,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_LENGTH_FUNCTION,
                  g_param_spec_pointer ("length_function", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_LENGTH_FUNCTION,
                  g_param_spec_pointer ("length_function", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_SOURCEFILE_LENGTH_FUNCTION,
                  g_param_spec_pointer ("sourcefile_length_function", NULL, NULL,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_SOURCEFILE_LENGTH_FUNCTION,
                  g_param_spec_pointer ("sourcefile_length_function", NULL, NULL,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_PEAK_FUNCTION,
                  g_param_spec_pointer ("peak_function", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_PEAK_FUNCTION,
                  g_param_spec_pointer ("peak_function", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_GAIN_FUNCTION,
                  g_param_spec_pointer ("gain_function", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_GAIN_FUNCTION,
                  g_param_spec_pointer ("gain_function", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_GAIN_SRC,
                  g_param_spec_pointer ("gain_src", NULL, NULL,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_GAIN_SRC,
                  g_param_spec_pointer ("gain_src", NULL, NULL,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-       
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_CACHE,
                  g_param_spec_pointer ("cache", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_CACHE,
                  g_param_spec_pointer ("cache", NULL, NULL,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_CACHE_UPDATER,
                  g_param_spec_boolean ("cache_updater", NULL, NULL,
                                       FALSE,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_CACHE_UPDATER,
                  g_param_spec_boolean ("cache_updater", NULL, NULL,
                                       FALSE,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_SAMPLES_PER_UNIT,
                  g_param_spec_double ("samples_per_unit", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_SAMPLES_PER_UNIT,
                  g_param_spec_double ("samples_per_unit", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_AMPLITUDE_ABOVE_AXIS,
                  g_param_spec_double ("amplitude_above_axis", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_AMPLITUDE_ABOVE_AXIS,
                  g_param_spec_double ("amplitude_above_axis", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_X,
                  g_param_spec_double ("x", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_X,
                  g_param_spec_double ("x", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_Y,
                  g_param_spec_double ("y", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_Y,
                  g_param_spec_double ("y", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_HEIGHT,
                  g_param_spec_double ("height", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_HEIGHT,
                  g_param_spec_double ("height", NULL, NULL,
                                       0.0, G_MAXDOUBLE, 0.0,
                                       (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_WAVE_COLOR,
                  g_param_spec_uint ("wave_color", NULL, NULL,
                                     0, G_MAXUINT, 0,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_WAVE_COLOR,
                  g_param_spec_uint ("wave_color", NULL, NULL,
                                     0, G_MAXUINT, 0,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_CLIP_COLOR,
                  g_param_spec_uint ("clip_color", NULL, NULL,
                                     0, G_MAXUINT, 0,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_CLIP_COLOR,
                  g_param_spec_uint ("clip_color", NULL, NULL,
                                     0, G_MAXUINT, 0,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_ZERO_COLOR,
         g_object_class_install_property
                 (gobject_class,
                  PROP_ZERO_COLOR,
@@ -283,7 +290,7 @@ gnome_canvas_waveview_class_init (GnomeCanvasWaveViewClass *class)
                  g_param_spec_boolean ("filled", NULL, NULL,
                                        FALSE,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
                  g_param_spec_boolean ("filled", NULL, NULL,
                                        FALSE,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_RECTIFIED,
         g_object_class_install_property
                 (gobject_class,
                  PROP_RECTIFIED,
@@ -304,16 +311,16 @@ gnome_canvas_waveview_class_init (GnomeCanvasWaveViewClass *class)
                  g_param_spec_boolean ("logscaled", NULL, NULL,
                                        FALSE,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
                  g_param_spec_boolean ("logscaled", NULL, NULL,
                                        FALSE,
                                        (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         g_object_class_install_property
                 (gobject_class,
                  PROP_REGION_START,
                  g_param_spec_uint ("region_start", NULL, NULL,
                                     0, G_MAXUINT, 0,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
         g_object_class_install_property
                 (gobject_class,
                  PROP_REGION_START,
                  g_param_spec_uint ("region_start", NULL, NULL,
                                     0, G_MAXUINT, 0,
                                     (G_PARAM_READABLE | G_PARAM_WRITABLE)));
-        
+
         object_class->destroy = gnome_canvas_waveview_destroy;
         object_class->destroy = gnome_canvas_waveview_destroy;
-        
+
         item_class->update = gnome_canvas_waveview_update;
         item_class->bounds = gnome_canvas_waveview_bounds;
         item_class->point = gnome_canvas_waveview_point;
         item_class->update = gnome_canvas_waveview_update;
         item_class->bounds = gnome_canvas_waveview_bounds;
         item_class->point = gnome_canvas_waveview_point;
@@ -392,7 +399,8 @@ gnome_canvas_waveview_destroy (GtkObject *object)
 #define DEBUG_CACHE 0
 #undef CACHE_MEMMOVE_OPTIMIZATION
 
 #define DEBUG_CACHE 0
 #undef CACHE_MEMMOVE_OPTIMIZATION
 
-static gint32
+/** @return cache index of start_sample within the cache */
+static guint32
 gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_sample, gulong end_sample)
 {
        gulong required_cache_entries;
 gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_sample, gulong end_sample)
 {
        gulong required_cache_entries;
@@ -417,12 +425,12 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
 #if DEBUG_CACHE
        // printf("waveview->region_start == %lu\n",waveview->region_start);
        // c_stacktrace ();
 #if DEBUG_CACHE
        // printf("waveview->region_start == %lu\n",waveview->region_start);
        // c_stacktrace ();
-       printf ("\n\n=> 0x%x cache @ 0x%x range: %lu - %lu request: %lu - %lu (%lu frames)\n", 
+       printf ("\n\n=> 0x%x cache @ 0x%x range: %lu - %lu request: %lu - %lu (%lu frames)\n",
                waveview, cache,
                cache->start, cache->end,
                start_sample, end_sample, end_sample - start_sample);
 #endif
                waveview, cache,
                cache->start, cache->end,
                start_sample, end_sample, end_sample - start_sample);
 #endif
-               
+
        if (cache->start <= start_sample && cache->end >= end_sample) {
 #if DEBUG_CACHE
                // printf ("0x%x: cache hit for %lu-%lu (cache holds: %lu-%lu\n",
        if (cache->start <= start_sample && cache->end >= end_sample) {
 #if DEBUG_CACHE
                // printf ("0x%x: cache hit for %lu-%lu (cache holds: %lu-%lu\n",
@@ -432,13 +440,13 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
        }
 
        /* make sure the cache is at least twice as wide as the screen width, and put the start sample
        }
 
        /* make sure the cache is at least twice as wide as the screen width, and put the start sample
-          in the middle, ensuring that we cover the end_sample. 
+          in the middle, ensuring that we cover the end_sample.
        */
 
        /* Note the assumption that we have a 1:1 units:pixel ratio for the canvas. Its everywhere ... */
        */
 
        /* Note the assumption that we have a 1:1 units:pixel ratio for the canvas. Its everywhere ... */
-       
+
        half_width = (gulong) floor ((waveview->screen_width * waveview->samples_per_unit)/2.0 + 0.5);
        half_width = (gulong) floor ((waveview->screen_width * waveview->samples_per_unit)/2.0 + 0.5);
-       
+
        if (start_sample < half_width) {
                new_cache_start = 0;
        } else {
        if (start_sample < half_width) {
                new_cache_start = 0;
        } else {
@@ -461,7 +469,7 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
        }
 
 #if DEBUG_CACHE
        }
 
 #if DEBUG_CACHE
-       fprintf (stderr, "AVAILABLE FRAMES = %lu of %lu, start = %lu, sstart = %lu, cstart = %lu\n", 
+       fprintf (stderr, "AVAILABLE FRAMES = %lu of %lu, start = %lu, sstart = %lu, cstart = %lu\n",
                 rf3, waveview->sourcefile_length_function (waveview->data_src, waveview->samples_per_unit),
                 waveview->region_start, start_sample, new_cache_start);
 #endif
                 rf3, waveview->sourcefile_length_function (waveview->data_src, waveview->samples_per_unit),
                 waveview->region_start, start_sample, new_cache_start);
 #endif
@@ -488,7 +496,7 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
        ostart = new_cache_start;
 
 #ifdef CACHE_MEMMOVE_OPTIMIZATION
        ostart = new_cache_start;
 
 #ifdef CACHE_MEMMOVE_OPTIMIZATION
-       
+
        /* data is not entirely in the cache, so go fetch it, making sure to fill the cache */
 
        /* some of the required cache entries are in the cache, but in the wrong
        /* data is not entirely in the cache, so go fetch it, making sure to fill the cache */
 
        /* some of the required cache entries are in the cache, but in the wrong
@@ -496,24 +504,24 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
        */
 
        if (cache->start < new_cache_start && new_cache_start < cache->end) {
        */
 
        if (cache->start < new_cache_start && new_cache_start < cache->end) {
-               
-               /* case one: the common area is at the end of the existing cache. move it 
+
+               /* case one: the common area is at the end of the existing cache. move it
                   to the beginning of the cache, and set up to refill whatever remains.
                   to the beginning of the cache, and set up to refill whatever remains.
-                  
-                  
+
+
                           wv->cache_start                                        wv->cache_end
                           |-------------------------------------------------------| cache
                                                               |--------------------------------| requested
                                                               <------------------->
                                                                     "present"
                           wv->cache_start                                        wv->cache_end
                           |-------------------------------------------------------| cache
                                                               |--------------------------------| requested
                                                               <------------------->
                                                                     "present"
-                                                           new_cache_start                      new_cache_end       
+                                                           new_cache_start                      new_cache_end
                */
                */
-                               
+
 
                present_frames = cache->end - new_cache_start;
                present_entries = (gulong) floor (present_frames / waveview->samples_per_unit);
 
 
                present_frames = cache->end - new_cache_start;
                present_entries = (gulong) floor (present_frames / waveview->samples_per_unit);
 
-#if DEBUG_CACHE                
+#if DEBUG_CACHE
                fprintf (stderr, "existing material at end of current cache, move to start of new cache\n"
                         "\tcopy from %lu to start\n", cache->data_size - present_entries);
 #endif
                fprintf (stderr, "existing material at end of current cache, move to start of new cache\n"
                         "\tcopy from %lu to start\n", cache->data_size - present_entries);
 #endif
@@ -521,7 +529,7 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
                memmove (&cache->data[0],
                         &cache->data[cache->data_size - present_entries],
                         present_entries * sizeof (GnomeCanvasWaveViewCacheEntry));
                memmove (&cache->data[0],
                         &cache->data[cache->data_size - present_entries],
                         present_entries * sizeof (GnomeCanvasWaveViewCacheEntry));
-               
+
 #if DEBUG_CACHE
                fprintf (stderr, "satisfied %lu of %lu frames, offset = %lu, will start at %lu (ptr = 0x%x)\n",
                         present_frames, required_frames, present_entries, new_cache_start + present_entries,
 #if DEBUG_CACHE
                fprintf (stderr, "satisfied %lu of %lu frames, offset = %lu, will start at %lu (ptr = 0x%x)\n",
                         present_frames, required_frames, present_entries, new_cache_start + present_entries,
@@ -535,8 +543,8 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
 
        } else if (new_cache_end > cache->start && new_cache_end < cache->end) {
 
 
        } else if (new_cache_end > cache->start && new_cache_end < cache->end) {
 
-               /* case two: the common area lives at the beginning of the existing cache. 
-                  
+               /* case two: the common area lives at the beginning of the existing cache.
+
                                             wv->cache_start                                      wv->cache_end
                                             |-----------------------------------------------------|
                               |--------------------------------|
                                             wv->cache_start                                      wv->cache_end
                                             |-----------------------------------------------------|
                               |--------------------------------|
@@ -545,15 +553,15 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
 
                              new_cache_start                      new_cache_end
                */
 
                              new_cache_start                      new_cache_end
                */
-               
+
                present_frames = new_cache_end - cache->start;
                present_entries = (gulong) floor (present_frames / waveview->samples_per_unit);
 
                memmove (&cache->data[cache->data_size - present_entries],
                         &cache->data[0],
                         present_entries * sizeof (GnomeCanvasWaveViewCacheEntry));
                present_frames = new_cache_end - cache->start;
                present_entries = (gulong) floor (present_frames / waveview->samples_per_unit);
 
                memmove (&cache->data[cache->data_size - present_entries],
                         &cache->data[0],
                         present_entries * sizeof (GnomeCanvasWaveViewCacheEntry));
-               
-#if DEBUG_CACHE                
+
+#if DEBUG_CACHE
                fprintf (stderr, "existing material at start of current cache, move to start of end cache\n");
 #endif
 
                fprintf (stderr, "existing material at start of current cache, move to start of end cache\n");
 #endif
 
@@ -567,7 +575,7 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
                offset = 0;
                required_frames -= present_frames;
 
                offset = 0;
                required_frames -= present_frames;
 
-               
+
        } else {
                copied = 0;
                offset = 0;
        } else {
                copied = 0;
                offset = 0;
@@ -604,7 +612,7 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
                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 */
                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 */
-               
+
                npeaks += copied;
        } else {
                npeaks = copied;
                npeaks += copied;
        } else {
                npeaks = copied;
@@ -633,27 +641,27 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
                }
 
                free (gain);
                }
 
                free (gain);
-       
+
        }
 
        /* do optional log scaling.  this implementation is not particularly efficient */
        }
 
        /* do optional log scaling.  this implementation is not particularly efficient */
-       
+
        if (waveview->logscaled) {
                guint32 n;
                GnomeCanvasWaveViewCacheEntry* buf = cache->data;
        if (waveview->logscaled) {
                guint32 n;
                GnomeCanvasWaveViewCacheEntry* buf = cache->data;
-               
+
                for (n = 0; n < cache->data_size; ++n) {
 
                        if (buf[n].max > 0.0f) {
                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));
+                               buf[n].max = alt_log_meter(fast_coefficient_to_dB(buf[n].max));
                        } else if (buf[n].max < 0.0f) {
                        } else if (buf[n].max < 0.0f) {
-                               buf[n].max = -alt_log_meter(coefficient_to_dB(-buf[n].max));
+                               buf[n].max = -alt_log_meter(fast_coefficient_to_dB(-buf[n].max));
                        }
                        }
-                       
+
                        if (buf[n].min > 0.0f) {
                        if (buf[n].min > 0.0f) {
-                               buf[n].min = alt_log_meter(coefficient_to_dB(buf[n].min));
+                               buf[n].min = alt_log_meter(fast_coefficient_to_dB(buf[n].min));
                        } else if (buf[n].min < 0.0f) {
                        } else if (buf[n].min < 0.0f) {
-                               buf[n].min = -alt_log_meter(coefficient_to_dB(-buf[n].min));
+                               buf[n].min = -alt_log_meter(fast_coefficient_to_dB(-buf[n].min));
                        }
                }
        }
                        }
                }
        }
@@ -663,10 +671,10 @@ gnome_canvas_waveview_ensure_cache (GnomeCanvasWaveView *waveview, gulong start_
 
   out:
 #if DEBUG_CACHE
 
   out:
 #if DEBUG_CACHE
-       fprintf (stderr, "return cache index = %d\n", 
-                (gint32) floor ((((double) (start_sample - cache->start)) / waveview->samples_per_unit) + 0.5));
+       fprintf (stderr, "return cache index = %d\n",
+                (guint32) floor ((((double) (start_sample - cache->start)) / waveview->samples_per_unit) + 0.5));
 #endif
 #endif
-       return (gint32) floor ((((double) (start_sample - cache->start)) / waveview->samples_per_unit) + 0.5);
+       return (guint32) floor ((((double) (start_sample - cache->start)) / waveview->samples_per_unit) + 0.5);
 
 }
 
 
 }
 
@@ -679,7 +687,7 @@ gnome_canvas_waveview_set_data_src (GnomeCanvasWaveView *waveview, void *data_sr
                        waveview->reload_cache_in_render = TRUE;
                        return;
                }
                        waveview->reload_cache_in_render = TRUE;
                        return;
                }
-       
+
                waveview->cache->start  = 0;
                waveview->cache->end = 0;
        }
                waveview->cache->start  = 0;
                waveview->cache->end = 0;
        }
@@ -693,11 +701,11 @@ gnome_canvas_waveview_set_channel (GnomeCanvasWaveView *waveview, guint32 chan)
        if (waveview->channel == chan) {
                return;
        }
        if (waveview->channel == chan) {
                return;
        }
-       
+
        waveview->channel = chan;
 }
 
        waveview->channel = chan;
 }
 
-static void 
+static void
 gnome_canvas_waveview_reset_bounds (GnomeCanvasItem *item)
 
 {
 gnome_canvas_waveview_reset_bounds (GnomeCanvasItem *item)
 
 {
@@ -726,8 +734,8 @@ gnome_canvas_waveview_reset_bounds (GnomeCanvasItem *item)
        gnome_canvas_update_bbox (item, Ix1, Iy1, Ix2, Iy2);
 }
 
        gnome_canvas_update_bbox (item, Ix1, Iy1, Ix2, Iy2);
 }
 
-/* 
- * CANVAS CALLBACKS 
+/*
+ * CANVAS CALLBACKS
  */
 
 static void
  */
 
 static void
@@ -737,6 +745,8 @@ gnome_canvas_waveview_set_property (GObject      *object,
                                    GParamSpec   *pspec)
 
 {
                                    GParamSpec   *pspec)
 
 {
+       (void) pspec;
+
        GnomeCanvasItem *item;
        GnomeCanvasWaveView *waveview;
        int redraw = FALSE;
        GnomeCanvasItem *item;
        GnomeCanvasWaveView *waveview;
        int redraw = FALSE;
@@ -748,6 +758,7 @@ gnome_canvas_waveview_set_property (GObject      *object,
        item = GNOME_CANVAS_ITEM (object);
        waveview = GNOME_CANVAS_WAVEVIEW (object);
 
        item = GNOME_CANVAS_ITEM (object);
        waveview = GNOME_CANVAS_WAVEVIEW (object);
 
+       void * ptr;
        switch (prop_id) {
        case PROP_DATA_SRC:
                gnome_canvas_waveview_set_data_src (waveview, g_value_get_pointer(value));
        switch (prop_id) {
        case PROP_DATA_SRC:
                gnome_canvas_waveview_set_data_src (waveview, g_value_get_pointer(value));
@@ -760,22 +771,27 @@ gnome_canvas_waveview_set_property (GObject      *object,
                break;
 
        case PROP_LENGTH_FUNCTION:
                break;
 
        case PROP_LENGTH_FUNCTION:
-               waveview->length_function = g_value_get_pointer(value);
+               ptr = g_value_get_pointer(value);
+               waveview->length_function = POSIX_FUNC_PTR_CAST(waveview_length_function_t, ptr);
                redraw = TRUE;
                break;
                redraw = TRUE;
                break;
+
        case PROP_SOURCEFILE_LENGTH_FUNCTION:
        case PROP_SOURCEFILE_LENGTH_FUNCTION:
-               waveview->sourcefile_length_function = g_value_get_pointer(value);
+               ptr = g_value_get_pointer(value);
+               waveview->sourcefile_length_function = POSIX_FUNC_PTR_CAST(waveview_sourcefile_length_function_t, ptr);
                redraw = TRUE;
                break;
 
        case PROP_PEAK_FUNCTION:
                redraw = TRUE;
                break;
 
        case PROP_PEAK_FUNCTION:
-               waveview->peak_function = g_value_get_pointer(value);
+               ptr = g_value_get_pointer(value);
+               waveview->peak_function = POSIX_FUNC_PTR_CAST(waveview_peak_function_t, ptr);
                redraw = TRUE;
                break;
 
        case PROP_GAIN_FUNCTION:
                redraw = TRUE;
                break;
 
        case PROP_GAIN_FUNCTION:
-               waveview->gain_curve_function = g_value_get_pointer(value);
-               redraw = TRUE;
+               ptr = g_value_get_pointer(value);
+               waveview->gain_curve_function = POSIX_FUNC_PTR_CAST(waveview_gain_curve_function_t, ptr);
+                        redraw = TRUE;
                break;
 
        case PROP_GAIN_SRC:
                break;
 
        case PROP_GAIN_SRC:
@@ -919,61 +935,62 @@ gnome_canvas_waveview_set_property (GObject      *object,
 }
 
 static void
 }
 
 static void
-gnome_canvas_waveview_get_property (GObject      *object,
-                                   guint         prop_id,
-                                   GValue       *value,
-                                   GParamSpec   *pspec)
+gnome_canvas_waveview_get_property (
+               GObject      *object,
+               guint         prop_id,
+               GValue       *value,
+               GParamSpec   *pspec)
 {
 {
-       
-   
+
+
        g_return_if_fail (object != NULL);
        g_return_if_fail (object != NULL);
-        g_return_if_fail (GNOME_IS_CANVAS_WAVEVIEW (object));
+       g_return_if_fail (GNOME_IS_CANVAS_WAVEVIEW (object));
 
        GnomeCanvasWaveView *waveview = GNOME_CANVAS_WAVEVIEW (object);
 
        switch (prop_id) {
        case PROP_DATA_SRC:
 
        GnomeCanvasWaveView *waveview = GNOME_CANVAS_WAVEVIEW (object);
 
        switch (prop_id) {
        case PROP_DATA_SRC:
-               g_value_set_pointer(value, waveview->data_src);
+               g_value_set_pointer(value, waveview->data_src);
                break;
 
        case PROP_CHANNEL:
                break;
 
        case PROP_CHANNEL:
-               g_value_set_uint(value, waveview->channel);
+               g_value_set_uint(value, waveview->channel);
                break;
 
        case PROP_LENGTH_FUNCTION:
                break;
 
        case PROP_LENGTH_FUNCTION:
-               g_value_set_pointer(value, waveview->length_function);
+               g_value_set_pointer(value, POSIX_FUNC_PTR_CAST(void*, waveview->length_function));
                break;
 
        case PROP_SOURCEFILE_LENGTH_FUNCTION:
                break;
 
        case PROP_SOURCEFILE_LENGTH_FUNCTION:
-               g_value_set_pointer(value, waveview->sourcefile_length_function);
+               g_value_set_pointer(value, POSIX_FUNC_PTR_CAST(void*, waveview->sourcefile_length_function));
                break;
 
        case PROP_PEAK_FUNCTION:
                break;
 
        case PROP_PEAK_FUNCTION:
-               g_value_set_pointer(value, waveview->peak_function);
+               g_value_set_pointer(value, POSIX_FUNC_PTR_CAST(void*, waveview->peak_function));
                break;
 
        case PROP_GAIN_FUNCTION:
                break;
 
        case PROP_GAIN_FUNCTION:
-               g_value_set_pointer(value, waveview->gain_curve_function);
+               g_value_set_pointer(value, POSIX_FUNC_PTR_CAST(void*, waveview->gain_curve_function));
                break;
 
        case PROP_GAIN_SRC:
                break;
 
        case PROP_GAIN_SRC:
-               g_value_set_pointer(value, waveview->gain_src);
+               g_value_set_pointer(value, waveview->gain_src);
                break;
 
        case PROP_CACHE:
                break;
 
        case PROP_CACHE:
-               g_value_set_pointer(value, waveview->cache);
+               g_value_set_pointer(value, waveview->cache);
                break;
 
        case PROP_CACHE_UPDATER:
                break;
 
        case PROP_CACHE_UPDATER:
-               g_value_set_boolean(value, waveview->cache_updater);
+               g_value_set_boolean(value, waveview->cache_updater);
                break;
 
        case PROP_SAMPLES_PER_UNIT:
                break;
 
        case PROP_SAMPLES_PER_UNIT:
-               g_value_set_double(value, waveview->samples_per_unit);
+               g_value_set_double(value, waveview->samples_per_unit);
                break;
 
        case PROP_AMPLITUDE_ABOVE_AXIS:
                break;
 
        case PROP_AMPLITUDE_ABOVE_AXIS:
-               g_value_set_double(value, waveview->amplitude_above_axis);
+               g_value_set_double(value, waveview->amplitude_above_axis);
                break;
 
        case PROP_X:
                break;
 
        case PROP_X:
@@ -1078,7 +1095,7 @@ gnome_canvas_waveview_update (GnomeCanvasItem *item, double *affine, ArtSVP *cli
                      &waveview->fill_a);
 
 //     check_cache (waveview, "end of update");
                      &waveview->fill_a);
 
 //     check_cache (waveview, "end of update");
-}                                 
+}
 
 static void
 gnome_canvas_waveview_render (GnomeCanvasItem *item,
 
 static void
 gnome_canvas_waveview_render (GnomeCanvasItem *item,
@@ -1088,10 +1105,9 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
        gulong s1, s2;
        int clip_length = 0;
        int pymin, pymax;
        gulong s1, s2;
        int clip_length = 0;
        int pymin, pymax;
-       int cache_index;
+       guint cache_index;
        double half_height;
        double half_height;
-       int x, end, begin;
-       int zbegin, zend;
+       int x;
        char rectify;
 
        waveview = GNOME_CANVAS_WAVEVIEW (item);
        char rectify;
 
        waveview = GNOME_CANVAS_WAVEVIEW (item);
@@ -1107,31 +1123,29 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                buf->is_bg = FALSE;
        }
 
                buf->is_bg = FALSE;
        }
 
-       begin = MAX(waveview->bbox_ulx, buf->rect.x0);
+       /* a "unit" means a pixel */
 
 
-       if (begin == waveview->bbox_ulx) {
-               zbegin = begin + 1;
-       } else {
-               zbegin = begin;
-       }
+       /* begin: render start x (units) */
+       int const begin = MAX (waveview->bbox_ulx, buf->rect.x0);
 
 
-       if (waveview->bbox_lrx >= 0) {
-               end = MIN(waveview->bbox_lrx,buf->rect.x1);
-       } else {
-               end = buf->rect.x1;
-       }
+        /* zbegin: start x for zero line (units) */
+       int const zbegin = (begin == waveview->bbox_ulx) ? (begin + 1) : begin;
 
 
-       if (end == waveview->bbox_lrx) {
-               zend = end - 1;
-       } else {
-               zend = end;
-       }
+       /* end: render end x (units) */
+       int const end = (waveview->bbox_lrx >= 0) ? MIN (waveview->bbox_lrx,buf->rect.x1) : buf->rect.x1;
+
+       /* zend: end x for zero-line (units) */
+       int const zend = (end == waveview->bbox_lrx) ? (end - 1) : end;
 
        if (begin == end) {
                return;
        }
 
 
        if (begin == end) {
                return;
        }
 
-       s1 = floor ((begin - waveview->bbox_ulx) * waveview->samples_per_unit) ;
+       /* s1: start sample
+          s2: end sample
+       */
+
+       s1 = floor ((begin - waveview->bbox_ulx) * waveview->samples_per_unit);
 
        // fprintf (stderr, "0x%x begins at sample %f\n", waveview, waveview->bbox_ulx * waveview->samples_per_unit);
 
 
        // fprintf (stderr, "0x%x begins at sample %f\n", waveview, waveview->bbox_ulx * waveview->samples_per_unit);
 
@@ -1175,7 +1189,7 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
 //     check_cache (waveview, "post-ensure");
 
        /* don't rectify at single-sample zoom */
 //     check_cache (waveview, "post-ensure");
 
        /* don't rectify at single-sample zoom */
-       if(waveview->rectified && waveview->samples_per_unit > 1) {
+       if (waveview->rectified && waveview->samples_per_unit > 1) {
                rectify = TRUE;
        }
        else {
                rectify = TRUE;
        }
        else {
@@ -1184,7 +1198,7 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
 
        clip_length = MIN(5,(waveview->height/4));
 
 
        clip_length = MIN(5,(waveview->height/4));
 
-       /* 
+       /*
           Now draw each line, clipping it appropriately. The clipping
           is done by the macros PAINT_FOO().
        */
           Now draw each line, clipping it appropriately. The clipping
           is done by the macros PAINT_FOO().
        */
@@ -1194,7 +1208,7 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
 /* this makes it slightly easier to comprehend whats going on */
 #define origin half_height
 
 /* this makes it slightly easier to comprehend whats going on */
 #define origin half_height
 
-       if(waveview->filled && !rectify) {
+       if (waveview->filled && !rectify) {
                int prev_pymin = 1;
                int prev_pymax = 0;
                int last_pymin = 1;
                int prev_pymin = 1;
                int prev_pymax = 0;
                int last_pymin = 1;
@@ -1204,7 +1218,7 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                int next_clip_max = 0;
                int next_clip_min = 0;
 
                int next_clip_max = 0;
                int next_clip_min = 0;
 
-               if(s1 < waveview->samples_per_unit) {
+               if (s1 < waveview->samples_per_unit) {
                        /* we haven't got a prev vars to compare with, so outline the whole line here */
                        prev_pymax = (int) rint ((item->y1 + origin) * item->canvas->pixels_per_unit);
                        prev_pymin = prev_pymax;
                        /* we haven't got a prev vars to compare with, so outline the whole line here */
                        prev_pymax = (int) rint ((item->y1 + origin) * item->canvas->pixels_per_unit);
                        prev_pymin = prev_pymax;
@@ -1228,37 +1242,50 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                 * Compute the variables outside the rendering rect
                 */
                if(prev_pymax != prev_pymin) {
                 * Compute the variables outside the rendering rect
                 */
                if(prev_pymax != prev_pymin) {
+
                        prev_pymax = (int) rint ((item->y1 + origin - MIN(waveview->cache->data[cache_index].max, 1.0) * half_height) * item->canvas->pixels_per_unit);
                        prev_pymin = (int) rint ((item->y1 + origin - MAX(waveview->cache->data[cache_index].min, -1.0) * half_height) * item->canvas->pixels_per_unit);
                        ++cache_index;
                }
                if(last_pymax != last_pymin) {
                        /* take the index of one sample right of what we render */
                        prev_pymax = (int) rint ((item->y1 + origin - MIN(waveview->cache->data[cache_index].max, 1.0) * half_height) * item->canvas->pixels_per_unit);
                        prev_pymin = (int) rint ((item->y1 + origin - MAX(waveview->cache->data[cache_index].min, -1.0) * half_height) * item->canvas->pixels_per_unit);
                        ++cache_index;
                }
                if(last_pymax != last_pymin) {
                        /* take the index of one sample right of what we render */
-                       int index = cache_index + (end - begin);
-                       
-                       last_pymax = (int) rint ((item->y1 + origin - MIN(waveview->cache->data[index].max, 1.0) * half_height) * item->canvas->pixels_per_unit);
-                       last_pymin = (int) rint ((item->y1 + origin - MAX(waveview->cache->data[index].min, -1.0) * half_height) * item->canvas->pixels_per_unit);
+                       guint index = cache_index + (end - begin);
+
+                       if (index >= waveview->cache->data_size) {
+
+                               /* the data we want is off the end of the cache, which must mean its beyond
+                                  the end of the region's source; hence the peak values are 0 */
+                               last_pymax = (int) rint ((item->y1 + origin) * item->canvas->pixels_per_unit);
+                               last_pymin = (int) rint ((item->y1 + origin) * item->canvas->pixels_per_unit);
+
+                       } else {
+
+                               last_pymax = (int) rint ((item->y1 + origin - MIN(waveview->cache->data[index].max, 1.0) * half_height) * item->canvas->pixels_per_unit);
+                               last_pymin = (int) rint ((item->y1 + origin - MAX(waveview->cache->data[index].min, -1.0) * half_height) * item->canvas->pixels_per_unit);
+
+                       }
+
                }
 
                }
 
-               /* 
+               /*
                 * initialize NEXT* variables for the first run, duplicated in the loop for speed
                 */
                max = waveview->cache->data[cache_index].max;
                min = waveview->cache->data[cache_index].min;
                 * initialize NEXT* variables for the first run, duplicated in the loop for speed
                 */
                max = waveview->cache->data[cache_index].max;
                min = waveview->cache->data[cache_index].min;
-               
+
                if (max >= 1.0) {
                        max = 1.0;
                        next_clip_max = 1;
                }
                if (max >= 1.0) {
                        max = 1.0;
                        next_clip_max = 1;
                }
-               
+
                if (min <= -1.0) {
                        min = -1.0;
                        next_clip_min = 1;
                }
                if (min <= -1.0) {
                        min = -1.0;
                        next_clip_min = 1;
                }
-               
+
                max *= half_height;
                min *= half_height;
                max *= half_height;
                min *= half_height;
-               
+
                next_pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
                next_pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
 
                next_pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
                next_pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
 
@@ -1282,8 +1309,12 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                        else {
                                ++cache_index;
 
                        else {
                                ++cache_index;
 
-                               max = waveview->cache->data[cache_index].max;
-                               min = waveview->cache->data[cache_index].min;
+                               if (cache_index < waveview->cache->data_size) {
+                                       max = waveview->cache->data[cache_index].max;
+                                       min = waveview->cache->data[cache_index].min;
+                               } else {
+                                       max = min = 0;
+                               }
 
                                next_clip_max = 0;
                                next_clip_min = 0;
 
                                next_clip_max = 0;
                                next_clip_min = 0;
@@ -1292,7 +1323,7 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                                        max = 1.0;
                                        next_clip_max = 1;
                                }
                                        max = 1.0;
                                        next_clip_max = 1;
                                }
-                               
+
                                if (min <= -1.0) {
                                        min = -1.0;
                                        next_clip_min = 1;
                                if (min <= -1.0) {
                                        min = -1.0;
                                        next_clip_min = 1;
@@ -1300,11 +1331,11 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
 
                                max *= half_height;
                                min *= half_height;
 
                                max *= half_height;
                                min *= half_height;
-                               
+
                                next_pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
                                next_pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
                        }
                                next_pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
                                next_pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
                        }
-                       
+
                        /* render */
                        if (pymax == pymin) {
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
                        /* render */
                        if (pymax == pymin) {
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
@@ -1351,7 +1382,7 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                        if (clip_max) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
                        }
                        if (clip_max) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
                        }
-                       
+
                        if (clip_min) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
                        }
                        if (clip_min) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
                        }
@@ -1407,7 +1438,7 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                if(last_pymax < 0) {
                        /* take the index of one sample right of what we render */
                        int index = cache_index + (end - begin);
                if(last_pymax < 0) {
                        /* take the index of one sample right of what we render */
                        int index = cache_index + (end - begin);
-                       
+
                        max = MIN(waveview->cache->data[index].max, 1.0);
                        min = MAX(waveview->cache->data[index].min, -1.0);
 
                        max = MIN(waveview->cache->data[index].max, 1.0);
                        min = MAX(waveview->cache->data[index].min, -1.0);
 
@@ -1418,26 +1449,26 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                        last_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
                }
 
                        last_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
                }
 
-               /* 
+               /*
                 * initialize NEXT* variables for the first run, duplicated in the loop for speed
                 */
                max = waveview->cache->data[cache_index].max;
                min = waveview->cache->data[cache_index].min;
                 * initialize NEXT* variables for the first run, duplicated in the loop for speed
                 */
                max = waveview->cache->data[cache_index].max;
                min = waveview->cache->data[cache_index].min;
-               
+
                if (max >= 1.0) {
                        max = 1.0;
                        next_clip_max = 1;
                }
                if (max >= 1.0) {
                        max = 1.0;
                        next_clip_max = 1;
                }
-               
+
                if (min <= -1.0) {
                        min = -1.0;
                        next_clip_min = 1;
                }
                if (min <= -1.0) {
                        min = -1.0;
                        next_clip_min = 1;
                }
-               
+
                if (fabs (min) > fabs (max)) {
                        max = fabs (min);
                if (fabs (min) > fabs (max)) {
                        max = fabs (min);
-               } 
-               
+               }
+
                next_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
 
                /*
                next_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
 
                /*
@@ -1460,24 +1491,24 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
 
                                max = waveview->cache->data[cache_index].max;
                                min = waveview->cache->data[cache_index].min;
 
                                max = waveview->cache->data[cache_index].max;
                                min = waveview->cache->data[cache_index].min;
-                               
+
                                if (max >= 1.0) {
                                        max = 1.0;
                                        next_clip_max = 1;
                                }
                                if (max >= 1.0) {
                                        max = 1.0;
                                        next_clip_max = 1;
                                }
-                               
+
                                if (min <= -1.0) {
                                        min = -1.0;
                                        next_clip_min = 1;
                                }
                                if (min <= -1.0) {
                                        min = -1.0;
                                        next_clip_min = 1;
                                }
-                               
+
                                if (fabs (min) > fabs (max)) {
                                        max = fabs (min);
                                if (fabs (min) > fabs (max)) {
                                        max = fabs (min);
-                               } 
-                               
+                               }
+
                                next_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
                        }
                                next_pymax = (int) rint ((item->y1 + waveview->height - max * waveview->height) * item->canvas->pixels_per_unit);
                        }
-                       
+
                        /* render */
                        if (pymax == pymin) {
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
                        /* render */
                        if (pymax == pymin) {
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
@@ -1509,7 +1540,7 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                        if (clip_max) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
                        }
                        if (clip_max) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
                        }
-                       
+
                        if (clip_min) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
                        }
                        if (clip_min) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
                        }
@@ -1521,80 +1552,79 @@ gnome_canvas_waveview_render (GnomeCanvasItem *item,
                cache_index = gnome_canvas_waveview_ensure_cache (waveview, s1, s2);
 
                for (x = begin; x < end; x++) {
                cache_index = gnome_canvas_waveview_ensure_cache (waveview, s1, s2);
 
                for (x = begin; x < end; x++) {
-                       
+
                        double max, min;
                        int clip_max, clip_min;
                        double max, min;
                        int clip_max, clip_min;
-                       
+
                        clip_max = 0;
                        clip_min = 0;
                        clip_max = 0;
                        clip_min = 0;
-                       
+
                        max = waveview->cache->data[cache_index].max;
                        min = waveview->cache->data[cache_index].min;
                        max = waveview->cache->data[cache_index].max;
                        min = waveview->cache->data[cache_index].min;
-                       
+
                        if (max >= 1.0) {
                                max = 1.0;
                                clip_max = 1;
                        }
                        if (max >= 1.0) {
                                max = 1.0;
                                clip_max = 1;
                        }
-                       
+
                        if (min <= -1.0) {
                                min = -1.0;
                                clip_min = 1;
                        }
                        if (min <= -1.0) {
                                min = -1.0;
                                clip_min = 1;
                        }
-                       
+
                        if (rectify) {
                        if (rectify) {
-                               
+
                                if (fabs (min) > fabs (max)) {
                                        max = fabs (min);
                                if (fabs (min) > fabs (max)) {
                                        max = fabs (min);
-                               } 
-                               
+                               }
+
                                max = max * waveview->height;
                                max = max * waveview->height;
-                               
+
                                pymax = (int) rint ((item->y1 + waveview->height - max) * item->canvas->pixels_per_unit);
                                pymin = (int) rint ((item->y1 + waveview->height) * item->canvas->pixels_per_unit);
                                pymax = (int) rint ((item->y1 + waveview->height - max) * item->canvas->pixels_per_unit);
                                pymin = (int) rint ((item->y1 + waveview->height) * item->canvas->pixels_per_unit);
-                               
+
                        } else {
                        } else {
-                               
+
                                max = max * half_height;
                                min = min * half_height;
                                max = max * half_height;
                                min = min * half_height;
-                               
+
                                pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
                                pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
                        }
                                pymax = (int) rint ((item->y1 + origin - max) * item->canvas->pixels_per_unit);
                                pymin = (int) rint ((item->y1 + origin - min) * item->canvas->pixels_per_unit);
                        }
-                       
+
                        /* OK, now fill the RGB buffer at x=i with a line between pymin and pymax,
                           or, if samples_per_unit == 1, then a dot at each location.
                        */
                        /* OK, now fill the RGB buffer at x=i with a line between pymin and pymax,
                           or, if samples_per_unit == 1, then a dot at each location.
                        */
-                       
+
                        if (pymax == pymin) {
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
                        } else {
                                PAINT_VERTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax, pymin);
                        }
                        if (pymax == pymin) {
                                PAINT_DOTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymin);
                        } else {
                                PAINT_VERTA(buf, waveview->wave_r, waveview->wave_g, waveview->wave_b, waveview->wave_a, x, pymax, pymin);
                        }
-                       
+
                        /* show clipped waveforms with small red lines */
                        /* show clipped waveforms with small red lines */
-                       
+
                        if (clip_max) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
                        }
                        if (clip_max) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymax, pymax+clip_length);
                        }
-                       
+
                        if (clip_min) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
                        }
 
                        /* presto, we're done */
                        if (clip_min) {
                                PAINT_VERTA(buf, waveview->clip_r, waveview->clip_g, waveview->clip_b, waveview->clip_a, x, pymin-clip_length, pymin);
                        }
 
                        /* presto, we're done */
-               
+
                        cache_index++;
                }
        }
 
                        cache_index++;
                }
        }
 
-       if (!waveview->rectified && waveview->zero_line) {
+       if (!waveview->rectified && waveview->zero_line && waveview->height >= 100) {
                // Paint zeroline.
                // Paint zeroline.
-               //PAINT_HORIZA(buf, waveview->zero_r, waveview->zero_g, waveview->zero_b, waveview->zero_a, begin, endi-1, origin );
-               
+
                unsigned char zero_r, zero_g, zero_b, zero_a;
                unsigned char zero_r, zero_g, zero_b, zero_a;
-               UINT_TO_RGBA( waveview->zero_color, &zero_r, &zero_g, &zero_b, &zero_a );
+               UINT_TO_RGBA( waveview->zero_color, &zero_r, &zero_g, &zero_b, &zero_a);
                int zeroline_y = (int) rint ((item->y1 + origin) * item->canvas->pixels_per_unit);
                int zeroline_y = (int) rint ((item->y1 + origin) * item->canvas->pixels_per_unit);
-               PAINT_HORIZA(buf, zero_r, zero_g, zero_b, zero_a, zbegin, end, zeroline_y);
+               PAINT_HORIZA(buf, zero_r, zero_g, zero_b, zero_a, zbegin, zend, zeroline_y);
        }
 #undef origin
 
        }
 #undef origin
 
@@ -1610,7 +1640,6 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
        cairo_t* cr;
        gulong s1, s2;
        int cache_index;
        cairo_t* cr;
        gulong s1, s2;
        int cache_index;
-       double zbegin, zend;
        gboolean rectify;
        double origin;
        double clip_length;
        gboolean rectify;
        double origin;
        double clip_length;
@@ -1629,10 +1658,8 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
 
        if (x > waveview->bbox_ulx) {
                ulx = x;
 
        if (x > waveview->bbox_ulx) {
                ulx = x;
-               zbegin = ulx;
        } else {
                ulx = waveview->bbox_ulx;
        } else {
                ulx = waveview->bbox_ulx;
-               zbegin = ulx + 1;
        }
 
        if (y > waveview->bbox_uly) {
        }
 
        if (y > waveview->bbox_uly) {
@@ -1643,10 +1670,8 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
 
        if (x + width > waveview->bbox_lrx) {
                lrx = waveview->bbox_lrx;
 
        if (x + width > waveview->bbox_lrx) {
                lrx = waveview->bbox_lrx;
-               zend = lrx - 1;
        } else {
                lrx = x + width;
        } else {
                lrx = x + width;
-               zend = lrx;
        }
 
        if (y + height > waveview->bbox_lry) {
        }
 
        if (y + height > waveview->bbox_lry) {
@@ -1674,8 +1699,6 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
        uly -= y;
        lrx -= x;
        lry -= y;
        uly -= y;
        lrx -= x;
        lry -= y;
-       zbegin -= x;
-       zend -= x;
 
        /* don't rectify at single-sample zoom */
        if(waveview->rectified && waveview->samples_per_unit > 1.0) {
 
        /* don't rectify at single-sample zoom */
        if(waveview->rectified && waveview->samples_per_unit > 1.0) {
@@ -1706,7 +1729,7 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
        printf ("%p r (%d,%d)(%d,%d)[%d x %d] bbox (%d,%d)(%d,%d)[%d x %d]"
                " draw (%.1f,%.1f)(%.1f,%.1f)[%.1f x %.1f] s= %lu..%lu\n",
                waveview,
        printf ("%p r (%d,%d)(%d,%d)[%d x %d] bbox (%d,%d)(%d,%d)[%d x %d]"
                " draw (%.1f,%.1f)(%.1f,%.1f)[%.1f x %.1f] s= %lu..%lu\n",
                waveview,
-               x, y, 
+               x, y,
                x + width,
                y + height,
                width,
                x + width,
                y + height,
                width,
@@ -1725,7 +1748,7 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
 #endif
 
        /* draw the top half */
 #endif
 
        /* draw the top half */
-       
+
        for (xoff = ulx; xoff < lrx; xoff++) {
                double max, min;
 
        for (xoff = ulx; xoff < lrx; xoff++) {
                double max, min;
 
@@ -1735,19 +1758,19 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
                if (min <= -1.0) {
                        min = -1.0;
                }
                if (min <= -1.0) {
                        min = -1.0;
                }
-               
+
                if (max >= 1.0) {
                        max = 1.0;
                }
                if (max >= 1.0) {
                        max = 1.0;
                }
-               
+
                if (rectify) {
                        if (fabs (min) > fabs (max)) {
                                max = fabs (min);
                if (rectify) {
                        if (fabs (min) > fabs (max)) {
                                max = fabs (min);
-                       } 
-               } 
-               
+                       }
+               }
+
                yoff = origin - (waveview->half_height * max) + 0.5;
                yoff = origin - (waveview->half_height * max) + 0.5;
-               
+
                if (xoff == ulx) {
                        /* first point */
                        cairo_move_to (cr, xoff+0.5, yoff);
                if (xoff == ulx) {
                        /* first point */
                        cairo_move_to (cr, xoff+0.5, yoff);
@@ -1759,9 +1782,9 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
        }
 
        /* from the final top point, move out of the clip zone */
        }
 
        /* from the final top point, move out of the clip zone */
-       
+
        cairo_line_to (cr, xoff + 10, yoff);
        cairo_line_to (cr, xoff + 10, yoff);
-       
+
        /* now draw the bottom half */
 
        for (--xoff, --cache_index; xoff >= ulx; --xoff) {
        /* now draw the bottom half */
 
        for (--xoff, --cache_index; xoff >= ulx; --xoff) {
@@ -1782,23 +1805,23 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
        /* from the final lower point, move out of the clip zone */
 
        cairo_line_to (cr, xoff - 10, yoff);
        /* from the final lower point, move out of the clip zone */
 
        cairo_line_to (cr, xoff - 10, yoff);
-       
+
        /* close path to fill */
 
        cairo_close_path (cr);
 
        /* fill and stroke */
 
        /* close path to fill */
 
        cairo_close_path (cr);
 
        /* fill and stroke */
 
-       cairo_set_source_rgba (cr, 
-                              (waveview->fill_r/255.0), 
-                              (waveview->fill_g/255.0), 
-                              (waveview->fill_b/255.0), 
+       cairo_set_source_rgba (cr,
+                              (waveview->fill_r/255.0),
+                              (waveview->fill_g/255.0),
+                              (waveview->fill_b/255.0),
                               (waveview->fill_a/255.0));
        cairo_fill_preserve (cr);
                               (waveview->fill_a/255.0));
        cairo_fill_preserve (cr);
-       cairo_set_source_rgba (cr, 
-                              (waveview->wave_r/255.0), 
-                              (waveview->wave_g/255.0), 
-                              (waveview->wave_b/255.0), 
+       cairo_set_source_rgba (cr,
+                              (waveview->wave_r/255.0),
+                              (waveview->wave_g/255.0),
+                              (waveview->wave_b/255.0),
                               (waveview->wave_a/255.0));
        cairo_stroke (cr);
 
                               (waveview->wave_a/255.0));
        cairo_stroke (cr);
 
@@ -1815,13 +1838,13 @@ gnome_canvas_waveview_draw (GnomeCanvasItem *item,
                        cairo_line_to (cr, xoff, yoff1 + clip_length);
                        cairo_stroke (cr);
                }
                        cairo_line_to (cr, xoff, yoff1 + clip_length);
                        cairo_stroke (cr);
                }
-               
+
                if (clip_min) {
                        cairo_move_to (cr, xoff, yoff2);
                        cairo_line_to (cr, xoff, yoff2 - clip_length);
                        cairo_stroke (cr);
                }
                if (clip_min) {
                        cairo_move_to (cr, xoff, yoff2);
                        cairo_line_to (cr, xoff, yoff2 - clip_length);
                        cairo_stroke (cr);
                }
-               
+
 #endif
 
 static void
 #endif
 
 static void
@@ -1844,14 +1867,21 @@ gnome_canvas_waveview_bounds (GnomeCanvasItem *item, double *x1, double *y1, dou
        gnome_canvas_item_i2w (item, &x, &y);
        gnome_canvas_w2c_d (GNOME_CANVAS(item->canvas), x, y, &c, &d);
        printf ("item bounds now (%g,%g),(%g,%g)\n", a, b, c, d);
        gnome_canvas_item_i2w (item, &x, &y);
        gnome_canvas_w2c_d (GNOME_CANVAS(item->canvas), x, y, &c, &d);
        printf ("item bounds now (%g,%g),(%g,%g)\n", a, b, c, d);
-#endif         
+#endif
 
 }
 
 static double
 gnome_canvas_waveview_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
 {
 
 }
 
 static double
 gnome_canvas_waveview_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item)
 {
-       /* XXX for now, point is never inside the wave 
+       (void) item;
+       (void) x;
+       (void) y;
+       (void) cx;
+       (void) cy;
+       (void) actual_item;
+
+       /* XXX for now, point is never inside the wave
        GnomeCanvasWaveView *waveview;
        double x1, y1, x2, y2;
        double dx, dy;
        GnomeCanvasWaveView *waveview;
        double x1, y1, x2, y2;
        double dx, dy;
@@ -1869,7 +1899,7 @@ gnome_canvas_waveview_point (GnomeCanvasItem *item, double x, double y, int cx,
        gnome_canvas_waveview_bounds (item, &x1, &y1, &x2, &y2);
 
        /* Is point inside rectangle */
        gnome_canvas_waveview_bounds (item, &x1, &y1, &x2, &y2);
 
        /* Is point inside rectangle */
-       
+
        if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
                return 0.0;
        }
        if ((x >= x1) && (y >= y1) && (x <= x2) && (y <= y2)) {
                return 0.0;
        }