changeset 1057:5c5d4863b428 tonioni

Merge from cxx11 branch
author Chris Cannam
date Mon, 23 Mar 2015 11:26:28 +0000 (2015-03-23)
parents c4898e57eea5 (current diff) 0559f25b99f2 (diff)
children c49d52386cde
files data/fileio/MatchFileReader.cpp data/fileio/MatchFileReader.h
diffstat 151 files changed, 1953 insertions(+), 1783 deletions(-) [+]
line wrap: on
line diff
--- a/acinclude.m4	Mon Mar 23 10:04:48 2015 +0000
+++ b/acinclude.m4	Mon Mar 23 11:26:28 2015 +0000
@@ -112,3 +112,146 @@
 
 ])
 
+# From autoconf archive:
+
+# ============================================================================
+#  http://www.gnu.org/software/autoconf-archive/ax_cxx_compile_stdcxx_11.html
+# ============================================================================
+#
+# SYNOPSIS
+#
+#   AX_CXX_COMPILE_STDCXX_11([ext|noext],[mandatory|optional])
+#
+# DESCRIPTION
+#
+#   Check for baseline language coverage in the compiler for the C++11
+#   standard; if necessary, add switches to CXXFLAGS to enable support.
+#
+#   The first argument, if specified, indicates whether you insist on an
+#   extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
+#   -std=c++11).  If neither is specified, you get whatever works, with
+#   preference for an extended mode.
+#
+#   The second argument, if specified 'mandatory' or if left unspecified,
+#   indicates that baseline C++11 support is required and that the macro
+#   should error out if no mode with that support is found.  If specified
+#   'optional', then configuration proceeds regardless, after defining
+#   HAVE_CXX11 if and only if a supporting mode is found.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Benjamin Kosnik <bkoz@redhat.com>
+#   Copyright (c) 2012 Zack Weinberg <zackw@panix.com>
+#   Copyright (c) 2013 Roy Stogner <roystgnr@ices.utexas.edu>
+#   Copyright (c) 2014 Alexey Sokolov <sokolov@google.com>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+m4_define([_AX_CXX_COMPILE_STDCXX_11_testbody], [[
+  template <typename T>
+    struct check
+    {
+      static_assert(sizeof(int) <= sizeof(T), "not big enough");
+    };
+
+    struct Base {
+    virtual void f() {}
+    };
+    struct Child : public Base {
+    virtual void f() override {}
+    };
+
+    typedef check<check<bool>> right_angle_brackets;
+
+    int a;
+    decltype(a) b;
+
+    typedef check<int> check_type;
+    check_type c;
+    check_type&& cr = static_cast<check_type&&>(c);
+
+    auto d = a;
+    auto l = [](){};
+]])
+
+AC_DEFUN([AX_CXX_COMPILE_STDCXX_11], [dnl
+  m4_if([$1], [], [],
+        [$1], [ext], [],
+        [$1], [noext], [],
+        [m4_fatal([invalid argument `$1' to AX_CXX_COMPILE_STDCXX_11])])dnl
+  m4_if([$2], [], [ax_cxx_compile_cxx11_required=true],
+        [$2], [mandatory], [ax_cxx_compile_cxx11_required=true],
+        [$2], [optional], [ax_cxx_compile_cxx11_required=false],
+        [m4_fatal([invalid second argument `$2' to AX_CXX_COMPILE_STDCXX_11])])
+  AC_LANG_PUSH([C++])dnl
+  ac_success=no
+  AC_CACHE_CHECK(whether $CXX supports C++11 features by default,
+  ax_cv_cxx_compile_cxx11,
+  [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
+    [ax_cv_cxx_compile_cxx11=yes],
+    [ax_cv_cxx_compile_cxx11=no])])
+  if test x$ax_cv_cxx_compile_cxx11 = xyes; then
+    ac_success=yes
+  fi
+
+  m4_if([$1], [noext], [], [dnl
+  if test x$ac_success = xno; then
+    for switch in -std=gnu++11 -std=gnu++0x; do
+      cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
+      AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
+                     $cachevar,
+        [ac_save_CXXFLAGS="$CXXFLAGS"
+         CXXFLAGS="$CXXFLAGS $switch"
+         AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
+          [eval $cachevar=yes],
+          [eval $cachevar=no])
+         CXXFLAGS="$ac_save_CXXFLAGS"])
+      if eval test x\$$cachevar = xyes; then
+        CXXFLAGS="$CXXFLAGS $switch"
+        ac_success=yes
+        break
+      fi
+    done
+  fi])
+
+  m4_if([$1], [ext], [], [dnl
+  if test x$ac_success = xno; then
+    for switch in -std=c++11 -std=c++0x; do
+      cachevar=AS_TR_SH([ax_cv_cxx_compile_cxx11_$switch])
+      AC_CACHE_CHECK(whether $CXX supports C++11 features with $switch,
+                     $cachevar,
+        [ac_save_CXXFLAGS="$CXXFLAGS"
+         CXXFLAGS="$CXXFLAGS $switch"
+         AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_11_testbody])],
+          [eval $cachevar=yes],
+          [eval $cachevar=no])
+         CXXFLAGS="$ac_save_CXXFLAGS"])
+      if eval test x\$$cachevar = xyes; then
+        CXXFLAGS="$CXXFLAGS $switch"
+        ac_success=yes
+        break
+      fi
+    done
+  fi])
+  AC_LANG_POP([C++])
+  if test x$ax_cxx_compile_cxx11_required = xtrue; then
+    if test x$ac_success = xno; then
+      AC_MSG_ERROR([*** A compiler with support for C++11 language features is required.])
+    fi
+  else
+    if test x$ac_success = xno; then
+      HAVE_CXX11=0
+      AC_MSG_NOTICE([No compiler with C++11 support was found])
+    else
+      HAVE_CXX11=1
+      AC_DEFINE(HAVE_CXX11,1,
+                [define if the compiler supports basic C++11 syntax])
+    fi
+
+    AC_SUBST(HAVE_CXX11)
+  fi
+])
+
--- a/base/AudioLevel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/AudioLevel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -26,52 +26,52 @@
 #include <cassert>
 #include "system/System.h"
 
-const float AudioLevel::DB_FLOOR = -1000.f;
+const double AudioLevel::DB_FLOOR = -1000.;
 
 struct FaderDescription
 {
-    FaderDescription(float _minDb, float _maxDb, float _zeroPoint) :
+    FaderDescription(double _minDb, double _maxDb, double _zeroPoint) :
 	minDb(_minDb), maxDb(_maxDb), zeroPoint(_zeroPoint) { }
 
-    float minDb;
-    float maxDb;
-    float zeroPoint; // as fraction of total throw
+    double minDb;
+    double maxDb;
+    double zeroPoint; // as fraction of total throw
 };
 
 static const FaderDescription faderTypes[] = {
-    FaderDescription(-40.f,  +6.f, 0.75f), // short
-    FaderDescription(-70.f, +10.f, 0.80f), // long
-    FaderDescription(-70.f,   0.f, 1.00f), // IEC268
-    FaderDescription(-70.f, +10.f, 0.80f), // IEC268 long
-    FaderDescription(-40.f,   0.f, 1.00f), // preview
+    FaderDescription(-40.,  +6., 0.75), // short
+    FaderDescription(-70., +10., 0.80), // long
+    FaderDescription(-70.,   0., 1.00), // IEC268
+    FaderDescription(-70., +10., 0.80), // IEC268 long
+    FaderDescription(-40.,   0., 1.00), // preview
 };
 
-//typedef std::vector<float> LevelList;
+//typedef std::vector<double> LevelList;
 //static std::map<int, LevelList> previewLevelCache;
 //static const LevelList &getPreviewLevelCache(int levels);
 
-float
-AudioLevel::multiplier_to_dB(float multiplier)
+double
+AudioLevel::multiplier_to_dB(double multiplier)
 {
-    if (multiplier == 0.f) return DB_FLOOR;
-    else if (multiplier < 0.f) return multiplier_to_dB(-multiplier);
-    float dB = 10 * log10f(multiplier);
+    if (multiplier == 0.) return DB_FLOOR;
+    else if (multiplier < 0.) return multiplier_to_dB(-multiplier);
+    double dB = 10 * log10(multiplier);
     return dB;
 }
 
-float
-AudioLevel::dB_to_multiplier(float dB)
+double
+AudioLevel::dB_to_multiplier(double dB)
 {
-    if (dB == DB_FLOOR) return 0.f;
-    float m = powf(10.f, dB / 10.f);
+    if (dB == DB_FLOOR) return 0.;
+    double m = pow(10., dB / 10.);
     return m;
 }
 
 /* IEC 60-268-18 fader levels.  Thanks to Steve Harris. */
 
-static float iec_dB_to_fader(float db)
+static double iec_dB_to_fader(double db)
 {
-    float def = 0.0f; // Meter deflection %age
+    double def = 0.0f; // Meter deflection %age
 
     if (db < -70.0f) {
         def = 0.0f;
@@ -92,9 +92,9 @@
     return def;
 }
 
-static float iec_fader_to_dB(float def)  // Meter deflection %age
+static double iec_fader_to_dB(double def)  // Meter deflection %age
 {
-    float db = 0.0f;
+    double db = 0.0f;
 
     if (def >= 50.0f) {
 	db = (def - 50.0f) / 2.5f - 20.0f;
@@ -113,16 +113,16 @@
     return db;
 }
 
-float
+double
 AudioLevel::fader_to_dB(int level, int maxLevel, FaderType type)
 {
     if (level == 0) return DB_FLOOR;
 
     if (type == IEC268Meter || type == IEC268LongMeter) {
 
-	float maxPercent = iec_dB_to_fader(faderTypes[type].maxDb);
-	float percent = float(level) * maxPercent / float(maxLevel);
-	float dB = iec_fader_to_dB(percent);
+	double maxPercent = iec_dB_to_fader(faderTypes[type].maxDb);
+	double percent = double(level) * maxPercent / double(maxLevel);
+	double dB = iec_fader_to_dB(percent);
 	return dB;
 
     } else { // scale proportional to sqrt(fabs(dB))
@@ -131,27 +131,27 @@
     
 	if (level >= zeroLevel) {
 	    
-	    float value = level - zeroLevel;
-	    float scale = float(maxLevel - zeroLevel) /
-		sqrtf(faderTypes[type].maxDb);
+	    double value = level - zeroLevel;
+	    double scale = (maxLevel - zeroLevel) /
+		sqrt(faderTypes[type].maxDb);
 	    value /= scale;
-	    float dB = powf(value, 2.f);
+	    double dB = pow(value, 2.);
 	    return dB;
 	    
 	} else {
 	    
-	    float value = zeroLevel - level;
-	    float scale = zeroLevel / sqrtf(0.f - faderTypes[type].minDb);
+	    double value = zeroLevel - level;
+	    double scale = zeroLevel / sqrt(0. - faderTypes[type].minDb);
 	    value /= scale;
-	    float dB = powf(value, 2.f);
-	    return 0.f - dB;
+	    double dB = pow(value, 2.);
+	    return 0. - dB;
 	}
     }
 }
 
 
 int
-AudioLevel::dB_to_fader(float dB, int maxLevel, FaderType type)
+AudioLevel::dB_to_fader(double dB, int maxLevel, FaderType type)
 {
     if (dB == DB_FLOOR) return 0;
 
@@ -162,8 +162,8 @@
 	// result not as a percentage, but as a scale between 0 and
 	// whatever the "percentage" for our (possibly >0dB) max dB is.
 	
-	float maxPercent = iec_dB_to_fader(faderTypes[type].maxDb);
-	float percent = iec_dB_to_fader(dB);
+	double maxPercent = iec_dB_to_fader(faderTypes[type].maxDb);
+	double percent = iec_dB_to_fader(dB);
 	int faderLevel = int((maxLevel * percent) / maxPercent + 0.01f);
 	
 	if (faderLevel < 0) faderLevel = 0;
@@ -174,16 +174,16 @@
 
 	int zeroLevel = int(maxLevel * faderTypes[type].zeroPoint);
 
-	if (dB >= 0.f) {
+	if (dB >= 0.) {
 	    
-            if (faderTypes[type].maxDb <= 0.f) {
+            if (faderTypes[type].maxDb <= 0.) {
                 
                 return maxLevel;
 
             } else {
 
-                float value = sqrtf(dB);
-                float scale = (maxLevel - zeroLevel) / sqrtf(faderTypes[type].maxDb);
+                double value = sqrt(dB);
+                double scale = (maxLevel - zeroLevel) / sqrt(faderTypes[type].maxDb);
                 value *= scale;
                 int level = int(value + 0.01f) + zeroLevel;
                 if (level > maxLevel) level = maxLevel;
@@ -192,9 +192,9 @@
 	    
 	} else {
 
-	    dB = 0.f - dB;
-	    float value = sqrtf(dB);
-	    float scale = zeroLevel / sqrtf(0.f - faderTypes[type].minDb);
+	    dB = 0. - dB;
+	    double value = sqrt(dB);
+	    double scale = zeroLevel / sqrt(0. - faderTypes[type].minDb);
 	    value *= scale;
 	    int level = zeroLevel - int(value + 0.01f);
 	    if (level < 0) level = 0;
@@ -204,18 +204,18 @@
 }
 
 	
-float
+double
 AudioLevel::fader_to_multiplier(int level, int maxLevel, FaderType type)
 {
-    if (level == 0) return 0.f;
+    if (level == 0) return 0.;
     return dB_to_multiplier(fader_to_dB(level, maxLevel, type));
 }
 
 int
-AudioLevel::multiplier_to_fader(float multiplier, int maxLevel, FaderType type)
+AudioLevel::multiplier_to_fader(double multiplier, int maxLevel, FaderType type)
 {
-    if (multiplier == 0.f) return 0;
-    float dB = multiplier_to_dB(multiplier);
+    if (multiplier == 0.) return 0;
+    double dB = multiplier_to_dB(multiplier);
     int fader = dB_to_fader(dB, maxLevel, type);
     return fader;
 }
@@ -227,7 +227,7 @@
     LevelList &ll = previewLevelCache[levels];
     if (ll.empty()) {
 	for (int i = 0; i <= levels; ++i) {
-	    float m = AudioLevel::fader_to_multiplier
+	    double m = AudioLevel::fader_to_multiplier
 		(i + levels/4, levels + levels/4, AudioLevel::PreviewLevel);
 	    if (levels == 1) m /= 100; // noise
 	    ll.push_back(m);
@@ -238,14 +238,14 @@
 */
 
 int
-AudioLevel::multiplier_to_preview(float m, int levels)
+AudioLevel::multiplier_to_preview(double m, int levels)
 {
     assert(levels > 0);
     return multiplier_to_fader(m, levels, PreviewLevel);
 
     /* The original multiplier_to_preview which follows is not thread-safe.
 
-    if (m < 0.f) return -multiplier_to_preview(-m, levels);
+    if (m < 0.) return -multiplier_to_preview(-m, levels);
 
     const LevelList &ll = getPreviewLevelCache(levels);
     int result = -1;
@@ -277,7 +277,7 @@
     */
 }
 
-float
+double
 AudioLevel::preview_to_multiplier(int level, int levels)
 {
     assert(levels > 0);
--- a/base/AudioLevel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/AudioLevel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -35,7 +35,7 @@
 {
 public:
 
-    static const float DB_FLOOR;
+    static const double DB_FLOOR;
 
     enum FaderType {
 	     ShortFader = 0, // -40 -> +6  dB
@@ -45,19 +45,19 @@
 	   PreviewLevel = 4
     };
 
-    static float multiplier_to_dB(float multiplier);
-    static float dB_to_multiplier(float dB);
+    static double multiplier_to_dB(double multiplier);
+    static double dB_to_multiplier(double dB);
 
-    static float fader_to_dB(int level, int maxLevel, FaderType type);
-    static int   dB_to_fader(float dB, int maxFaderLevel, FaderType type);
+    static double fader_to_dB(int level, int maxLevel, FaderType type);
+    static int    dB_to_fader(double dB, int maxFaderLevel, FaderType type);
 
-    static float fader_to_multiplier(int level, int maxLevel, FaderType type);
-    static int   multiplier_to_fader(float multiplier, int maxFaderLevel,
+    static double fader_to_multiplier(int level, int maxLevel, FaderType type);
+    static int    multiplier_to_fader(double multiplier, int maxFaderLevel,
 				     FaderType type);
 
     // fast if "levels" doesn't change often -- for audio segment previews
-    static int   multiplier_to_preview(float multiplier, int levels);
-    static float preview_to_multiplier(int level, int levels);
+    static int    multiplier_to_preview(double multiplier, int levels);
+    static double preview_to_multiplier(int level, int levels);
 };
 
 
--- a/base/AudioPlaySource.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/AudioPlaySource.h	Mon Mar 23 11:26:28 2015 +0000
@@ -16,6 +16,8 @@
 #ifndef _AUDIO_PLAY_SOURCE_H_
 #define _AUDIO_PLAY_SOURCE_H_
 
+#include "BaseTypes.h"
+
 struct Auditionable {
     virtual ~Auditionable() { }
 };
@@ -37,7 +39,7 @@
      * Start playing from the given frame.  If playback is already
      * under way, reseek to the given frame and continue.
      */
-    virtual void play(int startFrame) = 0;
+    virtual void play(sv_frame_t startFrame) = 0;
 
     /**
      * Stop playback.
@@ -53,7 +55,7 @@
      * Return the frame number that is currently expected to be coming
      * out of the speakers.  (i.e. compensating for playback latency.)
      */
-    virtual int getCurrentPlayingFrame() = 0;
+    virtual sv_frame_t getCurrentPlayingFrame() = 0;
 
     /**
      * Return the current (or thereabouts) output levels in the range
@@ -65,14 +67,14 @@
      * Return the sample rate of the source material -- any material
      * that wants to play at a different rate will sound wrong.
      */
-    virtual int getSourceSampleRate() const = 0;
+    virtual sv_samplerate_t getSourceSampleRate() const = 0;
 
     /**
      * Return the sample rate set by the target audio device (or the
      * source sample rate if the target hasn't set one).  If the
      * source and target sample rates differ, resampling will occur.
      */
-    virtual int getTargetSampleRate() const = 0;
+    virtual sv_samplerate_t getTargetSampleRate() const = 0;
 
     /**
      * Get the block size of the target audio device.  This may be an
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/BaseTypes.h	Mon Mar 23 11:26:28 2015 +0000
@@ -0,0 +1,50 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    
+    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.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef BASE_TYPES_H
+#define BASE_TYPES_H
+
+#include <cstdint>
+
+/** Frame index, the unit of our time axis. This is signed because the
+    axis conceptually extends below zero: zero represents the start of
+    the main loaded audio model, not the start of time; a windowed
+    transform could legitimately produce results before then. We also
+    use this for frame counts, simply to avoid error-prone arithmetic
+    between signed and unsigned types.
+*/
+typedef int64_t sv_frame_t;
+
+/** Check whether an integer index is in range for a container,
+    avoiding overflows and signed/unsigned comparison warnings.
+*/
+template<typename T, typename C>
+bool in_range_for(const C &container, T i)
+{
+    if (i < 0) return false;
+    if (sizeof(T) > sizeof(typename C::size_type)) {
+	return i < static_cast<T>(container.size());
+    } else {
+	return static_cast<typename C::size_type>(i) < container.size();
+    }
+}
+
+/** Sample rate. We have to deal with sample rates provided as float
+    or (unsigned) int types, so we might as well have a type that can
+    represent both. Storage size isn't an issue anyway.
+*/
+typedef double sv_samplerate_t;
+
+#endif
+
--- a/base/Clipboard.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Clipboard.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -15,7 +15,7 @@
 
 #include "Clipboard.h"
 
-Clipboard::Point::Point(long frame, QString label) :
+Clipboard::Point::Point(sv_frame_t frame, QString label) :
     m_haveFrame(true),
     m_frame(frame),
     m_haveValue(false),
@@ -31,7 +31,7 @@
 {
 }
 
-Clipboard::Point::Point(long frame, float value, QString label) :
+Clipboard::Point::Point(sv_frame_t frame, float value, QString label) :
     m_haveFrame(true),
     m_frame(frame),
     m_haveValue(true),
@@ -47,7 +47,7 @@
 {
 }
 
-Clipboard::Point::Point(long frame, float value, int duration, QString label) :
+Clipboard::Point::Point(sv_frame_t frame, float value, sv_frame_t duration, QString label) :
     m_haveFrame(true),
     m_frame(frame),
     m_haveValue(true),
@@ -63,7 +63,7 @@
 {
 }
 
-Clipboard::Point::Point(long frame, float value, int duration, float level, QString label) :
+Clipboard::Point::Point(sv_frame_t frame, float value, sv_frame_t duration, float level, QString label) :
     m_haveFrame(true),
     m_frame(frame),
     m_haveValue(true),
@@ -120,14 +120,14 @@
     return m_haveFrame;
 }
 
-long
+sv_frame_t
 Clipboard::Point::getFrame() const
 {
     return m_frame;
 }
 
 Clipboard::Point
-Clipboard::Point::withFrame(long frame) const
+Clipboard::Point::withFrame(sv_frame_t frame) const
 {
     Point p(*this);
     p.m_haveFrame = true;
@@ -162,14 +162,14 @@
     return m_haveDuration;
 }
 
-int
+sv_frame_t
 Clipboard::Point::getDuration() const
 {
     return m_duration;
 }
 
 Clipboard::Point
-Clipboard::Point::withDuration(int duration) const
+Clipboard::Point::withDuration(sv_frame_t duration) const
 {
     Point p(*this);
     p.m_haveDuration = true;
@@ -231,14 +231,14 @@
     return m_haveReferenceFrame && (m_referenceFrame != m_frame);
 }
 
-long
+sv_frame_t
 Clipboard::Point::getReferenceFrame() const
 {
     return m_referenceFrame;
 }
 
 void
-Clipboard::Point::setReferenceFrame(long f) 
+Clipboard::Point::setReferenceFrame(sv_frame_t f) 
 {
     m_haveReferenceFrame = true;
     m_referenceFrame = f;
--- a/base/Clipboard.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Clipboard.h	Mon Mar 23 11:26:28 2015 +0000
@@ -19,30 +19,32 @@
 #include <QString>
 #include <vector>
 
+#include "BaseTypes.h"
+
 class Clipboard
 {
 public:
     class Point
     {
     public:
-        Point(long frame, QString label);
-        Point(long frame, float value, QString label);
-        Point(long frame, float value, int duration, QString label);
-        Point(long frame, float value, int duration, float level, QString label);
+        Point(sv_frame_t frame, QString label);
+        Point(sv_frame_t frame, float value, QString label);
+        Point(sv_frame_t frame, float value, sv_frame_t duration, QString label);
+        Point(sv_frame_t frame, float value, sv_frame_t duration, float level, QString label);
         Point(const Point &point);
         Point &operator=(const Point &point);
 
         bool haveFrame() const;
-        long getFrame() const;
-        Point withFrame(long frame) const;
+        sv_frame_t getFrame() const;
+        Point withFrame(sv_frame_t frame) const;
 
         bool haveValue() const;
         float getValue() const;
         Point withValue(float value) const;
         
         bool haveDuration() const;
-        int getDuration() const;
-        Point withDuration(int duration) const;
+        sv_frame_t getDuration() const;
+        Point withDuration(sv_frame_t duration) const;
         
         bool haveLabel() const;
         QString getLabel() const;
@@ -55,22 +57,22 @@
         bool haveReferenceFrame() const;
         bool referenceFrameDiffers() const; // from point frame
 
-        long getReferenceFrame() const;
-        void setReferenceFrame(long);
+        sv_frame_t getReferenceFrame() const;
+        void setReferenceFrame(sv_frame_t);
 
     private:
         bool m_haveFrame;
-        long m_frame;
+        sv_frame_t m_frame;
         bool m_haveValue;
         float m_value;
         bool m_haveDuration;
-        int m_duration;
+        sv_frame_t m_duration;
         bool m_haveLabel;
         QString m_label;
         bool m_haveLevel;
         float m_level;
         bool m_haveReferenceFrame;
-        long m_referenceFrame;
+        sv_frame_t m_referenceFrame;
     };
 
     Clipboard();
--- a/base/Command.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Command.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -95,6 +95,6 @@
 BundleCommand::getName() const
 {
     if (m_commands.size() == 1) return m_name;
-    return tr("%1 (%n change(s))", "", m_commands.size()).arg(m_name);
+    return tr("%1 (%n change(s))", "", int(m_commands.size())).arg(m_name);
 }
 
--- a/base/Debug.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Debug.h	Mon Mar 23 11:26:28 2015 +0000
@@ -19,7 +19,7 @@
 #include <QDebug>
 #include <QTextStream>
 
-#include <vamp-hostsdk/RealTime.h>
+#include "RealTime.h"
 
 #include <string>
 #include <iostream>
@@ -41,6 +41,11 @@
 
 #define SVDEBUG getSVDebug()
 
+inline QDebug &operator<<(QDebug &d, const RealTime &rt) {
+    d << rt.toString();
+    return d;
+}
+
 inline QDebug &operator<<(QDebug &d, const Vamp::RealTime &rt) {
     d << rt.toString();
     return d;
--- a/base/Exceptions.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Exceptions.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -91,8 +91,8 @@
 }
 
 InsufficientDiscSpace::InsufficientDiscSpace(QString directory,
-                                             int required,
-                                             int available) throw() :
+                                             size_t required,
+                                             size_t available) throw() :
     m_directory(directory),
     m_required(required),
     m_available(available)
--- a/base/Exceptions.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Exceptions.h	Mon Mar 23 11:26:28 2015 +0000
@@ -82,19 +82,19 @@
 {
 public:
     InsufficientDiscSpace(QString directory,
-                          int required, int available) throw();
+                          size_t required, size_t available) throw();
     InsufficientDiscSpace(QString directory) throw();
     virtual ~InsufficientDiscSpace() throw() { }
     virtual const char *what() const throw();
 
     QString getDirectory() const { return m_directory; }
-    int getRequired() const { return m_required; }
-    int getAvailable() const { return m_available; }
+    size_t getRequired() const { return m_required; }
+    size_t getAvailable() const { return m_available; }
 
 protected:
     QString m_directory;
-    int m_required;
-    int m_available;
+    size_t m_required;
+    size_t m_available;
 };
 
 class AllocationFailed : virtual public std::exception
--- a/base/FrameTimer.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/FrameTimer.h	Mon Mar 23 11:26:28 2015 +0000
@@ -16,6 +16,8 @@
 #ifndef _FRAME_TIMER_H_
 #define _FRAME_TIMER_H_
 
+#include "BaseTypes.h"
+
 /**
  * A trivial interface for things that permit retrieving "the current
  * frame".  Implementations of this interface are used, for example,
@@ -25,7 +27,7 @@
 class FrameTimer
 {
 public:
-    virtual int getFrame() const = 0;
+    virtual sv_frame_t getFrame() const = 0;
 };
 
 #endif
--- a/base/LogRange.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/LogRange.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -21,7 +21,7 @@
 #include <cmath>
 
 void
-LogRange::mapRange(float &min, float &max, float logthresh)
+LogRange::mapRange(double &min, double &max, double logthresh)
 {
     if (min > max) std::swap(min, max);
     if (max == min) max = min + 1;
@@ -30,19 +30,19 @@
 
     if (min >= 0.f) {
 
-        max = log10f(max); // we know max != 0
+        max = log10(max); // we know max != 0
 
         if (min == 0.f) min = std::min(logthresh, max);
-        else min = log10f(min);
+        else min = log10(min);
 
 //        SVDEBUG << "LogRange::mapRange: positive: min = " << min << ", max = " << max << endl;
 
     } else if (max <= 0.f) {
         
-        min = log10f(-min); // we know min != 0
+        min = log10(-min); // we know min != 0
         
         if (max == 0.f) max = std::min(logthresh, min);
-        else max = log10f(-max);
+        else max = log10(-max);
         
         std::swap(min, max);
         
@@ -52,7 +52,7 @@
         
         // min < 0 and max > 0
         
-        max = log10f(std::max(max, -min));
+        max = log10(std::max(max, -min));
         min = std::min(logthresh, max);
 
 //        SVDEBUG << "LogRange::mapRange: spanning: min = " << min << ", max = " << max << endl;
@@ -61,48 +61,49 @@
     if (min == max) min = max - 1;
 }        
 
-float
-LogRange::map(float value, float thresh)
+double
+LogRange::map(double value, double thresh)
 {
     if (value == 0.f) return thresh;
-    return log10f(fabsf(value));
+    return log10(fabs(value));
 }
 
-float
-LogRange::unmap(float value)
+double
+LogRange::unmap(double value)
 {
-    return powf(10.0, value);
+    return pow(10.0, value);
 }
 
-static float
-sd(const std::vector<float> &values, size_t start, size_t n)
+static double
+sd(const std::vector<double> &values, int start, int n)
 {
-    float sum = 0.f, mean = 0.f, variance = 0.f;
-    for (size_t i = 0; i < n; ++i) {
+    double sum = 0.f, mean = 0.f, variance = 0.f;
+    for (int i = 0; i < n; ++i) {
         sum += values[start + i];
     }
     mean = sum / n;
-    for (size_t i = 0; i < n; ++i) {
-        float diff = values[start + i] - mean;
+    for (int i = 0; i < n; ++i) {
+        double diff = values[start + i] - mean;
         variance += diff * diff;
     }
     variance = variance / n;
-    return sqrtf(variance);
+    return sqrt(variance);
 }
 
 bool
-LogRange::useLogScale(std::vector<float> values)
+LogRange::useLogScale(std::vector<double> values)
 {
     // Principle: Partition the data into two sets around the median;
     // calculate the standard deviation of each set; if the two SDs
     // are very different, it's likely that a log scale would be good.
 
-    if (values.size() < 4) return false;
+    int n = int(values.size());
+    if (n < 4) return false;
     std::sort(values.begin(), values.end());
-    size_t mi = values.size() / 2;
+    int mi = n / 2;
 
-    float sd0 = sd(values, 0, mi);
-    float sd1 = sd(values, mi, values.size() - mi);
+    double sd0 = sd(values, 0, mi);
+    double sd1 = sd(values, mi, n - mi);
 
     SVDEBUG << "LogRange::useLogScale: sd0 = "
               << sd0 << ", sd1 = " << sd1 << endl;
@@ -111,7 +112,7 @@
 
     // I wonder what method of determining "one sd much bigger than
     // the other" would be appropriate here...
-    if (std::max(sd0, sd1) / std::min(sd0, sd1) > 10.f) return true;
+    if (std::max(sd0, sd1) / std::min(sd0, sd1) > 10.) return true;
     else return false;
 }
     
--- a/base/LogRange.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/LogRange.h	Mon Mar 23 11:26:28 2015 +0000
@@ -28,27 +28,27 @@
      * extents of the logarithmic range.  thresh is the minimum value
      * for the log range, to be used if the linear range spans zero.
      */
-    static void mapRange(float &min, float &max, float thresh = -10);
+    static void mapRange(double &min, double &max, double thresh = -10);
 
     /**
      * Map a value onto a logarithmic range.  This just means taking
      * the base-10 log of the absolute value, or using the threshold
      * value if the absolute value is zero.
      */
-    static float map(float value, float thresh = -10);
+    static double map(double value, double thresh = -10);
 
     /**
      * Map a value from the logarithmic range back again.  This just
      * means taking the value'th power of ten.
      */
-    static float unmap(float value);
+    static double unmap(double value);
 
     /**
      * Estimate whether a set of values would be more properly shown
      * using a logarithmic than a linear scale.  This is only ever
      * going to be a rough guess.
      */
-    static bool useLogScale(std::vector<float> values);
+    static bool useLogScale(std::vector<double> values);
 
 };
 
--- a/base/Pitch.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Pitch.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -141,7 +141,7 @@
 
     QString plain = (useFlats ? flatNotes : notes)[note].arg(octave);
 
-    int ic = lrint(centsOffset);
+    long ic = lrint(centsOffset);
     if (ic == 0) return plain;
     else if (ic > 0) return QString("%1+%2c").arg(plain).arg(ic);
     else return QString("%1%2c").arg(plain).arg(ic);
@@ -176,7 +176,7 @@
         }
     }
 
-    int ic = lrint(cents);
+    long ic = lrint(cents);
 
     if (ic == 0) {
         if (semis >= 12) {
--- a/base/Preferences.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Preferences.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -59,13 +59,13 @@
         (settings.value("spectrogram-y-smoothing", int(m_spectrogramSmoothing)).toInt());
     m_spectrogramXSmoothing = SpectrogramXSmoothing
         (settings.value("spectrogram-x-smoothing", int(m_spectrogramXSmoothing)).toInt());
-    m_tuningFrequency = settings.value("tuning-frequency", 440.f).toDouble();
+    m_tuningFrequency = settings.value("tuning-frequency", 440.).toDouble();
     m_propertyBoxLayout = PropertyBoxLayout
         (settings.value("property-box-layout", int(VerticallyStacked)).toInt());
     m_windowType = WindowType
         (settings.value("window-type", int(HanningWindow)).toInt());
     m_resampleQuality = settings.value("resample-quality", 1).toInt();
-    m_fixedSampleRate = settings.value("fixed-sample-rate", 0).toInt();
+    m_fixedSampleRate = settings.value("fixed-sample-rate", 0).toDouble();
     m_resampleOnLoad = settings.value("resample-on-load", false).toBool();
     m_normaliseAudio = settings.value("normalise-audio", false).toBool();
     m_backgroundMode = BackgroundMode
@@ -467,7 +467,7 @@
 }
 
 void
-Preferences::setTuningFrequency(float freq)
+Preferences::setTuningFrequency(double freq)
 {
     if (m_tuningFrequency != freq) {
         m_tuningFrequency = freq;
@@ -561,7 +561,7 @@
 }
 
 void
-Preferences::setFixedSampleRate(int rate)
+Preferences::setFixedSampleRate(sv_samplerate_t rate)
 {
     if (m_fixedSampleRate != rate) {
         m_fixedSampleRate = rate;
--- a/base/Preferences.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Preferences.h	Mon Mar 23 11:26:28 2015 +0000
@@ -49,7 +49,7 @@
 
     SpectrogramSmoothing getSpectrogramSmoothing() const { return m_spectrogramSmoothing; }
     SpectrogramXSmoothing getSpectrogramXSmoothing() const { return m_spectrogramXSmoothing; }
-    float getTuningFrequency() const { return m_tuningFrequency; }
+    double getTuningFrequency() const { return m_tuningFrequency; }
     WindowType getWindowType() const { return m_windowType; }
     int getResampleQuality() const { return m_resampleQuality; }
 
@@ -67,7 +67,7 @@
     QString getTemporaryDirectoryRoot() const { return m_tempDirRoot; }
 
     /// If we should always resample audio to the same rate, return it; otherwise (the normal case) return 0
-    int getFixedSampleRate() const { return m_fixedSampleRate; }
+    sv_samplerate_t getFixedSampleRate() const { return m_fixedSampleRate; }
 
     /// True if we should resample second or subsequent audio file to match first audio file's rate
     bool getResampleOnLoad() const { return m_resampleOnLoad; }    
@@ -110,13 +110,13 @@
 
     void setSpectrogramSmoothing(SpectrogramSmoothing smoothing);
     void setSpectrogramXSmoothing(SpectrogramXSmoothing smoothing);
-    void setTuningFrequency(float freq);
+    void setTuningFrequency(double freq);
     void setPropertyBoxLayout(PropertyBoxLayout layout);
     void setWindowType(WindowType type);
     void setResampleQuality(int quality);
     void setOmitTempsFromRecentFiles(bool omit);
     void setTemporaryDirectoryRoot(QString tempDirRoot);
-    void setFixedSampleRate(int);
+    void setFixedSampleRate(sv_samplerate_t);
     void setResampleOnLoad(bool);
     void setNormaliseAudio(bool);
     void setBackgroundMode(BackgroundMode mode);
@@ -147,13 +147,13 @@
 
     SpectrogramSmoothing m_spectrogramSmoothing;
     SpectrogramXSmoothing m_spectrogramXSmoothing;
-    float m_tuningFrequency;
+    double m_tuningFrequency;
     PropertyBoxLayout m_propertyBoxLayout;
     WindowType m_windowType;
     int m_resampleQuality;
     bool m_omitRecentTemps;
     QString m_tempDirRoot;
-    int m_fixedSampleRate;
+    sv_samplerate_t m_fixedSampleRate;
     bool m_resampleOnLoad;
     bool m_normaliseAudio;
     int m_viewFontSize;
--- a/base/Profiler.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Profiler.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -105,7 +105,7 @@
         fprintf(stderr, "\tCPU:  \t%.9g ms/call \t[%d ms total]\n",
                 (((double)pp.second.first * 1000.0 /
 		  (double)pp.first) / CLOCKS_PER_SEC),
-                int((pp.second.first * 1000.0) / CLOCKS_PER_SEC));
+                int((double(pp.second.first) * 1000.0) / CLOCKS_PER_SEC));
 
         fprintf(stderr, "\tReal: \t%s ms      \t[%s ms total]\n",
                 ((pp.second.second / pp.first) * 1000).toString().c_str(),
@@ -118,7 +118,7 @@
 
         fprintf(stderr, "\tWorst:\t%s ms/call \t[%d ms CPU]\n",
                 (wc.second * 1000).toString().c_str(),
-                int((wc.first * 1000.0) / CLOCKS_PER_SEC));
+                int((double(wc.first) * 1000.0) / CLOCKS_PER_SEC));
     }
 
     typedef std::multimap<RealTime, const char *> TimeRMap;
--- a/base/RangeMapper.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/RangeMapper.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -22,7 +22,7 @@
 #include <iostream>
 
 LinearRangeMapper::LinearRangeMapper(int minpos, int maxpos,
-				     float minval, float maxval,
+				     double minval, double maxval,
                                      QString unit, bool inverted) :
     m_minpos(minpos),
     m_maxpos(maxpos),
@@ -36,7 +36,7 @@
 }
 
 int
-LinearRangeMapper::getPositionForValue(float value) const
+LinearRangeMapper::getPositionForValue(double value) const
 {
     int position = getPositionForValueUnclamped(value);
     if (position < m_minpos) position = m_minpos;
@@ -45,36 +45,36 @@
 }
 
 int
-LinearRangeMapper::getPositionForValueUnclamped(float value) const
+LinearRangeMapper::getPositionForValueUnclamped(double value) const
 {
     int position = m_minpos +
-        lrintf(((value - m_minval) / (m_maxval - m_minval))
-               * (m_maxpos - m_minpos));
+        int(lrint(((value - m_minval) / (m_maxval - m_minval))
+                  * (m_maxpos - m_minpos)));
     if (m_inverted) return m_maxpos - (position - m_minpos);
     else return position;
 }
 
-float
+double
 LinearRangeMapper::getValueForPosition(int position) const
 {
     if (position < m_minpos) position = m_minpos;
     if (position > m_maxpos) position = m_maxpos;
-    float value = getValueForPositionUnclamped(position);
+    double value = getValueForPositionUnclamped(position);
     return value;
 }
 
-float
+double
 LinearRangeMapper::getValueForPositionUnclamped(int position) const
 {
     if (m_inverted) position = m_maxpos - (position - m_minpos);
-    float value = m_minval +
-        ((float(position - m_minpos) / float(m_maxpos - m_minpos))
+    double value = m_minval +
+        ((double(position - m_minpos) / double(m_maxpos - m_minpos))
          * (m_maxval - m_minval));
     return value;
 }
 
 LogRangeMapper::LogRangeMapper(int minpos, int maxpos,
-                               float minval, float maxval,
+                               double minval, double maxval,
                                QString unit, bool inverted) :
     m_minpos(minpos),
     m_maxpos(maxpos),
@@ -97,26 +97,26 @@
 
 void
 LogRangeMapper::convertMinMax(int minpos, int maxpos,
-                              float minval, float maxval,
-                              float &minlog, float &ratio)
+                              double minval, double maxval,
+                              double &minlog, double &ratio)
 {
-    static float thresh = powf(10, -10);
+    static double thresh = powf(10, -10);
     if (minval < thresh) minval = thresh;
-    minlog = log10f(minval);
-    ratio = (maxpos - minpos) / (log10f(maxval) - minlog);
+    minlog = log10(minval);
+    ratio = (maxpos - minpos) / (log10(maxval) - minlog);
 }
 
 void
-LogRangeMapper::convertRatioMinLog(float ratio, float minlog,
+LogRangeMapper::convertRatioMinLog(double ratio, double minlog,
                                    int minpos, int maxpos,
-                                   float &minval, float &maxval)
+                                   double &minval, double &maxval)
 {
-    minval = powf(10, minlog);
-    maxval = powf(10, (maxpos - minpos) / ratio + minlog);
+    minval = pow(10, minlog);
+    maxval = pow(10, (maxpos - minpos) / ratio + minlog);
 }
 
 int
-LogRangeMapper::getPositionForValue(float value) const
+LogRangeMapper::getPositionForValue(double value) const
 {
     int position = getPositionForValueUnclamped(value);
     if (position < m_minpos) position = m_minpos;
@@ -125,29 +125,29 @@
 }
 
 int
-LogRangeMapper::getPositionForValueUnclamped(float value) const
+LogRangeMapper::getPositionForValueUnclamped(double value) const
 {
-    static float thresh = powf(10, -10);
+    static double thresh = pow(10, -10);
     if (value < thresh) value = thresh;
-    int position = lrintf((log10(value) - m_minlog) * m_ratio) + m_minpos;
+    int position = int(lrint((log10(value) - m_minlog) * m_ratio)) + m_minpos;
     if (m_inverted) return m_maxpos - (position - m_minpos);
     else return position;
 }
 
-float
+double
 LogRangeMapper::getValueForPosition(int position) const
 {
     if (position < m_minpos) position = m_minpos;
     if (position > m_maxpos) position = m_maxpos;
-    float value = getValueForPositionUnclamped(position);
+    double value = getValueForPositionUnclamped(position);
     return value;
 }
 
-float
+double
 LogRangeMapper::getValueForPositionUnclamped(int position) const
 {
     if (m_inverted) position = m_maxpos - (position - m_minpos);
-    float value = powf(10, (position - m_minpos) / m_ratio + m_minlog);
+    double value = pow(10, (position - m_minpos) / m_ratio + m_minlog);
     return value;
 }
 
@@ -163,7 +163,7 @@
 }
 
 int
-InterpolatingRangeMapper::getPositionForValue(float value) const
+InterpolatingRangeMapper::getPositionForValue(double value) const
 {
     int pos = getPositionForValueUnclamped(value);
     CoordMap::const_iterator i = m_mappings.begin();
@@ -174,16 +174,16 @@
 }
 
 int
-InterpolatingRangeMapper::getPositionForValueUnclamped(float value) const
+InterpolatingRangeMapper::getPositionForValueUnclamped(double value) const
 {
-    float p = interpolate(&m_mappings, value);
-    return lrintf(p);
+    double p = interpolate(&m_mappings, value);
+    return int(lrint(p));
 }
 
-float
+double
 InterpolatingRangeMapper::getValueForPosition(int position) const
 {
-    float val = getValueForPositionUnclamped(position);
+    double val = getValueForPositionUnclamped(position);
     CoordMap::const_iterator i = m_mappings.begin();
     if (val < i->first) val = i->first;
     i = m_mappings.end(); --i;
@@ -191,18 +191,19 @@
     return val;
 }
 
-float
+double
 InterpolatingRangeMapper::getValueForPositionUnclamped(int position) const
 {
     return interpolate(&m_reverse, position);
 }
 
 template <typename T>
-float
-InterpolatingRangeMapper::interpolate(T *mapping, float value) const
+double
+InterpolatingRangeMapper::interpolate(T *mapping, double value) const
 {
     // lower_bound: first element which does not compare less than value
-    typename T::const_iterator i = mapping->lower_bound(value);
+    typename T::const_iterator i =
+        mapping->lower_bound(typename T::key_type(value));
 
     if (i == mapping->begin()) {
         // value is less than or equal to first element, so use the
@@ -219,7 +220,7 @@
     typename T::const_iterator j = i;
     --j;
 
-    float gradient = float(i->second - j->second) / float(i->first - j->first);
+    double gradient = double(i->second - j->second) / double(i->first - j->first);
 
     return j->second + (value - j->first) * gradient;
 }
@@ -316,24 +317,24 @@
 }
 
 int
-AutoRangeMapper::getPositionForValue(float value) const
+AutoRangeMapper::getPositionForValue(double value) const
 {
     return m_mapper->getPositionForValue(value);
 }
 
-float
+double
 AutoRangeMapper::getValueForPosition(int position) const
 {
     return m_mapper->getValueForPosition(position);
 }
 
 int
-AutoRangeMapper::getPositionForValueUnclamped(float value) const
+AutoRangeMapper::getPositionForValueUnclamped(double value) const
 {
     return m_mapper->getPositionForValueUnclamped(value);
 }
 
-float
+double
 AutoRangeMapper::getValueForPositionUnclamped(int position) const
 {
     return m_mapper->getValueForPositionUnclamped(position);
--- a/base/RangeMapper.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/RangeMapper.h	Mon Mar 23 11:26:28 2015 +0000
@@ -31,7 +31,7 @@
      * the nearest position and clamping to the minimum and maximum
      * extents of the mapper's positional range.
      */
-    virtual int getPositionForValue(float value) const = 0;
+    virtual int getPositionForValue(double value) const = 0;
 
     /**
      * Return the position that maps to the given value, rounding to
@@ -41,13 +41,13 @@
      * range. (The mapping outside that range is not guaranteed to be
      * exact, except if the mapper is a linear one.)
      */
-    virtual int getPositionForValueUnclamped(float value) const = 0;
+    virtual int getPositionForValueUnclamped(double value) const = 0;
 
     /**
      * Return the value mapped from the given position, clamping to
      * the minimum and maximum extents of the mapper's value range.
      */
-    virtual float getValueForPosition(int position) const = 0;
+    virtual double getValueForPosition(int position) const = 0;
 
     /**
      * Return the value mapped from the given positionq, without
@@ -56,7 +56,7 @@
      * mapper's value range. (The mapping outside that range is not
      * guaranteed to be exact, except if the mapper is a linear one.)
      */
-    virtual float getValueForPositionUnclamped(int position) const = 0;
+    virtual double getValueForPositionUnclamped(int position) const = 0;
 
     /**
      * Get the unit of the mapper's value range.
@@ -75,22 +75,22 @@
      * mapped "backwards" (minval to maxpos and maxval to minpos).
      */
     LinearRangeMapper(int minpos, int maxpos,
-                      float minval, float maxval,
+                      double minval, double maxval,
                       QString unit = "", bool inverted = false);
     
-    virtual int getPositionForValue(float value) const;
-    virtual int getPositionForValueUnclamped(float value) const;
+    virtual int getPositionForValue(double value) const;
+    virtual int getPositionForValueUnclamped(double value) const;
 
-    virtual float getValueForPosition(int position) const;
-    virtual float getValueForPositionUnclamped(int position) const;
+    virtual double getValueForPosition(int position) const;
+    virtual double getValueForPositionUnclamped(int position) const;
 
     virtual QString getUnit() const { return m_unit; }
 
 protected:
     int m_minpos;
     int m_maxpos;
-    float m_minval;
-    float m_maxval;
+    double m_minval;
+    double m_maxval;
     QString m_unit;
     bool m_inverted;
 };
@@ -107,31 +107,31 @@
      * to maxpos and maxval to minpos).
      */
     LogRangeMapper(int minpos, int maxpos,
-                   float minval, float maxval,
+                   double minval, double maxval,
                    QString m_unit = "", bool inverted = false);
 
-    static void convertRatioMinLog(float ratio, float minlog,
+    static void convertRatioMinLog(double ratio, double minlog,
                                    int minpos, int maxpos,
-                                   float &minval, float &maxval);
+                                   double &minval, double &maxval);
 
     static void convertMinMax(int minpos, int maxpos,
-                              float minval, float maxval,
-                              float &ratio, float &minlog);
+                              double minval, double maxval,
+                              double &ratio, double &minlog);
 
-    virtual int getPositionForValue(float value) const;
-    virtual int getPositionForValueUnclamped(float value) const;
+    virtual int getPositionForValue(double value) const;
+    virtual int getPositionForValueUnclamped(double value) const;
 
-    virtual float getValueForPosition(int position) const;
-    virtual float getValueForPositionUnclamped(int position) const;
+    virtual double getValueForPosition(int position) const;
+    virtual double getValueForPositionUnclamped(int position) const;
 
     virtual QString getUnit() const { return m_unit; }
 
 protected:
     int m_minpos;
     int m_maxpos;
-    float m_ratio;
-    float m_minlog;
-    float m_maxlog;
+    double m_ratio;
+    double m_minlog;
+    double m_maxlog;
     QString m_unit;
     bool m_inverted;
 };
@@ -139,7 +139,7 @@
 class InterpolatingRangeMapper : public RangeMapper
 {
 public:
-    typedef std::map<float, int> CoordMap;
+    typedef std::map<double, int> CoordMap;
 
     /**
      * Given a series of (value, position) coordinate mappings,
@@ -162,21 +162,21 @@
     InterpolatingRangeMapper(CoordMap pointMappings,
                              QString unit);
 
-    virtual int getPositionForValue(float value) const;
-    virtual int getPositionForValueUnclamped(float value) const;
+    virtual int getPositionForValue(double value) const;
+    virtual int getPositionForValueUnclamped(double value) const;
 
-    virtual float getValueForPosition(int position) const;
-    virtual float getValueForPositionUnclamped(int position) const;
+    virtual double getValueForPosition(int position) const;
+    virtual double getValueForPositionUnclamped(int position) const;
 
     virtual QString getUnit() const { return m_unit; }
 
 protected:
     CoordMap m_mappings;
-    std::map<int, float> m_reverse;
+    std::map<int, double> m_reverse;
     QString m_unit;
 
     template <typename T>
-    float interpolate(T *mapping, float v) const;
+    double interpolate(T *mapping, double v) const;
 };
 
 class AutoRangeMapper : public RangeMapper
@@ -188,7 +188,7 @@
         Logarithmic,
     };
 
-    typedef std::map<float, int> CoordMap;
+    typedef std::map<double, int> CoordMap;
 
     /**
      * Given a series of (value, position) coordinate mappings,
@@ -235,11 +235,11 @@
      */
     MappingType getType() const { return m_type; }
 
-    virtual int getPositionForValue(float value) const;
-    virtual int getPositionForValueUnclamped(float value) const;
+    virtual int getPositionForValue(double value) const;
+    virtual int getPositionForValueUnclamped(double value) const;
 
-    virtual float getValueForPosition(int position) const;
-    virtual float getValueForPositionUnclamped(int position) const;
+    virtual double getValueForPosition(int position) const;
+    virtual double getValueForPositionUnclamped(int position) const;
 
     virtual QString getUnit() const { return m_unit; }
 
--- a/base/RealTime.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/RealTime.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -75,7 +75,7 @@
 RealTime
 RealTime::fromTimeval(const struct timeval &tv)
 {
-    return RealTime(tv.tv_sec, tv.tv_usec * 1000);
+    return RealTime(int(tv.tv_sec), int(tv.tv_usec * 1000));
 }
 
 RealTime
@@ -89,7 +89,7 @@
     int i = 0;
 
     const char *s = xsdd.c_str();
-    int len = xsdd.length();
+    int len = int(xsdd.length());
 
     bool negative = false, afterT = false;
 
@@ -106,7 +106,7 @@
 
         if (isdigit(s[i]) || s[i] == '.') {
             value = strtod(&s[i], &eptr);
-            i = eptr - s;
+            i = int(eptr - s);
         }
 
         if (i == len) break;
@@ -456,24 +456,36 @@
     else return lTotal/rTotal;
 }
 
-long
-RealTime::realTime2Frame(const RealTime &time, unsigned int sampleRate)
+static RealTime
+frame2RealTime_i(sv_frame_t frame, sv_frame_t iSampleRate)
+{
+    if (frame < 0) return -frame2RealTime_i(-frame, iSampleRate);
+
+    RealTime rt;
+    sv_frame_t sec = frame / iSampleRate;
+    rt.sec = int(sec);
+    frame -= sec * iSampleRate;
+    rt.nsec = (int)(((double(frame) * 1000000.0) / double(iSampleRate)) * 1000.0);
+    return rt;
+}
+
+sv_frame_t
+RealTime::realTime2Frame(const RealTime &time, sv_samplerate_t sampleRate)
 {
     if (time < zeroTime) return -realTime2Frame(-time, sampleRate);
     double s = time.sec + double(time.nsec + 1) / 1000000000.0;
-    return long(s * double(sampleRate));
+    return sv_frame_t(s * sampleRate);
 }
 
 RealTime
-RealTime::frame2RealTime(long frame, unsigned int sampleRate)
+RealTime::frame2RealTime(sv_frame_t frame, sv_samplerate_t sampleRate)
 {
-    if (frame < 0) return -frame2RealTime(-frame, sampleRate);
+    if (sampleRate == double(int(sampleRate))) {
+        return frame2RealTime_i(frame, int(sampleRate));
+    }
 
-    RealTime rt;
-    rt.sec = frame / long(sampleRate);
-    frame -= rt.sec * long(sampleRate);
-    rt.nsec = (int)(((double(frame) * 1000000.0) / long(sampleRate)) * 1000.0);
-    return rt;
+    double sec = double(frame) / sampleRate;
+    return fromSeconds(sec);
 }
 
 const RealTime RealTime::zeroTime(0,0);
--- a/base/RealTime.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/RealTime.h	Mon Mar 23 11:26:28 2015 +0000
@@ -21,12 +21,15 @@
 #ifndef _REAL_TIME_H_
 #define _REAL_TIME_H_
 
+#include "BaseTypes.h"
+
 #include <iostream>
 #include <string>
 
+#include <vamp-hostsdk/RealTime.h>
+
 struct timeval;
 
-
 /**
  * RealTime represents time values to nanosecond precision
  * with accurate arithmetic and frame-rate conversion functions.
@@ -46,12 +49,16 @@
     RealTime(const RealTime &r) :
 	sec(r.sec), nsec(r.nsec) { }
 
+    RealTime(const Vamp::RealTime &r) :
+	sec(r.sec), nsec(r.nsec) { }
+
     static RealTime fromSeconds(double sec);
     static RealTime fromMilliseconds(int msec);
     static RealTime fromTimeval(const struct timeval &);
     static RealTime fromXsdDuration(std::string xsdd);
 
     double toDouble() const;
+    Vamp::RealTime toVampRealTime() const { return Vamp::RealTime(sec, nsec); }
 
     RealTime &operator=(const RealTime &r) {
 	sec = r.sec; nsec = r.nsec; return *this;
@@ -149,12 +156,12 @@
     /**
      * Convert a RealTime into a sample frame at the given sample rate.
      */
-    static long realTime2Frame(const RealTime &r, unsigned int sampleRate);
+    static sv_frame_t realTime2Frame(const RealTime &r, sv_samplerate_t sampleRate);
 
     /**
      * Convert a sample frame at the given sample rate into a RealTime.
      */
-    static RealTime frame2RealTime(long frame, unsigned int sampleRate);
+    static RealTime frame2RealTime(sv_frame_t frame, sv_samplerate_t sampleRate);
 
     static const RealTime zeroTime;
 };
--- a/base/Resampler.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Resampler.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -31,16 +31,16 @@
 class Resampler::D
 {
 public:
-    D(Quality quality, int channels, int chunkSize);
+    D(Quality quality, int channels, sv_frame_t chunkSize);
     ~D();
 
-    int resample(float **in, float **out,
-                    int incount, float ratio,
-                    bool final);
+    sv_frame_t resample(float **in, float **out,
+                 sv_frame_t incount, double ratio,
+                 bool final);
 
-    int resampleInterleaved(float *in, float *out,
-                               int incount, float ratio,
-                               bool final);
+    sv_frame_t resampleInterleaved(float *in, float *out,
+                            sv_frame_t incount, double ratio,
+                            bool final);
 
     void reset();
 
@@ -49,11 +49,11 @@
     float *m_iin;
     float *m_iout;
     int m_channels;
-    int m_iinsize;
-    int m_ioutsize;
+    sv_frame_t m_iinsize;
+    sv_frame_t m_ioutsize;
 };
 
-Resampler::D::D(Quality quality, int channels, int chunkSize) :
+Resampler::D::D(Quality quality, int channels, sv_frame_t chunkSize) :
     m_src(0),
     m_iin(0),
     m_iout(0),
@@ -89,16 +89,16 @@
     }
 }
 
-int
+sv_frame_t
 Resampler::D::resample(float **in, float **out,
-                       int incount, float ratio,
+                       sv_frame_t incount, double ratio,
                        bool final)
 {
     if (m_channels == 1) {
         return resampleInterleaved(*in, *out, incount, ratio, final);
     }
 
-    int outcount = lrintf(ceilf(incount * ratio));
+    sv_frame_t outcount = lrint(ceil(double(incount) * ratio));
 
     if (incount * m_channels > m_iinsize) {
         m_iinsize = incount * m_channels;
@@ -108,15 +108,15 @@
         m_ioutsize = outcount * m_channels;
         m_iout = (float *)realloc(m_iout, m_ioutsize * sizeof(float));
     }
-    for (int i = 0; i < incount; ++i) {
+    for (sv_frame_t i = 0; i < incount; ++i) {
         for (int c = 0; c < m_channels; ++c) {
             m_iin[i * m_channels + c] = in[c][i];
         }
     }
     
-    int gen = resampleInterleaved(m_iin, m_iout, incount, ratio, final);
+    sv_frame_t gen = resampleInterleaved(m_iin, m_iout, incount, ratio, final);
 
-    for (int i = 0; i < gen; ++i) {
+    for (sv_frame_t i = 0; i < gen; ++i) {
         for (int c = 0; c < m_channels; ++c) {
             out[c][i] = m_iout[i * m_channels + c];
         }
@@ -125,14 +125,14 @@
     return gen;
 }
 
-int
+sv_frame_t
 Resampler::D::resampleInterleaved(float *in, float *out,
-                                  int incount, float ratio,
+                                  sv_frame_t incount, double ratio,
                                   bool final)
 {
     SRC_DATA data;
 
-    int outcount = lrintf(ceilf(incount * ratio));
+    sv_frame_t outcount = lrint(ceil(double(incount) * ratio));
 
     data.data_in = in;
     data.data_out = out;
@@ -149,7 +149,7 @@
         return 0;
     }
 
-    if (data.input_frames_used != (int)incount) {
+    if (data.input_frames_used != incount) {
         cerr << "Resampler: NOTE: input_frames_used == " << data.input_frames_used << " (while incount = " << incount << ")" << endl;
     }
 
@@ -162,7 +162,7 @@
     src_reset(m_src);
 }
 
-Resampler::Resampler(Quality quality, int channels, int chunkSize)
+Resampler::Resampler(Quality quality, int channels, sv_frame_t chunkSize)
 {
     m_d = new D(quality, channels, chunkSize);
 }
@@ -172,18 +172,18 @@
     delete m_d;
 }
 
-int 
+sv_frame_t 
 Resampler::resample(float **in, float **out,
-                    int incount, float ratio,
+                    sv_frame_t incount, double ratio,
                     bool final)
 {
     return m_d->resample(in, out, incount, ratio, final);
 }
 
-int 
+sv_frame_t 
 Resampler::resampleInterleaved(float *in, float *out,
-                    int incount, float ratio,
-                    bool final)
+                               sv_frame_t incount, double ratio,
+                               bool final)
 {
     return m_d->resampleInterleaved(in, out, incount, ratio, final);
 }
--- a/base/Resampler.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Resampler.h	Mon Mar 23 11:26:28 2015 +0000
@@ -21,6 +21,8 @@
 #ifndef _RESAMPLER_H_
 #define _RESAMPLER_H_
 
+#include "BaseTypes.h"
+
 #include <sys/types.h>
 
 class Resampler
@@ -28,16 +30,16 @@
 public:
     enum Quality { Best, FastestTolerable, Fastest };
 
-    Resampler(Quality quality, int channels, int chunkSize = 0);
+    Resampler(Quality quality, int channels, sv_frame_t chunkSize = 0);
     ~Resampler();
 
-    int resample(float **in, float **out,
-                    int incount, float ratio,
-                    bool final = false);
+    sv_frame_t resample(float **in, float **out,
+                        sv_frame_t incount, double ratio,
+                        bool final = false);
 
-    int resampleInterleaved(float *in, float *out,
-                               int incount, float ratio,
-                               bool final = false);
+    sv_frame_t resampleInterleaved(float *in, float *out,
+                                   sv_frame_t incount, double ratio,
+                                   bool final = false);
 
     void reset();
 
--- a/base/ResizeableBitset.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/ResizeableBitset.h	Mon Mar 23 11:26:28 2015 +0000
@@ -62,11 +62,11 @@
     }
     
     void set(size_t column) {
-        ((*m_bits)[column >> 3]) |=  (uint8_t(1) << (column & 0x07));
+        ((*m_bits)[column >> 3]) |= uint8_t((1u << (column & 0x07)) & 0xff);
     }
 
     void reset(size_t column) {
-        ((*m_bits)[column >> 3]) &= ~(uint8_t(1) << (column & 0x07));
+        ((*m_bits)[column >> 3]) &= uint8_t((~(1u << (column & 0x07))) & 0xff);
     }
 
     void copy(size_t source, size_t dest) {
--- a/base/Scavenger.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Scavenger.h	Mon Mar 23 11:26:28 2015 +0000
@@ -61,17 +61,17 @@
     void scavenge(bool clearNow = false);
 
 protected:
-    typedef std::pair<T *, int> ObjectTimePair;
+    typedef std::pair<T *, time_t> ObjectTimePair;
     typedef std::vector<ObjectTimePair> ObjectTimeList;
     ObjectTimeList m_objects;
-    int m_sec;
+    time_t m_sec;
 
     typedef std::list<T *> ObjectList;
     ObjectList m_excess;
-    int m_lastExcess;
+    time_t m_lastExcess;
     QMutex m_excessMutex;
     void pushExcess(T *);
-    void clearExcess(int);
+    void clearExcess(time_t);
 
     unsigned int m_claimed;
     unsigned int m_scavenged;
@@ -129,7 +129,7 @@
 
     struct timeval tv;
     (void)gettimeofday(&tv, 0);
-    int sec = tv.tv_sec;
+    time_t sec = tv.tv_sec;
 
     for (size_t i = 0; i < m_objects.size(); ++i) {
 	ObjectTimePair &pair = m_objects[i];
@@ -156,7 +156,7 @@
     
     struct timeval tv;
     (void)gettimeofday(&tv, 0);
-    int sec = tv.tv_sec;
+    time_t sec = tv.tv_sec;
 
     for (size_t i = 0; i < m_objects.size(); ++i) {
 	ObjectTimePair &pair = m_objects[i];
@@ -188,7 +188,7 @@
 
 template <typename T>
 void
-Scavenger<T>::clearExcess(int sec)
+Scavenger<T>::clearExcess(time_t sec)
 {
     m_excessMutex.lock();
     for (typename ObjectList::iterator i = m_excess.begin();
--- a/base/Selection.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Selection.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -22,12 +22,12 @@
 {
 }
 
-Selection::Selection(int startFrame, int endFrame) :
+Selection::Selection(sv_frame_t startFrame, sv_frame_t endFrame) :
     m_startFrame(startFrame),
     m_endFrame(endFrame)
 {
     if (m_startFrame > m_endFrame) {
-	int tmp = m_endFrame;
+	sv_frame_t tmp = m_endFrame;
 	m_endFrame = m_startFrame;
 	m_startFrame = tmp;
     }
@@ -59,20 +59,20 @@
     return m_startFrame == m_endFrame;
 }
 
-int
+sv_frame_t
 Selection::getStartFrame() const
 {
     return m_startFrame;
 }
 
-int
+sv_frame_t
 Selection::getEndFrame() const
 {
     return m_endFrame;
 }
 
 bool
-Selection::contains(int frame) const
+Selection::contains(sv_frame_t frame) const
 {
     return (frame >= m_startFrame) && (frame < m_endFrame);
 }
@@ -174,7 +174,7 @@
 }
 
 void
-MultiSelection::getExtents(int &startFrame, int &endFrame) const
+MultiSelection::getExtents(sv_frame_t &startFrame, sv_frame_t &endFrame) const
 {
     startFrame = 0;
     endFrame = 0;
@@ -193,7 +193,7 @@
 }
 
 Selection
-MultiSelection::getContainingSelection(int frame, bool defaultToFollowing) const
+MultiSelection::getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const
 {
     // This scales very badly with the number of selections, but it's
     // more efficient for very small numbers of selections than a more
--- a/base/Selection.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Selection.h	Mon Mar 23 11:26:28 2015 +0000
@@ -20,6 +20,7 @@
 #include <set>
 
 #include "XmlExportable.h"
+#include "BaseTypes.h"
 
 /**
  * A selection object simply represents a range in time, via start and
@@ -40,22 +41,22 @@
 {
 public:
     Selection();
-    Selection(int startFrame, int endFrame);
+    Selection(sv_frame_t startFrame, sv_frame_t endFrame);
     Selection(const Selection &);
     Selection &operator=(const Selection &);
     virtual ~Selection();
 
     bool isEmpty() const;
-    int getStartFrame() const;
-    int getEndFrame() const;
-    bool contains(int frame) const;
+    sv_frame_t getStartFrame() const;
+    sv_frame_t getEndFrame() const;
+    bool contains(sv_frame_t frame) const;
 
     bool operator<(const Selection &) const;
     bool operator==(const Selection &) const;
     
 protected:
-    int m_startFrame;
-    int m_endFrame;
+    sv_frame_t m_startFrame;
+    sv_frame_t m_endFrame;
 };
 
 class MultiSelection : public XmlExportable
@@ -72,7 +73,7 @@
     void removeSelection(const Selection &selection);
     void clearSelections();
 
-    void getExtents(int &startFrame, int &endFrame) const;
+    void getExtents(sv_frame_t &startFrame, sv_frame_t &endFrame) const;
 
     /**
      * Return the selection that contains a given frame.
@@ -80,7 +81,7 @@
      * selected area, return the next selection after the given frame.
      * Return the empty selection if no appropriate selection is found.
      */
-    Selection getContainingSelection(int frame, bool defaultToFollowing) const;
+    Selection getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const;
 
     virtual void toXml(QTextStream &stream, QString indent = "",
                        QString extraAttributes = "") const;
--- a/base/StorageAdviser.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/StorageAdviser.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -24,16 +24,16 @@
 
 //#define DEBUG_STORAGE_ADVISER 1
 
-long StorageAdviser::m_discPlanned = 0;
-long StorageAdviser::m_memoryPlanned = 0;
+size_t StorageAdviser::m_discPlanned = 0;
+size_t StorageAdviser::m_memoryPlanned = 0;
 
 StorageAdviser::Recommendation
 StorageAdviser::m_baseRecommendation = StorageAdviser::NoRecommendation;
 
 StorageAdviser::Recommendation
 StorageAdviser::recommend(Criteria criteria,
-			  int minimumSize,
-			  int maximumSize)
+			  size_t minimumSize,
+			  size_t maximumSize)
 {
 #ifdef DEBUG_STORAGE_ADVISER
     SVDEBUG << "StorageAdviser::recommend: Criteria " << criteria 
@@ -52,17 +52,17 @@
         cerr << "StorageAdviser::recommend: ERROR: Failed to get temporary directory path: " << e.what() << endl;
         return Recommendation(UseMemory | ConserveSpace);
     }
-    int discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit());
-    int memoryFree, memoryTotal;
+    ssize_t discFree = GetDiscSpaceMBAvailable(path.toLocal8Bit());
+    ssize_t memoryFree, memoryTotal;
     GetRealMemoryMBAvailable(memoryFree, memoryTotal);
 
-    if (discFree > m_discPlanned / 1024 + 1) {
+    if (discFree > ssize_t(m_discPlanned / 1024 + 1)) {
         discFree -= m_discPlanned / 1024 + 1;
     } else if (discFree > 0) { // can also be -1 for unknown
         discFree = 0;
     }
 
-    if (memoryFree > m_memoryPlanned / 1024 + 1) {
+    if (memoryFree > ssize_t(m_memoryPlanned / 1024 + 1)) {
         memoryFree -= m_memoryPlanned / 1024 + 1;
     } else if (memoryFree > 0) { // can also be -1 for unknown
         memoryFree = 0;
@@ -87,8 +87,8 @@
     StorageStatus memoryStatus = Unknown;
     StorageStatus discStatus = Unknown;
 
-    int minmb = minimumSize / 1024 + 1;
-    int maxmb = maximumSize / 1024 + 1;
+    ssize_t minmb = ssize_t(minimumSize / 1024 + 1);
+    ssize_t maxmb = ssize_t(maximumSize / 1024 + 1);
 
     if (memoryFree == -1) memoryStatus = Unknown;
     else if (memoryFree < memoryTotal / 3) memoryStatus = Insufficient;
@@ -185,7 +185,7 @@
 }
 
 void
-StorageAdviser::notifyPlannedAllocation(AllocationArea area, int size)
+StorageAdviser::notifyPlannedAllocation(AllocationArea area, size_t size)
 {
     if (area == MemoryAllocation) m_memoryPlanned += size;
     else if (area == DiscAllocation) m_discPlanned += size;
@@ -194,7 +194,7 @@
 }
 
 void
-StorageAdviser::notifyDoneAllocation(AllocationArea area, int size)
+StorageAdviser::notifyDoneAllocation(AllocationArea area, size_t size)
 {
     if (area == MemoryAllocation) {
         if (m_memoryPlanned > size) m_memoryPlanned -= size;
--- a/base/StorageAdviser.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/StorageAdviser.h	Mon Mar 23 11:26:28 2015 +0000
@@ -17,6 +17,8 @@
 #ifndef _STORAGE_ADVISER_H_
 #define _STORAGE_ADVISER_H_
 
+#include <cstdlib>
+
 /**
  * A utility class designed to help decide whether to store cache data
  * (for example FFT outputs) in memory or on disk in the TempDirectory.
@@ -57,8 +59,8 @@
      * be nowhere the minimum amount of data can be stored.
      */
     static Recommendation recommend(Criteria criteria,
-                                    int minimumSize,
-                                    int maximumSize);
+                                    size_t minimumSize,
+                                    size_t maximumSize);
 
     enum AllocationArea {
         MemoryAllocation,
@@ -69,14 +71,14 @@
      * Specify that we are planning to use a given amount of storage
      * (in kilobytes), but haven't allocated it yet.
      */
-    static void notifyPlannedAllocation(AllocationArea area, int size);
+    static void notifyPlannedAllocation(AllocationArea area, size_t size);
 
     /**
      * Specify that we have now allocated, or abandoned the allocation
      * of, the given amount (in kilobytes) of a storage area that was
      * previously notified using notifyPlannedAllocation.
      */
-    static void notifyDoneAllocation(AllocationArea area, int size);
+    static void notifyDoneAllocation(AllocationArea area, size_t size);
 
     /**
      * Force all subsequent recommendations to use the (perhaps
@@ -86,8 +88,8 @@
     static void setFixedRecommendation(Recommendation recommendation);
 
 private:
-    static long m_discPlanned;
-    static long m_memoryPlanned;
+    static size_t m_discPlanned;
+    static size_t m_memoryPlanned;
     static Recommendation m_baseRecommendation;
 };
 
--- a/base/TempDirectory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/TempDirectory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -110,7 +110,7 @@
 
     QString suffix;
     int padlen = 6, attempts = 100;
-    unsigned int r = time(0) ^ getpid();
+    unsigned int r = (unsigned int)(time(0) ^ getpid());
 
     for (int i = 0; i < padlen; ++i) {
         suffix += "X";
--- a/base/ViewManagerBase.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/ViewManagerBase.h	Mon Mar 23 11:26:28 2015 +0000
@@ -37,15 +37,15 @@
 
     virtual void setAudioPlaySource(AudioPlaySource *source) = 0;
 
-    virtual int alignPlaybackFrameToReference(int) const = 0;
-    virtual int alignReferenceToPlaybackFrame(int) const = 0;
+    virtual sv_frame_t alignPlaybackFrameToReference(sv_frame_t) const = 0;
+    virtual sv_frame_t alignReferenceToPlaybackFrame(sv_frame_t) const = 0;
 
     virtual const MultiSelection &getSelection() const = 0;
     virtual const MultiSelection::SelectionList &getSelections() const = 0;
-    virtual int constrainFrameToSelection(int frame) const = 0;
+    virtual sv_frame_t constrainFrameToSelection(sv_frame_t frame) const = 0;
 
     virtual Selection getContainingSelection
-    (int frame, bool defaultToFollowing) const = 0;
+    (sv_frame_t frame, bool defaultToFollowing) const = 0;
 
     virtual bool getPlayLoopMode() const = 0;
     virtual bool getPlaySelectionMode() const = 0;
--- a/base/Window.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/Window.h	Mon Mar 23 11:26:28 2015 +0000
@@ -82,7 +82,7 @@
     T m_area;
     
     void encache();
-    void cosinewin(T *, T, T, T, T);
+    void cosinewin(T *, double, double, double, double);
 };
 
 template <typename T>
@@ -97,14 +97,14 @@
 		
     case RectangularWindow:
 	for (i = 0; i < n; ++i) {
-	    mult[i] *= 0.5;
+	    mult[i] *= T(0.5);
 	}
 	break;
 	    
     case BartlettWindow:
 	for (i = 0; i < n/2; ++i) {
-	    mult[i] *= (i / T(n/2));
-	    mult[i + n/2] *= (1.0 - (i / T(n/2)));
+	    mult[i] *= T(i) / T(n/2);
+	    mult[i + n/2] *= T(1.0) - T(i) / T(n/2);
 	}
 	break;
 	    
@@ -122,7 +122,7 @@
 	    
     case GaussianWindow:
 	for (i = 0; i < n; ++i) {
-            mult[i] *= pow(2, - pow((i - (n-1)/2.0) / ((n-1)/2.0 / 3), 2));
+            mult[i] *= T(pow(2, - pow((i - (n-1)/2.0) / ((n-1)/2.0 / 3), 2)));
 	}
 	break;
 	    
@@ -130,13 +130,13 @@
     {
         int N = n-1;
         for (i = 0; i < N/4; ++i) {
-            T m = 2 * pow(1.0 - (T(N)/2 - i) / (T(N)/2), 3);
+            T m = T(2 * pow(1.0 - (T(N)/2 - T(i)) / (T(N)/2), 3));
             mult[i] *= m;
             mult[N-i] *= m;
         }
         for (i = N/4; i <= N/2; ++i) {
             int wn = i - N/2;
-            T m = 1.0 - 6 * pow(wn / (T(N)/2), 2) * (1.0 - abs(wn) / (T(N)/2));
+            T m = T(1.0 - 6 * pow(T(wn) / (T(N)/2), 2) * (1.0 - T(abs(wn)) / (T(N)/2)));
             mult[i] *= m;
             mult[N-i] *= m;
         }            
@@ -158,18 +158,18 @@
     for (int i = 0; i < n; ++i) {
         m_area += m_cache[i];
     }
-    m_area /= n;
+    m_area /= T(n);
 }
 
 template <typename T>
-void Window<T>::cosinewin(T *mult, T a0, T a1, T a2, T a3)
+void Window<T>::cosinewin(T *mult, double a0, double a1, double a2, double a3)
 {
     const int n = m_size;
     for (int i = 0; i < n; ++i) {
-        mult[i] *= (a0
-                    - a1 * cos((2 * M_PI * i) / n)
-                    + a2 * cos((4 * M_PI * i) / n)
-                    - a3 * cos((6 * M_PI * i) / n));
+        mult[i] *= T(a0
+                     - a1 * cos((2 * M_PI * i) / n)
+                     + a2 * cos((4 * M_PI * i) / n)
+                     - a3 * cos((6 * M_PI * i) / n));
     }
 }
 
--- a/base/test/TestRealTime.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/test/TestRealTime.h	Mon Mar 23 11:26:28 2015 +0000
@@ -282,12 +282,12 @@
         int m = sizeof(rates)/sizeof(rates[0]);
 
         for (int i = 0; i < n; ++i) {
-            int frame = frames[i];
+            sv_frame_t frame = frames[i];
             for (int j = 0; j < m; ++j) {
                 int rate = rates[j];
 
                 RealTime rt = RealTime::frame2RealTime(frame, rate);
-                int conv = RealTime::realTime2Frame(rt, rate);
+                sv_frame_t conv = RealTime::realTime2Frame(rt, rate);
                 QCOMPARE(frame, conv);
 
                 rt = RealTime::frame2RealTime(-frame, rate);
--- a/base/test/test.pro	Mon Mar 23 10:04:48 2015 +0000
+++ b/base/test/test.pro	Mon Mar 23 11:26:28 2015 +0000
@@ -38,7 +38,7 @@
     }
 }
 
-CONFIG += qt thread warn_on stl rtti exceptions console
+CONFIG += qt thread warn_on stl rtti exceptions console c++11
 QT += network xml testlib
 QT -= gui
 
--- a/configure	Mon Mar 23 10:04:48 2015 +0000
+++ b/configure	Mon Mar 23 11:26:28 2015 +0000
@@ -673,6 +673,7 @@
 EGREP
 GREP
 CXXCPP
+HAVE_CXX11
 MKDIR_P
 INSTALL_DATA
 INSTALL_SCRIPT
@@ -3449,6 +3450,146 @@
 $as_echo "$MKDIR_P" >&6; }
 
 
+# We are daringly making use of C++11 now
+
+    ax_cxx_compile_cxx11_required=true
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+  ac_success=no
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports C++11 features by default" >&5
+$as_echo_n "checking whether $CXX supports C++11 features by default... " >&6; }
+if ${ax_cv_cxx_compile_cxx11+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+  template <typename T>
+    struct check
+    {
+      static_assert(sizeof(int) <= sizeof(T), "not big enough");
+    };
+
+    struct Base {
+    virtual void f() {}
+    };
+    struct Child : public Base {
+    virtual void f() override {}
+    };
+
+    typedef check<check<bool>> right_angle_brackets;
+
+    int a;
+    decltype(a) b;
+
+    typedef check<int> check_type;
+    check_type c;
+    check_type&& cr = static_cast<check_type&&>(c);
+
+    auto d = a;
+    auto l = [](){};
+
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  ax_cv_cxx_compile_cxx11=yes
+else
+  ax_cv_cxx_compile_cxx11=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_cxx_compile_cxx11" >&5
+$as_echo "$ax_cv_cxx_compile_cxx11" >&6; }
+  if test x$ax_cv_cxx_compile_cxx11 = xyes; then
+    ac_success=yes
+  fi
+
+
+
+    if test x$ac_success = xno; then
+    for switch in -std=c++11 -std=c++0x; do
+      cachevar=`$as_echo "ax_cv_cxx_compile_cxx11_$switch" | $as_tr_sh`
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports C++11 features with $switch" >&5
+$as_echo_n "checking whether $CXX supports C++11 features with $switch... " >&6; }
+if eval \${$cachevar+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_save_CXXFLAGS="$CXXFLAGS"
+         CXXFLAGS="$CXXFLAGS $switch"
+         cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+  template <typename T>
+    struct check
+    {
+      static_assert(sizeof(int) <= sizeof(T), "not big enough");
+    };
+
+    struct Base {
+    virtual void f() {}
+    };
+    struct Child : public Base {
+    virtual void f() override {}
+    };
+
+    typedef check<check<bool>> right_angle_brackets;
+
+    int a;
+    decltype(a) b;
+
+    typedef check<int> check_type;
+    check_type c;
+    check_type&& cr = static_cast<check_type&&>(c);
+
+    auto d = a;
+    auto l = [](){};
+
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  eval $cachevar=yes
+else
+  eval $cachevar=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+         CXXFLAGS="$ac_save_CXXFLAGS"
+fi
+eval ac_res=\$$cachevar
+	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
+$as_echo "$ac_res" >&6; }
+      if eval test x\$$cachevar = xyes; then
+        CXXFLAGS="$CXXFLAGS $switch"
+        ac_success=yes
+        break
+      fi
+    done
+  fi
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  if test x$ax_cxx_compile_cxx11_required = xtrue; then
+    if test x$ac_success = xno; then
+      as_fn_error $? "*** A compiler with support for C++11 language features is required." "$LINENO" 5
+    fi
+  else
+    if test x$ac_success = xno; then
+      HAVE_CXX11=0
+      { $as_echo "$as_me:${as_lineno-$LINENO}: No compiler with C++11 support was found" >&5
+$as_echo "$as_me: No compiler with C++11 support was found" >&6;}
+    else
+      HAVE_CXX11=1
+
+$as_echo "#define HAVE_CXX11 1" >>confdefs.h
+
+    fi
+
+
+  fi
+
 
 ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'
@@ -4202,9 +4343,10 @@
 CXXFLAGS_MINIMAL="$AUTOCONF_CXXFLAGS"
 
 if test "x$GCC" = "xyes"; then
-        CXXFLAGS_DEBUG="-Wall -Wextra -Werror -Woverloaded-virtual -Wformat-nonliteral -Wformat-security -Winit-self -Wswitch-enum -g -pipe"
-   	CXXFLAGS_RELEASE="-g0 -O2 -Wall -pipe"
-   	CXXFLAGS_MINIMAL="-g0 -O0"
+   	CXXFLAGS_ANY="-Wall -Wextra -Werror -Woverloaded-virtual -Wformat-nonliteral -Wformat-security -Winit-self -Wswitch-enum -Wconversion -pipe"
+        CXXFLAGS_DEBUG="$CXXFLAGS_ANY -g"
+   	CXXFLAGS_RELEASE="$CXXFLAGS_ANY -g0 -O2"
+   	CXXFLAGS_MINIMAL="$CXXFLAGS_ANY -g0 -O0"
 fi
 
 CXXFLAGS_BUILD="$CXXFLAGS_RELEASE"
--- a/configure.ac	Mon Mar 23 10:04:48 2015 +0000
+++ b/configure.ac	Mon Mar 23 11:26:28 2015 +0000
@@ -25,6 +25,9 @@
 AC_PROG_INSTALL
 AC_PROG_MKDIR_P
 
+# We are daringly making use of C++11 now
+AX_CXX_COMPILE_STDCXX_11(noext)
+
 AC_HEADER_STDC
 
 # These are the flags Autoconf guesses for us; we use them later if
@@ -50,9 +53,10 @@
 CXXFLAGS_MINIMAL="$AUTOCONF_CXXFLAGS"
 
 if test "x$GCC" = "xyes"; then
-        CXXFLAGS_DEBUG="-Wall -Wextra -Werror -Woverloaded-virtual -Wformat-nonliteral -Wformat-security -Winit-self -Wswitch-enum -g -pipe"
-   	CXXFLAGS_RELEASE="-g0 -O2 -Wall -pipe"
-   	CXXFLAGS_MINIMAL="-g0 -O0"
+   	CXXFLAGS_ANY="-Wall -Wextra -Werror -Woverloaded-virtual -Wformat-nonliteral -Wformat-security -Winit-self -Wswitch-enum -Wconversion -pipe"
+        CXXFLAGS_DEBUG="$CXXFLAGS_ANY -g"
+   	CXXFLAGS_RELEASE="$CXXFLAGS_ANY -g0 -O2"
+   	CXXFLAGS_MINIMAL="$CXXFLAGS_ANY -g0 -O0"
 fi
 
 CXXFLAGS_BUILD="$CXXFLAGS_RELEASE"
--- a/data/fft/FFTDataServer.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fft/FFTDataServer.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -30,6 +30,8 @@
 
 #include <QWriteLocker>
 
+#include <stdexcept>
+
 //#define DEBUG_FFT_SERVER 1
 //#define DEBUG_FFT_SERVER_FILL 1
 
@@ -53,7 +55,7 @@
                            int fftSize,
                            bool polar,
                            StorageAdviser::Criteria criteria,
-                           int fillFromColumn)
+                           sv_frame_t fillFromFrame)
 {
     QString n = generateFileBasename(model,
                                      channel,
@@ -93,7 +95,7 @@
                                    fftSize,
                                    polar,
                                    criteria,
-                                   fillFromColumn);
+                                   fillFromFrame);
     } catch (InsufficientDiscSpace) {
         delete server;
         server = 0;
@@ -115,7 +117,7 @@
                                 int fftSize,
                                 bool polar,
                                 StorageAdviser::Criteria criteria,
-                                int fillFromColumn)
+                                sv_frame_t fillFromFrame)
 {
     // Fuzzy matching:
     // 
@@ -221,7 +223,7 @@
                        fftSize,
                        polar,
                        criteria,
-                       fillFromColumn);
+                       fillFromFrame);
 }
 
 FFTDataServer *
@@ -488,7 +490,7 @@
 			     int fftSize,
                              bool polar,
                              StorageAdviser::Criteria criteria,
-                             int fillFromColumn) :
+                             sv_frame_t fillFromFrame) :
     m_fileBaseName(fileBaseName),
     m_model(model),
     m_channel(channel),
@@ -514,10 +516,10 @@
 
     //!!! end is not correct until model finished reading -- what to do???
 
-    int start = m_model->getStartFrame();
-    int end = m_model->getEndFrame();
+    sv_frame_t start = m_model->getStartFrame();
+    sv_frame_t end = m_model->getEndFrame();
 
-    m_width = (end - start) / m_windowIncrement + 1;
+    m_width = int((end - start) / m_windowIncrement) + 1;
     m_height = m_fftSize / 2 + 1; // DC == 0, Nyquist == fftsize/2
 
 #ifdef DEBUG_FFT_SERVER 
@@ -526,7 +528,7 @@
 #endif
 
     int maxCacheSize = 20 * 1024 * 1024;
-    int columnSize = m_height * sizeof(fftsample) * 2 + sizeof(fftsample);
+    int columnSize = int(m_height * sizeof(fftsample) * 2 + sizeof(fftsample));
     if (m_width * columnSize < maxCacheSize * 2) m_cacheWidth = m_width;
     else m_cacheWidth = maxCacheSize / columnSize;
     
@@ -585,7 +587,7 @@
         throw(0);
     }
 
-    m_fillThread = new FillThread(*this, fillFromColumn);
+    m_fillThread = new FillThread(*this, fillFromFrame);
 }
 
 FFTDataServer::~FFTDataServer()
@@ -681,9 +683,10 @@
 FFTDataServer::getStorageAdvice(int w, int h,
                                 bool &memoryCache, bool &compactCache)
 {
-    int cells = w * h;
-    int minimumSize = (cells / 1024) * sizeof(uint16_t); // kb
-    int maximumSize = (cells / 1024) * sizeof(float); // kb
+    if (w < 0 || h < 0) throw std::domain_error("width & height must be non-negative");
+    size_t cells = size_t(w) * h;
+    size_t minimumSize = (cells / 1024) * sizeof(uint16_t); // kb
+    size_t maximumSize = (cells / 1024) * sizeof(float); // kb
 
     // We don't have a compact rectangular representation, and compact
     // of course is never precision-critical
@@ -1248,11 +1251,11 @@
     int fftsize = m_fftSize;
     int hs = fftsize/2;
 
-    int pfx = 0;
+    sv_frame_t pfx = 0;
     int off = (fftsize - winsize) / 2;
 
-    int startFrame = m_windowIncrement * x;
-    int endFrame = startFrame + m_windowSize;
+    sv_frame_t startFrame = m_windowIncrement * sv_frame_t(x);
+    sv_frame_t endFrame = startFrame + m_windowSize;
 
     startFrame -= winsize / 2;
     endFrame   -= winsize / 2;
@@ -1300,11 +1303,11 @@
 	}
     }
 
-    int count = 0;
+    sv_frame_t count = 0;
     if (endFrame > startFrame + pfx) count = endFrame - (startFrame + pfx);
 
-    int got = m_model->getData(m_channel, startFrame + pfx,
-                               count, m_fftInput + off + pfx);
+    sv_frame_t got = m_model->getData(m_channel, startFrame + pfx,
+                                      count, m_fftInput + off + pfx);
 
     while (got + pfx < winsize) {
 	m_fftInput[off + got + pfx] = 0.0;
@@ -1315,7 +1318,7 @@
 	int channels = m_model->getChannelCount();
 	if (channels > 1) {
 	    for (int i = 0; i < winsize; ++i) {
-		m_fftInput[off + i] /= channels;
+		m_fftInput[off + i] /= float(channels);
 	    }
 	}
     }
@@ -1404,7 +1407,7 @@
     else return 100;
 }
 
-int
+sv_frame_t
 FFTDataServer::getFillExtent() const
 {
     if (m_fillThread) return m_fillThread->getExtent();
@@ -1456,18 +1459,18 @@
     }
     if (m_server.m_exiting) return;
 
-    int start = m_server.m_model->getStartFrame();
-    int end = m_server.m_model->getEndFrame();
-    int remainingEnd = end;
+    sv_frame_t start = m_server.m_model->getStartFrame();
+    sv_frame_t end = m_server.m_model->getEndFrame();
+    sv_frame_t remainingEnd = end;
 
     int counter = 0;
     int updateAt = 1;
-    int maxUpdateAt = (end / m_server.m_windowIncrement) / 20;
+    int maxUpdateAt = int(end / m_server.m_windowIncrement) / 20;
     if (maxUpdateAt < 100) maxUpdateAt = 100;
 
     if (m_fillFrom > start) {
 
-        for (int f = m_fillFrom; f < end; f += m_server.m_windowIncrement) {
+        for (sv_frame_t f = m_fillFrom; f < end; f += m_server.m_windowIncrement) {
 	    
             try {
                 m_server.fillColumn(int((f - start) / m_server.m_windowIncrement));
@@ -1516,7 +1519,7 @@
 
     int baseCompletion = m_completion;
 
-    for (int f = start; f < remainingEnd; f += m_server.m_windowIncrement) {
+    for (sv_frame_t f = start; f < remainingEnd; f += m_server.m_windowIncrement) {
 
         try {
             m_server.fillColumn(int((f - start) / m_server.m_windowIncrement));
--- a/data/fft/FFTDataServer.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fft/FFTDataServer.h	Mon Mar 23 11:26:28 2015 +0000
@@ -49,7 +49,7 @@
                                       bool polar,
                                       StorageAdviser::Criteria criteria =
                                           StorageAdviser::NoCriteria,
-                                      int fillFromColumn = 0);
+                                      sv_frame_t fillFromFrame = 0);
 
     static FFTDataServer *getFuzzyInstance(const DenseTimeValueModel *model,
                                            int channel,
@@ -60,7 +60,7 @@
                                            bool polar,
                                            StorageAdviser::Criteria criteria =
                                                StorageAdviser::NoCriteria,
-                                           int fillFromColumn = 0);
+                                           sv_frame_t fillFromFrame = 0);
 
     static void claimInstance(FFTDataServer *);
     static void releaseInstance(FFTDataServer *);
@@ -108,7 +108,7 @@
 
     QString getError() const;
     int getFillCompletion() const;
-    int getFillExtent() const;
+    sv_frame_t getFillExtent() const;
 
 private:
     FFTDataServer(QString fileBaseName,
@@ -120,7 +120,7 @@
                   int fftSize,
                   bool polar,
                   StorageAdviser::Criteria criteria,
-                  int fillFromColumn = 0);
+                  sv_frame_t fillFromFrame = 0);
 
     virtual ~FFTDataServer();
 
@@ -241,20 +241,20 @@
     class FillThread : public Thread
     {
     public:
-        FillThread(FFTDataServer &server, int fillFromColumn) :
+        FillThread(FFTDataServer &server, sv_frame_t fillFromFrame) :
             m_server(server), m_extent(0), m_completion(0),
-            m_fillFrom(fillFromColumn) { }
+            m_fillFrom(fillFromFrame) { }
 
-        int getExtent() const { return m_extent; }
+        sv_frame_t getExtent() const { return m_extent; }
         int getCompletion() const { return m_completion ? m_completion : 1; }
         QString getError() const { return m_error; }
         virtual void run();
 
     protected:
         FFTDataServer &m_server;
-        int m_extent;
+        sv_frame_t m_extent;
         int m_completion;
-        int m_fillFrom;
+        sv_frame_t m_fillFrom;
         QString m_error;
     };
 
--- a/data/fft/FFTFileCacheReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fft/FFTFileCacheReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -40,7 +40,7 @@
     m_mfc(new MatrixFile
           (writer->getFileBase(),
            MatrixFile::ReadOnly,
-           m_storageType == FFTCache::Compact ? sizeof(uint16_t) : sizeof(float),
+           int((m_storageType == FFTCache::Compact) ? sizeof(uint16_t) : sizeof(float)),
            writer->getWidth(),
            writer->getHeight() * 2 + m_factorSize))
 {
@@ -77,7 +77,7 @@
     switch (m_storageType) {
 
     case FFTCache::Compact:
-        value = (getFromReadBufCompactUnsigned(x, y * 2) / 65535.0)
+        value = (getFromReadBufCompactUnsigned(x, y * 2) / 65535.f)
             * getNormalizationFactor(x);
         break;
 
@@ -105,7 +105,7 @@
     switch (m_storageType) {
 
     case FFTCache::Compact:
-        value = getFromReadBufCompactUnsigned(x, y * 2) / 65535.0;
+        value = getFromReadBufCompactUnsigned(x, y * 2) / 65535.f;
         break;
 
     case FFTCache::Rectangular:
@@ -136,7 +136,7 @@
     switch (m_storageType) {
 
     case FFTCache::Compact:
-        value = (getFromReadBufCompactSigned(x, y * 2 + 1) / 32767.0) * M_PI;
+        value = (getFromReadBufCompactSigned(x, y * 2 + 1) / 32767.f) * float(M_PI);
         break;
 
     case FFTCache::Rectangular:
@@ -187,7 +187,7 @@
     case FFTCache::Compact:
         for (int i = 0; i < count; ++i) {
             int y = minbin + i * step;
-            values[i] = (getFromReadBufCompactUnsigned(x, y * 2) / 65535.0)
+            values[i] = (getFromReadBufCompactUnsigned(x, y * 2) / 65535.f)
                 * getNormalizationFactor(x);
         }
         break;
@@ -224,7 +224,7 @@
     return m_mfc->haveSetColumnAt(x);
 }
 
-int
+size_t
 FFTFileCacheReader::getCacheSize(int width, int height,
                                  FFTCache::StorageType type)
 {
--- a/data/fft/FFTFileCacheReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fft/FFTFileCacheReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -41,7 +41,7 @@
 
     bool haveSetColumnAt(int x) const;
 
-    static int getCacheSize(int width, int height,
+    static size_t getCacheSize(int width, int height,
                                FFTCache::StorageType type);
 
     FFTCache::StorageType getStorageType() const { return m_storageType; }
--- a/data/fft/FFTFileCacheWriter.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fft/FFTFileCacheWriter.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -40,7 +40,7 @@
     m_factorSize(storageType == FFTCache::Compact ? 2 : 1),
     m_mfc(new MatrixFile
           (fileBase, MatrixFile::WriteOnly, 
-           storageType == FFTCache::Compact ? sizeof(uint16_t) : sizeof(float),
+           int((storageType == FFTCache::Compact) ? sizeof(uint16_t) : sizeof(float)),
            width, height * 2 + m_factorSize))
 {
 #ifdef DEBUG_FFT_FILE_CACHE_WRITER
@@ -175,7 +175,7 @@
     m_mfc->setColumnAt(x, m_writebuf);
 }
 
-int
+size_t
 FFTFileCacheWriter::getCacheSize(int width, int height,
                                  FFTCache::StorageType type)
 {
--- a/data/fft/FFTFileCacheWriter.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fft/FFTFileCacheWriter.h	Mon Mar 23 11:26:28 2015 +0000
@@ -34,7 +34,7 @@
     void setColumnAt(int x, float *mags, float *phases, float factor);
     void setColumnAt(int x, float *reals, float *imags);
 
-    static int getCacheSize(int width, int height,
+    static size_t getCacheSize(int width, int height,
                                FFTCache::StorageType type);
 
     bool haveSetColumnAt(int x) const;
--- a/data/fft/FFTMemoryCache.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fft/FFTMemoryCache.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -196,10 +196,10 @@
     }
 }
 
-int
+size_t
 FFTMemoryCache::getCacheSize(int width, int height, FFTCache::StorageType type)
 {
-    int sz = 0;
+    size_t sz = 0;
 
     switch (type) {
 
--- a/data/fft/FFTMemoryCache.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fft/FFTMemoryCache.h	Mon Mar 23 11:26:28 2015 +0000
@@ -66,7 +66,7 @@
     float getNormalizedMagnitudeAt(int x, int y) const {
         if (m_storageType == FFTCache::Rectangular) return getMagnitudeAt(x, y) / m_factor[x];
         else if (m_storageType == FFTCache::Polar) return m_fmagnitude[x][y];
-        else return float(m_magnitude[x][y]) / 65535.0;
+        else return float(m_magnitude[x][y]) / 65535.f;
     }
     
     float getMaximumMagnitudeAt(int x) const {
@@ -81,7 +81,7 @@
             return m_fphase[x][y];
         } else {
             int16_t i = (int16_t)m_phase[x][y];
-            return (float(i) / 32767.0) * M_PI;
+            return float(i / 32767.0 * M_PI);
         }
     }
     
@@ -114,7 +114,7 @@
         } else {
             for (int i = 0; i < count; ++i) {
                 int y = i * step + minbin;
-                values[i] = (float(m_magnitude[x][y]) * m_factor[x]) / 65535.0;
+                values[i] = float(double(m_magnitude[x][y]) * m_factor[x] / 65535.0);
             }
         }
     }
@@ -132,7 +132,7 @@
 
     void allColumnsWritten() { } 
 
-    static int getCacheSize(int width, int height,
+    static size_t getCacheSize(int width, int height,
                                FFTCache::StorageType type);
 
     FFTCache::StorageType getStorageType() const { return m_storageType; }
--- a/data/fileio/AudioFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/AudioFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -15,26 +15,24 @@
 
 #include "AudioFileReader.h"
 
-void
-AudioFileReader::getDeInterleavedFrames(int start, int count,
-                                        std::vector<SampleBlock> &frames) const
+using std::vector;
+
+vector<SampleBlock>
+AudioFileReader::getDeInterleavedFrames(sv_frame_t start, sv_frame_t count) const
 {
-    SampleBlock interleaved;
-    getInterleavedFrames(start, count, interleaved);
+    SampleBlock interleaved = getInterleavedFrames(start, count);
     
     int channels = getChannelCount();
-    int rc = interleaved.size() / channels;
+    sv_frame_t rc = interleaved.size() / channels;
 
-    frames.clear();
-
+    vector<SampleBlock> frames(channels, SampleBlock(rc, 0.f));
+    
     for (int c = 0; c < channels; ++c) {
-        frames.push_back(SampleBlock());
+        for (sv_frame_t i = 0; i < rc; ++i) {
+            frames[c][i] = interleaved[i * channels + c];
+        }
     }
 
-    for (int i = 0; i < rc; ++i) {
-        for (int c = 0; c < channels; ++c) {
-            frames[c].push_back(interleaved[i * channels + c]);
-        }
-    }
+    return frames;
 }
 
--- a/data/fileio/AudioFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/AudioFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -18,6 +18,7 @@
 
 #include <QString>
 
+#include "base/BaseTypes.h"
 #include "FileSource.h"
 
 #include <vector>
@@ -36,11 +37,11 @@
 
     virtual QString getError() const { return ""; }
 
-    int getFrameCount() const { return m_frameCount; }
+    sv_frame_t getFrameCount() const { return m_frameCount; }
     int getChannelCount() const { return m_channelCount; }
-    int getSampleRate() const { return m_sampleRate; }
+    sv_samplerate_t getSampleRate() const { return m_sampleRate; }
 
-    virtual int getNativeRate() const { return m_sampleRate; } // if resampled
+    virtual sv_samplerate_t getNativeRate() const { return m_sampleRate; } // if resampled
 
     /**
      * Return the location of the audio data in the reader (as passed
@@ -93,8 +94,7 @@
      * thread-safe -- that is, safe to call from multiple threads with
      * different arguments on the same object at the same time.
      */
-    virtual void getInterleavedFrames(int start, int count,
-				      SampleBlock &frames) const = 0;
+    virtual SampleBlock getInterleavedFrames(sv_frame_t start, sv_frame_t count) const = 0;
 
     /**
      * Return de-interleaved samples for count frames from index
@@ -103,8 +103,7 @@
      * will contain getChannelCount() sample blocks of count samples
      * each (or fewer if end of file is reached).
      */
-    virtual void getDeInterleavedFrames(int start, int count,
-                                        std::vector<SampleBlock> &frames) const;
+    virtual std::vector<SampleBlock> getDeInterleavedFrames(sv_frame_t start, sv_frame_t count) const;
 
     // only subclasses that do not know exactly how long the audio
     // file is until it's been completely decoded should implement this
@@ -116,9 +115,9 @@
     void frameCountChanged();
     
 protected:
-    int m_frameCount;
+    sv_frame_t m_frameCount;
     int m_channelCount;
-    int m_sampleRate;
+    sv_samplerate_t m_sampleRate;
 };
 
 #endif
--- a/data/fileio/AudioFileReaderFactory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/AudioFileReaderFactory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -59,7 +59,7 @@
 
 AudioFileReader *
 AudioFileReaderFactory::createReader(FileSource source, 
-                                     int targetRate,
+                                     sv_samplerate_t targetRate,
                                      bool normalised,
                                      ProgressReporter *reporter)
 {
@@ -68,7 +68,7 @@
 
 AudioFileReader *
 AudioFileReaderFactory::createThreadingReader(FileSource source, 
-                                              int targetRate,
+                                              sv_samplerate_t targetRate,
                                               bool normalised,
                                               ProgressReporter *reporter)
 {
@@ -77,7 +77,7 @@
 
 AudioFileReader *
 AudioFileReaderFactory::create(FileSource source, 
-                               int targetRate, 
+                               sv_samplerate_t targetRate, 
                                bool normalised,
                                bool threading,
                                ProgressReporter *reporter)
@@ -105,7 +105,7 @@
 
         reader = new WavFileReader(source);
 
-        int fileRate = reader->getSampleRate();
+        sv_samplerate_t fileRate = reader->getSampleRate();
 
         if (reader->isOK() &&
             (!reader->isQuicklySeekable() ||
@@ -224,7 +224,7 @@
 
         reader = new WavFileReader(source);
 
-        int fileRate = reader->getSampleRate();
+        sv_samplerate_t fileRate = reader->getSampleRate();
 
         if (reader->isOK() &&
             (!reader->isQuicklySeekable() ||
--- a/data/fileio/AudioFileReaderFactory.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/AudioFileReaderFactory.h	Mon Mar 23 11:26:28 2015 +0000
@@ -19,6 +19,7 @@
 #include <QString>
 
 #include "FileSource.h"
+#include "base/BaseTypes.h"
 
 class AudioFileReader;
 class ProgressReporter;
@@ -53,7 +54,7 @@
      * Caller owns the returned object and must delete it after use.
      */
     static AudioFileReader *createReader(FileSource source,
-                                         int targetRate = 0,
+                                         sv_samplerate_t targetRate = 0,
                                          bool normalised = false,
                                          ProgressReporter *reporter = 0);
 
@@ -82,13 +83,13 @@
      * Caller owns the returned object and must delete it after use.
      */
     static AudioFileReader *createThreadingReader(FileSource source,
-                                                  int targetRate = 0,
+                                                  sv_samplerate_t targetRate = 0,
                                                   bool normalised = false,
                                                   ProgressReporter *reporter = 0);
 
 protected:
     static AudioFileReader *create(FileSource source,
-                                   int targetRate,
+                                   sv_samplerate_t targetRate,
                                    bool normalised,
                                    bool threading,
                                    ProgressReporter *reporter);
--- a/data/fileio/BZipFileDevice.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/BZipFileDevice.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -178,7 +178,7 @@
     if (m_atEnd) return 0;
 
     int bzError = BZ_OK;
-    int read = BZ2_bzRead(&bzError, m_bzFile, data, maxSize);
+    int read = BZ2_bzRead(&bzError, m_bzFile, data, int(maxSize));
 
 //    SVDEBUG << "BZipFileDevice::readData: requested " << maxSize << ", read " << read << endl;
 
@@ -201,7 +201,7 @@
 BZipFileDevice::writeData(const char *data, qint64 maxSize)
 {
     int bzError = BZ_OK;
-    BZ2_bzWrite(&bzError, m_bzFile, (void *)data, maxSize);
+    BZ2_bzWrite(&bzError, m_bzFile, (void *)data, int(maxSize));
 
 //    SVDEBUG << "BZipFileDevice::writeData: " << maxSize << " to write" << endl;
 
--- a/data/fileio/CSVFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/CSVFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -36,7 +36,7 @@
 #include <map>
 
 CSVFileReader::CSVFileReader(QString path, CSVFormat format,
-                             int mainModelSampleRate) :
+                             sv_samplerate_t mainModelSampleRate) :
     m_format(format),
     m_device(0),
     m_ownDevice(true),
@@ -63,7 +63,7 @@
 }
 
 CSVFileReader::CSVFileReader(QIODevice *device, CSVFormat format,
-                             int mainModelSampleRate) :
+                             sv_samplerate_t mainModelSampleRate) :
     m_format(format),
     m_device(device),
     m_ownDevice(false),
@@ -95,8 +95,9 @@
     return m_error;
 }
 
-int
-CSVFileReader::convertTimeValue(QString s, int lineno, int sampleRate,
+sv_frame_t
+CSVFileReader::convertTimeValue(QString s, int lineno,
+                                sv_samplerate_t sampleRate,
                                 int windowSize) const
 {
     QRegExp nonNumericRx("[^0-9eE.,+-]");
@@ -104,7 +105,7 @@
 
     CSVFormat::TimeUnits timeUnits = m_format.getTimeUnits();
 
-    int calculatedFrame = 0;
+    sv_frame_t calculatedFrame = 0;
 
     bool ok = false;
     QString numeric = s;
@@ -114,13 +115,13 @@
 
         double time = numeric.toDouble(&ok);
         if (!ok) time = StringBits::stringToDoubleLocaleFree(numeric, &ok);
-        calculatedFrame = int(time * sampleRate + 0.5);
+        calculatedFrame = sv_frame_t(time * sampleRate + 0.5);
     
     } else if (timeUnits == CSVFormat::TimeMilliseconds) {
 
         double time = numeric.toDouble(&ok);
         if (!ok) time = StringBits::stringToDoubleLocaleFree(numeric, &ok);
-        calculatedFrame = int((time / 1000.0) * sampleRate + 0.5);
+        calculatedFrame = sv_frame_t((time / 1000.0) * sampleRate + 0.5);
         
     } else {
         
@@ -155,7 +156,7 @@
     CSVFormat::ModelType modelType = m_format.getModelType();
     CSVFormat::TimingType timingType = m_format.getTimingType();
     CSVFormat::TimeUnits timeUnits = m_format.getTimeUnits();
-    int sampleRate = m_format.getSampleRate();
+    sv_samplerate_t sampleRate = m_format.getSampleRate();
     int windowSize = m_format.getWindowSize();
     QChar separator = m_format.getSeparator();
     bool allowQuoting = m_format.getAllowQuoting();
@@ -189,15 +190,15 @@
 
     float min = 0.0, max = 0.0;
 
-    int frameNo = 0;
-    int duration = 0;
-    int endFrame = 0;
+    sv_frame_t frameNo = 0;
+    sv_frame_t duration = 0;
+    sv_frame_t endFrame = 0;
 
     bool haveAnyValue = false;
     bool haveEndTime = false;
     bool pitchLooksLikeMIDI = true;
 
-    int startFrame = 0; // for calculation of dense model resolution
+    sv_frame_t startFrame = 0; // for calculation of dense model resolution
     bool firstEverValue = true;
 
     std::map<QString, int> labelCountMap;
@@ -373,7 +374,7 @@
                         model3->setStartFrame(startFrame);
                     } else if (lineno == 1 &&
                                timingType == CSVFormat::ExplicitTiming) {
-                        model3->setResolution(frameNo - startFrame);
+                        model3->setResolution(int(frameNo - startFrame));
                     }
                     
                     firstEverValue = false;
--- a/data/fileio/CSVFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/CSVFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -20,6 +20,8 @@
 
 #include "CSVFormat.h"
 
+#include "base/BaseTypes.h"
+
 #include <QList>
 #include <QStringList>
 
@@ -32,7 +34,7 @@
      * Construct a CSVFileReader to read the CSV file at the given
      * path, with the given format.
      */
-    CSVFileReader(QString path, CSVFormat format, int mainModelSampleRate);
+    CSVFileReader(QString path, CSVFormat format, sv_samplerate_t mainModelSampleRate);
 
     /**
      * Construct a CSVFileReader to read from the given
@@ -40,7 +42,7 @@
      * CSVFileReader will not close or delete it and it must outlive
      * the CSVFileReader.
      */
-    CSVFileReader(QIODevice *device, CSVFormat format, int mainModelSampleRate);
+    CSVFileReader(QIODevice *device, CSVFormat format, sv_samplerate_t mainModelSampleRate);
 
     virtual ~CSVFileReader();
 
@@ -56,10 +58,10 @@
     QString m_filename;
     QString m_error;
     mutable int m_warnings;
-    int m_mainModelSampleRate;
+    sv_samplerate_t m_mainModelSampleRate;
 
-    int convertTimeValue(QString, int lineno, int sampleRate,
-                            int windowSize) const;
+    sv_frame_t convertTimeValue(QString, int lineno, sv_samplerate_t sampleRate,
+                                int windowSize) const;
 };
 
 
--- a/data/fileio/CSVFileWriter.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/CSVFileWriter.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -95,7 +95,7 @@
                  selection->getSelections().begin();
              i != selection->getSelections().end(); ++i) {
 	
-            int f0(i->getStartFrame()), f1(i->getEndFrame());
+            sv_frame_t f0(i->getStartFrame()), f1(i->getEndFrame());
             out << m_model->toDelimitedDataStringSubset(m_delimiter, f0, f1);
         }
 
--- a/data/fileio/CSVFormat.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/CSVFormat.h	Mon Mar 23 11:26:28 2015 +0000
@@ -19,6 +19,8 @@
 #include <QString>
 #include <QStringList>
 
+#include "base/BaseTypes.h"
+
 class CSVFormat
 {
 public:
@@ -88,7 +90,7 @@
     ModelType    getModelType()     const { return m_modelType;     }
     TimingType   getTimingType()    const { return m_timingType;    }
     TimeUnits    getTimeUnits()     const { return m_timeUnits;     }
-    int          getSampleRate()    const { return m_sampleRate;    }
+    sv_samplerate_t getSampleRate() const { return m_sampleRate;    }
     int          getWindowSize()    const { return m_windowSize;    }
     int          getColumnCount()   const { return m_columnCount;   }
     bool         getAllowQuoting()  const { return m_allowQuoting;  }
@@ -101,7 +103,7 @@
     void setTimingType(TimingType t)      { m_timingType   = t; }
     void setTimeUnits(TimeUnits t)        { m_timeUnits    = t; }
     void setSeparator(QChar s)            { m_separator    = s; }
-    void setSampleRate(int r)             { m_sampleRate   = r; }
+    void setSampleRate(sv_samplerate_t r) { m_sampleRate   = r; }
     void setWindowSize(int s)             { m_windowSize   = s; }
     void setColumnCount(int c)            { m_columnCount  = c; }
     void setAllowQuoting(bool q)          { m_allowQuoting = q; }
@@ -125,7 +127,7 @@
     TimingType   m_timingType;
     TimeUnits    m_timeUnits;
     QString      m_separator;
-    int          m_sampleRate;
+    sv_samplerate_t m_sampleRate;
     int          m_windowSize;
 
     int          m_columnCount;
--- a/data/fileio/CodedAudioFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/CodedAudioFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -28,7 +28,7 @@
 #include <QMutexLocker>
 
 CodedAudioFileReader::CodedAudioFileReader(CacheMode cacheMode,
-                                           int targetRate,
+                                           sv_samplerate_t targetRate,
                                            bool normalised) :
     m_cacheMode(cacheMode),
     m_initialised(false),
@@ -113,9 +113,9 @@
         m_resampler = new Resampler(Resampler::FastestTolerable,
                                     m_channelCount,
                                     m_cacheWriteBufferSize);
-        float ratio = float(m_sampleRate) / float(m_fileRate);
+        double ratio = m_sampleRate / m_fileRate;
         m_resampleBuffer = new float
-            [lrintf(ceilf(m_cacheWriteBufferSize * m_channelCount * ratio + 1))];
+            [lrint(ceil(double(m_cacheWriteBufferSize) * m_channelCount * ratio + 1))];
     }
 
     m_cacheWriteBuffer = new float[m_cacheWriteBufferSize * m_channelCount];
@@ -129,9 +129,15 @@
                                            .arg((intptr_t)this));
 
             SF_INFO fileInfo;
-            fileInfo.samplerate = m_sampleRate;
+            int fileRate = int(round(m_sampleRate));
+            if (m_sampleRate != sv_samplerate_t(fileRate)) {
+                cerr << "CodedAudioFileReader: WARNING: Non-integer sample rate "
+                     << m_sampleRate << " presented for writing, rounding to " << fileRate
+                     << endl;
+            }
+            fileInfo.samplerate = fileRate;
             fileInfo.channels = m_channelCount;
-
+            
             // No point in writing 24-bit or float; generally this
             // class is used for decoding files that have come from a
             // 16 bit source or that decode to only 16 bits anyway.
@@ -176,13 +182,13 @@
 }
 
 void
-CodedAudioFileReader::addSamplesToDecodeCache(float **samples, int nframes)
+CodedAudioFileReader::addSamplesToDecodeCache(float **samples, sv_frame_t nframes)
 {
     QMutexLocker locker(&m_cacheMutex);
 
     if (!m_initialised) return;
 
-    for (int i = 0; i < nframes; ++i) {
+    for (sv_frame_t i = 0; i < nframes; ++i) {
         
         for (int c = 0; c < m_channelCount; ++c) {
 
@@ -206,13 +212,13 @@
 }
 
 void
-CodedAudioFileReader::addSamplesToDecodeCache(float *samples, int nframes)
+CodedAudioFileReader::addSamplesToDecodeCache(float *samples, sv_frame_t nframes)
 {
     QMutexLocker locker(&m_cacheMutex);
 
     if (!m_initialised) return;
 
-    for (int i = 0; i < nframes; ++i) {
+    for (sv_frame_t i = 0; i < nframes; ++i) {
         
         for (int c = 0; c < m_channelCount; ++c) {
 
@@ -242,9 +248,7 @@
 
     if (!m_initialised) return;
 
-    for (int i = 0; i < (int)samples.size(); ++i) {
-
-        float sample = samples[i];
+    for (float sample: samples) {
         
         m_cacheWriteBuffer[m_cacheWriteBufferIndex++] = sample;
 
@@ -295,16 +299,16 @@
 }
 
 void
-CodedAudioFileReader::pushBuffer(float *buffer, int sz, bool final)
+CodedAudioFileReader::pushBuffer(float *buffer, sv_frame_t sz, bool final)
 {
     m_fileFrameCount += sz;
 
-    float ratio = 1.f;
+    double ratio = 1.0;
     if (m_resampler && m_fileRate != 0) {
-        ratio = float(m_sampleRate) / float(m_fileRate);
+        ratio = m_sampleRate / m_fileRate;
     }
         
-    if (ratio != 1.f) {
+    if (ratio != 1.0) {
         pushBufferResampling(buffer, sz, ratio, final);
     } else {
         pushBufferNonResampling(buffer, sz);
@@ -312,13 +316,13 @@
 }
 
 void
-CodedAudioFileReader::pushBufferNonResampling(float *buffer, int sz)
+CodedAudioFileReader::pushBufferNonResampling(float *buffer, sv_frame_t sz)
 {
     float clip = 1.0;
-    int count = sz * m_channelCount;
+    sv_frame_t count = sz * m_channelCount;
 
     if (m_normalised) {
-        for (int i = 0; i < count; ++i) {
+        for (sv_frame_t i = 0; i < count; ++i) {
             float v = fabsf(buffer[i]);
             if (v > m_max) {
                 m_max = v;
@@ -326,10 +330,10 @@
             }
         }
     } else {
-        for (int i = 0; i < count; ++i) {
+        for (sv_frame_t i = 0; i < count; ++i) {
             if (buffer[i] >  clip) buffer[i] =  clip;
         }
-        for (int i = 0; i < count; ++i) {
+        for (sv_frame_t i = 0; i < count; ++i) {
             if (buffer[i] < -clip) buffer[i] = -clip;
         }
     }
@@ -339,7 +343,7 @@
     switch (m_cacheMode) {
 
     case CacheInTemporaryFile:
-        if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < (int)sz) {
+        if (sf_writef_float(m_cacheFileWritePtr, buffer, sz) < sz) {
             sf_close(m_cacheFileWritePtr);
             m_cacheFileWritePtr = 0;
             throw InsufficientDiscSpace(TempDirectory::getInstance()->getPath());
@@ -348,24 +352,23 @@
 
     case CacheInMemory:
         m_dataLock.lockForWrite();
-        for (int s = 0; s < count; ++s) {
+        for (sv_frame_t s = 0; s < count; ++s) {
             m_data.push_back(buffer[s]);
         }
-	MUNLOCK_SAMPLEBLOCK(m_data);
         m_dataLock.unlock();
         break;
     }
 }
 
 void
-CodedAudioFileReader::pushBufferResampling(float *buffer, int sz,
-                                           float ratio, bool final)
+CodedAudioFileReader::pushBufferResampling(float *buffer, sv_frame_t sz,
+                                           double ratio, bool final)
 {
     SVDEBUG << "pushBufferResampling: ratio = " << ratio << ", sz = " << sz << ", final = " << final << endl;
 
     if (sz > 0) {
 
-        int out = m_resampler->resampleInterleaved
+        sv_frame_t out = m_resampler->resampleInterleaved
             (buffer,
              m_resampleBuffer,
              sz,
@@ -377,27 +380,27 @@
 
     if (final) {
 
-        int padFrames = 1;
-        if (m_frameCount / ratio < m_fileFrameCount) {
-            padFrames = m_fileFrameCount - (m_frameCount / ratio) + 1;
+        sv_frame_t padFrames = 1;
+        if (double(m_frameCount) / ratio < double(m_fileFrameCount)) {
+            padFrames = m_fileFrameCount - sv_frame_t(double(m_frameCount) / ratio) + 1;
         }
 
-        int padSamples = padFrames * m_channelCount;
+        sv_frame_t padSamples = padFrames * m_channelCount;
 
-        SVDEBUG << "frameCount = " << m_frameCount << ", equivFileFrames = " << m_frameCount / ratio << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << endl;
+        SVDEBUG << "frameCount = " << m_frameCount << ", equivFileFrames = " << double(m_frameCount) / ratio << ", m_fileFrameCount = " << m_fileFrameCount << ", padFrames= " << padFrames << ", padSamples = " << padSamples << endl;
 
         float *padding = new float[padSamples];
-        for (int i = 0; i < padSamples; ++i) padding[i] = 0.f;
+        for (sv_frame_t i = 0; i < padSamples; ++i) padding[i] = 0.f;
 
-        int out = m_resampler->resampleInterleaved
+        sv_frame_t out = m_resampler->resampleInterleaved
             (padding,
              m_resampleBuffer,
              padFrames,
              ratio,
              true);
 
-        if (int(m_frameCount + out) > int(m_fileFrameCount * ratio)) {
-            out = int(m_fileFrameCount * ratio) - int(m_frameCount);
+        if (m_frameCount + out > sv_frame_t(double(m_fileFrameCount) * ratio)) {
+            out = sv_frame_t(double(m_fileFrameCount) * ratio) - m_frameCount;
         }
 
         pushBufferNonResampling(m_resampleBuffer, out);
@@ -405,9 +408,8 @@
     }
 }
 
-void
-CodedAudioFileReader::getInterleavedFrames(int start, int count,
-                                           SampleBlock &frames) const
+SampleBlock
+CodedAudioFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const
 {
     // Lock is only required in CacheInMemory mode (the cache file
     // reader is expected to be thread safe and manage its own
@@ -415,40 +417,44 @@
 
     if (!m_initialised) {
         SVDEBUG << "CodedAudioFileReader::getInterleavedFrames: not initialised" << endl;
-        return;
+        return SampleBlock();
     }
 
+    SampleBlock frames;
+    
     switch (m_cacheMode) {
 
     case CacheInTemporaryFile:
         if (m_cacheFileReader) {
-            m_cacheFileReader->getInterleavedFrames(start, count, frames);
+            frames = m_cacheFileReader->getInterleavedFrames(start, count);
         }
         break;
 
     case CacheInMemory:
     {
-        frames.clear();
-        if (!isOK()) return;
-        if (count == 0) return;
-        frames.reserve(count * m_channelCount);
+        if (!isOK()) return SampleBlock();
+        if (count == 0) return SampleBlock();
 
-        int idx = start * m_channelCount;
-        int i = 0;
+        sv_frame_t idx = start * m_channelCount;
+        sv_frame_t i = 0;
+        sv_frame_t n = count * m_channelCount;
+
+        frames.resize(n);
 
         m_dataLock.lockForRead();
-        while (i < count * m_channelCount && idx < (int)m_data.size()) {
-            frames.push_back(m_data[idx]);
-            ++idx;
+        while (i < n && in_range_for(m_data, idx)) {
+            frames[i++] = m_data[idx++];
         }
         m_dataLock.unlock();
+
+        frames.resize(i);
     }
     }
 
     if (m_normalised) {
-        for (int i = 0; i < (int)(count * m_channelCount); ++i) {
-            frames[i] *= m_gain;
-        }
+        for (auto &f: frames) f *= m_gain;
     }
+
+    return frames;
 }
 
--- a/data/fileio/CodedAudioFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/CodedAudioFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -38,10 +38,9 @@
         CacheInMemory
     };
 
-    virtual void getInterleavedFrames(int start, int count,
-				      SampleBlock &frames) const;
+    virtual SampleBlock getInterleavedFrames(sv_frame_t start, sv_frame_t count) const;
 
-    virtual int getNativeRate() const { return m_fileRate; }
+    virtual sv_samplerate_t getNativeRate() const { return m_fileRate; }
 
     virtual QString getLocalFilename() const { return m_cacheFileName; }
     
@@ -53,14 +52,14 @@
 
 protected:
     CodedAudioFileReader(CacheMode cacheMode, 
-                         int targetRate,
+                         sv_samplerate_t targetRate,
                          bool normalised);
 
     void initialiseDecodeCache(); // samplerate, channels must have been set
 
     // may throw InsufficientDiscSpace:
-    void addSamplesToDecodeCache(float **samples, int nframes);
-    void addSamplesToDecodeCache(float *samplesInterleaved, int nframes);
+    void addSamplesToDecodeCache(float **samples, sv_frame_t nframes);
+    void addSamplesToDecodeCache(float *samplesInterleaved, sv_frame_t nframes);
     void addSamplesToDecodeCache(const SampleBlock &interleaved);
 
     // may throw InsufficientDiscSpace:
@@ -72,9 +71,9 @@
     void endSerialised();
 
 private:
-    void pushBuffer(float *interleaved, int sz, bool final);
-    void pushBufferResampling(float *interleaved, int sz, float ratio, bool final);
-    void pushBufferNonResampling(float *interleaved, int sz);
+    void pushBuffer(float *interleaved, sv_frame_t sz, bool final);
+    void pushBufferResampling(float *interleaved, sv_frame_t sz, double ratio, bool final);
+    void pushBufferNonResampling(float *interleaved, sv_frame_t sz);
 
 protected:
     QMutex m_cacheMutex;
@@ -83,18 +82,18 @@
     mutable QReadWriteLock m_dataLock;
     bool m_initialised;
     Serialiser *m_serialiser;
-    int m_fileRate;
+    sv_samplerate_t m_fileRate;
 
     QString m_cacheFileName;
     SNDFILE *m_cacheFileWritePtr;
     WavFileReader *m_cacheFileReader;
     float *m_cacheWriteBuffer;
-    int m_cacheWriteBufferIndex;
-    int m_cacheWriteBufferSize; // frames
+    sv_frame_t m_cacheWriteBufferIndex;
+    sv_frame_t m_cacheWriteBufferSize; // frames
 
     Resampler *m_resampler;
     float *m_resampleBuffer;
-    int m_fileFrameCount;
+    sv_frame_t m_fileFrameCount;
 
     bool m_normalised;
     float m_max;
--- a/data/fileio/CoreAudioFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/CoreAudioFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -59,7 +59,7 @@
 CoreAudioFileReader::CoreAudioFileReader(FileSource source,
                                          DecodeMode decodeMode,
                                          CacheMode mode,
-                                         int targetRate,
+                                         sv_samplerate_t targetRate,
                                          bool normalised,
                                          ProgressReporter *reporter) :
     CodedAudioFileReader(mode, targetRate, normalised),
--- a/data/fileio/CoreAudioFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/CoreAudioFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -39,7 +39,7 @@
     CoreAudioFileReader(FileSource source,
                         DecodeMode decodeMode,
                         CacheMode cacheMode,
-                        int targetRate = 0,
+                        sv_samplerate_t targetRate = 0,
                         bool normalised = false,
                         ProgressReporter *reporter = 0);
     virtual ~CoreAudioFileReader();
--- a/data/fileio/DataFileReaderFactory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/DataFileReaderFactory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -32,7 +32,7 @@
                                     bool csv,
                                     MIDIFileImportPreferenceAcquirer *acquirer,
                                     CSVFormat format,
-                                    int mainModelSampleRate)
+                                    sv_samplerate_t mainModelSampleRate)
 {
     QString err;
 
@@ -58,7 +58,7 @@
 DataFileReader *
 DataFileReaderFactory::createReader(QString path,
                                     MIDIFileImportPreferenceAcquirer *acquirer,
-                                    int mainModelSampleRate)
+                                    sv_samplerate_t mainModelSampleRate)
 {
     DataFileReader *reader = createReader
         (path, false, acquirer, CSVFormat(), mainModelSampleRate);
@@ -74,7 +74,7 @@
 Model *
 DataFileReaderFactory::load(QString path,
                             MIDIFileImportPreferenceAcquirer *acquirer,
-                            int mainModelSampleRate)
+                            sv_samplerate_t mainModelSampleRate)
 {
     DataFileReader *reader = createReader(path,
                                           acquirer,
@@ -94,7 +94,7 @@
 Model *
 DataFileReaderFactory::loadNonCSV(QString path,
                                   MIDIFileImportPreferenceAcquirer *acquirer,
-                                  int mainModelSampleRate)
+                                  sv_samplerate_t mainModelSampleRate)
 {
     DataFileReader *reader = createReader(path, false,
                                           acquirer,
@@ -114,7 +114,7 @@
 
 Model *
 DataFileReaderFactory::loadCSV(QString path, CSVFormat format,
-                               int mainModelSampleRate)
+                               sv_samplerate_t mainModelSampleRate)
 {
     DataFileReader *reader = createReader(path, true, 0, format,
                                           mainModelSampleRate);
--- a/data/fileio/DataFileReaderFactory.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/DataFileReaderFactory.h	Mon Mar 23 11:26:28 2015 +0000
@@ -48,7 +48,7 @@
      */
     static DataFileReader *createReader(QString path,
                                         MIDIFileImportPreferenceAcquirer *,
-					int mainModelSampleRate);
+					sv_samplerate_t mainModelSampleRate);
 
     /**
      * Read the given path, if a suitable reader is available.
@@ -60,7 +60,7 @@
      */
     static Model *load(QString path,
                        MIDIFileImportPreferenceAcquirer *acquirer,
-                       int mainModelSampleRate);
+                       sv_samplerate_t mainModelSampleRate);
 
     /**
      * Read the given path, if a suitable reader is available.
@@ -69,7 +69,7 @@
      */
     static Model *loadNonCSV(QString path,
                              MIDIFileImportPreferenceAcquirer *acquirer,
-                             int mainModelSampleRate);
+                             sv_samplerate_t mainModelSampleRate);
 
     /**
      * Read the given path using the CSV reader with the given format.
@@ -77,13 +77,13 @@
      */
     static Model *loadCSV(QString path,
                           CSVFormat format,
-                          int mainModelSampleRate);
+                          sv_samplerate_t mainModelSampleRate);
 
 protected:
     static DataFileReader *createReader(QString path, bool csv,
                                         MIDIFileImportPreferenceAcquirer *,
                                         CSVFormat format,
-					int mainModelSampleRate);
+					sv_samplerate_t mainModelSampleRate);
 };
 
 #endif
--- a/data/fileio/DecodingWavFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/DecodingWavFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -24,7 +24,7 @@
 DecodingWavFileReader::DecodingWavFileReader(FileSource source,
                                              ResampleMode resampleMode,
                                              CacheMode mode,
-                                             int targetRate,
+                                             sv_samplerate_t targetRate,
                                              bool normalised,
                                              ProgressReporter *reporter) :
     CodedAudioFileReader(mode, targetRate, normalised),
@@ -64,17 +64,17 @@
                 (tr("Decoding %1...").arg(QFileInfo(m_path).fileName()));
         }
 
-        int blockSize = 16384;
-        int total = m_original->getFrameCount();
+        sv_frame_t blockSize = 16384;
+        sv_frame_t total = m_original->getFrameCount();
 
         SampleBlock block;
 
-        for (int i = 0; i < total; i += blockSize) {
+        for (sv_frame_t i = 0; i < total; i += blockSize) {
 
-            int count = blockSize;
+            sv_frame_t count = blockSize;
             if (i + count > total) count = total - i;
 
-            m_original->getInterleavedFrames(i, count, block);
+            block = m_original->getInterleavedFrames(i, count);
             addBlock(block);
 
             if (m_cancelled) break;
@@ -121,17 +121,17 @@
         m_reader->startSerialised("DecodingWavFileReader::Decode");
     }
 
-    int blockSize = 16384;
-    int total = m_reader->m_original->getFrameCount();
+    sv_frame_t blockSize = 16384;
+    sv_frame_t total = m_reader->m_original->getFrameCount();
     
     SampleBlock block;
     
-    for (int i = 0; i < total; i += blockSize) {
+    for (sv_frame_t i = 0; i < total; i += blockSize) {
         
-        int count = blockSize;
+        sv_frame_t count = blockSize;
         if (i + count > total) count = total - i;
         
-        m_reader->m_original->getInterleavedFrames(i, count, block);
+        block = m_reader->m_original->getInterleavedFrames(i, count);
         m_reader->addBlock(block);
 
         if (m_reader->m_cancelled) break;
@@ -153,10 +153,10 @@
 
     m_processed += frames.size();
 
-    float ratio = float(m_sampleRate) / float(m_fileRate);
+    double ratio = double(m_sampleRate) / double(m_fileRate);
 
-    int progress = lrint((float(m_processed) * ratio * 100) /
-                         float(m_original->getFrameCount()));
+    int progress = int(lrint((double(m_processed) * ratio * 100) /
+                             double(m_original->getFrameCount())));
 
     if (progress > 99) progress = 99;
     m_completion = progress;
--- a/data/fileio/DecodingWavFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/DecodingWavFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -37,7 +37,7 @@
     DecodingWavFileReader(FileSource source,
                           ResampleMode resampleMode,
                           CacheMode cacheMode,
-                          int targetRate = 0,
+                          sv_samplerate_t targetRate = 0,
                           bool normalised = false,
                           ProgressReporter *reporter = 0);
     virtual ~DecodingWavFileReader();
@@ -63,7 +63,7 @@
     QString m_path;
     QString m_error;
     bool m_cancelled;
-    int m_processed;
+    sv_frame_t m_processed;
     int m_completion;
 
     WavFileReader *m_original;
--- a/data/fileio/MIDIFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/MIDIFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -58,7 +58,7 @@
 
 MIDIFileReader::MIDIFileReader(QString path,
                                MIDIFileImportPreferenceAcquirer *acquirer,
-			       int mainModelSampleRate) :
+			       sv_samplerate_t mainModelSampleRate) :
     m_smpte(false),
     m_timingDivision(0),
     m_fps(0),
@@ -301,7 +301,9 @@
 	// Set file size so we can count it off
 	//
 	m_midiFile->seekg(0, ios::end);
-	m_fileSize = m_midiFile->tellg();
+        std::streamoff off = m_midiFile->tellg();
+	m_fileSize = 0;
+        if (off > 0) m_fileSize = off;
 	m_midiFile->seekg(0, ios::beg);
 
 	// Parse the MIDI header first.  The first 14 bytes of the file.
@@ -440,9 +442,9 @@
     MIDIByte midiByte, metaEventCode, data1, data2;
     MIDIByte eventCode = 0x80;
     string metaMessage;
-    unsigned int messageLength;
-    unsigned long deltaTime;
-    unsigned long accumulatedTime = 0;
+    long messageLength;
+    long deltaTime;
+    long accumulatedTime = 0;
 
     // The trackNum passed in to this method is the default track for
     // all events provided they're all on the same channel.  If we find
@@ -890,7 +892,7 @@
 
     if (tracksToLoad.empty()) return 0;
 
-    int n = tracksToLoad.size(), count = 0;
+    int n = int(tracksToLoad.size()), count = 0;
     Model *model = 0;
 
     for (std::set<unsigned int>::iterator i = tracksToLoad.begin();
@@ -938,7 +940,7 @@
 
     const MIDITrack &track = m_midiComposition.find(trackToLoad)->second;
 
-    int totalEvents = track.size();
+    int totalEvents = int(track.size());
     int count = 0;
 
     bool sharpKey = true;
--- a/data/fileio/MIDIFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/MIDIFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -62,7 +62,7 @@
 public:
     MIDIFileReader(QString path,
                    MIDIFileImportPreferenceAcquirer *pref,
-                   int mainModelSampleRate);
+                   sv_samplerate_t mainModelSampleRate);
     virtual ~MIDIFileReader();
 
     virtual bool isOK() const;
@@ -126,9 +126,9 @@
 
     QString                m_path;
     std::ifstream         *m_midiFile;
-    int                    m_fileSize;
+    size_t                 m_fileSize;
     QString                m_error;
-    int                    m_mainModelSampleRate;
+    sv_samplerate_t        m_mainModelSampleRate;
 
     MIDIFileImportPreferenceAcquirer *m_acquirer;
 };
--- a/data/fileio/MIDIFileWriter.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/MIDIFileWriter.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -37,7 +37,7 @@
 using namespace MIDIConstants;
 
 MIDIFileWriter::MIDIFileWriter(QString path, const NoteExportable *exportable,
-                               int sampleRate, float tempo) :
+                               sv_samplerate_t sampleRate, float tempo) :
     m_path(path),
     m_exportable(exportable),
     m_sampleRate(sampleRate),
@@ -89,8 +89,8 @@
     MIDIByte upper;
     MIDIByte lower;
 
-    upper = (number & 0xFF00) >> 8;
-    lower = (number & 0x00FF);
+    upper = MIDIByte((number & 0xFF00) >> 8);
+    lower = MIDIByte( number & 0x00FF);
 
     string rv;
     rv += upper;
@@ -106,10 +106,10 @@
     MIDIByte upper2;
     MIDIByte lower2;
 
-    upper1 = (number & 0xff000000) >> 24;
-    lower1 = (number & 0x00ff0000) >> 16;
-    upper2 = (number & 0x0000ff00) >> 8;
-    lower2 = (number & 0x000000ff);
+    upper1 = MIDIByte((number & 0xff000000) >> 24);
+    lower1 = MIDIByte((number & 0x00ff0000) >> 16);
+    upper2 = MIDIByte((number & 0x0000ff00) >> 8);
+    lower2 = MIDIByte((number & 0x000000ff));
 
     string rv;
     rv += upper1;
@@ -344,8 +344,8 @@
 
     for (NoteList::const_iterator i = notes.begin(); i != notes.end(); ++i) {
 
-        int frame = i->start;
-        int duration = i->duration;
+        sv_frame_t frame = i->start;
+        sv_frame_t duration = i->duration;
         int pitch = i->midiPitch;
         int velocity = i->velocity;
         int channel = i->channel;
@@ -358,12 +358,12 @@
 
         // Convert frame to MIDI time
 
-        double seconds = double(frame) / double(m_sampleRate);
+        double seconds = double(frame) / m_sampleRate;
         double quarters = (seconds * m_tempo) / 60.0;
         unsigned long midiTime = int(quarters * m_timingDivision + 0.5);
 
         // Get the sounding time for the matching NOTE_OFF
-        seconds = double(frame + duration) / double(m_sampleRate);
+        seconds = double(frame + duration) / m_sampleRate;
         quarters = (seconds * m_tempo) / 60.0;
         unsigned long endTime = int(quarters * m_timingDivision + 0.5);
 
--- a/data/fileio/MIDIFileWriter.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/MIDIFileWriter.h	Mon Mar 23 11:26:28 2015 +0000
@@ -24,6 +24,7 @@
 #define _MIDI_FILE_WRITER_H_
 
 #include "base/RealTime.h"
+#include "base/BaseTypes.h"
 
 #include <QString>
 
@@ -45,7 +46,7 @@
 public:
     MIDIFileWriter(QString path, 
                    const NoteExportable *exportable, 
-                   int sampleRate, // used to convert exportable sample timings
+                   sv_samplerate_t sampleRate, // used to convert exportable sample timings
                    float tempo = 120.f);
     virtual ~MIDIFileWriter();
 
@@ -79,7 +80,7 @@
 
     QString               m_path;
     const NoteExportable *m_exportable;
-    int                   m_sampleRate;
+    sv_samplerate_t       m_sampleRate;
     float                 m_tempo;
     int                   m_timingDivision;   // pulses per quarter note
     MIDIFileFormatType    m_format;
--- a/data/fileio/MP3FileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/MP3FileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -37,7 +37,7 @@
 #include <QFileInfo>
 
 MP3FileReader::MP3FileReader(FileSource source, DecodeMode decodeMode, 
-                             CacheMode mode, int targetRate,
+                             CacheMode mode, sv_samplerate_t targetRate,
                              bool normalised,
                              ProgressReporter *reporter) :
     CodedAudioFileReader(mode, targetRate, normalised),
@@ -86,7 +86,7 @@
     }
     
     ssize_t sz = 0;
-    int offset = 0;
+    ssize_t offset = 0;
     while (offset < m_fileSize) {
         sz = ::read(fd, m_filebuffer + offset, m_fileSize - offset);
         if (sz < 0) {
@@ -291,7 +291,7 @@
 } 
 
 bool
-MP3FileReader::decode(void *mm, int sz)
+MP3FileReader::decode(void *mm, sv_frame_t sz)
 {
     DecoderData data;
     struct mad_decoder decoder;
@@ -320,7 +320,7 @@
 
 #ifdef HAVE_ID3TAG
     if (length > ID3_TAG_QUERYSIZE) {
-        int taglen = id3_tag_query(start, ID3_TAG_QUERYSIZE);
+        ssize_t taglen = id3_tag_query(start, ID3_TAG_QUERYSIZE);
         if (taglen > 0) {
 //            cerr << "ID3 tag length to skip: " << taglen << endl;
             start += taglen;
@@ -352,7 +352,7 @@
     int frames = pcm->length;
 
     if (header) {
-        m_bitrateNum += header->bitrate;
+        m_bitrateNum = m_bitrateNum + double(header->bitrate);
         m_bitrateDenom ++;
     }
 
--- a/data/fileio/MP3FileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/MP3FileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -40,7 +40,7 @@
     MP3FileReader(FileSource source,
                   DecodeMode decodeMode,
                   CacheMode cacheMode,
-                  int targetRate = 0,
+                  sv_samplerate_t targetRate = 0,
                   bool normalised = false,
                   ProgressReporter *reporter = 0);
     virtual ~MP3FileReader();
@@ -73,7 +73,7 @@
     QString m_title;
     QString m_maker;
     TagMap m_tags;
-    int m_fileSize;
+    sv_frame_t m_fileSize;
     double m_bitrateNum;
     int m_bitrateDenom;
     int m_completion;
@@ -93,7 +93,7 @@
 	MP3FileReader *reader;
     };
 
-    bool decode(void *mm, int sz);
+    bool decode(void *mm, sv_frame_t sz);
     enum mad_flow accept(struct mad_header const *, struct mad_pcm *);
 
     static enum mad_flow input(void *, struct mad_stream *);
--- a/data/fileio/MatchFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,187 +0,0 @@
-/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
-
-/*
-    Sonic Visualiser
-    An audio file viewer and annotation editor.
-    Centre for Digital Music, Queen Mary, University of London.
-    This file copyright 2007 QMUL.
-    
-    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.  See the file
-    COPYING included with this distribution for more information.
-*/
-
-#include "MatchFileReader.h"
-
-#include <QFile>
-#include <QTextStream>
-
-#include <cmath>
-#include <iostream>
-
-Alignment::Alignment() :
-    thisHopTime(0.0),
-    refHopTime(0.0),
-    m_mainModel(0)
-{
-}
-
-double
-Alignment::fromReference(double t) const
-{
-    int ri = lrint(t / refHopTime);
-    int index = search(refIndex, ri);
-    return thisIndex[index] * thisHopTime;
-}
-
-double
-Alignment::toReference(double t) const
-{
-    int ti = lrint(t / thisHopTime);
-    int index = search(thisIndex, ti);
-    return refIndex[index] * refHopTime;
-}
-
-int
-Alignment::search(const FrameArray &arr, int val) const
-{
-    int len = arr.size();
-    int max = len - 1;
-    int min = 0;
-    while (max > min) {
-        int mid = (max + min) / 2;
-        if (val > arr[mid]) {
-            min = mid + 1;
-        } else {
-            max = mid;
-        }
-    } // max = MIN_j (arr[j] >= val)   i.e. the first equal or next highest
-    while ((max + 1 < len) && (arr[max + 1] == val)) {
-        max++;
-    }
-    return (min + max) / 2;
-}
-
-MatchFileReader::MatchFileReader(QString path) :
-    m_file(0)
-{
-    m_file = new QFile(path);
-    bool good = false;
-    
-    if (!m_file->exists()) {
-	m_error = QFile::tr("File \"%1\" does not exist").arg(path);
-    } else if (!m_file->open(QIODevice::ReadOnly | QIODevice::Text)) {
-	m_error = QFile::tr("Failed to open file \"%1\"").arg(path);
-    } else {
-	good = true;
-    }
-
-    if (!good) {
-	delete m_file;
-	m_file = 0;
-    }
-}
-
-MatchFileReader::~MatchFileReader()
-{
-    if (m_file) {
-        SVDEBUG << "MatchFileReader::MatchFileReader: Closing file" << endl;
-        m_file->close();
-    }
-    delete m_file;
-}
-
-bool
-MatchFileReader::isOK() const
-{
-    return (m_file != 0);
-}
-
-QString
-MatchFileReader::getError() const
-{
-    return m_error;
-}
-
-Alignment
-MatchFileReader::load() const
-{
-    Alignment alignment;
-
-    if (!m_file) return alignment;
-
-    QTextStream in(m_file);
-
-/*
-File: /home/studio/match-test/mahler-3-boulez-5.wav
-Marks: -1
-FixedPoints: true 0
-0
-0
-0
-0
-File: /home/studio/match-test/mahler-3-haitink-5.wav
-Marks: 0
-FixedPoints: true 0
-0.02
-0.02
-12836
-*/
-
-    int fileCount = 0;
-    int state = 0;
-    int count = 0;
-
-    while (!in.atEnd()) {
-
-        QString line = in.readLine().trimmed();
-        if (line.startsWith("File: ")) {
-            ++fileCount;
-            continue;
-        }
-        if (fileCount != 2) continue;
-        if (line.startsWith("Marks:") || line.startsWith("FixedPoints:")) {
-            continue;
-        }
-
-        switch (state) {
-        case 0:
-            alignment.thisHopTime = line.toDouble();
-            break;
-        case 1:
-            alignment.refHopTime = line.toDouble();
-            break;
-        case 2: 
-            count = line.toInt();
-            break;
-        case 3:
-            alignment.thisIndex.push_back(line.toInt());
-            break;
-        case 4:
-            alignment.refIndex.push_back(line.toInt());
-            break;
-        }
-
-        if (state < 3) {
-            ++state;
-        } else if (state == 3 && int(alignment.thisIndex.size()) == count) {
-            ++state;
-        }
-    }
-
-    if (alignment.thisHopTime == 0.0) {
-        cerr << "ERROR in Match file: this hop time == 0, using 0.01 instead" << endl;
-        alignment.thisHopTime = 0.01;
-    }
-
-    if (alignment.refHopTime == 0.0) {
-        cerr << "ERROR in Match file: ref hop time == 0, using 0.01 instead" << endl;
-        alignment.refHopTime = 0.01;
-    }
-
-    cerr << "MatchFileReader: this hop = " << alignment.thisHopTime << ", ref hop = " << alignment.refHopTime << ", this index count = " << alignment.thisIndex.size() << ", ref index count = " << alignment.refIndex.size() << endl;
-
-    return alignment;
-}
--- a/data/fileio/MatchFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,68 +0,0 @@
-/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
-
-/*
-    Sonic Visualiser
-    An audio file viewer and annotation editor.
-    Centre for Digital Music, Queen Mary, University of London.
-    This file copyright 2007 QMUL.
-    
-    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.  See the file
-    COPYING included with this distribution for more information.
-*/
-
-#ifndef _MATCH_FILE_READER_H_
-#define _MATCH_FILE_READER_H_
-
-#include <vector>
-#include <QString>
-#include "base/Debug.h"
-
-class QFile;
-class Model;
-
-class Alignment
-{
-public:
-    Alignment();
-
-    typedef std::vector<int> FrameArray;
-
-    double thisHopTime;
-    double refHopTime;
-
-    FrameArray thisIndex;
-    FrameArray refIndex;
-
-    double fromReference(double) const;
-    double toReference(double) const;
-
-    //!!! blah
-    void setMainModel(Model *m) { m_mainModel = m; }
-    bool isMainModel(Model *m) const { return m == m_mainModel; }
-
-    int search(const FrameArray &arr, int val) const;
-
-protected:
-    Model *m_mainModel;
-};
-
-class MatchFileReader
-{
-public:
-    MatchFileReader(QString path);
-    virtual ~MatchFileReader();
-
-    virtual bool isOK() const;
-    virtual QString getError() const;
-    virtual Alignment load() const;
-
-protected:
-    QFile *m_file;
-    QString m_error;
-};
-
-#endif
-
--- a/data/fileio/OggVorbisFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/OggVorbisFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -34,7 +34,7 @@
 OggVorbisFileReader::OggVorbisFileReader(FileSource source,
                                          DecodeMode decodeMode,
                                          CacheMode mode,
-                                         int targetRate,
+                                         sv_samplerate_t targetRate,
                                          bool normalised,
                                          ProgressReporter *reporter) :
     CodedAudioFileReader(mode, targetRate, normalised),
@@ -144,15 +144,15 @@
     OggVorbisFileReader *reader = (OggVorbisFileReader *)data;
     FishSound *fs = reader->m_fishSound;
 
-    fish_sound_prepare_truncation(fs, packet->granulepos, packet->e_o_s);
+    fish_sound_prepare_truncation(fs, packet->granulepos, int(packet->e_o_s));
     fish_sound_decode(fs, packet->packet, packet->bytes);
 
     reader->m_bytesRead += packet->bytes;
 
     // The number of bytes read by this function is smaller than
     // the file size because of the packet headers
-    int p = lrint(double(reader->m_bytesRead) * 114 /
-                  double(reader->m_fileSize));
+    int p = int(lrint(double(reader->m_bytesRead) * 114 /
+                      double(reader->m_fileSize)));
     if (p > 99) p = 99;
     reader->m_completion = p;
     reader->progress(p);
--- a/data/fileio/OggVorbisFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/OggVorbisFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -42,7 +42,7 @@
     OggVorbisFileReader(FileSource source,
                         DecodeMode decodeMode,
                         CacheMode cacheMode,
-                        int targetRate = 0,
+                        sv_samplerate_t targetRate = 0,
                         bool normalised = false,
                         ProgressReporter *reporter = 0);
     virtual ~OggVorbisFileReader();
@@ -79,8 +79,8 @@
     OGGZ *m_oggz;
     FishSound *m_fishSound;
     ProgressReporter *m_reporter;
-    int m_fileSize;
-    int m_bytesRead;
+    sv_frame_t m_fileSize;
+    sv_frame_t m_bytesRead;
     bool m_commentsRead;
     bool m_cancelled;
     int m_completion;
--- a/data/fileio/QuickTimeFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/QuickTimeFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -50,7 +50,7 @@
 QuickTimeFileReader::QuickTimeFileReader(FileSource source,
                                          DecodeMode decodeMode,
                                          CacheMode mode,
-                                         int targetRate,
+                                         sv_samplerate_t targetRate,
                                          bool normalised,
                                          ProgressReporter *reporter) :
     CodedAudioFileReader(mode, targetRate, normalised),
--- a/data/fileio/QuickTimeFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/QuickTimeFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -42,7 +42,7 @@
     QuickTimeFileReader(FileSource source,
                         DecodeMode decodeMode,
                         CacheMode cacheMode,
-                        int targetRate = 0,
+                        sv_samplerate_t targetRate = 0,
                         bool normalised = false,
                         ProgressReporter *reporter = 0);
     virtual ~QuickTimeFileReader();
--- a/data/fileio/WavFileReader.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/WavFileReader.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -25,8 +25,6 @@
     m_source(source),
     m_path(source.getLocalFilename()),
     m_seekable(false),
-    m_buffer(0),
-    m_bufsiz(0),
     m_lastStart(0),
     m_lastCount(0),
     m_updating(fileUpdating)
@@ -81,7 +79,6 @@
 WavFileReader::~WavFileReader()
 {
     if (m_file) sf_close(m_file);
-    delete[] m_buffer;
 }
 
 void
@@ -89,7 +86,7 @@
 {
     QMutexLocker locker(&m_mutex);
 
-    int prevCount = m_fileInfo.frames;
+    sv_frame_t prevCount = m_fileInfo.frames;
 
     if (m_file) {
         sf_close(m_file);
@@ -122,65 +119,49 @@
     m_updating = false;
 }
 
-void
-WavFileReader::getInterleavedFrames(int start, int count,
-				    SampleBlock &results) const
+SampleBlock
+WavFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const
 {
-    if (count == 0) return;
-    results.clear();
-    results.reserve(count * m_fileInfo.channels);
+    if (count == 0) return SampleBlock();
 
     QMutexLocker locker(&m_mutex);
 
     if (!m_file || !m_channelCount) {
-        return;
+        return SampleBlock();
     }
 
-    if ((long)start >= m_fileInfo.frames) {
+    if (start >= m_fileInfo.frames) {
 //        SVDEBUG << "WavFileReader::getInterleavedFrames: " << start
 //                  << " > " << m_fileInfo.frames << endl;
-	return;
+	return SampleBlock();
     }
 
-    if (long(start + count) > m_fileInfo.frames) {
+    if (start + count > m_fileInfo.frames) {
 	count = m_fileInfo.frames - start;
     }
 
-    sf_count_t readCount = 0;
-
     if (start != m_lastStart || count != m_lastCount) {
 
 	if (sf_seek(m_file, start, SEEK_SET) < 0) {
-//            cerr << "sf_seek failed" << endl;
-	    return;
-	}
-	
-	if (count * m_fileInfo.channels > m_bufsiz) {
-//	    cerr << "WavFileReader: Reallocating buffer for " << count
-//		      << " frames, " << m_fileInfo.channels << " channels: "
-//		      << m_bufsiz << " floats" << endl;
-	    m_bufsiz = count * m_fileInfo.channels;
-	    delete[] m_buffer;
-	    m_buffer = new float[m_bufsiz];
-	}
-	
-	if ((readCount = sf_readf_float(m_file, m_buffer, count)) < 0) {
-//            cerr << "sf_readf_float failed" << endl;
-	    return;
+	    return SampleBlock();
 	}
 
+        sv_frame_t n = count * m_fileInfo.channels;
+        m_buffer.resize(n);
+	
+        sf_count_t readCount = 0;
+
+	if ((readCount = sf_readf_float(m_file, m_buffer.data(), count)) < 0) {
+	    return SampleBlock();
+	}
+
+        m_buffer.resize(readCount * m_fileInfo.channels);
+        
 	m_lastStart = start;
 	m_lastCount = readCount;
     }
 
-    for (int i = 0; i < count * m_fileInfo.channels; ++i) {
-        if (i >= m_bufsiz) {
-            cerr << "INTERNAL ERROR: WavFileReader::getInterleavedFrames: " << i << " >= " << m_bufsiz << endl;
-        }
-	results.push_back(m_buffer[i]);
-    }
-
-    return;
+    return m_buffer;
 }
 
 void
--- a/data/fileio/WavFileReader.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/WavFileReader.h	Mon Mar 23 11:26:28 2015 +0000
@@ -50,8 +50,7 @@
      * Must be safe to call from multiple threads with different
      * arguments on the same object at the same time.
      */
-    virtual void getInterleavedFrames(int start, int count,
-				      SampleBlock &frames) const;
+    virtual SampleBlock getInterleavedFrames(sv_frame_t start, sv_frame_t count) const;
     
     static void getSupportedExtensions(std::set<QString> &extensions);
     static bool supportsExtension(QString ext);
@@ -76,10 +75,10 @@
     bool m_seekable;
 
     mutable QMutex m_mutex;
-    mutable float *m_buffer;
-    mutable int m_bufsiz;
-    mutable int m_lastStart;
-    mutable int m_lastCount;
+    mutable SampleBlock m_buffer;
+    mutable sv_frame_t m_bufsiz;
+    mutable sv_frame_t m_lastStart;
+    mutable sv_frame_t m_lastCount;
 
     bool m_updating;
 };
--- a/data/fileio/WavFileWriter.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/WavFileWriter.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -23,9 +23,10 @@
 #include <QFileInfo>
 
 #include <iostream>
+#include <cmath>
 
 WavFileWriter::WavFileWriter(QString path,
-			     int sampleRate,
+			     sv_samplerate_t sampleRate,
                              int channels,
                              FileWriteMode mode) :
     m_path(path),
@@ -35,7 +36,14 @@
     m_file(0)
 {
     SF_INFO fileInfo;
-    fileInfo.samplerate = m_sampleRate;
+
+    int fileRate = int(round(m_sampleRate));
+    if (m_sampleRate != sv_samplerate_t(fileRate)) {
+        cerr << "WavFileWriter: WARNING: Non-integer sample rate "
+             << m_sampleRate << " presented, rounding to " << fileRate
+             << endl;
+    }
+    fileInfo.samplerate = fileRate;
     fileInfo.channels = m_channels;
     fileInfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
 
@@ -120,7 +128,7 @@
         ownSelection = true;
     }
 
-    int bs = 2048;
+    sv_frame_t bs = 2048;
     float *ub = new float[bs]; // uninterleaved buffer (one channel)
     float *ib = new float[bs * m_channels]; // interleaved buffer
 
@@ -128,11 +136,11 @@
 	     selection->getSelections().begin();
 	 i != selection->getSelections().end(); ++i) {
 	
-	int f0(i->getStartFrame()), f1(i->getEndFrame());
+	sv_frame_t f0(i->getStartFrame()), f1(i->getEndFrame());
 
-	for (int f = f0; f < f1; f += bs) {
+	for (sv_frame_t f = f0; f < f1; f += bs) {
 	    
-	    int n = std::min(bs, f1 - f);
+	    sv_frame_t n = std::min(bs, f1 - f);
 
 	    for (int c = 0; c < int(m_channels); ++c) {
 		source->getData(c, f, n, ub);
@@ -159,7 +167,7 @@
 }
 	
 bool
-WavFileWriter::writeSamples(float **samples, int count)
+WavFileWriter::writeSamples(float **samples, sv_frame_t count)
 {
     if (!m_file) {
         m_error = QString("Failed to write model to audio file '%1': File not open")
@@ -168,17 +176,17 @@
     }
 
     float *b = new float[count * m_channels];
-    for (int i = 0; i < int(count); ++i) {
+    for (sv_frame_t i = 0; i < count; ++i) {
         for (int c = 0; c < int(m_channels); ++c) {
             b[i * m_channels + c] = samples[c][i];
         }
     }
 
-    sf_count_t written = sf_writef_float(m_file, b, count);
+    sv_frame_t written = sf_writef_float(m_file, b, count);
 
     delete[] b;
 
-    if (written < int(count)) {
+    if (written < count) {
         m_error = QString("Only wrote %1 of %2 frames")
             .arg(written).arg(count);
     }
--- a/data/fileio/WavFileWriter.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/WavFileWriter.h	Mon Mar 23 11:26:28 2015 +0000
@@ -20,6 +20,8 @@
 
 #include <sndfile.h>
 
+#include "base/BaseTypes.h"
+
 class DenseTimeValueModel;
 class MultiSelection;
 class TempWriteFile;
@@ -44,7 +46,7 @@
         WriteToTarget
     };
 
-    WavFileWriter(QString path, int sampleRate, int channels,
+    WavFileWriter(QString path, sv_samplerate_t sampleRate, int channels,
                   FileWriteMode mode);
     virtual ~WavFileWriter();
 
@@ -57,13 +59,13 @@
     bool writeModel(DenseTimeValueModel *source,
                     MultiSelection *selection = 0);
 
-    bool writeSamples(float **samples, int count); // count per channel
+    bool writeSamples(float **samples, sv_frame_t count); // count per channel
 
     bool close();
 
 protected:
     QString m_path;
-    int m_sampleRate;
+    sv_samplerate_t m_sampleRate;
     int m_channels;
     TempWriteFile *m_temp;
     SNDFILE *m_file;
--- a/data/fileio/test/AudioFileReaderTest.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/test/AudioFileReaderTest.h	Mon Mar 23 11:26:28 2015 +0000
@@ -63,7 +63,7 @@
     {
         QFETCH(QString, audiofile);
 
-        int readRate = 48000;
+        sv_samplerate_t readRate = 48000;
 
 	AudioFileReader *reader =
 	    AudioFileReaderFactory::createReader
@@ -72,7 +72,7 @@
         QStringList fileAndExt = audiofile.split(".");
         QStringList bits = fileAndExt[0].split("-");
         QString extension = fileAndExt[1];
-        int nominalRate = bits[0].toInt();
+        sv_samplerate_t nominalRate = bits[0].toInt();
         int nominalChannels = bits[1].toInt();
         int nominalDepth = 16;
         if (bits.length() > 2) nominalDepth = bits[2].toInt();
@@ -86,24 +86,22 @@
 	}
 
         QCOMPARE((int)reader->getChannelCount(), nominalChannels);
-        QCOMPARE((int)reader->getNativeRate(), nominalRate);
-        QCOMPARE((int)reader->getSampleRate(), readRate);
+        QCOMPARE(reader->getNativeRate(), nominalRate);
+        QCOMPARE(reader->getSampleRate(), readRate);
 
 	int channels = reader->getChannelCount();
 	AudioTestData tdata(readRate, channels);
 	
 	float *reference = tdata.getInterleavedData();
-        int refFrames = tdata.getFrameCount();
-	
-	vector<float> test;
+        sv_frame_t refFrames = tdata.getFrameCount();
 	
 	// The reader should give us exactly the expected number of
 	// frames, except for mp3/aac files. We ask for quite a lot
 	// more, though, so we can (a) check that we only get the
 	// expected number back (if this is not mp3/aac) or (b) take
 	// into account silence at beginning and end (if it is).
-	reader->getInterleavedFrames(0, refFrames + 5000, test);
-	int read = test.size() / channels;
+	vector<float> test = reader->getInterleavedFrames(0, refFrames + 5000);
+	sv_frame_t read = test.size() / channels;
 
         if (extension == "mp3" || extension == "aac" || extension == "m4a") {
             // mp3s and aacs can have silence at start and end
@@ -116,8 +114,8 @@
         // or resampler quality here, just whether the results are
         // plainly wrong (e.g. at wrong samplerate or with an offset)
 
-	float limit = 0.01;
-        float edgeLimit = limit * 10; // in first or final edgeSize frames
+	double limit = 0.01;
+        double edgeLimit = limit * 10; // in first or final edgeSize frames
         int edgeSize = 100; 
 
         if (nominalDepth < 16) {
@@ -130,23 +128,23 @@
         }
 
         // And we ignore completely the last few frames when upsampling
-        int discard = 1 + readRate / nominalRate;
+        int discard = 1 + int(round(readRate / nominalRate));
 
         int offset = 0;
 
         if (extension == "aac" || extension == "m4a") {
             // our m4a file appears to have a fixed offset of 1024 (at
             // file sample rate)
-            offset = (1024 / float(nominalRate)) * readRate;
+            offset = int(round((1024 / nominalRate) * readRate));
         }
 
         if (extension == "mp3") {
             // while mp3s appear to vary
             for (int i = 0; i < read; ++i) {
                 bool any = false;
-                float thresh = 0.01;
+                double thresh = 0.01;
                 for (int c = 0; c < channels; ++c) {
-                    if (fabsf(test[i * channels + c]) > thresh) {
+                    if (fabs(test[i * channels + c]) > thresh) {
                         any = true;
                         break;
                     }
@@ -180,7 +178,7 @@
                     }
 		}
 	    }
-	    float meandiff = totdiff / read;
+	    float meandiff = totdiff / float(read);
 //	    cerr << "meandiff on channel " << c << ": " << meandiff << endl;
 //	    cerr << "maxdiff on channel " << c << ": " << maxdiff << " at " << maxAt << endl;
             if (meandiff >= limit) {
--- a/data/fileio/test/AudioTestData.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/test/AudioTestData.h	Mon Mar 23 11:26:28 2015 +0000
@@ -18,6 +18,8 @@
 
 #include <cmath>
 
+#include "base/BaseTypes.h"
+
 /**
  * Class that generates a single fixed test pattern to a given sample
  * rate and number of channels.
@@ -35,7 +37,7 @@
 class AudioTestData
 {
 public:
-    AudioTestData(float rate, int channels) :
+    AudioTestData(double rate, int channels) :
 	m_channelCount(channels),
 	m_duration(2.0),
 	m_sampleRate(rate),
@@ -54,24 +56,25 @@
 
     void generate() {
 
-	float hpw = m_pulseWidth / 2.0;
+	double hpw = m_pulseWidth / 2.0;
 
 	for (int i = 0; i < m_frameCount; ++i) {
 	    for (int c = 0; c < m_channelCount; ++c) {
 
-		float s = 0.f;
+		double s = 0.0;
 
 		if (c == 0) {
 
-		    float phase = (i * m_sinFreq * 2.f * M_PI) / m_sampleRate;
-		    s = sinf(phase);
+		    double phase = (i * m_sinFreq * 2.0 * M_PI) / m_sampleRate;
+		    s = sin(phase);
 
 		} else if (c == 1) {
 
 		    int pulseNo = int((i * m_pulseFreq) / m_sampleRate);
-		    int index = (i * m_pulseFreq) - (m_sampleRate * pulseNo);
+		    int index = int(round((i * m_pulseFreq) -
+                                          (m_sampleRate * pulseNo)));
 		    if (index < m_pulseWidth) {
-			s = 1.0 - fabsf(hpw - index) / hpw;
+			s = 1.0 - fabs(hpw - index) / hpw;
 			if (pulseNo % 2) s = -s;
 		    }
 
@@ -80,7 +83,7 @@
 		    s = c / 20.0;
 		}
 
-		m_data[i * m_channelCount + c] = s;
+		m_data[i * m_channelCount + c] = float(s);
 	    }
 	}
     }
@@ -89,7 +92,7 @@
 	return m_data;
     }
 
-    int getFrameCount() const { 
+    sv_frame_t getFrameCount() const { 
 	return m_frameCount;
     }
 
@@ -97,23 +100,23 @@
 	return m_channelCount;
     }
 
-    float getSampleRate () const {
+    sv_samplerate_t getSampleRate () const {
 	return m_sampleRate;
     }
 
-    float getDuration() const { // seconds
+    double getDuration() const { // seconds
 	return m_duration;
     }
 
 private:
     float *m_data;
-    int m_frameCount;
+    sv_frame_t m_frameCount;
     int m_channelCount;
-    float m_duration;
-    float m_sampleRate;
-    float m_sinFreq;
-    float m_pulseFreq;
-    float m_pulseWidth;
+    double m_duration;
+    sv_samplerate_t m_sampleRate;
+    double m_sinFreq;
+    double m_pulseFreq;
+    double m_pulseWidth;
 };
 
 #endif
--- a/data/fileio/test/test.pro	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/fileio/test/test.pro	Mon Mar 23 11:26:28 2015 +0000
@@ -38,7 +38,7 @@
     }
 }
 
-CONFIG += qt thread warn_on stl rtti exceptions console
+CONFIG += qt thread warn_on stl rtti exceptions console c++11
 QT += network xml testlib
 QT -= gui
 
--- a/data/midi/MIDIEvent.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/midi/MIDIEvent.h	Mon Mar 23 11:26:28 2015 +0000
@@ -25,6 +25,8 @@
 #include <QString>
 #include <string>
 #include <iostream>
+#include <stdexcept>
+
 #include "base/Debug.h"
 
 typedef unsigned char MIDIByte;
@@ -118,16 +120,22 @@
 {
 public:
     MIDIEvent(unsigned long deltaTime,
-              MIDIByte eventCode,
-              MIDIByte data1 = 0,
-              MIDIByte data2 = 0) :
+              int eventCode,
+              int data1 = 0,
+              int data2 = 0) :
 	m_deltaTime(deltaTime),
 	m_duration(0),
-	m_eventCode(eventCode),
-	m_data1(data1),
-	m_data2(data2),
 	m_metaEventCode(0)
-    { }
+    {
+        if (eventCode < 0 || eventCode > 0xff ||
+            data1 < 0 || data1 > 0xff ||
+            data2 < 0 || data2 > 0xff) {
+            throw std::domain_error("not all args within byte range");
+        }
+        m_eventCode = MIDIByte(eventCode);
+        m_data1 = MIDIByte(data1);
+        m_data2 = MIDIByte(data2);
+    }
 
     MIDIEvent(unsigned long deltaTime,
               MIDIByte eventCode,
--- a/data/midi/rtmidi/RtMidi.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/midi/rtmidi/RtMidi.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -835,7 +835,7 @@
       if ( data->firstMessage == true )
         data->firstMessage = false;
       else
-        message.timeStamp = time * 0.000001;
+	  message.timeStamp = double(time) * 0.000001;
     }
 
     snd_seq_free_event(ev);
@@ -947,9 +947,9 @@
 
 
   snd_seq_addr_t sender, receiver;
-  sender.client = snd_seq_port_info_get_client( pinfo );
-  sender.port = snd_seq_port_info_get_port( pinfo );
-  receiver.client = snd_seq_client_id( data->seq );
+  sender.client = (unsigned char)snd_seq_port_info_get_client( pinfo );
+  sender.port = (unsigned char)snd_seq_port_info_get_port( pinfo );
+  receiver.client = (unsigned char)snd_seq_client_id( data->seq );
   if ( data->vport < 0 ) {
     snd_seq_port_info_set_client( pinfo, 0 );
     snd_seq_port_info_set_port( pinfo, 0 );
@@ -972,7 +972,7 @@
     }
   }
 
-  receiver.port = data->vport;
+  receiver.port = (unsigned char)data->vport;
 
   // Make subscription
   snd_seq_port_subscribe_malloc( &data->subscription );
@@ -1222,9 +1222,9 @@
   }
 
   snd_seq_addr_t sender, receiver;
-  receiver.client = snd_seq_port_info_get_client( pinfo );
-  receiver.port = snd_seq_port_info_get_port( pinfo );
-  sender.client = snd_seq_client_id( data->seq );
+  receiver.client = (unsigned char)snd_seq_port_info_get_client( pinfo );
+  receiver.port = (unsigned char)snd_seq_port_info_get_port( pinfo );
+  sender.client = (unsigned char)snd_seq_client_id( data->seq );
 
   if ( data->vport < 0 ) {
     data->vport = snd_seq_create_simple_port( data->seq, portName.c_str(),
@@ -1236,7 +1236,7 @@
     }
   }
 
-  sender.port = data->vport;
+  sender.port = (unsigned char)data->vport;
 
   // Make subscription
   snd_seq_port_subscribe_malloc( &data->subscription );
@@ -1295,7 +1295,7 @@
 {
   int result;
   AlsaMidiData *data = static_cast<AlsaMidiData *> (apiData_);
-  unsigned int nBytes = message->size();
+  unsigned int nBytes = (unsigned int) message->size();
   if ( nBytes > data->bufferSize ) {
     data->bufferSize = nBytes;
     result = snd_midi_event_resize_buffer ( data->coder, nBytes);
@@ -1313,11 +1313,11 @@
 
   snd_seq_event_t ev;
   snd_seq_ev_clear(&ev);
-  snd_seq_ev_set_source(&ev, data->vport);
+  snd_seq_ev_set_source(&ev, (unsigned char) data->vport);
   snd_seq_ev_set_subs(&ev);
   snd_seq_ev_set_direct(&ev);
   for ( unsigned int i=0; i<nBytes; i++ ) data->buffer[i] = message->at(i);
-  result = snd_midi_event_encode( data->coder, data->buffer, (long)nBytes, &ev );
+  result = (int) snd_midi_event_encode( data->coder, data->buffer, (long)nBytes, &ev );
   if ( result < (int)nBytes ) {
     errorString_ = "RtMidiOut::sendMessage: event parsing error!";
     error( RtError::WARNING );
--- a/data/model/AggregateWaveModel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/AggregateWaveModel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -65,14 +65,14 @@
     return ready;
 }
 
-int
+sv_frame_t
 AggregateWaveModel::getFrameCount() const
 {
-    int count = 0;
+    sv_frame_t count = 0;
 
     for (ChannelSpecList::const_iterator i = m_components.begin();
          i != m_components.end(); ++i) {
-        int thisCount = i->model->getEndFrame() - i->model->getStartFrame();
+        sv_frame_t thisCount = i->model->getEndFrame() - i->model->getStartFrame();
         if (thisCount > count) count = thisCount;
     }
 
@@ -82,10 +82,10 @@
 int
 AggregateWaveModel::getChannelCount() const
 {
-    return m_components.size();
+    return int(m_components.size());
 }
 
-int
+sv_samplerate_t
 AggregateWaveModel::getSampleRate() const
 {
     if (m_components.empty()) return 0;
@@ -98,8 +98,8 @@
     return new AggregateWaveModel(m_components);
 }
 
-int
-AggregateWaveModel::getData(int channel, int start, int count,
+sv_frame_t
+AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count,
                             float *buffer) const
 {
     int ch0 = channel, ch1 = channel;
@@ -113,15 +113,15 @@
     float *readbuf = buffer;
     if (mixing) {
         readbuf = new float[count];
-        for (int i = 0; i < count; ++i) {
+        for (sv_frame_t i = 0; i < count; ++i) {
             buffer[i] = 0.f;
         }
     }
 
-    int longest = 0;
+    sv_frame_t longest = 0;
     
     for (int c = ch0; c <= ch1; ++c) {
-        int here = 
+        sv_frame_t here = 
             m_components[c].model->getData(m_components[c].channel,
                                            start, count,
                                            readbuf);
@@ -129,12 +129,12 @@
             longest = here;
         }
         if (here < count) {
-            for (int i = here; i < count; ++i) {
+            for (sv_frame_t i = here; i < count; ++i) {
                 readbuf[i] = 0.f;
             }
         }
         if (mixing) {
-            for (int i = 0; i < count; ++i) {
+            for (sv_frame_t i = 0; i < count; ++i) {
                 buffer[i] += readbuf[i];
             }
         }
@@ -144,8 +144,8 @@
     return longest;
 }
          
-int
-AggregateWaveModel::getData(int channel, int start, int count,
+sv_frame_t
+AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count,
                             double *buffer) const
 {
     int ch0 = channel, ch1 = channel;
@@ -159,15 +159,15 @@
     double *readbuf = buffer;
     if (mixing) {
         readbuf = new double[count];
-        for (int i = 0; i < count; ++i) {
+        for (sv_frame_t i = 0; i < count; ++i) {
             buffer[i] = 0.0;
         }
     }
 
-    int longest = 0;
+    sv_frame_t longest = 0;
     
     for (int c = ch0; c <= ch1; ++c) {
-        int here = 
+        sv_frame_t here = 
             m_components[c].model->getData(m_components[c].channel,
                                            start, count,
                                            readbuf);
@@ -175,12 +175,12 @@
             longest = here;
         }
         if (here < count) {
-            for (int i = here; i < count; ++i) {
+            for (sv_frame_t i = here; i < count; ++i) {
                 readbuf[i] = 0.;
             }
         }
         if (mixing) {
-            for (int i = 0; i < count; ++i) {
+            for (sv_frame_t i = 0; i < count; ++i) {
                 buffer[i] += readbuf[i];
             }
         }
@@ -190,15 +190,15 @@
     return longest;
 }
 
-int
+sv_frame_t
 AggregateWaveModel::getData(int fromchannel, int tochannel,
-                            int start, int count,
+                            sv_frame_t start, sv_frame_t count,
                             float **buffer) const
 {
-    int min = count;
+    sv_frame_t min = count;
 
     for (int c = fromchannel; c <= tochannel; ++c) {
-        int here = getData(c, start, count, buffer[c - fromchannel]);
+        sv_frame_t here = getData(c, start, count, buffer[c - fromchannel]);
         if (here < min) min = here;
     }
     
@@ -213,14 +213,14 @@
 }
         
 void
-AggregateWaveModel::getSummaries(int, int, int,
+AggregateWaveModel::getSummaries(int, sv_frame_t, sv_frame_t,
                                  RangeBlock &, int &) const
 {
     //!!! complete
 }
 
 AggregateWaveModel::Range
-AggregateWaveModel::getSummary(int, int, int) const
+AggregateWaveModel::getSummary(int, sv_frame_t, sv_frame_t) const
 {
     //!!! complete
     return Range();
@@ -229,7 +229,7 @@
 int
 AggregateWaveModel::getComponentCount() const
 {
-    return m_components.size();
+    return int(m_components.size());
 }
 
 AggregateWaveModel::ModelChannelSpec
@@ -245,7 +245,7 @@
 }
 
 void
-AggregateWaveModel::componentModelChangedWithin(int start, int end)
+AggregateWaveModel::componentModelChangedWithin(sv_frame_t start, sv_frame_t end)
 {
     emit modelChangedWithin(start, end);
 }
--- a/data/model/AggregateWaveModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/AggregateWaveModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -49,35 +49,35 @@
 
     const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; }
 
-    int getFrameCount() const;
+    sv_frame_t getFrameCount() const;
     int getChannelCount() const;
-    int getSampleRate() const;
+    sv_samplerate_t getSampleRate() const;
 
     virtual Model *clone() const;
 
     float getValueMinimum() const { return -1.0f; }
     float getValueMaximum() const { return  1.0f; }
 
-    virtual int getStartFrame() const { return 0; }
-    virtual int getEndFrame() const { return getFrameCount(); }
+    virtual sv_frame_t getStartFrame() const { return 0; }
+    virtual sv_frame_t getEndFrame() const { return getFrameCount(); }
 
-    virtual int getData(int channel, int start, int count,
+    virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
                            float *buffer) const;
 
-    virtual int getData(int channel, int start, int count,
+    virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
                            double *buffer) const;
 
-    virtual int getData(int fromchannel, int tochannel,
-                           int start, int count,
+    virtual sv_frame_t getData(int fromchannel, int tochannel,
+                           sv_frame_t start, sv_frame_t count,
                            float **buffer) const;
 
     virtual int getSummaryBlockSize(int desired) const;
 
-    virtual void getSummaries(int channel, int start, int count,
+    virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
                               RangeBlock &ranges,
                               int &blockSize) const;
 
-    virtual Range getSummary(int channel, int start, int count) const;
+    virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const;
 
     virtual void toXml(QTextStream &out,
                        QString indent = "",
@@ -85,12 +85,12 @@
 
 signals:
     void modelChanged();
-    void modelChangedWithin(int, int);
+    void modelChangedWithin(sv_frame_t, sv_frame_t);
     void completionChanged();
 
 protected slots:
     void componentModelChanged();
-    void componentModelChangedWithin(int, int);
+    void componentModelChangedWithin(sv_frame_t, sv_frame_t);
     void componentModelCompletionChanged();
 
 protected:
--- a/data/model/AlignmentModel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/AlignmentModel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -37,8 +37,8 @@
         connect(m_rawPath, SIGNAL(modelChanged()),
                 this, SLOT(pathChanged()));
 
-        connect(m_rawPath, SIGNAL(modelChangedWithin(int, int)),
-                this, SLOT(pathChangedWithin(int, int)));
+        connect(m_rawPath, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
+                this, SLOT(pathChangedWithin(sv_frame_t, sv_frame_t)));
         
         connect(m_rawPath, SIGNAL(completionChanged()),
                 this, SLOT(pathCompletionChanged()));
@@ -74,23 +74,23 @@
     else return true;
 }
 
-int
+sv_frame_t
 AlignmentModel::getStartFrame() const
 {
-    int a = m_reference->getStartFrame();
-    int b = m_aligned->getStartFrame();
+    sv_frame_t a = m_reference->getStartFrame();
+    sv_frame_t b = m_aligned->getStartFrame();
     return std::min(a, b);
 }
 
-int
+sv_frame_t
 AlignmentModel::getEndFrame() const
 {
-    int a = m_reference->getEndFrame();
-    int b = m_aligned->getEndFrame();
+    sv_frame_t a = m_reference->getEndFrame();
+    sv_frame_t b = m_aligned->getEndFrame();
     return std::max(a, b);
 }
 
-int
+sv_samplerate_t
 AlignmentModel::getSampleRate() const
 {
     return m_reference->getSampleRate();
@@ -144,8 +144,8 @@
     return m_aligned;
 }
 
-int
-AlignmentModel::toReference(int frame) const
+sv_frame_t
+AlignmentModel::toReference(sv_frame_t frame) const
 {
 #ifdef DEBUG_ALIGNMENT_MODEL
     SVDEBUG << "AlignmentModel::toReference(" << frame << ")" << endl;
@@ -157,8 +157,8 @@
     return align(m_path, frame);
 }
 
-int
-AlignmentModel::fromReference(int frame) const
+sv_frame_t
+AlignmentModel::fromReference(sv_frame_t frame) const
 {
 #ifdef DEBUG_ALIGNMENT_MODEL
     SVDEBUG << "AlignmentModel::fromReference(" << frame << ")" << endl;
@@ -182,7 +182,7 @@
 }
 
 void
-AlignmentModel::pathChangedWithin(int, int)
+AlignmentModel::pathChangedWithin(sv_frame_t, sv_frame_t)
 {
     if (!m_pathComplete) return;
     constructPath();
@@ -242,9 +242,9 @@
         
     for (SparseTimeValueModel::PointList::const_iterator i = points.begin();
          i != points.end(); ++i) {
-        long frame = i->frame;
-        float value = i->value;
-        long rframe = lrintf(value * m_aligned->getSampleRate());
+        sv_frame_t frame = i->frame;
+        double value = i->value;
+        sv_frame_t rframe = lrint(value * m_aligned->getSampleRate());
         m_path->addPoint(PathPoint(frame, rframe));
     }
 
@@ -274,8 +274,8 @@
         
     for (PathModel::PointList::const_iterator i = points.begin();
          i != points.end(); ++i) {
-        long frame = i->frame;
-        long rframe = i->mapframe;
+        sv_frame_t frame = i->frame;
+        sv_frame_t rframe = i->mapframe;
         m_reversePath->addPoint(PathPoint(rframe, frame));
     }
 
@@ -284,8 +284,8 @@
 #endif
 }
 
-int
-AlignmentModel::align(PathModel *path, int frame) const
+sv_frame_t
+AlignmentModel::align(PathModel *path, sv_frame_t frame) const
 {
     if (!path) return frame;
 
@@ -315,13 +315,13 @@
 #endif
         --i;
     }
-    while (i != points.begin() && i->frame > long(frame)) --i;
+    while (i != points.begin() && i->frame > frame) --i;
 
-    long foundFrame = i->frame;
-    long foundMapFrame = i->mapframe;
+    sv_frame_t foundFrame = i->frame;
+    sv_frame_t foundMapFrame = i->mapframe;
 
-    long followingFrame = foundFrame;
-    long followingMapFrame = foundMapFrame;
+    sv_frame_t followingFrame = foundFrame;
+    sv_frame_t followingMapFrame = foundMapFrame;
 
     if (++i != points.end()) {
 #ifdef DEBUG_ALIGNMENT_MODEL
@@ -337,13 +337,13 @@
 
     if (foundMapFrame < 0) return 0;
 
-    int resultFrame = foundMapFrame;
+    sv_frame_t resultFrame = foundMapFrame;
 
-    if (followingFrame != foundFrame && long(frame) > foundFrame) {
-        float interp =
-            float(frame - foundFrame) /
-            float(followingFrame - foundFrame);
-        resultFrame += lrintf((followingMapFrame - foundMapFrame) * interp);
+    if (followingFrame != foundFrame && frame > foundFrame) {
+        double interp =
+            double(frame - foundFrame) /
+            double(followingFrame - foundFrame);
+        resultFrame += lrint(double(followingMapFrame - foundMapFrame) * interp);
     }
 
 #ifdef DEBUG_ALIGNMENT_MODEL
@@ -364,8 +364,8 @@
     connect(m_rawPath, SIGNAL(modelChanged()),
             this, SLOT(pathChanged()));
 
-    connect(m_rawPath, SIGNAL(modelChangedWithin(int, int)),
-            this, SLOT(pathChangedWithin(int, int)));
+    connect(m_rawPath, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
+            this, SLOT(pathChangedWithin(sv_frame_t, sv_frame_t)));
         
     connect(m_rawPath, SIGNAL(completionChanged()),
             this, SLOT(pathCompletionChanged()));
--- a/data/model/AlignmentModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/AlignmentModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -37,9 +37,9 @@
     ~AlignmentModel();
 
     virtual bool isOK() const;
-    virtual int getStartFrame() const;
-    virtual int getEndFrame() const;
-    virtual int getSampleRate() const;
+    virtual sv_frame_t getStartFrame() const;
+    virtual sv_frame_t getEndFrame() const;
+    virtual sv_samplerate_t getSampleRate() const;
     virtual Model *clone() const;
     virtual bool isReady(int *completion = 0) const;
     virtual const ZoomConstraint *getZoomConstraint() const;
@@ -49,8 +49,8 @@
     const Model *getReferenceModel() const;
     const Model *getAlignedModel() const;
 
-    int toReference(int frame) const;
-    int fromReference(int frame) const;
+    sv_frame_t toReference(sv_frame_t frame) const;
+    sv_frame_t fromReference(sv_frame_t frame) const;
 
     void setPathFrom(SparseTimeValueModel *rawpath);
     void setPath(PathModel *path);
@@ -61,12 +61,12 @@
 
 signals:
     void modelChanged();
-    void modelChangedWithin(int startFrame, int endFrame);
+    void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame);
     void completionChanged();
 
 protected slots:
     void pathChanged();
-    void pathChangedWithin(int startFrame, int endFrame);
+    void pathChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame);
     void pathCompletionChanged();
 
 protected:
@@ -84,7 +84,7 @@
     void constructPath() const;
     void constructReversePath() const;
 
-    int align(PathModel *path, int frame) const;
+    sv_frame_t align(PathModel *path, sv_frame_t frame) const;
 };
 
 #endif
--- a/data/model/Dense3DModelPeakCache.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/Dense3DModelPeakCache.h	Mon Mar 23 11:26:28 2015 +0000
@@ -33,15 +33,15 @@
         return m_source && m_source->isOK(); 
     }
 
-    virtual int getSampleRate() const {
+    virtual sv_samplerate_t getSampleRate() const {
         return m_source->getSampleRate();
     }
 
-    virtual int getStartFrame() const {
+    virtual sv_frame_t getStartFrame() const {
         return m_source->getStartFrame();
     }
 
-    virtual int getEndFrame() const {
+    virtual sv_frame_t getEndFrame() const {
         return m_source->getEndFrame();
     }
 
--- a/data/model/DenseThreeDimensionalModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/DenseThreeDimensionalModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -93,7 +93,7 @@
      * value which does not vary from one column to the next. This is
      * only meaningful if hasBinValues() returns true.
      */
-    virtual float getBinValue(int n) const { return n; }
+    virtual float getBinValue(int n) const { return float(n); }
 
     /**
      * Obtain the name of the unit of the values returned from
@@ -171,11 +171,11 @@
         return SortNumeric;
     }
 
-    virtual long getFrameForRow(int row) const {
-        return row * getResolution();
+    virtual sv_frame_t getFrameForRow(int row) const {
+        return sv_frame_t(row) * getResolution();
     }
-    virtual int getRowForFrame(long frame) const {
-        return frame / getResolution();
+    virtual int getRowForFrame(sv_frame_t frame) const {
+        return int(frame / getResolution());
     }
 
 protected:
--- a/data/model/DenseTimeValueModel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/DenseTimeValueModel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -29,7 +29,7 @@
 }
 	
 QString
-DenseTimeValueModel::toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
+DenseTimeValueModel::toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const
 {
     int ch = getChannelCount();
 
@@ -42,10 +42,10 @@
         all[c] = new float[f1 - f0];
     }
 
-    int n = getData(0, ch - 1, f0, f1 - f0, all);
+    sv_frame_t n = getData(0, ch - 1, f0, f1 - f0, all);
 
     QStringList list;
-    for (int i = 0; i < n; ++i) {
+    for (sv_frame_t i = 0; i < n; ++i) {
         QStringList parts;
         parts << QString("%1").arg(f0 + i);
         for (int c = 0; c < ch; ++c) {
--- a/data/model/DenseTimeValueModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/DenseTimeValueModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -62,8 +62,8 @@
      * If the channel is given as -1, mix all available channels and
      * return the result.
      */
-    virtual int getData(int channel, int start, int count,
-                           float *buffer) const = 0;
+    virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
+                               float *buffer) const = 0;
 
     /**
      * Get the specified set of samples from the given channel of the
@@ -72,22 +72,22 @@
      * If the channel is given as -1, mix all available channels and
      * return the result.
      */
-    virtual int getData(int channel, int start, int count,
-                           double *buffer) const = 0;
-
+    virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
+                               double *buffer) const = 0;
+    
     /**
      * Get the specified set of samples from given contiguous range
      * of channels of the model in single-precision floating-point
      * format.  Return the number of sample frames actually retrieved.
      */
-    virtual int getData(int fromchannel, int tochannel,
-                           int start, int count,
-                           float **buffers) const = 0;
+    virtual sv_frame_t getData(int fromchannel, int tochannel,
+                               sv_frame_t start, sv_frame_t count,
+                               float **buffers) const = 0;
 
     virtual bool canPlay() const { return true; }
     virtual QString getDefaultPlayClipId() const { return ""; }
 
-    virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const;
+    virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const;
 
     QString getTypeName() const { return tr("Dense Time-Value"); }
 };
--- a/data/model/EditableDenseThreeDimensionalModel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/EditableDenseThreeDimensionalModel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -27,9 +27,11 @@
 #include <cmath>
 #include <cassert>
 
+using std::vector;
+
 #include "system/System.h"
 
-EditableDenseThreeDimensionalModel::EditableDenseThreeDimensionalModel(int sampleRate,
+EditableDenseThreeDimensionalModel::EditableDenseThreeDimensionalModel(sv_samplerate_t sampleRate,
                                                                        int resolution,
                                                                        int yBinCount,
                                                                        CompressionType compression,
@@ -55,25 +57,25 @@
     return true;
 }
 
-int
+sv_samplerate_t
 EditableDenseThreeDimensionalModel::getSampleRate() const
 {
     return m_sampleRate;
 }
 
-int
+sv_frame_t
 EditableDenseThreeDimensionalModel::getStartFrame() const
 {
     return m_startFrame;
 }
 
 void
-EditableDenseThreeDimensionalModel::setStartFrame(int f)
+EditableDenseThreeDimensionalModel::setStartFrame(sv_frame_t f)
 {
     m_startFrame = f; 
 }
 
-int
+sv_frame_t
 EditableDenseThreeDimensionalModel::getEndFrame() const
 {
     return m_resolution * m_data.size() + (m_resolution - 1);
@@ -255,7 +257,7 @@
                     tcol[i - bcount] = values.at(i);
                 }
                 m_data[index] = tcol;
-                m_trunc[index] = -tdist;
+                m_trunc[index] = (signed char)(-tdist);
                 return;
             } else {
                 // create a new column with h - tcount values from 0 up
@@ -266,7 +268,7 @@
                     tcol[i] = values.at(i);
                 }
                 m_data[index] = tcol;
-                m_trunc[index] = tdist;
+                m_trunc[index] = (signed char)(tdist);
                 return;
             }
         }
@@ -445,15 +447,15 @@
 {
     QReadLocker locker(&m_lock);
 
-    QVector<float> sample;
-    QVector<int> n;
+    vector<double> sample;
+    vector<int> n;
     
     for (int i = 0; i < 10; ++i) {
         int index = i * 10;
         if (index < m_data.size()) {
             const Column &c = m_data.at(index);
-            while (c.size() > sample.size()) {
-                sample.push_back(0.f);
+            while (c.size() > int(sample.size())) {
+                sample.push_back(0.0);
                 n.push_back(0);
             }
             for (int j = 0; j < c.size(); ++j) {
@@ -464,11 +466,11 @@
     }
 
     if (sample.empty()) return false;
-    for (int j = 0; j < sample.size(); ++j) {
+    for (decltype(sample)::size_type j = 0; j < sample.size(); ++j) {
         if (n[j]) sample[j] /= n[j];
     }
     
-    return LogRange::useLogScale(sample.toStdVector());
+    return LogRange::useLogScale(sample);
 }
 
 void
@@ -515,13 +517,13 @@
 }
 
 QString
-EditableDenseThreeDimensionalModel::toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
+EditableDenseThreeDimensionalModel::toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const
 {
     QReadLocker locker(&m_lock);
     QString s;
     for (int i = 0; i < m_data.size(); ++i) {
-        int fr = m_startFrame + i * m_resolution;
-        if (fr >= int(f0) && fr < int(f1)) {
+        sv_frame_t fr = m_startFrame + i * m_resolution;
+        if (fr >= f0 && fr < f1) {
             QStringList list;
             for (int j = 0; j < m_data.at(i).size(); ++j) {
                 list << QString("%1").arg(m_data.at(i).at(j));
--- a/data/model/EditableDenseThreeDimensionalModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/EditableDenseThreeDimensionalModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -42,7 +42,7 @@
         BasicMultirateCompression
     };
 
-    EditableDenseThreeDimensionalModel(int sampleRate,
+    EditableDenseThreeDimensionalModel(sv_samplerate_t sampleRate,
 				       int resolution,
 				       int yBinCount,
                                        CompressionType compression,
@@ -50,9 +50,9 @@
 
     virtual bool isOK() const;
 
-    virtual int getSampleRate() const;
-    virtual int getStartFrame() const;
-    virtual int getEndFrame() const;
+    virtual sv_samplerate_t getSampleRate() const;
+    virtual sv_frame_t getStartFrame() const;
+    virtual sv_frame_t getEndFrame() const;
 
     virtual Model *clone() const;
     
@@ -60,7 +60,7 @@
     /**
      * Set the frame offset of the first column.
      */
-    virtual void setStartFrame(int);
+    virtual void setStartFrame(sv_frame_t);
 
     /**
      * Return the number of sample frames covered by each set of bins.
@@ -190,7 +190,7 @@
     QString getTypeName() const { return tr("Editable Dense 3-D"); }
 
     virtual QString toDelimitedDataString(QString delimiter) const;
-    virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const;
+    virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const;
 
     virtual void toXml(QTextStream &out,
                        QString indent = "",
@@ -216,8 +216,8 @@
     std::vector<float> m_binValues;
     QString m_binValueUnit;
 
-    int m_startFrame;
-    int m_sampleRate;
+    sv_frame_t m_startFrame;
+    sv_samplerate_t m_sampleRate;
     int m_resolution;
     int m_yBinCount;
     CompressionType m_compression;
--- a/data/model/FFTModel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/FFTModel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -36,7 +36,7 @@
                    int fftSize,
                    bool polar,
                    StorageAdviser::Criteria criteria,
-                   int fillFromColumn) :
+                   sv_frame_t fillFromFrame) :
     //!!! ZoomConstraint!
     m_server(0),
     m_xshift(0),
@@ -52,7 +52,7 @@
                          fftSize,
                          polar,
                          criteria,
-                         fillFromColumn);
+                         fillFromFrame);
 
     if (!m_server) return; // caller should check isOK()
 
@@ -110,7 +110,7 @@
                     int fftSize,
                     bool polar,
                     StorageAdviser::Criteria criteria,
-                    int fillFromColumn)
+                    sv_frame_t fillFromFrame)
 {
     // Obviously, an FFT model of channel C (where C != -1) of an
     // aggregate model is the same as the FFT model of the appropriate
@@ -142,7 +142,7 @@
                              fftSize,
                              polar,
                              criteria,
-                             fillFromColumn);
+                             fillFromFrame);
         }
     }
 
@@ -156,10 +156,10 @@
                                            fftSize,
                                            polar,
                                            criteria,
-                                           fillFromColumn);
+                                           fillFromFrame);
 }
 
-int
+sv_samplerate_t
 FFTModel::getSampleRate() const
 {
     return isOK() ? m_server->getModel()->getSampleRate() : 0;
@@ -198,21 +198,21 @@
 QString
 FFTModel::getBinName(int n) const
 {
-    int sr = getSampleRate();
+    sv_samplerate_t sr = getSampleRate();
     if (!sr) return "";
     QString name = tr("%1 Hz").arg((n * sr) / ((getHeight()-1) * 2));
     return name;
 }
 
 bool
-FFTModel::estimateStableFrequency(int x, int y, float &frequency)
+FFTModel::estimateStableFrequency(int x, int y, double &frequency)
 {
     if (!isOK()) return false;
 
-    int sampleRate = m_server->getModel()->getSampleRate();
+    sv_samplerate_t sampleRate = m_server->getModel()->getSampleRate();
 
     int fftSize = m_server->getFFTSize() >> m_yshift;
-    frequency = (float(y) * sampleRate) / fftSize;
+    frequency = double(y * sampleRate) / fftSize;
 
     if (x+1 >= getWidth()) return false;
 
@@ -225,14 +225,14 @@
     //  = 2pi * ((h * b * sr) / (w * sr))
     //  = 2pi * (h * b) / w.
 
-    float oldPhase = getPhaseAt(x, y);
-    float newPhase = getPhaseAt(x+1, y);
+    double oldPhase = getPhaseAt(x, y);
+    double newPhase = getPhaseAt(x+1, y);
 
     int incr = getResolution();
 
-    float expectedPhase = oldPhase + (2.0 * M_PI * y * incr) / fftSize;
+    double expectedPhase = oldPhase + (2.0 * M_PI * y * incr) / fftSize;
 
-    float phaseError = princargf(newPhase - expectedPhase);
+    double phaseError = princarg(newPhase - expectedPhase);
 
 //    bool stable = (fabsf(phaseError) < (1.1f * (m_windowIncrement * M_PI) / m_fftSize));
 
@@ -241,7 +241,7 @@
 
     frequency =
         (sampleRate * (expectedPhase + phaseError - oldPhase)) /
-        (2 * M_PI * incr);
+        (2.0 * M_PI * incr);
 
     return true;
 }
@@ -284,14 +284,14 @@
 
     float mean = 0.f;
     for (int i = 0; i < values.size(); ++i) mean += values[i];
-    if (values.size() >0) mean /= values.size();
-
+    if (values.size() > 0) mean = mean / float(values.size());
+    
     // For peak picking we use a moving median window, picking the
     // highest value within each continuous region of values that
     // exceed the median.  For pitch adaptivity, we adjust the window
     // size to a roughly constant pitch range (about four tones).
 
-    int sampleRate = getSampleRate();
+    sv_samplerate_t sampleRate = getSampleRate();
 
     std::deque<float> window;
     std::vector<int> inrange;
@@ -324,7 +324,7 @@
             window.pop_front();
         }
 
-        int actualSize = window.size();
+        int actualSize = int(window.size());
 
         if (type == MajorPitchAdaptivePeaks) {
             if (ymax + halfWin < values.size()) binmax = ymax + halfWin;
@@ -333,7 +333,7 @@
 
         std::deque<float> sorted(window);
         std::sort(sorted.begin(), sorted.end());
-        float median = sorted[int(sorted.size() * dist)];
+        float median = sorted[int(float(sorted.size()) * dist)];
 
         int centrebin = 0;
         if (bin > actualSize/2) centrebin = bin - actualSize/2;
@@ -373,7 +373,7 @@
 }
 
 int
-FFTModel::getPeakPickWindowSize(PeakPickType type, int sampleRate,
+FFTModel::getPeakPickWindowSize(PeakPickType type, sv_samplerate_t sampleRate,
                                 int bin, float &percentile) const
 {
     percentile = 0.5;
@@ -381,14 +381,14 @@
     if (bin == 0) return 3;
 
     int fftSize = m_server->getFFTSize() >> m_yshift;
-    float binfreq = (float(sampleRate) * bin) / fftSize;
-    float hifreq = Pitch::getFrequencyForPitch(73, 0, binfreq);
+    double binfreq = (sampleRate * bin) / fftSize;
+    double hifreq = Pitch::getFrequencyForPitch(73, 0, binfreq);
 
-    int hibin = lrintf((hifreq * fftSize) / sampleRate);
+    int hibin = int(lrint((hifreq * fftSize) / sampleRate));
     int medianWinSize = hibin - bin;
     if (medianWinSize < 3) medianWinSize = 3;
 
-    percentile = 0.5 + (binfreq / sampleRate);
+    percentile = 0.5f + float(binfreq / sampleRate);
 
     return medianWinSize;
 }
@@ -403,7 +403,7 @@
     if (!isOK()) return peaks;
     PeakLocationSet locations = getPeaks(type, x, ymin, ymax);
 
-    int sampleRate = getSampleRate();
+    sv_samplerate_t sampleRate = getSampleRate();
     int fftSize = m_server->getFFTSize() >> m_yshift;
     int incr = getResolution();
 
@@ -421,11 +421,11 @@
     int phaseIndex = 0;
     for (PeakLocationSet::iterator i = locations.begin();
          i != locations.end(); ++i) {
-        float oldPhase = phases[phaseIndex];
-        float newPhase = getPhaseAt(x+1, *i);
-        float expectedPhase = oldPhase + (2.0 * M_PI * *i * incr) / fftSize;
-        float phaseError = princargf(newPhase - expectedPhase);
-        float frequency =
+        double oldPhase = phases[phaseIndex];
+        double newPhase = getPhaseAt(x+1, *i);
+        double expectedPhase = oldPhase + (2.0 * M_PI * *i * incr) / fftSize;
+        double phaseError = princarg(newPhase - expectedPhase);
+        double frequency =
             (sampleRate * (expectedPhase + phaseError - oldPhase))
             / (2 * M_PI * incr);
 //        bool stable = (fabsf(phaseError) < (1.1f * (incr * M_PI) / fftSize));
--- a/data/model/FFTModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/FFTModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -63,7 +63,7 @@
              int fftSize,
              bool polar,
              StorageAdviser::Criteria criteria = StorageAdviser::NoCriteria,
-             int fillFromColumn = 0);
+             sv_frame_t fillFromFrame = 0);
     ~FFTModel();
 
     inline float getMagnitudeAt(int x, int y) {
@@ -98,7 +98,7 @@
         return m_server->getValuesAt(x << m_xshift, reals, imaginaries, minbin << m_yshift, count, getYRatio());
     }
 
-    inline int getFillExtent() const { return m_server->getFillExtent(); }
+    inline sv_frame_t getFillExtent() const { return m_server->getFillExtent(); }
 
     // DenseThreeDimensionalModel and Model methods:
     //
@@ -120,13 +120,13 @@
     virtual bool isOK() const {
         return m_server && m_server->getModel();
     }
-    virtual int getStartFrame() const {
+    virtual sv_frame_t getStartFrame() const {
         return 0;
     }
-    virtual int getEndFrame() const {
-        return getWidth() * getResolution() + getResolution();
+    virtual sv_frame_t getEndFrame() const {
+        return sv_frame_t(getWidth()) * getResolution() + getResolution();
     }
-    virtual int getSampleRate() const;
+    virtual sv_samplerate_t getSampleRate() const;
     virtual int getResolution() const {
         return m_server->getWindowIncrement() << m_xshift;
     }
@@ -151,7 +151,7 @@
      * bin, using phase unwrapping.  This will be completely wrong if
      * the signal is not stable here.
      */
-    virtual bool estimateStableFrequency(int x, int y, float &frequency);
+    virtual bool estimateStableFrequency(int x, int y, double &frequency);
 
     enum PeakPickType
     {
@@ -161,7 +161,7 @@
     };
 
     typedef std::set<int> PeakLocationSet; // bin
-    typedef std::map<int, float> PeakSet; // bin -> freq
+    typedef std::map<int, double> PeakSet; // bin -> freq
 
     /**
      * Return locations of peak bins in the range [ymin,ymax].  If
@@ -200,10 +200,10 @@
 
     FFTDataServer *getServer(const DenseTimeValueModel *,
                              int, WindowType, int, int, int,
-                             bool, StorageAdviser::Criteria, int);
+                             bool, StorageAdviser::Criteria, sv_frame_t);
 
-    int getPeakPickWindowSize(PeakPickType type, int sampleRate,
-                                 int bin, float &percentile) const;
+    int getPeakPickWindowSize(PeakPickType type, sv_samplerate_t sampleRate,
+                              int bin, float &percentile) const;
 
     int getYRatio() {
         int ys = m_yshift;
--- a/data/model/FlexiNoteModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/FlexiNoteModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -42,15 +42,15 @@
 struct FlexiNote
 {
 public:
-    FlexiNote(long _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
-    FlexiNote(long _frame, float _value, int _duration, float _level, QString _label) :
+    FlexiNote(sv_frame_t _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
+    FlexiNote(sv_frame_t _frame, float _value, sv_frame_t _duration, float _level, QString _label) :
 	frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { }
 
     int getDimensions() const { return 3; }
 
-    long frame;
+    sv_frame_t frame;
     float value;
-    int duration;
+    sv_frame_t duration;
     float level;
     QString label;
 
@@ -66,7 +66,7 @@
             .arg(XmlExportable::encodeEntities(label)).arg(extraAttributes);
     }
 
-    QString toDelimitedDataString(QString delimiter, int sampleRate) const
+    QString toDelimitedDataString(QString delimiter, sv_samplerate_t sampleRate) const
     {
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
@@ -102,15 +102,15 @@
     Q_OBJECT
     
 public:
-    FlexiNoteModel(int sampleRate, int resolution,
-	      bool notifyOnAdd = true) :
+    FlexiNoteModel(sv_samplerate_t sampleRate, int resolution,
+                   bool notifyOnAdd = true) :
 	IntervalModel<FlexiNote>(sampleRate, resolution, notifyOnAdd),
 	m_valueQuantization(0)
     {
 	PlayParameterRepository::getInstance()->addPlayable(this);
     }
 
-    FlexiNoteModel(int sampleRate, int resolution,
+    FlexiNoteModel(sv_samplerate_t sampleRate, int resolution,
 	      float valueMinimum, float valueMaximum,
 	      bool notifyOnAdd = true) :
 	IntervalModel<FlexiNote>(sampleRate, resolution,
@@ -208,7 +208,7 @@
         command->deletePoint(point);
 
         switch (column) {
-        case 4: point.level = value.toDouble(); break;
+        case 4: point.level = float(value.toDouble()); break;
         case 5: point.label = value.toString(); break;
         }
 
@@ -231,20 +231,20 @@
         return getNotesWithin(getStartFrame(), getEndFrame());
     }
 
-    NoteList getNotesWithin(int startFrame, int endFrame) const 
+    NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const 
     {    
     	PointList points = getPoints(startFrame, endFrame);
         NoteList notes;
         for (PointList::iterator pli = points.begin(); pli != points.end(); ++pli) {
-    	    int duration = pli->duration;
+    	    sv_frame_t duration = pli->duration;
             if (duration == 0 || duration == 1) {
-                duration = getSampleRate() / 20;
+                duration = sv_frame_t(getSampleRate() / 20);
             }
-            int pitch = lrintf(pli->value);
+            int pitch = int(lrintf(pli->value));
 
             int velocity = 100;
             if (pli->level > 0.f && pli->level <= 1.f) {
-                velocity = lrintf(pli->level * 127);
+                velocity = int(lrintf(pli->level * 127));
             }
 
             NoteData note(pli->frame, duration, pitch, velocity);
--- a/data/model/ImageModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/ImageModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -55,7 +55,7 @@
             .arg(extraAttributes);
     }
 
-    QString toDelimitedDataString(QString delimiter, int sampleRate) const
+    QString toDelimitedDataString(QString delimiter, sv_samplerate_t sampleRate) const
     {
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
@@ -89,7 +89,7 @@
     Q_OBJECT
 
 public:
-    ImageModel(int sampleRate, int resolution, bool notifyOnAdd = true) :
+    ImageModel(sv_samplerate_t sampleRate, int resolution, bool notifyOnAdd = true) :
 	SparseModel<ImagePoint>(sampleRate, resolution, notifyOnAdd)
     { }
 
--- a/data/model/IntervalModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/IntervalModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -29,12 +29,12 @@
 class IntervalModel : public SparseValueModel<PointType>
 {
 public:
-    IntervalModel(int sampleRate, int resolution,
+    IntervalModel(sv_samplerate_t sampleRate, int resolution,
                   bool notifyOnAdd = true) :
 	SparseValueModel<PointType>(sampleRate, resolution, notifyOnAdd)
     { }
 
-    IntervalModel(int sampleRate, int resolution,
+    IntervalModel(sv_samplerate_t sampleRate, int resolution,
                   float valueMinimum, float valueMaximum,
                   bool notifyOnAdd = true) :
 	SparseValueModel<PointType>(sampleRate, resolution,
@@ -48,14 +48,14 @@
      * and after).  Consequently this can be very slow (optimised data
      * structures still to be done!).
      */
-    virtual typename SparseValueModel<PointType>::PointList getPoints(long start, long end) const;
+    virtual typename SparseValueModel<PointType>::PointList getPoints(sv_frame_t start, sv_frame_t end) const;
 
     /**
      * PointTypes have a duration, so this returns all points that span the
      * given frame.  Consequently this can be very slow (optimised
      * data structures still to be done!).
      */
-    virtual typename SparseValueModel<PointType>::PointList getPoints(long frame) const;
+    virtual typename SparseValueModel<PointType>::PointList getPoints(sv_frame_t frame) const;
 
     virtual const typename SparseModel<PointType>::PointList &getPoints() const {
         return SparseModel<PointType>::getPoints(); 
@@ -107,7 +107,7 @@
 
         switch (column) {
         // column cannot be 0 or 1, those cases were handled above
-        case 2: point.value = value.toDouble(); break;
+        case 2: point.value = float(value.toDouble()); break;
         case 3: point.duration = value.toInt(); break;
         }
 
@@ -125,7 +125,7 @@
 
 template <typename PointType>
 typename SparseValueModel<PointType>::PointList
-IntervalModel<PointType>::getPoints(long start, long end) const
+IntervalModel<PointType>::getPoints(sv_frame_t start, sv_frame_t end) const
 {
     typedef IntervalModel<PointType> I;
 
@@ -146,7 +146,7 @@
     for (typename I::PointListConstIterator i = endItr; i != I::m_points.begin(); ) {
         --i;
         if (i->frame < start) {
-            if (i->frame + long(i->duration) >= start) {
+            if (i->frame + i->duration >= start) {
                 rv.insert(*i);
             }
         } else if (i->frame <= end) {
@@ -159,7 +159,7 @@
 
 template <typename PointType>
 typename SparseValueModel<PointType>::PointList
-IntervalModel<PointType>::getPoints(long frame) const
+IntervalModel<PointType>::getPoints(sv_frame_t frame) const
 {
     typedef IntervalModel<PointType> I;
 
@@ -168,8 +168,8 @@
 
     if (I::m_resolution == 0) return typename I::PointList();
 
-    long start = (frame / I::m_resolution) * I::m_resolution;
-    long end = start + I::m_resolution;
+    sv_frame_t start = (frame / I::m_resolution) * I::m_resolution;
+    sv_frame_t end = start + I::m_resolution;
 
     PointType endPoint(end);
     
@@ -180,7 +180,7 @@
     for (typename I::PointListConstIterator i = endItr; i != I::m_points.begin(); ) {
         --i;
         if (i->frame < start) {
-            if (i->frame + long(i->duration) >= start) {
+            if (i->frame + i->duration >= start) {
                 rv.insert(*i);
             }
         } else if (i->frame <= end) {
--- a/data/model/Labeller.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/Labeller.h	Mon Mar 23 11:26:28 2015 +0000
@@ -132,7 +132,7 @@
         if (m_counter > m_cycle) m_counter = 1;
     }
 
-    void setSampleRate(float rate) { m_rate = rate; }
+    void setSampleRate(sv_samplerate_t rate) { m_rate = rate; }
 
     void resetCounters() {
         m_counter = 1;
@@ -262,24 +262,24 @@
 
         case ValueFromSimpleCounter:
         case ValueFromCyclicalCounter:
-            value = m_counter;
+            value = float(m_counter);
             incrementCounter();
             break;
 
         case ValueFromTwoLevelCounter:
-            value = m_counter2 + double(m_counter) / double(m_dp);
+            value = float(m_counter2 + double(m_counter) / double(m_dp));
             incrementCounter();
             break;
 
         case ValueFromFrameNumber:
-            value = newPoint.frame;
+            value = float(newPoint.frame);
             break;
             
         case ValueFromRealTime: 
-            if (m_rate == 0.f) {
+            if (m_rate == 0.0) {
                 std::cerr << "ERROR: Labeller::getValueFor: Real-time conversion required, but no sample rate set" << std::endl;
             } else {
-                value = float(newPoint.frame) / float(m_rate);
+                value = float(double(newPoint.frame) / m_rate);
             }
             break;
 
@@ -287,18 +287,18 @@
         case ValueFromTempoToNext:
         case ValueFromDurationFromPrevious:
         case ValueFromTempoFromPrevious:
-            if (m_rate == 0.f) {
+            if (m_rate == 0.0) {
                 std::cerr << "ERROR: Labeller::getValueFor: Real-time conversion required, but no sample rate set" << std::endl;
             } else if (!prevPoint) {
                 std::cerr << "ERROR: Labeller::getValueFor: Time difference required, but only one point provided" << std::endl;
             } else {
-                int f0 = prevPoint->frame, f1 = newPoint.frame;
+                sv_frame_t f0 = prevPoint->frame, f1 = newPoint.frame;
                 if (m_type == ValueFromDurationToNext ||
                     m_type == ValueFromDurationFromPrevious) {
-                    value = float(f1 - f0) / m_rate;
+                    value = float(double(f1 - f0) / m_rate);
                 } else {
                     if (f1 > f0) {
-                        value = (60.f * m_rate) / (f1 - f0);
+                        value = float((60.0 * m_rate) / double(f1 - f0));
                     }
                 }
             }
@@ -313,7 +313,7 @@
         case ValueFromLabel:
             if (newPoint.label != "") {
                 // more forgiving than QString::toFloat()
-                value = atof(newPoint.label.toLocal8Bit());
+                value = float(atof(newPoint.label.toLocal8Bit()));
             } else {
                 value = 0.f;
             }
@@ -328,7 +328,7 @@
     int m_counter2;
     int m_cycle;
     int m_dp;
-    float m_rate;
+    sv_samplerate_t m_rate;
 };
 
 #endif
--- a/data/model/Model.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/Model.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -110,30 +110,30 @@
     return m_alignment->getReferenceModel();
 }
 
-int
-Model::alignToReference(int frame) const
+sv_frame_t
+Model::alignToReference(sv_frame_t frame) const
 {
 //    cerr << "Model(" << this << ")::alignToReference(" << frame << ")" << endl;
     if (!m_alignment) {
         if (m_sourceModel) return m_sourceModel->alignToReference(frame);
         else return frame;
     }
-    int refFrame = m_alignment->toReference(frame);
+    sv_frame_t refFrame = m_alignment->toReference(frame);
     const Model *m = m_alignment->getReferenceModel();
     if (m && refFrame > m->getEndFrame()) refFrame = m->getEndFrame();
 //    cerr << "have alignment, aligned is " << refFrame << endl;
     return refFrame;
 }
 
-int
-Model::alignFromReference(int refFrame) const
+sv_frame_t
+Model::alignFromReference(sv_frame_t refFrame) const
 {
 //    cerr << "Model(" << this << ")::alignFromReference(" << refFrame << ")" << endl;
     if (!m_alignment) {
         if (m_sourceModel) return m_sourceModel->alignFromReference(refFrame);
         else return refFrame;
     }
-    int frame = m_alignment->fromReference(refFrame);
+    sv_frame_t frame = m_alignment->fromReference(refFrame);
     if (frame > getEndFrame()) frame = getEndFrame();
 //    cerr << "have alignment, aligned is " << frame << endl;
     return frame;
--- a/data/model/Model.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/Model.h	Mon Mar 23 11:26:28 2015 +0000
@@ -21,6 +21,7 @@
 
 #include "base/XmlExportable.h"
 #include "base/Playable.h"
+#include "base/BaseTypes.h"
 
 typedef std::vector<float> SampleBlock;
 
@@ -50,23 +51,23 @@
     /**
      * Return the first audio frame spanned by the model.
      */
-    virtual int getStartFrame() const = 0;
+    virtual sv_frame_t getStartFrame() const = 0;
 
     /**
      * Return the last audio frame spanned by the model.
      */
-    virtual int getEndFrame() const = 0;
+    virtual sv_frame_t getEndFrame() const = 0;
 
     /**
      * Return the frame rate in frames per second.
      */
-    virtual int getSampleRate() const = 0;
+    virtual sv_samplerate_t getSampleRate() const = 0;
 
     /**
      * Return the frame rate of the underlying material, if the model
      * itself has already been resampled.
      */
-    virtual int getNativeRate() const { return getSampleRate(); }
+    virtual sv_samplerate_t getNativeRate() const { return getSampleRate(); }
 
     /**
      * Return the "work title" of the model, if known.
@@ -200,13 +201,13 @@
      * Return the frame number of the reference model that corresponds
      * to the given frame number in this model.
      */
-    virtual int alignToReference(int frame) const;
+    virtual sv_frame_t alignToReference(sv_frame_t frame) const;
 
     /**
      * Return the frame number in this model that corresponds to the
      * given frame number of the reference model.
      */
-    virtual int alignFromReference(int referenceFrame) const;
+    virtual sv_frame_t alignFromReference(sv_frame_t referenceFrame) const;
 
     /**
      * Return the completion percentage for the alignment model: 100
@@ -236,7 +237,7 @@
     virtual QString toDelimitedDataString(QString delimiter) const {
         return toDelimitedDataStringSubset(delimiter, getStartFrame(), getEndFrame());
     }
-    virtual QString toDelimitedDataStringSubset(QString, int /* f0 */, int /* f1 */) const {
+    virtual QString toDelimitedDataStringSubset(QString, sv_frame_t /* f0 */, sv_frame_t /* f1 */) const {
         return "";
     }
 
@@ -255,7 +256,7 @@
      * Emitted when a model has been edited (or more data retrieved
      * from cache, in the case of a cached model that generates slowly)
      */
-    void modelChangedWithin(int startFrame, int endFrame);
+    void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame);
 
     /**
      * Emitted when some internal processing has advanced a stage, but
--- a/data/model/ModelDataTableModel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/ModelDataTableModel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -31,8 +31,8 @@
     Model *baseModel = dynamic_cast<Model *>(m);
 
     connect(baseModel, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
-    connect(baseModel, SIGNAL(modelChangedWithin(int, int)),
-            this, SLOT(modelChangedWithin(int, int)));
+    connect(baseModel, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
+            this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
     connect(baseModel, SIGNAL(aboutToBeDeleted()),
             this, SLOT(modelAboutToBeDeleted()));
 }
@@ -155,14 +155,14 @@
 }
 
 QModelIndex 
-ModelDataTableModel::getModelIndexForFrame(int frame) const
+ModelDataTableModel::getModelIndexForFrame(sv_frame_t frame) const
 {
     if (!m_model) return createIndex(0, 0);
     int row = m_model->getRowForFrame(frame);
     return createIndex(getSorted(row), 0, (void *)0);
 }
 
-int 
+sv_frame_t
 ModelDataTableModel::getFrameForModelIndex(const QModelIndex &index) const
 {
     if (!m_model) return 0;
@@ -219,7 +219,7 @@
 }
 
 void 
-ModelDataTableModel::modelChangedWithin(int, int)
+ModelDataTableModel::modelChangedWithin(sv_frame_t, sv_frame_t)
 {
     //!!! inefficient
     clearSort();
--- a/data/model/ModelDataTableModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/ModelDataTableModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -20,6 +20,8 @@
 
 #include <vector>
 
+#include "base/BaseTypes.h"
+
 class TabularModel;
 class Command;
 
@@ -51,8 +53,8 @@
     int rowCount(const QModelIndex &parent = QModelIndex()) const;
     int columnCount(const QModelIndex &parent = QModelIndex()) const;
 
-    QModelIndex getModelIndexForFrame(int frame) const;
-    int getFrameForModelIndex(const QModelIndex &) const;
+    QModelIndex getModelIndexForFrame(sv_frame_t frame) const;
+    sv_frame_t getFrameForModelIndex(const QModelIndex &) const;
 
     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
 
@@ -69,7 +71,7 @@
 
 protected slots:
     void modelChanged();
-    void modelChangedWithin(int, int);
+    void modelChangedWithin(sv_frame_t, sv_frame_t);
     void modelAboutToBeDeleted();
 
 protected:
--- a/data/model/NoteData.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/NoteData.h	Mon Mar 23 11:26:28 2015 +0000
@@ -21,12 +21,12 @@
 
 struct NoteData
 {
-    NoteData(int _start, int _dur, int _mp, int _vel) :
+    NoteData(sv_frame_t _start, sv_frame_t _dur, int _mp, int _vel) :
 	start(_start), duration(_dur), midiPitch(_mp), frequency(0),
 	isMidiPitchQuantized(true), velocity(_vel), channel(0) { };
             
-    int start;       // audio sample frame
-    int duration;    // in audio sample frames
+    sv_frame_t start;       // audio sample frame
+    sv_frame_t duration;    // in audio sample frames
     int midiPitch;   // 0-127
     float frequency; // Hz, to be used if isMidiPitchQuantized false
     bool isMidiPitchQuantized;
@@ -35,7 +35,7 @@
 
     float getFrequency() const {
         if (isMidiPitchQuantized) {
-            return Pitch::getFrequencyForPitch(midiPitch);
+            return float(Pitch::getFrequencyForPitch(midiPitch));
         } else {
             return frequency;
         }
@@ -48,7 +48,7 @@
 {
 public:
     virtual NoteList getNotes() const = 0;
-    virtual NoteList getNotesWithin(int startFrame, int endFrame) const = 0;
+    virtual NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const = 0;
 };
 
 #endif
--- a/data/model/NoteModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/NoteModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -38,15 +38,15 @@
 struct Note
 {
 public:
-    Note(long _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
-    Note(long _frame, float _value, int _duration, float _level, QString _label) :
+    Note(sv_frame_t _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
+    Note(sv_frame_t _frame, float _value, sv_frame_t _duration, float _level, QString _label) :
 	frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { }
 
     int getDimensions() const { return 3; }
 
-    long frame;
+    sv_frame_t frame;
     float value;
-    int duration;
+    sv_frame_t duration;
     float level;
     QString label;
 
@@ -62,7 +62,7 @@
             .arg(XmlExportable::encodeEntities(label)).arg(extraAttributes);
     }
 
-    QString toDelimitedDataString(QString delimiter, int sampleRate) const
+    QString toDelimitedDataString(QString delimiter, sv_samplerate_t sampleRate) const
     {
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
@@ -98,7 +98,7 @@
     Q_OBJECT
     
 public:
-    NoteModel(int sampleRate, int resolution,
+    NoteModel(sv_samplerate_t sampleRate, int resolution,
 	      bool notifyOnAdd = true) :
 	IntervalModel<Note>(sampleRate, resolution, notifyOnAdd),
 	m_valueQuantization(0)
@@ -106,7 +106,7 @@
 	PlayParameterRepository::getInstance()->addPlayable(this);
     }
 
-    NoteModel(int sampleRate, int resolution,
+    NoteModel(sv_samplerate_t sampleRate, int resolution,
 	      float valueMinimum, float valueMaximum,
 	      bool notifyOnAdd = true) :
 	IntervalModel<Note>(sampleRate, resolution,
@@ -202,7 +202,7 @@
         command->deletePoint(point);
 
         switch (column) {
-        case 4: point.level = value.toDouble(); break;
+        case 4: point.level = float(value.toDouble()); break;
         case 5: point.label = value.toString(); break;
         }
 
@@ -224,7 +224,7 @@
         return getNotesWithin(getStartFrame(), getEndFrame());
     }
 
-    NoteList getNotesWithin(int startFrame, int endFrame) const {
+    NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const {
         
 	PointList points = getPoints(startFrame, endFrame);
         NoteList notes;
@@ -232,16 +232,16 @@
         for (PointList::iterator pli =
 		 points.begin(); pli != points.end(); ++pli) {
 
-	    int duration = pli->duration;
+	    sv_frame_t duration = pli->duration;
             if (duration == 0 || duration == 1) {
-                duration = getSampleRate() / 20;
+                duration = sv_frame_t(getSampleRate() / 20);
             }
 
-            int pitch = lrintf(pli->value);
+            int pitch = int(lrintf(pli->value));
             
             int velocity = 100;
             if (pli->level > 0.f && pli->level <= 1.f) {
-                velocity = lrintf(pli->level * 127);
+                velocity = int(lrintf(pli->level * 127));
             }
 
             NoteData note(pli->frame, duration, pitch, velocity);
--- a/data/model/PathModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/PathModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -19,20 +19,21 @@
 #include "Model.h"
 #include "SparseModel.h"
 #include "base/RealTime.h"
+#include "base/BaseTypes.h"
 
 #include <QStringList>
 
 
 struct PathPoint
 {
-    PathPoint(long _frame) : frame(_frame), mapframe(_frame) { }
-    PathPoint(long _frame, long _mapframe) :
+    PathPoint(sv_frame_t _frame) : frame(_frame), mapframe(_frame) { }
+    PathPoint(sv_frame_t _frame, sv_frame_t _mapframe) :
         frame(_frame), mapframe(_mapframe) { }
 
     int getDimensions() const { return 2; }
 
-    long frame;
-    long mapframe;
+    sv_frame_t frame;
+    sv_frame_t mapframe;
 
     QString getLabel() const { return ""; }
 
@@ -43,7 +44,7 @@
     }
         
     QString toDelimitedDataString(QString delimiter,
-                                  int sampleRate) const {
+                                  sv_samplerate_t sampleRate) const {
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
         list << QString("%1").arg(mapframe);
@@ -67,7 +68,7 @@
 class PathModel : public SparseModel<PathPoint>
 {
 public:
-    PathModel(int sampleRate, int resolution, bool notify = true) :
+    PathModel(sv_samplerate_t sampleRate, int resolution, bool notify = true) :
         SparseModel<PathPoint>(sampleRate, resolution, notify) { }
 
     virtual void toXml(QTextStream &out,
--- a/data/model/PowerOfSqrtTwoZoomConstraint.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/PowerOfSqrtTwoZoomConstraint.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -44,12 +44,13 @@
 	float val = 1.0, prevVal = 1.0;
 	while (val + 0.01 < blockSize) {
 	    prevVal = val;
-	    val *= sqrt(2.f);
+	    val *= sqrtf(2.f);
 	}
 	int rval;
-	if (dir == RoundUp) rval = int(val + 0.01);
-	else if (dir == RoundDown) rval = int(prevVal + 0.01);
-	else if (val - blockSize < blockSize - prevVal) rval = int(val + 0.01);
+	if (dir == RoundUp) rval = int(val + 0.01f);
+	else if (dir == RoundDown) rval = int(prevVal + 0.01f);
+	else if (val - float(blockSize) <
+                 float(blockSize) - prevVal) rval = int(val + 0.01f);
 	else rval = int(prevVal + 0.01);
 //	SVDEBUG << "returning " << rval << endl;
 	return rval;
--- a/data/model/RangeSummarisableTimeValueModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/RangeSummarisableTimeValueModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -41,21 +41,33 @@
     {
     public:
         Range() : 
-            m_min(0.f), m_max(0.f), m_absmean(0.f) { }
+            m_new(true), m_min(0.f), m_max(0.f), m_absmean(0.f) { }
         Range(const Range &r) : 
-            m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
+            m_new(true), m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
         Range(float min, float max, float absmean) :
-            m_min(min), m_max(max), m_absmean(absmean) { }
+            m_new(true), m_min(min), m_max(max), m_absmean(absmean) { }
 
         float min() const { return m_min; }
         float max() const { return m_max; }
         float absmean() const { return m_absmean; }
 
-        void setMin(float min) { m_min = min; }
-        void setMax(float max) { m_max = max; }
+        void setMin(float min) { m_min = min; m_new = false; }
+        void setMax(float max) { m_max = max; m_new = false; }
         void setAbsmean(float absmean) { m_absmean = absmean; }
 
+        void sample(float s) {
+            if (m_new) {
+                m_min = s;
+                m_max = s;
+                m_new = false;
+            } else {
+                if (s < m_min) m_min = s;
+                if (s > m_max) m_max = s;
+            }
+        }
+        
     private:
+        bool m_new;
         float m_min;
         float m_max;
         float m_absmean;
@@ -74,7 +86,7 @@
      * parameter so as to return the block size that was actually
      * obtained.
      */
-    virtual void getSummaries(int channel, int start, int count,
+    virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
                               RangeBlock &ranges,
                               int &blockSize) const = 0;
 
@@ -83,7 +95,7 @@
      * the given number of underlying sample frames, summarised at a
      * block size equal to the distance between start and end frames.
      */
-    virtual Range getSummary(int channel, int start, int count) const = 0;
+    virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const = 0;
 
     virtual int getSummaryBlockSize(int desired) const = 0;
 
--- a/data/model/RegionModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/RegionModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -37,15 +37,15 @@
 {
 public:
     RegionRec() : frame(0), value(0.f), duration(0) { }
-    RegionRec(long _frame) : frame(_frame), value(0.0f), duration(0) { }
-    RegionRec(long _frame, float _value, int _duration, QString _label) :
+    RegionRec(sv_frame_t _frame) : frame(_frame), value(0.0f), duration(0) { }
+    RegionRec(sv_frame_t _frame, float _value, sv_frame_t _duration, QString _label) :
 	frame(_frame), value(_value), duration(_duration), label(_label) { }
 
     int getDimensions() const { return 3; }
 
-    long frame;
+    sv_frame_t frame;
     float value;
-    int duration;
+    sv_frame_t duration;
     QString label;
 
     QString getLabel() const { return label; }
@@ -60,7 +60,7 @@
             .arg(XmlExportable::encodeEntities(label)).arg(extraAttributes);
     }
 
-    QString toDelimitedDataString(QString delimiter, int sampleRate) const
+    QString toDelimitedDataString(QString delimiter, sv_samplerate_t sampleRate) const
     {
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
@@ -94,7 +94,7 @@
     Q_OBJECT
     
 public:
-    RegionModel(int sampleRate, int resolution,
+    RegionModel(sv_samplerate_t sampleRate, int resolution,
                 bool notifyOnAdd = true) :
 	IntervalModel<RegionRec>(sampleRate, resolution, notifyOnAdd),
 	m_valueQuantization(0),
@@ -102,7 +102,7 @@
     {
     }
 
-    RegionModel(int sampleRate, int resolution,
+    RegionModel(sv_samplerate_t sampleRate, int resolution,
                 float valueMinimum, float valueMaximum,
                 bool notifyOnAdd = true) :
 	IntervalModel<RegionRec>(sampleRate, resolution,
--- a/data/model/SparseModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/SparseModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -43,14 +43,14 @@
                     public TabularModel
 {
 public:
-    SparseModel(int sampleRate, int resolution,
+    SparseModel(sv_samplerate_t sampleRate, int resolution,
 		bool notifyOnAdd = true);
     virtual ~SparseModel() { }
     
     virtual bool isOK() const { return true; }
-    virtual int getStartFrame() const;
-    virtual int getEndFrame() const;
-    virtual int getSampleRate() const { return m_sampleRate; }
+    virtual sv_frame_t getStartFrame() const;
+    virtual sv_frame_t getEndFrame() const;
+    virtual sv_samplerate_t getSampleRate() const { return m_sampleRate; }
 
     virtual Model *clone() const;
 
@@ -91,25 +91,25 @@
      * after the boundaries.  If you need exact boundaries, check the
      * point coordinates in the returned list.
      */
-    virtual PointList getPoints(long start, long end) const;
+    virtual PointList getPoints(sv_frame_t start, sv_frame_t end) const;
 
     /**
      * Get all points that cover the given frame number, taking the
      * resolution of the model into account.
      */
-    virtual PointList getPoints(long frame) const;
+    virtual PointList getPoints(sv_frame_t frame) const;
 
     /**
      * Return all points that share the nearest frame number prior to
      * the given one at which there are any points.
      */
-    virtual PointList getPreviousPoints(long frame) const;
+    virtual PointList getPreviousPoints(sv_frame_t frame) const;
 
     /**
      * Return all points that share the nearest frame number
      * subsequent to the given one at which there are any points.
      */
-    virtual PointList getNextPoints(long frame) const;
+    virtual PointList getNextPoints(sv_frame_t frame) const;
 
     /**
      * Remove all points.
@@ -157,11 +157,11 @@
         return s;
     }
 
-    virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
+    virtual QString toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const
     { 
         QString s;
         for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) {
-            if (i->frame >= (long)f0 && i->frame < (long)f1) {
+            if (i->frame >= f0 && i->frame < f1) {
                 s += i->toDelimitedDataString(delimiter, m_sampleRate) + "\n";
             }
         }
@@ -284,31 +284,26 @@
 
     virtual int getRowCount() const
     {
-        return m_points.size();
+        return int(m_points.size());
     }
 
-    virtual long getFrameForRow(int row) const
+    virtual sv_frame_t getFrameForRow(int row) const
     {
         PointListConstIterator i = getPointListIteratorForRow(row);
         if (i == m_points.end()) return 0;
         return i->frame;
     }
 
-    virtual int getRowForFrame(long frame) const
+    virtual int getRowForFrame(sv_frame_t frame) const
     {
         if (m_rows.empty()) rebuildRowVector();
-        std::vector<long>::iterator i =
+        std::vector<sv_frame_t>::iterator i =
             std::lower_bound(m_rows.begin(), m_rows.end(), frame);
-#if defined(__SUNPRO_CC) && defined(__STD_RW_ITERATOR__)
-        int row = 0;
-        std::distance(m_rows.begin(), i, row);
-#else
-        int row = std::distance(m_rows.begin(), i);
-#endif
+        ssize_t row = std::distance(m_rows.begin(), i);
         if (i != m_rows.begin() && (i == m_rows.end() || *i != frame)) {
             --row;
         }
-        return row;
+        return int(row);
     }
 
     virtual int getColumnCount() const { return 1; }
@@ -371,11 +366,11 @@
     }
             
 protected:
-    int m_sampleRate;
+    sv_samplerate_t m_sampleRate;
     int m_resolution;
     bool m_notifyOnAdd;
-    long m_sinceLastNotifyMin;
-    long m_sinceLastNotifyMax;
+    sv_frame_t m_sinceLastNotifyMin;
+    sv_frame_t m_sinceLastNotifyMax;
     bool m_hasTextLabels;
 
     PointList m_points;
@@ -383,16 +378,16 @@
     mutable QMutex m_mutex;
     int m_completion;
 
-    void getPointIterators(long frame,
+    void getPointIterators(sv_frame_t frame,
                            PointListIterator &startItr,
                            PointListIterator &endItr);
-    void getPointIterators(long frame,
+    void getPointIterators(sv_frame_t frame,
                            PointListConstIterator &startItr,
                            PointListConstIterator &endItr) const;
 
     // This is only used if the model is called on to act in
     // TabularModel mode
-    mutable std::vector<long> m_rows; // map from row number to frame
+    mutable std::vector<sv_frame_t> m_rows; // map from row number to frame
     void rebuildRowVector() const
     {
         m_rows.clear();
@@ -407,7 +402,7 @@
         if (m_rows.empty()) rebuildRowVector();
         if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
 
-        int frame = m_rows[row];
+        sv_frame_t frame = m_rows[row];
         int indexAtFrame = 0;
         int ri = row;
         while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
@@ -434,7 +429,7 @@
         if (m_rows.empty()) rebuildRowVector();
         if (row < 0 || row + 1 > int(m_rows.size())) return m_points.end();
 
-        int frame = m_rows[row];
+        sv_frame_t frame = m_rows[row];
         int indexAtFrame = 0;
         int ri = row;
         while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; }
@@ -465,7 +460,7 @@
 
 
 template <typename PointType>
-SparseModel<PointType>::SparseModel(int sampleRate,
+SparseModel<PointType>::SparseModel(sv_samplerate_t sampleRate,
                                     int resolution,
                                     bool notifyOnAdd) :
     m_sampleRate(sampleRate),
@@ -480,11 +475,11 @@
 }
 
 template <typename PointType>
-int
+sv_frame_t
 SparseModel<PointType>::getStartFrame() const
 {
     QMutexLocker locker(&m_mutex);
-    int f = 0;
+    sv_frame_t f = 0;
     if (!m_points.empty()) {
 	f = m_points.begin()->frame;
     }
@@ -492,11 +487,11 @@
 }
 
 template <typename PointType>
-int
+sv_frame_t
 SparseModel<PointType>::getEndFrame() const
 {
     QMutexLocker locker(&m_mutex);
-    int f = 0;
+    sv_frame_t f = 0;
     if (!m_points.empty()) {
 	PointListConstIterator i(m_points.end());
 	f = (--i)->frame;
@@ -541,7 +536,7 @@
 
 template <typename PointType>
 typename SparseModel<PointType>::PointList
-SparseModel<PointType>::getPoints(long start, long end) const
+SparseModel<PointType>::getPoints(sv_frame_t start, sv_frame_t end) const
 {
     if (start > end) return PointList();
     QMutexLocker locker(&m_mutex);
@@ -567,7 +562,7 @@
 
 template <typename PointType>
 typename SparseModel<PointType>::PointList
-SparseModel<PointType>::getPoints(long frame) const
+SparseModel<PointType>::getPoints(sv_frame_t frame) const
 {
     PointListConstIterator startItr, endItr;
     getPointIterators(frame, startItr, endItr);
@@ -583,7 +578,7 @@
 
 template <typename PointType>
 void
-SparseModel<PointType>::getPointIterators(long frame,
+SparseModel<PointType>::getPointIterators(sv_frame_t frame,
                                           PointListIterator &startItr,
                                           PointListIterator &endItr)
 {
@@ -595,8 +590,8 @@
         return;
     }
 
-    long start = (frame / m_resolution) * m_resolution;
-    long end = start + m_resolution;
+    sv_frame_t start = (frame / m_resolution) * m_resolution;
+    sv_frame_t end = start + m_resolution;
 
     PointType startPoint(start), endPoint(end);
 
@@ -606,7 +601,7 @@
 
 template <typename PointType>
 void
-SparseModel<PointType>::getPointIterators(long frame,
+SparseModel<PointType>::getPointIterators(sv_frame_t frame,
                                           PointListConstIterator &startItr,
                                           PointListConstIterator &endItr) const
 {
@@ -619,8 +614,8 @@
         return;
     }
 
-    long start = (frame / m_resolution) * m_resolution;
-    long end = start + m_resolution;
+    sv_frame_t start = (frame / m_resolution) * m_resolution;
+    sv_frame_t end = start + m_resolution;
 
     PointType startPoint(start), endPoint(end);
     
@@ -632,7 +627,7 @@
 
 template <typename PointType>
 typename SparseModel<PointType>::PointList
-SparseModel<PointType>::getPreviousPoints(long originFrame) const
+SparseModel<PointType>::getPreviousPoints(sv_frame_t originFrame) const
 {
     QMutexLocker locker(&m_mutex);
 
@@ -643,7 +638,7 @@
     if (i == m_points.begin()) return rv;
 
     --i;
-    long frame = i->frame;
+    sv_frame_t frame = i->frame;
     while (i->frame == frame) {
 	rv.insert(*i);
 	if (i == m_points.begin()) break;
@@ -655,7 +650,7 @@
  
 template <typename PointType>
 typename SparseModel<PointType>::PointList
-SparseModel<PointType>::getNextPoints(long originFrame) const
+SparseModel<PointType>::getNextPoints(sv_frame_t originFrame) const
 {
     QMutexLocker locker(&m_mutex);
 
@@ -665,7 +660,7 @@
     PointListConstIterator i = m_points.upper_bound(lookupPoint);
     if (i == m_points.end()) return rv;
 
-    long frame = i->frame;
+    sv_frame_t frame = i->frame;
     while (i != m_points.end() && i->frame == frame) {
 	rv.insert(*i);
 	++i;
--- a/data/model/SparseOneDimensionalModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/SparseOneDimensionalModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -26,12 +26,12 @@
 struct OneDimensionalPoint
 {
 public:
-    OneDimensionalPoint(int _frame) : frame(_frame) { }
-    OneDimensionalPoint(int _frame, QString _label) : frame(_frame), label(_label) { }
+    OneDimensionalPoint(sv_frame_t _frame) : frame(_frame) { }
+    OneDimensionalPoint(sv_frame_t _frame, QString _label) : frame(_frame), label(_label) { }
 
     int getDimensions() const { return 1; }
     
-    int frame;
+    sv_frame_t frame;
     QString label;
 
     QString getLabel() const { return label; }
@@ -45,7 +45,7 @@
             .arg(extraAttributes);
     }
 
-    QString toDelimitedDataString(QString delimiter, int sampleRate) const
+    QString toDelimitedDataString(QString delimiter, sv_samplerate_t sampleRate) const
     {
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
@@ -76,7 +76,7 @@
     Q_OBJECT
     
 public:
-    SparseOneDimensionalModel(int sampleRate, int resolution,
+    SparseOneDimensionalModel(sv_samplerate_t sampleRate, int resolution,
 			      bool notifyOnAdd = true) :
 	SparseModel<OneDimensionalPoint>(sampleRate, resolution, notifyOnAdd)
     {
@@ -187,7 +187,7 @@
         return getNotesWithin(getStartFrame(), getEndFrame());
     }
 
-    NoteList getNotesWithin(int startFrame, int endFrame) const {
+    NoteList getNotesWithin(sv_frame_t startFrame, sv_frame_t endFrame) const {
         
 	PointList points = getPoints(startFrame, endFrame);
         NoteList notes;
@@ -197,7 +197,7 @@
 
             notes.push_back
                 (NoteData(pli->frame,
-                          getSampleRate() / 6, // arbitrary short duration
+                          sv_frame_t(getSampleRate() / 6), // arbitrary short duration
                           64,   // default pitch
                           100)); // default velocity
         }
--- a/data/model/SparseTimeValueModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/SparseTimeValueModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -49,7 +49,7 @@
             .arg(extraAttributes);
     }
 
-    QString toDelimitedDataString(QString delimiter, int sampleRate) const
+    QString toDelimitedDataString(QString delimiter, sv_samplerate_t sampleRate) const
     {
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
@@ -81,7 +81,7 @@
     Q_OBJECT
     
 public:
-    SparseTimeValueModel(int sampleRate, int resolution,
+    SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution,
 			 bool notifyOnAdd = true) :
 	SparseValueModel<TimeValuePoint>(sampleRate, resolution,
 					 notifyOnAdd)
@@ -91,7 +91,7 @@
 	PlayParameterRepository::getInstance()->addPlayable(this);
     }
 
-    SparseTimeValueModel(int sampleRate, int resolution,
+    SparseTimeValueModel(sv_samplerate_t sampleRate, int resolution,
 			 float valueMinimum, float valueMaximum,
 			 bool notifyOnAdd = true) :
 	SparseValueModel<TimeValuePoint>(sampleRate, resolution,
@@ -168,7 +168,7 @@
         command->deletePoint(point);
 
         switch (column) {
-        case 2: point.value = value.toDouble(); break;
+        case 2: point.value = float(value.toDouble()); break;
         case 3: point.label = value.toString(); break;
         }
 
--- a/data/model/SparseValueModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/SparseValueModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -31,7 +31,7 @@
 class SparseValueModel : public SparseModel<PointType>
 {
 public:
-    SparseValueModel(int sampleRate, int resolution,
+    SparseValueModel(sv_samplerate_t sampleRate, int resolution,
 		     bool notifyOnAdd = true) :
 	SparseModel<PointType>(sampleRate, resolution, notifyOnAdd),
 	m_valueMinimum(0.f),
@@ -39,7 +39,7 @@
         m_haveExtents(false)
     { }
 
-    SparseValueModel(int sampleRate, int resolution,
+    SparseValueModel(sv_samplerate_t sampleRate, int resolution,
 		     float valueMinimum, float valueMaximum,
 		     bool notifyOnAdd = true) :
 	SparseModel<PointType>(sampleRate, resolution, notifyOnAdd),
--- a/data/model/TabularModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/TabularModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -48,8 +48,8 @@
     virtual bool isColumnTimeValue(int col) const = 0;
     virtual SortType getSortType(int col) const = 0;
 
-    virtual long getFrameForRow(int row) const = 0;
-    virtual int getRowForFrame(long frame) const = 0;
+    virtual sv_frame_t getFrameForRow(int row) const = 0;
+    virtual int getRowForFrame(sv_frame_t frame) const = 0;
 
     virtual bool isEditable() const { return false; }
     virtual Command *getSetDataCommand(int /* row */, int /* column */, const QVariant &, int /* role */) { return 0; }
--- a/data/model/TextModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/TextModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -31,13 +31,13 @@
 struct TextPoint : public XmlExportable
 {
 public:
-    TextPoint(long _frame) : frame(_frame), height(0.0f) { }
-    TextPoint(long _frame, float _height, QString _label) : 
+    TextPoint(sv_frame_t _frame) : frame(_frame), height(0.0f) { }
+    TextPoint(sv_frame_t _frame, float _height, QString _label) : 
 	frame(_frame), height(_height), label(_label) { }
 
     int getDimensions() const { return 2; }
     
-    long frame;
+    sv_frame_t frame;
     float height;
     QString label;
 
@@ -51,7 +51,7 @@
             .arg(encodeEntities(label)).arg(extraAttributes);
     }
 
-    QString toDelimitedDataString(QString delimiter, int sampleRate) const
+    QString toDelimitedDataString(QString delimiter, sv_samplerate_t sampleRate) const
     {
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
@@ -85,7 +85,7 @@
     Q_OBJECT
     
 public:
-    TextModel(int sampleRate, int resolution, bool notifyOnAdd = true) :
+    TextModel(sv_samplerate_t sampleRate, int resolution, bool notifyOnAdd = true) :
 	SparseModel<TextPoint>(sampleRate, resolution, notifyOnAdd)
     { }
 
@@ -155,7 +155,7 @@
         command->deletePoint(point);
 
         switch (column) {
-        case 2: point.height = value.toDouble(); break;
+        case 2: point.height = float(value.toDouble()); break;
         case 3: point.label = value.toString(); break;
         }
 
--- a/data/model/WaveFileModel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/WaveFileModel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -37,7 +37,7 @@
 PowerOfSqrtTwoZoomConstraint
 WaveFileModel::m_zoomConstraint;
 
-WaveFileModel::WaveFileModel(FileSource source, int targetRate) :
+WaveFileModel::WaveFileModel(FileSource source, sv_samplerate_t targetRate) :
     m_source(source),
     m_path(source.getLocation()),
     m_reader(0),
@@ -131,7 +131,7 @@
     return model;
 }
 
-int
+sv_frame_t
 WaveFileModel::getFrameCount() const
 {
     if (!m_reader) return 0;
@@ -145,18 +145,18 @@
     return m_reader->getChannelCount();
 }
 
-int
+sv_samplerate_t
 WaveFileModel::getSampleRate() const 
 {
     if (!m_reader) return 0;
     return m_reader->getSampleRate();
 }
 
-int
+sv_samplerate_t
 WaveFileModel::getNativeRate() const 
 {
     if (!m_reader) return 0;
-    int rate = m_reader->getNativeRate();
+    sv_samplerate_t rate = m_reader->getNativeRate();
     if (rate == 0) rate = getSampleRate();
     return rate;
 }
@@ -191,8 +191,8 @@
     return "";
 }
     
-int
-WaveFileModel::getData(int channel, int start, int count,
+sv_frame_t
+WaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count,
                        float *buffer) const
 {
     // Always read these directly from the file. 
@@ -206,7 +206,7 @@
     if (start >= m_startFrame) {
         start -= m_startFrame;
     } else {
-        for (int i = 0; i < count; ++i) {
+        for (sv_frame_t i = 0; i < count; ++i) {
             buffer[i] = 0.f;
         }
         if (count <= m_startFrame - start) {
@@ -218,7 +218,7 @@
     }
 
     if (!m_reader || !m_reader->isOK() || count == 0) {
-        for (int i = 0; i < count; ++i) buffer[i] = 0.f;
+        for (sv_frame_t i = 0; i < count; ++i) buffer[i] = 0.f;
         return 0;
     }
 
@@ -229,10 +229,9 @@
 
     int channels = getChannelCount();
 
-    SampleBlock frames(count * channels);
-    m_reader->getInterleavedFrames(start, count, frames);
+    SampleBlock frames = m_reader->getInterleavedFrames(start, count);
 
-    int i = 0;
+    sv_frame_t i = 0;
 
     int ch0 = channel, ch1 = channel;
     if (channel == -1) {
@@ -246,8 +245,8 @@
 
 	for (int ch = ch0; ch <= ch1; ++ch) {
 
-	    int index = i * channels + ch;
-	    if (index >= (int)frames.size()) break;
+	    sv_frame_t index = i * channels + ch;
+	    if (index >= (sv_frame_t)frames.size()) break;
             
 	    float sample = frames[index];
 	    buffer[i] += sample;
@@ -259,8 +258,8 @@
     return i;
 }
 
-int
-WaveFileModel::getData(int channel, int start, int count,
+sv_frame_t
+WaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count,
                        double *buffer) const
 {
 #ifdef DEBUG_WAVE_FILE_MODEL
@@ -270,7 +269,7 @@
     if (start > m_startFrame) {
         start -= m_startFrame;
     } else {
-        for (int i = 0; i < count; ++i) buffer[i] = 0.0;
+        for (sv_frame_t i = 0; i < count; ++i) buffer[i] = 0.0;
         if (count <= m_startFrame - start) {
             return 0;
         } else {
@@ -280,16 +279,15 @@
     }
 
     if (!m_reader || !m_reader->isOK() || count == 0) {
-        for (int i = 0; i < count; ++i) buffer[i] = 0.0;
+        for (sv_frame_t i = 0; i < count; ++i) buffer[i] = 0.0;
         return 0;
     }
 
     int channels = getChannelCount();
 
-    SampleBlock frames(count * channels);
-    m_reader->getInterleavedFrames(start, count, frames);
+    SampleBlock frames = m_reader->getInterleavedFrames(start, count);
 
-    int i = 0;
+    sv_frame_t i = 0;
 
     int ch0 = channel, ch1 = channel;
     if (channel == -1) {
@@ -303,8 +301,8 @@
 
 	for (int ch = ch0; ch <= ch1; ++ch) {
 
-	    int index = i * channels + ch;
-	    if (index >= (int)frames.size()) break;
+	    sv_frame_t index = i * channels + ch;
+	    if (index >= (sv_frame_t)frames.size()) break;
             
 	    float sample = frames[index];
 	    buffer[i] += sample;
@@ -316,9 +314,9 @@
     return i;
 }
 
-int
+sv_frame_t
 WaveFileModel::getData(int fromchannel, int tochannel,
-                       int start, int count,
+                       sv_frame_t start, sv_frame_t count,
                        float **buffer) const
 {
 #ifdef DEBUG_WAVE_FILE_MODEL
@@ -355,7 +353,7 @@
         start -= m_startFrame;
     } else {
         for (int c = 0; c < reqchannels; ++c) {
-            for (int i = 0; i < count; ++i) buffer[c][i] = 0.f;
+            for (sv_frame_t i = 0; i < count; ++i) buffer[c][i] = 0.f;
         }
         if (count <= m_startFrame - start) {
             return 0;
@@ -367,17 +365,16 @@
 
     if (!m_reader || !m_reader->isOK() || count == 0) {
         for (int c = 0; c < reqchannels; ++c) {
-            for (int i = 0; i < count; ++i) buffer[c][i] = 0.f;
+            for (sv_frame_t i = 0; i < count; ++i) buffer[c][i] = 0.f;
         }
         return 0;
     }
 
-    SampleBlock frames(count * channels);
-    m_reader->getInterleavedFrames(start, count, frames);
+    SampleBlock frames = m_reader->getInterleavedFrames(start, count);
 
-    int i = 0;
+    sv_frame_t i = 0;
 
-    int index = 0, available = frames.size();
+    sv_frame_t index = 0, available = frames.size();
 
     while (i < count) {
 
@@ -418,7 +415,7 @@
 }    
 
 void
-WaveFileModel::getSummaries(int channel, int start, int count,
+WaveFileModel::getSummaries(int channel, sv_frame_t start, sv_frame_t count,
                             RangeBlock &ranges, int &blockSize) const
 {
     ranges.clear();
@@ -455,18 +452,18 @@
             m_lastDirectReadCount != count ||
             m_directRead.empty()) {
 
-            m_reader->getInterleavedFrames(start, count, m_directRead);
+            m_directRead = m_reader->getInterleavedFrames(start, count);
             m_lastDirectReadStart = start;
             m_lastDirectReadCount = count;
         }
 
 	float max = 0.0, min = 0.0, total = 0.0;
-	int i = 0, got = 0;
+	sv_frame_t i = 0, got = 0;
 
 	while (i < count) {
 
-	    int index = i * channels + channel;
-	    if (index >= (int)m_directRead.size()) break;
+	    sv_frame_t index = i * channels + channel;
+	    if (index >= (sv_frame_t)m_directRead.size()) break;
             
 	    float sample = m_directRead[index];
             if (sample > max || got == 0) max = sample;
@@ -477,7 +474,7 @@
             ++got;
             
             if (got == blockSize) {
-                ranges.push_back(Range(min, max, total / got));
+                ranges.push_back(Range(min, max, total / float(got)));
                 min = max = total = 0.0f;
                 got = 0;
 	    }
@@ -486,7 +483,7 @@
         m_directReadMutex.unlock();
 
 	if (got > 0) {
-            ranges.push_back(Range(min, max, total / got));
+            ranges.push_back(Range(min, max, total / float(got)));
 	}
 
 	return;
@@ -499,21 +496,21 @@
 
         blockSize = roundedBlockSize;
 
-	int cacheBlock, div;
+	sv_frame_t cacheBlock, div;
         
 	if (cacheType == 0) {
 	    cacheBlock = (1 << m_zoomConstraint.getMinCachePower());
             div = (1 << power) / cacheBlock;
 	} else {
-	    cacheBlock = ((unsigned int)((1 << m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01));
-            div = ((unsigned int)((1 << power) * sqrt(2.) + 0.01)) / cacheBlock;
+	    cacheBlock = sv_frame_t((1 << m_zoomConstraint.getMinCachePower()) * sqrt(2.) + 0.01);
+            div = sv_frame_t(((1 << power) * sqrt(2.) + 0.01) / double(cacheBlock));
 	}
 
-	int startIndex = start / cacheBlock;
-	int endIndex = (start + count) / cacheBlock;
+	sv_frame_t startIndex = start / cacheBlock;
+	sv_frame_t endIndex = (start + count) / cacheBlock;
 
 	float max = 0.0, min = 0.0, total = 0.0;
-	int i = 0, got = 0;
+	sv_frame_t i = 0, got = 0;
 
 #ifdef DEBUG_WAVE_FILE_MODEL
 	cerr << "blockSize is " << blockSize << ", cacheBlock " << cacheBlock << ", start " << start << ", count " << count << " (frame count " << getFrameCount() << "), power is " << power << ", div is " << div << ", startIndex " << startIndex << ", endIndex " << endIndex << endl;
@@ -521,8 +518,8 @@
 
 	for (i = 0; i <= endIndex - startIndex; ) {
         
-	    int index = (i + startIndex) * channels + channel;
-	    if (index >= (int)cache.size()) break;
+	    sv_frame_t index = (i + startIndex) * channels + channel;
+	    if (index >= (sv_frame_t)cache.size()) break;
             
             const Range &range = cache[index];
             if (range.max() > max || got == 0) max = range.max();
@@ -533,14 +530,14 @@
             ++got;
             
 	    if (got == div) {
-		ranges.push_back(Range(min, max, total / got));
+		ranges.push_back(Range(min, max, total / float(got)));
                 min = max = total = 0.0f;
                 got = 0;
 	    }
 	}
 		
 	if (got > 0) {
-            ranges.push_back(Range(min, max, total / got));
+            ranges.push_back(Range(min, max, total / float(got)));
 	}
     }
 
@@ -551,7 +548,7 @@
 }
 
 WaveFileModel::Range
-WaveFileModel::getSummary(int channel, int start, int count) const
+WaveFileModel::getSummary(int channel, sv_frame_t start, sv_frame_t count) const
 {
     Range range;
     if (!isOK()) return range;
@@ -569,8 +566,8 @@
 
     bool first = false;
 
-    int blockStart = (start / blockSize) * blockSize;
-    int blockEnd = ((start + count) / blockSize) * blockSize;
+    sv_frame_t blockStart = (start / blockSize) * blockSize;
+    sv_frame_t blockEnd = ((start + count) / blockSize) * blockSize;
 
     if (blockStart < start) blockStart += blockSize;
         
@@ -626,7 +623,7 @@
 WaveFileModel::fillTimerTimedOut()
 {
     if (m_fillThread) {
-	int fillExtent = m_fillThread->getFillExtent();
+	sv_frame_t fillExtent = m_fillThread->getFillExtent();
 #ifdef DEBUG_WAVE_FILE_MODEL
         SVDEBUG << "WaveFileModel::fillTimerTimedOut: extent = " << fillExtent << endl;
 #endif
@@ -666,11 +663,11 @@
 {
     int cacheBlockSize[2];
     cacheBlockSize[0] = (1 << m_model.m_zoomConstraint.getMinCachePower());
-    cacheBlockSize[1] = ((unsigned int)((1 << m_model.m_zoomConstraint.getMinCachePower()) *
+    cacheBlockSize[1] = (int((1 << m_model.m_zoomConstraint.getMinCachePower()) *
                                         sqrt(2.) + 0.01));
     
-    int frame = 0;
-    int readBlockSize = 16384;
+    sv_frame_t frame = 0;
+    const sv_frame_t readBlockSize = 16384;
     SampleBlock block;
 
     if (!m_model.isOK()) return;
@@ -709,50 +706,44 @@
 
             if (updating && (frame + readBlockSize > m_frameCount)) break;
 
-            m_model.m_reader->getInterleavedFrames(frame, readBlockSize, block);
+            block = m_model.m_reader->getInterleavedFrames(frame, readBlockSize);
 
 //            cerr << "block is " << block.size() << endl;
 
-            for (int i = 0; i < readBlockSize; ++i) {
+            for (sv_frame_t i = 0; i < readBlockSize; ++i) {
 		
                 if (channels * i + channels > (int)block.size()) break;
 
                 for (int ch = 0; ch < channels; ++ch) {
 
-                    int index = channels * i + ch;
+                    sv_frame_t index = channels * i + ch;
                     float sample = block[index];
                     
-                    for (int ct = 0; ct < 2; ++ct) { // cache type
+                    for (int cacheType = 0; cacheType < 2; ++cacheType) { // cache type
                         
-                        int rangeIndex = ch * 2 + ct;
-                        
-                        if (sample > range[rangeIndex].max() || count[ct] == 0) {
-                            range[rangeIndex].setMax(sample);
-                        }
-                        if (sample < range[rangeIndex].min() || count[ct] == 0) {
-                            range[rangeIndex].setMin(sample);
-                        }
-
+                        sv_frame_t rangeIndex = ch * 2 + cacheType;
+                        range[rangeIndex].sample(sample);
                         means[rangeIndex] += fabsf(sample);
                     }
                 }
-                
+
+                //!!! this looks like a ludicrous way to do synchronisation
                 QMutexLocker locker(&m_model.m_mutex);
 
-                for (int ct = 0; ct < 2; ++ct) {
+                for (int cacheType = 0; cacheType < 2; ++cacheType) {
 
-                    if (++count[ct] == cacheBlockSize[ct]) {
+                    if (++count[cacheType] == cacheBlockSize[cacheType]) {
                         
                         for (int ch = 0; ch < int(channels); ++ch) {
-                            int rangeIndex = ch * 2 + ct;
-                            means[rangeIndex] /= count[ct];
+                            int rangeIndex = ch * 2 + cacheType;
+                            means[rangeIndex] = means[rangeIndex] / float(count[cacheType]);
                             range[rangeIndex].setAbsmean(means[rangeIndex]);
-                            m_model.m_cache[ct].push_back(range[rangeIndex]);
+                            m_model.m_cache[cacheType].push_back(range[rangeIndex]);
                             range[rangeIndex] = Range();
                             means[rangeIndex] = 0.f;
                         }
 
-                        count[ct] = 0;
+                        count[cacheType] = 0;
                     }
                 }
                 
@@ -778,24 +769,24 @@
 
         QMutexLocker locker(&m_model.m_mutex);
 
-        for (int ct = 0; ct < 2; ++ct) {
+        for (int cacheType = 0; cacheType < 2; ++cacheType) {
 
-            if (count[ct] > 0) {
+            if (count[cacheType] > 0) {
 
                 for (int ch = 0; ch < int(channels); ++ch) {
-                    int rangeIndex = ch * 2 + ct;
-                    means[rangeIndex] /= count[ct];
+                    int rangeIndex = ch * 2 + cacheType;
+                    means[rangeIndex] = means[rangeIndex] / float(count[cacheType]);
                     range[rangeIndex].setAbsmean(means[rangeIndex]);
-                    m_model.m_cache[ct].push_back(range[rangeIndex]);
+                    m_model.m_cache[cacheType].push_back(range[rangeIndex]);
                     range[rangeIndex] = Range();
                     means[rangeIndex] = 0.f;
                 }
 
-                count[ct] = 0;
+                count[cacheType] = 0;
             }
             
-            const Range &rr = *m_model.m_cache[ct].begin();
-            MUNLOCK(&rr, m_model.m_cache[ct].capacity() * sizeof(Range));
+            const Range &rr = *m_model.m_cache[cacheType].begin();
+            MUNLOCK(&rr, m_model.m_cache[cacheType].capacity() * sizeof(Range));
         }
     }
     
@@ -805,8 +796,8 @@
     m_fillExtent = m_frameCount;
 
 #ifdef DEBUG_WAVE_FILE_MODEL        
-    for (int ct = 0; ct < 2; ++ct) {
-        cerr << "Cache type " << ct << " now contains " << m_model.m_cache[ct].size() << " ranges" << endl;
+    for (int cacheType = 0; cacheType < 2; ++cacheType) {
+        cerr << "Cache type " << cacheType << " now contains " << m_model.m_cache[cacheType].size() << " ranges" << endl;
     }
 #endif
 }
--- a/data/model/WaveFileModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/WaveFileModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -34,7 +34,7 @@
     Q_OBJECT
 
 public:
-    WaveFileModel(FileSource source, int targetRate = 0);
+    WaveFileModel(FileSource source, sv_samplerate_t targetRate = 0);
     WaveFileModel(FileSource source, AudioFileReader *reader);
     ~WaveFileModel();
 
@@ -43,10 +43,10 @@
 
     const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; }
 
-    int getFrameCount() const;
+    sv_frame_t getFrameCount() const;
     int getChannelCount() const;
-    int getSampleRate() const;
-    int getNativeRate() const;
+    sv_samplerate_t getSampleRate() const;
+    sv_samplerate_t getNativeRate() const;
 
     QString getTitle() const;
     QString getMaker() const;
@@ -59,28 +59,28 @@
     float getValueMinimum() const { return -1.0f; }
     float getValueMaximum() const { return  1.0f; }
 
-    virtual int getStartFrame() const { return m_startFrame; }
-    virtual int getEndFrame() const { return m_startFrame + getFrameCount(); }
+    virtual sv_frame_t getStartFrame() const { return m_startFrame; }
+    virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); }
 
-    void setStartFrame(int startFrame) { m_startFrame = startFrame; }
+    void setStartFrame(sv_frame_t startFrame) { m_startFrame = startFrame; }
 
-    virtual int getData(int channel, int start, int count,
+    virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
                         float *buffer) const;
 
-    virtual int getData(int channel, int start, int count,
+    virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
                         double *buffer) const;
 
-    virtual int getData(int fromchannel, int tochannel,
-                        int start, int count,
+    virtual sv_frame_t getData(int fromchannel, int tochannel,
+                        sv_frame_t start, sv_frame_t count,
                         float **buffers) const;
 
     virtual int getSummaryBlockSize(int desired) const;
 
-    virtual void getSummaries(int channel, int start, int count,
+    virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
                               RangeBlock &ranges,
                               int &blockSize) const;
 
-    virtual Range getSummary(int channel, int start, int count) const;
+    virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const;
 
     QString getTypeName() const { return tr("Wave File"); }
 
@@ -102,13 +102,13 @@
 	    m_model(model), m_fillExtent(0),
             m_frameCount(model.getFrameCount()) { }
     
-	int getFillExtent() const { return m_fillExtent; }
+	sv_frame_t getFillExtent() const { return m_fillExtent; }
         virtual void run();
 
     protected:
         WaveFileModel &m_model;
-	int m_fillExtent;
-        int m_frameCount;
+	sv_frame_t m_fillExtent;
+        sv_frame_t m_frameCount;
     };
          
     void fillCache();
@@ -118,19 +118,19 @@
     AudioFileReader *m_reader;
     bool m_myReader;
 
-    int m_startFrame;
+    sv_frame_t m_startFrame;
 
     RangeBlock m_cache[2]; // interleaved at two base resolutions
     mutable QMutex m_mutex;
     RangeCacheFillThread *m_fillThread;
     QTimer *m_updateTimer;
-    int m_lastFillExtent;
+    sv_frame_t m_lastFillExtent;
     bool m_exiting;
     static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
 
     mutable SampleBlock m_directRead;
-    mutable int m_lastDirectReadStart;
-    mutable int m_lastDirectReadCount;
+    mutable sv_frame_t m_lastDirectReadStart;
+    mutable sv_frame_t m_lastDirectReadCount;
     mutable QMutex m_directReadMutex;
 };    
 
--- a/data/model/WritableWaveFileModel.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/WritableWaveFileModel.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -30,7 +30,7 @@
 
 //#define DEBUG_WRITABLE_WAVE_FILE_MODEL 1
 
-WritableWaveFileModel::WritableWaveFileModel(int sampleRate,
+WritableWaveFileModel::WritableWaveFileModel(sv_samplerate_t sampleRate,
 					     int channels,
 					     QString path) :
     m_model(0),
@@ -86,8 +86,8 @@
     m_model->setStartFrame(m_startFrame);
 
     connect(m_model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
-    connect(m_model, SIGNAL(modelChangedWithin(int, int)),
-            this, SIGNAL(modelChangedWithin(int, int)));
+    connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
+            this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)));
 }
 
 WritableWaveFileModel::~WritableWaveFileModel()
@@ -98,14 +98,14 @@
 }
 
 void
-WritableWaveFileModel::setStartFrame(int startFrame)
+WritableWaveFileModel::setStartFrame(sv_frame_t startFrame)
 {
     m_startFrame = startFrame;
     if (m_model) m_model->setStartFrame(startFrame);
 }
 
 bool
-WritableWaveFileModel::addSamples(float **samples, int count)
+WritableWaveFileModel::addSamples(float **samples, sv_frame_t count)
 {
     if (!m_writer) return false;
 
@@ -162,7 +162,7 @@
     }
 }
 
-int
+sv_frame_t
 WritableWaveFileModel::getFrameCount() const
 {
 //    SVDEBUG << "WritableWaveFileModel::getFrameCount: count = " << m_frameCount << endl;
@@ -176,25 +176,25 @@
     return 0;
 }
 
-int
-WritableWaveFileModel::getData(int channel, int start, int count,
+sv_frame_t
+WritableWaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count,
                                float *buffer) const
 {
     if (!m_model || m_model->getChannelCount() == 0) return 0;
     return m_model->getData(channel, start, count, buffer);
 }
 
-int
-WritableWaveFileModel::getData(int channel, int start, int count,
+sv_frame_t
+WritableWaveFileModel::getData(int channel, sv_frame_t start, sv_frame_t count,
                                double *buffer) const
 {
     if (!m_model || m_model->getChannelCount() == 0) return 0;
     return m_model->getData(channel, start, count, buffer);
 }
 
-int
+sv_frame_t
 WritableWaveFileModel::getData(int fromchannel, int tochannel,
-                               int start, int count,
+                               sv_frame_t start, sv_frame_t count,
                                float **buffers) const
 {
     if (!m_model || m_model->getChannelCount() == 0) return 0;
@@ -209,7 +209,7 @@
 }
 
 void
-WritableWaveFileModel::getSummaries(int channel, int start, int count,
+WritableWaveFileModel::getSummaries(int channel, sv_frame_t start, sv_frame_t count,
                                     RangeBlock &ranges,
                                     int &blockSize) const
 {
@@ -219,7 +219,7 @@
 }
 
 WritableWaveFileModel::Range
-WritableWaveFileModel::getSummary(int channel, int start, int count) const
+WritableWaveFileModel::getSummary(int channel, sv_frame_t start, sv_frame_t count) const
 {
     if (!m_model || m_model->getChannelCount() == 0) return Range();
     return m_model->getSummary(channel, start, count);
--- a/data/model/WritableWaveFileModel.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/model/WritableWaveFileModel.h	Mon Mar 23 11:26:28 2015 +0000
@@ -26,7 +26,7 @@
     Q_OBJECT
 
 public:
-    WritableWaveFileModel(int sampleRate, int channels, QString path = "");
+    WritableWaveFileModel(sv_samplerate_t sampleRate, int channels, QString path = "");
     ~WritableWaveFileModel();
 
     /**
@@ -35,7 +35,7 @@
      * progress of this file, if it has a known end point, and should
      * call setCompletion(100) when the file has been written.
      */
-    virtual bool addSamples(float **samples, int count);
+    virtual bool addSamples(float **samples, sv_frame_t count);
     
     bool isOK() const;
     bool isReady(int *) const;
@@ -48,36 +48,36 @@
         return &zc;
     }
 
-    int getFrameCount() const;
+    sv_frame_t getFrameCount() const;
     int getChannelCount() const { return m_channels; }
-    int getSampleRate() const { return m_sampleRate; }
+    sv_samplerate_t getSampleRate() const { return m_sampleRate; }
 
     virtual Model *clone() const;
 
     float getValueMinimum() const { return -1.0f; }
     float getValueMaximum() const { return  1.0f; }
 
-    virtual int getStartFrame() const { return m_startFrame; }
-    virtual int getEndFrame() const { return m_startFrame + getFrameCount(); }
+    virtual sv_frame_t getStartFrame() const { return m_startFrame; }
+    virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); }
 
-    void setStartFrame(int startFrame);
+    void setStartFrame(sv_frame_t startFrame);
 
-    virtual int getData(int channel, int start, int count,
+    virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
                            float *buffer) const;
 
-    virtual int getData(int channel, int start, int count,
+    virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
                            double *buffer) const;
 
-    virtual int getData(int fromchannel, int tochannel,
-                           int start, int count,
+    virtual sv_frame_t getData(int fromchannel, int tochannel,
+                           sv_frame_t start, sv_frame_t count,
                            float **buffer) const;
 
     virtual int getSummaryBlockSize(int desired) const;
 
-    virtual void getSummaries(int channel, int start, int count,
+    virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
                               RangeBlock &ranges, int &blockSize) const;
 
-    virtual Range getSummary(int channel, int start, int count) const;
+    virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const;
 
     QString getTypeName() const { return tr("Writable Wave File"); }
 
@@ -89,10 +89,10 @@
     WaveFileModel *m_model;
     WavFileWriter *m_writer;
     WavFileReader *m_reader;
-    int m_sampleRate;
+    sv_samplerate_t m_sampleRate;
     int m_channels;
-    int m_frameCount;
-    int m_startFrame;
+    sv_frame_t m_frameCount;
+    sv_frame_t m_startFrame;
     int m_completion;
 };
 
--- a/data/osc/OSCMessage.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/data/osc/OSCMessage.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -41,7 +41,7 @@
 int
 OSCMessage::getArgCount() const
 {
-    return m_args.size();
+    return int(m_args.size());
 }
 
 const QVariant &
--- a/plugin/DSSIPluginFactory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/DSSIPluginFactory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -82,7 +82,7 @@
 	list.push_back(m_taxonomy[*i]);
 	list.push_back(QString("%1").arg(descriptor->PortCount));
 
-	for (unsigned long p = 0; p < descriptor->PortCount; ++p) {
+	for (int p = 0; p < (int)descriptor->PortCount; ++p) {
 
 	    int type = 0;
 	    if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) {
@@ -113,9 +113,9 @@
 DSSIPluginFactory::instantiatePlugin(QString identifier,
 				     int instrument,
 				     int position,
-				     unsigned int sampleRate,
-				     unsigned int blockSize,
-				     unsigned int channels)
+				     sv_samplerate_t sampleRate,
+				     int blockSize,
+				     int channels)
 {
     Profiler profiler("DSSIPluginFactory::instantiatePlugin");
 
@@ -375,13 +375,13 @@
 	
 	unsigned int controlPortNumber = 1;
 	
-	for (unsigned long i = 0; i < ladspaDescriptor->PortCount; i++) {
+	for (int i = 0; i < (int)ladspaDescriptor->PortCount; i++) {
 	    
 	    if (LADSPA_IS_PORT_CONTROL(ladspaDescriptor->PortDescriptors[i])) {
 		
 		if (def_uri && defs) {
 		    
-		    for (unsigned int j = 0; j < defs->count; j++) {
+		    for (int j = 0; j < (int)defs->count; j++) {
 			if (defs->items[j].pid == controlPortNumber) {
 //			    cerr << "Default for this port (" << defs->items[j].pid << ", " << defs->items[j].label << ") is " << defs->items[j].value << "; applying this to port number " << i << " with name " << ladspaDescriptor->PortNames[i] << endl;
 			    m_portDefaults[ladspaDescriptor->UniqueID][i] =
--- a/plugin/DSSIPluginFactory.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/DSSIPluginFactory.h	Mon Mar 23 11:26:28 2015 +0000
@@ -40,9 +40,9 @@
     virtual RealTimePluginInstance *instantiatePlugin(QString identifier,
 						      int clientId,
 						      int position,
-						      unsigned int sampleRate,
-						      unsigned int blockSize,
-						      unsigned int channels);
+						      sv_samplerate_t sampleRate,
+						      int blockSize,
+						      int channels);
 
 protected:
     DSSIPluginFactory();
--- a/plugin/DSSIPluginInstance.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/DSSIPluginInstance.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -57,8 +57,8 @@
 				       int clientId,
 				       QString identifier,
 				       int position,
-				       unsigned long sampleRate,
-				       size_t blockSize,
+				       sv_samplerate_t sampleRate,
+				       int blockSize,
 				       int idealChannelCount,
 				       const DSSI_Descriptor* descriptor) :
     RealTimePluginInstance(factory, identifier),
@@ -90,7 +90,7 @@
     for (size_t i = 0; i < m_audioPortsIn.size(); ++i) {
 	m_inputBuffers[i] = new sample_t[blockSize];
     }
-    for (size_t i = 0; i < m_outputBufferCount; ++i) {
+    for (int i = 0; i < m_outputBufferCount; ++i) {
 	m_outputBuffers[i] = new sample_t[blockSize];
     }
 
@@ -149,10 +149,10 @@
     LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
     if (!f) return list;
     
-    for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
+    for (int i = 0; in_range_for(m_controlPortsIn, i); ++i) {
         
         ParameterDescriptor pd;
-        unsigned int pn = m_controlPortsIn[i].first;
+        int pn = (int)m_controlPortsIn[i].first;
 
         pd.identifier = m_descriptor->LADSPA_Plugin->PortNames[pn];
         pd.name = pd.identifier;
@@ -181,7 +181,7 @@
 #ifdef DEBUG_DSSI
     SVDEBUG << "DSSIPluginInstance::getParameter(" << id << ")" << endl;
 #endif
-    for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
+    for (int i = 0; in_range_for(m_controlPortsIn, i); ++i) {
         if (id == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) {
 #ifdef DEBUG_DSSI
             cerr << "Matches port " << i << endl;
@@ -204,7 +204,7 @@
     SVDEBUG << "DSSIPluginInstance::setParameter(" << id << ", " << value << ")" << endl;
 #endif
 
-    for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
+    for (int i = 0; in_range_for(m_controlPortsIn, i); ++i) {
         if (id == m_descriptor->LADSPA_Plugin->PortNames[m_controlPortsIn[i].first]) {
             setParameterValue(i, value);
             break;
@@ -223,7 +223,7 @@
     //
     const LADSPA_Descriptor *descriptor = m_descriptor->LADSPA_Plugin;
 
-    for (unsigned long i = 0; i < descriptor->PortCount; ++i)
+    for (int i = 0; i < (int)descriptor->PortCount; ++i)
     {
         if (LADSPA_IS_PORT_AUDIO(descriptor->PortDescriptors[i]))
         {
@@ -240,7 +240,7 @@
 
 		LADSPA_Data *data = new LADSPA_Data(0.0);
 
-		m_controlPortsIn.push_back(std::pair<unsigned long, LADSPA_Data*>
+		m_controlPortsIn.push_back(std::pair<long, LADSPA_Data*>
 					   (i, data));
 
 		m_backupControlPortsIn.push_back(0.0);
@@ -248,7 +248,7 @@
 	    } else {
 		LADSPA_Data *data = new LADSPA_Data(0.0);
 		m_controlPortsOut.push_back(
-                    std::pair<unsigned long, LADSPA_Data*>(i, data));
+                    std::pair<long, LADSPA_Data*>(i, data));
 		if (!strcmp(descriptor->PortNames[i], "latency") ||
 		    !strcmp(descriptor->PortNames[i], "_latency")) {
 #ifdef DEBUG_DSSI
@@ -265,13 +265,14 @@
 #endif
     }
 
-    m_outputBufferCount = std::max(m_idealChannelCount, m_audioPortsOut.size());
+    m_outputBufferCount = std::max(m_idealChannelCount,
+                                   (int)m_audioPortsOut.size());
 }
 
-size_t
+sv_frame_t
 DSSIPluginInstance::getLatency()
 {
-    size_t latency = 0;
+    sv_frame_t latency = 0;
 
 #ifdef DEBUG_DSSI_PROCESS
     SVDEBUG << "DSSIPluginInstance::getLatency(): m_latencyPort " << m_latencyPort << ", m_run " << m_run << endl;
@@ -279,14 +280,14 @@
 
     if (m_latencyPort) {
 	if (!m_run) {
-            for (size_t i = 0; i < getAudioInputCount(); ++i) {
-                for (size_t j = 0; j < m_blockSize; ++j) {
+            for (int i = 0; i < getAudioInputCount(); ++i) {
+                for (int j = 0; j < m_blockSize; ++j) {
                     m_inputBuffers[i][j] = 0.f;
                 }
             }
             run(Vamp::RealTime::zeroTime);
         }
-	latency = (size_t)(*m_latencyPort + 0.1);
+	latency = (sv_frame_t)(*m_latencyPort + 0.1);
     }
     
 #ifdef DEBUG_DSSI_PROCESS
@@ -312,7 +313,7 @@
 }
 
 void
-DSSIPluginInstance::setIdealChannelCount(size_t channels)
+DSSIPluginInstance::setIdealChannelCount(int channels)
 {
 #ifdef DEBUG_DSSI
     SVDEBUG << "DSSIPluginInstance::setIdealChannelCount: channel count "
@@ -332,7 +333,7 @@
 
     if (channels > m_outputBufferCount) {
 
-	for (size_t i = 0; i < m_outputBufferCount; ++i) {
+	for (int i = 0; i < m_outputBufferCount; ++i) {
 	    delete[] m_outputBuffers[i];
 	}
 
@@ -342,7 +343,7 @@
 
 	m_outputBuffers = new sample_t*[m_outputBufferCount];
 
-	for (size_t i = 0; i < m_outputBufferCount; ++i) {
+	for (int i = 0; i < m_outputBufferCount; ++i) {
 	    m_outputBuffers[i] = new sample_t[m_blockSize];
 	}
 
@@ -428,20 +429,20 @@
 
     cleanup();
 
-    for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i)
+    for (int i = 0; in_range_for(m_controlPortsIn, i); ++i)
         delete m_controlPortsIn[i].second;
 
-    for (unsigned int i = 0; i < m_controlPortsOut.size(); ++i)
+    for (int i = 0; in_range_for(m_controlPortsOut, i); ++i)
         delete m_controlPortsOut[i].second;
 
     m_controlPortsIn.clear();
     m_controlPortsOut.clear();
 
     if (m_ownBuffers) {
-	for (size_t i = 0; i < m_audioPortsIn.size(); ++i) {
+	for (int i = 0; i < getAudioInputCount(); ++i) {
 	    delete[] m_inputBuffers[i];
 	}
-	for (size_t i = 0; i < m_outputBufferCount; ++i) {
+	for (int i = 0; i < m_outputBufferCount; ++i) {
 	    delete[] m_outputBuffers[i];
 	}
 
@@ -455,7 +456,7 @@
 
 
 void
-DSSIPluginInstance::instantiate(unsigned long sampleRate)
+DSSIPluginInstance::instantiate(sv_samplerate_t sampleRate)
 {
     if (!m_descriptor) return;
 
@@ -472,13 +473,19 @@
 	return;
     }
 
-    m_instanceHandle = descriptor->instantiate(descriptor, sampleRate);
+    unsigned long pluginRate = (unsigned long)(sampleRate);
+    if (sampleRate != sv_samplerate_t(pluginRate)) {
+        cerr << "DSSIPluginInstance: WARNING: Non-integer sample rate "
+             << sampleRate << " presented, rounding to " << pluginRate
+             << endl;
+    }
+    m_instanceHandle = descriptor->instantiate(descriptor, pluginRate);
 
     if (m_instanceHandle) {
 
 	if (m_descriptor->get_midi_controller_for_port) {
 
-	    for (unsigned long i = 0; i < descriptor->PortCount; ++i) {
+	    for (int i = 0; i < (int)descriptor->PortCount; ++i) {
 
 		if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i]) &&
 		    LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
@@ -512,13 +519,13 @@
 	return;
     }
 
-    unsigned long index = 0;
+    int index = 0;
     const DSSI_Program_Descriptor *programDescriptor;
     while ((programDescriptor = m_descriptor->get_program(m_instanceHandle, index))) {
 	++index;
 	ProgramDescriptor d;
-	d.bank = programDescriptor->Bank;
-	d.program = programDescriptor->Program;
+	d.bank = (int)programDescriptor->Bank;
+	d.program = (int)programDescriptor->Program;
 	d.name = programDescriptor->Name;
 	m_cachedPrograms.push_back(d);
     }
@@ -570,7 +577,7 @@
     return std::string();
 }
 
-unsigned long
+int
 DSSIPluginInstance::getProgram(std::string name) const
 {
 #ifdef DEBUG_DSSI
@@ -581,7 +588,7 @@
 
     checkProgramCache();
 
-    unsigned long rv;
+    int rv;
 
     for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin();
 	 i != m_cachedPrograms.end(); ++i) {
@@ -621,7 +628,7 @@
     if (!m_descriptor->select_program) return;
 
     bool found = false;
-    unsigned long bankNo = 0, programNo = 0;
+    int bankNo = 0, programNo = 0;
 
     for (std::vector<ProgramDescriptor>::iterator i = m_cachedPrograms.begin();
 	 i != m_cachedPrograms.end(); ++i) {
@@ -689,7 +696,7 @@
 {
     if (!m_descriptor || !m_descriptor->LADSPA_Plugin->connect_port) return;
 #ifdef DEBUG_DSSI
-    SVDEBUG << "DSSIPluginInstance::connectPorts: " << m_audioPortsIn.size() 
+    SVDEBUG << "DSSIPluginInstance::connectPorts: " << getAudioInputCount() 
 	      << " audio ports in, " << m_audioPortsOut.size() << " out, "
 	      << m_outputBufferCount << " output buffers" << endl;
 #endif
@@ -700,7 +707,7 @@
     LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
     int inbuf = 0, outbuf = 0;
 
-    for (unsigned int i = 0; i < m_audioPortsIn.size(); ++i) {
+    for (int i = 0; i < getAudioInputCount(); ++i) {
 	m_descriptor->LADSPA_Plugin->connect_port
 	    (m_instanceHandle,
 	     m_audioPortsIn[i],
@@ -708,7 +715,7 @@
 	++inbuf;
     }
 
-    for (unsigned int i = 0; i < m_audioPortsOut.size(); ++i) {
+    for (size_t i = 0; i < m_audioPortsOut.size(); ++i) {
 	m_descriptor->LADSPA_Plugin->connect_port
 	    (m_instanceHandle,
 	     m_audioPortsOut[i],
@@ -716,7 +723,7 @@
 	++outbuf;
     }
 
-    for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
+    for (size_t i = 0; i < m_controlPortsIn.size(); ++i) {
 	m_descriptor->LADSPA_Plugin->connect_port
 	    (m_instanceHandle,
 	     m_controlPortsIn[i].first,
@@ -724,7 +731,7 @@
 
         if (f) {
             float defaultValue = f->getPortDefault
-                (m_descriptor->LADSPA_Plugin, m_controlPortsIn[i].first);
+                (m_descriptor->LADSPA_Plugin, (int)m_controlPortsIn[i].first);
             *m_controlPortsIn[i].second = defaultValue;
             m_backupControlPortsIn[i] = defaultValue;
 #ifdef DEBUG_DSSI
@@ -733,7 +740,7 @@
         }
     }
 
-    for (unsigned int i = 0; i < m_controlPortsOut.size(); ++i) {
+    for (size_t i = 0; i < m_controlPortsOut.size(); ++i) {
 	m_descriptor->LADSPA_Plugin->connect_port
 	    (m_instanceHandle,
 	     m_controlPortsOut[i].first,
@@ -741,21 +748,21 @@
     }
 }
 
-unsigned int
+int
 DSSIPluginInstance::getParameterCount() const
 {
-    return m_controlPortsIn.size();
+    return (int)m_controlPortsIn.size();
 }
 
 void
-DSSIPluginInstance::setParameterValue(unsigned int parameter, float value)
+DSSIPluginInstance::setParameterValue(int parameter, float value)
 {
 #ifdef DEBUG_DSSI
     SVDEBUG << "DSSIPluginInstance::setParameterValue(" << parameter << ") to " << value << endl;
 #endif
-    if (parameter >= m_controlPortsIn.size()) return;
+    if (!in_range_for(m_controlPortsIn, parameter)) return;
 
-    unsigned int portNumber = m_controlPortsIn[parameter].first;
+    int portNumber = m_controlPortsIn[parameter].first;
 
     LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
     if (f) {
@@ -772,7 +779,7 @@
 }
 
 void
-DSSIPluginInstance::setPortValueFromController(unsigned int port, int cv)
+DSSIPluginInstance::setPortValueFromController(int port, int cv)
 {
 #ifdef DEBUG_DSSI
     SVDEBUG << "DSSIPluginInstance::setPortValueFromController(" << port << ") to " << cv << endl;
@@ -803,7 +810,7 @@
 	}
     }
 
-    for (unsigned int i = 0; i < m_controlPortsIn.size(); ++i) {
+    for (int i = 0; in_range_for(m_controlPortsIn, i); ++i) {
 	if (m_controlPortsIn[i].first == port) {
 	    setParameterValue(i, value);
 	}
@@ -811,26 +818,26 @@
 }
 
 float
-DSSIPluginInstance::getControlOutputValue(size_t output) const
+DSSIPluginInstance::getControlOutputValue(int output) const
 {
-    if (output > m_controlPortsOut.size()) return 0.0;
+    if (!in_range_for(m_controlPortsOut, output)) return 0.0;
     return (*m_controlPortsOut[output].second);
 }
 
 float
-DSSIPluginInstance::getParameterValue(unsigned int parameter) const
+DSSIPluginInstance::getParameterValue(int parameter) const
 {
 #ifdef DEBUG_DSSI
     SVDEBUG << "DSSIPluginInstance::getParameterValue(" << parameter << ")" << endl;
 #endif
-    if (parameter >= m_controlPortsIn.size()) return 0.0;
+    if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
     return (*m_controlPortsIn[parameter].second);
 }
 
 float
-DSSIPluginInstance::getParameterDefault(unsigned int parameter) const
+DSSIPluginInstance::getParameterDefault(int parameter) const
 {
-    if (parameter >= m_controlPortsIn.size()) return 0.0;
+    if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
 
     LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
     if (f) {
@@ -842,9 +849,9 @@
 }
 
 int
-DSSIPluginInstance::getParameterDisplayHint(unsigned int parameter) const
+DSSIPluginInstance::getParameterDisplayHint(int parameter) const
 {
-    if (parameter >= m_controlPortsIn.size()) return 0.0;
+    if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
 
     LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
     if (f) {
@@ -906,7 +913,7 @@
 }
 
 void
-DSSIPluginInstance::sendEvent(const Vamp::RealTime &eventTime,
+DSSIPluginInstance::sendEvent(const RealTime &eventTime,
 			      const void *e)
 {
 #ifdef DEBUG_DSSI_PROCESS
@@ -982,7 +989,7 @@
 }
 
 void
-DSSIPluginInstance::run(const Vamp::RealTime &blockTime, size_t count)
+DSSIPluginInstance::run(const RealTime &blockTime, int count)
 {
     static snd_seq_event_t localEventBuffer[EVENT_BUFFER_SIZE];
     int evCount = 0;
@@ -1038,11 +1045,11 @@
 	*ev = m_eventBuffer.peekOne();
 	bool accept = true;
 
-	Vamp::RealTime evTime(ev->time.time.tv_sec, ev->time.time.tv_nsec);
+	RealTime evTime(ev->time.time.tv_sec, ev->time.time.tv_nsec);
 
-	int frameOffset = 0;
+        sv_frame_t frameOffset = 0;
 	if (evTime > blockTime) {
-	    frameOffset = Vamp::RealTime::realTime2Frame(evTime - blockTime, m_sampleRate);
+	    frameOffset = RealTime::realTime2Frame(evTime - blockTime, m_sampleRate);
 	}
 
 #ifdef DEBUG_DSSI_PROCESS
@@ -1051,7 +1058,7 @@
 	cerr << "Type: " << int(ev->type) << ", pitch: " << int(ev->data.note.note) << ", velocity: " << int(ev->data.note.velocity) << endl;
 #endif
 
-	if (frameOffset >= int(count)) break;
+	if (frameOffset >= (long)count) break;
 	if (frameOffset < 0) {
 	    frameOffset = 0;
 	    if (ev->type == SND_SEQ_EVENT_NOTEON) {
@@ -1060,7 +1067,7 @@
 	    }
 	}
 
-	ev->time.tick = frameOffset;
+	ev->time.tick = (snd_seq_tick_time_t)frameOffset;
 	m_eventBuffer.skip(1);
 
 	if (ev->type == SND_SEQ_EVENT_CONTROLLER) {
@@ -1110,28 +1117,30 @@
  done:
     if (needLock) m_processLock.unlock();
 
-    if (m_audioPortsOut.size() == 0) {
+    int numAudioOuts = int(m_audioPortsOut.size());
+    
+    if (numAudioOuts == 0) {
 	// copy inputs to outputs
-	for (size_t ch = 0; ch < m_idealChannelCount; ++ch) {
-	    size_t sch = ch % m_audioPortsIn.size();
-	    for (size_t i = 0; i < m_blockSize; ++i) {
+	for (int ch = 0; ch < m_idealChannelCount; ++ch) {
+	    int sch = ch % getAudioInputCount();
+	    for (int i = 0; i < m_blockSize; ++i) {
 		m_outputBuffers[ch][i] = m_inputBuffers[sch][i];
 	    }
 	}
-    } else if (m_idealChannelCount < m_audioPortsOut.size()) {
+    } else if (m_idealChannelCount < numAudioOuts) {
 	if (m_idealChannelCount == 1) {
 	    // mix down to mono
-	    for (size_t ch = 1; ch < m_audioPortsOut.size(); ++ch) {
-		for (size_t i = 0; i < m_blockSize; ++i) {
+	    for (int ch = 1; ch < numAudioOuts; ++ch) {
+		for (int i = 0; i < m_blockSize; ++i) {
 		    m_outputBuffers[0][i] += m_outputBuffers[ch][i];
 		}
 	    }
 	}
-    } else if (m_idealChannelCount > m_audioPortsOut.size()) {
+    } else if (m_idealChannelCount > numAudioOuts) {
 	// duplicate
-	for (size_t ch = m_audioPortsOut.size(); ch < m_idealChannelCount; ++ch) {
-	    size_t sch = (ch - m_audioPortsOut.size()) % m_audioPortsOut.size();
-	    for (size_t i = 0; i < m_blockSize; ++i) {
+	for (int ch = numAudioOuts; ch < m_idealChannelCount; ++ch) {
+	    int sch = (ch - numAudioOuts) % numAudioOuts;
+	    for (int i = 0; i < m_blockSize; ++i) {
 		m_outputBuffers[ch][i] = m_outputBuffers[sch][i];
 	    }
 	}
@@ -1142,7 +1151,7 @@
 }
 
 void
-DSSIPluginInstance::runGrouped(const Vamp::RealTime &blockTime)
+DSSIPluginInstance::runGrouped(const RealTime &blockTime)
 {
     // If something else in our group has just been called for this
     // block time (but we haven't) then we should just write out the
@@ -1214,11 +1223,11 @@
 	    *ev = instance->m_eventBuffer.peekOne();
 	    bool accept = true;
 
-	    Vamp::RealTime evTime(ev->time.time.tv_sec, ev->time.time.tv_nsec);
+	    RealTime evTime(ev->time.time.tv_sec, ev->time.time.tv_nsec);
 
-	    int frameOffset = 0;
+	    sv_frame_t frameOffset = 0;
 	    if (evTime > blockTime) {
-		frameOffset = Vamp::RealTime::realTime2Frame(evTime - blockTime, m_sampleRate);
+		frameOffset = RealTime::realTime2Frame(evTime - blockTime, m_sampleRate);
 	    }
 
 #ifdef DEBUG_DSSI_PROCESS
@@ -1229,7 +1238,7 @@
 	    if (frameOffset >= int(m_blockSize)) break;
 	    if (frameOffset < 0) frameOffset = 0;
 
-	    ev->time.tick = frameOffset;
+	    ev->time.tick = snd_seq_tick_time_t(frameOffset);
 	    instance->m_eventBuffer.skip(1);
 
 	    if (ev->type == SND_SEQ_EVENT_CONTROLLER) {
--- a/plugin/DSSIPluginInstance.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/DSSIPluginInstance.h	Mon Mar 23 11:26:28 2015 +0000
@@ -54,46 +54,46 @@
     virtual int getPluginVersion() const;
     virtual std::string getCopyright() const;
 
-    virtual void run(const Vamp::RealTime &, size_t count = 0);
+    virtual void run(const RealTime &, int count = 0);
 
-    virtual unsigned int getParameterCount() const;
-    virtual void setParameterValue(unsigned int parameter, float value);
-    virtual float getParameterValue(unsigned int parameter) const;
-    virtual float getParameterDefault(unsigned int parameter) const;
-    virtual int getParameterDisplayHint(unsigned int parameter) const;
+    virtual int getParameterCount() const;
+    virtual void setParameterValue(int parameter, float value);
+    virtual float getParameterValue(int parameter) const;
+    virtual float getParameterDefault(int parameter) const;
+    virtual int getParameterDisplayHint(int parameter) const;
 
     virtual ParameterList getParameterDescriptors() const;
     virtual float getParameter(std::string) const;
     virtual void setParameter(std::string, float);
 
     virtual std::string configure(std::string key, std::string value);
-    virtual void sendEvent(const Vamp::RealTime &eventTime,
+    virtual void sendEvent(const RealTime &eventTime,
 			   const void *event);
     virtual void clearEvents();
 
-    virtual size_t getBufferSize() const { return m_blockSize; }
-    virtual size_t getAudioInputCount() const { return m_audioPortsIn.size(); }
-    virtual size_t getAudioOutputCount() const { return m_idealChannelCount; }
+    virtual int getBufferSize() const { return m_blockSize; }
+    virtual int getAudioInputCount() const { return (int)m_audioPortsIn.size(); }
+    virtual int getAudioOutputCount() const { return m_idealChannelCount; }
     virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; }
     virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; }
 
-    virtual size_t getControlOutputCount() const { return m_controlPortsOut.size(); }
-    virtual float getControlOutputValue(size_t n) const;
+    virtual int getControlOutputCount() const { return (int)m_controlPortsOut.size(); }
+    virtual float getControlOutputValue(int n) const;
 
     virtual ProgramList getPrograms() const;
     virtual std::string getCurrentProgram() const;
     virtual std::string getProgram(int bank, int program) const;
-    virtual unsigned long getProgram(std::string name) const;
+    virtual int getProgram(std::string name) const;
     virtual void selectProgram(std::string program);
 
     virtual bool isBypassed() const { return m_bypassed; }
     virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; }
 
-    virtual size_t getLatency();
+    virtual sv_frame_t getLatency();
 
     virtual void silence();
     virtual void discardEvents();
-    virtual void setIdealChannelCount(size_t channels); // may re-instantiate
+    virtual void setIdealChannelCount(int channels); // may re-instantiate
 
     virtual bool isInGroup() const { return m_grouped; }
     virtual void detachFromGroup();
@@ -110,25 +110,25 @@
 		       int client,
 		       QString identifier,
 		       int position,
-		       unsigned long sampleRate,
-		       size_t blockSize,
+		       sv_samplerate_t sampleRate,
+		       int blockSize,
 		       int idealChannelCount,
 		       const DSSI_Descriptor* descriptor);
     
     void init();
-    void instantiate(unsigned long sampleRate);
+    void instantiate(sv_samplerate_t sampleRate);
     void cleanup();
     void activate();
     void deactivate();
     void connectPorts();
 
     bool handleController(snd_seq_event_t *ev);
-    void setPortValueFromController(unsigned int portNumber, int controlValue);
+    void setPortValueFromController(int portNumber, int controlValue);
     void selectProgramAux(std::string program, bool backupPortValues);
     void checkProgramCache() const;
 
     void initialiseGroupMembership();
-    void runGrouped(const Vamp::RealTime &);
+    void runGrouped(const RealTime &);
 
     // For use in DSSIPluginFactory (set in the DSSI_Host_Descriptor):
     static int requestMidiSend(LADSPA_Handle instance,
@@ -145,8 +145,8 @@
     LADSPA_Handle              m_instanceHandle;
     const DSSI_Descriptor     *m_descriptor;
 
-    std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsIn;
-    std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsOut;
+    std::vector<std::pair<int, LADSPA_Data*> > m_controlPortsIn;
+    std::vector<std::pair<int, LADSPA_Data*> > m_controlPortsOut;
 
     std::vector<LADSPA_Data>  m_backupControlPortsIn;
 
@@ -172,22 +172,22 @@
 
     RingBuffer<snd_seq_event_t> m_eventBuffer;
 
-    size_t                    m_blockSize;
+    int                       m_blockSize;
     sample_t                **m_inputBuffers;
     sample_t                **m_outputBuffers;
     bool                      m_ownBuffers;
-    size_t                    m_idealChannelCount;
-    size_t                    m_outputBufferCount;
-    size_t                    m_sampleRate;
+    int                       m_idealChannelCount;
+    int                       m_outputBufferCount;
+    sv_samplerate_t           m_sampleRate;
     float                    *m_latencyPort;
     bool                      m_run;
     
     bool                      m_bypassed;
     std::string               m_program;
     bool                      m_grouped;
-    Vamp::RealTime            m_lastRunTime;
+    RealTime                  m_lastRunTime;
 
-    Vamp::RealTime            m_lastEventSendTime;
+    RealTime                  m_lastEventSendTime;
     bool                      m_haveLastEventSendTime;
 
     QMutex                    m_processLock;
--- a/plugin/FeatureExtractionPluginFactory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/FeatureExtractionPluginFactory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -299,7 +299,7 @@
 
 Vamp::Plugin *
 FeatureExtractionPluginFactory::instantiatePlugin(QString identifier,
-						  float inputSampleRate)
+						  sv_samplerate_t inputSampleRate)
 {
     Profiler profiler("FeatureExtractionPluginFactory::instantiatePlugin");
 
@@ -357,7 +357,7 @@
         goto done;
     }
 
-    plugin = new Vamp::PluginHostAdapter(descriptor, inputSampleRate);
+    plugin = new Vamp::PluginHostAdapter(descriptor, float(inputSampleRate));
 
     if (plugin) {
         m_handleMap[plugin] = libraryHandle;
--- a/plugin/FeatureExtractionPluginFactory.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/FeatureExtractionPluginFactory.h	Mon Mar 23 11:26:28 2015 +0000
@@ -23,6 +23,7 @@
 #include <vamp-hostsdk/Plugin.h>
 
 #include "base/Debug.h"
+#include "base/BaseTypes.h"
 
 class FeatureExtractionPluginFactory
 {
@@ -42,7 +43,7 @@
     // We don't set blockSize or channels on this -- they're
     // negotiated and handled via initialize() on the plugin
     virtual Vamp::Plugin *instantiatePlugin(QString identifier,
-                                            float inputSampleRate);
+                                            sv_samplerate_t inputSampleRate);
 
     /**
      * Get category metadata about a plugin (without instantiating it).
--- a/plugin/LADSPAPluginFactory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/LADSPAPluginFactory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -104,7 +104,7 @@
 
 	list.push_back(QString("%1").arg(descriptor->PortCount));
 
-	for (unsigned long p = 0; p < descriptor->PortCount; ++p) {
+	for (int p = 0; p < (int)descriptor->PortCount; ++p) {
 
 	    int type = 0;
 	    if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) {
@@ -150,18 +150,18 @@
     LADSPA_PortRangeHintDescriptor d =
 	descriptor->PortRangeHints[port].HintDescriptor;
 
-    float minimum = 0.0;
+    float minimum = 0.f;
 		
     if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
 	float lb = descriptor->PortRangeHints[port].LowerBound;
 	minimum = lb;
     } else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
 	float ub = descriptor->PortRangeHints[port].UpperBound;
-	minimum = std::min(0.0, ub - 1.0);
+	minimum = std::min(0.f, ub - 1.f);
     }
     
     if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
-	minimum *= m_sampleRate;
+	minimum = float(minimum * m_sampleRate);
     }
 
     if (LADSPA_IS_HINT_LOGARITHMIC(d)) {
@@ -177,18 +177,18 @@
     LADSPA_PortRangeHintDescriptor d =
 	descriptor->PortRangeHints[port].HintDescriptor;
 
-    float maximum = 1.0;
+    float maximum = 1.f;
     
     if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
 	float ub = descriptor->PortRangeHints[port].UpperBound;
 	maximum = ub;
     } else {
 	float lb = descriptor->PortRangeHints[port].LowerBound;
-	maximum = lb + 1.0;
+	maximum = lb + 1.f;
     }
     
     if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
-	maximum *= m_sampleRate;
+	maximum = float(maximum * m_sampleRate);
     }
 
     return maximum;
@@ -240,25 +240,25 @@
     } else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) {
 	
 	if (logarithmic) {
-	    deft = powf(10, logmin * 0.75 + logmax * 0.25);
+	    deft = powf(10, logmin * 0.75f + logmax * 0.25f);
 	} else {
-	    deft = minimum * 0.75 + maximum * 0.25;
+	    deft = minimum * 0.75f + maximum * 0.25f;
 	}
 	
     } else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) {
 	
 	if (logarithmic) {
-	    deft = powf(10, logmin * 0.5 + logmax * 0.5);
+	    deft = powf(10, logmin * 0.5f + logmax * 0.5f);
 	} else {
-	    deft = minimum * 0.5 + maximum * 0.5;
+	    deft = minimum * 0.5f + maximum * 0.5f;
 	}
 	
     } else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) {
 	
 	if (logarithmic) {
-	    deft = powf(10, logmin * 0.25 + logmax * 0.75);
+	    deft = powf(10, logmin * 0.25f + logmax * 0.75f);
 	} else {
-	    deft = minimum * 0.25 + maximum * 0.75;
+	    deft = minimum * 0.25f + maximum * 0.75f;
 	}
 	
     } else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) {
@@ -280,7 +280,7 @@
     } else if (LADSPA_IS_HINT_DEFAULT_440(d)) {
 	
 //	deft = 440.0;
-        deft = Preferences::getInstance()->getTuningFrequency();
+        deft = (float)Preferences::getInstance()->getTuningFrequency();
 	
     } else {
 	
@@ -303,8 +303,8 @@
 {
     int displayHint = getPortDisplayHint(descriptor, port);
     if (displayHint & PortHint::Toggled) {
-        return lrintf(getPortMaximum(descriptor, port)) - 
-            lrintf(getPortMinimum(descriptor, port));
+        return float(lrintf(getPortMaximum(descriptor, port)) - 
+                     lrintf(getPortMinimum(descriptor, port)));
     }
     if (displayHint & PortHint::Integer) {
         return 1.0;
@@ -331,9 +331,9 @@
 LADSPAPluginFactory::instantiatePlugin(QString identifier,
 				       int instrument,
 				       int position,
-				       unsigned int sampleRate,
-				       unsigned int blockSize,
-				       unsigned int channels)
+				       sv_samplerate_t sampleRate,
+				       int blockSize,
+				       int channels)
 {
     Profiler profiler("LADSPAPluginFactory::instantiatePlugin");
 
@@ -754,7 +754,7 @@
 
 	unsigned int controlPortNumber = 1;
 	
-	for (unsigned long i = 0; i < descriptor->PortCount; i++) {
+	for (int i = 0; i < (int)descriptor->PortCount; i++) {
 	    
 	    if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
 		
@@ -774,7 +774,7 @@
 	}
 #endif // HAVE_LRDF
 
-	for (unsigned long i = 0; i < descriptor->PortCount; i++) {
+	for (int i = 0; i < (int)descriptor->PortCount; i++) {
 	    if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
                 if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
                     ++rtd->parameterCount;
--- a/plugin/LADSPAPluginFactory.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/LADSPAPluginFactory.h	Mon Mar 23 11:26:28 2015 +0000
@@ -47,9 +47,9 @@
     virtual RealTimePluginInstance *instantiatePlugin(QString identifier,
 						      int clientId,
 						      int position,
-						      unsigned int sampleRate,
-						      unsigned int blockSize,
-						      unsigned int channels);
+						      sv_samplerate_t sampleRate,
+						      int blockSize,
+						      int channels);
 
     virtual QString getPluginCategory(QString identifier);
 
--- a/plugin/LADSPAPluginInstance.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/LADSPAPluginInstance.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -37,8 +37,8 @@
 					   int clientId,
 					   QString identifier,
                                            int position,
-					   unsigned long sampleRate,
-					   size_t blockSize,
+					   sv_samplerate_t sampleRate,
+					   int blockSize,
 					   int idealChannelCount,
                                            const LADSPA_Descriptor* descriptor) :
     RealTimePluginInstance(factory, identifier),
@@ -156,12 +156,12 @@
             if (defaults) {
                 if (defaults->count > 0) {
                     std::map<int, std::string> values;
-                    size_t v = 0;
+                    int v = 0;
                     for (size_t i = 0; i < defaults->count; ++i) {
-                        v = size_t(lrintf(fabsf(defaults->items[i].value)));
+                        v = int(lrintf(fabsf(defaults->items[i].value)));
                         values[v] = defaults->items[i].label;
                     }
-                    for (size_t i = 0; i <= v; ++i) {
+                    for (int i = 0; i <= v; ++i) {
                         pd.valueNames.push_back(values[i]);
                     }
                     haveLabels = true;
@@ -227,7 +227,7 @@
 
     // Discover ports numbers and identities
     //
-    for (unsigned long i = 0; i < m_descriptor->PortCount; ++i) {
+    for (int i = 0; i < (int)m_descriptor->PortCount; ++i) {
 
         if (LADSPA_IS_PORT_AUDIO(m_descriptor->PortDescriptors[i])) {
 
@@ -289,19 +289,19 @@
     }
 }
 
-size_t
+sv_frame_t
 LADSPAPluginInstance::getLatency()
 {
     if (m_latencyPort) {
 	if (!m_run) {
-            for (size_t i = 0; i < getAudioInputCount(); ++i) {
-                for (size_t j = 0; j < m_blockSize; ++j) {
+            for (int i = 0; i < getAudioInputCount(); ++i) {
+                for (int j = 0; j < m_blockSize; ++j) {
                     m_inputBuffers[i][j] = 0.f;
                 }
             }
             run(Vamp::RealTime::zeroTime);
         }
-	if (*m_latencyPort > 0) return (size_t)*m_latencyPort;
+	if (*m_latencyPort > 0) return (sv_frame_t)*m_latencyPort;
     }
     return 0;
 }
@@ -316,7 +316,7 @@
 }
 
 void
-LADSPAPluginInstance::setIdealChannelCount(size_t channels)
+LADSPAPluginInstance::setIdealChannelCount(int channels)
 {
     if (m_audioPortsIn.size() != 1 || channels == m_instanceCount) {
 	silence();
@@ -378,7 +378,7 @@
 
 
 void
-LADSPAPluginInstance::instantiate(unsigned long sampleRate)
+LADSPAPluginInstance::instantiate(sv_samplerate_t sampleRate)
 {
     if (!m_descriptor) return;
 
@@ -394,9 +394,16 @@
 	return;
     }
 
-    for (size_t i = 0; i < m_instanceCount; ++i) {
+    unsigned long pluginRate = (unsigned long)(sampleRate);
+    if (sampleRate != sv_samplerate_t(pluginRate)) {
+        cerr << "LADSPAPluginInstance: WARNING: Non-integer sample rate "
+             << sampleRate << " presented, rounding to " << pluginRate
+             << endl;
+    }
+    
+    for (int i = 0; i < m_instanceCount; ++i) {
 	m_instanceHandles.push_back
-	    (m_descriptor->instantiate(m_descriptor, sampleRate));
+	    (m_descriptor->instantiate(m_descriptor, pluginRate));
     }
 }
 
@@ -464,16 +471,16 @@
     }
 }
 
-unsigned int
+int
 LADSPAPluginInstance::getParameterCount() const
 {
-    return m_controlPortsIn.size();
+    return (int)m_controlPortsIn.size();
 }
 
 void
-LADSPAPluginInstance::setParameterValue(unsigned int parameter, float value)
+LADSPAPluginInstance::setParameterValue(int parameter, float value)
 {
-    if (parameter >= m_controlPortsIn.size()) return;
+    if (!in_range_for(m_controlPortsIn, parameter)) return;
 
     unsigned int portNumber = m_controlPortsIn[parameter].first;
 
@@ -491,23 +498,23 @@
 }
 
 float
-LADSPAPluginInstance::getControlOutputValue(size_t output) const
+LADSPAPluginInstance::getControlOutputValue(int output) const
 {
-    if (output > m_controlPortsOut.size()) return 0.0;
+    if (!in_range_for(m_controlPortsOut, output)) return 0.0;
     return (*m_controlPortsOut[output].second);
 }
 
 float
-LADSPAPluginInstance::getParameterValue(unsigned int parameter) const
+LADSPAPluginInstance::getParameterValue(int parameter) const
 {
-    if (parameter >= m_controlPortsIn.size()) return 0.0;
+    if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
     return (*m_controlPortsIn[parameter].second);
 }
 
 float
-LADSPAPluginInstance::getParameterDefault(unsigned int parameter) const
+LADSPAPluginInstance::getParameterDefault(int parameter) const
 {
-    if (parameter >= m_controlPortsIn.size()) return 0.0;
+    if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
 
     LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
     if (f) {
@@ -518,9 +525,9 @@
 }
 
 int
-LADSPAPluginInstance::getParameterDisplayHint(unsigned int parameter) const
+LADSPAPluginInstance::getParameterDisplayHint(int parameter) const
 {
-    if (parameter >= m_controlPortsIn.size()) return 0.0;
+    if (!in_range_for(m_controlPortsIn, parameter)) return 0.0;
 
     LADSPAPluginFactory *f = dynamic_cast<LADSPAPluginFactory *>(m_factory);
     if (f) {
@@ -531,7 +538,7 @@
 }
 
 void
-LADSPAPluginInstance::run(const Vamp::RealTime &, size_t count)
+LADSPAPluginInstance::run(const RealTime &, int count)
 {
     if (!m_descriptor || !m_descriptor->run) return;
 
--- a/plugin/LADSPAPluginInstance.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/LADSPAPluginInstance.h	Mon Mar 23 11:26:28 2015 +0000
@@ -27,6 +27,7 @@
 
 #include "api/ladspa.h"
 #include "RealTimePluginInstance.h"
+#include "base/BaseTypes.h"
 
 // LADSPA plugin instance.  LADSPA is a variable block size API, but
 // for one reason and another it's more convenient to use a fixed
@@ -50,34 +51,34 @@
     virtual int getPluginVersion() const;
     virtual std::string getCopyright() const;
 
-    virtual void run(const Vamp::RealTime &rt, size_t count = 0);
+    virtual void run(const RealTime &rt, int count = 0);
 
-    virtual unsigned int getParameterCount() const;
-    virtual void setParameterValue(unsigned int parameter, float value);
-    virtual float getParameterValue(unsigned int parameter) const;
-    virtual float getParameterDefault(unsigned int parameter) const;
-    virtual int getParameterDisplayHint(unsigned int parameter) const;
+    virtual int getParameterCount() const;
+    virtual void setParameterValue(int parameter, float value);
+    virtual float getParameterValue(int parameter) const;
+    virtual float getParameterDefault(int parameter) const;
+    virtual int getParameterDisplayHint(int parameter) const;
     
     virtual ParameterList getParameterDescriptors() const;
     virtual float getParameter(std::string) const;
     virtual void setParameter(std::string, float);
 
-    virtual size_t getBufferSize() const { return m_blockSize; }
-    virtual size_t getAudioInputCount() const { return m_instanceCount * m_audioPortsIn.size(); }
-    virtual size_t getAudioOutputCount() const { return m_instanceCount * m_audioPortsOut.size(); }
+    virtual int getBufferSize() const { return m_blockSize; }
+    virtual int getAudioInputCount() const { return int(m_instanceCount * m_audioPortsIn.size()); }
+    virtual int getAudioOutputCount() const { return int(m_instanceCount * m_audioPortsOut.size()); }
     virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; }
     virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; }
 
-    virtual size_t getControlOutputCount() const { return m_controlPortsOut.size(); }
-    virtual float getControlOutputValue(size_t n) const;
+    virtual int getControlOutputCount() const { return int(m_controlPortsOut.size()); }
+    virtual float getControlOutputValue(int n) const;
 
     virtual bool isBypassed() const { return m_bypassed; }
     virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; }
 
-    virtual size_t getLatency();
+    virtual sv_frame_t getLatency();
 
     virtual void silence();
-    virtual void setIdealChannelCount(size_t channels); // may re-instantiate
+    virtual void setIdealChannelCount(int channels); // may re-instantiate
 
     virtual std::string getType() const { return "LADSPA Real-Time Plugin"; }
 
@@ -91,13 +92,13 @@
 			 int client,
 			 QString identifier,
                          int position,
-			 unsigned long sampleRate,
-			 size_t blockSize,
+			 sv_samplerate_t sampleRate,
+			 int blockSize,
 			 int idealChannelCount,
                          const LADSPA_Descriptor* descriptor);
 
     void init(int idealChannelCount = 0);
-    void instantiate(unsigned long sampleRate);
+    void instantiate(sv_samplerate_t sampleRate);
     void cleanup();
     void activate();
     void deactivate();
@@ -109,20 +110,20 @@
     int                        m_client;
     int                        m_position;
     std::vector<LADSPA_Handle> m_instanceHandles;
-    size_t                     m_instanceCount;
+    int                        m_instanceCount;
     const LADSPA_Descriptor   *m_descriptor;
 
-    std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsIn;
-    std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsOut;
+    std::vector<std::pair<int, LADSPA_Data*> > m_controlPortsIn;
+    std::vector<std::pair<int, LADSPA_Data*> > m_controlPortsOut;
 
     std::vector<int>          m_audioPortsIn;
     std::vector<int>          m_audioPortsOut;
 
-    size_t                    m_blockSize;
+    int                       m_blockSize;
     sample_t                **m_inputBuffers;
     sample_t                **m_outputBuffers;
     bool                      m_ownBuffers;
-    size_t                    m_sampleRate;
+    sv_samplerate_t           m_sampleRate;
     float                    *m_latencyPort;
     bool                      m_run;
     
--- a/plugin/RealTimePluginFactory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/RealTimePluginFactory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -30,7 +30,7 @@
 
 #include <iostream>
 
-int RealTimePluginFactory::m_sampleRate = 48000;
+sv_samplerate_t RealTimePluginFactory::m_sampleRate = 48000;
 
 static LADSPAPluginFactory *_ladspaInstance = 0;
 static LADSPAPluginFactory *_dssiInstance = 0;
--- a/plugin/RealTimePluginFactory.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/RealTimePluginFactory.h	Mon Mar 23 11:26:28 2015 +0000
@@ -26,6 +26,7 @@
 #include <vector>
 
 #include "base/Debug.h"
+#include "base/BaseTypes.h"
 
 class RealTimePluginInstance;
 
@@ -55,7 +56,7 @@
     static std::vector<QString> getAllPluginIdentifiers();
     static void enumerateAllPlugins(std::vector<QString> &);
 
-    static void setSampleRate(int sampleRate) { m_sampleRate = sampleRate; }
+    static void setSampleRate(sv_samplerate_t sampleRate) { m_sampleRate = sampleRate; }
 
     /**
      * Look up the plugin path and find the plugins in it.  Called 
@@ -87,9 +88,9 @@
     virtual RealTimePluginInstance *instantiatePlugin(QString identifier,
 						      int clientId,
 						      int position,
-						      unsigned int sampleRate,
-						      unsigned int blockSize,
-						      unsigned int channels) = 0;
+						      sv_samplerate_t sampleRate,
+						      int blockSize,
+						      int channels) = 0;
 
     /**
      * Get category metadata about a plugin (without instantiating it).
@@ -103,7 +104,7 @@
     virtual void releasePlugin(RealTimePluginInstance *, QString identifier) = 0;
     friend class RealTimePluginInstance;
 
-    static int m_sampleRate;
+    static sv_samplerate_t m_sampleRate;
 };
 
 #endif
--- a/plugin/RealTimePluginInstance.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/RealTimePluginInstance.h	Mon Mar 23 11:26:28 2015 +0000
@@ -22,7 +22,9 @@
 #define _REALTIME_PLUGIN_INSTANCE_H_
 
 #include <vamp-hostsdk/PluginBase.h>
-#include <vamp-hostsdk/RealTime.h>
+
+#include "base/RealTime.h"
+#include "base/AudioPlaySource.h"
 
 #include <QString>
 #include <QStringList>
@@ -30,8 +32,6 @@
 #include <string>
 #include <map>
 
-#include "base/AudioPlaySource.h"
-
 class RealTimePluginFactory;
 	
 /**
@@ -91,36 +91,36 @@
      * waiting.  Other plugins can ignore it.  The count, if zero,
      * defaults to our fixed buffer size.
      */
-    virtual void run(const Vamp::RealTime &blockStartTime,
-                     size_t count = 0) = 0;
+    virtual void run(const RealTime &blockStartTime,
+                     int count = 0) = 0;
     
-    virtual size_t getBufferSize() const = 0;
+    virtual int getBufferSize() const = 0;
 
-    virtual size_t getAudioInputCount() const = 0;
-    virtual size_t getAudioOutputCount() const = 0;
+    virtual int getAudioInputCount() const = 0;
+    virtual int getAudioOutputCount() const = 0;
 
     virtual sample_t **getAudioInputBuffers() = 0;
     virtual sample_t **getAudioOutputBuffers() = 0;
 
     // Control inputs are known as parameters here
-    virtual size_t getControlOutputCount() const = 0;
-    virtual float getControlOutputValue(size_t n) const = 0;
+    virtual int getControlOutputCount() const = 0;
+    virtual float getControlOutputValue(int n) const = 0;
 
 //     virtual QStringList getPrograms() const { return QStringList(); }
 //     virtual QString getCurrentProgram() const { return QString(); }
     virtual std::string getProgram(int /* bank */, int /* program */) const { return std::string(); }
-//     virtual unsigned long getProgram(QString /* name */) const { return 0; } // bank << 16 + program
+//     virtual int getProgram(QString /* name */) const { return 0; } // bank << 16 + program
 //     virtual void selectProgram(QString) { }
 
-    virtual unsigned int getParameterCount() const = 0;
-    virtual void setParameterValue(unsigned int parameter, float value) = 0;
-    virtual float getParameterValue(unsigned int parameter) const = 0;
-    virtual float getParameterDefault(unsigned int parameter) const = 0;
-    virtual int getParameterDisplayHint(unsigned int parameter) const = 0;
+    virtual int getParameterCount() const = 0;
+    virtual void setParameterValue(int parameter, float value) = 0;
+    virtual float getParameterValue(int parameter) const = 0;
+    virtual float getParameterDefault(int parameter) const = 0;
+    virtual int getParameterDisplayHint(int parameter) const = 0;
 
     virtual std::string configure(std::string /* key */, std::string /* value */) { return std::string(); }
 
-    virtual void sendEvent(const Vamp::RealTime & /* eventTime */,
+    virtual void sendEvent(const RealTime & /* eventTime */,
 			   const void * /* event */) { }
     virtual void clearEvents() { }
 
@@ -128,11 +128,11 @@
     virtual void setBypassed(bool value) = 0;
 
     // This should be called after setup, but while not actually playing.
-    virtual size_t getLatency() = 0;
+    virtual sv_frame_t getLatency() = 0;
 
     virtual void silence() = 0;
     virtual void discardEvents() { }
-    virtual void setIdealChannelCount(size_t channels) = 0; // must also silence(); may also re-instantiate
+    virtual void setIdealChannelCount(int channels) = 0; // must also silence(); may also re-instantiate
 
     void setFactory(RealTimePluginFactory *f) { m_factory = f; } // ew
 
--- a/plugin/plugins/SamplePlayer.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/plugin/plugins/SamplePlayer.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -69,7 +69,7 @@
     { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_INTEGER |
       LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0, 1 },
     { LADSPA_HINT_DEFAULT_MINIMUM | LADSPA_HINT_LOGARITHMIC |
-      LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0.001, 2.0 }
+      LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE, 0.001f, 2.0f }
 };
 
 const LADSPA_Properties
@@ -156,7 +156,7 @@
 	return 0;
     }
 
-    SamplePlayer *player = new SamplePlayer(rate);
+    SamplePlayer *player = new SamplePlayer(int(rate));
 	// std::cerr << "Instantiated sample player " << std::endl;
 
     if (hostDescriptor->request_non_rt_thread(player, workThreadCallback)) {
@@ -282,7 +282,7 @@
 			    unsigned long program)
 {
     SamplePlayer *player = (SamplePlayer *)handle;
-    player->m_pendingProgramChange = program;
+    player->m_pendingProgramChange = (int)program;
 }
 
 int
@@ -415,7 +415,7 @@
     if (info.samplerate != m_sampleRate) {
 	
 	double ratio = (double)m_sampleRate / (double)info.samplerate;
-	size_t target = (size_t)(info.frames * ratio);
+	size_t target = (size_t)(double(info.frames) * ratio);
 	SRC_DATA data;
 
 	tmpResamples = (float *)malloc(target * info.channels * sizeof(float));
@@ -572,7 +572,7 @@
             ratio *= *m_concertA / 440.f;
         }
 	if (m_basePitch && n != *m_basePitch) {
-	    ratio *= powf(1.059463094f, n - *m_basePitch);
+	    ratio *= powf(1.059463094f, float(n) - *m_basePitch);
 	}
     }
 
@@ -585,8 +585,8 @@
 	 ++i, ++s) {
 
 	float         lgain = gain;
-	float         rs = s * ratio;
-	unsigned long rsi = lrintf(floor(rs));
+	float         rs = float(s) * ratio;
+	unsigned long rsi = lrintf(floorf(rs));
 
 	if (rsi >= m_sampleCount) {
 #ifdef DEBUG_SAMPLE_PLAYER
@@ -604,7 +604,7 @@
 
 	    unsigned long releaseFrames = 200;
 	    if (m_release) {
-		releaseFrames = long(*m_release * m_sampleRate + 0.0001);
+		releaseFrames = long(*m_release * float(m_sampleRate) + 0.0001f);
 	    }
 
 	    if (dist > releaseFrames) {
--- a/rdf/RDFExporter.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/rdf/RDFExporter.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -78,7 +78,7 @@
     Vamp::Plugin::FeatureList features;
     features.push_back(Vamp::Plugin::Feature());
     Vamp::Plugin::Feature &f = features[0];
-    int sr = m_model->getSampleRate();
+    sv_samplerate_t sr = m_model->getSampleRate();
 
     {
         RegionModel *m = dynamic_cast<RegionModel *>(m_model);
@@ -88,8 +88,8 @@
             const RegionModel::PointList &pl(m->getPoints());
             for (RegionModel::PointList::const_iterator i = pl.begin(); 
                  i != pl.end(); ++i) {
-                f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
-                f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr);
+                f.timestamp = RealTime::frame2RealTime(i->frame, sr).toVampRealTime();
+                f.duration = RealTime::frame2RealTime(i->duration, sr).toVampRealTime();
                 f.values.clear();
                 f.values.push_back(i->value);
                 f.label = i->label.toStdString();
@@ -106,8 +106,8 @@
             const NoteModel::PointList &pl(m->getPoints());
             for (NoteModel::PointList::const_iterator i = pl.begin(); 
                  i != pl.end(); ++i) {
-                f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
-                f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr);
+                f.timestamp = RealTime::frame2RealTime(i->frame, sr).toVampRealTime();
+                f.duration = RealTime::frame2RealTime(i->duration, sr).toVampRealTime();
                 f.values.clear();
                 f.values.push_back(i->value);
                 f.values.push_back(i->level);
@@ -125,7 +125,7 @@
             const SparseOneDimensionalModel::PointList &pl(m->getPoints());
             for (SparseOneDimensionalModel::PointList::const_iterator i = pl.begin(); 
                  i != pl.end(); ++i) {
-                f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
+                f.timestamp = RealTime::frame2RealTime(i->frame, sr).toVampRealTime();
                 f.values.clear();
                 f.label = i->label.toStdString();
                 m_fw->write(trackId, transform, output, features, summaryType);
@@ -141,7 +141,7 @@
             const SparseTimeValueModel::PointList &pl(m->getPoints());
             for (SparseTimeValueModel::PointList::const_iterator i = pl.begin(); 
                  i != pl.end(); ++i) {
-                f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
+                f.timestamp = RealTime::frame2RealTime(i->frame, sr).toVampRealTime();
                 f.values.clear();
                 f.values.push_back(i->value);
                 f.label = i->label.toStdString();
@@ -159,7 +159,7 @@
             m_fw->setFixedEventTypeURI("af:Text");
             for (TextModel::PointList::const_iterator i = pl.begin(); 
                  i != pl.end(); ++i) {
-                f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
+                f.timestamp = RealTime::frame2RealTime(i->frame, sr).toVampRealTime();
                 f.values.clear();
                 f.values.push_back(i->height);
                 f.label = i->label.toStdString();
--- a/rdf/RDFFeatureWriter.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/rdf/RDFFeatureWriter.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -685,7 +685,7 @@
 
         stream << "\n:feature_timeline_" << featureNumber << " a tl:DiscreteTimeLine .\n\n";
 
-        float sampleRate;
+        sv_samplerate_t sampleRate;
         int stepSize, blockSize;
 
         // If the output is FixedSampleRate, we need to draw the
@@ -751,8 +751,10 @@
         RealTime startrt = transform.getStartTime();
         RealTime durationrt = transform.getDuration();
 
-        int start = RealTime::realTime2Frame(startrt, sampleRate) / stepSize;
-        int duration = RealTime::realTime2Frame(durationrt, sampleRate) / stepSize;
+        sv_frame_t start = RealTime::realTime2Frame
+            (startrt, sampleRate) / stepSize;
+        sv_frame_t duration = RealTime::realTime2Frame
+            (durationrt, sampleRate) / stepSize;
 
         if (start != 0) {
             stream << "\n        tl:start \"" << start << "\"^^xsd:int ;";
--- a/rdf/RDFImporter.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/rdf/RDFImporter.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -50,10 +50,10 @@
 class RDFImporterImpl
 {
 public:
-    RDFImporterImpl(QString url, int sampleRate);
+    RDFImporterImpl(QString url, sv_samplerate_t sampleRate);
     virtual ~RDFImporterImpl();
 
-    void setSampleRate(int sampleRate) { m_sampleRate = sampleRate; }
+    void setSampleRate(sv_samplerate_t sampleRate) { m_sampleRate = sampleRate; }
     
     bool isOK();
     QString getErrorString() const;
@@ -67,7 +67,7 @@
     QString m_uristring;
     QString m_errorString;
     std::map<QString, Model *> m_audioModelMap;
-    int m_sampleRate;
+    sv_samplerate_t m_sampleRate;
 
     std::map<Model *, std::map<QString, float> > m_labelValueMap;
 
@@ -78,10 +78,11 @@
     void getDenseModelTitle(Model *, QString, QString);
 
     void getDenseFeatureProperties(QString featureUri,
-                                   int &sampleRate, int &windowLength,
+                                   sv_samplerate_t &sampleRate, int &windowLength,
                                    int &hopSize, int &width, int &height);
 
-    void fillModel(Model *, long, long, bool, std::vector<float> &, QString);
+    void fillModel(Model *, sv_frame_t, sv_frame_t,
+                   bool, std::vector<float> &, QString);
 };
 
 QString
@@ -90,7 +91,7 @@
     return "*.rdf *.n3 *.ttl";
 }
 
-RDFImporter::RDFImporter(QString url, int sampleRate) :
+RDFImporter::RDFImporter(QString url, sv_samplerate_t sampleRate) :
     m_d(new RDFImporterImpl(url, sampleRate)) 
 {
 }
@@ -101,7 +102,7 @@
 }
 
 void
-RDFImporter::setSampleRate(int sampleRate)
+RDFImporter::setSampleRate(sv_samplerate_t sampleRate)
 {
     m_d->setSampleRate(sampleRate);
 }
@@ -124,7 +125,7 @@
     return m_d->getDataModels(r);
 }
 
-RDFImporterImpl::RDFImporterImpl(QString uri, int sampleRate) :
+RDFImporterImpl::RDFImporterImpl(QString uri, sv_samplerate_t sampleRate) :
     m_store(new BasicStore),
     m_uristring(uri),
     m_sampleRate(sampleRate)
@@ -309,7 +310,7 @@
         
         if (type == "" || value == "") continue;
 
-        int sampleRate = 0;
+        sv_samplerate_t sampleRate = 0;
         int windowLength = 0;
         int hopSize = 0;
         int width = 0;
@@ -416,7 +417,7 @@
 
 void
 RDFImporterImpl::getDenseFeatureProperties(QString featureUri,
-                                           int &sampleRate, int &windowLength,
+                                           sv_samplerate_t &sampleRate, int &windowLength,
                                            int &hopSize, int &width, int &height)
 {
     Node dim = m_store->complete
@@ -467,7 +468,7 @@
     PropertyObject po(m_store, "tl:", map);
 
     if (po.hasProperty("sampleRate")) {
-        sampleRate = po.getProperty("sampleRate").toInt();
+        sampleRate = po.getProperty("sampleRate").toDouble();
     }
     if (po.hasProperty("hopSize")) {
         hopSize = po.getProperty("hopSize").toInt();
@@ -686,8 +687,8 @@
                 model = modelMap[timeline][type][dimensions][haveDuration];
 
                 if (model) {
-                    long ftime = RealTime::realTime2Frame(time, m_sampleRate);
-                    long fduration = RealTime::realTime2Frame(duration, m_sampleRate);
+                    sv_frame_t ftime = RealTime::realTime2Frame(time, m_sampleRate);
+                    sv_frame_t fduration = RealTime::realTime2Frame(duration, m_sampleRate);
                     fillModel(model, ftime, fduration, haveDuration, values, label);
                 }
             }
@@ -697,8 +698,8 @@
 
 void
 RDFImporterImpl::fillModel(Model *model,
-                           long ftime,
-                           long fduration,
+                           sv_frame_t ftime,
+                           sv_frame_t fduration,
                            bool haveDuration,
                            std::vector<float> &values,
                            QString label)
@@ -757,7 +758,8 @@
                     }
                 }
             }
-            NoteModel::Point point(ftime, value, duration, level, label);
+            NoteModel::Point point(ftime, value, sv_frame_t(lrintf(duration)),
+                                   level, label);
             nm->addPoint(point);
         }
         return;
@@ -789,7 +791,8 @@
                     duration = values[1];
                 }
             }
-            RegionModel::Point point(ftime, value, duration, label);
+            RegionModel::Point point(ftime, value,
+                                     sv_frame_t(lrintf(duration)), label);
             rm->addPoint(point);
         }
         return;
--- a/rdf/RDFImporter.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/rdf/RDFImporter.h	Mon Mar 23 11:26:28 2015 +0000
@@ -21,6 +21,8 @@
 
 #include <vector>
 
+#include "base/BaseTypes.h"
+
 class Model;
 class RDFImporterImpl;
 class ProgressReporter;
@@ -37,10 +39,10 @@
      */
     static QString getKnownExtensions();
 
-    RDFImporter(QString url, int sampleRate = 0);
+    RDFImporter(QString url, sv_samplerate_t sampleRate = 0);
     virtual ~RDFImporter();
 
-    void setSampleRate(int sampleRate);
+    void setSampleRate(sv_samplerate_t sampleRate);
 
     bool isOK();
     QString getErrorString() const;
--- a/svcore.pro	Mon Mar 23 10:04:48 2015 +0000
+++ b/svcore.pro	Mon Mar 23 11:26:28 2015 +0000
@@ -29,7 +29,7 @@
     }
 }
 
-CONFIG += staticlib qt thread warn_on stl rtti exceptions
+CONFIG += staticlib qt thread warn_on stl rtti exceptions c++11
 QT += network xml
 QT -= gui
 
@@ -51,6 +51,7 @@
 
 HEADERS += base/AudioLevel.h \
            base/AudioPlaySource.h \
+           base/BaseTypes.h \
            base/Clipboard.h \
            base/Command.h \
            base/Debug.h \
@@ -138,7 +139,6 @@
            data/fileio/FileFinder.h \
            data/fileio/FileReadThread.h \
            data/fileio/FileSource.h \
-           data/fileio/MatchFileReader.h \
            data/fileio/MatrixFile.h \
            data/fileio/MIDIFileReader.h \
            data/fileio/MIDIFileWriter.h \
@@ -199,7 +199,6 @@
            data/fileio/DataFileReaderFactory.cpp \
            data/fileio/FileReadThread.cpp \
            data/fileio/FileSource.cpp \
-           data/fileio/MatchFileReader.cpp \
            data/fileio/MatrixFile.cpp \
            data/fileio/MIDIFileReader.cpp \
            data/fileio/MIDIFileWriter.cpp \
--- a/system/System.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/system/System.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -123,7 +123,7 @@
 #endif
 
 void
-GetRealMemoryMBAvailable(int &available, int &total)
+GetRealMemoryMBAvailable(ssize_t &available, ssize_t &total)
 {
     available = -1;
     total = -1;
@@ -175,11 +175,11 @@
 
     DWORDLONG size = wavail / 1048576;
     if (size > INT_MAX) size = INT_MAX;
-    available = int(size);
+    available = ssize_t(size);
 
     size = wtotal / 1048576;
     if (size > INT_MAX) size = INT_MAX;
-    total = int(size);
+    total = ssize_t(size);
 
     return;
 
@@ -243,7 +243,7 @@
 #endif
 }
 
-int
+ssize_t
 GetDiscSpaceMBAvailable(const char *path)
 {
 #ifdef _WIN32
@@ -252,7 +252,7 @@
 	  __int64 a = available.QuadPart;
         a /= 1048576;
         if (a > INT_MAX) a = INT_MAX;
-        return int(a);
+        return ssize_t(a);
     } else {
         cerr << "WARNING: GetDiskFreeSpaceEx failed: error code "
                   << GetLastError() << endl;
@@ -266,7 +266,7 @@
 //        cerr << "statvfs(" << path << ") says available: " << buf.f_bavail << ", block size: " << buf.f_bsize << endl;
         uint64_t available = ((buf.f_bavail / 1024) * buf.f_bsize) / 1024;
         if (available > INT_MAX) available = INT_MAX;
-        return int(available);
+        return ssize_t(available);
     } else {
         perror("statvfs failed");
         return -1;
@@ -323,5 +323,5 @@
 float modf(float x, float y) { return x - (y * floorf(x / y)); }
 
 double princarg(double a) { return mod(a + M_PI, -2 * M_PI) + M_PI; }
-float princargf(float a) { return modf(a + M_PI, -2 * M_PI) + M_PI; }
+float princargf(float a) { return float(princarg(a)); }
 
--- a/system/System.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/system/System.h	Mon Mar 23 11:26:28 2015 +0000
@@ -143,12 +143,13 @@
 extern ProcessStatus GetProcessStatus(int pid);
 
 // Return a vague approximation to the number of free megabytes of real memory.
-// Return -1 if unknown.
-extern void GetRealMemoryMBAvailable(int &available, int &total);
+// Return -1 if unknown. (Hence signed args)
+extern void GetRealMemoryMBAvailable(ssize_t &available, ssize_t &total);
 
-// Return a vague approximation to the number of free megabytes of disc space
-// on the partition containing the given path.  Return -1 if unknown.
-extern int GetDiscSpaceMBAvailable(const char *path);
+// Return a vague approximation to the number of free megabytes of
+// disc space on the partition containing the given path.  Return -1
+// if unknown. (Hence signed return type)
+extern ssize_t GetDiscSpaceMBAvailable(const char *path);
 
 extern void StoreStartupLocale();
 extern void RestoreStartupLocale();
--- a/transform/CSVFeatureWriter.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/CSVFeatureWriter.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -133,7 +133,7 @@
 
     QTextStream &stream = *sptr;
 
-    int n = features.size();
+    int n = (int)features.size();
 
     if (n == 0) return;
 
@@ -210,7 +210,7 @@
         }
     }
 
-    Vamp::RealTime duration;
+    ::RealTime duration;
     bool haveDuration = true;
     
     if (f.hasDuration) {
@@ -223,17 +223,17 @@
 
     if (m_sampleTiming) {
 
-        float rate = transform.getSampleRate();
+        sv_samplerate_t rate = transform.getSampleRate();
 
-        stream << Vamp::RealTime::realTime2Frame(f.timestamp, rate);
+        stream << ::RealTime::realTime2Frame(f.timestamp, rate);
 
         if (haveDuration) {
             stream << m_separator;
             if (m_endTimes) {
-                stream << Vamp::RealTime::realTime2Frame
-                    (f.timestamp + duration, rate);
+                stream << ::RealTime::realTime2Frame
+                    (::RealTime(f.timestamp) + duration, rate);
             } else {
-                stream << Vamp::RealTime::realTime2Frame(duration, rate);
+                stream << ::RealTime::realTime2Frame(duration, rate);
             }
         }
 
@@ -246,11 +246,11 @@
         if (haveDuration) {
             if (m_endTimes) {
                 QString endtime =
-                    (f.timestamp + duration).toString().c_str();
+                    (::RealTime(f.timestamp) + duration).toString().c_str();
                 endtime.replace(QRegExp("^ +"), "");
                 stream << m_separator << endtime;
             } else {
-                QString d = duration.toString().c_str();
+                QString d = ::RealTime(duration).toString().c_str();
                 d.replace(QRegExp("^ +"), "");
                 stream << m_separator << d;
             }
--- a/transform/FeatureExtractionModelTransformer.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/FeatureExtractionModelTransformer.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -235,7 +235,7 @@
     bool haveBinCount = m_descriptors[n]->hasFixedBinCount;
 
     if (haveBinCount) {
-	binCount = m_descriptors[n]->binCount;
+	binCount = (int)m_descriptors[n]->binCount;
     }
 
     m_needAdditionalModels[n] = false;
@@ -249,7 +249,7 @@
         haveExtents = true;
     }
 
-    int modelRate = input->getSampleRate();
+    sv_samplerate_t modelRate = input->getSampleRate();
     int modelResolution = 1;
 
     if (m_descriptors[n]->sampleType != 
@@ -264,7 +264,7 @@
 
     case Vamp::Plugin::OutputDescriptor::VariableSampleRate:
 	if (m_descriptors[n]->sampleRate != 0.0) {
-	    modelResolution = int(modelRate / m_descriptors[n]->sampleRate + 0.001);
+	    modelResolution = int(round(modelRate / m_descriptors[n]->sampleRate));
 	}
 	break;
 
@@ -281,8 +281,7 @@
         if (m_descriptors[n]->sampleRate > input->getSampleRate()) {
             modelResolution = 1;
         } else {
-            modelResolution = int(round(input->getSampleRate() /
-                                           m_descriptors[n]->sampleRate));
+            modelResolution = int(round(modelRate / m_descriptors[n]->sampleRate));
         }
 	break;
     }
@@ -573,7 +572,7 @@
     }
     if (m_abandoned) return;
 
-    int sampleRate = input->getSampleRate();
+    sv_samplerate_t sampleRate = input->getSampleRate();
 
     int channelCount = input->getChannelCount();
     if ((int)m_plugin->getMaxChannelCount() < channelCount) {
@@ -616,16 +615,16 @@
         }
     }
 
-    long startFrame = m_input.getModel()->getStartFrame();
-    long   endFrame = m_input.getModel()->getEndFrame();
+    sv_frame_t startFrame = m_input.getModel()->getStartFrame();
+    sv_frame_t endFrame = m_input.getModel()->getEndFrame();
 
     RealTime contextStartRT = primaryTransform.getStartTime();
     RealTime contextDurationRT = primaryTransform.getDuration();
 
-    long contextStart =
+    sv_frame_t contextStart =
         RealTime::realTime2Frame(contextStartRT, sampleRate);
 
-    long contextDuration =
+    sv_frame_t contextDuration =
         RealTime::realTime2Frame(contextDurationRT, sampleRate);
 
     if (contextStart == 0 || contextStart < startFrame) {
@@ -639,7 +638,7 @@
         contextDuration = endFrame - contextStart;
     }
 
-    long blockFrame = contextStart;
+    sv_frame_t blockFrame = contextStart;
 
     long prevCompletion = 0;
 
@@ -670,15 +669,15 @@
 //		  << blockFrame << ", endFrame " << endFrame << ", blockSize "
 //                  << blockSize << endl;
 
-	long completion =
-	    (((blockFrame - contextStart) / stepSize) * 99) /
-	    (contextDuration / stepSize + 1);
+	int completion = int
+	    ((((blockFrame - contextStart) / stepSize) * 99) /
+             (contextDuration / stepSize + 1));
 
 	// channelCount is either m_input.getModel()->channelCount or 1
 
         if (frequencyDomain) {
             for (int ch = 0; ch < channelCount; ++ch) {
-                int column = (blockFrame - startFrame) / stepSize;
+                int column = int((blockFrame - startFrame) / stepSize);
                 if (fftModels[ch]->getValuesAt(column, reals, imaginaries)) {
                     for (int i = 0; i <= blockSize/2; ++i) {
                         buffers[ch][i*2] = reals[i];
@@ -704,7 +703,7 @@
         if (m_abandoned) break;
 
 	Vamp::Plugin::FeatureSet features = m_plugin->process
-	    (buffers, Vamp::RealTime::frame2RealTime(blockFrame, sampleRate));
+	    (buffers, RealTime::frame2RealTime(blockFrame, sampleRate).toVampRealTime());
 
         if (m_abandoned) break;
 
@@ -756,14 +755,15 @@
 
 void
 FeatureExtractionModelTransformer::getFrames(int channelCount,
-                                             long startFrame, long size,
+                                             sv_frame_t startFrame,
+                                             sv_frame_t size,
                                              float **buffers)
 {
-    long offset = 0;
+    sv_frame_t offset = 0;
 
     if (startFrame < 0) {
         for (int c = 0; c < channelCount; ++c) {
-            for (int i = 0; i < size && startFrame + i < 0; ++i) {
+            for (sv_frame_t i = 0; i < size && startFrame + i < 0; ++i) {
                 buffers[c][i] = 0.0f;
             }
         }
@@ -776,7 +776,7 @@
     DenseTimeValueModel *input = getConformingInput();
     if (!input) return;
     
-    long got = 0;
+    sv_frame_t got = 0;
 
     if (channelCount == 1) {
 
@@ -786,7 +786,7 @@
         if (m_input.getChannel() == -1 && input->getChannelCount() > 1) {
             // use mean instead of sum, as plugin input
             float cc = float(input->getChannelCount());
-            for (long i = 0; i < size; ++i) {
+            for (sv_frame_t i = 0; i < size; ++i) {
                 buffers[0][i + offset] /= cc;
             }
         }
@@ -816,10 +816,10 @@
 
 void
 FeatureExtractionModelTransformer::addFeature(int n,
-                                              int blockFrame,
+                                              sv_frame_t blockFrame,
                                               const Vamp::Plugin::Feature &feature)
 {
-    int inputRate = m_input.getModel()->getSampleRate();
+    sv_samplerate_t inputRate = m_input.getModel()->getSampleRate();
 
 //    cerr << "FeatureExtractionModelTransformer::addFeature: blockFrame = "
 //              << blockFrame << ", hasTimestamp = " << feature.hasTimestamp
@@ -827,7 +827,7 @@
 //              << feature.hasDuration << ", duration = " << feature.duration
 //              << endl;
 
-    int frame = blockFrame;
+    sv_frame_t frame = blockFrame;
 
     if (m_descriptors[n]->sampleType ==
 	Vamp::Plugin::OutputDescriptor::VariableSampleRate) {
@@ -839,7 +839,7 @@
 		<< endl;
 	    return;
 	} else {
-	    frame = Vamp::RealTime::realTime2Frame(feature.timestamp, inputRate);
+	    frame = RealTime::realTime2Frame(feature.timestamp, inputRate);
 	}
 
     } else if (m_descriptors[n]->sampleType ==
@@ -849,7 +849,7 @@
             ++m_fixedRateFeatureNos[n];
         } else {
             RealTime ts(feature.timestamp.sec, feature.timestamp.nsec);
-            m_fixedRateFeatureNos[n] =
+            m_fixedRateFeatureNos[n] = (int)
                 lrint(ts.toDouble() * m_descriptors[n]->sampleRate);
         }
 
@@ -857,8 +857,9 @@
 //             << ", m_descriptor->sampleRate = " << m_descriptor->sampleRate
 //             << ", inputRate = " << inputRate
 //             << " giving frame = ";
-        frame = lrintf((m_fixedRateFeatureNos[n] / m_descriptors[n]->sampleRate)
-                       * int(inputRate));
+        frame = lrint((double(m_fixedRateFeatureNos[n])
+                       / m_descriptors[n]->sampleRate)
+                      * inputRate);
     }
 
     if (frame < 0) {
@@ -922,12 +923,12 @@
             value = feature.values[index++];
         }
 
-        float duration = 1;
+        sv_frame_t duration = 1;
         if (feature.hasDuration) {
-            duration = Vamp::RealTime::realTime2Frame(feature.duration, inputRate);
+            duration = RealTime::realTime2Frame(feature.duration, inputRate);
         } else {
-            if ((int)feature.values.size() > index) {
-                duration = feature.values[index++];
+            if (in_range_for(feature.values, index)) {
+                duration = lrintf(feature.values[index++]);
             }
         }
 
@@ -942,10 +943,11 @@
 
             FlexiNoteModel *model = getConformingOutput<FlexiNoteModel>(n);
             if (!model) return;
-            model->addPoint(FlexiNoteModel::Point(frame, value, // value is pitch
-                                             lrintf(duration),
-                                             velocity / 127.f,
-                                             feature.label.c_str()));
+            model->addPoint(FlexiNoteModel::Point(frame,
+                                                  value, // value is pitch
+                                                  duration,
+                                                  velocity / 127.f,
+                                                  feature.label.c_str()));
 			// GF: end -- added for flexi note model
         } else  if (isOutput<NoteModel>(n)) {
 
@@ -959,7 +961,7 @@
             NoteModel *model = getConformingOutput<NoteModel>(n);
             if (!model) return;
             model->addPoint(NoteModel::Point(frame, value, // value is pitch
-                                             lrintf(duration),
+                                             duration,
                                              velocity / 127.f,
                                              feature.label.c_str()));
         } else {
@@ -978,14 +980,16 @@
                         label = QString("[%1] %2").arg(i+1).arg(label);
                     }
 
-                    model->addPoint(RegionModel::Point(frame, value,
-                                                       lrintf(duration),
+                    model->addPoint(RegionModel::Point(frame,
+                                                       value,
+                                                       duration,
                                                        label));
                 }
             } else {
             
-                model->addPoint(RegionModel::Point(frame, value,
-                                                   lrintf(duration),
+                model->addPoint(RegionModel::Point(frame,
+                                                   value,
+                                                   duration,
                                                    feature.label.c_str()));
             }
         }
@@ -1005,7 +1009,7 @@
         if (!feature.hasTimestamp && m_fixedRateFeatureNos[n] >= 0) {
             model->setColumn(m_fixedRateFeatureNos[n], values);
         } else {
-            model->setColumn(frame / model->getResolution(), values);
+            model->setColumn(int(frame / model->getResolution()), values);
         }
 
     } else {
--- a/transform/FeatureExtractionModelTransformer.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/FeatureExtractionModelTransformer.h	Mon Mar 23 11:26:28 2015 +0000
@@ -66,12 +66,12 @@
     SparseTimeValueModel *getAdditionalModel(int transformNo, int binNo);
 
     void addFeature(int n,
-                    int blockFrame,
+                    sv_frame_t blockFrame,
 		    const Vamp::Plugin::Feature &feature);
 
     void setCompletion(int, int);
 
-    void getFrames(int channelCount, long startFrame, long size,
+    void getFrames(int channelCount, sv_frame_t startFrame, sv_frame_t size,
                    float **buffer);
 
     // just casts
--- a/transform/ModelTransformerFactory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/ModelTransformerFactory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -55,8 +55,8 @@
                                                       const std::vector<Model *> &candidateInputModels,
                                                       Model *defaultInputModel,
                                                       AudioPlaySource *source,
-                                                      int startFrame,
-                                                      int duration,
+                                                      sv_frame_t startFrame,
+                                                      sv_frame_t duration,
                                                       UserConfigurator *configurator)
 {
     ModelTransformer::Input input(0);
@@ -99,7 +99,7 @@
 
         Vamp::Plugin *vp =
             FeatureExtractionPluginFactory::instanceFor(id)->instantiatePlugin
-            (id, inputModel->getSampleRate());
+            (id, float(inputModel->getSampleRate()));
 
         plugin = vp;
 
@@ -107,7 +107,7 @@
 
         RealTimePluginFactory *factory = RealTimePluginFactory::instanceFor(id);
 
-        int sampleRate = inputModel->getSampleRate();
+        sv_samplerate_t sampleRate = inputModel->getSampleRate();
         int blockSize = 1024;
         int channels = 1;
         if (source) {
--- a/transform/ModelTransformerFactory.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/ModelTransformerFactory.h	Mon Mar 23 11:26:28 2015 +0000
@@ -47,8 +47,8 @@
                                Vamp::PluginBase *plugin,
                                Model *&inputModel,
                                AudioPlaySource *source,
-                               int startFrame,
-                               int duration,
+                               sv_frame_t startFrame,
+                               sv_frame_t duration,
                                const QMap<QString, Model *> &modelMap,
                                QStringList candidateModelNames,
                                QString defaultModelName) = 0;
@@ -67,8 +67,8 @@
                                  const std::vector<Model *> &candidateInputModels,
                                  Model *defaultInputModel,
                                  AudioPlaySource *source = 0,
-                                 int startFrame = 0,
-                                 int duration = 0,
+                                 sv_frame_t startFrame = 0,
+                                 sv_frame_t duration = 0,
                                  UserConfigurator *configurator = 0);
 
     class AdditionalModelHandler {
--- a/transform/RealTimeEffectModelTransformer.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/RealTimeEffectModelTransformer.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -82,7 +82,7 @@
 
     if (m_outputNo == -1) {
 
-        int outputChannels = m_plugin->getAudioOutputCount();
+        int outputChannels = (int)m_plugin->getAudioOutputCount();
         if (outputChannels > input->getChannelCount()) {
             outputChannels = input->getChannelCount();
         }
@@ -137,26 +137,26 @@
 
     if (stvm && (m_outputNo >= int(m_plugin->getControlOutputCount()))) return;
 
-    int sampleRate = input->getSampleRate();
+    sv_samplerate_t sampleRate = input->getSampleRate();
     int channelCount = input->getChannelCount();
     if (!wwfm && m_input.getChannel() != -1) channelCount = 1;
 
-    long blockSize = m_plugin->getBufferSize();
+    sv_frame_t blockSize = m_plugin->getBufferSize();
 
     float **inbufs = m_plugin->getAudioInputBuffers();
 
-    long startFrame = m_input.getModel()->getStartFrame();
-    long   endFrame = m_input.getModel()->getEndFrame();
+    sv_frame_t startFrame = m_input.getModel()->getStartFrame();
+    sv_frame_t endFrame = m_input.getModel()->getEndFrame();
 
     Transform transform = m_transforms[0];
     
     RealTime contextStartRT = transform.getStartTime();
     RealTime contextDurationRT = transform.getDuration();
 
-    long contextStart =
+    sv_frame_t contextStart =
         RealTime::realTime2Frame(contextStartRT, sampleRate);
 
-    long contextDuration =
+    sv_frame_t contextDuration =
         RealTime::realTime2Frame(contextDurationRT, sampleRate);
 
     if (contextStart == 0 || contextStart < startFrame) {
@@ -174,20 +174,20 @@
         wwfm->setStartFrame(contextStart);
     }
 
-    long blockFrame = contextStart;
+    sv_frame_t blockFrame = contextStart;
 
-    long prevCompletion = 0;
+    int prevCompletion = 0;
 
-    long latency = m_plugin->getLatency();
+    sv_frame_t latency = m_plugin->getLatency();
 
     while (blockFrame < contextStart + contextDuration + latency &&
            !m_abandoned) {
 
-	long completion =
-	    (((blockFrame - contextStart) / blockSize) * 99) /
-	    (1 + ((contextDuration) / blockSize));
+	int completion = int
+	    ((((blockFrame - contextStart) / blockSize) * 99) /
+             (1 + ((contextDuration) / blockSize)));
 
-	long got = 0;
+	sv_frame_t got = 0;
 
 	if (channelCount == 1) {
             if (inbufs && inbufs[0]) {
@@ -197,7 +197,7 @@
                     inbufs[0][got++] = 0.0;
                 }          
                 for (int ch = 1; ch < (int)m_plugin->getAudioInputCount(); ++ch) {
-                    for (long i = 0; i < blockSize; ++i) {
+                    for (sv_frame_t i = 0; i < blockSize; ++i) {
                         inbufs[ch][i] = inbufs[0][i];
                     }
                 }
@@ -214,7 +214,7 @@
                     ++got;
                 }
                 for (int ch = channelCount; ch < (int)m_plugin->getAudioInputCount(); ++ch) {
-                    for (long i = 0; i < blockSize; ++i) {
+                    for (sv_frame_t i = 0; i < blockSize; ++i) {
                         inbufs[ch][i] = inbufs[ch % channelCount][i];
                     }
                 }
@@ -235,13 +235,13 @@
         }
 */
 
-        m_plugin->run(Vamp::RealTime::frame2RealTime(blockFrame, sampleRate));
+        m_plugin->run(RealTime::frame2RealTime(blockFrame, sampleRate));
 
         if (stvm) {
 
             float value = m_plugin->getControlOutputValue(m_outputNo);
 
-            long pointFrame = blockFrame;
+            sv_frame_t pointFrame = blockFrame;
             if (pointFrame > latency) pointFrame -= latency;
             else pointFrame = 0;
 
@@ -255,13 +255,13 @@
             if (outbufs) {
 
                 if (blockFrame >= latency) {
-                    long writeSize = std::min
+                    sv_frame_t writeSize = std::min
                         (blockSize,
                          contextStart + contextDuration + latency - blockFrame);
                     wwfm->addSamples(outbufs, writeSize);
                 } else if (blockFrame + blockSize >= latency) {
-                    long offset = latency - blockFrame;
-                    long count = blockSize - offset;
+                    sv_frame_t offset = latency - blockFrame;
+                    sv_frame_t count = blockSize - offset;
                     float **tmp = new float *[channelCount];
                     for (int c = 0; c < channelCount; ++c) {
                         tmp[c] = outbufs[c] + offset;
--- a/transform/Transform.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/Transform.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -379,14 +379,14 @@
     m_duration = d;
 }
     
-float
+sv_samplerate_t
 Transform::getSampleRate() const
 {
     return m_sampleRate;
 }
 
 void
-Transform::setSampleRate(float rate)
+Transform::setSampleRate(sv_samplerate_t rate)
 {
     m_sampleRate = rate;
 }
--- a/transform/Transform.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/Transform.h	Mon Mar 23 11:26:28 2015 +0000
@@ -135,8 +135,8 @@
     RealTime getDuration() const; // 0 -> all
     void setDuration(RealTime d);
     
-    float getSampleRate() const; // 0 -> as input
-    void setSampleRate(float rate);
+    sv_samplerate_t getSampleRate() const; // 0 -> as input
+    void setSampleRate(sv_samplerate_t rate);
 
     void toXml(QTextStream &stream, QString indent = "",
                QString extraAttributes = "") const;
@@ -194,7 +194,7 @@
     WindowType m_windowType;
     RealTime m_startTime;
     RealTime m_duration;
-    float m_sampleRate;
+    sv_samplerate_t m_sampleRate;
 };
 
 typedef std::vector<Transform> Transforms;
--- a/transform/TransformFactory.cpp	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/TransformFactory.cpp	Mon Mar 23 11:26:28 2015 +0000
@@ -750,7 +750,7 @@
 }
 
 Transform
-TransformFactory::getDefaultTransformFor(TransformId id, int rate)
+TransformFactory::getDefaultTransformFor(TransformId id, sv_samplerate_t rate)
 {
     Transform t;
     t.setIdentifier(id);
@@ -782,11 +782,12 @@
 }
 
 Vamp::PluginBase *
-TransformFactory::instantiateDefaultPluginFor(TransformId identifier, int rate)
+TransformFactory::instantiateDefaultPluginFor(TransformId identifier,
+                                              sv_samplerate_t rate)
 {
     Transform t;
     t.setIdentifier(identifier);
-    if (rate == 0) rate = 44100;
+    if (rate == 0) rate = 44100.0;
     QString pluginId = t.getPluginIdentifier();
 
     Vamp::PluginBase *plugin = 0;
@@ -913,8 +914,8 @@
             instantiatePlugin(id, 44100);
         if (!plugin) return false;
 
-        min = plugin->getMinChannelCount();
-        max = plugin->getMaxChannelCount();
+        min = (int)plugin->getMinChannelCount();
+        max = (int)plugin->getMaxChannelCount();
         delete plugin;
 
         return true;
@@ -1040,10 +1041,10 @@
     } else {
         Vamp::Plugin::InputDomain domain = vp->getInputDomain();
         if (!transform.getStepSize()) {
-            transform.setStepSize(vp->getPreferredStepSize());
+            transform.setStepSize((int)vp->getPreferredStepSize());
         }
         if (!transform.getBlockSize()) {
-            transform.setBlockSize(vp->getPreferredBlockSize());
+            transform.setBlockSize((int)vp->getPreferredBlockSize());
         }
         if (!transform.getBlockSize()) {
             transform.setBlockSize(1024);
--- a/transform/TransformFactory.h	Mon Mar 23 10:04:48 2015 +0000
+++ b/transform/TransformFactory.h	Mon Mar 23 11:26:28 2015 +0000
@@ -88,7 +88,7 @@
      * with different parameters and execution context settings.
      * Return the default one for the given transform.
      */
-    Transform getDefaultTransformFor(TransformId identifier, int rate = 0);
+    Transform getDefaultTransformFor(TransformId identifier, sv_samplerate_t rate = 0);
 
     /**
      * Full name of a transform, suitable for putting on a menu.
@@ -210,7 +210,7 @@
     void populateFeatureExtractionPlugins(TransformDescriptionMap &);
     void populateRealTimePlugins(TransformDescriptionMap &);
 
-    Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, int rate);
+    Vamp::PluginBase *instantiateDefaultPluginFor(TransformId id, sv_samplerate_t rate);
     QMutex m_transformsMutex;
     QMutex m_uninstalledTransformsMutex;