Mercurial > hg > svgui
changeset 979:98827470ada2 3.0-integration
Merge from branch normalize_hybrid_option
author | Chris Cannam |
---|---|
date | Fri, 26 Jun 2015 14:13:31 +0100 |
parents | 64c2b3a4435a (diff) 1986c9b0d9c3 (current diff) |
children | 3f7cdfc56dce |
files | layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h widgets/PropertyBox.cpp |
diffstat | 99 files changed, 5029 insertions(+), 2699 deletions(-) [+] |
line wrap: on
line diff
--- a/acinclude.m4 Fri Sep 12 11:38:55 2014 +0100 +++ b/acinclude.m4 Fri Jun 26 14:13:31 2015 +0100 @@ -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/configure Fri Sep 12 11:38:55 2014 +0100 +++ b/configure Fri Jun 26 14:13:31 2015 +0100 @@ -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 -Woverloaded-virtual -Wformat-nonliteral -Wformat-security -Winit-self -Wswitch-enum -Wconversion -pipe" + CXXFLAGS_DEBUG="$CXXFLAGS_ANY -Werror -g" + CXXFLAGS_RELEASE="$CXXFLAGS_ANY -g0 -O2" + CXXFLAGS_MINIMAL="$CXXFLAGS_ANY -g0 -O0" fi CXXFLAGS_BUILD="$CXXFLAGS_RELEASE"
--- a/configure.ac Fri Sep 12 11:38:55 2014 +0100 +++ b/configure.ac Fri Jun 26 14:13:31 2015 +0100 @@ -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 -Woverloaded-virtual -Wformat-nonliteral -Wformat-security -Winit-self -Wswitch-enum -Wconversion -pipe" + CXXFLAGS_DEBUG="$CXXFLAGS_ANY -Werror -g" + CXXFLAGS_RELEASE="$CXXFLAGS_ANY -g0 -O2" + CXXFLAGS_MINIMAL="$CXXFLAGS_ANY -g0 -O0" fi CXXFLAGS_BUILD="$CXXFLAGS_RELEASE"
--- a/layer/Colour3DPlotLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/Colour3DPlotLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -34,6 +34,8 @@ #include <alloca.h> #endif +using std::vector; + //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1 @@ -52,6 +54,7 @@ m_normalizeVisibleArea(false), m_normalizeHybrid(false), m_invertVertical(false), + m_rectified(false), m_opaque(false), m_smooth(false), m_peakResolution(256), @@ -78,8 +81,8 @@ connectSignals(m_model); connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged())); - connect(m_model, SIGNAL(modelChangedWithin(int, int)), - this, SLOT(modelChangedWithin(int, int))); + connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), + this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t))); m_peakResolution = 256; if (model->getResolution() > 512) { @@ -107,13 +110,13 @@ } void -Colour3DPlotLayer::cacheInvalid(int startFrame, int endFrame) +Colour3DPlotLayer::cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame) { if (!m_cache || !m_model) return; int modelResolution = m_model->getResolution(); - int start = startFrame / modelResolution; - int end = endFrame / modelResolution + 1; + int start = int(startFrame / modelResolution); + int end = int(endFrame / modelResolution + 1); if (m_cacheValidStart < end) m_cacheValidStart = end; if (m_cacheValidEnd > start) m_cacheValidEnd = start; if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart; @@ -135,7 +138,7 @@ } void -Colour3DPlotLayer::modelChangedWithin(int startFrame, int endFrame) +Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) { if (!m_colourScaleSet && m_colourScale == LinearScale) { if (m_model && m_model->getWidth() > 50) { @@ -160,6 +163,7 @@ list.push_back("Gain"); list.push_back("Bin Scale"); list.push_back("Invert Vertical Scale"); + list.push_back("Show Rectified"); list.push_back("Opaque"); list.push_back("Smooth"); return list; @@ -173,6 +177,7 @@ if (name == "Normalize Columns") return tr("Normalize Columns"); if (name == "Normalize Visible Area") return tr("Normalize Visible Area"); if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale"); + if (name == "Show Rectified") return tr("Half-Wave Rectify"); if (name == "Gain") return tr("Gain"); if (name == "Opaque") return tr("Always Opaque"); if (name == "Smooth") return tr("Smooth"); @@ -186,6 +191,7 @@ if (name == "Normalize Columns") return "normalise-columns"; if (name == "Normalize Visible Area") return "normalise"; if (name == "Invert Vertical Scale") return "invert-vertical"; + if (name == "Show Rectified") return "derivative"; if (name == "Opaque") return "opaque"; if (name == "Smooth") return "smooth"; return ""; @@ -198,6 +204,7 @@ if (name == "Normalize Columns") return ToggleProperty; if (name == "Normalize Visible Area") return ToggleProperty; if (name == "Invert Vertical Scale") return ToggleProperty; + if (name == "Show Rectified") return ToggleProperty; if (name == "Opaque") return ToggleProperty; if (name == "Smooth") return ToggleProperty; return ValueProperty; @@ -209,6 +216,7 @@ if (name == "Normalize Columns" || name == "Normalize Visible Area" || name == "Colour Scale" || + name == "Show Rectified" || name == "Gain") return tr("Scale"); if (name == "Bin Scale" || name == "Invert Vertical Scale") return tr("Bins"); @@ -234,11 +242,11 @@ *min = -50; *max = 50; - *deflt = lrintf(log10(1.f) * 20.0);; + *deflt = int(lrint(log10(1.0) * 20.0)); if (*deflt < *min) *deflt = *min; if (*deflt > *max) *deflt = *max; - val = lrintf(log10(m_gain) * 20.0); + val = int(lrint(log10(m_gain) * 20.0)); if (val < *min) val = *min; if (val > *max) val = *max; @@ -273,6 +281,13 @@ *deflt = 0; val = (m_invertVertical ? 1 : 0); + } else if (name == "Show Rectified") { + + if (min) *min = 0; + if (max) *max = 0; + if (deflt) *deflt = 0; + val = (m_rectified ? 1.0 : 0.0); + } else if (name == "Bin Scale") { *min = 0; @@ -336,7 +351,7 @@ Colour3DPlotLayer::setProperty(const PropertyName &name, int value) { if (name == "Gain") { - setGain(pow(10, float(value)/20.0)); + setGain(float(pow(10, value/20.0))); } else if (name == "Colour Scale") { switch (value) { default: @@ -353,6 +368,8 @@ setNormalizeVisibleArea(value ? true : false); } else if (name == "Invert Vertical Scale") { setInvertVertical(value ? true : false); + } else if (name == "Show Rectified") { + setShowRectified(value > 0.5); } else if (name == "Opaque") { setOpaque(value ? true : false); } else if (name == "Smooth") { @@ -470,6 +487,15 @@ } void +Colour3DPlotLayer::setShowRectified(bool show) +{ + if (m_rectified == show) return; + m_rectified = show; + cacheInvalid(); + emit layerParametersChanged(); +} + +void Colour3DPlotLayer::setOpaque(bool n) { if (m_opaque == n) return; @@ -504,7 +530,7 @@ } void -Colour3DPlotLayer::setLayerDormant(const View *v, bool dormant) +Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) { if (dormant) { @@ -528,7 +554,7 @@ } bool -Colour3DPlotLayer::isLayerScrollable(const View *v) const +Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider *v) const { if (m_normalizeVisibleArea) { return false; @@ -541,13 +567,13 @@ } bool -Colour3DPlotLayer::getValueExtents(float &min, float &max, +Colour3DPlotLayer::getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const { if (!m_model) return false; min = 0; - max = m_model->getHeight(); + max = double(m_model->getHeight()); logarithmic = false; unit = ""; @@ -556,37 +582,39 @@ } bool -Colour3DPlotLayer::getDisplayExtents(float &min, float &max) const +Colour3DPlotLayer::getDisplayExtents(double &min, double &max) const { if (!m_model) return false; + double hmax = double(m_model->getHeight()); + min = m_miny; max = m_maxy; if (max <= min) { min = 0; - max = m_model->getHeight(); + max = hmax; } if (min < 0) min = 0; - if (max > m_model->getHeight()) max = m_model->getHeight(); + if (max > hmax) max = hmax; return true; } bool -Colour3DPlotLayer::setDisplayExtents(float min, float max) +Colour3DPlotLayer::setDisplayExtents(double min, double max) { if (!m_model) return false; - m_miny = lrintf(min); - m_maxy = lrintf(max); + m_miny = int(lrint(min)); + m_maxy = int(lrint(max)); emit layerParametersChanged(); return true; } bool -Colour3DPlotLayer::getYScaleValue(const View *, int, - float &, QString &) const +Colour3DPlotLayer::getYScaleValue(const LayerGeometryProvider *, int, + double &, QString &) const { return false;//!!! } @@ -606,9 +634,9 @@ { if (!m_model) return 0; - float min, max; + double min, max; getDisplayExtents(min, max); - return m_model->getHeight() - lrintf(max - min); + return m_model->getHeight() - int(lrint(max - min)); } void @@ -620,8 +648,8 @@ int dist = m_model->getHeight() - step; if (dist < 1) dist = 1; - float centre = m_miny + (float(m_maxy) - float(m_miny)) / 2.f; - m_miny = lrintf(centre - float(dist)/2); + double centre = m_miny + (m_maxy - m_miny) / 2.0; + m_miny = int(lrint(centre - dist/2.0)); if (m_miny < 0) m_miny = 0; m_maxy = m_miny + dist; if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight(); @@ -640,58 +668,70 @@ 0, m_model->getHeight(), ""); } -float -Colour3DPlotLayer::getYForBin(View *v, float bin) const +double +Colour3DPlotLayer::getYForBin(LayerGeometryProvider *v, double bin) const { - float y = bin; + double y = bin; if (!m_model) return y; - float mn = 0, mx = m_model->getHeight(); + double mn = 0, mx = m_model->getHeight(); getDisplayExtents(mn, mx); - float h = v->height(); + double h = v->getPaintHeight(); if (m_binScale == LinearBinScale) { y = h - (((bin - mn) * h) / (mx - mn)); } else { - float logmin = mn + 1, logmax = mx + 1; + double logmin = mn + 1, logmax = mx + 1; LogRange::mapRange(logmin, logmax); y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin)); } return y; } -float -Colour3DPlotLayer::getBinForY(View *v, float y) const +int +Colour3DPlotLayer::getIYForBin(LayerGeometryProvider *v, int bin) const { - float bin = y; + return int(round(getYForBin(v, bin))); +} + +double +Colour3DPlotLayer::getBinForY(LayerGeometryProvider *v, double y) const +{ + double bin = y; if (!m_model) return bin; - float mn = 0, mx = m_model->getHeight(); + double mn = 0, mx = m_model->getHeight(); getDisplayExtents(mn, mx); - float h = v->height(); + double h = v->getPaintHeight(); if (m_binScale == LinearBinScale) { bin = mn + ((h - y) * (mx - mn)) / h; } else { - float logmin = mn + 1, logmax = mx + 1; + double logmin = mn + 1, logmax = mx + 1; LogRange::mapRange(logmin, logmax); bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1; } return bin; } +int +Colour3DPlotLayer::getIBinForY(LayerGeometryProvider *v, int y) const +{ + return int(floor(getBinForY(v, y))); +} + QString -Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const +Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { if (!m_model) return ""; int x = pos.x(); int y = pos.y(); - int modelStart = m_model->getStartFrame(); + sv_frame_t modelStart = m_model->getStartFrame(); int modelResolution = m_model->getResolution(); - float srRatio = - float(v->getViewManager()->getMainModelSampleRate()) / - float(m_model->getSampleRate()); + double srRatio = + v->getViewManager()->getMainModelSampleRate() / + m_model->getSampleRate(); - int sx0 = int((v->getFrameForX(x) / srRatio - modelStart) / + int sx0 = int((double(v->getFrameForX(x)) / srRatio - double(modelStart)) / modelResolution); int f0 = sx0 * modelResolution; @@ -708,10 +748,10 @@ if (symin < 0) symin = 0; if (symax > sh) symax = sh; - // float binHeight = float(v->height()) / (symax - symin); -// int sy = int((v->height() - y) / binHeight) + symin; + // double binHeight = double(v->getPaintHeight()) / (symax - symin); +// int sy = int((v->getPaintHeight() - y) / binHeight) + symin; - int sy = getBinForY(v, y); + int sy = getIBinForY(v, y); if (sy < 0 || sy >= m_model->getHeight()) { return ""; @@ -739,14 +779,15 @@ } int -Colour3DPlotLayer::getColourScaleWidth(QPainter &) const +Colour3DPlotLayer::getColourScaleWidth(QPainter &p) const { - int cw = 20; + // Font is rotated + int cw = p.fontMetrics().height(); return cw; } int -Colour3DPlotLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const +Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const { if (!m_model) return 0; @@ -768,7 +809,7 @@ } void -Colour3DPlotLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const +Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const { if (!m_model) return; @@ -779,11 +820,11 @@ int ch = h - 20; if (ch > 20 && m_cache) { - float min = m_model->getMinimumLevel(); - float max = m_model->getMaximumLevel(); + double min = m_model->getMinimumLevel(); + double max = m_model->getMaximumLevel(); - float mmin = min; - float mmax = max; + double mmin = min; + double mmax = max; if (m_colourScale == LogScale) { LogRange::mapRange(mmin, mmax); @@ -792,23 +833,23 @@ mmax = 1.f; } else if (m_colourScale == AbsoluteScale) { if (mmin < 0) { - if (fabsf(mmin) > fabsf(mmax)) mmax = fabsf(mmin); - else mmax = fabsf(mmax); + if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin); + else mmax = fabs(mmax); mmin = 0; } else { - mmin = fabsf(mmin); - mmax = fabsf(mmax); + mmin = fabs(mmin); + mmax = fabs(mmax); } } - if (max == min) max = min + 1.0; - if (mmax == mmin) mmax = mmin + 1.0; + if (max == min) max = min + 1.f; + if (mmax == mmin) mmax = mmin + 1.f; paint.setPen(v->getForeground()); paint.drawRect(4, 10, cw - 8, ch+1); for (int y = 0; y < ch; ++y) { - float value = ((max - min) * (ch - y - 1)) / ch + min; + double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min; if (m_colourScale == LogScale) { value = LogRange::map(value); } @@ -828,7 +869,7 @@ paint.save(); QFont font = paint.font(); - font.setPixelSize(10); + font.setPixelSize(int(font.pixelSize() * 0.65)); paint.setFont(font); int msw = paint.fontMetrics().width(maxstr); @@ -866,18 +907,20 @@ int py = h; + int defaultFontHeight = paint.fontMetrics().height(); + for (int i = symin; i <= symax; ++i) { int y0; - y0 = lrintf(getYForBin(v, i)); + y0 = getIYForBin(v, i); int h = py - y0; if (i > symin) { if (paint.fontMetrics().height() >= h) { - if (h >= 8) { + if (h >= defaultFontHeight * 0.8) { QFont tf = paint.font(); - tf.setPixelSize(h-2); + tf.setPixelSize(int(h * 0.8)); paint.setFont(tf); } else { continue; @@ -914,12 +957,25 @@ { Profiler profiler("Colour3DPlotLayer::getColumn"); + DenseThreeDimensionalModel::Column prev; + if (m_rectified && (col > m_model->getStartFrame())) { + prev = m_model->getColumn(col - 1); + } + DenseThreeDimensionalModel::Column values = m_model->getColumn(col); + + if (m_rectified && !prev.empty()) { + for (int y = 0; y < values.size(); ++y) { + if (values[y] < prev[y]) values[y] = 0; + else values[y] -= prev[y]; + } + } + while (values.size() < m_model->getHeight()) values.push_back(0.f); if (!m_normalizeColumns && !m_normalizeHybrid) return values; - float colMax = 0.f, colMin = 0.f; - float min = 0.f, max = 0.f; + double colMax = 0.f, colMin = 0.f; + double min = 0.f, max = 0.f; min = m_model->getMinimumLevel(); max = m_model->getMaximumLevel(); @@ -932,17 +988,17 @@ for (int y = 0; y < values.size(); ++y) { - float value = values.at(y); - float norm = (value - colMin) / (colMax - colMin); - float newvalue = min + (max - min) * norm; + double value = values.at(y); + double norm = (value - colMin) / (colMax - colMin); + double newvalue = min + (max - min) * norm; - if (value != newvalue) values[y] = newvalue; + if (value != newvalue) values[y] = float(newvalue); } if (m_normalizeHybrid && (colMax > 0.0)) { - float logmax = log10(colMax); + double logmax = log10(colMax); for (int y = 0; y < values.size(); ++y) { - values[y] *= logmax; + values[y] = float(values[y] * logmax); } } @@ -954,12 +1010,12 @@ { Profiler profiler("Colour3DPlotLayer::fillCache", true); - int modelStart = m_model->getStartFrame(); - int modelEnd = m_model->getEndFrame(); + sv_frame_t modelStart = m_model->getStartFrame(); + sv_frame_t modelEnd = m_model->getEndFrame(); int modelResolution = m_model->getResolution(); - int modelStartBin = modelStart / modelResolution; - int modelEndBin = modelEnd / modelResolution; + int modelStartBin = int(modelStart / modelResolution); + int modelEndBin = int(modelEnd / modelResolution); #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT cerr << "Colour3DPlotLayer::fillCache: range " << firstBin << " -> " << lastBin << " of model range " << modelStartBin << " -> " << modelEndBin << " (model resolution " << modelResolution << ")" << endl; @@ -1069,8 +1125,8 @@ DenseThreeDimensionalModel::Column values; - float min = m_model->getMinimumLevel(); - float max = m_model->getMaximumLevel(); + double min = m_model->getMinimumLevel(); + double max = m_model->getMaximumLevel(); if (m_colourScale == LogScale) { LogRange::mapRange(min, max); @@ -1079,16 +1135,16 @@ max = 1.f; } else if (m_colourScale == AbsoluteScale) { if (min < 0) { - if (fabsf(min) > fabsf(max)) max = fabsf(min); - else max = fabsf(max); + if (fabs(min) > fabs(max)) max = fabs(min); + else max = fabs(max); min = 0; } else { - min = fabsf(min); - max = fabsf(max); + min = fabs(min); + max = fabs(max); } } - if (max == min) max = min + 1.0; + if (max == min) max = min + 1.f; ColourMapper mapper(m_colourMap, 0.f, 255.f); @@ -1102,7 +1158,7 @@ } } - float visibleMax = 0.f, visibleMin = 0.f; + double visibleMax = 0.f, visibleMin = 0.f; if (normalizeVisible) { @@ -1110,7 +1166,7 @@ values = getColumn(c); - float colMax = 0.f, colMin = 0.f; + double colMax = 0.f, colMin = 0.f; for (int y = 0; y < cacheHeight; ++y) { if (y >= values.size()) break; @@ -1128,12 +1184,12 @@ if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax); } else if (m_colourScale == AbsoluteScale) { if (visibleMin < 0) { - if (fabsf(visibleMin) > fabsf(visibleMax)) visibleMax = fabsf(visibleMin); - else visibleMax = fabsf(visibleMax); + if (fabs(visibleMin) > fabs(visibleMax)) visibleMax = fabs(visibleMin); + else visibleMax = fabs(visibleMax); visibleMin = 0; } else { - visibleMin = fabsf(visibleMin); - visibleMax = fabsf(visibleMax); + visibleMin = fabs(visibleMin); + visibleMax = fabs(visibleMax); } } } @@ -1162,7 +1218,7 @@ for (int y = 0; y < cacheHeight; ++y) { - float value = min; + double value = min; if (y < values.size()) { value = values.at(y); } @@ -1172,11 +1228,11 @@ if (m_colourScale == LogScale) { value = LogRange::map(value); } else if (m_colourScale == AbsoluteScale) { - value = fabsf(value); + value = fabs(value); } if (normalizeVisible) { - float norm = (value - visibleMin) / (visibleMax - visibleMin); + double norm = (value - visibleMin) / (visibleMax - visibleMin); value = min + (max - min) * norm; } @@ -1230,17 +1286,16 @@ } bool -Colour3DPlotLayer::shouldPaintDenseIn(const View *v) const +Colour3DPlotLayer::shouldPaintDenseIn(const LayerGeometryProvider *v) const { if (!m_model || !v || !(v->getViewManager())) { return false; } - float srRatio = - float(v->getViewManager()->getMainModelSampleRate()) / - float(m_model->getSampleRate()); + double srRatio = + v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); if (m_opaque || m_smooth || - m_model->getHeight() >= v->height() || + m_model->getHeight() >= v->getPaintHeight() || ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) { return true; } @@ -1248,7 +1303,7 @@ } void -Colour3DPlotLayer::paint(View *v, QPainter &paint, QRect rect) const +Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { /* if (m_model) { @@ -1263,16 +1318,16 @@ int completion = 0; if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) { if (completion > 0) { - paint.fillRect(0, 10, v->width() * completion / 100, + paint.fillRect(0, 10, v->getPaintWidth() * completion / 100, 10, QColor(120, 120, 120)); } return; } - if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect(); + if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->getPaintRect(); - int modelStart = m_model->getStartFrame(); - int modelEnd = m_model->getEndFrame(); + sv_frame_t modelStart = m_model->getStartFrame(); + sv_frame_t modelEnd = m_model->getEndFrame(); int modelResolution = m_model->getResolution(); // The cache is from the model's start frame to the model's end @@ -1287,15 +1342,14 @@ int x0 = rect.left(); int x1 = rect.right() + 1; - int h = v->height(); + int h = v->getPaintHeight(); - float srRatio = - float(v->getViewManager()->getMainModelSampleRate()) / - float(m_model->getSampleRate()); + double srRatio = + v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate(); - int sx0 = int((v->getFrameForX(x0) / srRatio - modelStart) + int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart)) / modelResolution); - int sx1 = int((v->getFrameForX(x1) / srRatio - modelStart) + int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart)) / modelResolution); int sh = m_model->getHeight(); @@ -1331,16 +1385,18 @@ QPoint illuminatePos; bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos); - char labelbuf[10]; + + const int buflen = 40; + char labelbuf[buflen]; for (int sx = sx0; sx <= sx1; ++sx) { - int fx = sx * modelResolution; + sv_frame_t fx = sx * modelResolution; if (fx + modelResolution <= modelStart || fx > modelEnd) continue; - int rx0 = v->getXForFrame(int((fx + modelStart) * srRatio)); - int rx1 = v->getXForFrame(int((fx + modelStart + modelResolution + 1) * srRatio)); + int rx0 = v->getXForFrame(int(double(fx + modelStart) * srRatio)); + int rx1 = v->getXForFrame(int(double(fx + modelStart + modelResolution + 1) * srRatio)); int rw = rx1 - rx0; if (rw < 1) rw = 1; @@ -1351,8 +1407,8 @@ for (int sy = symin; sy < symax; ++sy) { - int ry0 = getYForBin(v, sy); - int ry1 = getYForBin(v, sy + 1); + int ry0 = getIYForBin(v, sy); + int ry1 = getIYForBin(v, sy + 1); QRect r(rx0, ry1, rw, ry0 - ry1); QRgb pixel = qRgb(255, 255, 255); @@ -1394,8 +1450,8 @@ if (showLabel) { if (sx >= 0 && sx < m_cache->width() && sy >= 0 && sy < m_cache->height()) { - float value = m_model->getValueAt(sx, sy); - sprintf(labelbuf, "%06f", value); + double value = m_model->getValueAt(sx, sy); + snprintf(labelbuf, buflen, "%06f", value); QString text(labelbuf); paint.setPen(v->getBackground()); paint.drawText(rx0 + 2, @@ -1408,23 +1464,23 @@ } void -Colour3DPlotLayer::paintDense(View *v, QPainter &paint, QRect rect) const +Colour3DPlotLayer::paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { Profiler profiler("Colour3DPlotLayer::paintDense", true); if (!m_cache) return; - float modelStart = m_model->getStartFrame(); - float modelResolution = m_model->getResolution(); + double modelStart = double(m_model->getStartFrame()); + double modelResolution = double(m_model->getResolution()); - int mmsr = v->getViewManager()->getMainModelSampleRate(); - int msr = m_model->getSampleRate(); - float srRatio = float(mmsr) / float(msr); + sv_samplerate_t mmsr = v->getViewManager()->getMainModelSampleRate(); + sv_samplerate_t msr = m_model->getSampleRate(); + double srRatio = mmsr / msr; int x0 = rect.left(); int x1 = rect.right() + 1; const int w = x1 - x0; // const so it can be used as array size below - int h = v->height(); // we always paint full height + int h = v->getPaintHeight(); // we always paint full height int sh = m_model->getHeight(); int symin = m_miny; @@ -1474,29 +1530,26 @@ int sw = source->width(); - int xf = -1; - int nxf = v->getFrameForX(x0); + sv_frame_t xf = -1; + sv_frame_t nxf = v->getFrameForX(x0); - float epsilon = 0.000001; + double epsilon = 0.000001; -#ifdef __GNUC__ - float sxa[w * 2]; -#else - float *sxa = (float *)alloca(w * 2 * sizeof(float)); -#endif + vector<double> sxa(w*2); + for (int x = 0; x < w; ++x) { xf = nxf; nxf = xf + zoomLevel; - float sx0 = (float(xf) / srRatio - modelStart) / modelResolution; - float sx1 = (float(nxf) / srRatio - modelStart) / modelResolution; + double sx0 = (double(xf) / srRatio - modelStart) / modelResolution; + double sx1 = (double(nxf) / srRatio - modelStart) / modelResolution; sxa[x*2] = sx0; sxa[x*2 + 1] = sx1; } - float logmin = symin+1, logmax = symax+1; + double logmin = symin+1, logmax = symax+1; LogRange::mapRange(logmin, logmax); #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT @@ -1507,7 +1560,7 @@ for (int y = 0; y < h; ++y) { - float sy = getBinForY(v, y) - 0.5; + double sy = getBinForY(v, y) - 0.5; int syi = int(sy + epsilon); if (syi < 0 || syi >= source->height()) continue; @@ -1524,52 +1577,52 @@ targetLine[x] = 0; - float sx0 = sxa[x*2]; + double sx0 = sxa[x*2]; if (sx0 < 0) continue; int sx0i = int(sx0 + epsilon); if (sx0i >= sw) break; - float a = float(sourceLine[sx0i]); - float b = a; - float value; + double a = sourceLine[sx0i]; + double b = a; + double value; - float sx1 = sxa[x*2+1]; + double sx1 = sxa[x*2+1]; if (sx1 > sx0 + 1.f) { int sx1i = int(sx1); bool have = false; for (int sx = sx0i; sx <= sx1i; ++sx) { if (sx < 0 || sx >= sw) continue; if (!have) { - a = float(sourceLine[sx]); - b = float(nextSource[sx]); + a = sourceLine[sx]; + b = nextSource[sx]; have = true; } else { - a = std::max(a, float(sourceLine[sx])); - b = std::max(b, float(nextSource[sx])); + a = std::max(a, double(sourceLine[sx])); + b = std::max(b, double(nextSource[sx])); } } - float yprop = sy - syi; + double yprop = sy - syi; value = (a * (1.f - yprop) + b * yprop); } else { - a = float(sourceLine[sx0i]); - b = float(nextSource[sx0i]); - float yprop = sy - syi; + a = sourceLine[sx0i]; + b = nextSource[sx0i]; + double yprop = sy - syi; value = (a * (1.f - yprop) + b * yprop); int oi = sx0i + 1; - float xprop = sx0 - sx0i; + double xprop = sx0 - sx0i; xprop -= 0.5; if (xprop < 0) { oi = sx0i - 1; xprop = -xprop; } if (oi < 0 || oi >= sw) oi = sx0i; - a = float(sourceLine[oi]); - b = float(nextSource[oi]); + a = sourceLine[oi]; + b = nextSource[oi]; value = (value * (1.f - xprop) + (a * (1.f - yprop) + b * yprop) * xprop); } - int vi = lrintf(value); + int vi = int(lrint(value)); if (vi > 255) vi = 255; if (vi < 0) vi = 0; targetLine[x] = uchar(vi); @@ -1577,14 +1630,14 @@ } } else { - float sy0 = getBinForY(v, 0); + double sy0 = getBinForY(v, 0); int psy0i = -1, psy1i = -1; for (int y = 0; y < h; ++y) { - float sy1 = sy0; - sy0 = getBinForY(v, y + 1); + double sy1 = sy0; + sy0 = getBinForY(v, double(y + 1)); int sy0i = int(sy0 + epsilon); int sy1i = int(sy1); @@ -1611,11 +1664,11 @@ for (int x = 0; x < w; ++x) { - float sx1 = sxa[x*2 + 1]; + double sx1 = sxa[x*2 + 1]; if (sx1 < 0) continue; int sx1i = int(sx1); - float sx0 = sxa[x*2]; + double sx0 = sxa[x*2]; if (sx0 < 0) continue; int sx0i = int(sx0 + epsilon); if (sx0i >= sw) break; @@ -1642,7 +1695,7 @@ } bool -Colour3DPlotLayer::snapToFeatureFrame(View *v, int &frame, +Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -1651,8 +1704,8 @@ } resolution = m_model->getResolution(); - int left = (frame / resolution) * resolution; - int right = left + resolution; + sv_frame_t left = (frame / resolution) * resolution; + sv_frame_t right = left + resolution; switch (snap) { case SnapLeft: frame = left; break;
--- a/layer/Colour3DPlotLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/Colour3DPlotLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -49,20 +49,20 @@ return m_model ? m_model->getZoomConstraint() : 0; } virtual const Model *getModel() const { return m_model; } - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; - virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; + virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const; + virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void setLayerDormant(const View *v, bool dormant); + virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant); - virtual bool isLayerScrollable(const View *v) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; virtual ColourSignificance getLayerColourSignificance() const { return ColourHasMeaningfulValue; @@ -70,7 +70,7 @@ void setModel(const DenseThreeDimensionalModel *model); - virtual int getCompletion(View *) const { return m_model->getCompletion(); } + virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } virtual PropertyList getProperties() const; virtual PropertyType getPropertyType(const PropertyName &) const; @@ -139,20 +139,23 @@ void setInvertVertical(bool i); bool getInvertVertical() const; + void setShowRectified(bool); + bool getShowRectified() const { return m_rectified; } + void setOpaque(bool i); bool getOpaque() const; void setSmooth(bool i); bool getSmooth() const; - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const; - virtual bool getDisplayExtents(float &min, float &max) const; - virtual bool setDisplayExtents(float min, float max); + virtual bool getDisplayExtents(double &min, double &max) const; + virtual bool setDisplayExtents(double min, double max); - virtual bool getYScaleValue(const View *, int /* y */, - float &/* value */, QString &/* unit */) const; + virtual bool getYScaleValue(const LayerGeometryProvider *, int /* y */, + double &/* value */, QString &/* unit */) const; virtual int getVerticalZoomSteps(int &defaultStep) const; virtual int getCurrentVerticalZoomStep() const; @@ -166,9 +169,9 @@ protected slots: void cacheInvalid(); - void cacheInvalid(int startFrame, int endFrame); + void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame); void modelChanged(); - void modelChangedWithin(int, int); + void modelChangedWithin(sv_frame_t, sv_frame_t); protected: const DenseThreeDimensionalModel *m_model; // I do not own this @@ -187,6 +190,7 @@ bool m_normalizeVisibleArea; bool m_normalizeHybrid; bool m_invertVertical; + bool m_rectified; bool m_opaque; bool m_smooth; int m_peakResolution; @@ -202,15 +206,25 @@ * and the vertical scale is the usual way up). Bin number may be * fractional, to obtain a position part-way through a bin. */ - float getYForBin(View *, float bin) const; + double getYForBin(LayerGeometryProvider *, double bin) const; /** + * As getYForBin, but rounding to integer values. + */ + int getIYForBin(LayerGeometryProvider *, int bin) const; + + /** * Return the bin number, possibly fractional, at the given y * coordinate. Note that the whole numbers occur at the positions * at which the bins "start" (i.e. the bottom of the visible bin, * if the vertical scale is the usual way up). */ - float getBinForY(View *, float y) const; + double getBinForY(LayerGeometryProvider *, double y) const; + + /** + * As getBinForY, but rounding to integer values. + */ + int getIBinForY(LayerGeometryProvider *, int y) const; DenseThreeDimensionalModel::Column getColumn(int col) const; @@ -219,11 +233,11 @@ * are so small you can't see their borders. False for big, * translucent cells. */ - bool shouldPaintDenseIn(const View *) const; + bool shouldPaintDenseIn(const LayerGeometryProvider *) const; int getColourScaleWidth(QPainter &) const; void fillCache(int firstBin, int lastBin) const; - void paintDense(View *v, QPainter &paint, QRect rect) const; + void paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; }; #endif
--- a/layer/ColourDatabase.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/ColourDatabase.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -34,29 +34,28 @@ int ColourDatabase::getColourCount() const { - return m_colours.size(); + return int(m_colours.size()); } QString ColourDatabase::getColourName(int c) const { - if (c < 0 || size_t(c) >= m_colours.size()) return ""; + if (!in_range_for(m_colours, c)) return ""; return m_colours[c].name; } QColor ColourDatabase::getColour(int c) const { - if (c < 0 || size_t(c) >= m_colours.size()) return Qt::black; + if (!in_range_for(m_colours, c)) return Qt::black; return m_colours[c].colour; } QColor ColourDatabase::getColour(QString name) const { - for (ColourList::const_iterator i = m_colours.begin(); - i != m_colours.end(); ++i) { - if (i->name == name) return i->colour; + for (auto &c: m_colours) { + if (c.name == name) return c.colour; } return Qt::black; @@ -66,9 +65,8 @@ ColourDatabase::getColourIndex(QString name) const { int index = 0; - for (ColourList::const_iterator i = m_colours.begin(); - i != m_colours.end(); ++i) { - if (i->name == name) return index; + for (auto &c: m_colours) { + if (c.name == name) return index; ++index; } @@ -76,12 +74,11 @@ } int -ColourDatabase::getColourIndex(QColor c) const +ColourDatabase::getColourIndex(QColor col) const { int index = 0; - for (ColourList::const_iterator i = m_colours.begin(); - i != m_colours.end(); ++i) { - if (i->colour == c) return index; + for (auto &c: m_colours) { + if (c.colour == col) return index; ++index; } @@ -91,14 +88,14 @@ bool ColourDatabase::useDarkBackground(int c) const { - if (c < 0 || size_t(c) >= m_colours.size()) return false; + if (!in_range_for(m_colours, c)) return false; return m_colours[c].darkbg; } void ColourDatabase::setUseDarkBackground(int c, bool dark) { - if (c < 0 || size_t(c) >= m_colours.size()) return; + if (!in_range_for(m_colours, c)) return; if (m_colours[c].darkbg != dark) { m_colours[c].darkbg = dark; emit colourDatabaseChanged(); @@ -109,6 +106,7 @@ ColourDatabase::addColour(QColor c, QString name) { int index = 0; + for (ColourList::iterator i = m_colours.begin(); i != m_colours.end(); ++i) { if (i->name == name) { @@ -147,7 +145,7 @@ { colourName = ""; colourSpec = ""; - if (index < 0 || size_t(index) >= m_colours.size()) return; + if (!in_range_for(m_colours, index)) return; colourName = getColourName(index); QColor c = getColour(index);
--- a/layer/ColourMapper.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/ColourMapper.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -21,7 +21,7 @@ #include "base/Debug.h" -ColourMapper::ColourMapper(int map, float min, float max) : +ColourMapper::ColourMapper(int map, double min, double max) : QObject(), m_map(map), m_min(min), @@ -69,17 +69,16 @@ } QColor -ColourMapper::map(float value) const +ColourMapper::map(double value) const { - float norm = (value - m_min) / (m_max - m_min); - if (norm < 0.f) norm = 0.f; - if (norm > 1.f) norm = 1.f; + double norm = (value - m_min) / (m_max - m_min); + if (norm < 0.0) norm = 0.0; + if (norm > 1.0) norm = 1.0; - float h = 0.f, s = 0.f, v = 0.f, r = 0.f, g = 0.f, b = 0.f; + double h = 0.0, s = 0.0, v = 0.0, r = 0.0, g = 0.0, b = 0.0; bool hsv = true; -// float red = 0.f, green = 0.3333f; - float blue = 0.6666f, pieslice = 0.3333f; + double blue = 0.6666, pieslice = 0.3333; if (m_map >= getColourMapCount()) return Qt::black; StandardMap map = (StandardMap)m_map; @@ -87,8 +86,8 @@ switch (map) { case DefaultColours: - h = blue - norm * 2.f * pieslice; - s = 0.5f + norm/2.f; + h = blue - norm * 2.0 * pieslice; + s = 0.5f + norm/2.0; v = norm; break; @@ -98,53 +97,53 @@ break; case BlackOnWhite: - r = g = b = 1.f - norm; + r = g = b = 1.0 - norm; hsv = false; break; case RedOnBlue: - h = blue - pieslice/4.f + norm * (pieslice + pieslice/4.f); - s = 1.f; + h = blue - pieslice/4.0 + norm * (pieslice + pieslice/4.0); + s = 1.0; v = norm; break; case YellowOnBlack: - h = 0.15f; - s = 1.f; + h = 0.15; + s = 1.0; v = norm; break; case BlueOnBlack: h = blue; - s = 1.f; - v = norm * 2.f; - if (v > 1.f) { - v = 1.f; - s = 1.f - (sqrtf(norm) - 0.707f) * 3.413f; - if (s < 0.f) s = 0.f; - if (s > 1.f) s = 1.f; + s = 1.0; + v = norm * 2.0; + if (v > 1.0) { + v = 1.0; + s = 1.0 - (sqrt(norm) - 0.707) * 3.413; + if (s < 0.0) s = 0.0; + if (s > 1.0) s = 1.0; } break; case Sunset: - r = (norm - 0.24f) * 2.38f; - if (r > 1.f) r = 1.f; - if (r < 0.f) r = 0.f; - g = (norm - 0.64f) * 2.777f; - if (g > 1.f) g = 1.f; - if (g < 0.f) g = 0.f; + r = (norm - 0.24) * 2.38; + if (r > 1.0) r = 1.0; + if (r < 0.0) r = 0.0; + g = (norm - 0.64) * 2.777; + if (g > 1.0) g = 1.0; + if (g < 0.0) g = 0.0; b = (3.6f * norm); - if (norm > 0.277f) b = 2.f - b; - if (b > 1.f) b = 1.f; - if (b < 0.f) b = 0.f; + if (norm > 0.277) b = 2.0 - b; + if (b > 1.0) b = 1.0; + if (b < 0.0) b = 0.0; hsv = false; break; case FruitSalad: - h = blue + (pieslice/6.f) - norm; - if (h < 0.f) h += 1.f; - s = 1.f; - v = 1.f; + h = blue + (pieslice/6.0) - norm; + if (h < 0.0) h += 1.0; + s = 1.0; + v = 1.0; break; case Banded: @@ -164,47 +163,47 @@ case Printer: if (norm > 0.8) { - r = 1.f; + r = 1.0; } else if (norm > 0.7) { - r = 0.9f; + r = 0.9; } else if (norm > 0.6) { - r = 0.8f; + r = 0.8; } else if (norm > 0.5) { - r = 0.7f; + r = 0.7; } else if (norm > 0.4) { - r = 0.6f; + r = 0.6; } else if (norm > 0.3) { - r = 0.5f; + r = 0.5; } else if (norm > 0.2) { - r = 0.4f; + r = 0.4; } else { - r = 0.f; + r = 0.0; } - r = g = b = 1.f - r; + r = g = b = 1.0 - r; hsv = false; break; case HighGain: - if (norm <= 1.f / 256.f) { - norm = 0.f; + if (norm <= 1.0 / 256.0) { + norm = 0.0; } else { - norm = 0.1f + (powf(((norm - 0.5f) * 2.f), 3.f) + 1.f) / 2.081f; + norm = 0.1f + (pow(((norm - 0.5) * 2.0), 3.0) + 1.0) / 2.081; } // now as for Sunset - r = (norm - 0.24f) * 2.38f; - if (r > 1.f) r = 1.f; - if (r < 0.f) r = 0.f; - g = (norm - 0.64f) * 2.777f; - if (g > 1.f) g = 1.f; - if (g < 0.f) g = 0.f; + r = (norm - 0.24) * 2.38; + if (r > 1.0) r = 1.0; + if (r < 0.0) r = 0.0; + g = (norm - 0.64) * 2.777; + if (g > 1.0) g = 1.0; + if (g < 0.0) g = 0.0; b = (3.6f * norm); - if (norm > 0.277f) b = 2.f - b; - if (b > 1.f) b = 1.f; - if (b < 0.f) b = 0.f; + if (norm > 0.277) b = 2.0 - b; + if (b > 1.0) b = 1.0; + if (b < 0.0) b = 0.0; hsv = false; /* - if (r > 1.f) r = 1.f; - r = g = b = 1.f - r; + if (r > 1.0) r = 1.0; + r = g = b = 1.0 - r; hsv = false; */ break;
--- a/layer/ColourMapper.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/ColourMapper.h Fri Jun 26 14:13:31 2015 +0100 @@ -29,7 +29,7 @@ Q_OBJECT public: - ColourMapper(int map, float minValue, float maxValue); + ColourMapper(int map, double minValue, double maxValue); virtual ~ColourMapper(); enum StandardMap { @@ -48,21 +48,21 @@ }; int getMap() const { return m_map; } - float getMinValue() const { return m_min; } - float getMaxValue() const { return m_max; } + double getMinValue() const { return m_min; } + double getMaxValue() const { return m_max; } static int getColourMapCount(); static QString getColourMapName(int n); - QColor map(float value) const; + QColor map(double value) const; QColor getContrastingColour() const; // for cursors etc bool hasLightBackground() const; protected: int m_map; - float m_min; - float m_max; + double m_min; + double m_max; }; #endif
--- a/layer/ColourScaleLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/ColourScaleLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -19,11 +19,13 @@ #include <QString> #include <QColor> +class LayerGeometryProvider; + class ColourScaleLayer { public: virtual QString getScaleUnits() const = 0; - virtual QColor getColourForValue(View *v, float value) const = 0; + virtual QColor getColourForValue(LayerGeometryProvider *v, double value) const = 0; }; #endif
--- a/layer/FlexiNoteLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/FlexiNoteLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -204,7 +204,7 @@ } bool -FlexiNoteLayer::isLayerScrollable(const View *v) const +FlexiNoteLayer::isLayerScrollable(const LayerGeometryProvider *v) const { QPoint discard; return !v->shouldIlluminateLocalFeatures(this, discard); @@ -222,7 +222,7 @@ } bool -FlexiNoteLayer::getValueExtents(float &min, float &max, +FlexiNoteLayer::getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const { if (!m_model) return false; @@ -231,8 +231,8 @@ if (shouldConvertMIDIToHz()) { unit = "Hz"; - min = Pitch::getFrequencyForPitch(lrintf(min)); - max = Pitch::getFrequencyForPitch(lrintf(max + 1)); + min = Pitch::getFrequencyForPitch(int(lrint(min))); + max = Pitch::getFrequencyForPitch(int(lrint(max + 1))); } else unit = getScaleUnits(); if (m_verticalScale == MIDIRangeScale || @@ -242,7 +242,7 @@ } bool -FlexiNoteLayer::getDisplayExtents(float &min, float &max) const +FlexiNoteLayer::getDisplayExtents(double &min, double &max) const { if (!m_model || shouldAutoAlign()) { // std::cerr << "No model or shouldAutoAlign()" << std::endl; @@ -264,8 +264,8 @@ } if (shouldConvertMIDIToHz()) { - min = Pitch::getFrequencyForPitch(lrintf(min)); - max = Pitch::getFrequencyForPitch(lrintf(max + 1)); + min = Pitch::getFrequencyForPitch(int(lrint(min))); + max = Pitch::getFrequencyForPitch(int(lrint(max + 1))); } #ifdef DEBUG_NOTE_LAYER @@ -276,7 +276,7 @@ } bool -FlexiNoteLayer::setDisplayExtents(float min, float max) +FlexiNoteLayer::setDisplayExtents(double min, double max) { if (!m_model) return false; @@ -284,7 +284,7 @@ if (min == 0.f) { max = 1.f; } else { - max = min * 1.0001; + max = min * 1.0001f; } } @@ -318,7 +318,7 @@ RangeMapper *mapper = getNewVerticalZoomRangeMapper(); if (!mapper) return 0; - float dmin, dmax; + double dmin, dmax; getDisplayExtents(dmin, dmax); int nr = mapper->getPositionForValue(dmax - dmin); @@ -339,29 +339,29 @@ RangeMapper *mapper = getNewVerticalZoomRangeMapper(); if (!mapper) return; - float min, max; + double min, max; bool logarithmic; QString unit; getValueExtents(min, max, logarithmic, unit); - float dmin, dmax; + double dmin, dmax; getDisplayExtents(dmin, dmax); - float newdist = mapper->getValueForPosition(100 - step); + double newdist = mapper->getValueForPosition(100 - step); - float newmin, newmax; + double newmin, newmax; if (logarithmic) { // see SpectrogramLayer::setVerticalZoomStep - newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2; + newmax = (newdist + sqrt(newdist*newdist + 4*dmin*dmax)) / 2; newmin = newmax - newdist; // cerr << "newmin = " << newmin << ", newmax = " << newmax << endl; } else { - float dmid = (dmax + dmin) / 2; + double dmid = (dmax + dmin) / 2; newmin = dmid - newdist / 2; newmax = dmid + newdist / 2; } @@ -388,7 +388,7 @@ RangeMapper *mapper; - float min, max; + double min, max; bool logarithmic; QString unit; getValueExtents(min, max, logarithmic, unit); @@ -405,11 +405,11 @@ } FlexiNoteModel::PointList -FlexiNoteLayer::getLocalPoints(View *v, int x) const +FlexiNoteLayer::getLocalPoints(LayerGeometryProvider *v, int x) const { if (!m_model) return FlexiNoteModel::PointList(); - int frame = v->getFrameForX(x); + sv_frame_t frame = v->getFrameForX(x); FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); @@ -448,11 +448,11 @@ } bool -FlexiNoteLayer::getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &p) const +FlexiNoteLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, FlexiNoteModel::Point &p) const { if (!m_model) return false; - int frame = v->getFrameForX(x); + sv_frame_t frame = v->getFrameForX(x); FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); if (onPoints.empty()) return false; @@ -476,12 +476,12 @@ } bool -FlexiNoteLayer::getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &p) const +FlexiNoteLayer::getNoteToEdit(LayerGeometryProvider *v, int x, int y, FlexiNoteModel::Point &p) const { // GF: find the note that is closest to the cursor if (!m_model) return false; - int frame = v->getFrameForX(x); + sv_frame_t frame = v->getFrameForX(x); FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); if (onPoints.empty()) return false; @@ -505,7 +505,7 @@ } QString -FlexiNoteLayer::getFeatureDescription(View *v, QPoint &pos) const +FlexiNoteLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); @@ -552,9 +552,9 @@ if (shouldConvertMIDIToHz()) { - int mnote = lrintf(note.value); - int cents = lrintf((note.value - mnote) * 100); - float freq = Pitch::getFrequencyForPitch(mnote, cents); + int mnote = int(lrint(note.value)); + int cents = int(lrint((note.value - double(mnote)) * 100)); + double freq = Pitch::getFrequencyForPitch(mnote, cents); pitchText = tr("%1 (%2, %3 Hz)") .arg(Pitch::getPitchLabel(mnote, cents)) .arg(mnote) @@ -593,7 +593,7 @@ } bool -FlexiNoteLayer::snapToFeatureFrame(View *v, int &frame, +FlexiNoteLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -613,7 +613,7 @@ } points = m_model->getPoints(frame, frame); - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; for (FlexiNoteModel::PointList::const_iterator i = points.begin(); @@ -673,7 +673,7 @@ } void -FlexiNoteLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const +FlexiNoteLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const { min = 0.0; max = 0.0; @@ -691,8 +691,8 @@ max = m_model->getValueMaximum(); if (shouldConvertMIDIToHz()) { - min = Pitch::getFrequencyForPitch(lrintf(min)); - max = Pitch::getFrequencyForPitch(lrintf(max + 1)); + min = Pitch::getFrequencyForPitch(int(lrint(min))); + max = Pitch::getFrequencyForPitch(int(lrint(max + 1))); } #ifdef DEBUG_NOTE_LAYER @@ -716,8 +716,8 @@ min = Pitch::getFrequencyForPitch(0); max = Pitch::getFrequencyForPitch(70); } else if (shouldConvertMIDIToHz()) { - min = Pitch::getFrequencyForPitch(lrintf(min)); - max = Pitch::getFrequencyForPitch(lrintf(max + 1)); + min = Pitch::getFrequencyForPitch(int(lrint(min))); + max = Pitch::getFrequencyForPitch(int(lrint(max + 1))); } if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { @@ -730,11 +730,11 @@ } int -FlexiNoteLayer::getYForValue(View *v, float val) const +FlexiNoteLayer::getYForValue(LayerGeometryProvider *v, double val) const { - float min = 0.0, max = 0.0; + double min = 0.0, max = 0.0; bool logarithmic = false; - int h = v->height(); + int h = v->getPaintHeight(); getScaleExtents(v, min, max, logarithmic); @@ -743,8 +743,8 @@ #endif if (shouldConvertMIDIToHz()) { - val = Pitch::getFrequencyForPitch(lrintf(val), - lrintf((val - lrintf(val)) * 100)); + val = Pitch::getFrequencyForPitch(int(lrint(val)), + int(lrint((val - floor(val)) * 100.0))); #ifdef DEBUG_NOTE_LAYER cerr << "shouldConvertMIDIToHz true, val now = " << val << endl; #endif @@ -764,19 +764,19 @@ return y; } -float -FlexiNoteLayer::getValueForY(View *v, int y) const +double +FlexiNoteLayer::getValueForY(LayerGeometryProvider *v, int y) const { - float min = 0.0, max = 0.0; + double min = 0.0, max = 0.0; bool logarithmic = false; - int h = v->height(); + int h = v->getPaintHeight(); getScaleExtents(v, min, max, logarithmic); - float val = min + (float(h - y) * float(max - min)) / h; + double val = min + (double(h - y) * double(max - min)) / h; if (logarithmic) { - val = powf(10.f, val); + val = pow(10.f, val); } if (shouldConvertMIDIToHz()) { @@ -794,17 +794,17 @@ } void -FlexiNoteLayer::paint(View *v, QPainter &paint, QRect rect) const +FlexiNoteLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) return; - int sampleRate = m_model->getSampleRate(); + sv_samplerate_t sampleRate = m_model->getSampleRate(); if (!sampleRate) return; // Profiler profiler("FlexiNoteLayer::paint", true); int x1 = rect.right(); - int frame1 = v->getFrameForX(x1); + sv_frame_t frame1 = v->getFrameForX(x1); FlexiNoteModel::PointList points(m_model->getPoints(0, frame1)); if (points.empty()) return; @@ -817,8 +817,8 @@ // SVDEBUG << "FlexiNoteLayer::paint: resolution is " // << m_model->getResolution() << " frames" << endl; - float min = m_model->getValueMinimum(); - float max = m_model->getValueMaximum(); + double min = m_model->getValueMinimum(); + double max = m_model->getValueMaximum(); if (max == min) max = min + 1.0; QPoint localPos; @@ -860,8 +860,8 @@ !FlexiNoteModel::Point::Comparator()(illuminatePoint, p) && !FlexiNoteModel::Point::Comparator()(p, illuminatePoint)) { - paint.drawLine(x, -1, x, v->height() + 1); - paint.drawLine(x+w, -1, x+w, v->height() + 1); + paint.drawLine(x, -1, x, v->getPaintHeight() + 1); + paint.drawLine(x+w, -1, x+w, v->getPaintHeight() + 1); paint.setPen(v->getForeground()); // paint.setBrush(v->getForeground()); @@ -904,7 +904,7 @@ } int -FlexiNoteLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const +FlexiNoteLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const { if (!m_model || shouldAutoAlign()) { return 0; @@ -918,16 +918,16 @@ } void -FlexiNoteLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const +FlexiNoteLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const { if (!m_model || m_model->getPoints().empty()) return; QString unit; - float min, max; + double min, max; bool logarithmic; int w = getVerticalScaleWidth(v, false, paint); - int h = v->height(); + int h = v->getPaintHeight(); getScaleExtents(v, min, max, logarithmic); @@ -956,19 +956,19 @@ } void -FlexiNoteLayer::drawStart(View *v, QMouseEvent *e) +FlexiNoteLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "FlexiNoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; if (!m_model) return; - int frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float value = getValueForY(v, e->y()); + double value = getValueForY(v, e->y()); - m_editingPoint = FlexiNoteModel::Point(frame, value, 0, 0.8, tr("New Point")); + m_editingPoint = FlexiNoteModel::Point(frame, float(value), 0, 0.8f, tr("New Point")); m_originalPoint = m_editingPoint; if (m_editingCommand) finish(m_editingCommand); @@ -980,20 +980,20 @@ } void -FlexiNoteLayer::drawDrag(View *v, QMouseEvent *e) +FlexiNoteLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "FlexiNoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; - int frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float newValue = getValueForY(v, e->y()); + double newValue = getValueForY(v, e->y()); - int newFrame = m_editingPoint.frame; - int newDuration = frame - newFrame; + sv_frame_t newFrame = m_editingPoint.frame; + sv_frame_t newDuration = frame - newFrame; if (newDuration < 0) { newFrame = frame; newDuration = -newDuration; @@ -1003,13 +1003,13 @@ m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = newFrame; - m_editingPoint.value = newValue; + m_editingPoint.value = float(newValue); m_editingPoint.duration = newDuration; m_editingCommand->addPoint(m_editingPoint); } void -FlexiNoteLayer::drawEnd(View *, QMouseEvent *) +FlexiNoteLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) { // SVDEBUG << "FlexiNoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; @@ -1019,7 +1019,7 @@ } void -FlexiNoteLayer::eraseStart(View *v, QMouseEvent *e) +FlexiNoteLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return; @@ -1034,12 +1034,12 @@ } void -FlexiNoteLayer::eraseDrag(View *, QMouseEvent *) +FlexiNoteLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) { } void -FlexiNoteLayer::eraseEnd(View *v, QMouseEvent *e) +FlexiNoteLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; @@ -1059,7 +1059,7 @@ } void -FlexiNoteLayer::editStart(View *v, QMouseEvent *e) +FlexiNoteLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; std::cerr << "FlexiNoteLayer::editStart(" << e->x() << "," << e->y() << ")" << std::endl; @@ -1085,8 +1085,8 @@ m_dragStartX = e->x(); m_dragStartY = e->y(); - int onset = m_originalPoint.frame; - int offset = m_originalPoint.frame + m_originalPoint.duration - 1; + sv_frame_t onset = m_originalPoint.frame; + sv_frame_t offset = m_originalPoint.frame + m_originalPoint.duration - 1; m_greatestLeftNeighbourFrame = -1; m_smallestRightNeighbourFrame = std::numeric_limits<int>::max(); @@ -1110,7 +1110,7 @@ } void -FlexiNoteLayer::editDrag(View *v, QMouseEvent *e) +FlexiNoteLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; std::cerr << "FlexiNoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << std::endl; @@ -1122,11 +1122,11 @@ int newx = m_dragPointX + xdist; int newy = m_dragPointY + ydist; - int dragFrame = v->getFrameForX(newx); + sv_frame_t dragFrame = v->getFrameForX(newx); if (dragFrame < 0) dragFrame = 0; dragFrame = dragFrame / m_model->getResolution() * m_model->getResolution(); - float value = getValueForY(v, newy); + double value = getValueForY(v, newy); if (!m_editingCommand) { m_editingCommand = new FlexiNoteModel::EditCommand(m_model, @@ -1135,7 +1135,8 @@ m_editingCommand->deletePoint(m_editingPoint); - std::cerr << "edit mode: " << m_editMode << std::endl; + std::cerr << "edit mode: " << m_editMode << " intelligent actions = " + << m_intelligentActions << std::endl; switch (m_editMode) { case LeftBoundary : { @@ -1164,20 +1165,32 @@ dragFrame = m_smallestRightNeighbourFrame - m_originalPoint.duration; } m_editingPoint.frame = dragFrame; - m_editingPoint.value = value; + + m_editingPoint.value = float(value); + + // Re-analyse region within +/- 1 semitone of the dragged value + float cents = 0; + int midiPitch = Pitch::getPitchForFrequency(m_editingPoint.value, ¢s); + double lower = Pitch::getFrequencyForPitch(midiPitch - 1, cents); + double higher = Pitch::getFrequencyForPitch(midiPitch + 1, cents); + + emit reAnalyseRegion(m_editingPoint.frame, + m_editingPoint.frame + m_editingPoint.duration, + float(lower), float(higher)); break; } case SplitNote: // nothing break; } - updateNoteValue(v, m_editingPoint); + +// updateNoteValueFromPitchCurve(v, m_editingPoint); m_editingCommand->addPoint(m_editingPoint); + std::cerr << "added new point(" << m_editingPoint.frame << "," << m_editingPoint.duration << ")" << std::endl; - } void -FlexiNoteLayer::editEnd(View *, QMouseEvent *e) +FlexiNoteLayer::editEnd(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; std::cerr << "FlexiNoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << std::endl; @@ -1188,6 +1201,15 @@ QString newName = m_editingCommand->getName(); + if (m_editMode == DragNote) { + //!!! command nesting is wrong? + emit materialiseReAnalysis(); + } + + m_editingCommand->deletePoint(m_editingPoint); + updateNoteValueFromPitchCurve(v, m_editingPoint); + m_editingCommand->addPoint(m_editingPoint); + if (m_editingPoint.frame != m_originalPoint.frame) { if (m_editingPoint.value != m_originalPoint.value) { newName = tr("Edit Point"); @@ -1207,10 +1229,10 @@ } void -FlexiNoteLayer::splitStart(View *v, QMouseEvent *e) +FlexiNoteLayer::splitStart(LayerGeometryProvider *v, QMouseEvent *e) { // GF: note splitting starts (!! remove printing soon) - std::cerr << "splitStart" << std::endl; + std::cerr << "splitStart (n.b. editStart will be called later, if the user drags the mouse)" << std::endl; if (!m_model) return; if (!getPointToDrag(v, e->x(), e->y(), m_editingPoint)) return; @@ -1227,11 +1249,10 @@ m_editing = true; m_dragStartX = e->x(); m_dragStartY = e->y(); - } void -FlexiNoteLayer::splitEnd(View *v, QMouseEvent *e) +FlexiNoteLayer::splitEnd(LayerGeometryProvider *v, QMouseEvent *e) { // GF: note splitting ends. (!! remove printing soon) std::cerr << "splitEnd" << std::endl; @@ -1244,19 +1265,19 @@ return; } - int frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); splitNotesAt(v, frame, e); } void -FlexiNoteLayer::splitNotesAt(View *v, int frame) +FlexiNoteLayer::splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame) { splitNotesAt(v, frame, 0); } void -FlexiNoteLayer::splitNotesAt(View *v, int frame, QMouseEvent *e) +FlexiNoteLayer::splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame, QMouseEvent *e) { FlexiNoteModel::PointList onPoints = m_model->getPoints(frame); if (onPoints.empty()) return; @@ -1280,10 +1301,10 @@ note.level, note.label); if (m_intelligentActions) { - if (updateNoteValue(v, newNote1)) { + if (updateNoteValueFromPitchCurve(v, newNote1)) { command->addPoint(newNote1); } - if (updateNoteValue(v, newNote2)) { + if (updateNoteValueFromPitchCurve(v, newNote2)) { command->addPoint(newNote2); } } else { @@ -1296,20 +1317,20 @@ } void -FlexiNoteLayer::addNote(View *v, QMouseEvent *e) +FlexiNoteLayer::addNote(LayerGeometryProvider *v, QMouseEvent *e) { std::cerr << "addNote" << std::endl; if (!m_model) return; - int duration = 10000; + sv_frame_t duration = 10000; - int frame = v->getFrameForX(e->x()); - float value = getValueForY(v, e->y()); + sv_frame_t frame = v->getFrameForX(e->x()); + double value = getValueForY(v, e->y()); FlexiNoteModel::PointList noteList = m_model->getPoints(); if (m_intelligentActions) { - int smallestRightNeighbourFrame = 0; + sv_frame_t smallestRightNeighbourFrame = 0; for (FlexiNoteModel::PointList::const_iterator i = noteList.begin(); i != noteList.end(); ++i) { FlexiNote currentNote = *i; @@ -1326,7 +1347,7 @@ if (!m_intelligentActions || (m_model->getPoints(frame).empty() && duration > 0)) { - FlexiNote newNote(frame, value, duration, 100, "new note"); + FlexiNote newNote(frame, float(value), duration, 100.f, "new note"); FlexiNoteModel::EditCommand *command = new FlexiNoteModel::EditCommand (m_model, tr("Add Point")); command->addPoint(newNote); @@ -1335,31 +1356,32 @@ } SparseTimeValueModel * -FlexiNoteLayer::getAssociatedPitchModel(View *v) const +FlexiNoteLayer::getAssociatedPitchModel(LayerGeometryProvider *v) const { // Better than we used to do, but still not very satisfactory - cerr << "FlexiNoteLayer::getAssociatedPitchModel()" << endl; +// cerr << "FlexiNoteLayer::getAssociatedPitchModel()" << endl; - for (int i = 0; i < v->getLayerCount(); ++i) { - Layer *layer = v->getLayer(i); + for (int i = 0; i < v->getView()->getLayerCount(); ++i) { + Layer *layer = v->getView()->getLayer(i); if (layer && layer->getLayerPresentationName() != "candidate") { - cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl; +// cerr << "FlexiNoteLayer::getAssociatedPitchModel: looks like our layer is " << layer << endl; SparseTimeValueModel *model = qobject_cast<SparseTimeValueModel *> (layer->getModel()); - cerr << "FlexiNoteLayer::getAssociatedPitchModel: and its model is " << model << endl; +// cerr << "FlexiNoteLayer::getAssociatedPitchModel: and its model is " << model << endl; if (model && model->getScaleUnits() == "Hz") { cerr << "FlexiNoteLayer::getAssociatedPitchModel: it's good, returning " << model << endl; return model; } } } + cerr << "FlexiNoteLayer::getAssociatedPitchModel: failed to find a model" << endl; return 0; } void -FlexiNoteLayer::snapSelectedNotesToPitchTrack(View *v, Selection s) +FlexiNoteLayer::snapSelectedNotesToPitchTrack(LayerGeometryProvider *v, Selection s) { if (!m_model) return; @@ -1388,7 +1410,7 @@ command->deletePoint(note); - if (updateNoteValue(v, newNote)) { + if (updateNoteValueFromPitchCurve(v, newNote)) { command->addPoint(newNote); } } @@ -1397,7 +1419,7 @@ } void -FlexiNoteLayer::mergeNotes(View *v, Selection s, bool inclusive) +FlexiNoteLayer::mergeNotes(LayerGeometryProvider *v, Selection s, bool inclusive) { FlexiNoteModel::PointList points = m_model->getPoints(s.getStartFrame(), s.getEndFrame()); @@ -1434,13 +1456,13 @@ ++i; } - updateNoteValue(v, newNote); + updateNoteValueFromPitchCurve(v, newNote); command->addPoint(newNote); finish(command); } bool -FlexiNoteLayer::updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const +FlexiNoteLayer::updateNoteValueFromPitchCurve(LayerGeometryProvider *v, FlexiNoteModel::Point ¬e) const { SparseTimeValueModel *model = getAssociatedPitchModel(v); if (!model) return false; @@ -1454,7 +1476,7 @@ if (dataPoints.empty()) return false; - std::vector<float> pitchValues; + std::vector<double> pitchValues; for (SparseModel<TimeValuePoint>::PointList::const_iterator i = dataPoints.begin(); i != dataPoints.end(); ++i) { @@ -1467,7 +1489,7 @@ if (pitchValues.empty()) return false; sort(pitchValues.begin(), pitchValues.end()); - int size = pitchValues.size(); + int size = int(pitchValues.size()); double median; if (size % 2 == 0) { @@ -1475,42 +1497,54 @@ } else { median = pitchValues[size/2]; } + + std::cerr << "updateNoteValueFromPitchCurve: corrected from " << note.value << " to median " << median << std::endl; - note.value = median; + note.value = float(median); return true; } void -FlexiNoteLayer::mouseMoveEvent(View *v, QMouseEvent *e) +FlexiNoteLayer::mouseMoveEvent(LayerGeometryProvider *v, QMouseEvent *e) { // GF: context sensitive cursors - // v->setCursor(Qt::ArrowCursor); + // v->getView()->setCursor(Qt::ArrowCursor); FlexiNoteModel::Point note(0); if (!getNoteToEdit(v, e->x(), e->y(), note)) { - // v->setCursor(Qt::UpArrowCursor); + // v->getView()->setCursor(Qt::UpArrowCursor); return; } - bool closeToLeft = false, closeToRight = false, closeToTop = false, closeToBottom = false; - getRelativeMousePosition(v, note, e->x(), e->y(), closeToLeft, closeToRight, closeToTop, closeToBottom); - // if (!closeToLeft) return; - // if (closeToTop) v->setCursor(Qt::SizeVerCursor); + bool closeToLeft = false, closeToRight = false, + closeToTop = false, closeToBottom = false; + getRelativeMousePosition(v, note, e->x(), e->y(), + closeToLeft, closeToRight, + closeToTop, closeToBottom); - if (closeToLeft) { v->setCursor(Qt::SizeHorCursor); m_editMode = LeftBoundary; return; } - if (closeToRight) { v->setCursor(Qt::SizeHorCursor); m_editMode = RightBoundary; return; } - if (closeToTop) { v->setCursor(Qt::CrossCursor); m_editMode = DragNote; return; } - if (closeToBottom) { v->setCursor(Qt::UpArrowCursor); m_editMode = SplitNote; return; } - - v->setCursor(Qt::ArrowCursor); - - std::cerr << "Mouse moved in edit mode over FlexiNoteLayer" << std::endl; - // v->setCursor(Qt::SizeHorCursor); - + if (closeToLeft) { + v->getView()->setCursor(Qt::SizeHorCursor); + m_editMode = LeftBoundary; + cerr << "edit mode -> LeftBoundary" << endl; + } else if (closeToRight) { + v->getView()->setCursor(Qt::SizeHorCursor); + m_editMode = RightBoundary; + cerr << "edit mode -> RightBoundary" << endl; + } else if (closeToTop) { + v->getView()->setCursor(Qt::CrossCursor); + m_editMode = DragNote; + cerr << "edit mode -> DragNote" << endl; + } else if (closeToBottom) { + v->getView()->setCursor(Qt::UpArrowCursor); + m_editMode = SplitNote; + cerr << "edit mode -> SplitNote" << endl; + } else { + v->getView()->setCursor(Qt::ArrowCursor); + } } void -FlexiNoteLayer::getRelativeMousePosition(View *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const +FlexiNoteLayer::getRelativeMousePosition(LayerGeometryProvider *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const { // GF: TODO: consoloidate the tolerance values if (!m_model) return; @@ -1539,7 +1573,7 @@ bool -FlexiNoteLayer::editOpen(View *v, QMouseEvent *e) +FlexiNoteLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) { std::cerr << "Opening note editor dialog" << std::endl; if (!m_model) return false; @@ -1582,7 +1616,7 @@ } void -FlexiNoteLayer::moveSelection(Selection s, int newStartFrame) +FlexiNoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame) { if (!m_model) return; @@ -1626,13 +1660,13 @@ if (s.contains(i->frame)) { - double targetStart = i->frame; - targetStart = newSize.getStartFrame() + - double(targetStart - s.getStartFrame()) * ratio; + double targetStart = double(i->frame); + targetStart = double(newSize.getStartFrame()) + + targetStart - double(s.getStartFrame()) * ratio; - double targetEnd = i->frame + i->duration; - targetEnd = newSize.getStartFrame() + - double(targetEnd - s.getStartFrame()) * ratio; + double targetEnd = double(i->frame + i->duration); + targetEnd = double(newSize.getStartFrame()) + + targetEnd - double(s.getStartFrame()) * ratio; FlexiNoteModel::Point newPoint(*i); newPoint.frame = lrint(targetStart); @@ -1693,7 +1727,7 @@ } void -FlexiNoteLayer::copy(View *v, Selection s, Clipboard &to) +FlexiNoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) { if (!m_model) return; @@ -1711,7 +1745,7 @@ } bool -FlexiNoteLayer::paste(View *v, const Clipboard &from, int /*frameOffset */, bool /* interactive */) +FlexiNoteLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /*frameOffset */, bool /* interactive */) { if (!m_model) return false; @@ -1722,7 +1756,7 @@ if (clipboardHasDifferentAlignment(v, from)) { QMessageBox::StandardButton button = - QMessageBox::question(v, tr("Re-align pasted items?"), + QMessageBox::question(v->getView(), tr("Re-align pasted items?"), tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); @@ -1743,7 +1777,7 @@ i != points.end(); ++i) { if (!i->haveFrame()) continue; - int frame = 0; + sv_frame_t frame = 0; if (!realign) { @@ -1768,7 +1802,7 @@ if (i->haveLevel()) newPoint.level = i->getLevel(); if (i->haveDuration()) newPoint.duration = i->getDuration(); else { - int nextFrame = frame; + sv_frame_t nextFrame = frame; Clipboard::PointList::const_iterator j = i; for (; j != points.end(); ++j) { if (!j->haveFrame()) continue; @@ -1792,17 +1826,17 @@ } void -FlexiNoteLayer::addNoteOn(int frame, int pitch, int velocity) +FlexiNoteLayer::addNoteOn(sv_frame_t frame, int pitch, int velocity) { - m_pendingNoteOns.insert(FlexiNote(frame, pitch, 0, float(velocity) / 127.0, "")); + m_pendingNoteOns.insert(FlexiNote(frame, float(pitch), 0, float(velocity / 127.0), "")); } void -FlexiNoteLayer::addNoteOff(int frame, int pitch) +FlexiNoteLayer::addNoteOff(sv_frame_t frame, int pitch) { for (FlexiNoteSet::iterator i = m_pendingNoteOns.begin(); i != m_pendingNoteOns.end(); ++i) { - if (lrintf((*i).value) == pitch) { + if (lrint((*i).value) == pitch) { FlexiNote note(*i); m_pendingNoteOns.erase(i); note.duration = frame - note.frame; @@ -1853,16 +1887,16 @@ if (ok) setVerticalScale(scale); // bool alsoOk; -// float min = attributes.value("scaleMinimum").toFloat(&ok); -// float max = attributes.value("scaleMaximum").toFloat(&alsoOk); +// double min = attributes.value("scaleMinimum").toDouble(&ok); +// double max = attributes.value("scaleMaximum").toDouble(&alsoOk); // if (ok && alsoOk && min != max) setDisplayExtents(min, max); } void -FlexiNoteLayer::setVerticalRangeToNoteRange(View *v) +FlexiNoteLayer::setVerticalRangeToNoteRange(LayerGeometryProvider *v) { - float minf = std::numeric_limits<float>::max(); - float maxf = 0; + double minf = std::numeric_limits<double>::max(); + double maxf = 0; bool hasNotes = 0; for (FlexiNoteModel::PointList::const_iterator i = m_model->getPoints().begin(); i != m_model->getPoints().end(); ++i) { @@ -1875,7 +1909,7 @@ std::cerr << "min frequency:" << minf << ", max frequency: " << maxf << std::endl; if (hasNotes) { - v->getLayer(1)->setDisplayExtents(minf*0.66,maxf*1.5); + v->getView()->getLayer(1)->setDisplayExtents(minf*0.66,maxf*1.5); // MM: this is a hack because we rely on // * this layer being automatically aligned to layer 1 // * layer one is a log frequency layer.
--- a/layer/FlexiNoteLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/FlexiNoteLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -38,50 +38,50 @@ public: FlexiNoteLayer(); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; - virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; + virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const; + virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void drawStart(View *v, QMouseEvent *); - virtual void drawDrag(View *v, QMouseEvent *); - virtual void drawEnd(View *v, QMouseEvent *); + virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void eraseStart(View *v, QMouseEvent *); - virtual void eraseDrag(View *v, QMouseEvent *); - virtual void eraseEnd(View *v, QMouseEvent *); + virtual void eraseStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void editStart(View *v, QMouseEvent *); - virtual void editDrag(View *v, QMouseEvent *); - virtual void editEnd(View *v, QMouseEvent *); + virtual void editStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void splitStart(View *v, QMouseEvent *); - virtual void splitEnd(View *v, QMouseEvent *); + virtual void splitStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void splitEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void addNote(View *v, QMouseEvent *e); + virtual void addNote(LayerGeometryProvider *v, QMouseEvent *e); - virtual void mouseMoveEvent(View *v, QMouseEvent *); + virtual void mouseMoveEvent(LayerGeometryProvider *v, QMouseEvent *); - virtual bool editOpen(View *v, QMouseEvent *); + virtual bool editOpen(LayerGeometryProvider *v, QMouseEvent *); - virtual void moveSelection(Selection s, int newStartFrame); + virtual void moveSelection(Selection s, sv_frame_t newStartFrame); virtual void resizeSelection(Selection s, Selection newSize); virtual void deleteSelection(Selection s); virtual void deleteSelectionInclusive(Selection s); - virtual void copy(View *v, Selection s, Clipboard &to); - virtual bool paste(View *v, const Clipboard &from, int frameOffset, + virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to); + virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive); - void splitNotesAt(View *v, int frame); - void snapSelectedNotesToPitchTrack(View *v, Selection s); - void mergeNotes(View *v, Selection s, bool inclusive); + void splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame); + void snapSelectedNotesToPitchTrack(LayerGeometryProvider *v, Selection s); + void mergeNotes(LayerGeometryProvider *v, Selection s, bool inclusive); virtual const Model *getModel() const { return m_model; } void setModel(FlexiNoteModel *model); @@ -116,17 +116,17 @@ void setVerticalScale(VerticalScale scale); VerticalScale getVerticalScale() const { return m_verticalScale; } - virtual bool isLayerScrollable(const View *v) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; virtual bool isLayerEditable() const { return true; } - virtual int getCompletion(View *) const { return m_model->getCompletion(); } + virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &log, QString &unit) const; - virtual bool getDisplayExtents(float &min, float &max) const; - virtual bool setDisplayExtents(float min, float max); + virtual bool getDisplayExtents(double &min, double &max) const; + virtual bool setDisplayExtents(double min, double max); virtual int getVerticalZoomSteps(int &defaultStep) const; virtual int getCurrentVerticalZoomStep() const; @@ -138,13 +138,13 @@ * not be finally added to the layer until the corresponding * note-off. */ - void addNoteOn(int frame, int pitch, int velocity); + void addNoteOn(sv_frame_t frame, int pitch, int velocity); /** * Add a note-off. This will cause a note to appear, if and only * if there is a matching pending note-on. */ - void addNoteOff(int frame, int pitch); + void addNoteOff(sv_frame_t frame, int pitch); /** * Abandon all pending note-on events. @@ -156,27 +156,31 @@ void setProperties(const QXmlAttributes &attributes); - void setVerticalRangeToNoteRange(View *v); + void setVerticalRangeToNoteRange(LayerGeometryProvider *v); /// VerticalScaleLayer methods - virtual int getYForValue(View *v, float value) const; - virtual float getValueForY(View *v, int y) const; + virtual int getYForValue(LayerGeometryProvider *v, double value) const; + virtual double getValueForY(LayerGeometryProvider *v, int y) const; virtual QString getScaleUnits() const; +signals: + void reAnalyseRegion(sv_frame_t, sv_frame_t, float, float); + void materialiseReAnalysis(); + protected: - void getScaleExtents(View *, float &min, float &max, bool &log) const; + void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const; bool shouldConvertMIDIToHz() const; virtual int getDefaultColourHint(bool dark, bool &impose); - FlexiNoteModel::PointList getLocalPoints(View *v, int) const; + FlexiNoteModel::PointList getLocalPoints(LayerGeometryProvider *v, int) const; - bool getPointToDrag(View *v, int x, int y, FlexiNoteModel::Point &) const; - bool getNoteToEdit(View *v, int x, int y, FlexiNoteModel::Point &) const; - void getRelativeMousePosition(View *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const; - SparseTimeValueModel *getAssociatedPitchModel(View *v) const; - bool updateNoteValue(View *v, FlexiNoteModel::Point ¬e) const; - void splitNotesAt(View *v, int frame, QMouseEvent *e); + bool getPointToDrag(LayerGeometryProvider *v, int x, int y, FlexiNoteModel::Point &) const; + bool getNoteToEdit(LayerGeometryProvider *v, int x, int y, FlexiNoteModel::Point &) const; + void getRelativeMousePosition(LayerGeometryProvider *v, FlexiNoteModel::Point ¬e, int x, int y, bool &closeToLeft, bool &closeToRight, bool &closeToTop, bool &closeToBottom) const; + SparseTimeValueModel *getAssociatedPitchModel(LayerGeometryProvider *v) const; + bool updateNoteValueFromPitchCurve(LayerGeometryProvider *v, FlexiNoteModel::Point ¬e) const; + void splitNotesAt(LayerGeometryProvider *v, sv_frame_t frame, QMouseEvent *e); FlexiNoteModel *m_model; bool m_editing; @@ -187,8 +191,8 @@ int m_dragStartY; FlexiNoteModel::Point m_originalPoint; FlexiNoteModel::Point m_editingPoint; - int m_greatestLeftNeighbourFrame; - int m_smallestRightNeighbourFrame; + sv_frame_t m_greatestLeftNeighbourFrame; + sv_frame_t m_smallestRightNeighbourFrame; FlexiNoteModel::EditCommand *m_editingCommand; VerticalScale m_verticalScale; EditMode m_editMode; @@ -196,8 +200,8 @@ typedef std::set<FlexiNoteModel::Point, FlexiNoteModel::Point::Comparator> FlexiNoteSet; FlexiNoteSet m_pendingNoteOns; - mutable float m_scaleMinimum; - mutable float m_scaleMaximum; + mutable double m_scaleMinimum; + mutable double m_scaleMaximum; bool shouldAutoAlign() const;
--- a/layer/ImageLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/ImageLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -110,20 +110,20 @@ } bool -ImageLayer::getValueExtents(float &, float &, bool &, QString &) const +ImageLayer::getValueExtents(double &, double &, bool &, QString &) const { return false; } bool -ImageLayer::isLayerScrollable(const View *) const +ImageLayer::isLayerScrollable(const LayerGeometryProvider *) const { return true; } ImageModel::PointList -ImageLayer::getLocalPoints(View *v, int x, int ) const +ImageLayer::getLocalPoints(LayerGeometryProvider *v, int x, int ) const { if (!m_model) return ImageModel::PointList(); @@ -169,7 +169,7 @@ } QString -ImageLayer::getFeatureDescription(View *v, QPoint &pos) const +ImageLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); @@ -208,7 +208,7 @@ //!!! too much overlap with TimeValueLayer/TimeInstantLayer/TextLayer bool -ImageLayer::snapToFeatureFrame(View *v, int &frame, +ImageLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -228,7 +228,7 @@ } points = m_model->getPoints(frame, frame); - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; for (ImageModel::PointList::const_iterator i = points.begin(); @@ -280,26 +280,26 @@ } void -ImageLayer::paint(View *v, QPainter &paint, QRect rect) const +ImageLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) return; - int sampleRate = m_model->getSampleRate(); + sv_samplerate_t sampleRate = m_model->getSampleRate(); if (!sampleRate) return; // Profiler profiler("ImageLayer::paint", true); // int x0 = rect.left(), x1 = rect.right(); - int x0 = 0, x1 = v->width(); + int x0 = 0, x1 = v->getPaintWidth(); - int frame0 = v->getFrameForX(x0); - int frame1 = v->getFrameForX(x1); + sv_frame_t frame0 = v->getFrameForX(x0); + sv_frame_t frame1 = v->getFrameForX(x1); ImageModel::PointList points(m_model->getPoints(frame0, frame1)); if (points.empty()) return; paint.save(); - paint.setClipRect(rect.x(), 0, rect.width(), v->height()); + paint.setClipRect(rect.x(), 0, rect.width(), v->getPaintHeight()); QColor penColour; penColour = v->getForeground(); @@ -338,7 +338,7 @@ } void -ImageLayer::drawImage(View *v, QPainter &paint, const ImageModel::Point &p, +ImageLayer::drawImage(LayerGeometryProvider *v, QPainter &paint, const ImageModel::Point &p, int x, int nx) const { QString label = p.label; @@ -358,12 +358,12 @@ int bottomMargin = 10; int spacing = 5; - if (v->height() < 100) { + if (v->getPaintHeight() < 100) { topMargin = 5; bottomMargin = 5; } - int maxBoxHeight = v->height() - topMargin - bottomMargin; + int maxBoxHeight = v->getPaintHeight() - topMargin - bottomMargin; int availableWidth = nx - x - 3; if (availableWidth < 20) availableWidth = 20; @@ -372,7 +372,7 @@ if (label != "") { - int likelyHeight = v->height() / 4; + int likelyHeight = v->getPaintHeight() / 4; int likelyWidth = // available height times image aspect ((maxBoxHeight - likelyHeight) * imageSize.width()) @@ -435,10 +435,10 @@ division += paint.fontMetrics().height(); } - bottomMargin = v->height() - topMargin - boxHeight; - if (bottomMargin > topMargin + v->height()/7) { - topMargin += v->height()/8; - bottomMargin -= v->height()/8; + bottomMargin = v->getPaintHeight() - topMargin - boxHeight; + if (bottomMargin > topMargin + v->getPaintHeight()/7) { + topMargin += v->getPaintHeight()/8; + bottomMargin -= v->getPaintHeight()/8; } paint.drawRect(x - 1, @@ -480,7 +480,7 @@ } void -ImageLayer::setLayerDormant(const View *v, bool dormant) +ImageLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) { if (dormant) { // Delete the images named in the view's scaled map from the @@ -517,7 +517,7 @@ } QImage -ImageLayer::getImage(View *v, QString name, QSize maxSize) const +ImageLayer::getImage(LayerGeometryProvider *v, QString name, QSize maxSize) const { // SVDEBUG << "ImageLayer::getImage(" << v << ", " << name << ", (" // << maxSize.width() << "x" << maxSize.height() << "))" << endl; @@ -554,7 +554,7 @@ } void -ImageLayer::drawStart(View *v, QMouseEvent *e) +ImageLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "ImageLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; @@ -563,7 +563,7 @@ return; } - int frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); @@ -578,13 +578,13 @@ } void -ImageLayer::drawDrag(View *v, QMouseEvent *e) +ImageLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "ImageLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; - int frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); @@ -594,7 +594,7 @@ } void -ImageLayer::drawEnd(View *, QMouseEvent *) +ImageLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) { // SVDEBUG << "ImageLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; @@ -619,7 +619,7 @@ } bool -ImageLayer::addImage(int frame, QString url) +ImageLayer::addImage(sv_frame_t frame, QString url) { QImage image(getLocalFilename(url)); if (image.isNull()) { @@ -638,7 +638,7 @@ } void -ImageLayer::editStart(View *v, QMouseEvent *e) +ImageLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "ImageLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; @@ -660,12 +660,12 @@ } void -ImageLayer::editDrag(View *v, QMouseEvent *e) +ImageLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; - int frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); - int frame = m_originalPoint.frame + frameDiff; + sv_frame_t frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); + sv_frame_t frame = m_originalPoint.frame + frameDiff; if (frame < 0) frame = 0; frame = (frame / m_model->getResolution()) * m_model->getResolution(); @@ -680,7 +680,7 @@ } void -ImageLayer::editEnd(View *, QMouseEvent *) +ImageLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) { // SVDEBUG << "ImageLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; @@ -694,7 +694,7 @@ } bool -ImageLayer::editOpen(View *v, QMouseEvent *e) +ImageLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return false; @@ -723,7 +723,7 @@ } void -ImageLayer::moveSelection(Selection s, int newStartFrame) +ImageLayer::moveSelection(Selection s, sv_frame_t newStartFrame) { if (!m_model) return; @@ -767,9 +767,9 @@ if (s.contains(i->frame)) { - double target = i->frame; - target = newSize.getStartFrame() + - double(target - s.getStartFrame()) * ratio; + double target = double(i->frame); + target = double(newSize.getStartFrame()) + + target - double(s.getStartFrame()) * ratio; ImageModel::Point newPoint(*i); newPoint.frame = lrint(target); @@ -801,7 +801,7 @@ } void -ImageLayer::copy(View *v, Selection s, Clipboard &to) +ImageLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) { if (!m_model) return; @@ -819,7 +819,7 @@ } bool -ImageLayer::paste(View *v, const Clipboard &from, int /* frameOffset */, bool /* interactive */) +ImageLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) { if (!m_model) return false; @@ -830,7 +830,7 @@ if (clipboardHasDifferentAlignment(v, from)) { QMessageBox::StandardButton button = - QMessageBox::question(v, tr("Re-align pasted items?"), + QMessageBox::question(v->getView(), tr("Re-align pasted items?"), tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); @@ -852,7 +852,7 @@ if (!i->haveFrame()) continue; - int frame = 0; + sv_frame_t frame = 0; if (!realign) {
--- a/layer/ImageLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/ImageLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -38,31 +38,31 @@ ImageLayer(); virtual ~ImageLayer(); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void drawStart(View *v, QMouseEvent *); - virtual void drawDrag(View *v, QMouseEvent *); - virtual void drawEnd(View *v, QMouseEvent *); + virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void editStart(View *v, QMouseEvent *); - virtual void editDrag(View *v, QMouseEvent *); - virtual void editEnd(View *v, QMouseEvent *); + virtual void editStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void moveSelection(Selection s, int newStartFrame); + virtual void moveSelection(Selection s, sv_frame_t newStartFrame); virtual void resizeSelection(Selection s, Selection newSize); virtual void deleteSelection(Selection s); - virtual void copy(View *v, Selection s, Clipboard &to); - virtual bool paste(View *v, const Clipboard &from, int frameOffset, + virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to); + virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive); - virtual bool editOpen(View *, QMouseEvent *); // on double-click + virtual bool editOpen(LayerGeometryProvider *, QMouseEvent *); // on double-click virtual const Model *getModel() const { return m_model; } void setModel(ImageModel *model); @@ -80,43 +80,43 @@ return ColourAbsent; } - virtual bool isLayerScrollable(const View *v) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; virtual bool isLayerEditable() const { return true; } - virtual int getCompletion(View *) const { return m_model->getCompletion(); } + virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const; virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; - virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } + virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const { return 0; } - virtual void setLayerDormant(const View *v, bool dormant); + virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant); void setProperties(const QXmlAttributes &attributes); - virtual bool addImage(int frame, QString url); // using a command + virtual bool addImage(sv_frame_t frame, QString url); // using a command protected slots: void checkAddSources(); void fileSourceReady(); protected: - ImageModel::PointList getLocalPoints(View *v, int x, int y) const; + ImageModel::PointList getLocalPoints(LayerGeometryProvider *v, int x, int y) const; bool getImageOriginalSize(QString name, QSize &size) const; - QImage getImage(View *v, QString name, QSize maxSize) const; + QImage getImage(LayerGeometryProvider *v, QString name, QSize maxSize) const; - void drawImage(View *v, QPainter &paint, const ImageModel::Point &p, + void drawImage(LayerGeometryProvider *v, QPainter &paint, const ImageModel::Point &p, int x, int nx) const; //!!! how to reap no-longer-used images? typedef std::map<QString, QImage> ImageMap; - typedef std::map<const View *, ImageMap> ViewImageMap; + typedef std::map<const LayerGeometryProvider *, ImageMap> ViewImageMap; typedef std::map<QString, FileSource *> FileSourceMap; static ImageMap m_images;
--- a/layer/ImageRegionFinder.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/ImageRegionFinder.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -107,9 +107,9 @@ return false; } - float ar = float(qRed(a) / 255.f); - float ag = float(qGreen(a) / 255.f); - float ab = float(qBlue(a) / 255.f); + float ar = float(qRed(a)) / 255.f; + float ag = float(qGreen(a)) / 255.f; + float ab = float(qBlue(a)) / 255.f; float amag = sqrtf(ar * ar + ag * ag + ab * ab); float thresh = amag / 2;
--- a/layer/Layer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/Layer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -51,8 +51,8 @@ connect(model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged())); - connect(model, SIGNAL(modelChangedWithin(int, int)), - this, SIGNAL(modelChangedWithin(int, int))); + connect(model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), + this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t))); connect(model, SIGNAL(completionChanged()), this, SIGNAL(modelCompletionChanged())); @@ -115,7 +115,7 @@ } void -Layer::setLayerDormant(const View *v, bool dormant) +Layer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) { const void *vv = (const void *)v; QMutexLocker locker(&m_dormancyMutex); @@ -123,7 +123,7 @@ } bool -Layer::isLayerDormant(const View *v) const +Layer::isLayerDormant(const LayerGeometryProvider *v) const { const void *vv = (const void *)v; QMutexLocker locker(&m_dormancyMutex); @@ -132,65 +132,65 @@ } void -Layer::showLayer(View *view, bool show) +Layer::showLayer(LayerGeometryProvider *view, bool show) { setLayerDormant(view, !show); emit layerParametersChanged(); } bool -Layer::getXScaleValue(const View *v, int x, float &value, QString &unit) const +Layer::getXScaleValue(const LayerGeometryProvider *v, int x, double &value, QString &unit) const { if (!hasTimeXAxis()) return false; const Model *m = getModel(); if (!m) return false; - value = float(v->getFrameForX(x)) / m->getSampleRate(); + value = double(v->getFrameForX(x)) / m->getSampleRate(); unit = "s"; return true; } bool -Layer::getYScaleDifference(const View *v, int y0, int y1, - float &diff, QString &unit) const +Layer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1, + double &diff, QString &unit) const { - float v0, v1; + double v0, v1; if (!getYScaleValue(v, y0, v0, unit) || !getYScaleValue(v, y1, v1, unit)) { diff = 0.f; return false; } - diff = fabsf(v1 - v0); + diff = fabs(v1 - v0); return true; } -int -Layer::alignToReference(View *v, int frame) const +sv_frame_t +Layer::alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const { const Model *m = getModel(); SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; if (m && m->getAlignmentReference()) { return m->alignToReference(frame); } else { - return v->alignToReference(frame); + return v->getView()->alignToReference(frame); } } -int -Layer::alignFromReference(View *v, int frame) const +sv_frame_t +Layer::alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const { const Model *m = getModel(); SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; if (m && m->getAlignmentReference()) { return m->alignFromReference(frame); } else { - return v->alignFromReference(frame); + return v->getView()->alignFromReference(frame); } } bool -Layer::clipboardHasDifferentAlignment(View *v, const Clipboard &clip) const +Layer::clipboardHasDifferentAlignment(LayerGeometryProvider *v, const Clipboard &clip) const { // Notes on pasting to an aligned layer: // @@ -250,12 +250,12 @@ // reference (i.e. having been copied from the reference // model). - int sourceFrame = i->getFrame(); - int referenceFrame = sourceFrame; + sv_frame_t sourceFrame = i->getFrame(); + sv_frame_t referenceFrame = sourceFrame; if (i->haveReferenceFrame()) { referenceFrame = i->getReferenceFrame(); } - int myMappedFrame = alignToReference(v, sourceFrame); + sv_frame_t myMappedFrame = alignToReference(v, sourceFrame); // cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << endl; @@ -371,7 +371,7 @@ } void -Layer::measureStart(View *v, QMouseEvent *e) +Layer::measureStart(LayerGeometryProvider *v, QMouseEvent *e) { setMeasureRectFromPixrect(v, m_draggingRect, QRect(e->x(), e->y(), 0, 0)); @@ -379,7 +379,7 @@ } void -Layer::measureDrag(View *v, QMouseEvent *e) +Layer::measureDrag(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_haveDraggingRect) return; @@ -391,7 +391,7 @@ } void -Layer::measureEnd(View *v, QMouseEvent *e) +Layer::measureEnd(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_haveDraggingRect) return; measureDrag(v, e); @@ -405,7 +405,7 @@ } void -Layer::measureDoubleClick(View *, QMouseEvent *) +Layer::measureDoubleClick(LayerGeometryProvider *, QMouseEvent *) { // nothing, in the base class } @@ -425,7 +425,7 @@ } void -Layer::paintMeasurementRects(View *v, QPainter &paint, +Layer::paintMeasurementRects(LayerGeometryProvider *v, QPainter &paint, bool showFocus, QPoint focusPoint) const { updateMeasurePixrects(v); @@ -457,7 +457,7 @@ } bool -Layer::nearestMeasurementRectChanged(View *v, QPoint prev, QPoint now) const +Layer::nearestMeasurementRectChanged(LayerGeometryProvider *v, QPoint prev, QPoint now) const { updateMeasurePixrects(v); @@ -468,10 +468,10 @@ } void -Layer::updateMeasurePixrects(View *v) const +Layer::updateMeasurePixrects(LayerGeometryProvider *v) const { - int sf = v->getStartFrame(); - int ef = v->getEndFrame(); + sv_frame_t sf = v->getStartFrame(); + sv_frame_t ef = v->getEndFrame(); for (MeasureRectSet::const_iterator i = m_measureRects.begin(); i != m_measureRects.end(); ++i) { @@ -507,26 +507,26 @@ } void -Layer::updateMeasureRectYCoords(View *v, const MeasureRect &r) const +Layer::updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const { - int y0 = lrint(r.startY * v->height()); - int y1 = lrint(r.endY * v->height()); + int y0 = int(lrint(r.startY * v->getPaintHeight())); + int y1 = int(lrint(r.endY * v->getPaintHeight())); r.pixrect = QRect(r.pixrect.x(), y0, r.pixrect.width(), y1 - y0); } void -Layer::setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const +Layer::setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const { if (start) { - r.startY = double(y) / double(v->height()); + r.startY = double(y) / double(v->getPaintHeight()); r.endY = r.startY; } else { - r.endY = double(y) / double(v->height()); + r.endY = double(y) / double(v->getPaintHeight()); } } void -Layer::setMeasureRectFromPixrect(View *v, MeasureRect &r, QRect pixrect) const +Layer::setMeasureRectFromPixrect(LayerGeometryProvider *v, MeasureRect &r, QRect pixrect) const { r.pixrect = pixrect; r.haveFrames = hasTimeXAxis(); @@ -541,7 +541,7 @@ Layer::MeasureRectSet::const_iterator Layer::findFocusedMeasureRect(QPoint focusPoint) const { - float frDist = 0; + double frDist = 0; MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); for (MeasureRectSet::const_iterator i = m_measureRects.begin(); @@ -554,7 +554,7 @@ int xd = focusPoint.x() - cx; int yd = focusPoint.y() - cy; - float d = sqrt(float(xd * xd + yd * yd)); + double d = sqrt(double(xd * xd + yd * yd)); if (focusRectItr == m_measureRects.end() || d < frDist) { focusRectItr = i; @@ -566,13 +566,13 @@ } void -Layer::paintMeasurementRect(View *v, QPainter &paint, +Layer::paintMeasurementRect(LayerGeometryProvider *v, QPainter &paint, const MeasureRect &r, bool focus) const { if (r.haveFrames) { int x0 = -1; - int x1 = v->width() + 1; + int x1 = v->getPaintWidth() + 1; if (r.startFrame >= v->getStartFrame()) { x0 = v->getXForFrame(r.startFrame);
--- a/layer/Layer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/Layer.h Fri Jun 26 14:13:31 2015 +0100 @@ -39,6 +39,7 @@ class Model; class QPainter; class View; +class LayerGeometryProvider; class QMouseEvent; class Clipboard; class RangeMapper; @@ -62,7 +63,7 @@ Model *getModel() { return const_cast<Model *>(const_cast<const Layer *>(this)->getModel()); } - + /** * Return a zoom constraint object defining the supported zoom * levels for this layer. If this returns zero, the layer will @@ -83,12 +84,13 @@ /** * Paint the given rectangle of this layer onto the given view * using the given painter, superimposing it on top of any - * existing material in that view. The view is provided here - * because it is possible for one layer to exist in more than one - * view, so the dimensions of the view may vary from one paint - * call to another (without any view having been resized). + * existing material in that view. The LayerGeometryProvider (an + * interface implemented by View) is provided here because it is + * possible for one layer to exist in more than one view, so the + * dimensions of the view may vary from one paint call to another + * (without any view having been resized). */ - virtual void paint(View *, QPainter &, QRect) const = 0; + virtual void paint(LayerGeometryProvider *, QPainter &, QRect) const = 0; /** * Enable or disable synchronous painting. If synchronous @@ -128,29 +130,29 @@ virtual QString getLayerPresentationName() const; virtual QPixmap getLayerPresentationPixmap(QSize) const { return QPixmap(); } - virtual int getVerticalScaleWidth(View *, bool detailed, + virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool detailed, QPainter &) const = 0; - virtual void paintVerticalScale(View *, bool /* detailed */, + virtual void paintVerticalScale(LayerGeometryProvider *, bool /* detailed */, QPainter &, QRect) const { } - virtual bool getCrosshairExtents(View *, QPainter &, QPoint /* cursorPos */, + virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint /* cursorPos */, std::vector<QRect> &) const { return false; } - virtual void paintCrosshairs(View *, QPainter &, QPoint) const { } + virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const { } - virtual void paintMeasurementRects(View *, QPainter &, + virtual void paintMeasurementRects(LayerGeometryProvider *, QPainter &, bool showFocus, QPoint focusPoint) const; - virtual bool nearestMeasurementRectChanged(View *, QPoint prev, + virtual bool nearestMeasurementRectChanged(LayerGeometryProvider *, QPoint prev, QPoint now) const; - virtual QString getFeatureDescription(View *, QPoint &) const { + virtual QString getFeatureDescription(LayerGeometryProvider *, QPoint &) const { return ""; } - virtual QString getLabelPreceding(int /* frame */) const { + virtual QString getLabelPreceding(sv_frame_t /* frame */) const { return ""; } @@ -180,8 +182,8 @@ * (and leave frame unmodified). If returning true, also return * the resolution of the model in this layer in sample frames. */ - virtual bool snapToFeatureFrame(View * /* v */, - int & /* frame */, + virtual bool snapToFeatureFrame(LayerGeometryProvider * /* v */, + sv_frame_t & /* frame */, int &resolution, SnapType /* snap */) const { resolution = 1; @@ -204,8 +206,8 @@ * (and leave frame unmodified). If returning true, also return * the resolution of the model in this layer in sample frames. */ - virtual bool snapToSimilarFeature(View * /* v */, - int & /* source frame */, + virtual bool snapToSimilarFeature(LayerGeometryProvider * /* v */, + sv_frame_t & /* source frame */, int &resolution, SnapType /* snap */) const { resolution = 1; @@ -217,30 +219,30 @@ // Layer needs to get actual mouse events, I guess. Draw mode is // probably the easier. - virtual void drawStart(View *, QMouseEvent *) { } - virtual void drawDrag(View *, QMouseEvent *) { } - virtual void drawEnd(View *, QMouseEvent *) { } + virtual void drawStart(LayerGeometryProvider *, QMouseEvent *) { } + virtual void drawDrag(LayerGeometryProvider *, QMouseEvent *) { } + virtual void drawEnd(LayerGeometryProvider *, QMouseEvent *) { } - virtual void eraseStart(View *, QMouseEvent *) { } - virtual void eraseDrag(View *, QMouseEvent *) { } - virtual void eraseEnd(View *, QMouseEvent *) { } + virtual void eraseStart(LayerGeometryProvider *, QMouseEvent *) { } + virtual void eraseDrag(LayerGeometryProvider *, QMouseEvent *) { } + virtual void eraseEnd(LayerGeometryProvider *, QMouseEvent *) { } - virtual void editStart(View *, QMouseEvent *) { } - virtual void editDrag(View *, QMouseEvent *) { } - virtual void editEnd(View *, QMouseEvent *) { } + virtual void editStart(LayerGeometryProvider *, QMouseEvent *) { } + virtual void editDrag(LayerGeometryProvider *, QMouseEvent *) { } + virtual void editEnd(LayerGeometryProvider *, QMouseEvent *) { } - virtual void splitStart(View *, QMouseEvent *) { } - virtual void splitEnd(View *, QMouseEvent *) { } - virtual void addNote(View *, QMouseEvent *) { }; + virtual void splitStart(LayerGeometryProvider *, QMouseEvent *) { } + virtual void splitEnd(LayerGeometryProvider *, QMouseEvent *) { } + virtual void addNote(LayerGeometryProvider *, QMouseEvent *) { }; // Measurement rectangle (or equivalent). Unlike draw and edit, // the base Layer class can provide working implementations of // these for most situations. // - virtual void measureStart(View *, QMouseEvent *); - virtual void measureDrag(View *, QMouseEvent *); - virtual void measureEnd(View *, QMouseEvent *); - virtual void measureDoubleClick(View *, QMouseEvent *); + virtual void measureStart(LayerGeometryProvider *, QMouseEvent *); + virtual void measureDrag(LayerGeometryProvider *, QMouseEvent *); + virtual void measureEnd(LayerGeometryProvider *, QMouseEvent *); + virtual void measureDoubleClick(LayerGeometryProvider *, QMouseEvent *); virtual bool haveCurrentMeasureRect() const { return m_haveCurrentMeasureRect; @@ -252,13 +254,13 @@ * double-click). If there is no item or editing is not * supported, return false. */ - virtual bool editOpen(View *, QMouseEvent *) { return false; } + virtual bool editOpen(LayerGeometryProvider *, QMouseEvent *) { return false; } - virtual void moveSelection(Selection, int /* newStartFrame */) { } + virtual void moveSelection(Selection, sv_frame_t /* newStartFrame */) { } virtual void resizeSelection(Selection, Selection /* newSize */) { } virtual void deleteSelection(Selection) { } - virtual void copy(View *, Selection, Clipboard & /* to */) { } + virtual void copy(LayerGeometryProvider *, Selection, Clipboard & /* to */) { } /** * Paste from the given clipboard onto the layer at the given @@ -267,9 +269,9 @@ * return false if the user cancelled the paste operation. This * function should return true if a paste actually occurred. */ - virtual bool paste(View *, + virtual bool paste(LayerGeometryProvider *, const Clipboard & /* from */, - int /* frameOffset */, + sv_frame_t /* frameOffset */, bool /* interactive */) { return false; } // Text mode: @@ -289,7 +291,7 @@ * scrolling better if it is known that individual views can be * scrolled safely in this way. */ - virtual bool isLayerScrollable(const View *) const { return true; } + virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return true; } /** * This should return true if the layer completely obscures any @@ -344,14 +346,14 @@ * isReady(int *) call. The view may choose to show a progress * meter if it finds that this returns < 100 at any given moment. */ - virtual int getCompletion(View *) const { return 100; } + virtual int getCompletion(LayerGeometryProvider *) const { return 100; } /** * Return an error string if any errors have occurred while * loading or processing data for the given view. Return the * empty string if no error has occurred. */ - virtual QString getError(View *) const { return ""; } + virtual QString getError(LayerGeometryProvider *) const { return ""; } virtual void setObjectName(const QString &name); @@ -400,13 +402,13 @@ * A layer class that overrides this function must also call this * class's implementation. */ - virtual void setLayerDormant(const View *v, bool dormant); + virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant); /** * Return whether the layer is dormant (i.e. hidden) in the given * view. */ - virtual bool isLayerDormant(const View *v) const; + virtual bool isLayerDormant(const LayerGeometryProvider *v) const; virtual PlayParameters *getPlayParameters(); @@ -423,7 +425,7 @@ * This function returns the "normal" extents for the layer, not * necessarily the extents actually in use in the display. */ - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const = 0; /** @@ -434,8 +436,8 @@ * extent (using the normal layer extents or deferring to whatever * is in use for the same units elsewhere in the view). */ - virtual bool getDisplayExtents(float & /* min */, - float & /* max */) const { + virtual bool getDisplayExtents(double & /* min */, + double & /* max */) const { return false; } @@ -446,8 +448,8 @@ * return false for getDisplayExtents should also return false for * this function. */ - virtual bool setDisplayExtents(float /* min */, - float /* max */) { + virtual bool setDisplayExtents(double /* min */, + double /* max */) { return false; } @@ -457,15 +459,15 @@ * measurement tool. The default implementation works correctly * if the layer hasTimeXAxis(). */ - virtual bool getXScaleValue(const View *v, int x, - float &value, QString &unit) const; + virtual bool getXScaleValue(const LayerGeometryProvider *v, int x, + double &value, QString &unit) const; /** * Return the value and unit at the given y coordinate in the * given view. */ - virtual bool getYScaleValue(const View *, int /* y */, - float &/* value */, QString &/* unit */) const { + virtual bool getYScaleValue(const LayerGeometryProvider *, int /* y */, + double &/* value */, QString &/* unit */) const { return false; } @@ -475,8 +477,8 @@ * The default implementation just calls getYScaleValue twice and * returns the difference, with the same unit. */ - virtual bool getYScaleDifference(const View *v, int y0, int y1, - float &diff, QString &unit) const; + virtual bool getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1, + double &diff, QString &unit) const; /** * Get the number of vertical zoom steps available for this layer. @@ -518,14 +520,21 @@ */ virtual RangeMapper *getNewVerticalZoomRangeMapper() const { return 0; } + /** + * Return true if this layer type can function without a model + * being set. If false (the default), the layer will not be loaded + * from a session if its model cannot be found. + */ + virtual bool canExistWithoutModel() const { return false; } + public slots: - void showLayer(View *, bool show); + void showLayer(LayerGeometryProvider *, bool show); signals: void modelChanged(); void modelCompletionChanged(); void modelAlignmentCompletionChanged(); - void modelChangedWithin(int startFrame, int endFrame); + void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame); void modelReplaced(); void layerParametersChanged(); @@ -538,16 +547,16 @@ protected: void connectSignals(const Model *); - virtual int alignToReference(View *v, int frame) const; - virtual int alignFromReference(View *v, int frame) const; - bool clipboardHasDifferentAlignment(View *v, const Clipboard &clip) const; + virtual sv_frame_t alignToReference(LayerGeometryProvider *v, sv_frame_t frame) const; + virtual sv_frame_t alignFromReference(LayerGeometryProvider *v, sv_frame_t frame) const; + bool clipboardHasDifferentAlignment(LayerGeometryProvider *v, const Clipboard &clip) const; struct MeasureRect { mutable QRect pixrect; bool haveFrames; - int startFrame; // only valid if haveFrames - int endFrame; // ditto + sv_frame_t startFrame; // only valid if haveFrames + sv_frame_t endFrame; // ditto double startY; double endY; @@ -605,16 +614,16 @@ // Note that pixrects are only correct for a single view. // So we should update them at the start of the paint procedure // (painting is single threaded) and only use them after that. - void updateMeasurePixrects(View *v) const; + void updateMeasurePixrects(LayerGeometryProvider *v) const; - virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const; - virtual void setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const; - virtual void setMeasureRectFromPixrect(View *v, MeasureRect &r, QRect pixrect) const; + virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const; + virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const; + virtual void setMeasureRectFromPixrect(LayerGeometryProvider *v, MeasureRect &r, QRect pixrect) const; // This assumes updateMeasurementPixrects has been called MeasureRectSet::const_iterator findFocusedMeasureRect(QPoint) const; - void paintMeasurementRect(View *v, QPainter &paint, + void paintMeasurementRect(LayerGeometryProvider *v, QPainter &paint, const MeasureRect &r, bool focus) const; QString m_presentationName;
--- a/layer/LayerFactory.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LayerFactory.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -198,7 +198,10 @@ LayerTypeSet types; types.insert(TimeInstants); types.insert(TimeValues); - types.insert(FlexiNotes); + // Because this is strictly a UI function -- list the layer types + // to show in a menu -- it should not contain FlexiNotes; the + // layer isn't meaningfully editable in SV +// types.insert(FlexiNotes); types.insert(Notes); types.insert(Regions); types.insert(Text);
--- a/layer/LayerFactory.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LayerFactory.h Fri Jun 26 14:13:31 2015 +0100 @@ -57,6 +57,11 @@ typedef std::set<LayerType> LayerTypeSet; LayerTypeSet getValidLayerTypes(Model *model); + + /** + * Return the set of layer types that an end user should be + * allowed to create, empty, for subsequent editing. + */ LayerTypeSet getValidEmptyLayerTypes(); LayerType getLayerType(const Layer *);
--- a/layer/LinearColourScale.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LinearColourScale.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -20,31 +20,32 @@ #include <cmath> -#include "view/View.h" +#include "view/LayerGeometryProvider.h" int -LinearColourScale::getWidth(View *, +LinearColourScale::getWidth(LayerGeometryProvider *, QPainter &paint) { return paint.fontMetrics().width("-000.00") + 15; } void -LinearColourScale::paintVertical(View *v, +LinearColourScale::paintVertical(LayerGeometryProvider *v, const ColourScaleLayer *layer, QPainter &paint, int /* x0 */, - float min, - float max) + double min, + double max) { - int h = v->height(); + int h = v->getPaintHeight(); int n = 10; - float val = min; - float inc = (max - val) / n; - - char buffer[40]; + double val = min; + double inc = (max - val) / n; + + const int buflen = 40; + char buffer[buflen]; int boxx = 5, boxy = 5; if (layer->getScaleUnits() != "") { @@ -57,16 +58,16 @@ paint.save(); for (int y = 0; y < boxh; ++y) { - float val = ((boxh - y) * (max - min)) / boxh + min; + double val = ((boxh - y) * (max - min)) / boxh + min; paint.setPen(layer->getColourForValue(v, val)); paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1); } paint.restore(); -// float round = 1.f; +// double round = 1.f; int dp = 0; if (inc > 0) { - int prec = trunc(log10f(inc)); + int prec = int(trunc(log10(inc))); prec -= 1; if (prec < 0) dp = -prec; // round = powf(10.f, prec); @@ -84,7 +85,7 @@ ty = y - paint.fontMetrics().height() + paint.fontMetrics().ascent() + 2; - sprintf(buffer, "%.*f", dp, val); + snprintf(buffer, buflen, "%.*f", dp, val); QString label = QString(buffer); paint.drawLine(boxx + boxw - boxw/3, y, boxx + boxw, y);
--- a/layer/LinearColourScale.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LinearColourScale.h Fri Jun 26 14:13:31 2015 +0100 @@ -19,17 +19,17 @@ #include <QRect> class QPainter; -class View; +class LayerGeometryProvider; class ColourScaleLayer; class LinearColourScale { public: - int getWidth(View *v, QPainter &paint); + int getWidth(LayerGeometryProvider *v, QPainter &paint); void paintVertical - (View *v, const ColourScaleLayer *layer, QPainter &paint, int x0, - float minf, float maxf); + (LayerGeometryProvider *v, const ColourScaleLayer *layer, QPainter &paint, int x0, + double minf, double maxf); }; #endif
--- a/layer/LinearNumericalScale.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LinearNumericalScale.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -23,36 +23,37 @@ #include "view/View.h" int -LinearNumericalScale::getWidth(View *, +LinearNumericalScale::getWidth(LayerGeometryProvider *, QPainter &paint) { return paint.fontMetrics().width("-000.00") + 10; } void -LinearNumericalScale::paintVertical(View *v, +LinearNumericalScale::paintVertical(LayerGeometryProvider *v, const VerticalScaleLayer *layer, QPainter &paint, int x0, - float minf, - float maxf) + double minf, + double maxf) { int n = 10; - float val = minf; - float inc = (maxf - val) / n; + double val = minf; + double inc = (maxf - val) / n; - char buffer[40]; + const int buflen = 40; + char buffer[buflen]; int w = getWidth(v, paint) + x0; - float round = 1.f; + double round = 1.0; int dp = 0; if (inc > 0) { - int prec = trunc(log10f(inc)); + int prec = int(trunc(log10(inc))); prec -= 1; if (prec < 0) dp = -prec; - round = powf(10.f, prec); + round = pow(10.0, prec); #ifdef DEBUG_TIME_VALUE_LAYER cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << endl; #endif @@ -65,13 +66,13 @@ int y, ty; bool drawText = true; - float dispval = val; + double dispval = val; if (i == n-1 && - v->height() < paint.fontMetrics().height() * (n*2)) { + v->getPaintHeight() < paint.fontMetrics().height() * (n*2)) { if (layer->getScaleUnits() != "") drawText = false; } - dispval = lrintf(val / round) * round; + dispval = int(rint(val / round) * round); #ifdef DEBUG_TIME_VALUE_LAYER cerr << "val = " << val << ", dispval = " << dispval << endl; @@ -86,7 +87,7 @@ continue; } - sprintf(buffer, "%.*f", dp, dispval); + snprintf(buffer, buflen, "%.*f", dp, dispval); QString label = QString(buffer);
--- a/layer/LinearNumericalScale.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LinearNumericalScale.h Fri Jun 26 14:13:31 2015 +0100 @@ -19,17 +19,17 @@ #include <QRect> class QPainter; -class View; +class LayerGeometryProvider; class VerticalScaleLayer; class LinearNumericalScale { public: - int getWidth(View *v, QPainter &paint); + int getWidth(LayerGeometryProvider *v, QPainter &paint); void paintVertical - (View *v, const VerticalScaleLayer *layer, QPainter &paint, int x0, - float minf, float maxf); + (LayerGeometryProvider *v, const VerticalScaleLayer *layer, + QPainter &paint, int x0, double minf, double maxf); }; #endif
--- a/layer/LogColourScale.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LogColourScale.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -25,28 +25,29 @@ #include "view/View.h" int -LogColourScale::getWidth(View *, +LogColourScale::getWidth(LayerGeometryProvider *, QPainter &paint) { return paint.fontMetrics().width("-000.00") + 15; } void -LogColourScale::paintVertical(View *v, +LogColourScale::paintVertical(LayerGeometryProvider *v, const ColourScaleLayer *layer, QPainter &paint, int /* x0 */, - float minlog, - float maxlog) + double minlog, + double maxlog) { - int h = v->height(); + int h = v->getPaintHeight(); int n = 10; - float val = minlog; - float inc = (maxlog - val) / n; + double val = minlog; + double inc = (maxlog - val) / n; - char buffer[40]; + const int buflen = 40; + char buffer[buflen]; int boxx = 5, boxy = 5; if (layer->getScaleUnits() != "") { @@ -59,7 +60,7 @@ paint.save(); for (int y = 0; y < boxh; ++y) { - float val = ((boxh - y) * (maxlog - minlog)) / boxh + minlog; + double val = ((boxh - y) * (maxlog - minlog)) / boxh + minlog; paint.setPen(layer->getColourForValue(v, LogRange::unmap(val))); paint.drawLine(boxx + 1, y + boxy + 1, boxx + boxw, y + boxy + 1); } @@ -67,7 +68,7 @@ int dp = 0; if (inc > 0) { - int prec = trunc(log10f(inc)); + int prec = int(trunc(log10(inc))); prec -= 1; if (prec < 0) dp = -prec; } @@ -82,10 +83,10 @@ paint.fontMetrics().ascent() + 2; double dv = LogRange::unmap(val); - int digits = trunc(log10f(dv)); + int digits = int(trunc(log10(dv))); int sf = dp + (digits > 0 ? digits : 0); if (sf < 2) sf = 2; - sprintf(buffer, "%.*g", sf, dv); + snprintf(buffer, buflen, "%.*g", sf, dv); QString label = QString(buffer);
--- a/layer/LogColourScale.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LogColourScale.h Fri Jun 26 14:13:31 2015 +0100 @@ -19,17 +19,17 @@ #include <QRect> class QPainter; -class View; +class LayerGeometryProvider; class ColourScaleLayer; class LogColourScale { public: - int getWidth(View *v, QPainter &paint); + int getWidth(LayerGeometryProvider *v, QPainter &paint); void paintVertical - (View *v, const ColourScaleLayer *layer, QPainter &paint, int x0, - float minf, float maxf); + (LayerGeometryProvider *v, const ColourScaleLayer *layer, QPainter &paint, int x0, + double minf, double maxf); }; #endif
--- a/layer/LogNumericalScale.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LogNumericalScale.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -27,43 +27,44 @@ //#define DEBUG_TIME_VALUE_LAYER 1 int -LogNumericalScale::getWidth(View *, +LogNumericalScale::getWidth(LayerGeometryProvider *, QPainter &paint) { return paint.fontMetrics().width("-000.00") + 10; } void -LogNumericalScale::paintVertical(View *v, +LogNumericalScale::paintVertical(LayerGeometryProvider *v, const VerticalScaleLayer *layer, QPainter &paint, int x0, - float minlog, - float maxlog) + double minlog, + double maxlog) { int w = getWidth(v, paint) + x0; int n = 10; - float val = minlog; - float inc = (maxlog - val) / n; // even increments of log scale + double val = minlog; + double inc = (maxlog - val) / n; // even increments of log scale // smallest increment as displayed - float minDispInc = LogRange::unmap(minlog + inc) - LogRange::unmap(minlog); + double minDispInc = LogRange::unmap(minlog + inc) - LogRange::unmap(minlog); #ifdef DEBUG_TIME_VALUE_LAYER cerr << "min = " << minlog << ", max = " << maxlog << ", inc = " << inc << ", minDispInc = " << minDispInc << endl; #endif - char buffer[40]; + const int buflen = 40; + char buffer[buflen]; - float round = 1.f; + double round = 1.f; int dp = 0; if (minDispInc > 0) { - int prec = trunc(log10f(minDispInc)); + int prec = int(trunc(log10(minDispInc))); if (prec < 0) dp = -prec; - round = powf(10.f, prec); + round = pow(10.0, prec); if (dp > 4) dp = 4; #ifdef DEBUG_TIME_VALUE_LAYER cerr << "round = " << round << ", prec = " << prec << ", dp = " << dp << endl; @@ -78,11 +79,11 @@ bool drawText = true; if (i == n-1 && - v->height() < paint.fontMetrics().height() * (n*2)) { + v->getPaintHeight() < paint.fontMetrics().height() * (n*2)) { if (layer->getScaleUnits() != "") drawText = false; } - float dispval = LogRange::unmap(val); + double dispval = LogRange::unmap(val); dispval = floor(dispval / round) * round; #ifdef DEBUG_TIME_VALUE_LAYER @@ -98,13 +99,13 @@ continue; } - int digits = trunc(log10f(dispval)); + int digits = int(trunc(log10(dispval))); int sf = dp + (digits > 0 ? digits : 0); if (sf < 4) sf = 4; #ifdef DEBUG_TIME_VALUE_LAYER cerr << "sf = " << sf << endl; #endif - sprintf(buffer, "%.*g", sf, dispval); + snprintf(buffer, buflen, "%.*g", sf, dispval); QString label = QString(buffer);
--- a/layer/LogNumericalScale.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/LogNumericalScale.h Fri Jun 26 14:13:31 2015 +0100 @@ -19,17 +19,17 @@ #include <QRect> class QPainter; -class View; +class LayerGeometryProvider; class VerticalScaleLayer; class LogNumericalScale { public: - int getWidth(View *v, QPainter &paint); + int getWidth(LayerGeometryProvider *v, QPainter &paint); void paintVertical - (View *v, const VerticalScaleLayer *layer, QPainter &paint, int x0, - float minlog, float maxlog); + (LayerGeometryProvider *v, const VerticalScaleLayer *layer, QPainter &paint, int x0, + double minlog, double maxlog); }; #endif
--- a/layer/NoteLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/NoteLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -191,7 +191,7 @@ } bool -NoteLayer::isLayerScrollable(const View *v) const +NoteLayer::isLayerScrollable(const LayerGeometryProvider *v) const { QPoint discard; return !v->shouldIlluminateLocalFeatures(this, discard); @@ -209,7 +209,7 @@ } bool -NoteLayer::getValueExtents(float &min, float &max, +NoteLayer::getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const { if (!m_model) return false; @@ -218,8 +218,8 @@ if (shouldConvertMIDIToHz()) { unit = "Hz"; - min = Pitch::getFrequencyForPitch(lrintf(min)); - max = Pitch::getFrequencyForPitch(lrintf(max + 1)); + min = Pitch::getFrequencyForPitch(int(lrint(min))); + max = Pitch::getFrequencyForPitch(int(lrint(max + 1))); } else unit = getScaleUnits(); if (m_verticalScale == MIDIRangeScale || @@ -229,7 +229,7 @@ } bool -NoteLayer::getDisplayExtents(float &min, float &max) const +NoteLayer::getDisplayExtents(double &min, double &max) const { if (!m_model || shouldAutoAlign()) return false; @@ -248,8 +248,8 @@ } if (shouldConvertMIDIToHz()) { - min = Pitch::getFrequencyForPitch(lrintf(min)); - max = Pitch::getFrequencyForPitch(lrintf(max + 1)); + min = Pitch::getFrequencyForPitch(int(lrint(min))); + max = Pitch::getFrequencyForPitch(int(lrint(max + 1))); } #ifdef DEBUG_NOTE_LAYER @@ -260,7 +260,7 @@ } bool -NoteLayer::setDisplayExtents(float min, float max) +NoteLayer::setDisplayExtents(double min, double max) { if (!m_model) return false; @@ -302,7 +302,7 @@ RangeMapper *mapper = getNewVerticalZoomRangeMapper(); if (!mapper) return 0; - float dmin, dmax; + double dmin, dmax; getDisplayExtents(dmin, dmax); int nr = mapper->getPositionForValue(dmax - dmin); @@ -323,29 +323,29 @@ RangeMapper *mapper = getNewVerticalZoomRangeMapper(); if (!mapper) return; - float min, max; + double min, max; bool logarithmic; QString unit; getValueExtents(min, max, logarithmic, unit); - float dmin, dmax; + double dmin, dmax; getDisplayExtents(dmin, dmax); - float newdist = mapper->getValueForPosition(100 - step); + double newdist = mapper->getValueForPosition(100 - step); - float newmin, newmax; + double newmin, newmax; if (logarithmic) { // see SpectrogramLayer::setVerticalZoomStep - newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2; + newmax = (newdist + sqrt(newdist*newdist + 4*dmin*dmax)) / 2; newmin = newmax - newdist; // cerr << "newmin = " << newmin << ", newmax = " << newmax << endl; } else { - float dmid = (dmax + dmin) / 2; + double dmid = (dmax + dmin) / 2; newmin = dmid - newdist / 2; newmax = dmid + newdist / 2; } @@ -372,7 +372,7 @@ RangeMapper *mapper; - float min, max; + double min, max; bool logarithmic; QString unit; getValueExtents(min, max, logarithmic, unit); @@ -389,11 +389,11 @@ } NoteModel::PointList -NoteLayer::getLocalPoints(View *v, int x) const +NoteLayer::getLocalPoints(LayerGeometryProvider *v, int x) const { if (!m_model) return NoteModel::PointList(); - int frame = v->getFrameForX(x); + sv_frame_t frame = v->getFrameForX(x); NoteModel::PointList onPoints = m_model->getPoints(frame); @@ -432,11 +432,11 @@ } bool -NoteLayer::getPointToDrag(View *v, int x, int y, NoteModel::Point &p) const +NoteLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, NoteModel::Point &p) const { if (!m_model) return false; - int frame = v->getFrameForX(x); + sv_frame_t frame = v->getFrameForX(x); NoteModel::PointList onPoints = m_model->getPoints(frame); if (onPoints.empty()) return false; @@ -460,7 +460,7 @@ } QString -NoteLayer::getFeatureDescription(View *v, QPoint &pos) const +NoteLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); @@ -506,9 +506,9 @@ if (shouldConvertMIDIToHz()) { - int mnote = lrintf(note.value); - int cents = lrintf((note.value - mnote) * 100); - float freq = Pitch::getFrequencyForPitch(mnote, cents); + int mnote = int(lrint(note.value)); + int cents = int(lrint((note.value - float(mnote)) * 100)); + double freq = Pitch::getFrequencyForPitch(mnote, cents); pitchText = tr("%1 (%2, %3 Hz)") .arg(Pitch::getPitchLabel(mnote, cents)) .arg(mnote) @@ -547,7 +547,7 @@ } bool -NoteLayer::snapToFeatureFrame(View *v, int &frame, +NoteLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -567,7 +567,7 @@ } points = m_model->getPoints(frame, frame); - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; for (NoteModel::PointList::const_iterator i = points.begin(); @@ -619,7 +619,7 @@ } void -NoteLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const +NoteLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const { min = 0.0; max = 0.0; @@ -637,8 +637,8 @@ max = m_model->getValueMaximum(); if (shouldConvertMIDIToHz()) { - min = Pitch::getFrequencyForPitch(lrintf(min)); - max = Pitch::getFrequencyForPitch(lrintf(max + 1)); + min = Pitch::getFrequencyForPitch(int(lrint(min))); + max = Pitch::getFrequencyForPitch(int(lrint(max + 1))); } #ifdef DEBUG_NOTE_LAYER @@ -663,8 +663,8 @@ min = Pitch::getFrequencyForPitch(0); max = Pitch::getFrequencyForPitch(127); } else if (shouldConvertMIDIToHz()) { - min = Pitch::getFrequencyForPitch(lrintf(min)); - max = Pitch::getFrequencyForPitch(lrintf(max + 1)); + min = Pitch::getFrequencyForPitch(int(lrint(min))); + max = Pitch::getFrequencyForPitch(int(lrint(max + 1))); } if (m_verticalScale == LogScale || m_verticalScale == MIDIRangeScale) { @@ -677,11 +677,11 @@ } int -NoteLayer::getYForValue(View *v, float val) const +NoteLayer::getYForValue(LayerGeometryProvider *v, double val) const { - float min = 0.0, max = 0.0; + double min = 0.0, max = 0.0; bool logarithmic = false; - int h = v->height(); + int h = v->getPaintHeight(); getScaleExtents(v, min, max, logarithmic); @@ -690,8 +690,8 @@ #endif if (shouldConvertMIDIToHz()) { - val = Pitch::getFrequencyForPitch(lrintf(val), - lrintf((val - lrintf(val)) * 100)); + val = Pitch::getFrequencyForPitch(int(lrint(val)), + int(lrint((val - rint(val)) * 100))); #ifdef DEBUG_NOTE_LAYER cerr << "shouldConvertMIDIToHz true, val now = " << val << endl; #endif @@ -711,19 +711,19 @@ return y; } -float -NoteLayer::getValueForY(View *v, int y) const +double +NoteLayer::getValueForY(LayerGeometryProvider *v, int y) const { - float min = 0.0, max = 0.0; + double min = 0.0, max = 0.0; bool logarithmic = false; - int h = v->height(); + int h = v->getPaintHeight(); getScaleExtents(v, min, max, logarithmic); - float val = min + (float(h - y) * float(max - min)) / h; + double val = min + (double(h - y) * double(max - min)) / h; if (logarithmic) { - val = powf(10.f, val); + val = pow(10.0, val); } if (shouldConvertMIDIToHz()) { @@ -741,18 +741,18 @@ } void -NoteLayer::paint(View *v, QPainter &paint, QRect rect) const +NoteLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) return; - int sampleRate = m_model->getSampleRate(); + sv_samplerate_t sampleRate = m_model->getSampleRate(); if (!sampleRate) return; // Profiler profiler("NoteLayer::paint", true); int x0 = rect.left(), x1 = rect.right(); - int frame0 = v->getFrameForX(x0); - int frame1 = v->getFrameForX(x1); + sv_frame_t frame0 = v->getFrameForX(x0); + sv_frame_t frame1 = v->getFrameForX(x1); NoteModel::PointList points(m_model->getPoints(frame0, frame1)); if (points.empty()) return; @@ -765,8 +765,8 @@ // SVDEBUG << "NoteLayer::paint: resolution is " // << m_model->getResolution() << " frames" << endl; - float min = m_model->getValueMinimum(); - float max = m_model->getValueMaximum(); + double min = m_model->getValueMinimum(); + double max = m_model->getValueMaximum(); if (max == min) max = min + 1.0; QPoint localPos; @@ -830,7 +830,7 @@ } int -NoteLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const +NoteLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const { if (!m_model || shouldAutoAlign()) { return 0; @@ -844,16 +844,16 @@ } void -NoteLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const +NoteLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const { if (!m_model || m_model->getPoints().empty()) return; QString unit; - float min, max; + double min, max; bool logarithmic; int w = getVerticalScaleWidth(v, false, paint); - int h = v->height(); + int h = v->getPaintHeight(); getScaleExtents(v, min, max, logarithmic); @@ -882,19 +882,19 @@ } void -NoteLayer::drawStart(View *v, QMouseEvent *e) +NoteLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "NoteLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; if (!m_model) return; - int frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float value = getValueForY(v, e->y()); + double value = getValueForY(v, e->y()); - m_editingPoint = NoteModel::Point(frame, value, 0, 0.8, tr("New Point")); + m_editingPoint = NoteModel::Point(frame, float(value), 0, 0.8f, tr("New Point")); m_originalPoint = m_editingPoint; if (m_editingCommand) finish(m_editingCommand); @@ -906,20 +906,20 @@ } void -NoteLayer::drawDrag(View *v, QMouseEvent *e) +NoteLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "NoteLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; - int frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float newValue = getValueForY(v, e->y()); + double newValue = getValueForY(v, e->y()); - int newFrame = m_editingPoint.frame; - int newDuration = frame - newFrame; + sv_frame_t newFrame = m_editingPoint.frame; + sv_frame_t newDuration = frame - newFrame; if (newDuration < 0) { newFrame = frame; newDuration = -newDuration; @@ -929,13 +929,13 @@ m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = newFrame; - m_editingPoint.value = newValue; + m_editingPoint.value = float(newValue); m_editingPoint.duration = newDuration; m_editingCommand->addPoint(m_editingPoint); } void -NoteLayer::drawEnd(View *, QMouseEvent *) +NoteLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) { // SVDEBUG << "NoteLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; @@ -945,7 +945,7 @@ } void -NoteLayer::eraseStart(View *v, QMouseEvent *e) +NoteLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return; @@ -960,12 +960,12 @@ } void -NoteLayer::eraseDrag(View *, QMouseEvent *) +NoteLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) { } void -NoteLayer::eraseEnd(View *v, QMouseEvent *e) +NoteLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; @@ -985,7 +985,7 @@ } void -NoteLayer::editStart(View *v, QMouseEvent *e) +NoteLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "NoteLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; @@ -1008,7 +1008,7 @@ } void -NoteLayer::editDrag(View *v, QMouseEvent *e) +NoteLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "NoteLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; @@ -1019,11 +1019,11 @@ int newx = m_dragPointX + xdist; int newy = m_dragPointY + ydist; - int frame = v->getFrameForX(newx); + sv_frame_t frame = v->getFrameForX(newx); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float value = getValueForY(v, newy); + double value = getValueForY(v, newy); if (!m_editingCommand) { m_editingCommand = new NoteModel::EditCommand(m_model, @@ -1032,12 +1032,12 @@ m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = frame; - m_editingPoint.value = value; + m_editingPoint.value = float(value); m_editingCommand->addPoint(m_editingPoint); } void -NoteLayer::editEnd(View *, QMouseEvent *) +NoteLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) { // SVDEBUG << "NoteLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; @@ -1065,7 +1065,7 @@ } bool -NoteLayer::editOpen(View *v, QMouseEvent *e) +NoteLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return false; @@ -1107,7 +1107,7 @@ } void -NoteLayer::moveSelection(Selection s, int newStartFrame) +NoteLayer::moveSelection(Selection s, sv_frame_t newStartFrame) { if (!m_model) return; @@ -1151,13 +1151,13 @@ if (s.contains(i->frame)) { - double targetStart = i->frame; - targetStart = newSize.getStartFrame() + - double(targetStart - s.getStartFrame()) * ratio; + double targetStart = double(i->frame); + targetStart = double(newSize.getStartFrame()) + + targetStart - double(s.getStartFrame()) * ratio; - double targetEnd = i->frame + i->duration; - targetEnd = newSize.getStartFrame() + - double(targetEnd - s.getStartFrame()) * ratio; + double targetEnd = double(i->frame + i->duration); + targetEnd = double(newSize.getStartFrame()) + + targetEnd - double(s.getStartFrame()) * ratio; NoteModel::Point newPoint(*i); newPoint.frame = lrint(targetStart); @@ -1193,7 +1193,7 @@ } void -NoteLayer::copy(View *v, Selection s, Clipboard &to) +NoteLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) { if (!m_model) return; @@ -1211,7 +1211,7 @@ } bool -NoteLayer::paste(View *v, const Clipboard &from, int /* frameOffset */, bool /* interactive */) +NoteLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) { if (!m_model) return false; @@ -1222,7 +1222,7 @@ if (clipboardHasDifferentAlignment(v, from)) { QMessageBox::StandardButton button = - QMessageBox::question(v, tr("Re-align pasted items?"), + QMessageBox::question(v->getView(), tr("Re-align pasted items?"), tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); @@ -1243,7 +1243,7 @@ i != points.end(); ++i) { if (!i->haveFrame()) continue; - int frame = 0; + sv_frame_t frame = 0; if (!realign) { @@ -1268,7 +1268,7 @@ if (i->haveLevel()) newPoint.level = i->getLevel(); if (i->haveDuration()) newPoint.duration = i->getDuration(); else { - int nextFrame = frame; + sv_frame_t nextFrame = frame; Clipboard::PointList::const_iterator j = i; for (; j != points.end(); ++j) { if (!j->haveFrame()) continue; @@ -1292,13 +1292,13 @@ } void -NoteLayer::addNoteOn(int frame, int pitch, int velocity) +NoteLayer::addNoteOn(sv_frame_t frame, int pitch, int velocity) { - m_pendingNoteOns.insert(Note(frame, pitch, 0, float(velocity) / 127.0, "")); + m_pendingNoteOns.insert(Note(frame, float(pitch), 0, float(velocity) / 127.f, "")); } void -NoteLayer::addNoteOff(int frame, int pitch) +NoteLayer::addNoteOff(sv_frame_t frame, int pitch) { for (NoteSet::iterator i = m_pendingNoteOns.begin(); i != m_pendingNoteOns.end(); ++i) {
--- a/layer/NoteLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/NoteLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -35,37 +35,37 @@ public: NoteLayer(); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; - virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; + virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const; + virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void drawStart(View *v, QMouseEvent *); - virtual void drawDrag(View *v, QMouseEvent *); - virtual void drawEnd(View *v, QMouseEvent *); + virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void eraseStart(View *v, QMouseEvent *); - virtual void eraseDrag(View *v, QMouseEvent *); - virtual void eraseEnd(View *v, QMouseEvent *); + virtual void eraseStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void editStart(View *v, QMouseEvent *); - virtual void editDrag(View *v, QMouseEvent *); - virtual void editEnd(View *v, QMouseEvent *); + virtual void editStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual bool editOpen(View *v, QMouseEvent *); + virtual bool editOpen(LayerGeometryProvider *v, QMouseEvent *); - virtual void moveSelection(Selection s, int newStartFrame); + virtual void moveSelection(Selection s, sv_frame_t newStartFrame); virtual void resizeSelection(Selection s, Selection newSize); virtual void deleteSelection(Selection s); - virtual void copy(View *v, Selection s, Clipboard &to); - virtual bool paste(View *v, const Clipboard &from, int frameOffset, + virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to); + virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive); virtual const Model *getModel() const { return m_model; } @@ -91,17 +91,17 @@ void setVerticalScale(VerticalScale scale); VerticalScale getVerticalScale() const { return m_verticalScale; } - virtual bool isLayerScrollable(const View *v) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; virtual bool isLayerEditable() const { return true; } - virtual int getCompletion(View *) const { return m_model->getCompletion(); } + virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &log, QString &unit) const; - virtual bool getDisplayExtents(float &min, float &max) const; - virtual bool setDisplayExtents(float min, float max); + virtual bool getDisplayExtents(double &min, double &max) const; + virtual bool setDisplayExtents(double min, double max); virtual int getVerticalZoomSteps(int &defaultStep) const; virtual int getCurrentVerticalZoomStep() const; @@ -113,13 +113,13 @@ * not be finally added to the layer until the corresponding * note-off. */ - void addNoteOn(int frame, int pitch, int velocity); + void addNoteOn(sv_frame_t frame, int pitch, int velocity); /** * Add a note-off. This will cause a note to appear, if and only * if there is a matching pending note-on. */ - void addNoteOff(int frame, int pitch); + void addNoteOff(sv_frame_t frame, int pitch); /** * Abandon all pending note-on events. @@ -132,19 +132,19 @@ void setProperties(const QXmlAttributes &attributes); /// VerticalScaleLayer methods - virtual int getYForValue(View *v, float value) const; - virtual float getValueForY(View *v, int y) const; + virtual int getYForValue(LayerGeometryProvider *v, double value) const; + virtual double getValueForY(LayerGeometryProvider *v, int y) const; virtual QString getScaleUnits() const; protected: - void getScaleExtents(View *, float &min, float &max, bool &log) const; + void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const; bool shouldConvertMIDIToHz() const; virtual int getDefaultColourHint(bool dark, bool &impose); - NoteModel::PointList getLocalPoints(View *v, int) const; + NoteModel::PointList getLocalPoints(LayerGeometryProvider *v, int) const; - bool getPointToDrag(View *v, int x, int y, NoteModel::Point &) const; + bool getPointToDrag(LayerGeometryProvider *v, int x, int y, NoteModel::Point &) const; NoteModel *m_model; bool m_editing; @@ -160,8 +160,8 @@ typedef std::set<NoteModel::Point, NoteModel::Point::Comparator> NoteSet; NoteSet m_pendingNoteOns; - mutable float m_scaleMinimum; - mutable float m_scaleMaximum; + mutable double m_scaleMinimum; + mutable double m_scaleMaximum; bool shouldAutoAlign() const;
--- a/layer/PaintAssistant.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/PaintAssistant.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -25,11 +25,11 @@ void PaintAssistant::paintVerticalLevelScale(QPainter &paint, QRect rect, - float minVal, float maxVal, + double minVal, double maxVal, Scale scale, int &mult, std::vector<int> *vy) { - static float meterdbs[] = { -40, -30, -20, -15, -10, + static double meterdbs[] = { -40, -30, -20, -15, -10, -5, -3, -2, -1, -0.5, 0 }; int h = rect.height(), w = rect.width(); @@ -41,7 +41,7 @@ int n = 10; if (vy) vy->clear(); - float step = 0; + double step = 0; mult = 1; if (scale == LinearScale) { step = (maxVal - minVal) / n; @@ -53,8 +53,8 @@ if (round) { mult /= 10; // cerr << "\n\nstep goes from " << step; - step = float(round) / mult; - n = lrintf((maxVal - minVal) / step); + step = double(round) / mult; + n = int(lrint((maxVal - minVal) / step)); if (mult > 1) { mult /= 10; } @@ -64,7 +64,7 @@ for (int i = 0; i <= n; ++i) { - float val = 0.0, nval = 0.0; + double val = 0.0, nval = 0.0; QString text = ""; switch (scale) { @@ -166,20 +166,20 @@ } static int -dBscale(float sample, int m, float maxVal, float minVal) +dBscale(double sample, int m, double maxVal, double minVal) { if (sample < 0.0) return dBscale(-sample, m, maxVal, minVal); - float dB = AudioLevel::multiplier_to_dB(sample); - float mindB = AudioLevel::multiplier_to_dB(minVal); - float maxdB = AudioLevel::multiplier_to_dB(maxVal); + double dB = AudioLevel::multiplier_to_dB(sample); + double mindB = AudioLevel::multiplier_to_dB(minVal); + double maxdB = AudioLevel::multiplier_to_dB(maxVal); if (dB < mindB) return 0; if (dB > 0.0) return m; return int(((dB - mindB) * m) / (maxdB - mindB) + 0.1); } int -PaintAssistant::getYForValue(Scale scale, float value, - float minVal, float maxVal, +PaintAssistant::getYForValue(Scale scale, double value, + double minVal, double maxVal, int minY, int height) { int vy = 0;
--- a/layer/PaintAssistant.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/PaintAssistant.h Fri Jun 26 14:13:31 2015 +0100 @@ -27,12 +27,12 @@ enum Scale { LinearScale, MeterScale, dBScale }; static void paintVerticalLevelScale(QPainter &p, QRect rect, - float minVal, float maxVal, + double minVal, double maxVal, Scale scale, int &multRtn, std::vector<int> *markCoordRtns = 0); - static int getYForValue(Scale scale, float value, - float minVal, float maxVal, + static int getYForValue(Scale scale, double value, + double minVal, double maxVal, int minY, int height); };
--- a/layer/PianoScale.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/PianoScale.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -21,14 +21,14 @@ #include "base/Pitch.h" -#include "view/View.h" +#include "view/LayerGeometryProvider.h" void -PianoScale::paintPianoVertical(View *v, +PianoScale::paintPianoVertical(LayerGeometryProvider *v, QPainter &paint, QRect r, - float minf, - float maxf) + double minf, + double maxf) { int x0 = r.x(), y0 = r.y(), x1 = r.x() + r.width(), y1 = r.y() + r.height(); @@ -39,8 +39,8 @@ for (int i = 0; i < 128; ++i) { - float f = Pitch::getFrequencyForPitch(i); - int y = lrintf(v->getYForFrequency(f, minf, maxf, true)); + double f = Pitch::getFrequencyForPitch(i); + int y = int(lrint(v->getYForFrequency(f, minf, maxf, true))); if (y < y0 - 2) break; if (y > y1 + 2) {
--- a/layer/PianoScale.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/PianoScale.h Fri Jun 26 14:13:31 2015 +0100 @@ -19,13 +19,13 @@ #include <QRect> class QPainter; -class View; +class LayerGeometryProvider; class PianoScale { public: void paintPianoVertical - (View *v, QPainter &paint, QRect rect, float minf, float maxf); + (LayerGeometryProvider *v, QPainter &paint, QRect rect, double minf, double maxf); }; #endif
--- a/layer/RegionLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/RegionLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -244,7 +244,7 @@ } bool -RegionLayer::isLayerScrollable(const View *v) const +RegionLayer::isLayerScrollable(const LayerGeometryProvider *v) const { QPoint discard; return !v->shouldIlluminateLocalFeatures(this, discard); @@ -275,7 +275,7 @@ } bool -RegionLayer::getValueExtents(float &min, float &max, +RegionLayer::getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const { if (!m_model) return false; @@ -289,7 +289,7 @@ } bool -RegionLayer::getDisplayExtents(float &min, float &max) const +RegionLayer::getDisplayExtents(double &min, double &max) const { if (!m_model || m_verticalScale == AutoAlignScale || @@ -302,7 +302,7 @@ } RegionModel::PointList -RegionLayer::getLocalPoints(View *v, int x) const +RegionLayer::getLocalPoints(LayerGeometryProvider *v, int x) const { if (!m_model) return RegionModel::PointList(); @@ -345,7 +345,7 @@ } bool -RegionLayer::getPointToDrag(View *v, int x, int y, RegionModel::Point &p) const +RegionLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, RegionModel::Point &p) const { if (!m_model) return false; @@ -371,7 +371,7 @@ } QString -RegionLayer::getLabelPreceding(int frame) const +RegionLayer::getLabelPreceding(sv_frame_t frame) const { if (!m_model) return ""; RegionModel::PointList points = m_model->getPreviousPoints(frame); @@ -383,7 +383,7 @@ } QString -RegionLayer::getFeatureDescription(View *v, QPoint &pos) const +RegionLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); @@ -453,7 +453,7 @@ } bool -RegionLayer::snapToFeatureFrame(View *v, int &frame, +RegionLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -473,7 +473,7 @@ } points = m_model->getPoints(frame, frame); - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; for (RegionModel::PointList::const_iterator i = points.begin(); @@ -536,7 +536,7 @@ } bool -RegionLayer::snapToSimilarFeature(View *v, int &frame, +RegionLayer::snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -551,8 +551,8 @@ RegionModel::PointList::const_iterator i; - int matchframe = frame; - float matchvalue = 0.f; + sv_frame_t matchframe = frame; + double matchvalue = 0.f; for (i = close.begin(); i != close.end(); ++i) { if (i->frame > frame) break; @@ -560,10 +560,10 @@ matchframe = i->frame; } - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; bool distant = false; - float epsilon = 0.0001; + double epsilon = 0.0001; i = close.begin(); @@ -588,7 +588,7 @@ if (snap == SnapRight) { if (i->frame > matchframe && - fabsf(i->value - matchvalue) < epsilon) { + fabs(i->value - matchvalue) < epsilon) { snapped = i->frame; found = true; break; @@ -597,7 +597,7 @@ } else if (snap == SnapLeft) { if (i->frame < matchframe) { - if (fabsf(i->value - matchvalue) < epsilon) { + if (fabs(i->value - matchvalue) < epsilon) { snapped = i->frame; found = true; // don't break, as the next may be better } @@ -624,7 +624,7 @@ } void -RegionLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const +RegionLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const { min = 0.0; max = 0.0; @@ -676,33 +676,33 @@ } int -RegionLayer::spacingIndexToY(View *v, int i) const +RegionLayer::spacingIndexToY(LayerGeometryProvider *v, int i) const { - int h = v->height(); - int n = m_spacingMap.size(); + int h = v->getPaintHeight(); + int n = int(m_spacingMap.size()); // this maps from i (spacing of the value from the spacing // map) and n (number of region types) to y int y = h - (((h * i) / n) + (h / (2 * n))); return y; } -float -RegionLayer::yToSpacingIndex(View *v, int y) const +double +RegionLayer::yToSpacingIndex(LayerGeometryProvider *v, int y) const { - // we return an inexact result here (float rather than int) - int h = v->height(); - int n = m_spacingMap.size(); + // we return an inexact result here (double rather than int) + int h = v->getPaintHeight(); + int n = int(m_spacingMap.size()); // from y = h - ((h * i) / n) + (h / (2 * n)) as above (vh taking place of i) - float vh = float(2*h*n - h - 2*n*y) / float(2*h); + double vh = double(2*h*n - h - 2*n*y) / double(2*h); return vh; } int -RegionLayer::getYForValue(View *v, float val) const +RegionLayer::getYForValue(LayerGeometryProvider *v, double val) const { - float min = 0.0, max = 0.0; + double min = 0.0, max = 0.0; bool logarithmic = false; - int h = v->height(); + int h = v->getPaintHeight(); if (m_verticalScale == EqualSpaced) { @@ -732,18 +732,18 @@ } } -float -RegionLayer::getValueForY(View *v, int y) const +double +RegionLayer::getValueForY(LayerGeometryProvider *v, int y) const { return getValueForY(v, y, -1); } -float -RegionLayer::getValueForY(View *v, int y, int avoid) const +double +RegionLayer::getValueForY(LayerGeometryProvider *v, int y, int avoid) const { - float min = 0.0, max = 0.0; + double min = 0.0, max = 0.0; bool logarithmic = false; - int h = v->height(); + int h = v->getPaintHeight(); if (m_verticalScale == EqualSpaced) { @@ -757,14 +757,14 @@ // one of the m/n divisions in the y scale, we should snap to // the value of the mth region. - float vh = yToSpacingIndex(v, y); + double vh = yToSpacingIndex(v, y); // spacings in the map are integral, so find the closest one, // map it back to its y coordinate, and see how far we are // from it - int n = m_spacingMap.size(); - int ivh = lrintf(vh); + int n = int(m_spacingMap.size()); + int ivh = int(lrint(vh)); if (ivh < 0) ivh = 0; if (ivh > n-1) ivh = n-1; int iy = spacingIndexToY(v, ivh); @@ -783,7 +783,7 @@ // cerr << "nearest existing value = " << i->first << " at " << iy << endl; - float val = 0; + double val = 0; // cerr << "note: avoid = " << avoid << ", i->second = " << i->second << endl; @@ -825,10 +825,10 @@ getScaleExtents(v, min, max, logarithmic); - float val = min + (float(h - y) * float(max - min)) / h; + double val = min + (double(h - y) * double(max - min)) / h; if (logarithmic) { - val = powf(10.f, val); + val = pow(10.0, val); } return val; @@ -836,9 +836,9 @@ } QColor -RegionLayer::getColourForValue(View *v, float val) const +RegionLayer::getColourForValue(LayerGeometryProvider *v, double val) const { - float min, max; + double min, max; bool log; getScaleExtents(v, min, max, log); @@ -866,18 +866,18 @@ } void -RegionLayer::paint(View *v, QPainter &paint, QRect rect) const +RegionLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) return; - int sampleRate = m_model->getSampleRate(); + sv_samplerate_t sampleRate = m_model->getSampleRate(); if (!sampleRate) return; // Profiler profiler("RegionLayer::paint", true); int x0 = rect.left() - 40, x1 = rect.right(); - long frame0 = v->getFrameForX(x0); - long frame1 = v->getFrameForX(x1); + sv_frame_t frame0 = v->getFrameForX(x0); + sv_frame_t frame1 = v->getFrameForX(x1); RegionModel::PointList points(m_model->getPoints(frame0, frame1)); if (points.empty()) return; @@ -890,8 +890,8 @@ // SVDEBUG << "RegionLayer::paint: resolution is " // << m_model->getResolution() << " frames" << endl; - float min = m_model->getValueMinimum(); - float max = m_model->getValueMaximum(); + double min = m_model->getValueMinimum(); + double max = m_model->getValueMaximum(); if (max == min) max = min + 1.0; QPoint localPos; @@ -942,7 +942,7 @@ if (w < 1) w = 1; if (m_plotStyle == PlotSegmentation) { - paint.setPen(getForegroundQColor(v)); + paint.setPen(getForegroundQColor(v->getView())); paint.setBrush(getColourForValue(v, p.value)); } else { paint.setPen(getBaseQColor()); @@ -958,15 +958,15 @@ RegionModel::Point::Comparator()(illuminatePoint, p) || RegionModel::Point::Comparator()(p, illuminatePoint)) { - paint.setPen(QPen(getForegroundQColor(v), 1)); - paint.drawLine(x, 0, x, v->height()); + paint.setPen(QPen(getForegroundQColor(v->getView()), 1)); + paint.drawLine(x, 0, x, v->getPaintHeight()); paint.setPen(Qt::NoPen); } else { - paint.setPen(QPen(getForegroundQColor(v), 2)); + paint.setPen(QPen(getForegroundQColor(v->getView()), 2)); } - paint.drawRect(x, -1, ex - x, v->height() + 2); + paint.drawRect(x, -1, ex - x, v->getPaintHeight() + 2); } else { @@ -1040,7 +1040,7 @@ labelX = x + 5; labelY = v->getTextLabelHeight(this, paint); if (labelX < nextLabelMinX) { - if (lastLabelY < v->height()/2) { + if (lastLabelY < v->getPaintHeight()/2) { labelY = lastLabelY + fontHeight; } } @@ -1056,7 +1056,7 @@ } int -RegionLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const +RegionLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const { if (!m_model || m_verticalScale == AutoAlignScale || @@ -1078,12 +1078,12 @@ } void -RegionLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const +RegionLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const { if (!m_model || m_model->getPoints().empty()) return; QString unit; - float min, max; + double min, max; bool logarithmic; int w = getVerticalScaleWidth(v, false, paint); @@ -1121,7 +1121,7 @@ } void -RegionLayer::drawStart(View *v, QMouseEvent *e) +RegionLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return; @@ -1129,9 +1129,9 @@ if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float value = getValueForY(v, e->y()); + double value = getValueForY(v, e->y()); - m_editingPoint = RegionModel::Point(frame, value, 0, ""); + m_editingPoint = RegionModel::Point(frame, float(value), 0, ""); m_originalPoint = m_editingPoint; if (m_editingCommand) finish(m_editingCommand); @@ -1145,19 +1145,19 @@ } void -RegionLayer::drawDrag(View *v, QMouseEvent *e) +RegionLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; - long frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float newValue = m_editingPoint.value; + double newValue = m_editingPoint.value; if (m_verticalScale != EqualSpaced) newValue = getValueForY(v, e->y()); - long newFrame = m_editingPoint.frame; - long newDuration = frame - newFrame; + sv_frame_t newFrame = m_editingPoint.frame; + sv_frame_t newDuration = frame - newFrame; if (newDuration < 0) { newFrame = frame; newDuration = -newDuration; @@ -1167,7 +1167,7 @@ m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = newFrame; - m_editingPoint.value = newValue; + m_editingPoint.value = float(newValue); m_editingPoint.duration = newDuration; m_editingCommand->addPoint(m_editingPoint); @@ -1175,7 +1175,7 @@ } void -RegionLayer::drawEnd(View *, QMouseEvent *) +RegionLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) { if (!m_model || !m_editing) return; finish(m_editingCommand); @@ -1186,7 +1186,7 @@ } void -RegionLayer::eraseStart(View *v, QMouseEvent *e) +RegionLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return; @@ -1202,12 +1202,12 @@ } void -RegionLayer::eraseDrag(View *, QMouseEvent *) +RegionLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) { } void -RegionLayer::eraseEnd(View *v, QMouseEvent *e) +RegionLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; @@ -1229,7 +1229,7 @@ } void -RegionLayer::editStart(View *v, QMouseEvent *e) +RegionLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return; @@ -1254,7 +1254,7 @@ } void -RegionLayer::editDrag(View *v, QMouseEvent *e) +RegionLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; @@ -1274,7 +1274,7 @@ // ... unless there are other points with the same value if (m_distributionMap[m_editingPoint.value] > 1) avoid = -1; - float value = getValueForY(v, newy, avoid); + double value = getValueForY(v, newy, avoid); if (!m_editingCommand) { m_editingCommand = new RegionModel::EditCommand(m_model, @@ -1283,13 +1283,13 @@ m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = frame; - m_editingPoint.value = value; + m_editingPoint.value = float(value); m_editingCommand->addPoint(m_editingPoint); recalcSpacing(); } void -RegionLayer::editEnd(View *, QMouseEvent *) +RegionLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) { if (!m_model || !m_editing) return; @@ -1317,7 +1317,7 @@ } bool -RegionLayer::editOpen(View *v, QMouseEvent *e) +RegionLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return false; @@ -1358,7 +1358,7 @@ } void -RegionLayer::moveSelection(Selection s, int newStartFrame) +RegionLayer::moveSelection(Selection s, sv_frame_t newStartFrame) { if (!m_model) return; @@ -1403,13 +1403,13 @@ if (s.contains(i->frame)) { - double targetStart = i->frame; - targetStart = newSize.getStartFrame() + - double(targetStart - s.getStartFrame()) * ratio; + double targetStart = double(i->frame); + targetStart = double(newSize.getStartFrame()) + + targetStart - double(s.getStartFrame()) * ratio; - double targetEnd = i->frame + i->duration; - targetEnd = newSize.getStartFrame() + - double(targetEnd - s.getStartFrame()) * ratio; + double targetEnd = double(i->frame + i->duration); + targetEnd = double(newSize.getStartFrame()) + + targetEnd - double(s.getStartFrame()) * ratio; RegionModel::Point newPoint(*i); newPoint.frame = lrint(targetStart); @@ -1447,7 +1447,7 @@ } void -RegionLayer::copy(View *v, Selection s, Clipboard &to) +RegionLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) { if (!m_model) return; @@ -1465,7 +1465,7 @@ } bool -RegionLayer::paste(View *v, const Clipboard &from, int /* frameOffset */, bool /* interactive */) +RegionLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) { if (!m_model) return false; @@ -1476,7 +1476,7 @@ if (clipboardHasDifferentAlignment(v, from)) { QMessageBox::StandardButton button = - QMessageBox::question(v, tr("Re-align pasted items?"), + QMessageBox::question(v->getView(), tr("Re-align pasted items?"), tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); @@ -1497,7 +1497,7 @@ i != points.end(); ++i) { if (!i->haveFrame()) continue; - int frame = 0; + sv_frame_t frame = 0; if (!realign) { @@ -1521,7 +1521,7 @@ m_model->getValueMaximum()) / 2; if (i->haveDuration()) newPoint.duration = i->getDuration(); else { - int nextFrame = frame; + sv_frame_t nextFrame = frame; Clipboard::PointList::const_iterator j = i; for (; j != points.end(); ++j) { if (!j->haveFrame()) continue;
--- a/layer/RegionLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/RegionLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -39,41 +39,41 @@ public: RegionLayer(); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; - virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; + virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const; + virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; - virtual QString getLabelPreceding(int) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; + virtual QString getLabelPreceding(sv_frame_t) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual bool snapToSimilarFeature(View *v, int &frame, + virtual bool snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void drawStart(View *v, QMouseEvent *); - virtual void drawDrag(View *v, QMouseEvent *); - virtual void drawEnd(View *v, QMouseEvent *); + virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void eraseStart(View *v, QMouseEvent *); - virtual void eraseDrag(View *v, QMouseEvent *); - virtual void eraseEnd(View *v, QMouseEvent *); + virtual void eraseStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void editStart(View *v, QMouseEvent *); - virtual void editDrag(View *v, QMouseEvent *); - virtual void editEnd(View *v, QMouseEvent *); + virtual void editStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual bool editOpen(View *v, QMouseEvent *); + virtual bool editOpen(LayerGeometryProvider *v, QMouseEvent *); - virtual void moveSelection(Selection s, int newStartFrame); + virtual void moveSelection(Selection s, sv_frame_t newStartFrame); virtual void resizeSelection(Selection s, Selection newSize); virtual void deleteSelection(Selection s); - virtual void copy(View *v, Selection s, Clipboard &to); - virtual bool paste(View *v, const Clipboard &from, int frameOffset, + virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to); + virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive); virtual const Model *getModel() const { return m_model; } @@ -110,16 +110,16 @@ void setPlotStyle(PlotStyle style); PlotStyle getPlotStyle() const { return m_plotStyle; } - virtual bool isLayerScrollable(const View *v) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; virtual bool isLayerEditable() const { return true; } - virtual int getCompletion(View *) const { return m_model->getCompletion(); } + virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &log, QString &unit) const; - virtual bool getDisplayExtents(float &min, float &max) const; + virtual bool getDisplayExtents(double &min, double &max) const; virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; @@ -127,23 +127,23 @@ void setProperties(const QXmlAttributes &attributes); /// VerticalScaleLayer and ColourScaleLayer methods - int getYForValue(View *v, float value) const; - float getValueForY(View *v, int y) const; + int getYForValue(LayerGeometryProvider *v, double value) const; + double getValueForY(LayerGeometryProvider *v, int y) const; virtual QString getScaleUnits() const; - QColor getColourForValue(View *v, float value) const; + QColor getColourForValue(LayerGeometryProvider *v, double value) const; protected slots: void recalcSpacing(); protected: - float getValueForY(View *v, int y, int avoid) const; - void getScaleExtents(View *, float &min, float &max, bool &log) const; + double getValueForY(LayerGeometryProvider *v, int y, int avoid) const; + void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const; virtual int getDefaultColourHint(bool dark, bool &impose); - RegionModel::PointList getLocalPoints(View *v, int x) const; + RegionModel::PointList getLocalPoints(LayerGeometryProvider *v, int x) const; - bool getPointToDrag(View *v, int x, int y, RegionModel::Point &) const; + bool getPointToDrag(LayerGeometryProvider *v, int x, int y, RegionModel::Point &) const; RegionModel *m_model; bool m_editing; @@ -158,7 +158,7 @@ int m_colourMap; PlotStyle m_plotStyle; - typedef std::map<float, int> SpacingMap; + typedef std::map<double, int> SpacingMap; // region value -> ordering SpacingMap m_spacingMap; @@ -166,8 +166,8 @@ // region value -> number of regions with this value SpacingMap m_distributionMap; - int spacingIndexToY(View *v, int i) const; - float yToSpacingIndex(View *v, int y) const; + int spacingIndexToY(LayerGeometryProvider *v, int i) const; + double yToSpacingIndex(LayerGeometryProvider *v, int y) const; void finish(RegionModel::EditCommand *command) { Command *c = command->finish();
--- a/layer/SingleColourLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/SingleColourLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -137,7 +137,7 @@ } void -SingleColourLayer::setDefaultColourFor(View *v) +SingleColourLayer::setDefaultColourFor(LayerGeometryProvider *v) { #ifdef DEBUG_COLOUR_SELECTION SVDEBUG << "SingleColourLayer::setDefaultColourFor: m_colourExplicitlySet = " << m_colourExplicitlySet << ", m_defaultColourSet " << m_defaultColourSet << endl; @@ -244,19 +244,19 @@ } QColor -SingleColourLayer::getBackgroundQColor(View *v) const +SingleColourLayer::getBackgroundQColor(LayerGeometryProvider *v) const { return v->getBackground(); } QColor -SingleColourLayer::getForegroundQColor(View *v) const +SingleColourLayer::getForegroundQColor(LayerGeometryProvider *v) const { return v->getForeground(); } std::vector<QColor> -SingleColourLayer::getPartialShades(View *v) const +SingleColourLayer::getPartialShades(LayerGeometryProvider *v) const { std::vector<QColor> s; QColor base = getBaseQColor();
--- a/layer/SingleColourLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/SingleColourLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -71,16 +71,16 @@ virtual void setProperties(const QXmlAttributes &attributes); - virtual void setDefaultColourFor(View *v); + virtual void setDefaultColourFor(LayerGeometryProvider *v); protected: SingleColourLayer(); virtual ~SingleColourLayer(); virtual QColor getBaseQColor() const; - virtual QColor getBackgroundQColor(View *v) const; - virtual QColor getForegroundQColor(View *v) const; - std::vector<QColor> getPartialShades(View *v) const; + virtual QColor getBackgroundQColor(LayerGeometryProvider *v) const; + virtual QColor getForegroundQColor(LayerGeometryProvider *v) const; + std::vector<QColor> getPartialShades(LayerGeometryProvider *v) const; virtual void flagBaseColourChanged() { } virtual int getDefaultColourHint(bool /* darkBackground */,
--- a/layer/SliceLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/SliceLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -92,14 +92,14 @@ } QString -SliceLayer::getFeatureDescription(View *v, QPoint &p) const +SliceLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const { int minbin, maxbin, range; return getFeatureDescriptionAux(v, p, true, minbin, maxbin, range); } QString -SliceLayer::getFeatureDescriptionAux(View *v, QPoint &p, +SliceLayer::getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &p, bool includeBinDescription, int &minbin, int &maxbin, int &range) const { @@ -108,7 +108,7 @@ if (!m_sliceableModel) return ""; int xorigin = m_xorigins[v]; - int w = v->width() - xorigin - 1; + int w = v->getPaintWidth() - xorigin - 1; int mh = m_sliceableModel->getHeight(); minbin = getBinForX(p.x() - xorigin, mh, w); @@ -119,21 +119,21 @@ if (minbin < 0) minbin = 0; if (maxbin < 0) maxbin = 0; - int sampleRate = m_sliceableModel->getSampleRate(); + sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate(); - int f0 = m_currentf0; - int f1 = m_currentf1; + sv_frame_t f0 = m_currentf0; + sv_frame_t f1 = m_currentf1; RealTime rt0 = RealTime::frame2RealTime(f0, sampleRate); RealTime rt1 = RealTime::frame2RealTime(f1, sampleRate); - range = f1 - f0 + 1; + range = int(f1 - f0 + 1); QString rtrangestr = QString("%1 s").arg((rt1 - rt0).toText().c_str()); if (includeBinDescription) { - float minvalue = 0.f; + float minvalue = 0.0; if (minbin < int(m_values.size())) minvalue = m_values[minbin]; float maxvalue = minvalue; @@ -179,23 +179,23 @@ } } -float -SliceLayer::getXForBin(int bin, int count, float w) const +double +SliceLayer::getXForBin(int bin, int count, double w) const { - float x = 0; + double x = 0; switch (m_binScale) { case LinearBins: - x = (float(w) * bin) / count; + x = (w * bin) / count; break; case LogBins: - x = (float(w) * log10f(bin + 1)) / log10f(count + 1); + x = (w * log10(bin + 1)) / log10(count + 1); break; case InvertedLogBins: - x = w - (float(w) * log10f(count - bin - 1)) / log10f(count); + x = w - (w * log10(count - bin - 1)) / log10(count); break; } @@ -203,7 +203,7 @@ } int -SliceLayer::getBinForX(float x, int count, float w) const +SliceLayer::getBinForX(double x, int count, double w) const { int bin = 0; @@ -214,21 +214,21 @@ break; case LogBins: - bin = int(powf(10.f, (x * log10f(count + 1)) / w) - 1 + 0.0001); + bin = int(pow(10.0, (x * log10(count + 1)) / w) - 1 + 0.0001); break; case InvertedLogBins: - bin = count + 1 - int(powf(10.f, (log10f(count) * (w - x)) / float(w)) + 0.0001); + bin = count + 1 - int(pow(10.0, (log10(count) * (w - x)) / double(w)) + 0.0001); break; } return bin; } -float -SliceLayer::getYForValue(float value, const View *v, float &norm) const +double +SliceLayer::getYForValue(double value, const LayerGeometryProvider *v, double &norm) const { - norm = 0.f; + norm = 0.0; if (m_yorigins.find(v) == m_yorigins.end()) return 0; @@ -236,9 +236,9 @@ int yorigin = m_yorigins[v]; int h = m_heights[v]; - float thresh = getThresholdDb(); + double thresh = getThresholdDb(); - float y = 0.f; + double y = 0.0; if (h <= 0) return y; @@ -246,45 +246,45 @@ case dBScale: { - float db = thresh; - if (value > 0.f) db = 10.f * log10f(fabsf(value)); + double db = thresh; + if (value > 0.0) db = 10.0 * log10(fabs(value)); if (db < thresh) db = thresh; norm = (db - thresh) / -thresh; - y = yorigin - (float(h) * norm); + y = yorigin - (double(h) * norm); break; } case MeterScale: y = AudioLevel::multiplier_to_preview(value, h); - norm = float(y) / float(h); + norm = double(y) / double(h); y = yorigin - y; break; case AbsoluteScale: - value = fabsf(value); + value = fabs(value); // and fall through case LinearScale: default: norm = (value - m_threshold); if (norm < 0) norm = 0; - y = yorigin - (float(h) * norm); + y = yorigin - (double(h) * norm); break; } return y; } -float -SliceLayer::getValueForY(float y, const View *v) const +double +SliceLayer::getValueForY(double y, const LayerGeometryProvider *v) const { - float value = 0.f; + double value = 0.0; if (m_yorigins.find(v) == m_yorigins.end()) return value; int yorigin = m_yorigins[v]; int h = m_heights[v]; - float thresh = getThresholdDb(); + double thresh = getThresholdDb(); if (h <= 0) return value; @@ -294,13 +294,13 @@ case dBScale: { - float db = ((y / h) * -thresh) + thresh; - value = powf(10.f, db/10.f); + double db = ((y / h) * -thresh) + thresh; + value = pow(10.0, db/10.0); break; } case MeterScale: - value = AudioLevel::preview_to_multiplier(lrintf(y), h); + value = AudioLevel::preview_to_multiplier(int(lrint(y)), h); break; case LinearScale: @@ -313,7 +313,7 @@ } void -SliceLayer::paint(View *v, QPainter &paint, QRect rect) const +SliceLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_sliceableModel || !m_sliceableModel->isOK() || !m_sliceableModel->isReady()) return; @@ -334,11 +334,11 @@ paint.setPen(getBaseQColor()); int xorigin = getVerticalScaleWidth(v, true, paint) + 1; - int w = v->width() - xorigin - 1; + int w = v->getPaintWidth() - xorigin - 1; m_xorigins[v] = xorigin; // for use in getFeatureDescription - int yorigin = v->height() - 20 - paint.fontMetrics().height() - 7; + int yorigin = v->getPaintHeight() - 20 - paint.fontMetrics().height() - 7; int h = yorigin - paint.fontMetrics().height() - 8; m_yorigins[v] = yorigin; // for getYForValue etc @@ -354,21 +354,21 @@ m_values.clear(); for (int bin = 0; bin < mh; ++bin) { - m_values.push_back(0.f); + m_values.push_back(0.0); } - int f0 = v->getCentreFrame(); + sv_frame_t f0 = v->getCentreFrame(); int f0x = v->getXForFrame(f0); f0 = v->getFrameForX(f0x); - int f1 = v->getFrameForX(f0x + 1); + sv_frame_t f1 = v->getFrameForX(f0x + 1); if (f1 > f0) --f1; // cerr << "centre frame " << v->getCentreFrame() << ", x " << f0x << ", f0 " << f0 << ", f1 " << f1 << endl; int res = m_sliceableModel->getResolution(); - int col0 = f0 / res; + int col0 = int(f0 / res); int col1 = col0; - if (m_samplingMode != NearestSample) col1 = f1 / res; + if (m_samplingMode != NearestSample) col1 = int(f1 / res); f0 = col0 * res; f1 = (col1 + 1) * res - 1; @@ -379,7 +379,7 @@ BiasCurve curve; getBiasCurve(curve); - int cs = curve.size(); + int cs = int(curve.size()); for (int col = col0; col <= col1; ++col) { for (int bin = 0; bin < mh; ++bin) { @@ -394,31 +394,31 @@ ++divisor; } - float max = 0.f; + float max = 0.0; for (int bin = 0; bin < mh; ++bin) { if (m_samplingMode == SampleMean && divisor > 0) { - m_values[bin] /= divisor; + m_values[bin] /= float(divisor); } if (m_values[bin] > max) max = m_values[bin]; } - if (max != 0.f && m_normalize) { + if (max != 0.0 && m_normalize) { for (int bin = 0; bin < mh; ++bin) { m_values[bin] /= max; } } - float nx = xorigin; + double nx = xorigin; ColourMapper mapper(m_colourMap, 0, 1); for (int bin = 0; bin < mh; ++bin) { - float x = nx; + double x = nx; nx = xorigin + getXForBin(bin + 1, mh, w); - float value = m_values[bin]; - float norm = 0.f; - float y = getYForValue(value, v, norm); + double value = m_values[bin]; + double norm = 0.0; + double y = getYForValue(value, v, norm); if (m_plotStyle == PlotLines) { @@ -501,7 +501,7 @@ } int -SliceLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const +SliceLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const { if (m_energyScale == LinearScale || m_energyScale == AbsoluteScale) { return std::max(paint.fontMetrics().width("0.0") + 13, @@ -513,9 +513,9 @@ } void -SliceLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const +SliceLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const { - float thresh = m_threshold; + double thresh = m_threshold; if (m_energyScale != LinearScale && m_energyScale != AbsoluteScale) { thresh = AudioLevel::dB_to_multiplier(getThresholdDb()); } @@ -523,7 +523,7 @@ // int h = (rect.height() * 3) / 4; // int y = (rect.height() / 2) - (h / 2); - int yorigin = v->height() - 20 - paint.fontMetrics().height() - 6; + int yorigin = v->getPaintHeight() - 20 - paint.fontMetrics().height() - 6; int h = yorigin - paint.fontMetrics().height() - 8; if (h < 0) return; @@ -538,7 +538,7 @@ const_cast<std::vector<int> *>(&m_scalePoints)); if (mult != 1 && mult != 0) { - int log = lrintf(log10f(mult)); + int log = int(lrint(log10(mult))); QString a = tr("x10"); QString b = QString("%1").arg(-log); paint.drawText(3, 8 + paint.fontMetrics().ascent(), a); @@ -627,7 +627,7 @@ cerr << "gain is " << m_gain << ", mode is " << m_samplingMode << endl; - val = lrint(log10(m_gain) * 20.0); + val = int(lrint(log10(m_gain) * 20.0)); if (val < *min) val = *min; if (val > *max) val = *max; @@ -636,11 +636,11 @@ *min = -80; *max = 0; - *deflt = lrintf(AudioLevel::multiplier_to_dB(m_initialThreshold)); + *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold))); if (*deflt < *min) *deflt = *min; if (*deflt > *max) *deflt = *max; - val = lrintf(AudioLevel::multiplier_to_dB(m_threshold)); + val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold))); if (val < *min) val = *min; if (val > *max) val = *max; @@ -757,10 +757,10 @@ SliceLayer::setProperty(const PropertyName &name, int value) { if (name == "Gain") { - setGain(pow(10, float(value)/20.0)); + setGain(powf(10, float(value)/20.0f)); } else if (name == "Threshold") { - if (value == -80) setThreshold(0.0); - else setThreshold(AudioLevel::dB_to_multiplier(value)); + if (value == -80) setThreshold(0.0f); + else setThreshold(float(AudioLevel::dB_to_multiplier(value))); } else if (name == "Colour" && m_plotStyle == PlotFilledBlocks) { setFillColourMap(value); } else if (name == "Scale") { @@ -867,7 +867,7 @@ SliceLayer::getThresholdDb() const { if (m_threshold == 0.0) return -80.f; - float db = AudioLevel::multiplier_to_dB(m_threshold); + float db = float(AudioLevel::multiplier_to_dB(m_threshold)); return db; } @@ -942,7 +942,7 @@ } bool -SliceLayer::getValueExtents(float &, float &, bool &, QString &) const +SliceLayer::getValueExtents(double &, double &, bool &, QString &) const { return false; }
--- a/layer/SliceLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/SliceLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -38,12 +38,12 @@ void setSliceableModel(const Model *model); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; - virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; + virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const; + virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const; virtual ColourSignificance getLayerColourSignificance() const { return ColourAndBackgroundSignificant; @@ -62,12 +62,12 @@ virtual void setProperty(const PropertyName &, int value); virtual void setProperties(const QXmlAttributes &); - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const; virtual bool hasTimeXAxis() const { return false; } - virtual bool isLayerScrollable(const View *) const { return false; } + virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return false; } enum EnergyScale { LinearScale, MeterScale, dBScale, AbsoluteScale }; @@ -93,7 +93,7 @@ BinScale getBinScale() const { return m_binScale; } void setThreshold(float); - int getThreshold() const { return m_threshold; } + float getThreshold() const { return m_threshold; } void setGain(float gain); float getGain() const; @@ -109,13 +109,13 @@ void modelAboutToBeDeleted(Model *); protected: - virtual float getXForBin(int bin, int totalBins, float w) const; - virtual int getBinForX(float x, int totalBins, float w) const; + virtual double getXForBin(int bin, int totalBins, double w) const; + virtual int getBinForX(double x, int totalBins, double w) const; - virtual float getYForValue(float value, const View *v, float &norm) const; - virtual float getValueForY(float y, const View *v) const; + virtual double getYForValue(double value, const LayerGeometryProvider *v, double &norm) const; + virtual double getValueForY(double y, const LayerGeometryProvider *v) const; - virtual QString getFeatureDescriptionAux(View *v, QPoint &, + virtual QString getFeatureDescriptionAux(LayerGeometryProvider *v, QPoint &, bool includeBinDescription, int &minbin, int &maxbin, int &range) const; @@ -141,11 +141,11 @@ float m_initialThreshold; float m_gain; mutable std::vector<int> m_scalePoints; - mutable std::map<const View *, int> m_xorigins; - mutable std::map<const View *, int> m_yorigins; - mutable std::map<const View *, int> m_heights; - mutable int m_currentf0; - mutable int m_currentf1; + mutable std::map<const LayerGeometryProvider *, int> m_xorigins; + mutable std::map<const LayerGeometryProvider *, int> m_yorigins; + mutable std::map<const LayerGeometryProvider *, int> m_heights; + mutable sv_frame_t m_currentf0; + mutable sv_frame_t m_currentf1; mutable std::vector<float> m_values; };
--- a/layer/SpectrogramLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/SpectrogramLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -41,8 +41,6 @@ #include <iostream> - - #include <cassert> #include <cmath> @@ -52,6 +50,8 @@ //#define DEBUG_SPECTROGRAM_REPAINT 1 +using std::vector; + SpectrogramLayer::SpectrogramLayer(Configuration config) : m_model(0), m_channel(0), @@ -139,8 +139,8 @@ connectSignals(m_model); connect(m_model, SIGNAL(modelChanged()), this, SLOT(cacheInvalid())); - connect(m_model, SIGNAL(modelChangedWithin(int, int)), - this, SLOT(cacheInvalid(int, int))); + connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), + this, SLOT(cacheInvalid(sv_frame_t, sv_frame_t))); emit modelReplaced(); } @@ -233,11 +233,11 @@ *min = -50; *max = 50; - *deflt = lrintf(log10(m_initialGain) * 20.0);; + *deflt = int(lrint(log10(m_initialGain) * 20.0)); if (*deflt < *min) *deflt = *min; if (*deflt > *max) *deflt = *max; - val = lrintf(log10(m_gain) * 20.0); + val = int(lrint(log10(m_gain) * 20.0)); if (val < *min) val = *min; if (val > *max) val = *max; @@ -246,11 +246,11 @@ *min = -50; *max = 0; - *deflt = lrintf(AudioLevel::multiplier_to_dB(m_initialThreshold)); + *deflt = int(lrint(AudioLevel::multiplier_to_dB(m_initialThreshold))); if (*deflt < *min) *deflt = *min; if (*deflt > *max) *deflt = *max; - val = lrintf(AudioLevel::multiplier_to_dB(m_threshold)); + val = int(lrint(AudioLevel::multiplier_to_dB(m_threshold))); if (val < *min) val = *min; if (val > *max) val = *max; @@ -488,10 +488,10 @@ SpectrogramLayer::setProperty(const PropertyName &name, int value) { if (name == "Gain") { - setGain(pow(10, float(value)/20.0)); + setGain(float(pow(10, float(value)/20.0))); } else if (name == "Threshold") { if (value == -50) setThreshold(0.0); - else setThreshold(AudioLevel::dB_to_multiplier(value)); + else setThreshold(float(AudioLevel::dB_to_multiplier(value))); } else if (name == "Colour Rotation") { setColourRotation(value); } else if (name == "Colour") { @@ -583,13 +583,13 @@ } void -SpectrogramLayer::invalidateImageCaches(int startFrame, int endFrame) +SpectrogramLayer::invalidateImageCaches(sv_frame_t startFrame, sv_frame_t endFrame) { for (ViewImageCache::iterator i = m_imageCaches.begin(); i != m_imageCaches.end(); ++i) { //!!! when are views removed from the map? on setLayerDormant? - const View *v = i->first; + const LayerGeometryProvider *v = i->first; #ifdef DEBUG_SPECTROGRAM_REPAINT SVDEBUG << "SpectrogramLayer::invalidateImageCaches(" @@ -616,7 +616,7 @@ #endif if (x > 1) { i->second.validArea &= - QRect(0, 0, x-1, v->height()); + QRect(0, 0, x-1, v->getPaintHeight()); } else { i->second.validArea = QRect(); } @@ -629,12 +629,12 @@ } int x = v->getXForFrame(endFrame); #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "clipping from " << x+1 << " to " << v->width() + SVDEBUG << "clipping from " << x+1 << " to " << v->getPaintWidth() << endl; #endif - if (x < v->width()) { + if (x < v->getPaintWidth()) { i->second.validArea &= - QRect(x+1, 0, v->width()-(x+1), v->height()); + QRect(x+1, 0, v->getPaintWidth()-(x+1), v->getPaintHeight()); } else { i->second.validArea = QRect(); } @@ -963,7 +963,7 @@ } void -SpectrogramLayer::setLayerDormant(const View *v, bool dormant) +SpectrogramLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) { if (dormant) { @@ -978,12 +978,14 @@ Layer::setLayerDormant(v, true); + const View *view = v->getView(); + invalidateImageCaches(); - m_imageCaches.erase(v); - - if (m_fftModels.find(v) != m_fftModels.end()) { - - if (m_sliceableModel == m_fftModels[v].first) { + m_imageCaches.erase(view); + + if (m_fftModels.find(view) != m_fftModels.end()) { + + if (m_sliceableModel == m_fftModels[view].first) { bool replaced = false; for (ViewFFTMap::iterator i = m_fftModels.begin(); i != m_fftModels.end(); ++i) { @@ -996,11 +998,11 @@ if (!replaced) emit sliceableModelReplaced(m_sliceableModel, 0); } - delete m_fftModels[v].first; - m_fftModels.erase(v); - - delete m_peakCaches[v]; - m_peakCaches.erase(v); + delete m_fftModels[view].first; + m_fftModels.erase(view); + + delete m_peakCaches[view]; + m_peakCaches.erase(view); } } else { @@ -1021,7 +1023,7 @@ } void -SpectrogramLayer::cacheInvalid(int from, int to) +SpectrogramLayer::cacheInvalid(sv_frame_t from, sv_frame_t to) { #ifdef DEBUG_SPECTROGRAM_REPAINT SVDEBUG << "SpectrogramLayer::cacheInvalid(" << from << ", " << to << ")" << endl; @@ -1046,11 +1048,11 @@ i != m_fftModels.end(); ++i) { const FFTModel *model = i->second.first; - int lastFill = i->second.second; + sv_frame_t lastFill = i->second.second; if (model) { - int fill = model->getFillExtent(); + sv_frame_t fill = model->getFillExtent(); #ifdef DEBUG_SPECTROGRAM_REPAINT SVDEBUG << "SpectrogramLayer::fillTimerTimedOut: extent for " << model << ": " << fill << ", last " << lastFill << ", total " << m_model->getEndFrame() << endl; @@ -1119,7 +1121,7 @@ ColourMapper mapper(m_colourMap, 1.f, 255.f); for (int pixel = 1; pixel < 256; ++pixel) { - m_palette.setColour(pixel, mapper.map(pixel)); + m_palette.setColour((unsigned char)pixel, mapper.map(pixel)); } m_crosshairColour = mapper.getContrastingColour(); @@ -1142,23 +1144,23 @@ int target = pixel + distance; while (target < 1) target += 255; while (target > 255) target -= 255; - newPixels[target] = m_palette.getColour(pixel); + newPixels[target] = m_palette.getColour((unsigned char)pixel); } for (int pixel = 0; pixel < 256; ++pixel) { - m_palette.setColour(pixel, newPixels[pixel]); + m_palette.setColour((unsigned char)pixel, newPixels[pixel]); } m_drawBuffer = QImage(); } unsigned char -SpectrogramLayer::getDisplayValue(View *v, float input) const +SpectrogramLayer::getDisplayValue(LayerGeometryProvider *v, double input) const { int value; - float min = 0.f; - float max = 1.f; + double min = 0.0; + double max = 1.0; if (m_normalization == NormalizeVisibleArea) { min = m_viewMags[v].getMin(); @@ -1167,20 +1169,20 @@ if (m_colourScale == LinearColourScale //|| // m_colourScale == MeterColourScale) { ) { - max = 0.1f; + max = 0.1; } } - float thresh = -80.f; - - if (max == 0.f) max = 1.f; - if (max == min) min = max - 0.0001f; + double thresh = -80.0; + + if (max == 0.0) max = 1.0; + if (max == min) min = max - 0.0001; switch (m_colourScale) { default: case LinearColourScale: - value = int(((input - min) / (max - min)) * 255.f) + 1; + value = int(((input - min) / (max - min)) * 255.0) + 1; break; case MeterColourScale: @@ -1190,19 +1192,19 @@ case dBSquaredColourScale: input = ((input - min) * (input - min)) / ((max - min) * (max - min)); - if (input > 0.f) { - input = 10.f * log10f(input); + if (input > 0.0) { + input = 10.0 * log10(input); } else { input = thresh; } - if (min > 0.f) { - thresh = 10.f * log10f(min * min); - if (thresh < -80.f) thresh = -80.f; + if (min > 0.0) { + thresh = 10.0 * log10(min * min); + if (thresh < -80.0) thresh = -80.0; } input = (input - thresh) / (-thresh); - if (input < 0.f) input = 0.f; - if (input > 1.f) input = 1.f; - value = int(input * 255.f) + 1; + if (input < 0.0) input = 0.0; + if (input > 1.0) input = 1.0; + value = int(input * 255.0) + 1; break; case dBColourScale: @@ -1210,19 +1212,19 @@ //In any case, we need to have some indication of what the dB //scale is relative to. input = (input - min) / (max - min); - if (input > 0.f) { - input = 10.f * log10f(input); + if (input > 0.0) { + input = 10.0 * log10(input); } else { input = thresh; } - if (min > 0.f) { - thresh = 10.f * log10f(min); - if (thresh < -80.f) thresh = -80.f; + if (min > 0.0) { + thresh = 10.0 * log10(min); + if (thresh < -80.0) thresh = -80.0; } input = (input - thresh) / (-thresh); - if (input < 0.f) input = 0.f; - if (input > 1.f) input = 1.f; - value = int(input * 255.f) + 1; + if (input < 0.0) input = 0.0; + if (input > 1.0) input = 1.0; + value = int(input * 255.0) + 1; break; case PhaseColourScale: @@ -1232,14 +1234,14 @@ if (value > UCHAR_MAX) value = UCHAR_MAX; if (value < 0) value = 0; - return value; + return (unsigned char)value; } -float +double SpectrogramLayer::getEffectiveMinFrequency() const { - int sr = m_model->getSampleRate(); - float minf = float(sr) / m_fftSize; + sv_samplerate_t sr = m_model->getSampleRate(); + double minf = double(sr) / m_fftSize; if (m_minFrequency > 0.0) { int minbin = int((double(m_minFrequency) * m_fftSize) / sr + 0.01); @@ -1250,11 +1252,11 @@ return minf; } -float +double SpectrogramLayer::getEffectiveMaxFrequency() const { - int sr = m_model->getSampleRate(); - float maxf = float(sr) / 2; + sv_samplerate_t sr = m_model->getSampleRate(); + double maxf = double(sr) / 2; if (m_maxFrequency > 0.0) { int maxbin = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1); @@ -1266,16 +1268,16 @@ } bool -SpectrogramLayer::getYBinRange(View *v, int y, float &q0, float &q1) const +SpectrogramLayer::getYBinRange(LayerGeometryProvider *v, int y, double &q0, double &q1) const { Profiler profiler("SpectrogramLayer::getYBinRange"); - int h = v->height(); + int h = v->getPaintHeight(); if (y < 0 || y >= h) return false; - int sr = m_model->getSampleRate(); - float minf = getEffectiveMinFrequency(); - float maxf = getEffectiveMaxFrequency(); + sv_samplerate_t sr = m_model->getSampleRate(); + double minf = getEffectiveMinFrequency(); + double maxf = getEffectiveMaxFrequency(); bool logarithmic = (m_frequencyScale == LogFrequencyScale); @@ -1292,16 +1294,16 @@ } bool -SpectrogramLayer::getSmoothedYBinRange(View *v, int y, float &q0, float &q1) const +SpectrogramLayer::getSmoothedYBinRange(LayerGeometryProvider *v, int y, double &q0, double &q1) const { Profiler profiler("SpectrogramLayer::getSmoothedYBinRange"); - int h = v->height(); + int h = v->getPaintHeight(); if (y < 0 || y >= h) return false; - int sr = m_model->getSampleRate(); - float minf = getEffectiveMinFrequency(); - float maxf = getEffectiveMaxFrequency(); + sv_samplerate_t sr = m_model->getSampleRate(); + double minf = getEffectiveMinFrequency(); + double maxf = getEffectiveMaxFrequency(); bool logarithmic = (m_frequencyScale == LogFrequencyScale); @@ -1318,14 +1320,14 @@ } bool -SpectrogramLayer::getXBinRange(View *v, int x, float &s0, float &s1) const +SpectrogramLayer::getXBinRange(LayerGeometryProvider *v, int x, double &s0, double &s1) const { - int modelStart = m_model->getStartFrame(); - int modelEnd = m_model->getEndFrame(); + sv_frame_t modelStart = m_model->getStartFrame(); + sv_frame_t modelEnd = m_model->getEndFrame(); // Each pixel column covers an exact range of sample frames: - int f0 = v->getFrameForX(x) - modelStart; - int f1 = v->getFrameForX(x + 1) - modelStart - 1; + sv_frame_t f0 = v->getFrameForX(x) - modelStart; + sv_frame_t f1 = v->getFrameForX(x + 1) - modelStart - 1; if (f1 < int(modelStart) || f0 > int(modelEnd)) { return false; @@ -1335,16 +1337,16 @@ // range of spectrogram windows: int windowIncrement = getWindowIncrement(); - s0 = float(f0) / windowIncrement; - s1 = float(f1) / windowIncrement; + s0 = double(f0) / windowIncrement; + s1 = double(f1) / windowIncrement; return true; } bool -SpectrogramLayer::getXBinSourceRange(View *v, int x, RealTime &min, RealTime &max) const +SpectrogramLayer::getXBinSourceRange(LayerGeometryProvider *v, int x, RealTime &min, RealTime &max) const { - float s0 = 0, s1 = 0; + double s0 = 0, s1 = 0; if (!getXBinRange(v, x, s0, s1)) return false; int s0i = int(s0 + 0.001); @@ -1361,16 +1363,16 @@ } bool -SpectrogramLayer::getYBinSourceRange(View *v, int y, float &freqMin, float &freqMax) +SpectrogramLayer::getYBinSourceRange(LayerGeometryProvider *v, int y, double &freqMin, double &freqMax) const { - float q0 = 0, q1 = 0; + double q0 = 0, q1 = 0; if (!getYBinRange(v, y, q0, q1)) return false; int q0i = int(q0 + 0.001); int q1i = int(q1); - int sr = m_model->getSampleRate(); + sv_samplerate_t sr = m_model->getSampleRate(); for (int q = q0i; q <= q1i; ++q) { if (q == q0i) freqMin = (sr * q) / m_fftSize; @@ -1380,9 +1382,9 @@ } bool -SpectrogramLayer::getAdjustedYBinSourceRange(View *v, int x, int y, - float &freqMin, float &freqMax, - float &adjFreqMin, float &adjFreqMax) +SpectrogramLayer::getAdjustedYBinSourceRange(LayerGeometryProvider *v, int x, int y, + double &freqMin, double &freqMax, + double &adjFreqMin, double &adjFreqMax) const { if (!m_model || !m_model->isOK() || !m_model->isReady()) { @@ -1392,10 +1394,10 @@ FFTModel *fft = getFFTModel(v); if (!fft) return false; - float s0 = 0, s1 = 0; + double s0 = 0, s1 = 0; if (!getXBinRange(v, x, s0, s1)) return false; - float q0 = 0, q1 = 0; + double q0 = 0, q1 = 0; if (!getYBinRange(v, y, q0, q1)) return false; int s0i = int(s0 + 0.001); @@ -1404,7 +1406,7 @@ int q0i = int(q0 + 0.001); int q1i = int(q1); - int sr = m_model->getSampleRate(); + sv_samplerate_t sr = m_model->getSampleRate(); bool haveAdj = false; @@ -1417,15 +1419,15 @@ if (!fft->isColumnAvailable(s)) continue; - float binfreq = (float(sr) * q) / m_windowSize; + double binfreq = (double(sr) * q) / m_windowSize; if (q == q0i) freqMin = binfreq; if (q == q1i) freqMax = binfreq; if (peaksOnly && !fft->isLocalPeak(s, q)) continue; - if (!fft->isOverThreshold(s, q, m_threshold * (m_fftSize/2))) continue; - - float freq = binfreq; + if (!fft->isOverThreshold(s, q, float(m_threshold * double(m_fftSize)/2.0))) continue; + + double freq = binfreq; if (s < int(fft->getWidth()) - 1) { @@ -1447,18 +1449,18 @@ } bool -SpectrogramLayer::getXYBinSourceRange(View *v, int x, int y, - float &min, float &max, - float &phaseMin, float &phaseMax) const +SpectrogramLayer::getXYBinSourceRange(LayerGeometryProvider *v, int x, int y, + double &min, double &max, + double &phaseMin, double &phaseMax) const { if (!m_model || !m_model->isOK() || !m_model->isReady()) { return false; } - float q0 = 0, q1 = 0; + double q0 = 0, q1 = 0; if (!getYBinRange(v, y, q0, q1)) return false; - float s0 = 0, s1 = 0; + double s0 = 0, s1 = 0; if (!getXBinRange(v, x, s0, s1)) return false; int q0i = int(q0 + 0.001); @@ -1492,13 +1494,13 @@ if (!fft->isColumnAvailable(s)) continue; - float value; + double value; value = fft->getPhaseAt(s, q); if (!have || value < phaseMin) { phaseMin = value; } if (!have || value > phaseMax) { phaseMax = value; } - value = fft->getMagnitudeAt(s, q) / (m_fftSize/2); + value = fft->getMagnitudeAt(s, q) / (m_fftSize/2.0); if (!have || value < min) { min = value; } if (!have || value > max) { max = value; } @@ -1516,7 +1518,7 @@ } int -SpectrogramLayer::getZeroPadLevel(const View *v) const +SpectrogramLayer::getZeroPadLevel(const LayerGeometryProvider *v) const { //!!! tidy all this stuff @@ -1530,7 +1532,7 @@ if (m_frequencyScale == LogFrequencyScale) return 3; - int sr = m_model->getSampleRate(); + sv_samplerate_t sr = m_model->getSampleRate(); int maxbin = m_fftSize / 2; if (m_maxFrequency > 0) { @@ -1545,9 +1547,9 @@ if (minbin >= maxbin) minbin = maxbin - 1; } - float perPixel = - float(v->height()) / - float((maxbin - minbin) / (m_zeroPadLevel + 1)); + double perPixel = + double(v->getPaintHeight()) / + double((maxbin - minbin) / (m_zeroPadLevel + 1)); if (perPixel > 2.8) { return 3; // 4x oversampling @@ -1559,52 +1561,51 @@ } int -SpectrogramLayer::getFFTSize(const View *v) const +SpectrogramLayer::getFFTSize(const LayerGeometryProvider *v) const { return m_fftSize * (getZeroPadLevel(v) + 1); } FFTModel * -SpectrogramLayer::getFFTModel(const View *v) const +SpectrogramLayer::getFFTModel(const LayerGeometryProvider *v) const { if (!m_model) return 0; int fftSize = getFFTSize(v); - if (m_fftModels.find(v) != m_fftModels.end()) { - if (m_fftModels[v].first == 0) { + const View *view = v->getView(); + + if (m_fftModels.find(view) != m_fftModels.end()) { + if (m_fftModels[view].first == 0) { #ifdef DEBUG_SPECTROGRAM_REPAINT SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found null model" << endl; #endif return 0; } - if (m_fftModels[v].first->getHeight() != fftSize / 2 + 1) { + if (m_fftModels[view].first->getHeight() != fftSize / 2 + 1) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[v].first->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl; + SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a model with the wrong height (" << m_fftModels[view].first->getHeight() << ", wanted " << (fftSize / 2 + 1) << ")" << endl; #endif - delete m_fftModels[v].first; - m_fftModels.erase(v); - delete m_peakCaches[v]; - m_peakCaches.erase(v); + delete m_fftModels[view].first; + m_fftModels.erase(view); + delete m_peakCaches[view]; + m_peakCaches.erase(view); } else { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[v].first->getHeight() << endl; + SVDEBUG << "SpectrogramLayer::getFFTModel(" << v << "): Found a good model of height " << m_fftModels[view].first->getHeight() << endl; #endif - return m_fftModels[v].first; + return m_fftModels[view].first; } } - if (m_fftModels.find(v) == m_fftModels.end()) { + if (m_fftModels.find(view) == m_fftModels.end()) { FFTModel *model = new FFTModel(m_model, m_channel, m_windowType, m_windowSize, getWindowIncrement(), - fftSize, - true, // polar - StorageAdviser::SpeedCritical, - m_candidateFillStartFrame); + fftSize); if (!model->isOK()) { QMessageBox::critical @@ -1612,7 +1613,7 @@ tr("Failed to create the FFT model for this spectrogram.\n" "There may be insufficient memory or disc space to continue.")); delete model; - m_fftModels[v] = FFTFillPair(0, 0); + m_fftModels[view] = FFTFillPair(0, 0); return 0; } @@ -1624,10 +1625,8 @@ m_sliceableModel = model; } - m_fftModels[v] = FFTFillPair(model, 0); - - model->resume(); - + m_fftModels[view] = FFTFillPair(model, 0); + delete m_updateTimer; m_updateTimer = new QTimer((SpectrogramLayer *)this); connect(m_updateTimer, SIGNAL(timeout()), @@ -1635,18 +1634,19 @@ m_updateTimer->start(200); } - return m_fftModels[v].first; + return m_fftModels[view].first; } Dense3DModelPeakCache * -SpectrogramLayer::getPeakCache(const View *v) const +SpectrogramLayer::getPeakCache(const LayerGeometryProvider *v) const { - if (!m_peakCaches[v]) { + const View *view = v->getView(); + if (!m_peakCaches[view]) { FFTModel *f = getFFTModel(v); if (!f) return 0; - m_peakCaches[v] = new Dense3DModelPeakCache(f, 8); + m_peakCaches[view] = new Dense3DModelPeakCache(f, 8); } - return m_peakCaches[v]; + return m_peakCaches[view]; } const Model * @@ -1691,19 +1691,19 @@ } bool -SpectrogramLayer::updateViewMagnitudes(View *v) const +SpectrogramLayer::updateViewMagnitudes(LayerGeometryProvider *v) const { MagnitudeRange mag; - int x0 = 0, x1 = v->width(); - float s00 = 0, s01 = 0, s10 = 0, s11 = 0; + int x0 = 0, x1 = v->getPaintWidth(); + double s00 = 0, s01 = 0, s10 = 0, s11 = 0; if (!getXBinRange(v, x0, s00, s01)) { - s00 = s01 = m_model->getStartFrame() / getWindowIncrement(); + s00 = s01 = double(m_model->getStartFrame()) / getWindowIncrement(); } if (!getXBinRange(v, x1, s10, s11)) { - s10 = s11 = m_model->getEndFrame() / getWindowIncrement(); + s10 = s11 = double(m_model->getEndFrame()) / getWindowIncrement(); } int s0 = int(std::min(s00, s10) + 0.0001); @@ -1739,7 +1739,7 @@ } void -SpectrogramLayer::paint(View *v, QPainter &paint, QRect rect) const +SpectrogramLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { // What a lovely, old-fashioned function this is. // It's practically FORTRAN 77 in its clarity and linearity. @@ -1752,7 +1752,7 @@ cerr << "rect is " << rect.x() << "," << rect.y() << " " << rect.width() << "x" << rect.height() << endl; #endif - int startFrame = v->getStartFrame(); + sv_frame_t startFrame = v->getStartFrame(); if (startFrame < 0) m_candidateFillStartFrame = 0; else m_candidateFillStartFrame = startFrame; @@ -1779,7 +1779,10 @@ return; } */ - ImageCache &cache = m_imageCaches[v]; + + const View *view = v->getView(); + + ImageCache &cache = m_imageCaches[view]; #ifdef DEBUG_SPECTROGRAM_REPAINT SVDEBUG << "SpectrogramLayer::paint(): image cache valid area " << cache. @@ -1795,14 +1798,14 @@ int zoomLevel = v->getZoomLevel(); int x0 = 0; - int x1 = v->width(); + int x1 = v->getPaintWidth(); bool recreateWholeImageCache = true; x0 = rect.left(); x1 = rect.right() + 1; /* - float xPixelRatio = float(fft->getResolution()) / float(zoomLevel); + double xPixelRatio = double(fft->getResolution()) / double(zoomLevel); cerr << "xPixelRatio = " << xPixelRatio << endl; if (xPixelRatio < 1.f) xPixelRatio = 1.f; */ @@ -1812,8 +1815,8 @@ int ch = cache.image.height(); if (int(cache.zoomLevel) == zoomLevel && - cw == v->width() && - ch == v->height()) { + cw == v->getPaintWidth() && + ch == v->getPaintHeight()) { if (v->getXForFrame(cache.startFrame) == v->getXForFrame(startFrame) && @@ -1853,7 +1856,7 @@ int dxp = dx; if (dxp < 0) dxp = -dxp; - int copy = (cw - dxp) * sizeof(QRgb); + size_t copy = (cw - dxp) * sizeof(QRgb); for (int y = 0; y < ch; ++y) { QRgb *line = (QRgb *)cache.image.scanLine(y); if (dx < 0) { @@ -1919,13 +1922,13 @@ cerr << "(cache zoomLevel " << cache.zoomLevel << " != " << zoomLevel << ")" << endl; } - if (cw != v->width()) { + if (cw != v->getPaintWidth()) { cerr << "(cache width " << cw - << " != " << v->width(); + << " != " << v->getPaintWidth(); } - if (ch != v->height()) { + if (ch != v->getPaintHeight()) { cerr << "(cache height " << ch - << " != " << v->height(); + << " != " << v->getPaintHeight(); } #endif cache.validArea = QRect(); @@ -1949,7 +1952,7 @@ if (recreateWholeImageCache) { x0 = 0; - x1 = v->width(); + x1 = v->getPaintWidth(); } struct timeval tv; @@ -1993,7 +1996,7 @@ // is coherent without having to worry about vertical matching of // required and valid areas as well as horizontal. - int h = v->height(); + int h = v->getPaintHeight(); if (cache.validArea.width() > 0) { @@ -2078,7 +2081,7 @@ cerr << "x0 " << x0 << ", x1 " << x1 << ", w " << w << ", h " << h << endl; #endif - int sr = m_model->getSampleRate(); + sv_samplerate_t sr = m_model->getSampleRate(); // Set minFreq and maxFreq to the frequency extents of the possibly // zero-padded visible bin range, and displayMinFreq and displayMaxFreq @@ -2109,11 +2112,11 @@ minbin = minbin * zpl; maxbin = (maxbin + 1) * zpl - 1; - float minFreq = (float(minbin) * sr) / fftSize; - float maxFreq = (float(maxbin) * sr) / fftSize; - - float displayMinFreq = minFreq; - float displayMaxFreq = maxFreq; + double minFreq = (double(minbin) * sr) / fftSize; + double maxFreq = (double(maxbin) * sr) / fftSize; + + double displayMinFreq = minFreq; + double displayMaxFreq = maxFreq; if (fftSize != m_fftSize) { displayMinFreq = getEffectiveMinFrequency(); @@ -2126,10 +2129,10 @@ bool logarithmic = (m_frequencyScale == LogFrequencyScale); /* - float yforbin[maxbin - minbin + 1]; + double yforbin[maxbin - minbin + 1]; for (int q = minbin; q <= maxbin; ++q) { - float f0 = (float(q) * sr) / fftSize; + double f0 = (double(q) * sr) / fftSize; yforbin[q - minbin] = v->getYForFrequency(f0, displayMinFreq, displayMaxFreq, logarithmic); @@ -2139,7 +2142,7 @@ bool overallMagChanged = false; #ifdef DEBUG_SPECTROGRAM_REPAINT - cerr << ((float(v->getFrameForX(1) - v->getFrameForX(0))) / increment) << " bin(s) per pixel" << endl; + cerr << ((double(v->getFrameForX(1) - v->getFrameForX(0))) / increment) << " bin(s) per pixel" << endl; #endif if (w == 0) { @@ -2168,22 +2171,22 @@ bool bufferBinResolution = false; if (increment > zoomLevel) bufferBinResolution = true; - int leftBoundaryFrame = -1, leftCropFrame = -1; - int rightBoundaryFrame = -1, rightCropFrame = -1; + sv_frame_t leftBoundaryFrame = -1, leftCropFrame = -1; + sv_frame_t rightBoundaryFrame = -1, rightCropFrame = -1; int bufwid; if (bufferBinResolution) { for (int x = x0; ; --x) { - int f = v->getFrameForX(x); + sv_frame_t f = v->getFrameForX(x); if ((f / increment) * increment == f) { if (leftCropFrame == -1) leftCropFrame = f; else if (x < x0 - 2) { leftBoundaryFrame = f; break; } } } for (int x = x0 + w; ; ++x) { - int f = v->getFrameForX(x); + sv_frame_t f = v->getFrameForX(x); if ((f / increment) * increment == f) { if (rightCropFrame == -1) rightCropFrame = f; else if (x > x0 + w + 2) { rightBoundaryFrame = f; break; } @@ -2194,32 +2197,27 @@ cerr << "Right: crop: " << rightCropFrame << " (bin " << rightCropFrame/increment << "); boundary: " << rightBoundaryFrame << " (bin " << rightBoundaryFrame/increment << ")" << endl; #endif - bufwid = (rightBoundaryFrame - leftBoundaryFrame) / increment; + bufwid = int((rightBoundaryFrame - leftBoundaryFrame) / increment); } else { bufwid = w; } -#ifdef __GNUC__ - int binforx[bufwid]; - float binfory[h]; -#else - int *binforx = (int *)alloca(bufwid * sizeof(int)); - float *binfory = (float *)alloca(h * sizeof(float)); -#endif - + vector<int> binforx(bufwid); + vector<double> binfory(h); + bool usePeaksCache = false; if (bufferBinResolution) { for (int x = 0; x < bufwid; ++x) { - binforx[x] = (leftBoundaryFrame / increment) + x; + binforx[x] = int(leftBoundaryFrame / increment) + x; // cerr << "binforx[" << x << "] = " << binforx[x] << endl; } m_drawBuffer = QImage(bufwid, h, QImage::Format_Indexed8); } else { for (int x = 0; x < bufwid; ++x) { - float s0 = 0, s1 = 0; + double s0 = 0, s1 = 0; if (getXBinRange(v, x + x0, s0, s1)) { binforx[x] = int(s0 + 0.0001); } else { @@ -2235,7 +2233,8 @@ // No longer exists in Qt5: m_drawBuffer.setNumColors(256); for (int pixel = 0; pixel < 256; ++pixel) { - m_drawBuffer.setColor(pixel, m_palette.getColour(pixel).rgb()); + m_drawBuffer.setColor((unsigned char)pixel, + m_palette.getColour((unsigned char)pixel).rgb()); } m_drawBuffer.fill(0); @@ -2243,7 +2242,7 @@ if (m_binDisplay != PeakFrequencies) { for (int y = 0; y < h; ++y) { - float q0 = 0, q1 = 0; + double q0 = 0, q1 = 0; if (!getSmoothedYBinRange(v, h-y-1, q0, q1)) { binfory[y] = -1; } else { @@ -2304,10 +2303,10 @@ if (recreateWholeImageCache) { #ifdef DEBUG_SPECTROGRAM_REPAINT - SVDEBUG << "Recreating image cache: width = " << v->width() + SVDEBUG << "Recreating image cache: width = " << v->getPaintWidth() << ", height = " << h << endl; #endif - cache.image = QImage(v->width(), h, QImage::Format_ARGB32_Premultiplied); + cache.image = QImage(v->getPaintWidth(), h, QImage::Format_ARGB32_Premultiplied); } if (w > 0) { @@ -2383,7 +2382,7 @@ SVDEBUG << "SpectrogramLayer::paint() updating left (0, " << cache.validArea.x() << ")" << endl; #endif - v->update(0, 0, cache.validArea.x(), h); + v->getView()->update(0, 0, cache.validArea.x(), h); } if (cache.validArea.x() + cache.validArea.width() < @@ -2396,7 +2395,7 @@ cache.validArea.width()) << ")" << endl; #endif - v->update(cache.validArea.x() + cache.validArea.width(), + v->getView()->update(cache.validArea.x() + cache.validArea.width(), 0, cache.image.width() - (cache.validArea.x() + cache.validArea.width()), @@ -2406,7 +2405,7 @@ // overallMagChanged cerr << "\noverallMagChanged - updating all\n" << endl; cache.validArea = QRect(); - v->update(); + v->getView()->update(); } } @@ -2421,19 +2420,17 @@ (void)gettimeofday(&tv, 0); m_lastPaintTime = RealTime::fromTimeval(tv) - mainPaintStart; } - -//!!! if (fftSuspended) fft->resume(); } bool -SpectrogramLayer::paintDrawBufferPeakFrequencies(View *v, +SpectrogramLayer::paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h, - int *binforx, + const vector<int> &binforx, int minbin, int maxbin, - float displayMinFreq, - float displayMaxFreq, + double displayMinFreq, + double displayMaxFreq, bool logarithmic, MagnitudeRange &overallMag, bool &overallMagChanged) const @@ -2494,10 +2491,10 @@ fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); } else if (m_normalization == NormalizeHybrid) { fft->getNormalizedMagnitudesAt(sx, values, minbin, maxbin - minbin + 1); - float max = fft->getMaximumMagnitudeAt(sx); + double max = fft->getMaximumMagnitudeAt(sx); if (max > 0.f) { for (int i = minbin; i <= maxbin; ++i) { - values[i - minbin] *= log10(max); + values[i - minbin] = float(values[i - minbin] * log10(max)); } } } else { @@ -2510,22 +2507,22 @@ pi != peakfreqs.end(); ++pi) { int bin = pi->first; - int freq = pi->second; + double freq = pi->second; if (bin < minbin) continue; if (bin > maxbin) break; - float value = values[bin - minbin]; + double value = values[bin - minbin]; if (m_colourScale != PhaseColourScale) { if (m_normalization != NormalizeColumns) { - value /= (m_fftSize/2.f); + value /= (m_fftSize/2.0); } - mag.sample(value); + mag.sample(float(value)); value *= m_gain; } - float y = v->getYForFrequency + double y = v->getYForFrequency (freq, displayMinFreq, displayMaxFreq, logarithmic); int iy = int(y + 0.5); @@ -2554,11 +2551,11 @@ } bool -SpectrogramLayer::paintDrawBuffer(View *v, +SpectrogramLayer::paintDrawBuffer(LayerGeometryProvider *v, int w, int h, - int *binforx, - float *binfory, + const vector<int> &binforx, + const vector<double> &binfory, bool usePeaksCache, MagnitudeRange &overallMag, bool &overallMagChanged) const @@ -2566,7 +2563,7 @@ Profiler profiler("SpectrogramLayer::paintDrawBuffer"); int minbin = int(binfory[0] + 0.0001); - int maxbin = binfory[h-1]; + int maxbin = int(binfory[h-1]); #ifdef DEBUG_SPECTROGRAM_REPAINT cerr << "minbin " << minbin << ", maxbin " << maxbin << "; w " << w << ", h " << h << endl; @@ -2661,7 +2658,7 @@ fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); } else if (m_normalization == NormalizeHybrid) { fft->getNormalizedMagnitudesAt(sx, autoarray, minbin, maxbin - minbin + 1); - float max = fft->getMaximumMagnitudeAt(sx); + double max = fft->getMaximumMagnitudeAt(sx); float scale = log10(max + 1.f); cout << "sx = " << sx << ", max = " << max << ", log10(max) = " << log10(max) << ", scale = " << scale << endl; for (int i = minbin; i <= maxbin; ++i) { @@ -2688,46 +2685,46 @@ for (int y = 0; y < h; ++y) { - float sy0 = binfory[y]; - float sy1 = sy0 + 1; + double sy0 = binfory[y]; + double sy1 = sy0 + 1; if (y+1 < h) sy1 = binfory[y+1]; - float value = 0.f; - - if (interpolate && fabsf(sy1 - sy0) < 1.f) { - - float centre = (sy0 + sy1) / 2; - float dist = (centre - 0.5) - lrintf(centre - 0.5); + double value = 0.0; + + if (interpolate && fabs(sy1 - sy0) < 1.0) { + + double centre = (sy0 + sy1) / 2; + double dist = (centre - 0.5) - rint(centre - 0.5); int bin = int(centre); int other = (dist < 0 ? (bin-1) : (bin+1)); if (bin < minbin) bin = minbin; if (bin > maxbin) bin = maxbin; if (other < minbin || other > maxbin) other = bin; - float prop = 1.f - fabsf(dist); - - float v0 = values[bin - minbin]; - float v1 = values[other - minbin]; + double prop = 1.0 - fabs(dist); + + double v0 = values[bin - minbin]; + double v1 = values[other - minbin]; if (m_binDisplay == PeakBins) { if (bin == minbin || bin == maxbin || v0 < values[bin-minbin-1] || - v0 < values[bin-minbin+1]) v0 = 0.f; + v0 < values[bin-minbin+1]) v0 = 0.0; if (other == minbin || other == maxbin || v1 < values[other-minbin-1] || - v1 < values[other-minbin+1]) v1 = 0.f; + v1 < values[other-minbin+1]) v1 = 0.0; } - if (v0 == 0.f && v1 == 0.f) continue; - value = prop * v0 + (1.f - prop) * v1; + if (v0 == 0.0 && v1 == 0.0) continue; + value = prop * v0 + (1.0 - prop) * v1; if (m_colourScale != PhaseColourScale) { if (m_normalization != NormalizeColumns && m_normalization != NormalizeHybrid) { - value /= (m_fftSize/2.f); + value /= (m_fftSize/2.0); } - mag.sample(value); + mag.sample(float(value)); value *= m_gain; } - peaks[y] = value; + peaks[y] = float(value); } else { @@ -2747,13 +2744,15 @@ if (m_colourScale != PhaseColourScale) { if (m_normalization != NormalizeColumns && m_normalization != NormalizeHybrid) { - value /= (m_fftSize/2.f); + value /= (m_fftSize/2.0); } - mag.sample(value); + mag.sample(float(value)); value *= m_gain; } - if (value > peaks[y]) peaks[y] = value; //!!! not right for phase! + if (value > peaks[y]) { + peaks[y] = float(value); //!!! not right for phase! + } } } } @@ -2775,7 +2774,7 @@ for (int y = 0; y < h; ++y) { - float peak = peaks[y]; + double peak = peaks[y]; if (m_colourScale != PhaseColourScale && (m_normalization == NormalizeColumns || @@ -2797,7 +2796,7 @@ } void -SpectrogramLayer::illuminateLocalFeatures(View *v, QPainter &paint) const +SpectrogramLayer::illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &paint) const { Profiler profiler("SpectrogramLayer::illuminateLocalFeatures"); @@ -2809,8 +2808,8 @@ // cerr << "SpectrogramLayer: illuminateLocalFeatures(" // << localPos.x() << "," << localPos.y() << ")" << endl; - float s0, s1; - float f0, f1; + double s0, s1; + double f0, f1; if (getXBinRange(v, localPos.x(), s0, s1) && getYBinSourceRange(v, localPos.y(), f0, f1)) { @@ -2835,8 +2834,8 @@ } } -float -SpectrogramLayer::getYForFrequency(const View *v, float frequency) const +double +SpectrogramLayer::getYForFrequency(const LayerGeometryProvider *v, double frequency) const { return v->getYForFrequency(frequency, getEffectiveMinFrequency(), @@ -2844,8 +2843,8 @@ m_frequencyScale == LogFrequencyScale); } -float -SpectrogramLayer::getFrequencyForY(const View *v, int y) const +double +SpectrogramLayer::getFrequencyForY(const LayerGeometryProvider *v, int y) const { return v->getFrequencyForY(y, getEffectiveMinFrequency(), @@ -2854,12 +2853,15 @@ } int -SpectrogramLayer::getCompletion(View *v) const +SpectrogramLayer::getCompletion(LayerGeometryProvider *v) const { if (m_updateTimer == 0) return 100; - if (m_fftModels.find(v) == m_fftModels.end()) return 100; - - int completion = m_fftModels[v].first->getCompletion(); + + const View *view = v->getView(); + + if (m_fftModels.find(view) == m_fftModels.end()) return 100; + + int completion = m_fftModels[view].first->getCompletion(); #ifdef DEBUG_SPECTROGRAM_REPAINT SVDEBUG << "SpectrogramLayer::getCompletion: completion = " << completion << endl; #endif @@ -2867,21 +2869,22 @@ } QString -SpectrogramLayer::getError(View *v) const +SpectrogramLayer::getError(LayerGeometryProvider *v) const { - if (m_fftModels.find(v) == m_fftModels.end()) return ""; - return m_fftModels[v].first->getError(); + const View *view = v->getView(); + if (m_fftModels.find(view) == m_fftModels.end()) return ""; + return m_fftModels[view].first->getError(); } bool -SpectrogramLayer::getValueExtents(float &min, float &max, +SpectrogramLayer::getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const { if (!m_model) return false; - int sr = m_model->getSampleRate(); - min = float(sr) / m_fftSize; - max = float(sr) / 2; + sv_samplerate_t sr = m_model->getSampleRate(); + min = double(sr) / m_fftSize; + max = double(sr) / 2; logarithmic = (m_frequencyScale == LogFrequencyScale); unit = "Hz"; @@ -2889,7 +2892,7 @@ } bool -SpectrogramLayer::getDisplayExtents(float &min, float &max) const +SpectrogramLayer::getDisplayExtents(double &min, double &max) const { min = getEffectiveMinFrequency(); max = getEffectiveMaxFrequency(); @@ -2899,17 +2902,17 @@ } bool -SpectrogramLayer::setDisplayExtents(float min, float max) +SpectrogramLayer::setDisplayExtents(double min, double max) { if (!m_model) return false; // SVDEBUG << "SpectrogramLayer::setDisplayExtents: " << min << "->" << max << endl; if (min < 0) min = 0; - if (max > m_model->getSampleRate()/2.f) max = m_model->getSampleRate()/2.f; + if (max > m_model->getSampleRate()/2.0) max = m_model->getSampleRate()/2.0; - int minf = lrintf(min); - int maxf = lrintf(max); + int minf = int(lrint(min)); + int maxf = int(lrint(max)); if (m_minFrequency == minf && m_maxFrequency == maxf) return true; @@ -2931,8 +2934,8 @@ } bool -SpectrogramLayer::getYScaleValue(const View *v, int y, - float &value, QString &unit) const +SpectrogramLayer::getYScaleValue(const LayerGeometryProvider *v, int y, + double &value, QString &unit) const { value = getFrequencyForY(v, y); unit = "Hz"; @@ -2940,13 +2943,14 @@ } bool -SpectrogramLayer::snapToFeatureFrame(View *, int &frame, +SpectrogramLayer::snapToFeatureFrame(LayerGeometryProvider *, + sv_frame_t &frame, int &resolution, SnapType snap) const { resolution = getWindowIncrement(); - int left = (frame / resolution) * resolution; - int right = left + resolution; + sv_frame_t left = (frame / resolution) * resolution; + sv_frame_t right = left + resolution; switch (snap) { case SnapLeft: frame = left; break; @@ -2962,12 +2966,13 @@ } void -SpectrogramLayer::measureDoubleClick(View *v, QMouseEvent *e) +SpectrogramLayer::measureDoubleClick(LayerGeometryProvider *v, QMouseEvent *e) { - ImageCache &cache = m_imageCaches[v]; + const View *view = v->getView(); + ImageCache &cache = m_imageCaches[view]; cerr << "cache width: " << cache.image.width() << ", height: " - << cache.image.height() << endl; + << cache.image.height() << endl; QImage image = cache.image; @@ -2982,11 +2987,11 @@ } bool -SpectrogramLayer::getCrosshairExtents(View *v, QPainter &paint, +SpectrogramLayer::getCrosshairExtents(LayerGeometryProvider *v, QPainter &paint, QPoint cursorPos, std::vector<QRect> &extents) const { - QRect vertical(cursorPos.x() - 12, 0, 12, v->height()); + QRect vertical(cursorPos.x() - 12, 0, 12, v->getPaintHeight()); extents.push_back(vertical); QRect horizontal(0, cursorPos.y(), cursorPos.x(), 1); @@ -3005,14 +3010,14 @@ extents.push_back(pitch); QRect rt(cursorPos.x(), - v->height() - paint.fontMetrics().height() - 2, + v->getPaintHeight() - paint.fontMetrics().height() - 2, paint.fontMetrics().width("1234.567 s"), paint.fontMetrics().height()); extents.push_back(rt); int w(paint.fontMetrics().width("1234567890") + 2); QRect frame(cursorPos.x() - w - 2, - v->height() - paint.fontMetrics().height() - 2, + v->getPaintHeight() - paint.fontMetrics().height() - 2, w, paint.fontMetrics().height()); extents.push_back(frame); @@ -3021,7 +3026,7 @@ } void -SpectrogramLayer::paintCrosshairs(View *v, QPainter &paint, +SpectrogramLayer::paintCrosshairs(LayerGeometryProvider *v, QPainter &paint, QPoint cursorPos) const { paint.save(); @@ -3036,9 +3041,9 @@ paint.setPen(m_crosshairColour); paint.drawLine(0, cursorPos.y(), cursorPos.x() - 1, cursorPos.y()); - paint.drawLine(cursorPos.x(), 0, cursorPos.x(), v->height()); + paint.drawLine(cursorPos.x(), 0, cursorPos.x(), v->getPaintHeight()); - float fundamental = getFrequencyForY(v, cursorPos.y()); + double fundamental = getFrequencyForY(v, cursorPos.y()); v->drawVisibleText(paint, sw + 2, @@ -3055,18 +3060,18 @@ View::OutlinedText); } - int frame = v->getFrameForX(cursorPos.x()); + sv_frame_t frame = v->getFrameForX(cursorPos.x()); RealTime rt = RealTime::frame2RealTime(frame, m_model->getSampleRate()); QString rtLabel = QString("%1 s").arg(rt.toText(true).c_str()); QString frameLabel = QString("%1").arg(frame); v->drawVisibleText(paint, cursorPos.x() - paint.fontMetrics().width(frameLabel) - 2, - v->height() - 2, + v->getPaintHeight() - 2, frameLabel, View::OutlinedText); v->drawVisibleText(paint, cursorPos.x() + 2, - v->height() - 2, + v->getPaintHeight() - 2, rtLabel, View::OutlinedText); @@ -3074,8 +3079,8 @@ while (harmonic < 100) { - float hy = lrintf(getYForFrequency(v, fundamental * harmonic)); - if (hy < 0 || hy > v->height()) break; + int hy = int(lrint(getYForFrequency(v, fundamental * harmonic))); + if (hy < 0 || hy > v->getPaintHeight()) break; int len = 7; @@ -3088,9 +3093,9 @@ } paint.drawLine(cursorPos.x() - len, - int(hy), + hy, cursorPos.x(), - int(hy)); + hy); ++harmonic; } @@ -3099,17 +3104,17 @@ } QString -SpectrogramLayer::getFeatureDescription(View *v, QPoint &pos) const +SpectrogramLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); int y = pos.y(); if (!m_model || !m_model->isOK()) return ""; - float magMin = 0, magMax = 0; - float phaseMin = 0, phaseMax = 0; - float freqMin = 0, freqMax = 0; - float adjFreqMin = 0, adjFreqMax = 0; + double magMin = 0, magMax = 0; + double phaseMin = 0, phaseMax = 0; + double freqMin = 0, freqMax = 0; + double adjFreqMin = 0, adjFreqMax = 0; QString pitchMin, pitchMax; RealTime rtMin, rtMax; @@ -3181,21 +3186,21 @@ } if (haveValues) { - float dbMin = AudioLevel::multiplier_to_dB(magMin); - float dbMax = AudioLevel::multiplier_to_dB(magMax); + double dbMin = AudioLevel::multiplier_to_dB(magMin); + double dbMax = AudioLevel::multiplier_to_dB(magMax); QString dbMinString; QString dbMaxString; if (dbMin == AudioLevel::DB_FLOOR) { dbMinString = tr("-Inf"); } else { - dbMinString = QString("%1").arg(lrintf(dbMin)); + dbMinString = QString("%1").arg(lrint(dbMin)); } if (dbMax == AudioLevel::DB_FLOOR) { dbMaxString = tr("-Inf"); } else { - dbMaxString = QString("%1").arg(lrintf(dbMax)); + dbMaxString = QString("%1").arg(lrint(dbMax)); } - if (lrintf(dbMin) != lrintf(dbMax)) { + if (lrint(dbMin) != lrint(dbMax)) { text += tr("dB:\t%1 - %2").arg(dbMinString).arg(dbMaxString); } else { text += tr("dB:\t%1").arg(dbMinString); @@ -3221,7 +3226,7 @@ } int -SpectrogramLayer::getVerticalScaleWidth(View *, bool detailed, QPainter &paint) const +SpectrogramLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool detailed, QPainter &paint) const { if (!m_model || !m_model->isOK()) return 0; @@ -3242,7 +3247,7 @@ } void -SpectrogramLayer::paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const +SpectrogramLayer::paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) { return; @@ -3258,7 +3263,7 @@ int pkw = (m_frequencyScale == LogFrequencyScale ? 10 : 0); int bins = m_fftSize / 2; - int sr = m_model->getSampleRate(); + sv_samplerate_t sr = m_model->getSampleRate(); if (m_maxFrequency > 0) { bins = int((double(m_maxFrequency) * m_fftSize) / sr + 0.1); @@ -3284,17 +3289,17 @@ paint.drawRect(4 + cw - cbw, textHeight * topLines + 4, cbw - 1, ch + 1); QString top, bottom; - float min = m_viewMags[v].getMin(); - float max = m_viewMags[v].getMax(); - - float dBmin = AudioLevel::multiplier_to_dB(min); - float dBmax = AudioLevel::multiplier_to_dB(max); + double min = m_viewMags[v].getMin(); + double max = m_viewMags[v].getMax(); + + double dBmin = AudioLevel::multiplier_to_dB(min); + double dBmax = AudioLevel::multiplier_to_dB(max); if (dBmax < -60.f) dBmax = -60.f; - else top = QString("%1").arg(lrintf(dBmax)); + else top = QString("%1").arg(lrint(dBmax)); if (dBmin < dBmax - 60.f) dBmin = dBmax - 60.f; - bottom = QString("%1").arg(lrintf(dBmin)); + bottom = QString("%1").arg(lrint(dBmin)); //!!! & phase etc @@ -3318,13 +3323,13 @@ for (int i = 0; i < ch; ++i) { - float dBval = dBmin + (((dBmax - dBmin) * i) / (ch - 1)); + double dBval = dBmin + (((dBmax - dBmin) * i) / (ch - 1)); int idb = int(dBval); - float value = AudioLevel::dB_to_multiplier(dBval); + double value = AudioLevel::dB_to_multiplier(dBval); int colour = getDisplayValue(v, value * m_gain); - paint.setPen(m_palette.getColour(colour)); + paint.setPen(m_palette.getColour((unsigned char)colour)); int y = textHeight * topLines + 4 + ch - i; @@ -3356,10 +3361,10 @@ int bin = -1; - for (int y = 0; y < v->height(); ++y) { - - float q0, q1; - if (!getYBinRange(v, v->height() - y, q0, q1)) continue; + for (int y = 0; y < v->getPaintHeight(); ++y) { + + double q0, q1; + if (!getYBinRange(v, v->getPaintHeight() - y, q0, q1)) continue; int vy; @@ -3370,7 +3375,7 @@ continue; } - int freq = (sr * bin) / m_fftSize; + int freq = int((sr * bin) / m_fftSize); if (py >= 0 && (vy - py) < textHeight - 1) { if (m_frequencyScale == LinearFrequencyScale) { @@ -3406,18 +3411,18 @@ class SpectrogramRangeMapper : public RangeMapper { public: - SpectrogramRangeMapper(int sr, int /* fftsize */) : - m_dist(float(sr) / 2), - m_s2(sqrtf(sqrtf(2))) { } + SpectrogramRangeMapper(sv_samplerate_t sr, int /* fftsize */) : + m_dist(sr / 2), + m_s2(sqrt(sqrt(2))) { } ~SpectrogramRangeMapper() { } - virtual int getPositionForValue(float value) const { - - float dist = m_dist; + virtual int getPositionForValue(double value) const { + + double dist = m_dist; int n = 0; - while (dist > (value + 0.00001) && dist > 0.1f) { + while (dist > (value + 0.00001) && dist > 0.1) { dist /= m_s2; ++n; } @@ -3425,19 +3430,19 @@ return n; } - virtual int getPositionForValueUnclamped(float value) const { + virtual int getPositionForValueUnclamped(double value) const { // We don't really support this return getPositionForValue(value); } - virtual float getValueForPosition(int position) const { + virtual double getValueForPosition(int position) const { // Vertical zoom step 0 shows the entire range from DC -> // Nyquist frequency. Step 1 shows 2^(1/4) of the range of // step 0, and so on until the visible range is smaller than // the frequency step between bins at the current fft size. - float dist = m_dist; + double dist = m_dist; int n = 0; while (n < position) { @@ -3448,7 +3453,7 @@ return dist; } - virtual float getValueForPositionUnclamped(int position) const { + virtual double getValueForPositionUnclamped(int position) const { // We don't really support this return getValueForPosition(position); } @@ -3456,8 +3461,8 @@ virtual QString getUnit() const { return "Hz"; } protected: - float m_dist; - float m_s2; + double m_dist; + double m_s2; }; int @@ -3465,16 +3470,16 @@ { if (!m_model) return 0; - int sr = m_model->getSampleRate(); + sv_samplerate_t sr = m_model->getSampleRate(); SpectrogramRangeMapper mapper(sr, m_fftSize); -// int maxStep = mapper.getPositionForValue((float(sr) / m_fftSize) + 0.001); +// int maxStep = mapper.getPositionForValue((double(sr) / m_fftSize) + 0.001); int maxStep = mapper.getPositionForValue(0); - int minStep = mapper.getPositionForValue(float(sr) / 2); + int minStep = mapper.getPositionForValue(double(sr) / 2); int initialMax = m_initialMaxFrequency; - if (initialMax == 0) initialMax = sr / 2; + if (initialMax == 0) initialMax = int(sr / 2); defaultStep = mapper.getPositionForValue(initialMax) - minStep; @@ -3488,7 +3493,7 @@ { if (!m_model) return 0; - float dmin, dmax; + double dmin, dmax; getDisplayExtents(dmin, dmax); SpectrogramRangeMapper mapper(m_model->getSampleRate(), m_fftSize); @@ -3502,16 +3507,16 @@ { if (!m_model) return; - float dmin = m_minFrequency, dmax = m_maxFrequency; + double dmin = m_minFrequency, dmax = m_maxFrequency; // getDisplayExtents(dmin, dmax); // cerr << "current range " << dmin << " -> " << dmax << ", range " << dmax-dmin << ", mid " << (dmax + dmin)/2 << endl; - int sr = m_model->getSampleRate(); + sv_samplerate_t sr = m_model->getSampleRate(); SpectrogramRangeMapper mapper(sr, m_fftSize); - float newdist = mapper.getValueForPosition(step); - - float newmin, newmax; + double newdist = mapper.getValueForPosition(step); + + double newmin, newmax; if (m_frequencyScale == LogFrequencyScale) { @@ -3536,20 +3541,20 @@ // = dmin.dmax // so newmax = (newdist + sqrtf(newdist^2 + 4dmin.dmax)) / 2 - newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2; + newmax = (newdist + sqrt(newdist*newdist + 4*dmin*dmax)) / 2; newmin = newmax - newdist; // cerr << "newmin = " << newmin << ", newmax = " << newmax << endl; } else { - float dmid = (dmax + dmin) / 2; + double dmid = (dmax + dmin) / 2; newmin = dmid - newdist / 2; newmax = dmid + newdist / 2; } - float mmin, mmax; + double mmin, mmax; mmin = 0; - mmax = float(sr) / 2; + mmax = double(sr) / 2; if (newmin < mmin) { newmax += (mmin - newmin); @@ -3561,8 +3566,8 @@ // SVDEBUG << "SpectrogramLayer::setVerticalZoomStep: " << step << ": " << newmin << " -> " << newmax << " (range " << newdist << ")" << endl; - setMinFrequency(lrintf(newmin)); - setMaxFrequency(lrintf(newmax)); + setMinFrequency(int(lrint(newmin))); + setMaxFrequency(int(lrint(newmax))); } RangeMapper * @@ -3573,13 +3578,13 @@ } void -SpectrogramLayer::updateMeasureRectYCoords(View *v, const MeasureRect &r) const +SpectrogramLayer::updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const { int y0 = 0; - if (r.startY > 0.0) y0 = getYForFrequency(v, r.startY); + if (r.startY > 0.0) y0 = int(getYForFrequency(v, r.startY)); int y1 = y0; - if (r.endY > 0.0) y1 = getYForFrequency(v, r.endY); + if (r.endY > 0.0) y1 = int(getYForFrequency(v, r.endY)); // SVDEBUG << "SpectrogramLayer::updateMeasureRectYCoords: start " << r.startY << " -> " << y0 << ", end " << r.endY << " -> " << y1 << endl; @@ -3587,7 +3592,7 @@ } void -SpectrogramLayer::setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const +SpectrogramLayer::setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const { if (start) { r.startY = getFrequencyForY(v, y);
--- a/layer/SpectrogramLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/SpectrogramLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -57,23 +57,23 @@ virtual const ZoomConstraint *getZoomConstraint() const { return this; } virtual const Model *getModel() const { return m_model; } - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; virtual void setSynchronousPainting(bool synchronous); - virtual int getVerticalScaleWidth(View *v, bool detailed, QPainter &) const; - virtual void paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const; + virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool detailed, QPainter &) const; + virtual void paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const; - virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos, + virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos, std::vector<QRect> &extents) const; - virtual void paintCrosshairs(View *, QPainter &, QPoint) const; + virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void measureDoubleClick(View *, QMouseEvent *); + virtual void measureDoubleClick(LayerGeometryProvider *, QMouseEvent *); virtual bool hasLightBackground() const; @@ -209,29 +209,29 @@ return ColourHasMeaningfulValue; } - float getYForFrequency(const View *v, float frequency) const; - float getFrequencyForY(const View *v, int y) const; + double getYForFrequency(const LayerGeometryProvider *v, double frequency) const; + double getFrequencyForY(const LayerGeometryProvider *v, int y) const; - virtual int getCompletion(View *v) const; - virtual QString getError(View *v) const; + virtual int getCompletion(LayerGeometryProvider *v) const; + virtual QString getError(LayerGeometryProvider *v) const; - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const; - virtual bool getDisplayExtents(float &min, float &max) const; + virtual bool getDisplayExtents(double &min, double &max) const; - virtual bool setDisplayExtents(float min, float max); + virtual bool setDisplayExtents(double min, double max); - virtual bool getYScaleValue(const View *, int, float &, QString &) const; + virtual bool getYScaleValue(const LayerGeometryProvider *, int, double &, QString &) const; virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; void setProperties(const QXmlAttributes &attributes); - virtual void setLayerDormant(const View *v, bool dormant); + virtual void setLayerDormant(const LayerGeometryProvider *v, bool dormant); - virtual bool isLayerScrollable(const View *) const { return false; } + virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return false; } virtual int getVerticalZoomSteps(int &defaultStep) const; virtual int getCurrentVerticalZoomStep() const; @@ -242,7 +242,7 @@ protected slots: void cacheInvalid(); - void cacheInvalid(int startFrame, int endFrame); + void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame); void preferenceChanged(PropertyContainer::PropertyName name); @@ -307,12 +307,12 @@ { QImage image; QRect validArea; - int startFrame; + sv_frame_t startFrame; int zoomLevel; }; typedef std::map<const View *, ImageCache> ViewImageCache; void invalidateImageCaches(); - void invalidateImageCaches(int startFrame, int endFrame); + void invalidateImageCaches(sv_frame_t startFrame, sv_frame_t endFrame); mutable ViewImageCache m_imageCaches; /** @@ -325,27 +325,20 @@ mutable QTimer *m_updateTimer; - mutable int m_candidateFillStartFrame; + mutable sv_frame_t m_candidateFillStartFrame; bool m_exiting; void initialisePalette(); void rotatePalette(int distance); - unsigned char getDisplayValue(View *v, float input) const; + unsigned char getDisplayValue(LayerGeometryProvider *v, double input) const; int getColourScaleWidth(QPainter &) const; - void illuminateLocalFeatures(View *v, QPainter &painter) const; + void illuminateLocalFeatures(LayerGeometryProvider *v, QPainter &painter) const; - float getEffectiveMinFrequency() const; - float getEffectiveMaxFrequency() const; - - struct LayerRange { - int startFrame; - int zoomLevel; - int modelStart; - int modelEnd; - }; + double getEffectiveMinFrequency() const; + double getEffectiveMaxFrequency() const; // Note that the getYBin... methods return the nominal bin in the // un-smoothed spectrogram. This is not necessarily the same bin @@ -353,17 +346,17 @@ // position, if the spectrogram has oversampling smoothing. Use // getSmoothedYBinRange to obtain that. - bool getXBinRange(View *v, int x, float &windowMin, float &windowMax) const; - bool getYBinRange(View *v, int y, float &freqBinMin, float &freqBinMax) const; - bool getSmoothedYBinRange(View *v, int y, float &freqBinMin, float &freqBinMax) const; + bool getXBinRange(LayerGeometryProvider *v, int x, double &windowMin, double &windowMax) const; + bool getYBinRange(LayerGeometryProvider *v, int y, double &freqBinMin, double &freqBinMax) const; + bool getSmoothedYBinRange(LayerGeometryProvider *v, int y, double &freqBinMin, double &freqBinMax) const; - bool getYBinSourceRange(View *v, int y, float &freqMin, float &freqMax) const; - bool getAdjustedYBinSourceRange(View *v, int x, int y, - float &freqMin, float &freqMax, - float &adjFreqMin, float &adjFreqMax) const; - bool getXBinSourceRange(View *v, int x, RealTime &timeMin, RealTime &timeMax) const; - bool getXYBinSourceRange(View *v, int x, int y, float &min, float &max, - float &phaseMin, float &phaseMax) const; + bool getYBinSourceRange(LayerGeometryProvider *v, int y, double &freqMin, double &freqMax) const; + bool getAdjustedYBinSourceRange(LayerGeometryProvider *v, int x, int y, + double &freqMin, double &freqMax, + double &adjFreqMin, double &adjFreqMax) const; + bool getXBinSourceRange(LayerGeometryProvider *v, int x, RealTime &timeMin, RealTime &timeMax) const; + bool getXYBinSourceRange(LayerGeometryProvider *v, int x, int y, double &min, double &max, + double &phaseMin, double &phaseMax) const; int getWindowIncrement() const { if (m_windowHopLevel == 0) return m_windowSize; @@ -371,13 +364,13 @@ else return m_windowSize / (1 << (m_windowHopLevel - 1)); } - int getZeroPadLevel(const View *v) const; - int getFFTSize(const View *v) const; - FFTModel *getFFTModel(const View *v) const; - Dense3DModelPeakCache *getPeakCache(const View *v) const; + int getZeroPadLevel(const LayerGeometryProvider *v) const; + int getFFTSize(const LayerGeometryProvider *v) const; + FFTModel *getFFTModel(const LayerGeometryProvider *v) const; + Dense3DModelPeakCache *getPeakCache(const LayerGeometryProvider *v) const; void invalidateFFTModels(); - typedef std::pair<FFTModel *, int> FFTFillPair; // model, last fill + typedef std::pair<FFTModel *, sv_frame_t> FFTFillPair; // model, last fill typedef std::map<const View *, FFTFillPair> ViewFFTMap; typedef std::map<const View *, Dense3DModelPeakCache *> PeakCacheMap; mutable ViewFFTMap m_fftModels; @@ -390,20 +383,19 @@ bool operator==(const MagnitudeRange &r) { return r.m_min == m_min && r.m_max == m_max; } - bool isSet() const { return (m_min != 0 || m_max != 0); } + bool isSet() const { return (m_min != 0.f || m_max != 0.f); } void set(float min, float max) { - m_min = convert(min); - m_max = convert(max); + m_min = min; + m_max = max; if (m_max < m_min) m_max = m_min; } bool sample(float f) { - unsigned int ui = convert(f); bool changed = false; if (isSet()) { - if (ui < m_min) { m_min = ui; changed = true; } - if (ui > m_max) { m_max = ui; changed = true; } + if (f < m_min) { m_min = f; changed = true; } + if (f > m_max) { m_max = f; changed = true; } } else { - m_max = m_min = ui; + m_max = m_min = f; changed = true; } return changed; @@ -420,40 +412,36 @@ } return changed; } - float getMin() const { return float(m_min) / UINT_MAX; } - float getMax() const { return float(m_max) / UINT_MAX; } + float getMin() const { return m_min; } + float getMax() const { return m_max; } private: - unsigned int m_min; - unsigned int m_max; - unsigned int convert(float f) { - if (f < 0.f) f = 0.f; - if (f > 1.f) f = 1.f; - return (unsigned int)(f * UINT_MAX); - } + float m_min; + float m_max; }; - typedef std::map<const View *, MagnitudeRange> ViewMagMap; + typedef std::map<const LayerGeometryProvider *, MagnitudeRange> ViewMagMap; mutable ViewMagMap m_viewMags; mutable std::vector<MagnitudeRange> m_columnMags; void invalidateMagnitudes(); - bool updateViewMagnitudes(View *v) const; - bool paintDrawBuffer(View *v, int w, int h, - int *binforx, float *binfory, + bool updateViewMagnitudes(LayerGeometryProvider *v) const; + bool paintDrawBuffer(LayerGeometryProvider *v, int w, int h, + const std::vector<int> &binforx, + const std::vector<double> &binfory, bool usePeaksCache, MagnitudeRange &overallMag, bool &overallMagChanged) const; - bool paintDrawBufferPeakFrequencies(View *v, int w, int h, - int *binforx, + bool paintDrawBufferPeakFrequencies(LayerGeometryProvider *v, int w, int h, + const std::vector<int> &binforx, int minbin, int maxbin, - float displayMinFreq, - float displayMaxFreq, + double displayMinFreq, + double displayMaxFreq, bool logarithmic, MagnitudeRange &overallMag, bool &overallMagChanged) const; - virtual void updateMeasureRectYCoords(View *v, const MeasureRect &r) const; - virtual void setMeasureRectYCoord(View *v, MeasureRect &r, bool start, int y) const; + virtual void updateMeasureRectYCoords(LayerGeometryProvider *v, const MeasureRect &r) const; + virtual void setMeasureRectYCoord(LayerGeometryProvider *v, MeasureRect &r, bool start, int y) const; }; #endif
--- a/layer/SpectrumLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/SpectrumLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -112,11 +112,7 @@ m_windowType, m_windowSize, getWindowIncrement(), - m_windowSize, - false, - StorageAdviser::Criteria - (StorageAdviser::SpeedCritical | - StorageAdviser::FrequentLookupLikely)); + m_windowSize); setSliceableModel(newFFT); @@ -125,8 +121,6 @@ m_biasCurve.push_back(1.f / (float(m_windowSize)/2.f)); } - newFFT->resume(); - m_newFFTNeeded = false; } @@ -301,42 +295,42 @@ } bool -SpectrumLayer::getValueExtents(float &, float &, bool &, QString &) const +SpectrumLayer::getValueExtents(double &, double &, bool &, QString &) const { return false; } -float -SpectrumLayer::getXForBin(int bin, int totalBins, float w) const +double +SpectrumLayer::getXForBin(int bin, int totalBins, double w) const { if (!m_sliceableModel) return SliceLayer::getXForBin(bin, totalBins, w); - float sampleRate = m_sliceableModel->getSampleRate(); - float binfreq = (sampleRate * bin) / (totalBins * 2); + sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate(); + double binfreq = (sampleRate * bin) / (totalBins * 2); return getXForFrequency(binfreq, w); } int -SpectrumLayer::getBinForX(float x, int totalBins, float w) const +SpectrumLayer::getBinForX(double x, int totalBins, double w) const { if (!m_sliceableModel) return SliceLayer::getBinForX(x, totalBins, w); - float sampleRate = m_sliceableModel->getSampleRate(); - float binfreq = getFrequencyForX(x, w); + sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate(); + double binfreq = getFrequencyForX(x, w); return int((binfreq * totalBins * 2) / sampleRate); } -float -SpectrumLayer::getFrequencyForX(float x, float w) const +double +SpectrumLayer::getFrequencyForX(double x, double w) const { - float freq = 0; + double freq = 0; if (!m_sliceableModel) return 0; - int sampleRate = m_sliceableModel->getSampleRate(); + sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate(); - float maxfreq = float(sampleRate) / 2; + double maxfreq = double(sampleRate) / 2; switch (m_binScale) { @@ -345,26 +339,26 @@ break; case LogBins: - freq = powf(10.f, (x * log10f(maxfreq)) / w); + freq = pow(10.0, (x * log10(maxfreq)) / w); break; case InvertedLogBins: - freq = maxfreq - powf(10.f, ((w - x) * log10f(maxfreq)) / w); + freq = maxfreq - pow(10.0, ((w - x) * log10(maxfreq)) / w); break; } return freq; } -float -SpectrumLayer::getXForFrequency(float freq, float w) const +double +SpectrumLayer::getXForFrequency(double freq, double w) const { - float x = 0; + double x = 0; if (!m_sliceableModel) return x; - int sampleRate = m_sliceableModel->getSampleRate(); + sv_samplerate_t sampleRate = m_sliceableModel->getSampleRate(); - float maxfreq = float(sampleRate) / 2; + double maxfreq = double(sampleRate) / 2; switch (m_binScale) { @@ -373,12 +367,12 @@ break; case LogBins: - x = (log10f(freq) * w) / log10f(maxfreq); + x = (log10(freq) * w) / log10(maxfreq); break; case InvertedLogBins: if (maxfreq == freq) x = w; - else x = w - (log10f(maxfreq - freq) * w) / log10f(maxfreq); + else x = w - (log10(maxfreq - freq) * w) / log10(maxfreq); break; } @@ -386,26 +380,26 @@ } bool -SpectrumLayer::getXScaleValue(const View *v, int x, - float &value, QString &unit) const +SpectrumLayer::getXScaleValue(const LayerGeometryProvider *v, int x, + double &value, QString &unit) const { if (m_xorigins.find(v) == m_xorigins.end()) return false; int xorigin = m_xorigins.find(v)->second; - value = getFrequencyForX(x - xorigin, v->width() - xorigin - 1); + value = getFrequencyForX(x - xorigin, v->getPaintWidth() - xorigin - 1); unit = "Hz"; return true; } bool -SpectrumLayer::getYScaleValue(const View *v, int y, - float &value, QString &unit) const +SpectrumLayer::getYScaleValue(const LayerGeometryProvider *v, int y, + double &value, QString &unit) const { value = getValueForY(y, v); if (m_energyScale == dBScale || m_energyScale == MeterScale) { - if (value > 0.f) { - value = 10.f * log10f(value); + if (value > 0.0) { + value = 10.0 * log10(value); if (value < m_threshold) value = m_threshold; } else value = m_threshold; @@ -419,8 +413,8 @@ } bool -SpectrumLayer::getYScaleDifference(const View *v, int y0, int y1, - float &diff, QString &unit) const +SpectrumLayer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1, + double &diff, QString &unit) const { bool rv = SliceLayer::getYScaleDifference(v, y0, y1, diff, unit); if (rv && (unit == "dBV")) unit = "dB"; @@ -429,14 +423,14 @@ bool -SpectrumLayer::getCrosshairExtents(View *v, QPainter &paint, +SpectrumLayer::getCrosshairExtents(LayerGeometryProvider *v, QPainter &paint, QPoint cursorPos, std::vector<QRect> &extents) const { - QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->height() - cursorPos.y()); + QRect vertical(cursorPos.x(), cursorPos.y(), 1, v->getPaintHeight() - cursorPos.y()); extents.push_back(vertical); - QRect horizontal(0, cursorPos.y(), v->width(), 12); + QRect horizontal(0, cursorPos.y(), v->getPaintWidth(), 12); extents.push_back(horizontal); int hoffset = 2; @@ -455,14 +449,14 @@ extents.push_back(log); QRect freq(cursorPos.x(), - v->height() - paint.fontMetrics().height() - hoffset, + v->getPaintHeight() - paint.fontMetrics().height() - hoffset, paint.fontMetrics().width("123456 Hz") + 2, paint.fontMetrics().height()); extents.push_back(freq); int w(paint.fontMetrics().width("C#10+50c") + 2); QRect pitch(cursorPos.x() - w, - v->height() - paint.fontMetrics().height() - hoffset, + v->getPaintHeight() - paint.fontMetrics().height() - hoffset, w, paint.fontMetrics().height()); extents.push_back(pitch); @@ -471,7 +465,7 @@ } void -SpectrumLayer::paintCrosshairs(View *v, QPainter &paint, +SpectrumLayer::paintCrosshairs(LayerGeometryProvider *v, QPainter &paint, QPoint cursorPos) const { if (!m_sliceableModel) return; @@ -487,19 +481,19 @@ paint.setPen(mapper.getContrastingColour()); int xorigin = m_xorigins[v]; - int w = v->width() - xorigin - 1; + int w = v->getPaintWidth() - xorigin - 1; - paint.drawLine(xorigin, cursorPos.y(), v->width(), cursorPos.y()); - paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->height()); + paint.drawLine(xorigin, cursorPos.y(), v->getPaintWidth(), cursorPos.y()); + paint.drawLine(cursorPos.x(), cursorPos.y(), cursorPos.x(), v->getPaintHeight()); - float fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); + double fundamental = getFrequencyForX(cursorPos.x() - xorigin, w); int hoffset = 2; if (m_binScale == LogBins) hoffset = 13; v->drawVisibleText(paint, cursorPos.x() + 2, - v->height() - 2 - hoffset, + v->getPaintHeight() - 2 - hoffset, QString("%1 Hz").arg(fundamental), View::OutlinedText); @@ -507,15 +501,15 @@ QString pitchLabel = Pitch::getPitchLabelForFrequency(fundamental); v->drawVisibleText(paint, cursorPos.x() - paint.fontMetrics().width(pitchLabel) - 2, - v->height() - 2 - hoffset, + v->getPaintHeight() - 2 - hoffset, pitchLabel, View::OutlinedText); } - float value = getValueForY(cursorPos.y(), v); - float thresh = m_threshold; - float db = thresh; - if (value > 0.f) db = 10.f * log10f(value); + double value = getValueForY(cursorPos.y(), v); + double thresh = m_threshold; + double db = thresh; + if (value > 0.0) db = 10.0 * log10(value); if (db < thresh) db = thresh; v->drawVisibleText(paint, @@ -534,10 +528,10 @@ while (harmonic < 100) { - float hx = lrintf(getXForFrequency(fundamental * harmonic, w)); + int hx = int(lrint(getXForFrequency(fundamental * harmonic, w))); hx += xorigin; - if (hx < xorigin || hx > v->width()) break; + if (hx < xorigin || hx > v->getPaintWidth()) break; int len = 7; @@ -549,9 +543,9 @@ } } - paint.drawLine(int(hx), + paint.drawLine(hx, cursorPos.y(), - int(hx), + hx, cursorPos.y() + len); ++harmonic; @@ -561,7 +555,7 @@ } QString -SpectrumLayer::getFeatureDescription(View *v, QPoint &p) const +SpectrumLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &p) const { if (!m_sliceableModel) return ""; @@ -571,21 +565,21 @@ if (genericDesc == "") return ""; - float minvalue = 0.f; + double minvalue = 0.f; if (minbin < int(m_values.size())) minvalue = m_values[minbin]; - float maxvalue = minvalue; + double maxvalue = minvalue; if (maxbin < int(m_values.size())) maxvalue = m_values[maxbin]; if (minvalue > maxvalue) std::swap(minvalue, maxvalue); QString binstr; QString hzstr; - int minfreq = lrintf((minbin * m_sliceableModel->getSampleRate()) / - m_windowSize); - int maxfreq = lrintf((std::max(maxbin, minbin+1) - * m_sliceableModel->getSampleRate()) / - m_windowSize); + int minfreq = int(lrint((minbin * m_sliceableModel->getSampleRate()) / + m_windowSize)); + int maxfreq = int(lrint((std::max(maxbin, minbin+1) + * m_sliceableModel->getSampleRate()) / + m_windowSize)); if (maxbin != minbin) { binstr = tr("%1 - %2").arg(minbin+1).arg(maxbin+1); @@ -606,21 +600,21 @@ } QString dbstr; - float mindb = AudioLevel::multiplier_to_dB(minvalue); - float maxdb = AudioLevel::multiplier_to_dB(maxvalue); + double mindb = AudioLevel::multiplier_to_dB(minvalue); + double maxdb = AudioLevel::multiplier_to_dB(maxvalue); QString mindbstr; QString maxdbstr; if (mindb == AudioLevel::DB_FLOOR) { mindbstr = tr("-Inf"); } else { - mindbstr = QString("%1").arg(lrintf(mindb)); + mindbstr = QString("%1").arg(lrint(mindb)); } if (maxdb == AudioLevel::DB_FLOOR) { maxdbstr = tr("-Inf"); } else { - maxdbstr = QString("%1").arg(lrintf(maxdb)); + maxdbstr = QString("%1").arg(lrint(maxdb)); } - if (lrintf(mindb) != lrintf(maxdb)) { + if (lrint(mindb) != lrint(maxdb)) { dbstr = tr("%1 - %2").arg(mindbstr).arg(maxdbstr); } else { dbstr = tr("%1").arg(mindbstr); @@ -650,7 +644,7 @@ } void -SpectrumLayer::paint(View *v, QPainter &paint, QRect rect) const +SpectrumLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_originModel || !m_originModel->isOK() || !m_originModel->isReady()) { @@ -666,10 +660,10 @@ FFTModel *fft = dynamic_cast<FFTModel *> (const_cast<DenseThreeDimensionalModel *>(m_sliceableModel)); - float thresh = (powf(10, -6) / m_gain) * (m_windowSize / 2.f); // -60dB adj + double thresh = (pow(10, -6) / m_gain) * (m_windowSize / 2.0); // -60dB adj int xorigin = getVerticalScaleWidth(v, false, paint) + 1; - int w = v->width() - xorigin - 1; + int w = v->getPaintWidth() - xorigin - 1; int pkh = 0; //!!! if (m_binScale == LogBins) { @@ -684,7 +678,7 @@ // SVDEBUG << "Showing peaks..." << endl; - int col = v->getCentreFrame() / fft->getResolution(); + int col = int(v->getCentreFrame() / fft->getResolution()); paint.save(); paint.setRenderHint(QPainter::Antialiasing, false); @@ -692,8 +686,8 @@ int peakminbin = 0; int peakmaxbin = fft->getHeight() - 1; - float peakmaxfreq = Pitch::getFrequencyForPitch(128); - peakmaxbin = ((peakmaxfreq * fft->getHeight() * 2) / fft->getSampleRate()); + double peakmaxfreq = Pitch::getFrequencyForPitch(128); + peakmaxbin = int(((peakmaxfreq * fft->getHeight() * 2) / fft->getSampleRate())); FFTModel::PeakSet peaks = fft->getPeakFrequencies (FFTModel::MajorPitchAdaptivePeaks, col, peakminbin, peakmaxbin); @@ -702,12 +696,12 @@ BiasCurve curve; getBiasCurve(curve); - int cs = curve.size(); + int cs = int(curve.size()); - std::vector<float> values; + std::vector<double> values; for (int bin = 0; bin < fft->getHeight(); ++bin) { - float value = m_sliceableModel->getValueAt(col, bin); + double value = m_sliceableModel->getValueAt(col, bin); if (bin < cs) value *= curve[bin]; values.push_back(value); } @@ -719,17 +713,17 @@ // cerr << "bin = " << bin << ", thresh = " << thresh << ", value = " << fft->getMagnitudeAt(col, bin) << endl; - if (!fft->isOverThreshold(col, bin, thresh)) continue; + if (!fft->isOverThreshold(col, bin, float(thresh))) continue; - float freq = i->second; + double freq = i->second; - int x = lrintf(getXForFrequency(freq, w)); + int x = int(lrint(getXForFrequency(freq, w))); - float norm = 0.f; + double norm = 0.f; (void)getYForValue(values[bin], v, norm); // don't need return value, need norm paint.setPen(mapper.map(norm)); - paint.drawLine(xorigin + x, 0, xorigin + x, v->height() - pkh - 1); + paint.drawLine(xorigin + x, 0, xorigin + x, v->getPaintHeight() - pkh - 1); } paint.restore(); @@ -749,7 +743,7 @@ // if (m_binScale == LogBins) { // int pkh = 10; - int h = v->height(); + int h = v->getPaintHeight(); // piano keyboard //!!! should be in a new paintHorizontalScale()? @@ -762,8 +756,8 @@ for (int i = 0; i < 128; ++i) { - float f = Pitch::getFrequencyForPitch(i); - int x = lrintf(getXForFrequency(f, w)); + double f = Pitch::getFrequencyForPitch(i); + int x = int(lrint(getXForFrequency(f, w))); x += xorigin; @@ -805,7 +799,7 @@ if (n == 1 || n == 3 || n == 6 || n == 8 || n == 10) { // black notes paint.drawLine(x, h - pkh, x, h); - int rw = lrintf(float(x - px) / 4) * 2; + int rw = int(lrint(double(x - px) / 4) * 2); if (rw < 2) rw = 2; paint.drawRect(x - rw/2, h - pkh, rw, pkh/2); } else if (n == 0 || n == 5) {
--- a/layer/SpectrumLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/SpectrumLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -39,13 +39,13 @@ void setModel(DenseTimeValueModel *model); virtual const Model *getModel() const { return m_originModel; } - virtual bool getCrosshairExtents(View *, QPainter &, QPoint cursorPos, + virtual bool getCrosshairExtents(LayerGeometryProvider *, QPainter &, QPoint cursorPos, std::vector<QRect> &extents) const; - virtual void paintCrosshairs(View *, QPainter &, QPoint) const; + virtual void paintCrosshairs(LayerGeometryProvider *, QPainter &, QPoint) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; virtual VerticalPosition getPreferredFrameCountPosition() const { return PositionTop; @@ -64,19 +64,19 @@ virtual void setProperty(const PropertyName &, int value); virtual void setProperties(const QXmlAttributes &); - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const; - virtual bool getXScaleValue(const View *v, int x, - float &value, QString &unit) const; + virtual bool getXScaleValue(const LayerGeometryProvider *v, int x, + double &value, QString &unit) const; - virtual bool getYScaleValue(const View *, int y, - float &value, QString &unit) const; + virtual bool getYScaleValue(const LayerGeometryProvider *, int y, + double &value, QString &unit) const; - virtual bool getYScaleDifference(const View *, int y0, int y1, - float &diff, QString &unit) const; + virtual bool getYScaleDifference(const LayerGeometryProvider *, int y0, int y1, + double &diff, QString &unit) const; - virtual bool isLayerScrollable(const View *) const { return false; } + virtual bool isLayerScrollable(const LayerGeometryProvider *) const { return false; } void setChannel(int); int getChannel() const { return m_channel; } @@ -93,7 +93,7 @@ void setShowPeaks(bool); bool getShowPeaks() const { return m_showPeaks; } - virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } + virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const { return 0; } virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; @@ -123,11 +123,11 @@ virtual void getBiasCurve(BiasCurve &) const; BiasCurve m_biasCurve; - virtual float getXForBin(int bin, int totalBins, float w) const; - virtual int getBinForX(float x, int totalBins, float w) const; + virtual double getXForBin(int bin, int totalBins, double w) const; + virtual int getBinForX(double x, int totalBins, double w) const; - float getFrequencyForX(float x, float w) const; - float getXForFrequency(float freq, float w) const; + double getFrequencyForX(double x, double w) const; + double getXForFrequency(double freq, double w) const; int getWindowIncrement() const { if (m_windowHopLevel == 0) return m_windowSize;
--- a/layer/TextLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/TextLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -96,13 +96,13 @@ } bool -TextLayer::getValueExtents(float &, float &, bool &, QString &) const +TextLayer::getValueExtents(double &, double &, bool &, QString &) const { return false; } bool -TextLayer::isLayerScrollable(const View *v) const +TextLayer::isLayerScrollable(const LayerGeometryProvider *v) const { QPoint discard; return !v->shouldIlluminateLocalFeatures(this, discard); @@ -110,12 +110,12 @@ TextModel::PointList -TextLayer::getLocalPoints(View *v, int x, int y) const +TextLayer::getLocalPoints(LayerGeometryProvider *v, int x, int y) const { if (!m_model) return TextModel::PointList(); - long frame0 = v->getFrameForX(-150); - long frame1 = v->getFrameForX(v->width() + 150); + sv_frame_t frame0 = v->getFrameForX(-150); + sv_frame_t frame1 = v->getFrameForX(v->getPaintWidth() + 150); TextModel::PointList points(m_model->getPoints(frame0, frame1)); @@ -139,9 +139,9 @@ (QRect(0, 0, 150, 200), Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, label); - if (py + rect.height() > v->height()) { - if (rect.height() > v->height()) py = 0; - else py = v->height() - rect.height() - 1; + if (py + rect.height() > v->getPaintHeight()) { + if (rect.height() > v->getPaintHeight()) py = 0; + else py = v->getPaintHeight() - rect.height() - 1; } if (x >= px && x < px + rect.width() && @@ -154,23 +154,23 @@ } bool -TextLayer::getPointToDrag(View *v, int x, int y, TextModel::Point &p) const +TextLayer::getPointToDrag(LayerGeometryProvider *v, int x, int y, TextModel::Point &p) const { if (!m_model) return false; - long a = v->getFrameForX(x - 120); - long b = v->getFrameForX(x + 10); + sv_frame_t a = v->getFrameForX(x - 120); + sv_frame_t b = v->getFrameForX(x + 10); TextModel::PointList onPoints = m_model->getPoints(a, b); if (onPoints.empty()) return false; - float nearestDistance = -1; + double nearestDistance = -1; for (TextModel::PointList::const_iterator i = onPoints.begin(); i != onPoints.end(); ++i) { - int yd = getYForHeight(v, (*i).height) - y; - int xd = v->getXForFrame((*i).frame) - x; - float distance = sqrtf(yd*yd + xd*xd); + double yd = getYForHeight(v, (*i).height) - y; + double xd = v->getXForFrame((*i).frame) - x; + double distance = sqrt(yd*yd + xd*xd); if (nearestDistance == -1 || distance < nearestDistance) { nearestDistance = distance; @@ -182,7 +182,7 @@ } QString -TextLayer::getFeatureDescription(View *v, QPoint &pos) const +TextLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); @@ -198,7 +198,7 @@ } } - long useFrame = points.begin()->frame; + sv_frame_t useFrame = points.begin()->frame; RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); @@ -220,7 +220,7 @@ //!!! too much overlap with TimeValueLayer/TimeInstantLayer bool -TextLayer::snapToFeatureFrame(View *v, int &frame, +TextLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -240,7 +240,7 @@ } points = m_model->getPoints(frame, frame); - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; for (TextModel::PointList::const_iterator i = points.begin(); @@ -292,32 +292,32 @@ } int -TextLayer::getYForHeight(View *v, float height) const +TextLayer::getYForHeight(LayerGeometryProvider *v, double height) const { - int h = v->height(); + int h = v->getPaintHeight(); return h - int(height * h); } -float -TextLayer::getHeightForY(View *v, int y) const +double +TextLayer::getHeightForY(LayerGeometryProvider *v, int y) const { - int h = v->height(); - return float(h - y) / h; + int h = v->getPaintHeight(); + return double(h - y) / h; } void -TextLayer::paint(View *v, QPainter &paint, QRect rect) const +TextLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) return; - int sampleRate = m_model->getSampleRate(); + sv_samplerate_t sampleRate = m_model->getSampleRate(); if (!sampleRate) return; // Profiler profiler("TextLayer::paint", true); int x0 = rect.left(), x1 = rect.right(); - long frame0 = v->getFrameForX(x0); - long frame1 = v->getFrameForX(x1); + sv_frame_t frame0 = v->getFrameForX(x0); + sv_frame_t frame1 = v->getFrameForX(x1); TextModel::PointList points(m_model->getPoints(frame0, frame1)); if (points.empty()) return; @@ -347,7 +347,7 @@ int boxMaxHeight = 200; paint.save(); - paint.setClipRect(rect.x(), 0, rect.width() + boxMaxWidth, v->height()); + paint.setClipRect(rect.x(), 0, rect.width() + boxMaxWidth, v->getPaintHeight()); for (TextModel::PointList::const_iterator i = points.begin(); i != points.end(); ++i) { @@ -380,9 +380,9 @@ QRect textRect = QRect(3, 2, boxRect.width(), boxRect.height()); boxRect = QRect(0, 0, boxRect.width() + 6, boxRect.height() + 2); - if (y + boxRect.height() > v->height()) { - if (boxRect.height() > v->height()) y = 0; - else y = v->height() - boxRect.height() - 1; + if (y + boxRect.height() > v->getPaintHeight()) { + if (boxRect.height() > v->getPaintHeight()) y = 0; + else y = v->getPaintHeight() - boxRect.height() - 1; } boxRect = QRect(x, y, boxRect.width(), boxRect.height()); @@ -411,7 +411,7 @@ } void -TextLayer::drawStart(View *v, QMouseEvent *e) +TextLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "TextLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; @@ -420,13 +420,13 @@ return; } - long frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float height = getHeightForY(v, e->y()); + double height = getHeightForY(v, e->y()); - m_editingPoint = TextModel::Point(frame, height, ""); + m_editingPoint = TextModel::Point(frame, float(height), ""); m_originalPoint = m_editingPoint; if (m_editingCommand) finish(m_editingCommand); @@ -437,32 +437,32 @@ } void -TextLayer::drawDrag(View *v, QMouseEvent *e) +TextLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "TextLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; - long frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float height = getHeightForY(v, e->y()); + double height = getHeightForY(v, e->y()); m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = frame; - m_editingPoint.height = height; + m_editingPoint.height = float(height); m_editingCommand->addPoint(m_editingPoint); } void -TextLayer::drawEnd(View *v, QMouseEvent *) +TextLayer::drawEnd(LayerGeometryProvider *v, QMouseEvent *) { // SVDEBUG << "TextLayer::drawEnd(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; bool ok = false; - QString label = QInputDialog::getText(v, tr("Enter label"), + QString label = QInputDialog::getText(v->getView(), tr("Enter label"), tr("Please enter a new label:"), QLineEdit::Normal, "", &ok); @@ -480,7 +480,7 @@ } void -TextLayer::eraseStart(View *v, QMouseEvent *e) +TextLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return; @@ -495,12 +495,12 @@ } void -TextLayer::eraseDrag(View *, QMouseEvent *) +TextLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) { } void -TextLayer::eraseEnd(View *v, QMouseEvent *e) +TextLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; @@ -521,7 +521,7 @@ } void -TextLayer::editStart(View *v, QMouseEvent *e) +TextLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) { // SVDEBUG << "TextLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; @@ -543,21 +543,21 @@ } void -TextLayer::editDrag(View *v, QMouseEvent *e) +TextLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; - long frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); - float heightDiff = getHeightForY(v, e->y()) - getHeightForY(v, m_editOrigin.y()); + sv_frame_t frameDiff = v->getFrameForX(e->x()) - v->getFrameForX(m_editOrigin.x()); + double heightDiff = getHeightForY(v, e->y()) - getHeightForY(v, m_editOrigin.y()); - long frame = m_originalPoint.frame + frameDiff; - float height = m_originalPoint.height + heightDiff; + sv_frame_t frame = m_originalPoint.frame + frameDiff; + double height = m_originalPoint.height + heightDiff; -// long frame = v->getFrameForX(e->x()); +// sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = (frame / m_model->getResolution()) * m_model->getResolution(); -// float height = getHeightForY(v, e->y()); +// double height = getHeightForY(v, e->y()); if (!m_editingCommand) { m_editingCommand = new TextModel::EditCommand(m_model, tr("Drag Label")); @@ -565,12 +565,12 @@ m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = frame; - m_editingPoint.height = height; + m_editingPoint.height = float(height); m_editingCommand->addPoint(m_editingPoint); } void -TextLayer::editEnd(View *, QMouseEvent *) +TextLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) { // SVDEBUG << "TextLayer::editEnd(" << e->x() << "," << e->y() << ")" << endl; if (!m_model || !m_editing) return; @@ -598,7 +598,7 @@ } bool -TextLayer::editOpen(View *v, QMouseEvent *e) +TextLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return false; @@ -608,7 +608,7 @@ QString label = text.label; bool ok = false; - label = QInputDialog::getText(v, tr("Enter label"), + label = QInputDialog::getText(v->getView(), tr("Enter label"), tr("Please enter a new label:"), QLineEdit::Normal, label, &ok); if (ok && label != text.label) { @@ -621,7 +621,7 @@ } void -TextLayer::moveSelection(Selection s, int newStartFrame) +TextLayer::moveSelection(Selection s, sv_frame_t newStartFrame) { if (!m_model) return; @@ -665,9 +665,9 @@ if (s.contains(i->frame)) { - double target = i->frame; - target = newSize.getStartFrame() + - double(target - s.getStartFrame()) * ratio; + double target = double(i->frame); + target = double(newSize.getStartFrame()) + + target - double(s.getStartFrame()) * ratio; TextModel::Point newPoint(*i); newPoint.frame = lrint(target); @@ -699,7 +699,7 @@ } void -TextLayer::copy(View *v, Selection s, Clipboard &to) +TextLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) { if (!m_model) return; @@ -717,7 +717,7 @@ } bool -TextLayer::paste(View *v, const Clipboard &from, int /* frameOffset */, bool /* interactive */) +TextLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool /* interactive */) { if (!m_model) return false; @@ -728,7 +728,7 @@ if (clipboardHasDifferentAlignment(v, from)) { QMessageBox::StandardButton button = - QMessageBox::question(v, tr("Re-align pasted items?"), + QMessageBox::question(v->getView(), tr("Re-align pasted items?"), tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); @@ -745,7 +745,7 @@ TextModel::EditCommand *command = new TextModel::EditCommand(m_model, tr("Paste")); - float valueMin = 0.0, valueMax = 1.0; + double valueMin = 0.0, valueMax = 1.0; for (Clipboard::PointList::const_iterator i = points.begin(); i != points.end(); ++i) { if (i->haveValue()) { @@ -759,7 +759,7 @@ i != points.end(); ++i) { if (!i->haveFrame()) continue; - int frame = 0; + sv_frame_t frame = 0; if (!realign) { @@ -778,9 +778,9 @@ TextModel::Point newPoint(frame); if (i->haveValue()) { - newPoint.height = (i->getValue() - valueMin) / (valueMax - valueMin); + newPoint.height = float((i->getValue() - valueMin) / (valueMax - valueMin)); } else { - newPoint.height = 0.5; + newPoint.height = 0.5f; } if (i->haveLabel()) {
--- a/layer/TextLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/TextLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -32,35 +32,35 @@ public: TextLayer(); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void drawStart(View *v, QMouseEvent *); - virtual void drawDrag(View *v, QMouseEvent *); - virtual void drawEnd(View *v, QMouseEvent *); + virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void eraseStart(View *v, QMouseEvent *); - virtual void eraseDrag(View *v, QMouseEvent *); - virtual void eraseEnd(View *v, QMouseEvent *); + virtual void eraseStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void editStart(View *v, QMouseEvent *); - virtual void editDrag(View *v, QMouseEvent *); - virtual void editEnd(View *v, QMouseEvent *); + virtual void editStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void moveSelection(Selection s, int newStartFrame); + virtual void moveSelection(Selection s, sv_frame_t newStartFrame); virtual void resizeSelection(Selection s, Selection newSize); virtual void deleteSelection(Selection s); - virtual void copy(View *v, Selection s, Clipboard &to); - virtual bool paste(View *v, const Clipboard &from, int frameOffset, + virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to); + virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive); - virtual bool editOpen(View *, QMouseEvent *); // on double-click + virtual bool editOpen(LayerGeometryProvider *, QMouseEvent *); // on double-click virtual const Model *getModel() const { return m_model; } void setModel(TextModel *model); @@ -74,16 +74,16 @@ int value) const; virtual void setProperty(const PropertyName &, int value); - virtual bool isLayerScrollable(const View *v) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; virtual bool isLayerEditable() const { return true; } - virtual int getCompletion(View *) const { return m_model->getCompletion(); } + virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const; - virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } + virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const { return 0; } virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; @@ -91,14 +91,14 @@ void setProperties(const QXmlAttributes &attributes); protected: - int getYForHeight(View *v, float height) const; - float getHeightForY(View *v, int y) const; + int getYForHeight(LayerGeometryProvider *v, double height) const; + double getHeightForY(LayerGeometryProvider *v, int y) const; virtual int getDefaultColourHint(bool dark, bool &impose); - TextModel::PointList getLocalPoints(View *v, int x, int y) const; + TextModel::PointList getLocalPoints(LayerGeometryProvider *v, int x, int y) const; - bool getPointToDrag(View *v, int x, int y, TextModel::Point &) const; + bool getPointToDrag(LayerGeometryProvider *v, int x, int y, TextModel::Point &) const; TextModel *m_model; bool m_editing;
--- a/layer/TimeInstantLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/TimeInstantLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -147,14 +147,14 @@ } bool -TimeInstantLayer::isLayerScrollable(const View *v) const +TimeInstantLayer::isLayerScrollable(const LayerGeometryProvider *v) const { QPoint discard; return !v->shouldIlluminateLocalFeatures(this, discard); } SparseOneDimensionalModel::PointList -TimeInstantLayer::getLocalPoints(View *v, int x) const +TimeInstantLayer::getLocalPoints(LayerGeometryProvider *v, int x) const { // Return a set of points that all have the same frame number, the // nearest to the given x coordinate, and that are within a @@ -201,7 +201,7 @@ } QString -TimeInstantLayer::getLabelPreceding(int frame) const +TimeInstantLayer::getLabelPreceding(sv_frame_t frame) const { if (!m_model) return ""; SparseOneDimensionalModel::PointList points = m_model->getPreviousPoints(frame); @@ -213,7 +213,7 @@ } QString -TimeInstantLayer::getFeatureDescription(View *v, QPoint &pos) const +TimeInstantLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); @@ -249,7 +249,7 @@ } bool -TimeInstantLayer::snapToFeatureFrame(View *v, int &frame, +TimeInstantLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -269,7 +269,7 @@ } points = m_model->getPoints(frame, frame); - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; for (SparseOneDimensionalModel::PointList::const_iterator i = points.begin(); @@ -321,7 +321,7 @@ } void -TimeInstantLayer::paint(View *v, QPainter &paint, QRect rect) const +TimeInstantLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) return; @@ -403,16 +403,16 @@ } if (p.frame == illuminateFrame) { - paint.setPen(getForegroundQColor(v)); + paint.setPen(getForegroundQColor(v->getView())); } else { paint.setPen(brushColour); } if (m_plotStyle == PlotInstants) { if (iw > 1) { - paint.drawRect(x, 0, iw - 1, v->height() - 1); + paint.drawRect(x, 0, iw - 1, v->getPaintHeight() - 1); } else { - paint.drawLine(x, 0, x, v->height() - 1); + paint.drawLine(x, 0, x, v->getPaintHeight() - 1); } } else { @@ -431,11 +431,11 @@ if (nx >= x) { if (illuminateFrame != p.frame && - (nx < x + 5 || x >= v->width() - 1)) { + (nx < x + 5 || x >= v->getPaintWidth() - 1)) { paint.setPen(Qt::NoPen); } - paint.drawRect(x, -1, nx - x, v->height() + 1); + paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1); } odd = !odd; @@ -466,7 +466,7 @@ } void -TimeInstantLayer::drawStart(View *v, QMouseEvent *e) +TimeInstantLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) { #ifdef DEBUG_TIME_INSTANT_LAYER cerr << "TimeInstantLayer::drawStart(" << e->x() << ")" << endl; @@ -489,7 +489,7 @@ } void -TimeInstantLayer::drawDrag(View *v, QMouseEvent *e) +TimeInstantLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) { #ifdef DEBUG_TIME_INSTANT_LAYER cerr << "TimeInstantLayer::drawDrag(" << e->x() << ")" << endl; @@ -506,7 +506,7 @@ } void -TimeInstantLayer::drawEnd(View *, QMouseEvent *) +TimeInstantLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) { #ifdef DEBUG_TIME_INSTANT_LAYER cerr << "TimeInstantLayer::drawEnd(" << e->x() << ")" << endl; @@ -523,7 +523,7 @@ } void -TimeInstantLayer::eraseStart(View *v, QMouseEvent *e) +TimeInstantLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return; @@ -541,12 +541,12 @@ } void -TimeInstantLayer::eraseDrag(View *, QMouseEvent *) +TimeInstantLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) { } void -TimeInstantLayer::eraseEnd(View *v, QMouseEvent *e) +TimeInstantLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; @@ -567,7 +567,7 @@ } void -TimeInstantLayer::editStart(View *v, QMouseEvent *e) +TimeInstantLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) { #ifdef DEBUG_TIME_INSTANT_LAYER cerr << "TimeInstantLayer::editStart(" << e->x() << ")" << endl; @@ -589,7 +589,7 @@ } void -TimeInstantLayer::editDrag(View *v, QMouseEvent *e) +TimeInstantLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) { #ifdef DEBUG_TIME_INSTANT_LAYER cerr << "TimeInstantLayer::editDrag(" << e->x() << ")" << endl; @@ -612,7 +612,7 @@ } void -TimeInstantLayer::editEnd(View *, QMouseEvent *) +TimeInstantLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) { #ifdef DEBUG_TIME_INSTANT_LAYER cerr << "TimeInstantLayer::editEnd(" << e->x() << ")" << endl; @@ -631,7 +631,7 @@ } bool -TimeInstantLayer::editOpen(View *v, QMouseEvent *e) +TimeInstantLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return false; @@ -666,7 +666,7 @@ } void -TimeInstantLayer::moveSelection(Selection s, int newStartFrame) +TimeInstantLayer::moveSelection(Selection s, sv_frame_t newStartFrame) { if (!m_model) return; @@ -712,9 +712,9 @@ if (s.contains(i->frame)) { - double target = i->frame; - target = newSize.getStartFrame() + - double(target - s.getStartFrame()) * ratio; + double target = double(i->frame); + target = double(newSize.getStartFrame()) + + target - double(s.getStartFrame()) * ratio; SparseOneDimensionalModel::Point newPoint(*i); newPoint.frame = lrint(target); @@ -747,7 +747,7 @@ } void -TimeInstantLayer::copy(View *v, Selection s, Clipboard &to) +TimeInstantLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) { if (!m_model) return; @@ -765,7 +765,7 @@ } bool -TimeInstantLayer::paste(View *v, const Clipboard &from, int frameOffset, bool) +TimeInstantLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool) { if (!m_model) return false; @@ -776,7 +776,7 @@ if (clipboardHasDifferentAlignment(v, from)) { QMessageBox::StandardButton button = - QMessageBox::question(v, tr("Re-align pasted instants?"), + QMessageBox::question(v->getView(), tr("Re-align pasted instants?"), tr("The instants you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); @@ -798,7 +798,7 @@ if (!i->haveFrame()) continue; - int frame = 0; + sv_frame_t frame = 0; if (!realign) {
--- a/layer/TimeInstantLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/TimeInstantLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -33,35 +33,35 @@ TimeInstantLayer(); virtual ~TimeInstantLayer(); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual QString getLabelPreceding(int) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getLabelPreceding(sv_frame_t) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void drawStart(View *v, QMouseEvent *); - virtual void drawDrag(View *v, QMouseEvent *); - virtual void drawEnd(View *v, QMouseEvent *); + virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void eraseStart(View *v, QMouseEvent *); - virtual void eraseDrag(View *v, QMouseEvent *); - virtual void eraseEnd(View *v, QMouseEvent *); + virtual void eraseStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void editStart(View *v, QMouseEvent *); - virtual void editDrag(View *v, QMouseEvent *); - virtual void editEnd(View *v, QMouseEvent *); + virtual void editStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual bool editOpen(View *, QMouseEvent *); + virtual bool editOpen(LayerGeometryProvider *, QMouseEvent *); - virtual void moveSelection(Selection s, int newStartFrame); + virtual void moveSelection(Selection s, sv_frame_t newStartFrame); virtual void resizeSelection(Selection s, Selection newSize); virtual void deleteSelection(Selection s); - virtual void copy(View *v, Selection s, Clipboard &to); - virtual bool paste(View *v, const Clipboard &from, int frameOffset, + virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to); + virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive); virtual const Model *getModel() const { return m_model; } @@ -84,15 +84,15 @@ void setPlotStyle(PlotStyle style); PlotStyle getPlotStyle() const { return m_plotStyle; } - virtual bool isLayerScrollable(const View *v) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; virtual bool isLayerEditable() const { return true; } - virtual int getCompletion(View *) const { return m_model->getCompletion(); } + virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } virtual bool needsTextLabelHeight() const { return m_model->hasTextLabels(); } - virtual bool getValueExtents(float &, float &, bool &, QString &) const { + virtual bool getValueExtents(double &, double &, bool &, QString &) const { return false; } @@ -109,14 +109,14 @@ } } - virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } + virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const { return 0; } protected: - SparseOneDimensionalModel::PointList getLocalPoints(View *v, int) const; + SparseOneDimensionalModel::PointList getLocalPoints(LayerGeometryProvider *v, int) const; virtual int getDefaultColourHint(bool dark, bool &impose); - bool clipboardAlignmentDiffers(View *v, const Clipboard &) const; + bool clipboardAlignmentDiffers(LayerGeometryProvider *v, const Clipboard &) const; SparseOneDimensionalModel *m_model; bool m_editing;
--- a/layer/TimeRulerLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/TimeRulerLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -49,7 +49,7 @@ } bool -TimeRulerLayer::snapToFeatureFrame(View *v, int &frame, +TimeRulerLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { if (!m_model) { @@ -60,7 +60,7 @@ bool q; int tick = getMajorTickSpacing(v, q); RealTime rtick = RealTime::fromMilliseconds(tick); - int rate = m_model->getSampleRate(); + sv_samplerate_t rate = m_model->getSampleRate(); RealTime rt = RealTime::frame2RealTime(frame, rate); double ratio = rt / rtick; @@ -68,9 +68,9 @@ int rounded = int(ratio); RealTime rdrt = rtick * rounded; - int left = RealTime::realTime2Frame(rdrt, rate); - resolution = RealTime::realTime2Frame(rtick, rate); - int right = left + resolution; + sv_frame_t left = RealTime::realTime2Frame(rdrt, rate); + resolution = int(RealTime::realTime2Frame(rtick, rate)); + sv_frame_t right = left + resolution; // SVDEBUG << "TimeRulerLayer::snapToFeatureFrame: type " // << int(snap) << ", frame " << frame << " (time " @@ -88,7 +88,7 @@ case SnapNearest: { - if (abs(frame - left) > abs(right - frame)) { + if (labs(frame - left) > labs(right - frame)) { frame = right; } else { frame = left; @@ -141,24 +141,24 @@ } int -TimeRulerLayer::getMajorTickSpacing(View *v, bool &quarterTicks) const +TimeRulerLayer::getMajorTickSpacing(LayerGeometryProvider *v, bool &quarterTicks) const { // return value is in milliseconds if (!m_model || !v) return 1000; - int sampleRate = m_model->getSampleRate(); + sv_samplerate_t sampleRate = m_model->getSampleRate(); if (!sampleRate) return 1000; - long startFrame = v->getStartFrame(); - long endFrame = v->getEndFrame(); + sv_frame_t startFrame = v->getStartFrame(); + sv_frame_t endFrame = v->getEndFrame(); int minPixelSpacing = 50; RealTime rtStart = RealTime::frame2RealTime(startFrame, sampleRate); RealTime rtEnd = RealTime::frame2RealTime(endFrame, sampleRate); - int count = v->width() / minPixelSpacing; + int count = v->getPaintWidth() / minPixelSpacing; if (count < 1) count = 1; RealTime rtGap = (rtEnd - rtStart) / count; @@ -192,7 +192,7 @@ } void -TimeRulerLayer::paint(View *v, QPainter &paint, QRect rect) const +TimeRulerLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { #ifdef DEBUG_TIME_RULER_LAYER SVDEBUG << "TimeRulerLayer::paint (" << rect.x() << "," << rect.y() @@ -201,10 +201,10 @@ if (!m_model || !m_model->isOK()) return; - int sampleRate = m_model->getSampleRate(); + sv_samplerate_t sampleRate = m_model->getSampleRate(); if (!sampleRate) return; - long startFrame = v->getFrameForX(rect.x() - 50); + sv_frame_t startFrame = v->getFrameForX(rect.x() - 50); #ifdef DEBUG_TIME_RULER_LAYER cerr << "start frame = " << startFrame << endl; @@ -213,7 +213,7 @@ bool quarter = false; int incms = getMajorTickSpacing(v, quarter); - int ms = lrint(1000.0 * (double(startFrame) / double(sampleRate))); + int ms = int(lrint(1000.0 * (double(startFrame) / double(sampleRate)))); ms = (ms / incms) * incms - incms; #ifdef DEBUG_TIME_RULER_LAYER @@ -226,8 +226,8 @@ // draw the actual ticks or lines. int minPixelSpacing = 50; - long incFrame = (incms * sampleRate) / 1000; - int incX = incFrame / v->getZoomLevel(); + sv_frame_t incFrame = lrint((incms * sampleRate) / 1000); + int incX = int(incFrame / v->getZoomLevel()); int ticks = 10; if (incX < minPixelSpacing * 2) { ticks = quarter ? 4 : 5; @@ -249,7 +249,7 @@ // re-drawing with a different start frame). double dms = ms; - long frame = lrint((dms * sampleRate) / 1000.0); + sv_frame_t frame = lrint((dms * sampleRate) / 1000.0); frame /= v->getZoomLevel(); frame *= v->getZoomLevel(); // so frame corresponds to an exact pixel @@ -287,11 +287,11 @@ } paint.setPen(greyColour); - paint.drawLine(x, 0, x, v->height()); + paint.drawLine(x, 0, x, v->getPaintHeight()); paint.setPen(getBaseQColor()); paint.drawLine(x, 0, x, 5); - paint.drawLine(x, v->height() - 6, x, v->height() - 1); + paint.drawLine(x, v->getPaintHeight() - 6, x, v->getPaintHeight() - 1); int y; switch (m_labelHeight) { @@ -300,16 +300,16 @@ y = 6 + metrics.ascent(); break; case LabelMiddle: - y = v->height() / 2 - metrics.height() / 2 + metrics.ascent(); + y = v->getPaintHeight() / 2 - metrics.height() / 2 + metrics.ascent(); break; case LabelBottom: - y = v->height() - metrics.height() + metrics.ascent() - 6; + y = v->getPaintHeight() - metrics.height() + metrics.ascent() - 6; } if (v->getViewManager() && v->getViewManager()->getOverlayMode() != ViewManager::NoOverlays) { - if (v->getLayer(0) == this) { + if (v->getView()->getLayer(0) == this) { // backmost layer, don't worry about outlining the text paint.drawText(x+2 - tw/2, y, text); } else { @@ -344,14 +344,14 @@ if (ticks == 10) { if ((i % 2) == 1) { if (i == 5) { - paint.drawLine(x, 0, x, v->height()); + paint.drawLine(x, 0, x, v->getPaintHeight()); } else sz = 3; } else { sz = 7; } } paint.drawLine(x, 0, x, sz); - paint.drawLine(x, v->height() - sz - 1, x, v->height() - 1); + paint.drawLine(x, v->getPaintHeight() - sz - 1, x, v->getPaintHeight() - 1); } ms += incms;
--- a/layer/TimeRulerLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/TimeRulerLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -32,7 +32,7 @@ public: TimeRulerLayer(); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; void setModel(Model *); virtual const Model *getModel() const { return m_model; } @@ -41,32 +41,34 @@ void setLabelHeight(LabelHeight h) { m_labelHeight = h; } LabelHeight getLabelHeight() const { return m_labelHeight; } - virtual bool snapToFeatureFrame(View *, int &, int &, SnapType) const; + virtual bool snapToFeatureFrame(LayerGeometryProvider *, sv_frame_t &, int &, SnapType) const; virtual ColourSignificance getLayerColourSignificance() const { return ColourIrrelevant; } - virtual bool getValueExtents(float &, float &, bool &, QString &) const { + virtual bool getValueExtents(double &, double &, bool &, QString &) const { return false; } virtual QString getLayerPresentationName() const; - virtual int getVerticalScaleWidth(View *, bool, QPainter &) const { return 0; } + virtual int getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &) const { return 0; } virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; void setProperties(const QXmlAttributes &attributes); + virtual bool canExistWithoutModel() const { return true; } + protected: Model *m_model; LabelHeight m_labelHeight; virtual int getDefaultColourHint(bool dark, bool &impose); - int getMajorTickSpacing(View *, bool &quarterTicks) const; + int getMajorTickSpacing(LayerGeometryProvider *, bool &quarterTicks) const; }; #endif
--- a/layer/TimeValueLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/TimeValueLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -20,6 +20,7 @@ #include "base/Profiler.h" #include "base/LogRange.h" #include "base/RangeMapper.h" +#include "base/Pitch.h" #include "ColourDatabase.h" #include "view/View.h" @@ -315,7 +316,7 @@ } bool -TimeValueLayer::isLayerScrollable(const View *v) const +TimeValueLayer::isLayerScrollable(const LayerGeometryProvider *v) const { // We don't illuminate sections in the line or curve modes, so // they're always scrollable @@ -329,7 +330,7 @@ } bool -TimeValueLayer::getValueExtents(float &min, float &max, +TimeValueLayer::getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const { if (!m_model) return false; @@ -342,7 +343,7 @@ unit = getScaleUnits(); if (m_derivative) { - max = std::max(fabsf(min), fabsf(max)); + max = std::max(fabs(min), fabs(max)); min = -max; } @@ -356,7 +357,7 @@ max = max + 0.5; min = min - 0.5; } else { - float margin = (max - min) / 10.0; + double margin = (max - min) / 10.0; max = max + margin; min = min - margin; } @@ -370,7 +371,7 @@ } bool -TimeValueLayer::getDisplayExtents(float &min, float &max) const +TimeValueLayer::getDisplayExtents(double &min, double &max) const { if (!m_model || shouldAutoAlign()) return false; @@ -384,7 +385,7 @@ } if (m_derivative) { - max = std::max(fabsf(min), fabsf(max)); + max = std::max(fabs(min), fabs(max)); min = -max; } @@ -396,7 +397,7 @@ } bool -TimeValueLayer::setDisplayExtents(float min, float max) +TimeValueLayer::setDisplayExtents(double min, double max) { if (!m_model) return false; @@ -438,7 +439,7 @@ RangeMapper *mapper = getNewVerticalZoomRangeMapper(); if (!mapper) return 0; - float dmin, dmax; + double dmin, dmax; getDisplayExtents(dmin, dmax); int nr = mapper->getPositionForValue(dmax - dmin); @@ -461,23 +462,23 @@ RangeMapper *mapper = getNewVerticalZoomRangeMapper(); if (!mapper) return; - float min, max; + double min, max; bool logarithmic; QString unit; getValueExtents(min, max, logarithmic, unit); - float dmin, dmax; + double dmin, dmax; getDisplayExtents(dmin, dmax); - float newdist = mapper->getValueForPosition(100 - step); + double newdist = mapper->getValueForPosition(100 - step); - float newmin, newmax; + double newmin, newmax; if (logarithmic) { // see SpectrogramLayer::setVerticalZoomStep - newmax = (newdist + sqrtf(newdist*newdist + 4*dmin*dmax)) / 2; + newmax = (newdist + sqrt(newdist*newdist + 4*dmin*dmax)) / 2; newmin = newmax - newdist; #ifdef DEBUG_TIME_VALUE_LAYER @@ -485,7 +486,7 @@ #endif } else { - float dmid = (dmax + dmin) / 2; + double dmid = (dmax + dmin) / 2; newmin = dmid - newdist / 2; newmax = dmid + newdist / 2; } @@ -512,7 +513,7 @@ RangeMapper *mapper; - float min, max; + double min, max; bool logarithmic; QString unit; getValueExtents(min, max, logarithmic, unit); @@ -529,11 +530,11 @@ } SparseTimeValueModel::PointList -TimeValueLayer::getLocalPoints(View *v, int x) const +TimeValueLayer::getLocalPoints(LayerGeometryProvider *v, int x) const { if (!m_model) return SparseTimeValueModel::PointList(); - long frame = v->getFrameForX(x); + sv_frame_t frame = v->getFrameForX(x); SparseTimeValueModel::PointList onPoints = m_model->getPoints(frame); @@ -553,7 +554,7 @@ usePoints = nextPoints; } else if (nextPoints.empty()) { // stick with prevPoints - } else if (long(prevPoints.begin()->frame) < v->getStartFrame() && + } else if (prevPoints.begin()->frame < v->getStartFrame() && !(nextPoints.begin()->frame > v->getEndFrame())) { usePoints = nextPoints; } else if (nextPoints.begin()->frame - frame < @@ -574,7 +575,7 @@ } QString -TimeValueLayer::getLabelPreceding(int frame) const +TimeValueLayer::getLabelPreceding(sv_frame_t frame) const { if (!m_model) return ""; SparseTimeValueModel::PointList points = m_model->getPreviousPoints(frame); @@ -586,7 +587,7 @@ } QString -TimeValueLayer::getFeatureDescription(View *v, QPoint &pos) const +TimeValueLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); @@ -602,24 +603,35 @@ } } - long useFrame = points.begin()->frame; + sv_frame_t useFrame = points.begin()->frame; RealTime rt = RealTime::frame2RealTime(useFrame, m_model->getSampleRate()); + QString valueText; + float value = points.begin()->value; + QString unit = getScaleUnits(); + + if (unit == "Hz") { + valueText = tr("%1 Hz (%2, %3)") + .arg(value) + .arg(Pitch::getPitchLabelForFrequency(value)) + .arg(Pitch::getPitchForFrequency(value)); + } else if (unit != "") { + valueText = tr("%1 %2").arg(value).arg(unit); + } else { + valueText = tr("%1").arg(value); + } + QString text; - QString unit = getScaleUnits(); - if (unit != "") unit = " " + unit; if (points.begin()->label == "") { - text = QString(tr("Time:\t%1\nValue:\t%2%3\nNo label")) + text = QString(tr("Time:\t%1\nValue:\t%2\nNo label")) .arg(rt.toText(true).c_str()) - .arg(points.begin()->value) - .arg(unit); + .arg(valueText); } else { - text = QString(tr("Time:\t%1\nValue:\t%2%3\nLabel:\t%4")) + text = QString(tr("Time:\t%1\nValue:\t%2\nLabel:\t%4")) .arg(rt.toText(true).c_str()) - .arg(points.begin()->value) - .arg(unit) + .arg(valueText) .arg(points.begin()->label); } @@ -629,7 +641,7 @@ } bool -TimeValueLayer::snapToFeatureFrame(View *v, int &frame, +TimeValueLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -649,7 +661,7 @@ } points = m_model->getPoints(frame, frame); - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); @@ -701,7 +713,7 @@ } bool -TimeValueLayer::snapToSimilarFeature(View *v, int &frame, +TimeValueLayer::snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const { @@ -716,8 +728,8 @@ SparseTimeValueModel::PointList::const_iterator i; - int matchframe = frame; - float matchvalue = 0.f; + sv_frame_t matchframe = frame; + double matchvalue = 0.0; for (i = close.begin(); i != close.end(); ++i) { if (i->frame > frame) break; @@ -725,10 +737,10 @@ matchframe = i->frame; } - int snapped = frame; + sv_frame_t snapped = frame; bool found = false; bool distant = false; - float epsilon = 0.0001; + double epsilon = 0.0001; i = close.begin(); @@ -753,7 +765,7 @@ if (snap == SnapRight) { if (i->frame > matchframe && - fabsf(i->value - matchvalue) < epsilon) { + fabs(i->value - matchvalue) < epsilon) { snapped = i->frame; found = true; break; @@ -762,7 +774,7 @@ } else if (snap == SnapLeft) { if (i->frame < matchframe) { - if (fabsf(i->value - matchvalue) < epsilon) { + if (fabs(i->value - matchvalue) < epsilon) { snapped = i->frame; found = true; // don't break, as the next may be better } @@ -782,7 +794,7 @@ } void -TimeValueLayer::getScaleExtents(View *v, float &min, float &max, bool &log) const +TimeValueLayer::getScaleExtents(LayerGeometryProvider *v, double &min, double &max, bool &log) const { min = 0.0; max = 0.0; @@ -818,11 +830,11 @@ } int -TimeValueLayer::getYForValue(View *v, float val) const +TimeValueLayer::getYForValue(LayerGeometryProvider *v, double val) const { - float min = 0.0, max = 0.0; + double min = 0.0, max = 0.0; bool logarithmic = false; - int h = v->height(); + int h = v->getPaintHeight(); getScaleExtents(v, min, max, logarithmic); @@ -838,16 +850,16 @@ return int(h - ((val - min) * h) / (max - min)); } -float -TimeValueLayer::getValueForY(View *v, int y) const +double +TimeValueLayer::getValueForY(LayerGeometryProvider *v, int y) const { - float min = 0.0, max = 0.0; + double min = 0.0, max = 0.0; bool logarithmic = false; - int h = v->height(); + int h = v->getPaintHeight(); getScaleExtents(v, min, max, logarithmic); - float val = min + (float(h - y) * float(max - min)) / h; + double val = min + (double(h - y) * double(max - min)) / h; if (logarithmic) { val = LogRange::map(val); @@ -865,9 +877,9 @@ } QColor -TimeValueLayer::getColourForValue(View *v, float val) const +TimeValueLayer::getColourForValue(LayerGeometryProvider *v, double val) const { - float min, max; + double min, max; bool log; getScaleExtents(v, min, max, log); @@ -896,11 +908,11 @@ } void -TimeValueLayer::paint(View *v, QPainter &paint, QRect rect) const +TimeValueLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) return; - int sampleRate = m_model->getSampleRate(); + sv_samplerate_t sampleRate = m_model->getSampleRate(); if (!sampleRate) return; paint.setRenderHint(QPainter::Antialiasing, false); @@ -908,8 +920,8 @@ // Profiler profiler("TimeValueLayer::paint", true); int x0 = rect.left(), x1 = rect.right(); - long frame0 = v->getFrameForX(x0); - long frame1 = v->getFrameForX(x1); + sv_frame_t frame0 = v->getFrameForX(x0); + sv_frame_t frame1 = v->getFrameForX(x1); if (m_derivative) --frame0; SparseTimeValueModel::PointList points(m_model->getPoints @@ -927,15 +939,15 @@ << m_model->getResolution() << " frames" << endl; #endif - float min = m_model->getValueMinimum(); - float max = m_model->getValueMaximum(); + double min = m_model->getValueMinimum(); + double max = m_model->getValueMaximum(); if (max == min) max = min + 1.0; - int origin = int(nearbyint(v->height() - - (-min * v->height()) / (max - min))); + int origin = int(nearbyint(v->getPaintHeight() - + (-min * v->getPaintHeight()) / (max - min))); QPoint localPos; - long illuminateFrame = -1; + sv_frame_t illuminateFrame = -1; if (v->shouldIlluminateLocalFeatures(this, localPos)) { SparseTimeValueModel::PointList localPoints = @@ -966,7 +978,7 @@ textY = v->getTextLabelHeight(this, paint); } else { int originY = getYForValue(v, 0.f); - if (originY > 0 && originY < v->height()) { + if (originY > 0 && originY < v->getPaintHeight()) { paint.save(); paint.setPen(getPartialShades(v)[1]); paint.drawLine(x0, originY, x1, originY); @@ -974,7 +986,7 @@ } } - int prevFrame = 0; + sv_frame_t prevFrame = 0; for (SparseTimeValueModel::PointList::const_iterator i = points.begin(); i != points.end(); ++i) { @@ -983,7 +995,7 @@ const SparseTimeValueModel::Point &p(*i); - float value = p.value; + double value = p.value; if (m_derivative) { SparseTimeValueModel::PointList::const_iterator j = i; --j; @@ -1012,8 +1024,8 @@ } bool haveNext = false; - float nvalue = 0.f; - int nf = v->getModelsEndFrame(); + double nvalue = 0.f; + sv_frame_t nf = v->getModelsEndFrame(); int nx = v->getXForFrame(nf); int ny = y; @@ -1122,11 +1134,11 @@ } else { - float x0 = x + float(w)/2; - float x1 = nx + float(w)/2; + double x0 = x + double(w)/2; + double x1 = nx + double(w)/2; - float y0 = y; - float y1 = ny; + double y0 = y; + double y1 = ny; if (m_plotStyle == PlotDiscreteCurves) { bool nextGap = @@ -1151,6 +1163,7 @@ // path.quadTo(x0, y0, (x0 + x1) / 2, (y0 + y1) / 2); } else { + path.lineTo(x0, y0); path.lineTo((x0 + x1) / 2, (y0 + y1) / 2); } } @@ -1170,12 +1183,12 @@ if (!illuminate) { if (!m_drawSegmentDivisions || nx < x + 5 || - x >= v->width() - 1) { + x >= v->getPaintWidth() - 1) { paint.setPen(Qt::NoPen); } } - paint.drawRect(x, -1, nx - x, v->height() + 1); + paint.drawRect(x, -1, nx - x, v->getPaintHeight() + 1); } if (v->shouldShowFeatureLabels()) { @@ -1218,7 +1231,7 @@ paint.drawPath(path); } else if ((m_plotStyle == PlotCurve || m_plotStyle == PlotLines) && !path.isEmpty()) { - paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->width()); + paint.setRenderHint(QPainter::Antialiasing, pointCount <= v->getPaintWidth()); paint.drawPath(path); } @@ -1229,7 +1242,7 @@ } int -TimeValueLayer::getVerticalScaleWidth(View *v, bool, QPainter &paint) const +TimeValueLayer::getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &paint) const { if (!m_model || shouldAutoAlign()) { return 0; @@ -1249,16 +1262,16 @@ } void -TimeValueLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect) const +TimeValueLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect) const { if (!m_model || m_model->getPoints().empty()) return; QString unit; - float min, max; + double min, max; bool logarithmic; int w = getVerticalScaleWidth(v, false, paint); - int h = v->height(); + int h = v->getPaintHeight(); if (m_plotStyle == PlotSegmentation) { @@ -1301,7 +1314,7 @@ } void -TimeValueLayer::drawStart(View *v, QMouseEvent *e) +TimeValueLayer::drawStart(LayerGeometryProvider *v, QMouseEvent *e) { #ifdef DEBUG_TIME_VALUE_LAYER cerr << "TimeValueLayer::drawStart(" << e->x() << "," << e->y() << ")" << endl; @@ -1309,12 +1322,12 @@ if (!m_model) return; - long frame = v->getFrameForX(e->x()); - long resolution = m_model->getResolution(); + sv_frame_t frame = v->getFrameForX(e->x()); + int resolution = m_model->getResolution(); if (frame < 0) frame = 0; frame = (frame / resolution) * resolution; - float value = getValueForY(v, e->y()); + double value = getValueForY(v, e->y()); bool havePoint = false; @@ -1335,7 +1348,7 @@ if (!havePoint) { m_editingPoint = SparseTimeValueModel::Point - (frame, value, tr("New Point")); + (frame, float(value), tr("New Point")); } m_originalPoint = m_editingPoint; @@ -1351,7 +1364,7 @@ } void -TimeValueLayer::drawDrag(View *v, QMouseEvent *e) +TimeValueLayer::drawDrag(LayerGeometryProvider *v, QMouseEvent *e) { #ifdef DEBUG_TIME_VALUE_LAYER cerr << "TimeValueLayer::drawDrag(" << e->x() << "," << e->y() << ")" << endl; @@ -1359,12 +1372,12 @@ if (!m_model || !m_editing) return; - long frame = v->getFrameForX(e->x()); - long resolution = m_model->getResolution(); + sv_frame_t frame = v->getFrameForX(e->x()); + int resolution = m_model->getResolution(); if (frame < 0) frame = 0; frame = (frame / resolution) * resolution; - float value = getValueForY(v, e->y()); + double value = getValueForY(v, e->y()); SparseTimeValueModel::PointList points = getLocalPoints(v, e->x()); @@ -1408,12 +1421,12 @@ // m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = frame; - m_editingPoint.value = value; + m_editingPoint.value = float(value); m_editingCommand->addPoint(m_editingPoint); } void -TimeValueLayer::drawEnd(View *, QMouseEvent *) +TimeValueLayer::drawEnd(LayerGeometryProvider *, QMouseEvent *) { #ifdef DEBUG_TIME_VALUE_LAYER cerr << "TimeValueLayer::drawEnd" << endl; @@ -1425,7 +1438,7 @@ } void -TimeValueLayer::eraseStart(View *v, QMouseEvent *e) +TimeValueLayer::eraseStart(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return; @@ -1443,12 +1456,12 @@ } void -TimeValueLayer::eraseDrag(View *, QMouseEvent *) +TimeValueLayer::eraseDrag(LayerGeometryProvider *, QMouseEvent *) { } void -TimeValueLayer::eraseEnd(View *v, QMouseEvent *e) +TimeValueLayer::eraseEnd(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model || !m_editing) return; @@ -1470,7 +1483,7 @@ } void -TimeValueLayer::editStart(View *v, QMouseEvent *e) +TimeValueLayer::editStart(LayerGeometryProvider *v, QMouseEvent *e) { #ifdef DEBUG_TIME_VALUE_LAYER cerr << "TimeValueLayer::editStart(" << e->x() << "," << e->y() << ")" << endl; @@ -1493,7 +1506,7 @@ } void -TimeValueLayer::editDrag(View *v, QMouseEvent *e) +TimeValueLayer::editDrag(LayerGeometryProvider *v, QMouseEvent *e) { #ifdef DEBUG_TIME_VALUE_LAYER cerr << "TimeValueLayer::editDrag(" << e->x() << "," << e->y() << ")" << endl; @@ -1501,11 +1514,11 @@ if (!m_model || !m_editing) return; - long frame = v->getFrameForX(e->x()); + sv_frame_t frame = v->getFrameForX(e->x()); if (frame < 0) frame = 0; frame = frame / m_model->getResolution() * m_model->getResolution(); - float value = getValueForY(v, e->y()); + double value = getValueForY(v, e->y()); if (!m_editingCommand) { m_editingCommand = new SparseTimeValueModel::EditCommand(m_model, @@ -1514,12 +1527,12 @@ m_editingCommand->deletePoint(m_editingPoint); m_editingPoint.frame = frame; - m_editingPoint.value = value; + m_editingPoint.value = float(value); m_editingCommand->addPoint(m_editingPoint); } void -TimeValueLayer::editEnd(View *, QMouseEvent *) +TimeValueLayer::editEnd(LayerGeometryProvider *, QMouseEvent *) { #ifdef DEBUG_TIME_VALUE_LAYER cerr << "TimeValueLayer::editEnd" << endl; @@ -1549,7 +1562,7 @@ } bool -TimeValueLayer::editOpen(View *v, QMouseEvent *e) +TimeValueLayer::editOpen(LayerGeometryProvider *v, QMouseEvent *e) { if (!m_model) return false; @@ -1588,7 +1601,7 @@ } void -TimeValueLayer::moveSelection(Selection s, int newStartFrame) +TimeValueLayer::moveSelection(Selection s, sv_frame_t newStartFrame) { if (!m_model) return; @@ -1634,9 +1647,9 @@ if (s.contains(i->frame)) { - double target = i->frame; - target = newSize.getStartFrame() + - double(target - s.getStartFrame()) * ratio; + double target = double(i->frame); + target = double(newSize.getStartFrame()) + + target - double(s.getStartFrame()) * ratio; SparseTimeValueModel::Point newPoint(*i); newPoint.frame = lrint(target); @@ -1672,7 +1685,7 @@ } void -TimeValueLayer::copy(View *v, Selection s, Clipboard &to) +TimeValueLayer::copy(LayerGeometryProvider *v, Selection s, Clipboard &to) { if (!m_model) return; @@ -1690,7 +1703,7 @@ } bool -TimeValueLayer::paste(View *v, const Clipboard &from, int /* frameOffset */, +TimeValueLayer::paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t /* frameOffset */, bool interactive) { if (!m_model) return false; @@ -1702,7 +1715,7 @@ if (clipboardHasDifferentAlignment(v, from)) { QMessageBox::StandardButton button = - QMessageBox::question(v, tr("Re-align pasted items?"), + QMessageBox::question(v->getView(), tr("Re-align pasted items?"), tr("The items you are pasting came from a layer with different source material from this one. Do you want to re-align them in time, to match the source material for this layer?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes); @@ -1833,7 +1846,7 @@ if (!i->haveFrame()) continue; - int frame = 0; + sv_frame_t frame = 0; if (!realign) {
--- a/layer/TimeValueLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/TimeValueLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -37,41 +37,41 @@ public: TimeValueLayer(); - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual int getVerticalScaleWidth(View *v, bool, QPainter &) const; - virtual void paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const; + virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool, QPainter &) const; + virtual void paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; - virtual QString getLabelPreceding(int) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; + virtual QString getLabelPreceding(sv_frame_t) const; - virtual bool snapToFeatureFrame(View *v, int &frame, + virtual bool snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual bool snapToSimilarFeature(View *v, int &frame, + virtual bool snapToSimilarFeature(LayerGeometryProvider *v, sv_frame_t &frame, int &resolution, SnapType snap) const; - virtual void drawStart(View *v, QMouseEvent *); - virtual void drawDrag(View *v, QMouseEvent *); - virtual void drawEnd(View *v, QMouseEvent *); + virtual void drawStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void drawEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void eraseStart(View *v, QMouseEvent *); - virtual void eraseDrag(View *v, QMouseEvent *); - virtual void eraseEnd(View *v, QMouseEvent *); + virtual void eraseStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void eraseEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual void editStart(View *v, QMouseEvent *); - virtual void editDrag(View *v, QMouseEvent *); - virtual void editEnd(View *v, QMouseEvent *); + virtual void editStart(LayerGeometryProvider *v, QMouseEvent *); + virtual void editDrag(LayerGeometryProvider *v, QMouseEvent *); + virtual void editEnd(LayerGeometryProvider *v, QMouseEvent *); - virtual bool editOpen(View *v, QMouseEvent *); + virtual bool editOpen(LayerGeometryProvider *v, QMouseEvent *); - virtual void moveSelection(Selection s, int newStartFrame); + virtual void moveSelection(Selection s, sv_frame_t newStartFrame); virtual void resizeSelection(Selection s, Selection newSize); virtual void deleteSelection(Selection s); - virtual void copy(View *v, Selection s, Clipboard &to); - virtual bool paste(View *v, const Clipboard &from, int frameOffset, + virtual void copy(LayerGeometryProvider *v, Selection s, Clipboard &to); + virtual bool paste(LayerGeometryProvider *v, const Clipboard &from, sv_frame_t frameOffset, bool interactive); virtual const Model *getModel() const { return m_model; } @@ -120,21 +120,21 @@ void setShowDerivative(bool); bool getShowDerivative() const { return m_derivative; } - virtual bool isLayerScrollable(const View *v) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *v) const; virtual bool isLayerEditable() const { return true; } - virtual int getCompletion(View *) const { return m_model->getCompletion(); } + virtual int getCompletion(LayerGeometryProvider *) const { return m_model->getCompletion(); } virtual bool needsTextLabelHeight() const { return m_plotStyle == PlotSegmentation && m_model->hasTextLabels(); } - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &logarithmic, QString &unit) const; - virtual bool getDisplayExtents(float &min, float &max) const; - virtual bool setDisplayExtents(float min, float max); + virtual bool getDisplayExtents(double &min, double &max) const; + virtual bool setDisplayExtents(double min, double max); virtual int getVerticalZoomSteps(int &defaultStep) const; virtual int getCurrentVerticalZoomStep() const; @@ -155,16 +155,16 @@ } /// VerticalScaleLayer and ColourScaleLayer methods - virtual int getYForValue(View *, float value) const; - virtual float getValueForY(View *, int y) const; + virtual int getYForValue(LayerGeometryProvider *, double value) const; + virtual double getValueForY(LayerGeometryProvider *, int y) const; virtual QString getScaleUnits() const; - virtual QColor getColourForValue(View *v, float value) const; + virtual QColor getColourForValue(LayerGeometryProvider *v, double value) const; protected: - void getScaleExtents(View *, float &min, float &max, bool &log) const; + void getScaleExtents(LayerGeometryProvider *, double &min, double &max, bool &log) const; bool shouldAutoAlign() const; - SparseTimeValueModel::PointList getLocalPoints(View *v, int) const; + SparseTimeValueModel::PointList getLocalPoints(LayerGeometryProvider *v, int) const; virtual int getDefaultColourHint(bool dark, bool &impose); @@ -179,8 +179,8 @@ bool m_drawSegmentDivisions; bool m_derivative; - mutable float m_scaleMinimum; - mutable float m_scaleMaximum; + mutable double m_scaleMinimum; + mutable double m_scaleMaximum; void finish(SparseTimeValueModel::EditCommand *command) { Command *c = command->finish();
--- a/layer/VerticalScaleLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/VerticalScaleLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -19,8 +19,8 @@ class VerticalScaleLayer { public: - virtual int getYForValue(View *, float value) const = 0; - virtual float getValueForY(View *, int y) const = 0; + virtual int getYForValue(LayerGeometryProvider *, double value) const = 0; + virtual double getValueForY(LayerGeometryProvider *, int y) const = 0; virtual QString getScaleUnits() const = 0; };
--- a/layer/WaveformLayer.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/WaveformLayer.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -153,7 +153,7 @@ *max = 50; *deflt = 0; - val = lrint(log10(m_gain) * 20.0); + val = int(lrint(log10(m_gain) * 20.0)); if (val < *min) val = *min; if (val > *max) val = *max; @@ -222,7 +222,7 @@ WaveformLayer::setProperty(const PropertyName &name, int value) { if (name == "Gain") { - setGain(pow(10, float(value)/20.0)); + setGain(float(pow(10, float(value)/20.0))); } else if (name == "Normalize Visible Area") { setAutoNormalize(value ? true : false); } else if (name == "Channels") { @@ -308,7 +308,7 @@ } void -WaveformLayer::setMiddleLineHeight(float height) +WaveformLayer::setMiddleLineHeight(double height) { if (m_middleLineHeight == height) return; m_middleLineHeight = height; @@ -326,7 +326,7 @@ } int -WaveformLayer::getCompletion(View *) const +WaveformLayer::getCompletion(LayerGeometryProvider *) const { int completion = 100; if (!m_model || !m_model->isOK()) return completion; @@ -335,7 +335,7 @@ } bool -WaveformLayer::getValueExtents(float &min, float &max, +WaveformLayer::getValueExtents(double &min, double &max, bool &, QString &unit) const { if (m_scale == LinearScale) { @@ -353,10 +353,10 @@ } int -WaveformLayer::dBscale(float sample, int m) const +WaveformLayer::dBscale(double sample, int m) const { if (sample < 0.0) return dBscale(-sample, m); - float dB = AudioLevel::multiplier_to_dB(sample); + double dB = AudioLevel::multiplier_to_dB(sample); if (dB < -50.0) return 0; if (dB > 0.0) return m; return int(((dB + 50.0) * m) / 50.0 + 0.1); @@ -399,7 +399,7 @@ } bool -WaveformLayer::isLayerScrollable(const View *) const +WaveformLayer::isLayerScrollable(const LayerGeometryProvider *) const { return !m_autoNormalize; } @@ -408,10 +408,10 @@ -5, -3, -2, -1, -0.5, 0 }; bool -WaveformLayer::getSourceFramesForX(View *v, int x, int modelZoomLevel, - int &f0, int &f1) const +WaveformLayer::getSourceFramesForX(LayerGeometryProvider *v, int x, int modelZoomLevel, + sv_frame_t &f0, sv_frame_t &f1) const { - int viewFrame = v->getFrameForX(x); + sv_frame_t viewFrame = v->getFrameForX(x); if (viewFrame < 0) { f0 = 0; f1 = 0; @@ -433,15 +433,15 @@ } float -WaveformLayer::getNormalizeGain(View *v, int channel) const +WaveformLayer::getNormalizeGain(LayerGeometryProvider *v, int channel) const { - int startFrame = v->getStartFrame(); - int endFrame = v->getEndFrame(); + sv_frame_t startFrame = v->getStartFrame(); + sv_frame_t endFrame = v->getEndFrame(); - int modelStart = m_model->getStartFrame(); - int modelEnd = m_model->getEndFrame(); + sv_frame_t modelStart = m_model->getStartFrame(); + sv_frame_t modelEnd = m_model->getEndFrame(); - int rangeStart, rangeEnd; + sv_frame_t rangeStart, rangeEnd; if (startFrame < modelStart) rangeStart = modelStart; else rangeStart = startFrame; @@ -469,11 +469,11 @@ range.setAbsmean(std::min(range.absmean(), otherRange.absmean())); } - return 1.0 / std::max(fabsf(range.max()), fabsf(range.min())); + return float(1.0 / std::max(fabs(range.max()), fabs(range.min()))); } void -WaveformLayer::paint(View *v, QPainter &viewPainter, QRect rect) const +WaveformLayer::paint(LayerGeometryProvider *v, QPainter &viewPainter, QRect rect) const { if (!m_model || !m_model->isOK()) { return; @@ -494,8 +494,8 @@ mergingChannels, mixingChannels); if (channels == 0) return; - int w = v->width(); - int h = v->height(); + int w = v->getPaintWidth(); + int h = v->getPaintHeight(); bool ready = m_model->isReady(); QPainter *paint; @@ -543,9 +543,9 @@ if (m_middleLineHeight != 0.5) { paint->save(); - float space = m_middleLineHeight * 2; + double space = m_middleLineHeight * 2; if (space > 1.0) space = 2.0 - space; - float yt = h * (m_middleLineHeight - space/2); + double yt = h * (m_middleLineHeight - space/2); paint->translate(QPointF(0, yt)); paint->scale(1.0, space); } @@ -559,7 +559,7 @@ y1 = rect.bottom(); if (x0 > 0) --x0; - if (x1 < v->width()) ++x1; + if (x1 < w) ++x1; // Our zoom level may differ from that at which the underlying // model has its blocks. @@ -572,9 +572,9 @@ int modelZoomLevel = m_model->getSummaryBlockSize(zoomLevel); - int frame0; - int frame1; - int spare; + sv_frame_t frame0; + sv_frame_t frame1; + sv_frame_t spare; getSourceFramesForX(v, x0, modelZoomLevel, frame0, spare); getSourceFramesForX(v, x1, modelZoomLevel, spare, frame1); @@ -616,7 +616,7 @@ m_effectiveGains[ch] = getNormalizeGain(v, ch); } - float gain = m_effectiveGains[ch]; + double gain = m_effectiveGains[ch]; int m = (h / channels) / 2; int my = m + (((ch - minChannel) * h) / channels); @@ -647,7 +647,7 @@ for (int i = 1; i < n; ++i) { - float val = 0.0, nval = 0.0; + double val = 0.0, nval = 0.0; switch (m_scale) { @@ -710,7 +710,7 @@ range = RangeSummarisableTimeValueModel::Range(); - int f0, f1; + sv_frame_t f0, f1; if (!getSourceFramesForX(v, x, modelZoomLevel, f0, f1)) continue; f1 = f1 - 1; @@ -719,8 +719,8 @@ continue; } - int i0 = (f0 - frame0) / modelZoomLevel; - int i1 = (f1 - frame0) / modelZoomLevel; + sv_frame_t i0 = (f0 - frame0) / modelZoomLevel; + sv_frame_t i1 = (f1 - frame0) / modelZoomLevel; #ifdef DEBUG_WAVEFORM_PAINT cerr << "WaveformLayer::paint: pixel " << x << ": i0 " << i0 << " (f " << f0 << "), i1 " << i1 << " (f " << f1 << ")" << endl; @@ -784,10 +784,10 @@ switch (m_scale) { case LinearScale: - rangeBottom = int( m * greyLevels * range.min() * gain); - rangeTop = int( m * greyLevels * range.max() * gain); - meanBottom = int(-m * range.absmean() * gain); - meanTop = int( m * range.absmean() * gain); + rangeBottom = int(double(m * greyLevels) * range.min() * gain); + rangeTop = int(double(m * greyLevels) * range.max() * gain); + meanBottom = int(double(-m) * range.absmean() * gain); + meanTop = int(double(m) * range.absmean() * gain); break; case dBScale: @@ -939,7 +939,7 @@ if (m_aggressive) { - if (ready && rect == v->rect()) { + if (ready && rect == v->getPaintRect()) { m_cacheValid = true; m_cacheZoomLevel = zoomLevel; } @@ -953,7 +953,7 @@ } QString -WaveformLayer::getFeatureDescription(View *v, QPoint &pos) const +WaveformLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const { int x = pos.x(); @@ -963,7 +963,7 @@ int modelZoomLevel = m_model->getSummaryBlockSize(zoomLevel); - int f0, f1; + sv_frame_t f0, f1; if (!getSourceFramesForX(v, x, modelZoomLevel, f0, f1)) return ""; QString text; @@ -1005,18 +1005,18 @@ } bool singleValue = false; - float min, max; + double min, max; if (fabs(range.min()) < 0.01) { min = range.min(); max = range.max(); singleValue = (min == max); } else { - int imin = lrint(range.min() * 10000); - int imax = lrint(range.max() * 10000); + int imin = int(lrint(range.min() * 10000)); + int imax = int(lrint(range.max() * 10000)); singleValue = (imin == imax); - min = float(imin)/10000; - max = float(imax)/10000; + min = double(imin)/10000; + max = double(imax)/10000; } int db = int(AudioLevel::multiplier_to_dB(std::max(fabsf(range.min()), @@ -1025,10 +1025,10 @@ if (!singleValue) { text += tr("\n%1\t%2 - %3 (%4 dB peak)") - .arg(label).arg(min).arg(max).arg(float(db)/100); + .arg(label).arg(min).arg(max).arg(double(db)/100); } else { text += tr("\n%1\t%2 (%3 dB peak)") - .arg(label).arg(min).arg(float(db)/100); + .arg(label).arg(min).arg(double(db)/100); } } @@ -1036,7 +1036,7 @@ } int -WaveformLayer::getYForValue(const View *v, float value, int channel) const +WaveformLayer::getYForValue(const LayerGeometryProvider *v, double value, int channel) const { int channels = 0, minChannel = 0, maxChannel = 0; bool mergingChannels = false, mixingChannels = false; @@ -1046,7 +1046,7 @@ if (channels == 0) return 0; if (maxChannel < minChannel || channel < minChannel) return 0; - int h = v->height(); + int h = v->getPaintHeight(); int m = (h / channels) / 2; if ((m_scale == dBScale || m_scale == MeterScale) && @@ -1078,8 +1078,8 @@ return my - vy; } -float -WaveformLayer::getValueForY(const View *v, int y, int &channel) const +double +WaveformLayer::getValueForY(const LayerGeometryProvider *v, int y, int &channel) const { int channels = 0, minChannel = 0, maxChannel = 0; bool mergingChannels = false, mixingChannels = false; @@ -1089,7 +1089,7 @@ if (channels == 0) return 0; if (maxChannel < minChannel) return 0; - int h = v->height(); + int h = v->getPaintHeight(); int m = (h / channels) / 2; if ((m_scale == dBScale || m_scale == MeterScale) && @@ -1102,13 +1102,13 @@ int my = m + (((channel - minChannel) * h) / channels); int vy = my - y; - float value = 0; - float thresh = -50.f; + double value = 0; + double thresh = -50.f; switch (m_scale) { case LinearScale: - value = float(vy) / m; + value = double(vy) / m; break; case MeterScale: @@ -1116,7 +1116,7 @@ break; case dBScale: - value = (-thresh * float(vy)) / m + thresh; + value = (-thresh * double(vy)) / m + thresh; value = AudioLevel::dB_to_multiplier(value); break; } @@ -1125,8 +1125,8 @@ } bool -WaveformLayer::getYScaleValue(const View *v, int y, - float &value, QString &unit) const +WaveformLayer::getYScaleValue(const LayerGeometryProvider *v, int y, + double &value, QString &unit) const { int channel; @@ -1134,10 +1134,10 @@ if (m_scale == dBScale || m_scale == MeterScale) { - float thresh = -50.f; + double thresh = -50.f; - if (value > 0.f) { - value = 10.f * log10f(value); + if (value > 0.0) { + value = 10.0 * log10(value); if (value < thresh) value = thresh; } else value = thresh; @@ -1151,37 +1151,37 @@ } bool -WaveformLayer::getYScaleDifference(const View *v, int y0, int y1, - float &diff, QString &unit) const +WaveformLayer::getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1, + double &diff, QString &unit) const { int c0, c1; - float v0 = getValueForY(v, y0, c0); - float v1 = getValueForY(v, y1, c1); + double v0 = getValueForY(v, y0, c0); + double v1 = getValueForY(v, y1, c1); if (c0 != c1) { // different channels, not comparable - diff = 0.f; + diff = 0.0; unit = ""; return false; } if (m_scale == dBScale || m_scale == MeterScale) { - float thresh = -50.f; + double thresh = -50.0; if (v1 == v0) diff = thresh; else { if (v1 > v0) diff = v0 / v1; else diff = v1 / v0; - diff = 10.f * log10f(diff); + diff = 10.0 * log10(diff); if (diff < thresh) diff = thresh; } unit = "dBV"; } else { - diff = fabsf(v1 - v0); + diff = fabs(v1 - v0); unit = "V"; } @@ -1189,7 +1189,7 @@ } int -WaveformLayer::getVerticalScaleWidth(View *, bool, QPainter &paint) const +WaveformLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const { if (m_scale == LinearScale) { return paint.fontMetrics().width("0.0") + 13; @@ -1200,7 +1200,7 @@ } void -WaveformLayer::paintVerticalScale(View *v, bool, QPainter &paint, QRect rect) const +WaveformLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const { if (!m_model || !m_model->isOK()) { return; @@ -1217,7 +1217,7 @@ int textHeight = paint.fontMetrics().height(); int toff = -textHeight/2 + paint.fontMetrics().ascent() + 1; - float gain = m_gain; + double gain = m_gain; for (int ch = minChannel; ch <= maxChannel; ++ch) { @@ -1229,14 +1229,14 @@ for (int i = 0; i <= n; ++i) { - float val = 0.0, nval = 0.0; + double val = 0.0, nval = 0.0; QString text = ""; switch (m_scale) { case LinearScale: val = (i * gain) / n; - text = QString("%1").arg(float(i) / n); + text = QString("%1").arg(double(i) / n); if (i == 0) text = "0.0"; else { nval = -val; @@ -1402,7 +1402,7 @@ int WaveformLayer::getCurrentVerticalZoomStep() const { - int val = lrint(log10(m_gain) * 20.0) + 50; + int val = int(lrint(log10(m_gain) * 20.0) + 50); if (val < 0) val = 0; if (val > 100) val = 100; return val; @@ -1411,6 +1411,6 @@ void WaveformLayer::setVerticalZoomStep(int step) { - setGain(pow(10, float(step - 50) / 20.0)); + setGain(powf(10, float(step - 50) / 20.f)); }
--- a/layer/WaveformLayer.h Fri Sep 12 11:38:55 2014 +0100 +++ b/layer/WaveformLayer.h Fri Jun 26 14:13:31 2015 +0100 @@ -38,16 +38,16 @@ return m_model ? m_model->getZoomConstraint() : 0; } virtual const Model *getModel() const { return m_model; } - virtual void paint(View *v, QPainter &paint, QRect rect) const; + virtual void paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const; - virtual QString getFeatureDescription(View *v, QPoint &) const; + virtual QString getFeatureDescription(LayerGeometryProvider *v, QPoint &) const; virtual ColourSignificance getLayerColourSignificance() const { return ColourAndBackgroundSignificant; } - virtual int getVerticalScaleWidth(View *v, bool detailed, QPainter &) const; - virtual void paintVerticalScale(View *v, bool detailed, QPainter &paint, QRect rect) const; + virtual int getVerticalScaleWidth(LayerGeometryProvider *v, bool detailed, QPainter &) const; + virtual void paintVerticalScale(LayerGeometryProvider *v, bool detailed, QPainter &paint, QRect rect) const; void setModel(const RangeSummarisableTimeValueModel *model); @@ -156,8 +156,8 @@ * bottom; the default value of 0.5 indicates that it occupies the * whole layer, centred at the middle. */ - void setMiddleLineHeight(float height); - float getMiddleLineHeight() const { return m_middleLineHeight; } + void setMiddleLineHeight(double); + double getMiddleLineHeight() const { return m_middleLineHeight; } /** * Enable or disable aggressive pixmap cacheing. If enabled, @@ -180,18 +180,18 @@ void setAggressiveCacheing(bool); bool getAggressiveCacheing() const { return m_aggressive; } - virtual bool isLayerScrollable(const View *) const; + virtual bool isLayerScrollable(const LayerGeometryProvider *) const; - virtual int getCompletion(View *) const; + virtual int getCompletion(LayerGeometryProvider *) const; - virtual bool getValueExtents(float &min, float &max, + virtual bool getValueExtents(double &min, double &max, bool &log, QString &unit) const; - virtual bool getYScaleValue(const View *v, int y, - float &value, QString &unit) const; + virtual bool getYScaleValue(const LayerGeometryProvider *v, int y, + double &value, QString &unit) const; - virtual bool getYScaleDifference(const View *v, int y0, int y1, - float &diff, QString &unit) const; + virtual bool getYScaleDifference(const LayerGeometryProvider *v, int y0, int y1, + double &diff, QString &unit) const; virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; @@ -202,8 +202,10 @@ virtual int getCurrentVerticalZoomStep() const; virtual void setVerticalZoomStep(int); + virtual bool canExistWithoutModel() const { return true; } + protected: - int dBscale(float sample, int m) const; + int dBscale(double sample, int m) const; const RangeSummarisableTimeValueModel *m_model; // I do not own this @@ -211,14 +213,14 @@ int getChannelArrangement(int &min, int &max, bool &merging, bool &mixing) const; - int getYForValue(const View *v, float value, int channel) const; + int getYForValue(const LayerGeometryProvider *v, double value, int channel) const; - float getValueForY(const View *v, int y, int &channel) const; + double getValueForY(const LayerGeometryProvider *v, int y, int &channel) const; - bool getSourceFramesForX(View *v, int x, int modelZoomLevel, - int &f0, int &f1) const; + bool getSourceFramesForX(LayerGeometryProvider *v, int x, int modelZoomLevel, + sv_frame_t &f0, sv_frame_t &f1) const; - float getNormalizeGain(View *v, int channel) const; + float getNormalizeGain(LayerGeometryProvider *v, int channel) const; virtual void flagBaseColourChanged() { m_cacheValid = false; } @@ -229,7 +231,7 @@ ChannelMode m_channelMode; int m_channel; Scale m_scale; - float m_middleLineHeight; + double m_middleLineHeight; bool m_aggressive; mutable std::vector<float> m_effectiveGains;
--- a/svgui.pro Fri Sep 12 11:38:55 2014 +0100 +++ b/svgui.pro Fri Jun 26 14:13:31 2015 +0100 @@ -25,8 +25,8 @@ DEFINES += HAVE_BZ2 HAVE_FFTW3 HAVE_FFTW3F HAVE_SNDFILE HAVE_SAMPLERATE HAVE_VAMP HAVE_VAMPHOSTSDK HAVE_RUBBERBAND HAVE_LIBLO HAVE_MAD HAVE_ID3TAG } -CONFIG += staticlib qt thread warn_on stl rtti exceptions -QT += network xml gui widgets +CONFIG += staticlib qt thread warn_on stl rtti exceptions c++11 +QT += network xml gui widgets svg TARGET = svgui @@ -93,7 +93,8 @@ view/Pane.h \ view/PaneStack.h \ view/View.h \ - view/ViewManager.h + view/ViewManager.h \ + view/ViewProxy.h SOURCES += view/Overview.cpp \ view/Pane.cpp \ view/PaneStack.cpp \ @@ -116,6 +117,8 @@ widgets/LayerTree.h \ widgets/LayerTreeDialog.h \ widgets/LEDButton.h \ + widgets/LevelPanToolButton.h \ + widgets/LevelPanWidget.h \ widgets/ListInputDialog.h \ widgets/MIDIFileImportDialog.h \ widgets/ModelDataTableDialog.h \ @@ -136,6 +139,7 @@ widgets/Thumbwheel.h \ widgets/TipDialog.h \ widgets/TransformFinder.h \ + widgets/UnitConverter.h \ widgets/WindowShapePreview.h \ widgets/WindowTypeSelector.h SOURCES += widgets/ActivityLog.cpp \ @@ -153,6 +157,8 @@ widgets/LayerTree.cpp \ widgets/LayerTreeDialog.cpp \ widgets/LEDButton.cpp \ + widgets/LevelPanToolButton.cpp \ + widgets/LevelPanWidget.cpp \ widgets/ListInputDialog.cpp \ widgets/MIDIFileImportDialog.cpp \ widgets/ModelDataTableDialog.cpp \ @@ -173,5 +179,6 @@ widgets/Thumbwheel.cpp \ widgets/TipDialog.cpp \ widgets/TransformFinder.cpp \ + widgets/UnitConverter.cpp \ widgets/WindowShapePreview.cpp \ widgets/WindowTypeSelector.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/view/LayerGeometryProvider.h Fri Jun 26 14:13:31 2015 +0100 @@ -0,0 +1,130 @@ +/* -*- 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 LAYER_GEOMETRY_PROVIDER_H +#define LAYER_GEOMETRY_PROVIDER_H + +#include "base/BaseTypes.h" + +class ViewManager; +class View; +class Layer; + +class LayerGeometryProvider +{ +public: + /** + * Retrieve the first visible sample frame on the widget. + * This is a calculated value based on the centre-frame, widget + * width and zoom level. The result may be negative. + */ + virtual sv_frame_t getStartFrame() const = 0; + + /** + * Return the centre frame of the visible widget. This is an + * exact value that does not depend on the zoom block size. Other + * frame values (start, end) are calculated from this based on the + * zoom and other factors. + */ + virtual sv_frame_t getCentreFrame() const = 0; + + /** + * Retrieve the last visible sample frame on the widget. + * This is a calculated value based on the centre-frame, widget + * width and zoom level. + */ + virtual sv_frame_t getEndFrame() const = 0; + + /** + * Return the pixel x-coordinate corresponding to a given sample + * frame (which may be negative). + */ + virtual int getXForFrame(sv_frame_t frame) const = 0; + + /** + * Return the closest frame to the given pixel x-coordinate. + */ + virtual sv_frame_t getFrameForX(int x) const = 0; + + virtual sv_frame_t getModelsStartFrame() const = 0; + virtual sv_frame_t getModelsEndFrame() const = 0; + + /** + * Return the pixel y-coordinate corresponding to a given + * frequency, if the frequency range is as specified. This does + * not imply any policy about layer frequency ranges, but it might + * be useful for layers to match theirs up if desired. + * + * Not thread-safe in logarithmic mode. Call only from GUI thread. + */ + virtual double getYForFrequency(double frequency, double minFreq, double maxFreq, + bool logarithmic) const = 0; + + /** + * Return the closest frequency to the given pixel y-coordinate, + * if the frequency range is as specified. + * + * Not thread-safe in logarithmic mode. Call only from GUI thread. + */ + virtual double getFrequencyForY(int y, double minFreq, double maxFreq, + bool logarithmic) const = 0; + + virtual int getTextLabelHeight(const Layer *layer, QPainter &) const = 0; + + virtual bool getValueExtents(QString unit, double &min, double &max, + bool &log) const = 0; + + /** + * Return the zoom level, i.e. the number of frames per pixel + */ + virtual int getZoomLevel() const = 0; + + /** + * To be called from a layer, to obtain the extent of the surface + * that the layer is currently painting to. This may be the extent + * of the view (if 1x display scaling is in effect) or of a larger + * cached pixmap (if greater display scaling is in effect). + */ + virtual QRect getPaintRect() const = 0; + + virtual QSize getPaintSize() const { return getPaintRect().size(); } + virtual int getPaintWidth() const { return getPaintRect().width(); } + virtual int getPaintHeight() const { return getPaintRect().height(); } + + virtual bool hasLightBackground() const = 0; + virtual QColor getForeground() const = 0; + virtual QColor getBackground() const = 0; + + virtual ViewManager *getViewManager() const = 0; + + virtual bool shouldIlluminateLocalFeatures(const Layer *, QPoint &) const = 0; + virtual bool shouldShowFeatureLabels() const = 0; + + enum TextStyle { + BoxedText, + OutlinedText, + OutlinedItalicText + }; + + virtual void drawVisibleText(QPainter &p, int x, int y, + QString text, TextStyle style) const = 0; + + virtual void drawMeasurementRect(QPainter &p, const Layer *, + QRect rect, bool focus) const = 0; + + virtual View *getView() = 0; + virtual const View *getView() const = 0; +}; + +#endif
--- a/view/Overview.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/view/Overview.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -35,15 +35,19 @@ m_followZoom = false; setPlaybackFollow(PlaybackIgnore); m_modelTestTime.start(); + + bool light = hasLightBackground(); + if (light) m_boxColour = Qt::darkGray; + else m_boxColour = Qt::lightGray; } void -Overview::modelChangedWithin(int startFrame, int endFrame) +Overview::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) { bool zoomChanged = false; - int frameCount = getModelsEndFrame() - getModelsStartFrame(); - int zoomLevel = frameCount / width(); + sv_frame_t frameCount = getModelsEndFrame() - getModelsStartFrame(); + int zoomLevel = int(frameCount / width()); if (zoomLevel < 1) zoomLevel = 1; zoomLevel = getZoomConstraintBlockSize(zoomLevel, ZoomConstraint::RoundUp); @@ -91,7 +95,7 @@ } void -Overview::globalCentreFrameChanged(int +Overview::globalCentreFrameChanged(sv_frame_t #ifdef DEBUG_OVERVIEW f #endif @@ -104,7 +108,7 @@ } void -Overview::viewCentreFrameChanged(View *v, int +Overview::viewCentreFrameChanged(View *v, sv_frame_t #ifdef DEBUG_OVERVIEW f #endif @@ -128,7 +132,7 @@ } void -Overview::viewManagerPlaybackFrameChanged(int f) +Overview::viewManagerPlaybackFrameChanged(sv_frame_t f) { #ifdef DEBUG_OVERVIEW cerr << "Overview[" << this << "]::viewManagerPlaybackFrameChanged(" << f << "): " << f << endl; @@ -144,6 +148,26 @@ if (changed) update(); } +QColor +Overview::getFillWithin() const +{ + return Qt::transparent; +} + +QColor +Overview::getFillWithout() const +{ + QColor c = palette().window().color(); + c.setAlpha(100); + return c; +} + +void +Overview::setBoxColour(QColor c) +{ + m_boxColour = c; +} + void Overview::paintEvent(QPaintEvent *e) { @@ -153,9 +177,9 @@ cerr << "Overview::paintEvent: width is " << width() << ", centre frame " << m_centreFrame << endl; #endif - int startFrame = getModelsStartFrame(); - int frameCount = getModelsEndFrame() - getModelsStartFrame(); - int zoomLevel = frameCount / width(); + sv_frame_t startFrame = getModelsStartFrame(); + sv_frame_t frameCount = getModelsEndFrame() - getModelsStartFrame(); + int zoomLevel = int(frameCount / width()); if (zoomLevel < 1) zoomLevel = 1; zoomLevel = getZoomConstraintBlockSize(zoomLevel, ZoomConstraint::RoundUp); @@ -164,7 +188,7 @@ emit zoomLevelChanged(m_zoomLevel, m_followZoom); } - int centreFrame = startFrame + m_zoomLevel * (width() / 2); + sv_frame_t centreFrame = startFrame + m_zoomLevel * (width() / 2); if (centreFrame > (startFrame + getModelsEndFrame())/2) { centreFrame = (startFrame + getModelsEndFrame())/2; } @@ -184,50 +208,73 @@ QPainter paint; paint.begin(this); - + paint.setClipRegion(e->region()); + paint.setRenderHints(QPainter::Antialiasing); + QRect r(rect()); - if (e) { - r = e->rect(); - paint.setClipRect(r); - } + // We paint a rounded rect for each distinct set of view extents, + // and we colour in the inside and outside of the rect that + // corresponds to the current view. (One small caveat -- we don't + // know which rect that is yet. We'll have to figure it out + // somehow...) - paint.setPen(getForeground()); + std::set<std::pair<int, int> > extents; + std::vector<QRect> rects; + QRect primary; int y = 0; - int prevx0 = -10; - int prevx1 = -10; - for (ViewSet::iterator i = m_views.begin(); i != m_views.end(); ++i) { if (!*i) continue; View *w = (View *)*i; - int f0 = w->getFrameForX(0); - int f1 = w->getFrameForX(w->width()); + sv_frame_t f0 = w->getFrameForX(0); + sv_frame_t f1 = w->getFrameForX(w->width()); if (f0 >= 0) { - int rf0 = w->alignToReference(f0); + sv_frame_t rf0 = w->alignToReference(f0); f0 = alignFromReference(rf0); } if (f1 >= 0) { - int rf1 = w->alignToReference(f1); + sv_frame_t rf1 = w->alignToReference(f1); f1 = alignFromReference(rf1); } int x0 = getXForFrame(f0); int x1 = getXForFrame(f1); - if (x0 != prevx0 || x1 != prevx1) { - y += height() / 10 + 1; - prevx0 = x0; - prevx1 = x1; - } if (x1 <= x0) x1 = x0 + 1; - - paint.drawRect(x0, y, x1 - x0, height() - 2 * y); + + std::pair<int, int> extent(x0, x1); + + if (extents.find(extent) == extents.end()) { + + y += height() / 10 + 1; + extents.insert(extent); + + QRect vr(x0, y, x1 - x0, height() - 2 * y); + rects.push_back(vr); + primary = vr; //!!! for now + } + } + + QPainterPath without; + without.addRoundedRect(primary, 4, 4); + without.addRect(rect()); + paint.setPen(Qt::NoPen); + paint.setBrush(getFillWithout()); + paint.drawPath(without); + + paint.setBrush(getFillWithin()); + paint.drawRoundedRect(primary, 4, 4); + + foreach (QRect vr, rects) { + paint.setBrush(Qt::NoBrush); + paint.setPen(QPen(m_boxColour, 2)); + paint.drawRoundedRect(vr, 4, 4); } paint.end(); @@ -237,7 +284,7 @@ Overview::mousePressEvent(QMouseEvent *e) { m_clickPos = e->pos(); - int clickFrame = getFrameForX(m_clickPos.x()); + sv_frame_t clickFrame = getFrameForX(m_clickPos.x()); if (clickFrame > 0) m_dragCentreFrame = clickFrame; else m_dragCentreFrame = 0; m_clickedInRange = true; @@ -265,12 +312,12 @@ if (!m_clickedInRange) return; int xoff = int(e->x()) - int(m_clickPos.x()); - int frameOff = xoff * m_zoomLevel; + sv_frame_t frameOff = xoff * m_zoomLevel; - int newCentreFrame = m_dragCentreFrame; + sv_frame_t newCentreFrame = m_dragCentreFrame; if (frameOff > 0) { newCentreFrame += frameOff; - } else if (newCentreFrame >= int(-frameOff)) { + } else if (newCentreFrame >= -frameOff) { newCentreFrame += frameOff; } else { newCentreFrame = 0; @@ -282,8 +329,8 @@ } if (std::max(m_centreFrame, newCentreFrame) - - std::min(m_centreFrame, newCentreFrame) > int(m_zoomLevel)) { - int rf = alignToReference(newCentreFrame); + std::min(m_centreFrame, newCentreFrame) > m_zoomLevel) { + sv_frame_t rf = alignToReference(newCentreFrame); #ifdef DEBUG_OVERVIEW cerr << "Overview::mouseMoveEvent: x " << e->x() << " and click x " << m_clickPos.x() << " -> frame " << newCentreFrame << " -> rf " << rf << endl; #endif @@ -299,8 +346,8 @@ void Overview::mouseDoubleClickEvent(QMouseEvent *e) { - int frame = getFrameForX(e->x()); - int rf = 0; + sv_frame_t frame = getFrameForX(e->x()); + sv_frame_t rf = 0; if (frame > 0) rf = alignToReference(frame); #ifdef DEBUG_OVERVIEW cerr << "Overview::mouseDoubleClickEvent: frame " << frame << " -> rf " << rf << endl;
--- a/view/Overview.h Fri Sep 12 11:38:55 2014 +0100 +++ b/view/Overview.h Fri Jun 26 14:13:31 2015 +0100 @@ -41,14 +41,16 @@ virtual QString getPropertyContainerIconName() const { return "panner"; } public slots: - virtual void modelChangedWithin(int startFrame, int endFrame); + virtual void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame); virtual void modelReplaced(); - virtual void globalCentreFrameChanged(int); - virtual void viewCentreFrameChanged(View *, int); + virtual void globalCentreFrameChanged(sv_frame_t); + virtual void viewCentreFrameChanged(View *, sv_frame_t); virtual void viewZoomLevelChanged(View *, int, bool); - virtual void viewManagerPlaybackFrameChanged(int); + virtual void viewManagerPlaybackFrameChanged(sv_frame_t); + virtual void setBoxColour(QColor); + protected: virtual void paintEvent(QPaintEvent *e); virtual void mousePressEvent(QMouseEvent *e); @@ -59,11 +61,15 @@ virtual void leaveEvent(QEvent *); virtual bool shouldLabelSelections() const { return false; } + QColor getFillWithin() const; + QColor getFillWithout() const; + QPoint m_clickPos; QPoint m_mousePos; bool m_clickedInRange; - int m_dragCentreFrame; + sv_frame_t m_dragCentreFrame; QTime m_modelTestTime; + QColor m_boxColour; typedef std::set<View *> ViewSet; ViewSet m_views;
--- a/view/Pane.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/view/Pane.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -24,6 +24,7 @@ #include "widgets/TextAbbrev.h" #include "base/Preferences.h" #include "layer/WaveformLayer.h" +#include "layer/TimeRulerLayer.h" // GF: added so we can propagate the mouse move event to the note layer for context handling. #include "layer/LayerFactory.h" @@ -143,7 +144,7 @@ m_hthumb->setFixedWidth(70); m_hthumb->setFixedHeight(16); m_hthumb->setDefaultValue(0); - m_hthumb->setSpeed(0.6); + m_hthumb->setSpeed(0.6f); connect(m_hthumb, SIGNAL(valueChanged(int)), this, SLOT(horizontalThumbwheelMoved(int))); connect(m_hthumb, SIGNAL(mouseEntered()), this, SLOT(mouseEnteredWidget())); @@ -320,12 +321,12 @@ return; } - float vmin, vmax, dmin, dmax; + double vmin, vmax, dmin, dmax; if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax) && vmax != vmin) { - float y0 = (dmin - vmin) / (vmax - vmin); - float y1 = (dmax - vmin) / (vmax - vmin); + double y0 = (dmin - vmin) / (vmax - vmin); + double y1 = (dmax - vmin) / (vmax - vmin); m_vpan->blockSignals(true); - m_vpan->setRectExtents(0, 1.0 - y1, 1, y1 - y0); + m_vpan->setRectExtents(0, float(1.0 - y1), 1, float(y1 - y0)); m_vpan->blockSignals(false); m_vpan->show(); } else { @@ -387,10 +388,10 @@ Pane::selectionIsBeingEdited() const { if (!m_editingSelection.isEmpty()) { - if (m_mousePos != m_clickPos && - getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { - return true; - } + if (m_mousePos != m_clickPos && + getFrameForX(m_mousePos.x()) != getFrameForX(m_clickPos.x())) { + return true; + } } return false; } @@ -483,7 +484,7 @@ drawFeatureDescription(topLayer, paint); } - int sampleRate = getModelsSampleRate(); + sv_samplerate_t sampleRate = getModelsSampleRate(); paint.setBrush(Qt::NoBrush); if (m_centreLineVisible && @@ -560,7 +561,7 @@ { Layer *scaleLayer = 0; - float min, max; + double min, max; bool log; QString unit; @@ -714,7 +715,7 @@ } void -Pane::drawCentreLine(int sampleRate, QPainter &paint, bool omitLine) +Pane::drawCentreLine(sv_samplerate_t sampleRate, QPainter &paint, bool omitLine) { int fontHeight = paint.fontMetrics().height(); int fontAscent = paint.fontMetrics().ascent(); @@ -969,7 +970,7 @@ { int offset = m_mousePos.x() - m_clickPos.x(); - int origStart = m_editingSelection.getStartFrame(); + sv_frame_t origStart = m_editingSelection.getStartFrame(); int p0 = getXForFrame(origStart) + offset; int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; @@ -980,15 +981,15 @@ p0 = getXForFrame(m_editingSelection.getStartFrame()); } - int newStart = getFrameForX(p0); - int newEnd = getFrameForX(p1); + sv_frame_t newStart = getFrameForX(p0); + sv_frame_t newEnd = getFrameForX(p1); paint.save(); paint.setPen(QPen(getForeground(), 2)); int fontHeight = paint.fontMetrics().height(); int fontAscent = paint.fontMetrics().ascent(); - int sampleRate = getModelsSampleRate(); + sv_samplerate_t sampleRate = getModelsSampleRate(); QString startText, endText, offsetText; startText = QString("%1").arg(newStart); endText = QString("%1").arg(newEnd); @@ -1037,17 +1038,17 @@ void Pane::drawDurationAndRate(QRect r, const Model *waveformModel, - int sampleRate, QPainter &paint) + sv_samplerate_t sampleRate, QPainter &paint) { int fontHeight = paint.fontMetrics().height(); int fontAscent = paint.fontMetrics().ascent(); if (r.y() + r.height() < height() - fontHeight - 6) return; - int modelRate = waveformModel->getSampleRate(); - int nativeRate = waveformModel->getNativeRate(); - int playbackRate = m_manager->getPlaybackSampleRate(); - int outputRate = m_manager->getOutputSampleRate(); + sv_samplerate_t modelRate = waveformModel->getSampleRate(); + sv_samplerate_t nativeRate = waveformModel->getNativeRate(); + sv_samplerate_t playbackRate = m_manager->getPlaybackSampleRate(); + sv_samplerate_t outputRate = m_manager->getOutputSampleRate(); QString srNote = ""; @@ -1086,7 +1087,7 @@ } bool -Pane::render(QPainter &paint, int xorigin, int f0, int f1) +Pane::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1) { if (!View::render(paint, xorigin + m_scaleWidth, f0, f1)) { return false; @@ -1117,10 +1118,10 @@ } QImage * -Pane::toNewImage(int f0, int f1) +Pane::toNewImage(sv_frame_t f0, sv_frame_t f1) { - int x0 = f0 / getZoomLevel(); - int x1 = f1 / getZoomLevel(); + int x0 = int(f0 / getZoomLevel()); + int x1 = int(f1 / getZoomLevel()); QImage *image = new QImage(x1 - x0 + m_scaleWidth, height(), QImage::Format_RGB32); @@ -1156,7 +1157,7 @@ } QSize -Pane::getImageSize(int f0, int f1) +Pane::getImageSize(sv_frame_t f0, sv_frame_t f1) { QSize s = View::getImageSize(f0, f1); QImage *image = new QImage(100, 100, QImage::Format_RGB32); @@ -1174,12 +1175,12 @@ return QSize(sw + s.width(), s.height()); } -int +sv_frame_t Pane::getFirstVisibleFrame() const { - int f0 = getFrameForX(m_scaleWidth); - int f = View::getFirstVisibleFrame(); - if (f0 < 0 || f0 < long(f)) return f; + sv_frame_t f0 = getFrameForX(m_scaleWidth); + sv_frame_t f = View::getFirstVisibleFrame(); + if (f0 < 0 || f0 < f) return f; return f0; } @@ -1190,10 +1191,10 @@ if (!m_manager) return Selection(); - int testFrame = getFrameForX(x - 5); + sv_frame_t testFrame = getFrameForX(x - 5); if (testFrame < 0) { - testFrame = getFrameForX(x); - if (testFrame < 0) return Selection(); + testFrame = getFrameForX(x); + if (testFrame < 0) return Selection(); } Selection selection = m_manager->getContainingSelection(testFrame, true); @@ -1219,15 +1220,15 @@ bool Pane::canTopLayerMoveVertical() { - float vmin, vmax, dmin, dmax; + double vmin, vmax, dmin, dmax; if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return false; if (dmin <= vmin && dmax >= vmax) return false; return true; } bool -Pane::getTopLayerDisplayExtents(float &vmin, float &vmax, - float &dmin, float &dmax, +Pane::getTopLayerDisplayExtents(double &vmin, double &vmax, + double &dmin, double &dmax, QString *unit) { Layer *layer = getTopLayer(); @@ -1241,7 +1242,7 @@ } bool -Pane::setTopLayerDisplayExtents(float dmin, float dmax) +Pane::setTopLayerDisplayExtents(double dmin, double dmax) { Layer *layer = getTopLayer(); if (!layer) return false; @@ -1327,7 +1328,7 @@ m_dragCentreFrame = m_centreFrame; m_dragStartMinValue = 0; - float vmin, vmax, dmin, dmax; + double vmin, vmax, dmin, dmax; if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { m_dragStartMinValue = dmin; } @@ -1362,12 +1363,13 @@ } else { - int mouseFrame = getFrameForX(e->x()); + sv_frame_t mouseFrame = getFrameForX(e->x()); int resolution = 1; - int snapFrame = mouseFrame; + sv_frame_t snapFrame = mouseFrame; Layer *layer = getInteractionLayer(); - if (layer && !m_shiftPressed) { + if (layer && !m_shiftPressed && + !qobject_cast<TimeRulerLayer *>(layer)) { // don't snap to secs layer->snapToFeatureFrame(this, snapFrame, resolution, Layer::SnapLeft); } @@ -1433,7 +1435,7 @@ } void -Pane::schedulePlaybackFrameMove(int frame) +Pane::schedulePlaybackFrameMove(sv_frame_t frame) { m_playbackFrameMoveTo = frame; m_playbackFrameMoveScheduled = true; @@ -1468,7 +1470,7 @@ mouseMoveEvent(e); } - int mouseFrame = e ? getFrameForX(e->x()) : 0; + sv_frame_t mouseFrame = e ? getFrameForX(e->x()) : 0; if (mouseFrame < 0) mouseFrame = 0; if (m_navigating || mode == ViewManager::NavigateMode) { @@ -1740,9 +1742,9 @@ if (!editSelectionDrag(e)) { - Layer *layer = getInteractionLayer(); - - if (layer && layer->isLayerEditable()) { + Layer *layer = getTopFlexiNoteLayer(); + + if (layer) { int x = e->x(); int y = e->y(); @@ -1854,18 +1856,18 @@ int w = x1 - x0; - int newStartFrame = getFrameForX(x0); + sv_frame_t newStartFrame = getFrameForX(x0); - int visibleFrames = getEndFrame() - getStartFrame(); + sv_frame_t visibleFrames = getEndFrame() - getStartFrame(); if (newStartFrame <= -visibleFrames) { newStartFrame = -visibleFrames + 1; } - if (newStartFrame >= long(getModelsEndFrame())) { + if (newStartFrame >= getModelsEndFrame()) { newStartFrame = getModelsEndFrame() - 1; } - float ratio = float(w) / float(width()); + double ratio = double(w) / double(width()); // cerr << "ratio: " << ratio << endl; int newZoomLevel = (int)nearbyint(m_zoomLevel * ratio); if (newZoomLevel < 1) newZoomLevel = 1; @@ -1875,7 +1877,7 @@ setStartFrame(newStartFrame); QString unit; - float min, max; + double min, max; bool log; Layer *layer = 0; for (LayerList::const_iterator i = m_layerStack.begin(); @@ -1889,15 +1891,15 @@ if (layer) { if (log) { - min = (min < 0.0) ? -log10f(-min) : (min == 0.0) ? 0.0 : log10f(min); - max = (max < 0.0) ? -log10f(-max) : (max == 0.0) ? 0.0 : log10f(max); + min = (min < 0.0) ? -log10(-min) : (min == 0.0) ? 0.0 : log10(min); + max = (max < 0.0) ? -log10(-max) : (max == 0.0) ? 0.0 : log10(max); } - float rmin = min + ((max - min) * (height() - y1)) / height(); - float rmax = min + ((max - min) * (height() - y0)) / height(); + double rmin = min + ((max - min) * (height() - y1)) / height(); + double rmax = min + ((max - min) * (height() - y0)) / height(); cerr << "min: " << min << ", max: " << max << ", y0: " << y0 << ", y1: " << y1 << ", h: " << height() << ", rmin: " << rmin << ", rmax: " << rmax << endl; if (log) { - rmin = powf(10, rmin); - rmax = powf(10, rmax); + rmin = pow(10, rmin); + rmax = pow(10, rmax); } cerr << "finally: rmin: " << rmin << ", rmax: " << rmax << " " << unit << endl; @@ -1946,8 +1948,8 @@ if (m_dragMode == HorizontalDrag || m_dragMode == FreeDrag) { - int frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); - int newCentreFrame = m_dragCentreFrame; + sv_frame_t frameOff = getFrameForX(e->x()) - getFrameForX(m_clickPos.x()); + sv_frame_t newCentreFrame = m_dragCentreFrame; if (frameOff < 0) { newCentreFrame -= frameOff; @@ -1975,24 +1977,24 @@ if (m_dragMode == VerticalDrag || m_dragMode == FreeDrag) { - float vmin = 0.f, vmax = 0.f; - float dmin = 0.f, dmax = 0.f; + double vmin = 0.f, vmax = 0.f; + double dmin = 0.f, dmax = 0.f; if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { // cerr << "ydiff = " << ydiff << endl; int ydiff = e->y() - m_clickPos.y(); - float perpix = (dmax - dmin) / height(); - float valdiff = ydiff * perpix; + double perpix = (dmax - dmin) / height(); + double valdiff = ydiff * perpix; // cerr << "valdiff = " << valdiff << endl; if (m_dragMode == UnresolvedDrag && ydiff != 0) { m_dragMode = VerticalDrag; } - float newmin = m_dragStartMinValue + valdiff; - float newmax = m_dragStartMinValue + (dmax - dmin) + valdiff; + double newmin = m_dragStartMinValue + valdiff; + double newmax = m_dragStartMinValue + (dmax - dmin) + valdiff; if (newmin < vmin) { newmax += vmin - newmin; newmin += vmin - newmin; @@ -2024,6 +2026,11 @@ int smallThreshold = 10, bigThreshold = 80; + if (m_manager) { + smallThreshold = m_manager->scalePixelSize(smallThreshold); + bigThreshold = m_manager->scalePixelSize(bigThreshold); + } + // SVDEBUG << "Pane::updateDragMode: xdiff = " << xdiff << ", ydiff = " // << ydiff << ", canMoveVertical = " << canMoveVertical << ", drag mode = " << m_dragMode << endl; @@ -2072,13 +2079,14 @@ void Pane::dragExtendSelection(QMouseEvent *e) { - int mouseFrame = getFrameForX(e->x()); + sv_frame_t mouseFrame = getFrameForX(e->x()); int resolution = 1; - int snapFrameLeft = mouseFrame; - int snapFrameRight = mouseFrame; + sv_frame_t snapFrameLeft = mouseFrame; + sv_frame_t snapFrameRight = mouseFrame; Layer *layer = getInteractionLayer(); - if (layer && !m_shiftPressed) { + if (layer && !m_shiftPressed && + !qobject_cast<TimeRulerLayer *>(layer)) { // don't snap to secs layer->snapToFeatureFrame(this, snapFrameLeft, resolution, Layer::SnapLeft); layer->snapToFeatureFrame(this, snapFrameRight, @@ -2090,7 +2098,7 @@ if (snapFrameLeft < 0) snapFrameLeft = 0; if (snapFrameRight < 0) snapFrameRight = 0; - int min, max; + sv_frame_t min, max; if (m_selectionStartFrame > snapFrameLeft) { min = snapFrameLeft; @@ -2103,14 +2111,25 @@ max = snapFrameRight; } + sv_frame_t end = getModelsEndFrame(); + if (min > end) min = end; + if (max > end) max = end; + if (m_manager) { - m_manager->setInProgressSelection(Selection(alignToReference(min), - alignToReference(max)), - !m_resizing && !m_ctrlPressed); + + Selection sel(alignToReference(min), alignToReference(max)); + + bool exc; + bool same = (m_manager->haveInProgressSelection() && + m_manager->getInProgressSelection(exc) == sel); + + m_manager->setInProgressSelection(sel, !m_resizing && !m_ctrlPressed); + + if (!same) { + edgeScrollMaybe(e->x()); + } } - edgeScrollMaybe(e->x()); - update(); if (min != max) { @@ -2121,7 +2140,7 @@ void Pane::edgeScrollMaybe(int x) { - int mouseFrame = getFrameForX(x); + sv_frame_t mouseFrame = getFrameForX(x); bool doScroll = false; if (!m_manager) doScroll = true; @@ -2130,14 +2149,15 @@ if (m_followPlay != PlaybackScrollContinuous) doScroll = true; if (doScroll) { - int offset = mouseFrame - getStartFrame(); - int available = getEndFrame() - getStartFrame(); - int move = 0; - if (offset >= available * 0.95) { - move = int(offset - available * 0.95) + 1; - } else if (offset <= available * 0.10) { - move = int(available * 0.10 - offset) + 1; - move = -move; + sv_frame_t offset = mouseFrame - getStartFrame(); + sv_frame_t available = getEndFrame() - getStartFrame(); + sv_frame_t move = 0; + sv_frame_t rightEdge = available - (available / 20); + sv_frame_t leftEdge = (available / 10); + if (offset >= rightEdge) { + move = offset - rightEdge + 1; + } else if (offset <= leftEdge) { + move = offset - leftEdge - 1; } if (move != 0) { setCentreFrame(m_centreFrame + move); @@ -2194,7 +2214,7 @@ if (relocate) { - int f = getFrameForX(e->x()); + sv_frame_t f = getFrameForX(e->x()); setCentreFrame(f); @@ -2202,7 +2222,7 @@ m_dragStartMinValue = 0; m_dragMode = UnresolvedDrag; - float vmin, vmax, dmin, dmax; + double vmin, vmax, dmin, dmax; if (getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) { m_dragStartMinValue = dmin; } @@ -2286,6 +2306,13 @@ // Coarse wheel information (or vertical zoom, which is // necessarily coarse itself) + // Sometimes on Linux we're seeing absurdly extreme angles on + // the first wheel event -- discard those entirely + if (abs(m_pendingWheelAngle) >= 600) { + m_pendingWheelAngle = 0; + return; + } + while (abs(m_pendingWheelAngle) >= 120) { int sign = (m_pendingWheelAngle < 0 ? -1 : 1); @@ -2456,11 +2483,11 @@ void Pane::verticalPannerMoved(float , float y0, float , float h) { - float vmin, vmax, dmin, dmax; + double vmin, vmax, dmin, dmax; if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax)) return; - float y1 = y0 + h; - float newmax = vmin + ((1.0 - y0) * (vmax - vmin)); - float newmin = vmin + ((1.0 - y1) * (vmax - vmin)); + double y1 = y0 + h; + double newmax = vmin + ((1.0 - y0) * (vmax - vmin)); + double newmin = vmin + ((1.0 - y1) * (vmax - vmin)); // cerr << "verticalPannerMoved: (" << x0 << "," << y0 << "," << w // << "," << h << ") -> (" << newmin << "," << newmax << ")" << endl; setTopLayerDisplayExtents(newmin, newmax); @@ -2471,7 +2498,7 @@ { if (!m_vpan || !m_manager || !m_manager->getZoomWheelsEnabled()) return; - float vmin, vmax, dmin, dmax; + double vmin, vmax, dmin, dmax; QString unit; if (!getTopLayerDisplayExtents(vmin, vmax, dmin, dmax, &unit) || vmax == vmin) { @@ -2481,12 +2508,13 @@ RangeInputDialog dialog(tr("Enter new range"), tr("New vertical display range, from %1 to %2 %4:") .arg(vmin).arg(vmax).arg(unit), - unit, vmin, vmax, this); - dialog.setRange(dmin, dmax); + unit, float(vmin), float(vmax), this); + dialog.setRange(float(dmin), float(dmax)); if (dialog.exec() == QDialog::Accepted) { - dialog.getRange(dmin, dmax); - setTopLayerDisplayExtents(dmin, dmax); + float newmin, newmax; + dialog.getRange(newmin, newmax); + setTopLayerDisplayExtents(newmin, newmax); updateVerticalPanner(); } } @@ -2592,8 +2620,8 @@ int p0 = getXForFrame(m_editingSelection.getStartFrame()) + offset; int p1 = getXForFrame(m_editingSelection.getEndFrame()) + offset; - int f0 = getFrameForX(p0); - int f1 = getFrameForX(p1); + sv_frame_t f0 = getFrameForX(p0); + sv_frame_t f1 = getFrameForX(p1); Selection newSelection(f0, f1);
--- a/view/Pane.h Fri Sep 12 11:38:55 2014 +0100 +++ b/view/Pane.h Fri Jun 26 14:13:31 2015 +0100 @@ -48,13 +48,13 @@ void setCentreLineVisible(bool visible); bool getCentreLineVisible() const { return m_centreLineVisible; } - virtual int getFirstVisibleFrame() const; + virtual sv_frame_t getFirstVisibleFrame() const; virtual int getVerticalScaleWidth() const; - virtual QImage *toNewImage(int f0, int f1); + virtual QImage *toNewImage(sv_frame_t f0, sv_frame_t f1); virtual QImage *toNewImage() { return View::toNewImage(); } - virtual QSize getImageSize(int f0, int f1); + virtual QSize getImageSize(sv_frame_t f0, sv_frame_t f1); virtual QSize getImageSize() { return View::getImageSize(); } virtual void toXml(QTextStream &stream, QString indent = "", @@ -73,7 +73,7 @@ void rightButtonMenuRequested(QPoint position); void dropAccepted(QStringList uriList); void dropAccepted(QString text); - void doubleClickSelectInvoked(int frame); + void doubleClickSelectInvoked(sv_frame_t frame); void regionOutlined(QRect rect); public slots: @@ -119,15 +119,15 @@ void drawVerticalScale(QRect r, Layer *, QPainter &); void drawFeatureDescription(Layer *, QPainter &); - void drawCentreLine(int, QPainter &, bool omitLine); + void drawCentreLine(sv_samplerate_t, QPainter &, bool omitLine); void drawModelTimeExtents(QRect, QPainter &, const Model *); - void drawDurationAndRate(QRect, const Model *, int, QPainter &); + void drawDurationAndRate(QRect, const Model *, sv_samplerate_t, QPainter &); void drawWorkTitle(QRect, QPainter &, const Model *); void drawLayerNames(QRect, QPainter &); void drawEditingSelection(QPainter &); void drawAlignmentStatus(QRect, QPainter &, const Model *, bool down); - virtual bool render(QPainter &paint, int x0, int f0, int f1); + virtual bool render(QPainter &paint, int x0, sv_frame_t f0, sv_frame_t f1); Selection getSelectionAt(int x, bool &closeToLeft, bool &closeToRight) const; @@ -140,10 +140,10 @@ void updateVerticalPanner(); bool canTopLayerMoveVertical(); - bool getTopLayerDisplayExtents(float &valueMin, float &valueMax, - float &displayMin, float &displayMax, + bool getTopLayerDisplayExtents(double &valueMin, double &valueMax, + double &displayMin, double &displayMax, QString *unit = 0); - bool setTopLayerDisplayExtents(float displayMin, float displayMax); + bool setTopLayerDisplayExtents(double displayMin, double displayMax); void dragTopLayer(QMouseEvent *e); void dragExtendSelection(QMouseEvent *e); @@ -152,7 +152,7 @@ Layer *getTopFlexiNoteLayer(); - void schedulePlaybackFrameMove(int frame); + void schedulePlaybackFrameMove(sv_frame_t frame); bool m_identifyFeatures; QPoint m_identifyPoint; @@ -167,10 +167,10 @@ bool m_resizing; bool m_editing; bool m_releasing; - int m_dragCentreFrame; - float m_dragStartMinValue; + sv_frame_t m_dragCentreFrame; + double m_dragStartMinValue; bool m_centreLineVisible; - int m_selectionStartFrame; + sv_frame_t m_selectionStartFrame; Selection m_editingSelection; int m_editingSelectionEdge; mutable int m_scaleWidth; @@ -202,7 +202,7 @@ bool m_mouseInWidget; bool m_playbackFrameMoveScheduled; - int m_playbackFrameMoveTo; + sv_frame_t m_playbackFrameMoveTo; static QCursor *m_measureCursor1; static QCursor *m_measureCursor2;
--- a/view/PaneStack.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/view/PaneStack.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -98,7 +98,7 @@ currentIndicator->setScaledContents(true); currentIndicator->setVisible(m_showAccessories); - int initialCentreFrame = -1; + sv_frame_t initialCentreFrame = -1; if (!m_panes.empty()) { initialCentreFrame = m_panes[0].pane->getCentreFrame(); } @@ -156,8 +156,8 @@ this, SLOT(paneDropAccepted(QStringList))); connect(pane, SIGNAL(dropAccepted(QString)), this, SLOT(paneDropAccepted(QString))); - connect(pane, SIGNAL(doubleClickSelectInvoked(int)), - this, SIGNAL(doubleClickSelectInvoked(int))); + connect(pane, SIGNAL(doubleClickSelectInvoked(sv_frame_t)), + this, SIGNAL(doubleClickSelectInvoked(sv_frame_t))); emit paneAdded(pane); emit paneAdded(); @@ -323,13 +323,13 @@ int PaneStack::getPaneCount() const { - return m_panes.size(); + return int(m_panes.size()); } int PaneStack::getHiddenPaneCount() const { - return m_hiddenPanes.size(); + return int(m_hiddenPanes.size()); } void
--- a/view/PaneStack.h Fri Sep 12 11:38:55 2014 +0100 +++ b/view/PaneStack.h Fri Jun 26 14:13:31 2015 +0100 @@ -20,6 +20,8 @@ #include <map> +#include "base/BaseTypes.h" + class QWidget; class QLabel; class QStackedWidget; @@ -93,7 +95,7 @@ void paneDeleteButtonClicked(Pane *pane); - void doubleClickSelectInvoked(int frame); + void doubleClickSelectInvoked(sv_frame_t frame); public slots: void propertyContainerAdded(PropertyContainer *);
--- a/view/View.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/view/View.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -20,6 +20,7 @@ #include "base/Profiler.h" #include "base/Pitch.h" #include "base/Preferences.h" +#include "ViewProxy.h" #include "layer/TimeRulerLayer.h" #include "layer/SingleColourLayer.h" @@ -37,6 +38,7 @@ #include <QFont> #include <QMessageBox> #include <QPushButton> +#include <QSettings> #include <iostream> #include <cassert> @@ -44,8 +46,8 @@ #include <unistd.h> -//#define DEBUG_VIEW 1 -//#define DEBUG_VIEW_WIDGET_PAINT 1 +#define DEBUG_VIEW 1 +#define DEBUG_VIEW_WIDGET_PAINT 1 View::View(QWidget *w, bool showProgress) : @@ -59,6 +61,7 @@ m_playPointerFrame(0), m_showProgress(showProgress), m_cache(0), + m_buffer(0), m_cacheCentreFrame(0), m_cacheZoomLevel(1024), m_selectionCached(false), @@ -164,7 +167,7 @@ int View::getPropertyContainerCount() const { - return m_fixedOrderLayers.size() + 1; // the 1 is for me + return int(m_fixedOrderLayers.size()) + 1; // the 1 is for me } const PropertyContainer * @@ -182,7 +185,7 @@ } bool -View::getValueExtents(QString unit, float &min, float &max, bool &log) const +View::getValueExtents(QString unit, double &min, double &max, bool &log) const { bool have = false; @@ -190,8 +193,8 @@ i != m_layerStack.end(); ++i) { QString layerUnit; - float layerMin = 0.0, layerMax = 0.0; - float displayMin = 0.0, displayMax = 0.0; + double layerMin = 0.0, layerMax = 0.0; + double displayMin = 0.0, displayMax = 0.0; bool layerLog = false; if ((*i)->getValueExtents(layerMin, layerMax, layerLog, layerUnit) && @@ -298,36 +301,36 @@ // subclass might override this } -int +sv_frame_t View::getStartFrame() const { return getFrameForX(0); } -int +sv_frame_t View::getEndFrame() const { return getFrameForX(width()) - 1; } void -View::setStartFrame(int f) +View::setStartFrame(sv_frame_t f) { setCentreFrame(f + m_zoomLevel * (width() / 2)); } bool -View::setCentreFrame(int f, bool e) +View::setCentreFrame(sv_frame_t f, bool e) { bool changeVisible = false; if (m_centreFrame != f) { - int formerPixel = m_centreFrame / m_zoomLevel; + int formerPixel = int(m_centreFrame / m_zoomLevel); m_centreFrame = f; - int newPixel = m_centreFrame / m_zoomLevel; + int newPixel = int(m_centreFrame / m_zoomLevel); if (newPixel != formerPixel) { @@ -340,7 +343,7 @@ } if (e) { - int rf = alignToReference(f); + sv_frame_t rf = alignToReference(f); #ifdef DEBUG_VIEW cerr << "View[" << this << "]::setCentreFrame(" << f << "): emitting centreFrameChanged(" @@ -354,16 +357,16 @@ } int -View::getXForFrame(int frame) const +View::getXForFrame(sv_frame_t frame) const { - return (frame - getStartFrame()) / m_zoomLevel; + return int((frame - getStartFrame()) / m_zoomLevel); } -int +sv_frame_t View::getFrameForX(int x) const { int z = m_zoomLevel; - int frame = m_centreFrame - (width()/2) * z; + sv_frame_t frame = m_centreFrame - (width()/2) * z; #ifdef DEBUG_VIEW_WIDGET_PAINT SVDEBUG << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; @@ -373,10 +376,10 @@ return frame + x * z; } -float -View::getYForFrequency(float frequency, - float minf, - float maxf, +double +View::getYForFrequency(double frequency, + double minf, + double maxf, bool logarithmic) const { Profiler profiler("View::getYForFrequency"); @@ -385,20 +388,20 @@ if (logarithmic) { - static float lastminf = 0.0, lastmaxf = 0.0; - static float logminf = 0.0, logmaxf = 0.0; + static double lastminf = 0.0, lastmaxf = 0.0; + static double logminf = 0.0, logmaxf = 0.0; if (lastminf != minf) { lastminf = (minf == 0.0 ? 1.0 : minf); - logminf = log10f(minf); + logminf = log10(minf); } if (lastmaxf != maxf) { lastmaxf = (maxf < lastminf ? lastminf : maxf); - logmaxf = log10f(maxf); + logmaxf = log10(maxf); } if (logminf == logmaxf) return 0; - return h - (h * (log10f(frequency) - logminf)) / (logmaxf - logminf); + return h - (h * (log10(frequency) - logminf)) / (logmaxf - logminf); } else { @@ -407,30 +410,30 @@ } } -float +double View::getFrequencyForY(int y, - float minf, - float maxf, + double minf, + double maxf, bool logarithmic) const { int h = height(); if (logarithmic) { - static float lastminf = 0.0, lastmaxf = 0.0; - static float logminf = 0.0, logmaxf = 0.0; + static double lastminf = 0.0, lastmaxf = 0.0; + static double logminf = 0.0, logmaxf = 0.0; if (lastminf != minf) { lastminf = (minf == 0.0 ? 1.0 : minf); - logminf = log10f(minf); + logminf = log10(minf); } if (lastmaxf != maxf) { lastmaxf = (maxf < lastminf ? lastminf : maxf); - logmaxf = log10f(maxf); + logmaxf = log10(maxf); } if (logminf == logmaxf) return 0; - return pow(10.f, logminf + ((logmaxf - logminf) * (h - y)) / h); + return pow(10.0, logminf + ((logmaxf - logminf) * (h - y)) / h); } else { @@ -448,9 +451,30 @@ return m_zoomLevel; } +int +View::effectiveDevicePixelRatio() const +{ +#ifdef Q_OS_MAC + int dpratio = devicePixelRatio(); + if (dpratio > 1) { + QSettings settings; + settings.beginGroup("Preferences"); + if (!settings.value("scaledHiDpi", true).toBool()) { + dpratio = 1; + } + settings.endGroup(); + } + return dpratio; +#else + return 1; +#endif +} + void View::setZoomLevel(int z) { + int dpratio = effectiveDevicePixelRatio(); + if (z < dpratio) return; if (z < 1) z = 1; if (m_zoomLevel != int(z)) { m_zoomLevel = z; @@ -580,8 +604,8 @@ this, SLOT(modelCompletionChanged())); connect(layer, SIGNAL(modelAlignmentCompletionChanged()), this, SLOT(modelAlignmentCompletionChanged())); - connect(layer, SIGNAL(modelChangedWithin(int, int)), - this, SLOT(modelChangedWithin(int, int))); + connect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), + this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t))); connect(layer, SIGNAL(modelReplaced()), this, SLOT(modelReplaced())); @@ -636,8 +660,8 @@ this, SLOT(modelCompletionChanged())); disconnect(layer, SIGNAL(modelAlignmentCompletionChanged()), this, SLOT(modelAlignmentCompletionChanged())); - disconnect(layer, SIGNAL(modelChangedWithin(int, int)), - this, SLOT(modelChangedWithin(int, int))); + disconnect(layer, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), + this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t))); disconnect(layer, SIGNAL(modelReplaced()), this, SLOT(modelReplaced())); @@ -692,26 +716,26 @@ View::setViewManager(ViewManager *manager) { if (m_manager) { - m_manager->disconnect(this, SLOT(globalCentreFrameChanged(int))); - m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, int))); - m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(int))); + m_manager->disconnect(this, SLOT(globalCentreFrameChanged(sv_frame_t))); + m_manager->disconnect(this, SLOT(viewCentreFrameChanged(View *, sv_frame_t))); + m_manager->disconnect(this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t))); m_manager->disconnect(this, SLOT(viewZoomLevelChanged(View *, int, bool))); m_manager->disconnect(this, SLOT(toolModeChanged())); m_manager->disconnect(this, SLOT(selectionChanged())); m_manager->disconnect(this, SLOT(overlayModeChanged())); m_manager->disconnect(this, SLOT(zoomWheelsEnabledChanged())); - disconnect(m_manager, SLOT(viewCentreFrameChanged(int, bool, PlaybackFollowMode))); + disconnect(m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode))); disconnect(m_manager, SLOT(zoomLevelChanged(int, bool))); } m_manager = manager; - connect(m_manager, SIGNAL(globalCentreFrameChanged(int)), - this, SLOT(globalCentreFrameChanged(int))); - connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, int)), - this, SLOT(viewCentreFrameChanged(View *, int))); - connect(m_manager, SIGNAL(playbackFrameChanged(int)), - this, SLOT(viewManagerPlaybackFrameChanged(int))); + connect(m_manager, SIGNAL(globalCentreFrameChanged(sv_frame_t)), + this, SLOT(globalCentreFrameChanged(sv_frame_t))); + connect(m_manager, SIGNAL(viewCentreFrameChanged(View *, sv_frame_t)), + this, SLOT(viewCentreFrameChanged(View *, sv_frame_t))); + connect(m_manager, SIGNAL(playbackFrameChanged(sv_frame_t)), + this, SLOT(viewManagerPlaybackFrameChanged(sv_frame_t))); connect(m_manager, SIGNAL(viewZoomLevelChanged(View *, int, bool)), this, SLOT(viewZoomLevelChanged(View *, int, bool))); @@ -729,9 +753,9 @@ connect(m_manager, SIGNAL(zoomWheelsEnabledChanged()), this, SLOT(zoomWheelsEnabledChanged())); - connect(this, SIGNAL(centreFrameChanged(int, bool, + connect(this, SIGNAL(centreFrameChanged(sv_frame_t, bool, PlaybackFollowMode)), - m_manager, SLOT(viewCentreFrameChanged(int, bool, + m_manager, SLOT(viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode))); connect(this, SIGNAL(zoomLevelChanged(int, bool)), @@ -763,7 +787,7 @@ } void -View::setViewManager(ViewManager *vm, int initialCentreFrame) +View::setViewManager(ViewManager *vm, sv_frame_t initialCentreFrame) { setViewManager(vm); setCentreFrame(initialCentreFrame, false); @@ -877,18 +901,18 @@ } void -View::modelChangedWithin(int startFrame, int endFrame) +View::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) { QObject *obj = sender(); - int myStartFrame = getStartFrame(); - int myEndFrame = getEndFrame(); + sv_frame_t myStartFrame = getStartFrame(); + sv_frame_t myEndFrame = getEndFrame(); #ifdef DEBUG_VIEW_WIDGET_PAINT cerr << "View(" << this << ")::modelChangedWithin(" << startFrame << "," << endFrame << ") [me " << myStartFrame << "," << myEndFrame << "]" << endl; #endif - if (myStartFrame > 0 && endFrame < int(myStartFrame)) { + if (myStartFrame > 0 && endFrame < myStartFrame) { checkProgress(obj); return; } @@ -995,10 +1019,10 @@ } void -View::globalCentreFrameChanged(int rf) +View::globalCentreFrameChanged(sv_frame_t rf) { if (m_followPan) { - int f = alignFromReference(rf); + sv_frame_t f = alignFromReference(rf); #ifdef DEBUG_VIEW cerr << "View[" << this << "]::globalCentreFrameChanged(" << rf << "): setting centre frame to " << f << endl; @@ -1008,13 +1032,13 @@ } void -View::viewCentreFrameChanged(View *, int ) +View::viewCentreFrameChanged(View *, sv_frame_t ) { // We do nothing with this, but a subclass might } void -View::viewManagerPlaybackFrameChanged(int f) +View::viewManagerPlaybackFrameChanged(sv_frame_t f) { if (m_manager) { if (sender() != m_manager) return; @@ -1027,14 +1051,14 @@ f = getAlignedPlaybackFrame(); #ifdef DEBUG_VIEW - cerr << " -> aligned frame = " << af << endl; + cerr << " -> aligned frame = " << f << endl; #endif movePlayPointer(f); } void -View::movePlayPointer(int newFrame) +View::movePlayPointer(sv_frame_t newFrame) { #ifdef DEBUG_VIEW cerr << "View(" << this << ")::movePlayPointer(" << newFrame << ")" << endl; @@ -1043,7 +1067,7 @@ if (m_playPointerFrame == newFrame) return; bool visibleChange = (getXForFrame(m_playPointerFrame) != getXForFrame(newFrame)); - int oldPlayPointerFrame = m_playPointerFrame; + sv_frame_t oldPlayPointerFrame = m_playPointerFrame; m_playPointerFrame = newFrame; if (!visibleChange) return; @@ -1081,16 +1105,16 @@ int xold = getXForFrame(oldPlayPointerFrame); update(xold - 4, 0, 9, height()); - int w = getEndFrame() - getStartFrame(); + sv_frame_t w = getEndFrame() - getStartFrame(); w -= w/5; - int sf = (m_playPointerFrame / w) * w - w/8; + sv_frame_t sf = (m_playPointerFrame / w) * w - w/8; if (m_manager && m_manager->isPlaying() && m_manager->getPlaySelectionMode()) { MultiSelection::SelectionList selections = m_manager->getSelections(); if (!selections.empty()) { - int selectionStart = selections.begin()->getStartFrame(); + sv_frame_t selectionStart = selections.begin()->getStartFrame(); if (sf < selectionStart - w / 10) { sf = selectionStart - w / 10; } @@ -1124,8 +1148,8 @@ } if (!somethingGoingOn && shouldScroll) { - int offset = getFrameForX(width()/2) - getStartFrame(); - int newCentre = sf + offset; + sv_frame_t offset = getFrameForX(width()/2) - getStartFrame(); + sv_frame_t newCentre = sf + offset; bool changed = setCentreFrame(newCentre, false); if (changed) { xold = getXForFrame(oldPlayPointerFrame); @@ -1168,35 +1192,35 @@ update(); } -int +sv_frame_t View::getFirstVisibleFrame() const { - int f0 = getStartFrame(); - int f = getModelsStartFrame(); + sv_frame_t f0 = getStartFrame(); + sv_frame_t f = getModelsStartFrame(); if (f0 < 0 || f0 < f) return f; return f0; } -int +sv_frame_t View::getLastVisibleFrame() const { - int f0 = getEndFrame(); - int f = getModelsEndFrame(); + sv_frame_t f0 = getEndFrame(); + sv_frame_t f = getModelsEndFrame(); if (f0 > f) return f; return f0; } -int +sv_frame_t View::getModelsStartFrame() const { bool first = true; - int startFrame = 0; + sv_frame_t startFrame = 0; for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { if ((*i)->getModel() && (*i)->getModel()->isOK()) { - int thisStartFrame = (*i)->getModel()->getStartFrame(); + sv_frame_t thisStartFrame = (*i)->getModel()->getStartFrame(); if (first || thisStartFrame < startFrame) { startFrame = thisStartFrame; @@ -1207,17 +1231,17 @@ return startFrame; } -int +sv_frame_t View::getModelsEndFrame() const { bool first = true; - int endFrame = 0; + sv_frame_t endFrame = 0; for (LayerList::const_iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { if ((*i)->getModel() && (*i)->getModel()->isOK()) { - int thisEndFrame = (*i)->getModel()->getEndFrame(); + sv_frame_t thisEndFrame = (*i)->getModel()->getEndFrame(); if (first || thisEndFrame > endFrame) { endFrame = thisEndFrame; @@ -1230,7 +1254,7 @@ return endFrame; } -int +sv_samplerate_t View::getModelsSampleRate() const { //!!! Just go for the first, for now. If we were supporting @@ -1309,8 +1333,8 @@ else return anyModel; } -int -View::alignFromReference(int f) const +sv_frame_t +View::alignFromReference(sv_frame_t f) const { if (!m_manager || !m_manager->getAlignMode()) return f; Model *aligningModel = getAligningModel(); @@ -1318,8 +1342,8 @@ return aligningModel->alignFromReference(f); } -int -View::alignToReference(int f) const +sv_frame_t +View::alignToReference(sv_frame_t f) const { if (!m_manager->getAlignMode()) return f; Model *aligningModel = getAligningModel(); @@ -1327,17 +1351,17 @@ return aligningModel->alignToReference(f); } -int +sv_frame_t View::getAlignedPlaybackFrame() const { if (!m_manager) return 0; - int pf = m_manager->getPlaybackFrame(); + sv_frame_t pf = m_manager->getPlaybackFrame(); if (!m_manager->getAlignMode()) return pf; Model *aligningModel = getAligningModel(); if (!aligningModel) return pf; - int af = aligningModel->alignFromReference(pf); + sv_frame_t af = aligningModel->alignFromReference(pf); return af; } @@ -1492,7 +1516,7 @@ void View::scroll(bool right, bool lots, bool e) { - int delta; + sv_frame_t delta; if (lots) { delta = (getEndFrame() - getStartFrame()) / 2; } else { @@ -1500,9 +1524,9 @@ } if (right) delta = -delta; - if (int(m_centreFrame) < delta) { + if (m_centreFrame < delta) { setCentreFrame(0, e); - } else if (int(m_centreFrame) - delta >= int(getModelsEndFrame())) { + } else if (m_centreFrame - delta >= getModelsEndFrame()) { setCentreFrame(getModelsEndFrame(), e); } else { setCentreFrame(m_centreFrame - delta, e); @@ -1653,11 +1677,27 @@ void View::setPaintFont(QPainter &paint) { + int scaleFactor = 1; + int dpratio = effectiveDevicePixelRatio(); + if (dpratio > 1) { + QPaintDevice *dev = paint.device(); + if (dynamic_cast<QPixmap *>(dev) || dynamic_cast<QImage *>(dev)) { + scaleFactor = dpratio; + } + } + QFont font(paint.font()); - font.setPointSize(Preferences::getInstance()->getViewFontSize()); + font.setPointSize(Preferences::getInstance()->getViewFontSize() + * scaleFactor); paint.setFont(font); } +QRect +View::getPaintRect() const +{ + return rect(); +} + void View::paintEvent(QPaintEvent *e) { @@ -1694,6 +1734,8 @@ QRect nonCacheRect(cacheRect); + int dpratio = effectiveDevicePixelRatio(); + // If not all layers are scrollable, but some of the back layers // are, we should store only those in the cache. @@ -1705,25 +1747,34 @@ // If all the non-scrollable layers are non-opaque, then we draw // the selection rectangle behind them and cache it. If any are - // opaque, however, we can't cache. + // opaque, however, or if our device-pixel ratio is not 1 (so we + // need to paint direct to the widget), then we can't cache. // - if (!selectionCacheable) { - selectionCacheable = true; - for (LayerList::const_iterator i = nonScrollables.begin(); - i != nonScrollables.end(); ++i) { - if ((*i)->isLayerOpaque()) { - selectionCacheable = false; - break; - } - } - } - - if (selectionCacheable) { - QPoint localPos; - bool closeToLeft, closeToRight; - if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) { - selectionCacheable = false; - } + if (dpratio == 1) { + + if (!selectionCacheable) { + selectionCacheable = true; + for (LayerList::const_iterator i = nonScrollables.begin(); + i != nonScrollables.end(); ++i) { + if ((*i)->isLayerOpaque()) { + selectionCacheable = false; + break; + } + } + } + + if (selectionCacheable) { + QPoint localPos; + bool closeToLeft, closeToRight; + if (shouldIlluminateLocalSelection + (localPos, closeToLeft, closeToRight)) { + selectionCacheable = false; + } + } + + } else { + + selectionCacheable = false; } #ifdef DEBUG_VIEW_WIDGET_PAINT @@ -1741,6 +1792,14 @@ m_selectionCached = false; } + QSize scaledCacheSize(scaledSize(size(), dpratio)); + QRect scaledCacheRect(scaledRect(cacheRect, dpratio)); + + if (!m_buffer || scaledCacheSize != m_buffer->size()) { + delete m_buffer; + m_buffer = new QPixmap(scaledCacheSize); + } + if (!scrollables.empty()) { #ifdef DEBUG_VIEW_WIDGET_PAINT @@ -1750,8 +1809,7 @@ if (!m_cache || m_cacheZoomLevel != m_zoomLevel || - width() != m_cache->width() || - height() != m_cache->height()) { + scaledCacheSize != m_cache->size()) { // cache is not valid @@ -1763,7 +1821,7 @@ #endif } else { delete m_cache; - m_cache = new QPixmap(width(), height()); + m_cache = new QPixmap(scaledCacheSize); #ifdef DEBUG_VIEW_WIDGET_PAINT cerr << "View(" << this << ")::paintEvent: recreated cache" << endl; #endif @@ -1778,24 +1836,10 @@ getXForFrame(m_centreFrame); if (dx > -width() && dx < width()) { -#ifdef PIXMAP_COPY_TO_SELF - // This is not normally defined. Copying a pixmap to - // itself doesn't work properly on Windows, Mac, or - // X11 with the raster backend (it only works when - // moving in one direction and then presumably only by - // accident). It does actually seem to be fine on X11 - // with the native backend, but we prefer not to use - // that anyway - paint.begin(m_cache); - paint.drawPixmap(dx, 0, *m_cache); - paint.end(); -#else static QPixmap *tmpPixmap = 0; - if (!tmpPixmap || - tmpPixmap->width() != width() || - tmpPixmap->height() != height()) { + if (!tmpPixmap || tmpPixmap->size() != scaledCacheSize) { delete tmpPixmap; - tmpPixmap = new QPixmap(width(), height()); + tmpPixmap = new QPixmap(scaledCacheSize); } paint.begin(tmpPixmap); paint.drawPixmap(0, 0, *m_cache); @@ -1803,7 +1847,6 @@ paint.begin(m_cache); paint.drawPixmap(dx, 0, *tmpPixmap); paint.end(); -#endif if (dx < 0) { cacheRect = QRect(width() + dx, 0, -dx, height()); } else { @@ -1824,8 +1867,8 @@ #ifdef DEBUG_VIEW_WIDGET_PAINT cerr << "View(" << this << ")::paintEvent: cache is good" << endl; #endif - paint.begin(this); - paint.drawPixmap(cacheRect, *m_cache, cacheRect); + paint.begin(m_buffer); + paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect); paint.end(); QFrame::paintEvent(e); paintedCacheRect = true; @@ -1841,16 +1884,26 @@ // Scrollable (cacheable) items first + ViewProxy proxy(this, dpratio); + if (!paintedCacheRect) { - if (repaintCache) paint.begin(m_cache); - else paint.begin(this); + QRect rectToPaint; + + if (repaintCache) { + paint.begin(m_cache); + rectToPaint = scaledCacheRect; + } else { + paint.begin(m_buffer); + rectToPaint = scaledCacheRect; + } + setPaintFont(paint); - paint.setClipRect(cacheRect); + paint.setClipRect(rectToPaint); paint.setPen(getBackground()); paint.setBrush(getBackground()); - paint.drawRect(cacheRect); + paint.drawRect(rectToPaint); paint.setPen(getForeground()); paint.setBrush(Qt::NoBrush); @@ -1858,7 +1911,10 @@ for (LayerList::iterator i = scrollables.begin(); i != scrollables.end(); ++i) { paint.setRenderHint(QPainter::Antialiasing, false); paint.save(); - (*i)->paint(this, paint, cacheRect); +#ifdef DEBUG_VIEW_WIDGET_PAINT + cerr << "Painting scrollable layer " << *i << " using proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << rectToPaint.x() << "," << rectToPaint.y() << " " << rectToPaint.width() << "x" << rectToPaint.height() << endl; +#endif + (*i)->paint(&proxy, paint, rectToPaint); paint.restore(); } @@ -1871,8 +1927,9 @@ if (repaintCache) { cacheRect |= (e ? e->rect() : rect()); - paint.begin(this); - paint.drawPixmap(cacheRect, *m_cache, cacheRect); + scaledCacheRect = scaledRect(cacheRect, dpratio); + paint.begin(m_buffer); + paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect); paint.end(); } } @@ -1883,13 +1940,15 @@ nonCacheRect |= cacheRect; - paint.begin(this); - paint.setClipRect(nonCacheRect); + QRect scaledNonCacheRect = scaledRect(nonCacheRect, dpratio); + + paint.begin(m_buffer); + paint.setClipRect(scaledNonCacheRect); setPaintFont(paint); if (scrollables.empty()) { paint.setPen(getBackground()); paint.setBrush(getBackground()); - paint.drawRect(nonCacheRect); + paint.drawRect(scaledNonCacheRect); } paint.setPen(getForeground()); @@ -1897,10 +1956,18 @@ for (LayerList::iterator i = nonScrollables.begin(); i != nonScrollables.end(); ++i) { // Profiler profiler2("View::paintEvent non-cacheable"); - (*i)->paint(this, paint, nonCacheRect); +#ifdef DEBUG_VIEW_WIDGET_PAINT + cerr << "Painting non-scrollable layer " << *i << " without proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << nonCacheRect.x() << "," << nonCacheRect.y() << " " << nonCacheRect.width() << "x" << nonCacheRect.height() << endl; +#endif + (*i)->paint(&proxy, paint, scaledNonCacheRect); } paint.end(); + + paint.begin(this); + QRect finalPaintRect = e ? e->rect() : rect(); + paint.drawPixmap(finalPaintRect, *m_buffer, scaledRect(finalPaintRect, dpratio)); + paint.end(); paint.begin(this); setPaintFont(paint); @@ -1925,7 +1992,7 @@ showPlayPointer = false; } } - + if (showPlayPointer) { paint.begin(this); @@ -1974,10 +2041,10 @@ paint.setBrush(Qt::NoBrush); } - int sampleRate = getModelsSampleRate(); + sv_samplerate_t sampleRate = getModelsSampleRate(); QPoint localPos; - int illuminateFrame = -1; + sv_frame_t illuminateFrame = -1; bool closeToLeft, closeToRight; if (shouldIlluminateLocalSelection(localPos, closeToLeft, closeToRight)) { @@ -2145,7 +2212,7 @@ int fontHeight = paint.fontMetrics().height(); int fontAscent = paint.fontMetrics().ascent(); - float v0, v1; + double v0, v1; QString u0, u1; bool b0 = false, b1 = false; @@ -2217,7 +2284,7 @@ } bool bd = false; - float dy = 0.f; + double dy = 0.f; QString du; // dimension, height @@ -2228,7 +2295,7 @@ if (du != "") { if (du == "Hz") { int semis; - float cents; + double cents; semis = Pitch::getPitchForFrequencyDifference(v0, v1, ¢s); dys = QString("[%1 %2 (%3)]") .arg(dy).arg(du) @@ -2333,14 +2400,14 @@ } bool -View::render(QPainter &paint, int xorigin, int f0, int f1) +View::render(QPainter &paint, int xorigin, sv_frame_t f0, sv_frame_t f1) { - int x0 = f0 / m_zoomLevel; - int x1 = f1 / m_zoomLevel; + int x0 = int(f0 / m_zoomLevel); + int x1 = int(f1 / m_zoomLevel); int w = x1 - x0; - int origCentreFrame = m_centreFrame; + sv_frame_t origCentreFrame = m_centreFrame; bool someLayersIncomplete = false; @@ -2412,23 +2479,23 @@ for (LayerList::iterator i = m_layerStack.begin(); i != m_layerStack.end(); ++i) { - if(!((*i)->isLayerDormant(this))){ - - paint.setRenderHint(QPainter::Antialiasing, false); - - paint.save(); - paint.translate(xorigin + x, 0); - - cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << endl; - - (*i)->setSynchronousPainting(true); - - (*i)->paint(this, paint, chunk); - - (*i)->setSynchronousPainting(false); - - paint.restore(); - } + if (!((*i)->isLayerDormant(this))){ + + paint.setRenderHint(QPainter::Antialiasing, false); + + paint.save(); + paint.translate(xorigin + x, 0); + + cerr << "Centre frame now: " << m_centreFrame << " drawing to " << chunk.x() + x + xorigin << ", " << chunk.width() << endl; + + (*i)->setSynchronousPainting(true); + + (*i)->paint(this, paint, chunk); + + (*i)->setSynchronousPainting(false); + + paint.restore(); + } } } @@ -2440,17 +2507,17 @@ QImage * View::toNewImage() { - int f0 = getModelsStartFrame(); - int f1 = getModelsEndFrame(); + sv_frame_t f0 = getModelsStartFrame(); + sv_frame_t f1 = getModelsEndFrame(); return toNewImage(f0, f1); } QImage * -View::toNewImage(int f0, int f1) +View::toNewImage(sv_frame_t f0, sv_frame_t f1) { - int x0 = f0 / getZoomLevel(); - int x1 = f1 / getZoomLevel(); + int x0 = int(f0 / getZoomLevel()); + int x1 = int(f1 / getZoomLevel()); QImage *image = new QImage(x1 - x0, height(), QImage::Format_RGB32); @@ -2468,17 +2535,17 @@ QSize View::getImageSize() { - int f0 = getModelsStartFrame(); - int f1 = getModelsEndFrame(); + sv_frame_t f0 = getModelsStartFrame(); + sv_frame_t f1 = getModelsEndFrame(); return getImageSize(f0, f1); } QSize -View::getImageSize(int f0, int f1) +View::getImageSize(sv_frame_t f0, sv_frame_t f1) { - int x0 = f0 / getZoomLevel(); - int x1 = f1 / getZoomLevel(); + int x0 = int(f0 / getZoomLevel()); + int x1 = int(f1 / getZoomLevel()); return QSize(x1 - x0, height()); }
--- a/view/View.h Fri Sep 12 11:38:55 2014 +0100 +++ b/view/View.h Fri Jun 26 14:13:31 2015 +0100 @@ -19,10 +19,13 @@ #include <QFrame> #include <QProgressBar> +#include "LayerGeometryProvider.h" + #include "base/ZoomConstraint.h" #include "base/PropertyContainer.h" #include "ViewManager.h" #include "base/XmlExportable.h" +#include "base/BaseTypes.h" // #define DEBUG_VIEW_WIDGET_PAINT 1 @@ -48,7 +51,8 @@ */ class View : public QFrame, - public XmlExportable + public XmlExportable, + public LayerGeometryProvider { Q_OBJECT @@ -64,13 +68,13 @@ * This is a calculated value based on the centre-frame, widget * width and zoom level. The result may be negative. */ - int getStartFrame() const; + sv_frame_t getStartFrame() const; /** * Set the widget pan based on the given first visible frame. The * frame value may be negative. */ - void setStartFrame(int); + void setStartFrame(sv_frame_t); /** * Return the centre frame of the visible widget. This is an @@ -78,30 +82,30 @@ * frame values (start, end) are calculated from this based on the * zoom and other factors. */ - int getCentreFrame() const { return m_centreFrame; } + sv_frame_t getCentreFrame() const { return m_centreFrame; } /** * Set the centre frame of the visible widget. */ - void setCentreFrame(int f) { setCentreFrame(f, true); } + void setCentreFrame(sv_frame_t f) { setCentreFrame(f, true); } /** * Retrieve the last visible sample frame on the widget. * This is a calculated value based on the centre-frame, widget * width and zoom level. */ - int getEndFrame() const; + sv_frame_t getEndFrame() const; /** * Return the pixel x-coordinate corresponding to a given sample * frame (which may be negative). */ - int getXForFrame(int frame) const; + int getXForFrame(sv_frame_t frame) const; /** * Return the closest frame to the given pixel x-coordinate. */ - int getFrameForX(int x) const; + sv_frame_t getFrameForX(int x) const; /** * Return the pixel y-coordinate corresponding to a given @@ -111,7 +115,7 @@ * * Not thread-safe in logarithmic mode. Call only from GUI thread. */ - float getYForFrequency(float frequency, float minFreq, float maxFreq, + double getYForFrequency(double frequency, double minFreq, double maxFreq, bool logarithmic) const; /** @@ -120,7 +124,7 @@ * * Not thread-safe in logarithmic mode. Call only from GUI thread. */ - float getFrequencyForY(int y, float minFreq, float maxFreq, + double getFrequencyForY(int y, double minFreq, double maxFreq, bool logarithmic) const; /** @@ -163,7 +167,7 @@ * Return the number of layers, regardless of whether visible or * dormant, i.e. invisible, in this view. */ - virtual int getLayerCount() const { return m_layerStack.size(); } + virtual int getLayerCount() const { return int(m_layerStack.size()); } /** * Return the nth layer, counted in stacking order. That is, @@ -172,7 +176,7 @@ * dormant, i.e. invisible. */ virtual Layer *getLayer(int n) { - if (n < int(m_layerStack.size())) return m_layerStack[n]; + if (in_range_for(m_layerStack, n)) return m_layerStack[n]; else return 0; } @@ -229,7 +233,7 @@ } virtual void setViewManager(ViewManager *m); - virtual void setViewManager(ViewManager *m, int initialFrame); + virtual void setViewManager(ViewManager *m, sv_frame_t initialFrame); virtual ViewManager *getViewManager() const { return m_manager; } virtual void setFollowGlobalPan(bool f); @@ -242,12 +246,6 @@ virtual QColor getForeground() const; virtual QColor getBackground() const; - enum TextStyle { - BoxedText, - OutlinedText, - OutlinedItalicText - }; - virtual void drawVisibleText(QPainter &p, int x, int y, QString text, TextStyle style) const; @@ -294,35 +292,50 @@ virtual PropertyContainer *getPropertyContainer(int i); // Render the contents on a wide canvas - virtual QImage *toNewImage(int f0, int f1); + virtual QImage *toNewImage(sv_frame_t f0, sv_frame_t f1); virtual QImage *toNewImage(); - virtual QSize getImageSize(int f0, int f1); + virtual QSize getImageSize(sv_frame_t f0, sv_frame_t f1); virtual QSize getImageSize(); virtual int getTextLabelHeight(const Layer *layer, QPainter &) const; - virtual bool getValueExtents(QString unit, float &min, float &max, + virtual bool getValueExtents(QString unit, double &min, double &max, bool &log) const; virtual void toXml(QTextStream &stream, QString indent = "", QString extraAttributes = "") const; // First frame actually in model, to right of scale, if present - virtual int getFirstVisibleFrame() const; - virtual int getLastVisibleFrame() const; + virtual sv_frame_t getFirstVisibleFrame() const; + virtual sv_frame_t getLastVisibleFrame() const; - int getModelsStartFrame() const; - int getModelsEndFrame() const; + sv_frame_t getModelsStartFrame() const; + sv_frame_t getModelsEndFrame() const; + + /** + * To be called from a layer, to obtain the extent of the surface + * that the layer is currently painting to. This may be the extent + * of the view (if 1x display scaling is in effect) or of a larger + * cached pixmap (if greater display scaling is in effect). + */ + QRect getPaintRect() const; + + QSize getPaintSize() const { return getPaintRect().size(); } + int getPaintWidth() const { return getPaintRect().width(); } + int getPaintHeight() const { return getPaintRect().height(); } typedef std::set<Model *> ModelSet; ModelSet getModels(); //!!! Model *getAligningModel() const; - int alignFromReference(int) const; - int alignToReference(int) const; - int getAlignedPlaybackFrame() const; + sv_frame_t alignFromReference(sv_frame_t) const; + sv_frame_t alignToReference(sv_frame_t) const; + sv_frame_t getAlignedPlaybackFrame() const; + View *getView() { return this; } + const View *getView() const { return this; } + signals: void propertyContainerAdded(PropertyContainer *pc); void propertyContainerRemoved(PropertyContainer *pc); @@ -334,7 +347,7 @@ void layerModelChanged(); - void centreFrameChanged(int frame, + void centreFrameChanged(sv_frame_t frame, bool globalScroll, PlaybackFollowMode followMode); @@ -344,7 +357,7 @@ public slots: virtual void modelChanged(); - virtual void modelChangedWithin(int startFrame, int endFrame); + virtual void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame); virtual void modelCompletionChanged(); virtual void modelAlignmentCompletionChanged(); virtual void modelReplaced(); @@ -353,9 +366,9 @@ virtual void layerMeasurementRectsChanged(); virtual void layerNameChanged(); - virtual void globalCentreFrameChanged(int); - virtual void viewCentreFrameChanged(View *, int); - virtual void viewManagerPlaybackFrameChanged(int); + virtual void globalCentreFrameChanged(sv_frame_t); + virtual void viewCentreFrameChanged(View *, sv_frame_t); + virtual void viewManagerPlaybackFrameChanged(sv_frame_t); virtual void viewZoomLevelChanged(View *, int, bool); virtual void propertyContainerSelected(View *, PropertyContainer *pc); @@ -374,12 +387,20 @@ virtual void paintEvent(QPaintEvent *e); virtual void drawSelections(QPainter &); virtual bool shouldLabelSelections() const { return true; } - virtual bool render(QPainter &paint, int x0, int f0, int f1); + virtual bool render(QPainter &paint, int x0, sv_frame_t f0, sv_frame_t f1); virtual void setPaintFont(QPainter &paint); + + QSize scaledSize(const QSize &s, int factor) { + return QSize(s.width() * factor, s.height() * factor); + } + QRect scaledRect(const QRect &r, int factor) { + return QRect(r.x() * factor, r.y() * factor, + r.width() * factor, r.height() * factor); + } typedef std::vector<Layer *> LayerList; - int getModelsSampleRate() const; + sv_samplerate_t getModelsSampleRate() const; bool areLayersScrollable() const; LayerList getScrollableBackLayers(bool testChanged, bool &changed) const; LayerList getNonScrollableFrontLayers(bool testChanged, bool &changed) const; @@ -398,25 +419,28 @@ // false. bool hasTopLayerTimeXAxis() const; - bool setCentreFrame(int f, bool doEmit); + bool setCentreFrame(sv_frame_t f, bool doEmit); - void movePlayPointer(int f); + void movePlayPointer(sv_frame_t f); void checkProgress(void *object); int getProgressBarWidth() const; // if visible - int m_centreFrame; + int effectiveDevicePixelRatio() const; + + sv_frame_t m_centreFrame; int m_zoomLevel; bool m_followPan; bool m_followZoom; PlaybackFollowMode m_followPlay; bool m_followPlayIsDetached; - int m_playPointerFrame; + sv_frame_t m_playPointerFrame; bool m_lightBackground; bool m_showProgress; QPixmap *m_cache; - int m_cacheCentreFrame; + QPixmap *m_buffer; + sv_frame_t m_cacheCentreFrame; int m_cacheZoomLevel; bool m_selectionCached;
--- a/view/ViewManager.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/view/ViewManager.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -126,7 +126,7 @@ { } -int +sv_frame_t ViewManager::getGlobalCentreFrame() const { #ifdef DEBUG_VIEW_MANAGER @@ -136,7 +136,7 @@ } void -ViewManager::setGlobalCentreFrame(int f) +ViewManager::setGlobalCentreFrame(sv_frame_t f) { #ifdef DEBUG_VIEW_MANAGER cerr << "ViewManager::setGlobalCentreFrame to " << f << endl; @@ -154,7 +154,7 @@ return m_globalZoom; } -int +sv_frame_t ViewManager::getPlaybackFrame() const { if (m_playSource && m_playSource->isPlaying()) { @@ -164,8 +164,9 @@ } void -ViewManager::setPlaybackFrame(int f) +ViewManager::setPlaybackFrame(sv_frame_t f) { + if (f < 0) f = 0; if (m_playbackFrame != f) { m_playbackFrame = f; emit playbackFrameChanged(f); @@ -187,8 +188,8 @@ m_playbackModel = model; } -int -ViewManager::alignPlaybackFrameToReference(int frame) const +sv_frame_t +ViewManager::alignPlaybackFrameToReference(sv_frame_t frame) const { #ifdef DEBUG_VIEW_MANAGER cerr << "ViewManager::alignPlaybackFrameToReference(" << frame << "): playback model is " << m_playbackModel << endl; @@ -196,7 +197,7 @@ if (!m_playbackModel) { return frame; } else { - int f = m_playbackModel->alignToReference(frame); + sv_frame_t f = m_playbackModel->alignToReference(frame); #ifdef DEBUG_VIEW_MANAGER cerr << "aligned frame = " << f << endl; #endif @@ -204,8 +205,8 @@ } } -int -ViewManager::alignReferenceToPlaybackFrame(int frame) const +sv_frame_t +ViewManager::alignReferenceToPlaybackFrame(sv_frame_t frame) const { #ifdef DEBUG_VIEW_MANAGER cerr << "ViewManager::alignReferenceToPlaybackFrame(" << frame << "): playback model is " << m_playbackModel << endl; @@ -213,7 +214,7 @@ if (!m_playbackModel) { return frame; } else { - int f = m_playbackModel->alignFromReference(frame); + sv_frame_t f = m_playbackModel->alignFromReference(frame); #ifdef DEBUG_VIEW_MANAGER cerr << "aligned frame = " << f << endl; #endif @@ -313,8 +314,8 @@ } } -int -ViewManager::constrainFrameToSelection(int frame) const +sv_frame_t +ViewManager::constrainFrameToSelection(sv_frame_t frame) const { MultiSelection::SelectionList sl = getSelections(); if (sl.empty()) return frame; @@ -373,7 +374,7 @@ } Selection -ViewManager::getContainingSelection(int frame, bool defaultToFollowing) const +ViewManager::getContainingSelection(sv_frame_t frame, bool defaultToFollowing) const { return m_selections.getContainingSelection(frame, defaultToFollowing); } @@ -478,7 +479,7 @@ } } -int +sv_samplerate_t ViewManager::getPlaybackSampleRate() const { if (m_playSource) { @@ -487,7 +488,7 @@ return 0; } -int +sv_samplerate_t ViewManager::getOutputSampleRate() const { if (m_playSource) { @@ -559,7 +560,7 @@ } void -ViewManager::viewCentreFrameChanged(int f, bool locked, +ViewManager::viewCentreFrameChanged(sv_frame_t f, bool locked, PlaybackFollowMode mode) { View *v = dynamic_cast<View *>(sender()); @@ -590,15 +591,15 @@ } void -ViewManager::seek(int f) +ViewManager::seek(sv_frame_t f) { #ifdef DEBUG_VIEW_MANAGER cerr << "ViewManager::seek(" << f << ")" << endl; #endif if (m_playSource && m_playSource->isPlaying()) { - int playFrame = m_playSource->getCurrentPlayingFrame(); - int diff = std::max(f, playFrame) - std::min(f, playFrame); + sv_frame_t playFrame = m_playSource->getCurrentPlayingFrame(); + sv_frame_t diff = std::max(f, playFrame) - std::min(f, playFrame); if (diff > 20000) { m_playbackFrame = f; m_playSource->play(f); @@ -720,3 +721,23 @@ return dark; } +int +ViewManager::scalePixelSize(int pixels) +{ + static double ratio = 0.0; + if (ratio == 0.0) { + double baseEm; +#ifdef Q_OS_MAC + baseEm = 17.0; +#else + baseEm = 15.0; +#endif + double em = QFontMetrics(QFont()).height(); + ratio = em / baseEm; + } + + int scaled = int(pixels * ratio + 0.5); +// cerr << "scaledSize: " << pixels << " -> " << scaled << " at ratio " << ratio << endl; + if (pixels != 0 && scaled == 0) scaled = 1; + return scaled; +}
--- a/view/ViewManager.h Fri Sep 12 11:38:55 2014 +0100 +++ b/view/ViewManager.h Fri Jun 26 14:13:31 2015 +0100 @@ -26,6 +26,7 @@ #include "base/Selection.h" #include "base/Command.h" #include "base/Clipboard.h" +#include "base/BaseTypes.h" class AudioPlaySource; class Model; @@ -82,17 +83,17 @@ bool isPlaying() const; - int getGlobalCentreFrame() const; // the set method is a slot + sv_frame_t getGlobalCentreFrame() const; // the set method is a slot int getGlobalZoom() const; - int getPlaybackFrame() const; // the set method is a slot + sv_frame_t getPlaybackFrame() const; // the set method is a slot // Only meaningful in solo mode, and used for optional alignment feature Model *getPlaybackModel() const; void setPlaybackModel(Model *); - int alignPlaybackFrameToReference(int) const; - int alignReferenceToPlaybackFrame(int) const; + sv_frame_t alignPlaybackFrameToReference(sv_frame_t) const; + sv_frame_t alignReferenceToPlaybackFrame(sv_frame_t) const; bool haveInProgressSelection() const; const Selection &getInProgressSelection(bool &exclusive) const; @@ -106,7 +107,7 @@ void addSelection(const Selection &selection); void removeSelection(const Selection &selection); void clearSelections(); - int constrainFrameToSelection(int frame) const; + sv_frame_t constrainFrameToSelection(sv_frame_t frame) const; /** * Adding a selection normally emits the selectionChangedByUser @@ -121,7 +122,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; Clipboard &getClipboard() { return m_clipboard; } @@ -166,24 +167,31 @@ * differ from this will play back at the wrong speed -- there is * no per-model resampler. */ - int getPlaybackSampleRate() const; + sv_samplerate_t getPlaybackSampleRate() const; /** * The sample rate of the audio output device. If the playback * sample rate differs from this, everything will be resampled at * the output stage. */ - int getOutputSampleRate() const; + sv_samplerate_t getOutputSampleRate() const; /** * The sample rate of the current main model. This may in theory * differ from the playback sample rate, in which case even the * main model will play at the wrong speed. */ - int getMainModelSampleRate() const { return m_mainModelSampleRate; } + sv_samplerate_t getMainModelSampleRate() const { return m_mainModelSampleRate; } - void setMainModelSampleRate(int sr) { m_mainModelSampleRate = sr; } + void setMainModelSampleRate(sv_samplerate_t sr) { m_mainModelSampleRate = sr; } + /** + * Take a "design pixel" size and scale it for the actual + * display. This is relevant to hi-dpi systems that do not do + * pixel doubling (i.e. Windows and Linux rather than OS/X). + */ + int scalePixelSize(int pixels); + enum OverlayMode { NoOverlays, GlobalOverlays, @@ -235,16 +243,16 @@ signals: /** Emitted when user causes the global centre frame to change. */ - void globalCentreFrameChanged(int frame); + void globalCentreFrameChanged(sv_frame_t frame); /** Emitted when user scrolls a view, but doesn't affect global centre. */ - void viewCentreFrameChanged(View *v, int frame); + void viewCentreFrameChanged(View *v, sv_frame_t frame); /** Emitted when a view zooms. */ void viewZoomLevelChanged(View *v, int zoom, bool locked); /** Emitted when the playback frame changes. */ - void playbackFrameChanged(int frame); + void playbackFrameChanged(sv_frame_t frame); /** Emitted when the output levels change. Values in range 0.0 -> 1.0. */ void outputLevelsChanged(float left, float right); @@ -292,24 +300,24 @@ void activity(QString); public slots: - void viewCentreFrameChanged(int, bool, PlaybackFollowMode); + void viewCentreFrameChanged(sv_frame_t, bool, PlaybackFollowMode); void viewZoomLevelChanged(int, bool); - void setGlobalCentreFrame(int); - void setPlaybackFrame(int); + void setGlobalCentreFrame(sv_frame_t); + void setPlaybackFrame(sv_frame_t); void playStatusChanged(bool playing); protected slots: void checkPlayStatus(); - void seek(int); + void seek(sv_frame_t); //!!! void considerZoomChange(void *, int, bool); protected: AudioPlaySource *m_playSource; - int m_globalCentreFrame; + sv_frame_t m_globalCentreFrame; int m_globalZoom; - mutable int m_playbackFrame; + mutable sv_frame_t m_playbackFrame; Model *m_playbackModel; //!!! - int m_mainModelSampleRate; + sv_samplerate_t m_mainModelSampleRate; float m_lastLeft; float m_lastRight;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/view/ViewProxy.h Fri Jun 26 14:13:31 2015 +0100 @@ -0,0 +1,140 @@ +/* -*- 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 VIEW_PROXY_H +#define VIEW_PROXY_H + +#include "LayerGeometryProvider.h" + +class ViewProxy : public LayerGeometryProvider +{ +public: + ViewProxy(View *view, int scaleFactor) : + m_view(view), m_scaleFactor(scaleFactor) { } + + virtual sv_frame_t getStartFrame() const { + return m_view->getStartFrame(); + } + virtual sv_frame_t getCentreFrame() const { + return m_view->getCentreFrame(); + } + virtual sv_frame_t getEndFrame() const { + return m_view->getEndFrame(); + } + virtual int getXForFrame(sv_frame_t frame) const { + //!!! not actually correct, if frame lies between view's pixels + return m_scaleFactor * m_view->getXForFrame(frame); + } + virtual sv_frame_t getFrameForX(int x) const { + sv_frame_t f0 = m_view->getFrameForX(x / m_scaleFactor); + if (m_scaleFactor == 1) return f0; + sv_frame_t f1 = m_view->getFrameForX((x / m_scaleFactor) + 1); + return f0 + ((f1 - f0) * (x % m_scaleFactor)) / m_scaleFactor; + } + virtual sv_frame_t getModelsStartFrame() const { + return m_view->getModelsStartFrame(); + } + virtual sv_frame_t getModelsEndFrame() const { + return m_view->getModelsEndFrame(); + } + virtual double getYForFrequency(double frequency, + double minFreq, double maxFreq, + bool logarithmic) const { + return m_scaleFactor * + m_view->getYForFrequency(frequency, minFreq, maxFreq, logarithmic); + } + virtual double getFrequencyForY(int y, double minFreq, double maxFreq, + bool logarithmic) const { + double f0 = m_view->getFrequencyForY + (y / m_scaleFactor, minFreq, maxFreq, logarithmic); + if (m_scaleFactor == 1) return f0; + double f1 = m_view->getFrequencyForY + ((y / m_scaleFactor) + 1, minFreq, maxFreq, logarithmic); + return f0 + ((f1 - f0) * (y % m_scaleFactor)) / m_scaleFactor; + } + virtual int getTextLabelHeight(const Layer *layer, QPainter &paint) const { + return m_scaleFactor * m_view->getTextLabelHeight(layer, paint); + } + virtual bool getValueExtents(QString unit, double &min, double &max, + bool &log) const { + return m_view->getValueExtents(unit, min, max, log); + } + virtual int getZoomLevel() const { + //!!! aarg, what if it's already 1? + int z = m_view->getZoomLevel(); + cerr << "getZoomLevel: from " << z << " to "; + z = z / m_scaleFactor; + cerr << z << endl; + return z; + } + virtual QRect getPaintRect() const { + QRect r = m_view->getPaintRect(); + return QRect(r.x() * m_scaleFactor, + r.y() * m_scaleFactor, + r.width() * m_scaleFactor, + r.height() * m_scaleFactor); + } + virtual QSize getPaintSize() const { + return getPaintRect().size(); + } + virtual int getPaintWidth() const { + return getPaintRect().width(); + } + virtual int getPaintHeight() const { + return getPaintRect().height(); + } + virtual bool hasLightBackground() const { + return m_view->hasLightBackground(); + } + virtual QColor getForeground() const { + return m_view->getForeground(); + } + virtual QColor getBackground() const { + return m_view->getBackground(); + } + virtual ViewManager *getViewManager() const { + return m_view->getViewManager(); + } + + virtual bool shouldIlluminateLocalFeatures(const Layer *layer, + QPoint &point) const { + QPoint p; + bool should = m_view->shouldIlluminateLocalFeatures(layer, p); + point = QPoint(p.x() * m_scaleFactor, p.y() * m_scaleFactor); + return should; + } + + virtual bool shouldShowFeatureLabels() const { + return m_view->shouldShowFeatureLabels(); + } + + virtual void drawVisibleText(QPainter &p, int x, int y, + QString text, TextStyle style) const { + m_view->drawVisibleText(p, x, y, text, style); + } + + virtual void drawMeasurementRect(QPainter &p, const Layer *layer, + QRect rect, bool focus) const { + m_view->drawMeasurementRect(p, layer, rect, focus); + } + + virtual View *getView() { return m_view; } + virtual const View *getView() const { return m_view; } + +private: + View *m_view; + int m_scaleFactor; +}; + +#endif
--- a/widgets/AudioDial.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/AudioDial.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -121,10 +121,10 @@ QPainter paint; - float angle = AUDIO_DIAL_MIN // offset + double angle = AUDIO_DIAL_MIN // offset + (AUDIO_DIAL_RANGE * - (float(QDial::value() - QDial::minimum()) / - (float(QDial::maximum() - QDial::minimum())))); + (double(QDial::value() - QDial::minimum()) / + (double(QDial::maximum() - QDial::minimum())))); int degrees = int(angle * 180.0 / M_PI); int ns = notchSize(); @@ -268,15 +268,15 @@ // Pointer notch... - float hyp = float(width) / 2.0; - float len = hyp - indent; + double hyp = double(width) / 2.0; + double len = hyp - indent; --len; - float x0 = hyp; - float y0 = hyp; + double x0 = hyp; + double y0 = hyp; - float x = hyp - len * sin(angle); - float y = hyp + len * cos(angle); + double x = hyp - len * sin(angle); + double y = hyp + len * cos(angle); c = palette().dark().color(); pen.setColor(isEnabled() ? c.dark(130) : c); @@ -289,27 +289,27 @@ void AudioDial::drawTick(QPainter &paint, - float angle, int size, bool internal) + double angle, int size, bool internal) { - float hyp = float(size) / 2.0; - float x0 = hyp - (hyp - 1) * sin(angle); - float y0 = hyp + (hyp - 1) * cos(angle); + double hyp = double(size) / 2.0; + double x0 = hyp - (hyp - 1) * sin(angle); + double y0 = hyp + (hyp - 1) * cos(angle); // cerr << "drawTick: angle " << angle << ", size " << size << ", internal " << internal << endl; if (internal) { - float len = hyp / 4; - float x1 = hyp - (hyp - len) * sin(angle); - float y1 = hyp + (hyp - len) * cos(angle); + double len = hyp / 4; + double x1 = hyp - (hyp - len) * sin(angle); + double y1 = hyp + (hyp - len) * cos(angle); paint.drawLine(int(x0), int(y0), int(x1), int(y1)); } else { - float len = hyp / 4; - float x1 = hyp - (hyp + len) * sin(angle); - float y1 = hyp + (hyp + len) * cos(angle); + double len = hyp / 4; + double x1 = hyp - (hyp + len) * sin(angle); + double y1 = hyp + (hyp + len) * cos(angle); paint.drawLine(int(x0), int(y0), int(x1), int(y1)); } @@ -350,7 +350,7 @@ updateMappedValue(value); } -void AudioDial::setDefaultMappedValue(float value) +void AudioDial::setDefaultMappedValue(double value) { m_defaultMappedValue = value; if (m_rangeMapper) { @@ -358,7 +358,7 @@ } } -void AudioDial::setMappedValue(float mappedValue) +void AudioDial::setMappedValue(double mappedValue) { if (m_rangeMapper) { int newPosition = m_rangeMapper->getPositionForValue(mappedValue); @@ -387,7 +387,7 @@ } -float AudioDial::mappedValue() const +double AudioDial::mappedValue() const { if (m_rangeMapper) { // SVDEBUG << "AudioDial::mappedValue(): value = " << value() << ", mappedValue = " << m_mappedValue << endl; @@ -464,11 +464,11 @@ if (m_rangeMapper) { - float min = m_rangeMapper->getValueForPosition(minimum()); - float max = m_rangeMapper->getValueForPosition(maximum()); + double min = m_rangeMapper->getValueForPosition(minimum()); + double max = m_rangeMapper->getValueForPosition(maximum()); if (min > max) { - float tmp = min; + double tmp = min; min = max; max = tmp; } @@ -494,7 +494,7 @@ } } - float newValue = QInputDialog::getDouble + double newValue = QInputDialog::getDouble (this, tr("Enter new value"), text,
--- a/widgets/AudioDial.h Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/AudioDial.h Fri Jun 26 14:13:31 2015 +0100 @@ -73,7 +73,7 @@ void setRangeMapper(RangeMapper *mapper); // I take ownership, will delete const RangeMapper *rangeMapper() const { return m_rangeMapper; } - float mappedValue() const; + double mappedValue() const; int defaultValue() const { return m_defaultValue; } @@ -107,14 +107,14 @@ void setValue(int value); - void setDefaultMappedValue(float mappedValue); + void setDefaultMappedValue(double mappedValue); - void setMappedValue(float mappedValue); + void setMappedValue(double mappedValue); void setToDefault(); protected: - void drawTick(QPainter &paint, float angle, int size, bool internal); + void drawTick(QPainter &paint, double angle, int size, bool internal); virtual void paintEvent(QPaintEvent *); // Alternate mouse behavior event handlers. @@ -133,8 +133,8 @@ QColor m_meterColor; int m_defaultValue; - float m_defaultMappedValue; - float m_mappedValue; + double m_defaultMappedValue; + double m_mappedValue; bool m_noMappedUpdate; // Alternate mouse behavior tracking.
--- a/widgets/CSVFormatDialog.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/CSVFormatDialog.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -30,6 +30,7 @@ #include <QDialogButtonBox> #include <iostream> +#include <cmath> #include "base/Debug.h" @@ -62,7 +63,7 @@ exampleFrame->setPalette(palette); QFont fp; - fp.setPointSize(fp.pointSize() * 0.9); + fp.setPointSize(int(floor(fp.pointSize() * 0.9))); // fp.setFixedPitch(true); // fp.setStyleHint(QFont::TypeWriter); // fp.setFamily("Monospaced"); @@ -99,6 +100,9 @@ cpc->setCurrentIndex(int(m_format.getColumnPurpose(i))); for (int j = 0; j < example.size() && j < 6; ++j) { + if (i >= example[j].size()) { + continue; + } QLabel *label = new QLabel; label->setTextFormat(Qt::PlainText); QString text = TextAbbrev::abbreviate(example[j][i], 35); @@ -117,15 +121,37 @@ layout->addWidget(new QLabel(tr("Timing is specified:")), row, 0); m_timingTypeCombo = new QComboBox; - m_timingTypeCombo->addItem(tr("Explicitly, in seconds")); - m_timingTypeCombo->addItem(tr("Explicitly, in audio sample frames")); - m_timingTypeCombo->addItem(tr("Implicitly: rows are equally spaced in time")); + + m_timingLabels = { + { TimingExplicitSeconds, tr("Explicitly, in seconds") }, + { TimingExplicitMsec, tr("Explicitly, in milliseconds") }, + { TimingExplicitSamples, tr("Explicitly, in audio sample frames") }, + { TimingImplicit, tr("Implicitly: rows are equally spaced in time") } + }; + + for (auto &l: m_timingLabels) { + m_timingTypeCombo->addItem(l.second); + } + layout->addWidget(m_timingTypeCombo, row++, 1, 1, 2); + connect(m_timingTypeCombo, SIGNAL(activated(int)), this, SLOT(timingTypeChanged(int))); - m_timingTypeCombo->setCurrentIndex - (m_format.getTimingType() == CSVFormat::ExplicitTiming ? - m_format.getTimeUnits() == CSVFormat::TimeSeconds ? 0 : 1 : 2); + + m_initialTimingOption = TimingImplicit; + if (m_format.getTimingType() == CSVFormat::ExplicitTiming) { + switch (m_format.getTimeUnits()) { + case CSVFormat::TimeSeconds: + m_initialTimingOption = TimingExplicitSeconds; break; + case CSVFormat::TimeMilliseconds: + m_initialTimingOption = TimingExplicitMsec; break; + case CSVFormat::TimeAudioFrames: + m_initialTimingOption = TimingExplicitSamples; break; + case CSVFormat::TimeWindows: + m_initialTimingOption = TimingImplicit; break; + } + } + m_timingTypeCombo->setCurrentIndex(int(m_initialTimingOption)); m_sampleRateLabel = new QLabel(tr("Audio sample rate (Hz):")); layout->addWidget(m_sampleRateLabel, row, 0); @@ -184,7 +210,6 @@ setLayout(layout); timingTypeChanged(m_timingTypeCombo->currentIndex()); - updateModelLabel(); } CSVFormatDialog::~CSVFormatDialog() @@ -225,37 +250,66 @@ } void +CSVFormatDialog::applyStartTimePurpose() +{ + // First check if we already have any. NB there may be fewer than + // m_format.getColumnCount() elements in m_columnPurposeCombos + // (because of the fuzzy column behaviour) + for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { + QComboBox *cb = m_columnPurposeCombos[i]; + if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) { + return; + } + } + // and if not, select one + for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { + QComboBox *cb = m_columnPurposeCombos[i]; + if (cb->currentIndex() == int(CSVFormat::ColumnValue)) { + cb->setCurrentIndex(int(CSVFormat::ColumnStartTime)); + return; + } + } +} + +void +CSVFormatDialog::removeStartTimePurpose() +{ + // NB there may be fewer than m_format.getColumnCount() elements + // in m_columnPurposeCombos (because of the fuzzy column + // behaviour) + for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { + QComboBox *cb = m_columnPurposeCombos[i]; + if (cb->currentIndex() == int(CSVFormat::ColumnStartTime)) { + cb->setCurrentIndex(int(CSVFormat::ColumnValue)); + } + } +} + +void +CSVFormatDialog::updateComboVisibility() +{ + bool wantRate = (m_format.getTimingType() == CSVFormat::ImplicitTiming || + m_format.getTimeUnits() == CSVFormat::TimeAudioFrames); + bool wantWindow = (m_format.getTimingType() == CSVFormat::ImplicitTiming); + + m_sampleRateCombo->setEnabled(wantRate); + m_sampleRateLabel->setEnabled(wantRate); + + m_windowSizeCombo->setEnabled(wantWindow); + m_windowSizeLabel->setEnabled(wantWindow); +} + +void CSVFormatDialog::timingTypeChanged(int type) { - switch (type) { - - case 0: - m_format.setTimingType(CSVFormat::ExplicitTiming); - m_format.setTimeUnits(CSVFormat::TimeSeconds); - m_sampleRateCombo->setEnabled(false); - m_sampleRateLabel->setEnabled(false); - m_windowSizeCombo->setEnabled(false); - m_windowSizeLabel->setEnabled(false); - break; - - case 1: - m_format.setTimingType(CSVFormat::ExplicitTiming); - m_format.setTimeUnits(CSVFormat::TimeAudioFrames); - m_sampleRateCombo->setEnabled(true); - m_sampleRateLabel->setEnabled(true); - m_windowSizeCombo->setEnabled(false); - m_windowSizeLabel->setEnabled(false); - break; - - case 2: - m_format.setTimingType(CSVFormat::ImplicitTiming); - m_format.setTimeUnits(CSVFormat::TimeWindows); - m_sampleRateCombo->setEnabled(true); - m_sampleRateLabel->setEnabled(true); - m_windowSizeCombo->setEnabled(true); - m_windowSizeLabel->setEnabled(true); - break; + // Update any column purpose combos + if (TimingOption(type) == TimingImplicit) { + removeStartTimePurpose(); + } else { + applyStartTimePurpose(); } + updateFormatFromDialog(); + updateComboVisibility(); } void @@ -278,43 +332,26 @@ CSVFormatDialog::columnPurposeChanged(int p) { QObject *o = sender(); - QComboBox *cb = qobject_cast<QComboBox *>(o); if (!cb) return; CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose)p; - bool haveStartTime = false; - bool haveDuration = false; - bool havePitch = false; - int valueCount = 0; - + bool haveStartTime = false; // so as to update timing type combo appropriately + + // Ensure the column purpose combos are consistent with one + // another, without reference to m_format (which we'll update + // separately) + for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { - CSVFormat::ColumnPurpose cp = m_format.getColumnPurpose(i); - - bool thisChanged = (cb == m_columnPurposeCombos[i]); + QComboBox *thisCombo = m_columnPurposeCombos[i]; - if (thisChanged) { - - cerr << "i == " << i << ", fuzzy == " << m_fuzzyColumn - << ", p == " << p << endl; - - if (i == m_fuzzyColumn) { - for (int j = i; j < m_format.getColumnCount(); ++j) { - if (p == 0) { // Ignore - m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown); - } else { // Value - m_format.setColumnPurpose(j, CSVFormat::ColumnValue); - ++valueCount; - } - } - continue; - } - - cp = purpose; - - } else { + CSVFormat::ColumnPurpose cp = (CSVFormat::ColumnPurpose) + (thisCombo->currentIndex()); + bool thisChanged = (cb == thisCombo); + + if (!thisChanged) { if (i == m_fuzzyColumn) continue; @@ -339,29 +376,98 @@ cp = CSVFormat::ColumnUnknown; } } + + if (cp == CSVFormat::ColumnStartTime) { + haveStartTime = true; + } + + thisCombo->setCurrentIndex(int(cp)); + + } else { + if (purpose == CSVFormat::ColumnStartTime) { + haveStartTime = true; + } } + } - if (cp == CSVFormat::ColumnStartTime) { + if (!haveStartTime) { + m_timingTypeCombo->setCurrentIndex(int(TimingImplicit)); + } else if (m_timingTypeCombo->currentIndex() == int(TimingImplicit)) { + if (m_initialTimingOption == TimingImplicit) { + m_timingTypeCombo->setCurrentIndex(TimingExplicitSeconds); + } else { + m_timingTypeCombo->setCurrentIndex(m_initialTimingOption); + } + } + + updateFormatFromDialog(); + updateComboVisibility(); +} + +void +CSVFormatDialog::updateFormatFromDialog() +{ + switch (TimingOption(m_timingTypeCombo->currentIndex())) { + + case TimingExplicitSeconds: + m_format.setTimingType(CSVFormat::ExplicitTiming); + m_format.setTimeUnits(CSVFormat::TimeSeconds); + break; + + case TimingExplicitMsec: + m_format.setTimingType(CSVFormat::ExplicitTiming); + m_format.setTimeUnits(CSVFormat::TimeMilliseconds); + break; + + case TimingExplicitSamples: + m_format.setTimingType(CSVFormat::ExplicitTiming); + m_format.setTimeUnits(CSVFormat::TimeAudioFrames); + break; + + case TimingImplicit: + m_format.setTimingType(CSVFormat::ImplicitTiming); + m_format.setTimeUnits(CSVFormat::TimeWindows); + break; + } + + bool haveStartTime = false; + bool haveDuration = false; + bool havePitch = false; + int valueCount = 0; + + for (int i = 0; i < m_columnPurposeCombos.size(); ++i) { + + QComboBox *thisCombo = m_columnPurposeCombos[i]; + + CSVFormat::ColumnPurpose purpose = (CSVFormat::ColumnPurpose) + (thisCombo->currentIndex()); + + if (purpose == CSVFormat::ColumnStartTime) { haveStartTime = true; } - if (cp == CSVFormat::ColumnEndTime || - cp == CSVFormat::ColumnDuration) { + if (purpose == CSVFormat::ColumnEndTime || + purpose == CSVFormat::ColumnDuration) { haveDuration = true; } - if (cp == CSVFormat::ColumnPitch) { + if (purpose == CSVFormat::ColumnPitch) { havePitch = true; } - if (cp == CSVFormat::ColumnValue) { + if (purpose == CSVFormat::ColumnValue) { ++valueCount; } - m_columnPurposeCombos[i]->setCurrentIndex(int(cp)); - m_format.setColumnPurpose(i, cp); - } + m_format.setColumnPurpose(i, purpose); - if (!haveStartTime) { - m_timingTypeCombo->setCurrentIndex(2); - timingTypeChanged(2); + if (i == m_fuzzyColumn) { + for (int j = i + 1; j < m_format.getColumnCount(); ++j) { + if (purpose == CSVFormat::ColumnUnknown) { + m_format.setColumnPurpose(j, CSVFormat::ColumnUnknown); + } else { // Value + m_format.setColumnPurpose(j, CSVFormat::ColumnValue); + ++valueCount; + } + } + } } if (haveStartTime && haveDuration) { @@ -384,3 +490,4 @@ } +
--- a/widgets/CSVFormatDialog.h Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/CSVFormatDialog.h Fri Jun 26 14:13:31 2015 +0100 @@ -40,11 +40,26 @@ void sampleRateChanged(QString); void windowSizeChanged(QString); void columnPurposeChanged(int purpose); + + void updateFormatFromDialog(); void updateModelLabel(); protected: CSVFormat m_format; int m_maxDisplayCols; + + enum TimingOption { + TimingExplicitSeconds = 0, + TimingExplicitMsec, + TimingExplicitSamples, + TimingImplicit + }; + std::map<TimingOption, QString> m_timingLabels; + TimingOption m_initialTimingOption; + + void updateComboVisibility(); + void applyStartTimePurpose(); + void removeStartTimePurpose(); QComboBox *m_timingTypeCombo; QLabel *m_sampleRateLabel;
--- a/widgets/CommandHistory.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/CommandHistory.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -26,6 +26,8 @@ #include "base/Command.h" +#include "IconLoader.h" + #include <QRegExp> #include <QMenu> #include <QToolBar> @@ -53,12 +55,16 @@ m_bundleTimer(0), m_bundleTimeout(3000) { - m_undoAction = new QAction(QIcon(":/icons/undo.png"), tr("&Undo"), this); + IconLoader loader; + QIcon undoIcon(loader.load("undo")); + QIcon redoIcon(loader.load("redo")); + + m_undoAction = new QAction(undoIcon, ("&Undo"), this); m_undoAction->setShortcut(tr("Ctrl+Z")); m_undoAction->setStatusTip(tr("Undo the last editing operation")); connect(m_undoAction, SIGNAL(triggered()), this, SLOT(undo())); - m_undoMenuAction = new QAction(QIcon(":/icons/undo.png"), tr("&Undo"), this); + m_undoMenuAction = new QAction(undoIcon, tr("&Undo"), this); connect(m_undoMenuAction, SIGNAL(triggered()), this, SLOT(undo())); m_undoMenu = new QMenu(tr("&Undo")); @@ -66,12 +72,12 @@ connect(m_undoMenu, SIGNAL(triggered(QAction *)), this, SLOT(undoActivated(QAction*))); - m_redoAction = new QAction(QIcon(":/icons/redo.png"), tr("Re&do"), this); + m_redoAction = new QAction(redoIcon, tr("Re&do"), this); m_redoAction->setShortcut(tr("Ctrl+Shift+Z")); m_redoAction->setStatusTip(tr("Redo the last operation that was undone")); connect(m_redoAction, SIGNAL(triggered()), this, SLOT(redo())); - m_redoMenuAction = new QAction(QIcon(":/icons/redo.png"), tr("Re&do"), this); + m_redoMenuAction = new QAction(redoIcon, tr("Re&do"), this); connect(m_redoMenuAction, SIGNAL(triggered()), this, SLOT(redo())); m_redoMenu = new QMenu(tr("Re&do")); @@ -420,14 +426,14 @@ CommandHistory::documentSaved() { closeBundle(); - m_savedAt = m_undoStack.size(); + m_savedAt = int(m_undoStack.size()); } void CommandHistory::clipCommands() { - if ((int)m_undoStack.size() > m_undoLimit) { - m_savedAt -= (m_undoStack.size() - m_undoLimit); + if (int(m_undoStack.size()) > m_undoLimit) { + m_savedAt -= (int(m_undoStack.size()) - m_undoLimit); } clipStack(m_undoStack, m_undoLimit);
--- a/widgets/Fader.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/Fader.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -110,7 +110,7 @@ if (vx > getMaxX()) vx = getMaxX(); if (vx < 0) vx = 0; - float fval = AudioLevel::fader_to_multiplier + float fval = (float)AudioLevel::fader_to_multiplier (vx, getMaxX(), AudioLevel::LongFader); setValue(fval); @@ -132,20 +132,20 @@ Fader::mouseDoubleClickEvent(QMouseEvent *) { bool ok = false; - float min = AudioLevel::fader_to_dB + float min = (float)AudioLevel::fader_to_dB (0, getMaxX(), AudioLevel::LongFader); - float max = AudioLevel::fader_to_dB + float max = (float)AudioLevel::fader_to_dB (getMaxX(), getMaxX(), AudioLevel::LongFader); - float deft = AudioLevel::multiplier_to_dB(m_value); + float deft = (float)AudioLevel::multiplier_to_dB(m_value); - float dB = QInputDialog::getDouble + float dB = (float)QInputDialog::getDouble (this, tr("Enter new fader level"), tr("New fader level, from %1 to %2 dBFS:").arg(min).arg(max), deft, min, max, 3, &ok); if (ok) { - float value = AudioLevel::dB_to_multiplier(dB); + float value = (float)AudioLevel::dB_to_multiplier(dB); setValue(value); emit valueChanged(value); update(); @@ -179,9 +179,9 @@ //!!! needs improvement if (ev->delta() > 0) { - setValue(m_value * 1.1); + setValue(m_value * 1.f); } else { - setValue(m_value / 1.1); + setValue(m_value / 1.f); } update(); @@ -203,7 +203,7 @@ void Fader::setValue(float v) { - float max = AudioLevel::dB_to_multiplier(10.0); + float max = (float)AudioLevel::dB_to_multiplier(10.0); if (v > max) { v = max; @@ -213,7 +213,7 @@ if (m_value != v) { m_value = v; - float db = AudioLevel::multiplier_to_dB(m_value); + float db = (float)AudioLevel::multiplier_to_dB(m_value); QString text; if (db <= AudioLevel::DB_FLOOR) { text = tr("Level: Off");
--- a/widgets/IconLoader.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/IconLoader.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -19,8 +19,17 @@ #include <QApplication> #include <QPainter> #include <QPalette> +#include <QFile> +#include <QSvgRenderer> -static const char *autoInvertExceptions[] = { +#include <vector> +#include <set> + +#include "base/Debug.h" + +using namespace std; + +static set<QString> autoInvertExceptions { // These are the icons that look OK in their default colours, even // in a colour scheme with a black background. (They may also be // icons that would look worse if we tried to auto-invert them.) @@ -29,16 +38,13 @@ // supply inverted versions -- the loader will load xx_inverse.png // in preference to xx.png if a dark background is found.) "fileclose", - "filenew-22", "filenew", - "fileopen-22", "fileopen", "fileopenaudio", "fileopensession", - "filesave-22", "filesave", - "filesaveas-22", "filesaveas", + "filesaveas-sv", "help", "editcut", "editcopy", @@ -51,42 +57,121 @@ "zoom" }; +static vector<int> sizes { 0, 16, 22, 24, 32, 48, 64, 128 }; + QIcon IconLoader::load(QString name) { - QPixmap pmap(loadPixmap(name)); - if (pmap.isNull()) return QIcon(); - else return QIcon(pmap); + QIcon icon; + for (int sz: sizes) { + QPixmap pmap(loadPixmap(name, sz)); + if (!pmap.isNull()) icon.addPixmap(pmap); + } + return icon; +} + +bool +IconLoader::shouldInvert() const +{ + QColor bg = QApplication::palette().window().color(); + bool darkBackground = (bg.red() + bg.green() + bg.blue() <= 384); + return darkBackground; +} + +bool +IconLoader::shouldAutoInvert(QString name) const +{ + if (shouldInvert()) { + return (autoInvertExceptions.find(name) == autoInvertExceptions.end()); + } else { + return false; + } } QPixmap -IconLoader::loadPixmap(QString name) +IconLoader::loadPixmap(QString name, int size) { - QColor bg = QApplication::palette().window().color(); - if (bg.red() + bg.green() + bg.blue() > 384) { // light background - QPixmap pmap(QString(":icons/%1").arg(name)); - if (pmap.isNull()) { - pmap = QPixmap(QString(":icons/%1.png").arg(name)); - } - return pmap; + bool invert = shouldInvert(); + + QString scalableName, nonScalableName; + QPixmap pmap; + + nonScalableName = makeNonScalableFilename(name, size, invert); + pmap = QPixmap(nonScalableName); + if (!pmap.isNull()) return pmap; + + if (size > 0) { + scalableName = makeScalableFilename(name, invert); + pmap = loadScalable(scalableName, size); + if (!pmap.isNull()) return pmap; } - QPixmap pmap(QString(":icons/%1").arg(name)); - if (pmap.isNull()) { - pmap = QPixmap(QString(":icons/%1_inverse.png").arg(name)); - if (pmap.isNull()) { - pmap = QPixmap(QString(":icons/%1.png").arg(name)); - } - } - if (pmap.isNull()) return pmap; + if (invert && shouldAutoInvert(name)) { - for (int i = 0; i < int(sizeof(autoInvertExceptions)/ - sizeof(autoInvertExceptions[0])); ++i) { - if (autoInvertExceptions[i] == name) { - return pmap; + nonScalableName = makeNonScalableFilename(name, size, false); + pmap = QPixmap(nonScalableName); + if (!pmap.isNull()) return invertPixmap(pmap); + + if (size > 0) { + scalableName = makeScalableFilename(name, false); + pmap = loadScalable(scalableName, size); + if (!pmap.isNull()) return invertPixmap(pmap); } } + return QPixmap(); +} + +QPixmap +IconLoader::loadScalable(QString name, int size) +{ + if (!QFile(name).exists()) { + cerr << "loadScalable: no such file as: \"" << name << "\"" << endl; + return QPixmap(); + } + QPixmap pmap(size, size); + pmap.fill(Qt::transparent); + QSvgRenderer renderer(name); + QPainter painter; + painter.begin(&pmap); + cerr << "calling renderer for " << name << " at size " << size << "..." << endl; + renderer.render(&painter); + cerr << "renderer completed" << endl; + painter.end(); + return pmap; +} + +QString +IconLoader::makeNonScalableFilename(QString name, int size, bool invert) +{ + if (invert) { + if (size == 0) { + return QString(":icons/%1_inverse.png").arg(name); + } else { + return QString(":icons/%1-%2_inverse.png").arg(name).arg(size); + } + } else { + if (size == 0) { + return QString(":icons/%1.png").arg(name); + } else { + return QString(":icons/%1-%2.png").arg(name).arg(size); + } + } +} + +QString +IconLoader::makeScalableFilename(QString name, bool invert) +{ + if (invert) { + return QString(":icons/scalable/%1_inverse.svg").arg(name); + } else { + return QString(":icons/scalable/%1.svg").arg(name); + } +} + +QPixmap +IconLoader::invertPixmap(QPixmap pmap) +{ // No suitable inverted icon found for black background; try to // auto-invert the default one
--- a/widgets/IconLoader.h Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/IconLoader.h Fri Jun 26 14:13:31 2015 +0100 @@ -25,7 +25,15 @@ virtual ~IconLoader() { } QIcon load(QString name); - QPixmap loadPixmap(QString name); + +private: + bool shouldInvert() const; + bool shouldAutoInvert(QString) const; + QPixmap loadPixmap(QString, int); + QPixmap loadScalable(QString, int); + QPixmap invertPixmap(QPixmap); + QString makeScalableFilename(QString, bool); + QString makeNonScalableFilename(QString, int, bool); }; #endif
--- a/widgets/ItemEditDialog.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/ItemEditDialog.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -28,7 +28,7 @@ #include <float.h> // for FLT_MIN/MAX -ItemEditDialog::ItemEditDialog(int sampleRate, int options, +ItemEditDialog::ItemEditDialog(sv_samplerate_t sampleRate, int options, QString valueUnits, QWidget *parent) : QDialog(parent), m_sampleRate(sampleRate), @@ -193,19 +193,19 @@ } void -ItemEditDialog::setFrameTime(int frame) +ItemEditDialog::setFrameTime(sv_frame_t frame) { if (!m_frameTimeSpinBox) return; RealTime rt(RealTime::frame2RealTime(frame, m_sampleRate)); m_realTimeSecsSpinBox->setValue(rt.sec); m_realTimeUSecsSpinBox->setValue(rt.usec()); - m_frameTimeSpinBox->setValue(frame); + m_frameTimeSpinBox->setValue(int(frame)); m_defaultFrame = frame; m_resetButton->setEnabled(false); } -int +sv_frame_t ItemEditDialog::getFrameTime() const { return m_frameTimeSpinBox->value(); @@ -224,19 +224,19 @@ } void -ItemEditDialog::setFrameDuration(int duration) +ItemEditDialog::setFrameDuration(sv_frame_t duration) { if (!m_frameDurationSpinBox) return; RealTime rt(RealTime::frame2RealTime(duration, m_sampleRate)); m_realDurationSecsSpinBox->setValue(rt.sec); m_realDurationUSecsSpinBox->setValue(rt.usec()); - m_frameDurationSpinBox->setValue(duration); + m_frameDurationSpinBox->setValue(int(duration)); m_defaultDuration = duration; m_resetButton->setEnabled(false); } -int +sv_frame_t ItemEditDialog::getFrameDuration() const { return m_frameDurationSpinBox->value(); @@ -267,7 +267,7 @@ float ItemEditDialog::getValue() const { - return m_valueSpinBox->value(); + return float(m_valueSpinBox->value()); } void @@ -306,8 +306,8 @@ { RealTime rt = getRealTime(); rt.sec = i; - int frame = RealTime::realTime2Frame(rt, m_sampleRate); - m_frameTimeSpinBox->setValue(frame); + sv_frame_t frame = RealTime::realTime2Frame(rt, m_sampleRate); + m_frameTimeSpinBox->setValue(int(frame)); m_resetButton->setEnabled(true); } @@ -316,8 +316,8 @@ { RealTime rt = getRealTime(); rt.nsec = i * 1000; - int frame = RealTime::realTime2Frame(rt, m_sampleRate); - m_frameTimeSpinBox->setValue(frame); + sv_frame_t frame = RealTime::realTime2Frame(rt, m_sampleRate); + m_frameTimeSpinBox->setValue(int(frame)); m_resetButton->setEnabled(true); } @@ -341,8 +341,8 @@ { RealTime rt = getRealDuration(); rt.sec = i; - int frame = RealTime::realTime2Frame(rt, m_sampleRate); - m_frameDurationSpinBox->setValue(frame); + sv_frame_t frame = RealTime::realTime2Frame(rt, m_sampleRate); + m_frameDurationSpinBox->setValue(int(frame)); m_resetButton->setEnabled(true); } @@ -351,8 +351,8 @@ { RealTime rt = getRealDuration(); rt.nsec = i * 1000; - int frame = RealTime::realTime2Frame(rt, m_sampleRate); - m_frameDurationSpinBox->setValue(frame); + sv_frame_t frame = RealTime::realTime2Frame(rt, m_sampleRate); + m_frameDurationSpinBox->setValue(int(frame)); m_resetButton->setEnabled(true); }
--- a/widgets/ItemEditDialog.h Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/ItemEditDialog.h Fri Jun 26 14:13:31 2015 +0100 @@ -37,17 +37,17 @@ ShowText = 1 << 3 }; - ItemEditDialog(int sampleRate, int options, QString valueUnits = "", + ItemEditDialog(sv_samplerate_t sampleRate, int options, QString valueUnits = "", QWidget *parent = 0); - void setFrameTime(int frame); - int getFrameTime() const; + void setFrameTime(sv_frame_t frame); + sv_frame_t getFrameTime() const; void setRealTime(RealTime rt); RealTime getRealTime() const; - void setFrameDuration(int frame); - int getFrameDuration() const; + void setFrameDuration(sv_frame_t frame); + sv_frame_t getFrameDuration() const; void setRealDuration(RealTime rt); RealTime getRealDuration() const; @@ -59,10 +59,10 @@ QString getText() const; protected slots: - void frameTimeChanged(int); + void frameTimeChanged(int); // must be int as invoked from int signal void realTimeSecsChanged(int); void realTimeUSecsChanged(int); - void frameDurationChanged(int); + void frameDurationChanged(int); // must be int as invoked from int signal void realDurationSecsChanged(int); void realDurationUSecsChanged(int); void valueChanged(double); @@ -70,9 +70,9 @@ void reset(); protected: - int m_sampleRate; - int m_defaultFrame; - int m_defaultDuration; + sv_samplerate_t m_sampleRate; + sv_frame_t m_defaultFrame; + sv_frame_t m_defaultDuration; float m_defaultValue; QString m_defaultText; QSpinBox *m_frameTimeSpinBox;
--- a/widgets/LayerTree.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/LayerTree.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -253,7 +253,7 @@ int ModelMetadataModel::rowCount(const QModelIndex &parent) const { - if (!parent.isValid()) return m_models.size(); + if (!parent.isValid()) return int(m_models.size()); return 0; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/LevelPanToolButton.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -0,0 +1,173 @@ +/* -*- 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. +*/ + +#include "LevelPanToolButton.h" +#include "LevelPanWidget.h" + +#include <QMenu> +#include <QWidgetAction> +#include <QImage> +#include <QStylePainter> +#include <QStyleOptionToolButton> + +#include <iostream> +using std::cerr; +using std::endl; + +LevelPanToolButton::LevelPanToolButton(QWidget *parent) : + QToolButton(parent), + m_pixels(32), + m_pixelsBig(32 * 3), + m_muted(false), + m_savedLevel(1.f) +{ + m_lpw = new LevelPanWidget(); + + connect(m_lpw, SIGNAL(levelChanged(float)), this, SIGNAL(levelChanged(float))); + connect(m_lpw, SIGNAL(levelChanged(float)), this, SLOT(selfLevelChanged(float))); + + connect(m_lpw, SIGNAL(panChanged(float)), this, SIGNAL(panChanged(float))); + connect(m_lpw, SIGNAL(panChanged(float)), this, SLOT(update())); + + connect(this, SIGNAL(clicked(bool)), this, SLOT(selfClicked())); + + QMenu *menu = new QMenu(); + QWidgetAction *wa = new QWidgetAction(menu); + wa->setDefaultWidget(m_lpw); + menu->addAction(wa); + + setPopupMode(InstantPopup); + setMenu(menu); + + setImageSize(m_pixels); + setBigImageSize(m_pixelsBig); +} + +LevelPanToolButton::~LevelPanToolButton() +{ +} + +float +LevelPanToolButton::getLevel() const +{ + return m_lpw->getLevel(); +} + +float +LevelPanToolButton::getPan() const +{ + return m_lpw->getPan(); +} + +bool +LevelPanToolButton::includesMute() const +{ + return m_lpw->includesMute(); +} + +void +LevelPanToolButton::setImageSize(int pixels) +{ + m_pixels = pixels; + + QPixmap px(m_pixels, m_pixels); + px.fill(Qt::transparent); + setIcon(px); +} + +void +LevelPanToolButton::setBigImageSize(int pixels) +{ + m_pixelsBig = pixels; + + m_lpw->setFixedWidth(m_pixelsBig); + m_lpw->setFixedHeight(m_pixelsBig); +} + +void +LevelPanToolButton::setLevel(float level) +{ + m_lpw->setLevel(level); + update(); +} + +void +LevelPanToolButton::setPan(float pan) +{ + m_lpw->setPan(pan); + update(); +} + +void +LevelPanToolButton::setIncludeMute(bool include) +{ + m_lpw->setIncludeMute(include); + update(); +} + +void +LevelPanToolButton::setEnabled(bool enabled) +{ + m_lpw->setEnabled(enabled); + QToolButton::setEnabled(enabled); +} + +void +LevelPanToolButton::selfLevelChanged(float level) +{ + if (level > 0.f) { + m_muted = false; + } else { + m_muted = true; + m_savedLevel = 1.f; + } + update(); +} + +void +LevelPanToolButton::selfClicked() +{ + cerr << "selfClicked" << endl; + + if (m_muted) { + m_muted = false; + m_lpw->setLevel(m_savedLevel); + emit levelChanged(m_savedLevel); + } else { + m_savedLevel = m_lpw->getLevel(); + m_muted = true; + m_lpw->setLevel(0.f); + emit levelChanged(0.f); + } + update(); +} + +void +LevelPanToolButton::paintEvent(QPaintEvent *) +{ + QStylePainter p(this); + QStyleOptionToolButton opt; + initStyleOption(&opt); + opt.features &= (~QStyleOptionToolButton::HasMenu); + p.drawComplexControl(QStyle::CC_ToolButton, opt); + + if (m_pixels >= height()) { + setImageSize(height()-1); + } + + double margin = (double(height()) - m_pixels) / 2.0; + m_lpw->renderTo(this, QRectF(margin, margin, m_pixels, m_pixels), false); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/LevelPanToolButton.h Fri Jun 26 14:13:31 2015 +0100 @@ -0,0 +1,73 @@ +/* -*- 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 LEVEL_PAN_TOOLBUTTON_H +#define LEVEL_PAN_TOOLBUTTON_H + +#include <QToolButton> + +class LevelPanWidget; + +class LevelPanToolButton : public QToolButton +{ + Q_OBJECT + +public: + LevelPanToolButton(QWidget *parent = 0); + ~LevelPanToolButton(); + + /// Return level as a gain value in the range [0,1] + float getLevel() const; + + /// Return pan as a value in the range [-1,1] + float getPan() const; + + /// Discover whether the level range includes muting or not + bool includesMute() const; + + void setImageSize(int pixels); + + void setBigImageSize(int pixels); + +public slots: + /// Set level in the range [0,1] -- will be rounded + void setLevel(float); + + /// Set pan in the range [-1,1] -- will be rounded + void setPan(float); + + /// Specify whether the level range should include muting or not + void setIncludeMute(bool); + + void setEnabled(bool enabled); + +signals: + void levelChanged(float); + void panChanged(float); + +private slots: + void selfLevelChanged(float); + void selfClicked(); + +protected: + void paintEvent(QPaintEvent *); + + LevelPanWidget *m_lpw; + int m_pixels; + int m_pixelsBig; + bool m_muted; + float m_savedLevel; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/LevelPanWidget.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -0,0 +1,388 @@ +/* -*- 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. +*/ + +#include "LevelPanWidget.h" + +#include <QPainter> +#include <QMouseEvent> +#include <QWheelEvent> + +#include "layer/ColourMapper.h" +#include "base/AudioLevel.h" + +#include <iostream> +#include <cmath> +#include <cassert> + +using std::cerr; +using std::endl; + +static const int maxLevel = 4; // min is 0, may be mute or not depending on m_includeMute +static const int maxPan = 2; // range is -maxPan to maxPan + +LevelPanWidget::LevelPanWidget(QWidget *parent) : + QWidget(parent), + m_level(maxLevel), + m_pan(0), + m_editable(true), + m_includeMute(true) +{ +} + +LevelPanWidget::~LevelPanWidget() +{ +} + +QSize +LevelPanWidget::sizeHint() const +{ + static double ratio = 0.0; + if (ratio == 0.0) { + double baseEm; +#ifdef Q_OS_MAC + baseEm = 17.0; +#else + baseEm = 15.0; +#endif + double em = QFontMetrics(QFont()).height(); + ratio = em / baseEm; + } + + int pixels = 40; + int scaled = int(pixels * ratio + 0.5); + if (pixels != 0 && scaled == 0) scaled = 1; + return QSize(scaled, scaled); +} + +static int +db_to_level(double db) +{ + // Only if !m_includeMute, otherwise AudioLevel is used. + // Levels are: +6 0 -6 -12 -20 + assert(maxLevel == 4); + if (db > 3.) return 4; + else if (db > -3.) return 3; + else if (db > -9.) return 2; + else if (db > -16.) return 1; + else return 0; +} + +static double +level_to_db(int level) +{ + // Only if !m_includeMute, otherwise AudioLevel is used. + // Levels are: +6 0 -6 -12 -20 + assert(maxLevel == 4); + if (level >= 4) return 6.; + else if (level == 3) return 0.; + else if (level == 2) return -6.; + else if (level == 1) return -12.; + else return -20.; +} + +void +LevelPanWidget::setLevel(float flevel) +{ + int level; + if (m_includeMute) { + level = AudioLevel::multiplier_to_fader + (flevel, maxLevel, AudioLevel::ShortFader); + } else { + level = db_to_level(AudioLevel::multiplier_to_dB(flevel)); + } + if (level < 0) level = 0; + if (level > maxLevel) level = maxLevel; + if (level != m_level) { + m_level = level; + float convertsTo = getLevel(); + if (fabsf(convertsTo - flevel) > 1e-5) { + emitLevelChanged(); + } + update(); + } +} + +float +LevelPanWidget::getLevel() const +{ + if (m_includeMute) { + return float(AudioLevel::fader_to_multiplier + (m_level, maxLevel, AudioLevel::ShortFader)); + } else { + return float(AudioLevel::dB_to_multiplier(level_to_db(m_level))); + } +} + +void +LevelPanWidget::setPan(float pan) +{ + m_pan = int(round(pan * maxPan)); + if (m_pan < -maxPan) m_pan = -maxPan; + if (m_pan > maxPan) m_pan = maxPan; + update(); +} + +bool +LevelPanWidget::isEditable() const +{ + return m_editable; +} + +bool +LevelPanWidget::includesMute() const +{ + return m_includeMute; +} + +void +LevelPanWidget::setEditable(bool editable) +{ + m_editable = editable; + update(); +} + +void +LevelPanWidget::setIncludeMute(bool include) +{ + m_includeMute = include; + emitLevelChanged(); + update(); +} + +float +LevelPanWidget::getPan() const +{ + return float(m_pan) / float(maxPan); +} + +void +LevelPanWidget::emitLevelChanged() +{ + cerr << "emitting levelChanged(" << getLevel() << ")" << endl; + emit levelChanged(getLevel()); +} + +void +LevelPanWidget::emitPanChanged() +{ + cerr << "emitting panChanged(" << getPan() << ")" << endl; + emit panChanged(getPan()); +} + +void +LevelPanWidget::mousePressEvent(QMouseEvent *e) +{ + mouseMoveEvent(e); +} + +void +LevelPanWidget::mouseMoveEvent(QMouseEvent *e) +{ + if (!m_editable) return; + + int level, pan; + toCell(rect(), e->pos(), level, pan); + if (level == m_level && pan == m_pan) { + return; + } + if (level != m_level) { + m_level = level; + emitLevelChanged(); + } + if (pan != m_pan) { + m_pan = pan; + emitPanChanged(); + } + update(); +} + +void +LevelPanWidget::mouseReleaseEvent(QMouseEvent *e) +{ + mouseMoveEvent(e); +} + +void +LevelPanWidget::wheelEvent(QWheelEvent *e) +{ + if (e->modifiers() & Qt::ControlModifier) { + if (e->delta() > 0) { + if (m_pan < maxPan) { + ++m_pan; + emitPanChanged(); + update(); + } + } else { + if (m_pan > -maxPan) { + --m_pan; + emitPanChanged(); + update(); + } + } + } else { + if (e->delta() > 0) { + if (m_level < maxLevel) { + ++m_level; + emitLevelChanged(); + update(); + } + } else { + if (m_level > 0) { + --m_level; + emitLevelChanged(); + update(); + } + } + } +} + +void +LevelPanWidget::toCell(QRectF rect, QPointF loc, int &level, int &pan) const +{ + double w = rect.width(), h = rect.height(); + + int npan = maxPan * 2 + 1; + int nlevel = maxLevel + 1; + + double wcell = w / npan, hcell = h / nlevel; + + level = int((h - (loc.y() - rect.y())) / hcell); + if (level < 0) level = 0; + if (level > maxLevel) level = maxLevel; + + pan = int((loc.x() - rect.x()) / wcell) - maxPan; + if (pan < -maxPan) pan = -maxPan; + if (pan > maxPan) pan = maxPan; +} + +QSizeF +LevelPanWidget::cellSize(QRectF rect) const +{ + double w = rect.width(), h = rect.height(); + int npan = maxPan * 2 + 1; + int nlevel = maxLevel + 1; + double wcell = w / npan, hcell = h / nlevel; + return QSizeF(wcell, hcell); +} + +QPointF +LevelPanWidget::cellCentre(QRectF rect, int level, int pan) const +{ + QSizeF cs = cellSize(rect); + return QPointF(rect.x() + cs.width() * (pan + maxPan) + cs.width() / 2., + rect.y() + rect.height() - cs.height() * (level + 1) + cs.height() / 2.); +} + +QSizeF +LevelPanWidget::cellLightSize(QRectF rect) const +{ + double extent = 3. / 4.; + QSizeF cs = cellSize(rect); + double m = std::min(cs.width(), cs.height()); + return QSizeF(m * extent, m * extent); +} + +QRectF +LevelPanWidget::cellLightRect(QRectF rect, int level, int pan) const +{ + QSizeF cls = cellLightSize(rect); + QPointF cc = cellCentre(rect, level, pan); + return QRectF(cc.x() - cls.width() / 2., + cc.y() - cls.height() / 2., + cls.width(), + cls.height()); +} + +double +LevelPanWidget::thinLineWidth(QRectF rect) const +{ + double tw = ceil(rect.width() / (maxPan * 2. * 10.)); + double th = ceil(rect.height() / (maxLevel * 10.)); + return std::min(th, tw); +} + +static QColor +level_to_colour(int level) +{ + assert(maxLevel == 4); + if (level == 0) return Qt::black; + else if (level == 1) return QColor(80, 0, 0); + else if (level == 2) return QColor(160, 0, 0); + else if (level == 3) return QColor(255, 0, 0); + else return QColor(255, 255, 0); +} + +void +LevelPanWidget::renderTo(QPaintDevice *dev, QRectF rect, bool asIfEditable) const +{ + QPainter paint(dev); + + paint.setRenderHint(QPainter::Antialiasing, true); + + QPen pen; + + double thin = thinLineWidth(rect); + + pen.setColor(QColor(127, 127, 127, 127)); + pen.setWidthF(cellLightSize(rect).width() + thin); + pen.setCapStyle(Qt::RoundCap); + paint.setPen(pen); + + for (int pan = -maxPan; pan <= maxPan; ++pan) { + paint.drawLine(cellCentre(rect, 0, pan), cellCentre(rect, maxLevel, pan)); + } + + if (isEnabled()) { + pen.setColor(Qt::black); + } else { + pen.setColor(Qt::darkGray); + } + + if (!asIfEditable && m_includeMute && m_level == 0) { + pen.setWidthF(thin * 2); + pen.setCapStyle(Qt::RoundCap); + paint.setPen(pen); + paint.drawLine(cellCentre(rect, 0, -maxPan), + cellCentre(rect, maxLevel, maxPan)); + paint.drawLine(cellCentre(rect, maxLevel, -maxPan), + cellCentre(rect, 0, maxPan)); + return; + } + + pen.setWidthF(thin); + pen.setCapStyle(Qt::FlatCap); + paint.setPen(pen); + + for (int level = 0; level <= m_level; ++level) { + if (isEnabled()) { + paint.setBrush(level_to_colour(level)); + } + QRectF clr = cellLightRect(rect, level, m_pan); + if (m_includeMute && m_level == 0) { + paint.drawLine(clr.topLeft(), clr.bottomRight()); + paint.drawLine(clr.bottomLeft(), clr.topRight()); + } else { + paint.drawEllipse(clr); + } + } +} + +void +LevelPanWidget::paintEvent(QPaintEvent *) +{ + renderTo(this, rect(), m_editable); +} + + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/LevelPanWidget.h Fri Jun 26 14:13:31 2015 +0100 @@ -0,0 +1,89 @@ +/* -*- 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 LEVEL_PAN_WIDGET_H +#define LEVEL_PAN_WIDGET_H + +#include <QWidget> + +/** + * A simple widget for coarse level and pan control. + */ + +class LevelPanWidget : public QWidget +{ + Q_OBJECT + +public: + LevelPanWidget(QWidget *parent = 0); + ~LevelPanWidget(); + + /// Return level as a gain value in the range [0,1] + float getLevel() const; + + /// Return pan as a value in the range [-1,1] + float getPan() const; + + /// Find out whether the widget is editable + bool isEditable() const; + + /// Discover whether the level range includes muting or not + bool includesMute() const; + + /// Draw a suitably sized copy of the widget's contents to the given device + void renderTo(QPaintDevice *, QRectF, bool asIfEditable) const; + + QSize sizeHint() const; + +public slots: + /// Set level in the range [0,1] -- will be rounded + void setLevel(float); + + /// Set pan in the range [-1,1] -- will be rounded + void setPan(float); + + /// Specify whether the widget is editable or read-only (default editable) + void setEditable(bool); + + /// Specify whether the level range should include muting or not + void setIncludeMute(bool); + +signals: + void levelChanged(float); + void panChanged(float); + +protected: + virtual void mousePressEvent(QMouseEvent *ev); + virtual void mouseMoveEvent(QMouseEvent *ev); + virtual void mouseReleaseEvent(QMouseEvent *ev); + virtual void wheelEvent(QWheelEvent *ev); + virtual void paintEvent(QPaintEvent *ev); + + void emitLevelChanged(); + void emitPanChanged(); + + int m_level; + int m_pan; + bool m_editable; + bool m_includeMute; + + QSizeF cellSize(QRectF) const; + QPointF cellCentre(QRectF, int level, int pan) const; + QSizeF cellLightSize(QRectF) const; + QRectF cellLightRect(QRectF, int level, int pan) const; + double thinLineWidth(QRectF) const; + void toCell(QRectF, QPointF loc, int &level, int &pan) const; +}; + +#endif
--- a/widgets/ListInputDialog.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/ListInputDialog.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -67,7 +67,7 @@ { for (size_t i = 0; i < m_radioButtons.size(); ++i) { if (m_radioButtons[i]->isChecked()) { - return m_strings[i]; + return m_strings[int(i)]; } } return "";
--- a/widgets/ModelDataTableDialog.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/ModelDataTableDialog.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -168,14 +168,14 @@ } void -ModelDataTableDialog::userScrolledToFrame(int frame) +ModelDataTableDialog::userScrolledToFrame(sv_frame_t frame) { QModelIndex index = m_table->getModelIndexForFrame(frame); makeCurrent(index.row()); } void -ModelDataTableDialog::playbackScrolledToFrame(int frame) +ModelDataTableDialog::playbackScrolledToFrame(sv_frame_t frame) { if (m_trackPlayback) { QModelIndex index = m_table->getModelIndexForFrame(frame);
--- a/widgets/ModelDataTableDialog.h Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/ModelDataTableDialog.h Fri Jun 26 14:13:31 2015 +0100 @@ -18,6 +18,8 @@ #include <QMainWindow> +#include "base/BaseTypes.h" + class TabularModel; class ModelDataTableModel; class QTableView; @@ -38,11 +40,11 @@ QToolBar *getPlayToolbar() { return m_playToolbar; } signals: - void scrollToFrame(int frame); + void scrollToFrame(sv_frame_t frame); public slots: - void userScrolledToFrame(int frame); - void playbackScrolledToFrame(int frame); + void userScrolledToFrame(sv_frame_t frame); + void playbackScrolledToFrame(sv_frame_t frame); void addCommand(Command *); protected slots:
--- a/widgets/Panner.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/Panner.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -65,7 +65,7 @@ float unit = m_scrollUnit; if (unit == 0.f) { unit = float(m_rectHeight) / (6 * float(height())); - if (unit < 0.01) unit = 0.01; + if (unit < 0.01f) unit = 0.01f; } if (!up) { @@ -165,24 +165,24 @@ paint.setBrush(hl); - int rw = lrintf((width() - 1) * m_rectWidth); - int rh = lrintf((height() - 1) * m_rectHeight); + int rw = int(lrintf(float(width() - 1) * m_rectWidth)); + int rh = int(lrintf(float(height() - 1) * m_rectHeight)); if (rw < 2) rw = 2; if (rh < 2) rh = 2; - paint.drawRect(lrintf(width() * m_rectX), - lrintf(height() * m_rectY), + paint.drawRect(int(lrintf(float(width()) * m_rectX)), + int(lrintf(float(height()) * m_rectY)), rw, rh); } void Panner::normalise() { - if (m_rectWidth > 1.0) m_rectWidth = 1.0; - if (m_rectHeight > 1.0) m_rectHeight = 1.0; - if (m_rectX + m_rectWidth > 1.0) m_rectX = 1.0 - m_rectWidth; + if (m_rectWidth > 1.f) m_rectWidth = 1.f; + if (m_rectHeight > 1.f) m_rectHeight = 1.f; + if (m_rectX + m_rectWidth > 1.f) m_rectX = 1.f - m_rectWidth; if (m_rectX < 0) m_rectX = 0; - if (m_rectY + m_rectHeight > 1.0) m_rectY = 1.0 - m_rectHeight; + if (m_rectY + m_rectHeight > 1.f) m_rectY = 1.f - m_rectHeight; if (m_rectY < 0) m_rectY = 0; if (!m_defaultsSet) {
--- a/widgets/PluginParameterBox.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/PluginParameterBox.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -70,12 +70,12 @@ m_programCombo = new QComboBox; m_programCombo->setMaxVisibleItems - (m_programs.size() < 25 ? m_programs.size() : 20); + (int(m_programs.size() < 25 ? m_programs.size() : 20)); - for (size_t i = 0; i < m_programs.size(); ++i) { + for (int i = 0; in_range_for(m_programs, i); ++i) { m_programCombo->addItem(m_programs[i].c_str()); if (m_programs[i] == currentProgram) { - m_programCombo->setCurrentIndex(i); + m_programCombo->setCurrentIndex(int(i)); } } @@ -88,7 +88,7 @@ offset = 1; } - for (size_t i = 0; i < params.size(); ++i) { + for (int i = 0; in_range_for(params, i); ++i) { QString identifier = params[i].identifier.c_str(); QString name = params[i].name.c_str(); @@ -120,9 +120,9 @@ if (!(hint & PortHint::Logarithmic)) { if (qtz > 0.0) { - imax = lrintf((max - min) / qtz); + imax = int(lrintf((max - min) / qtz)); } else { - qtz = (max - min) / 100.0; + qtz = (max - min) / 100.f; } } @@ -245,19 +245,19 @@ if (ad && ad->rangeMapper()) { - newValue = ad->mappedValue(); + newValue = float(ad->mappedValue()); if (newValue < min) newValue = min; if (newValue > max) newValue = max; if (qtz != 0.0) { - ival = lrintf((newValue - min) / qtz); - newValue = min + ival * qtz; + ival = int(lrintf((newValue - min) / qtz)); + newValue = min + float(ival) * qtz; } } else { - if (qtz == 0.0) { - qtz = (max - min) / 100.0; + if (qtz == 0.f) { + qtz = (max - min) / 100.f; } - newValue = min + ival * qtz; + newValue = min + float(ival) * qtz; } // SVDEBUG << "PluginParameterBox::dialChanged: newValue = " << newValue << endl; @@ -329,8 +329,8 @@ if (params.isQuantized) qtz = params.quantizeStep; if (qtz > 0.0) { - int step = lrintf((value - min) / qtz); - value = min + step * qtz; + int step = int(lrintf(float(value - min) / qtz)); + value = min + float(step) * qtz; } // int imax = 100; @@ -338,10 +338,10 @@ if (qtz > 0.0) { // imax = lrintf((max - min) / qtz); } else { - qtz = (max - min) / 100.0; + qtz = (max - min) / 100.f; } - int ival = lrintf((value - min) / qtz); + int ival = int(lrintf(float(value - min) / qtz)); AudioDial *dial = m_params[identifier].dial; if (dial) { @@ -356,7 +356,7 @@ SVDEBUG << "setting plugin parameter \"" << identifier << "\" to value " << value << endl; - m_plugin->setParameter(identifier.toStdString(), value); + m_plugin->setParameter(identifier.toStdString(), float(value)); updateProgramCombo(); @@ -389,17 +389,17 @@ if (param.isQuantized) qtz = param.quantizeStep; if (qtz == 0.0) { - qtz = (max - min) / 100.0; + qtz = (max - min) / 100.f; } i->second.dial->blockSignals(true); - i->second.dial->setValue(lrintf((value - min) / qtz)); + i->second.dial->setValue(int(lrintf(float(value - min) / qtz))); i->second.dial->blockSignals(false); } if (i->second.combo) { i->second.combo->blockSignals(true); - i->second.combo->setCurrentIndex(lrintf(value)); + i->second.combo->setCurrentIndex(int(lrintf(value))); i->second.combo->blockSignals(false); } @@ -420,7 +420,7 @@ std::string currentProgram = m_plugin->getCurrentProgram(); - for (size_t i = 0; i < m_programs.size(); ++i) { + for (int i = 0; in_range_for(m_programs, i); ++i) { if (m_programs[i] == currentProgram) { m_programCombo->setCurrentIndex(i); }
--- a/widgets/PluginParameterDialog.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/PluginParameterDialog.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -386,10 +386,10 @@ int size = 1024; int increment = 1024; if (fePlugin) { - size = fePlugin->getPreferredBlockSize(); + size = int(fePlugin->getPreferredBlockSize()); cerr << "Feature extraction plugin \"" << fePlugin->getName() << "\" reports preferred block size as " << size << endl; if (size == 0) size = 1024; - increment = fePlugin->getPreferredStepSize(); + increment = int(fePlugin->getPreferredStepSize()); if (increment == 0) { if (fePlugin->getInputDomain() == Vamp::Plugin::TimeDomain) { increment = size;
--- a/widgets/PropertyBox.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/PropertyBox.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -698,7 +698,7 @@ void PropertyBox::playGainChanged(float gain) { - int dialValue = lrint(log10(gain) * 20.0); + int dialValue = int(lrint(log10(gain) * 20.0)); if (dialValue < -50) dialValue = -50; if (dialValue > 50) dialValue = 50; emit changePlayGainDial(dialValue); @@ -712,7 +712,7 @@ PlayParameters *params = m_container->getPlayParameters(); if (!params) return; - float gain = pow(10, float(dialValue) / 20.0); + float gain = float(pow(10, float(dialValue) / 20.0)); if (params->getPlayGain() != gain) { PlayParameterRepository::EditCommand *command = @@ -727,7 +727,7 @@ void PropertyBox::playPanChanged(float pan) { - int dialValue = lrint(pan * 50.0); + int dialValue = int(lrint(pan * 50.0)); if (dialValue < -50) dialValue = -50; if (dialValue > 50) dialValue = 50; emit changePlayPanDial(dialValue); @@ -741,9 +741,9 @@ PlayParameters *params = m_container->getPlayParameters(); if (!params) return; - float pan = float(dialValue) / 50.0; - if (pan < -1.0) pan = -1.0; - if (pan > 1.0) pan = 1.0; + float pan = float(dialValue) / 50.f; + if (pan < -1.f) pan = -1.f; + if (pan > 1.f) pan = 1.f; if (params->getPlayPan() != pan) { PlayParameterRepository::EditCommand *command = @@ -841,7 +841,7 @@ QString extraText; AudioDial *dial = dynamic_cast<AudioDial *>(w); if (dial) { - float mv = dial->mappedValue(); + double mv = dial->mappedValue(); QString unit = ""; if (dial->rangeMapper()) unit = dial->rangeMapper()->getUnit(); if (unit != "") {
--- a/widgets/PropertyStack.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/PropertyStack.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -30,7 +30,7 @@ #include <iostream> -#define DEBUG_PROPERTY_STACK 1 +//#define DEBUG_PROPERTY_STACK 1 PropertyStack::PropertyStack(QWidget *parent, View *client) : QTabWidget(parent), @@ -172,7 +172,7 @@ // remain in the same order. So we must find this container in the // box list, not in the view. - for (size_t i = 0; i < m_boxes.size(); ++i) { + for (int i = 0; in_range_for(m_boxes, i); ++i) { PropertyContainer *container = m_boxes[i]->getContainer(); if (pc == container) { return i;
--- a/widgets/SubdividingMenu.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/SubdividingMenu.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -53,7 +53,7 @@ { m_entriesSet = true; - int total = entries.size(); + int total = int(entries.size()); if (total < m_upperLimit) return;
--- a/widgets/Thumbwheel.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/Thumbwheel.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -135,7 +135,7 @@ } void -Thumbwheel::setMappedValue(float mappedValue) +Thumbwheel::setMappedValue(double mappedValue) { if (m_rangeMapper) { int newValue = m_rangeMapper->getPositionForValue(mappedValue); @@ -202,7 +202,7 @@ return m_value; } -float +double Thumbwheel::getMappedValue() const { if (m_rangeMapper) { @@ -240,7 +240,7 @@ void Thumbwheel::scroll(bool up) { - int step = lrintf(m_speed); + int step = int(lrintf(m_speed)); if (step == 0) step = 1; if (up) { @@ -327,11 +327,11 @@ if (m_rangeMapper) { - float min = m_rangeMapper->getValueForPosition(m_min); - float max = m_rangeMapper->getValueForPosition(m_max); + double min = m_rangeMapper->getValueForPosition(m_min); + double max = m_rangeMapper->getValueForPosition(m_max); if (min > max) { - float tmp = min; + double tmp = min; min = max; max = tmp; } @@ -357,7 +357,7 @@ } } - float newValue = QInputDialog::getDouble + double newValue = QInputDialog::getDouble (this, tr("Enter new value"), text, @@ -398,10 +398,10 @@ dist = e->y() - m_clickPos.y(); } - float rotation = m_clickRotation + (m_speed * dist) / 100; + float rotation = m_clickRotation + (m_speed * float(dist)) / 100; if (rotation < 0.f) rotation = 0.f; if (rotation > 1.f) rotation = 1.f; - int value = lrintf(m_min + (m_max - m_min) * m_rotation); + int value = int(lrintf(float(m_min) + float(m_max - m_min) * m_rotation)); if (value != m_value) { setValue(value); if (m_tracking) emit valueChanged(getValue()); @@ -426,7 +426,7 @@ void Thumbwheel::wheelEvent(QWheelEvent *e) { - int step = lrintf(m_speed); + int step = int(lrintf(m_speed)); if (step == 0) step = 1; if (e->delta() > 0) { @@ -469,13 +469,13 @@ paint.setRenderHint(QPainter::Antialiasing, true); - float w = width(); - float w0 = 0.5; - float w1 = w - 0.5; + double w = width(); + double w0 = 0.5; + double w1 = w - 0.5; - float h = height(); - float h0 = 0.5; - float h1 = h - 0.5; + double h = height(); + double h0 = 0.5; + double h1 = h - 0.5; for (int i = bw-1; i >= 0; --i) { @@ -504,7 +504,7 @@ paint.setClipRect(subclip); - float radians = m_rotation * 1.5f * M_PI; + double radians = m_rotation * 1.5f * M_PI; // cerr << "value = " << m_value << ", min = " << m_min << ", max = " << m_max << ", rotation = " << rotation << endl; @@ -518,16 +518,16 @@ for (int i = 0; i < notches; ++i) { - float a0 = (2.f * M_PI * i) / notches + radians; - float a1 = a0 + M_PI / (notches * 2); - float a2 = (2.f * M_PI * (i + 1)) / notches + radians; + double a0 = (2.0 * M_PI * i) / notches + radians; + double a1 = a0 + M_PI / (notches * 2); + double a2 = (2.0 * M_PI * (i + 1)) / notches + radians; - float depth = cosf((a0 + a2) / 2); + double depth = cos((a0 + a2) / 2); if (depth < 0) continue; - float x0 = radius * sinf(a0) + w/2; - float x1 = radius * sinf(a1) + w/2; - float x2 = radius * sinf(a2) + w/2; + double x0 = radius * sin(a0) + w/2; + double x1 = radius * sin(a1) + w/2; + double x2 = radius * sin(a2) + w/2; if (x2 < 0 || x0 > w) continue; if (x0 < 0) x0 = 0; @@ -537,7 +537,7 @@ x1 += bw; x2 += bw; - int grey = lrintf(120 * depth); + int grey = int(lrint(120 * depth)); QColor fc = QColor(grey, grey, grey); QColor oc = palette().highlight().color(); @@ -548,9 +548,9 @@ paint.setBrush(oc); - float prop; + double prop; if (i >= notches / 4) { - prop = float(notches - (((i - float(notches) / 4.f) * 4.f) / 3.f)) + prop = double(notches - (((i - double(notches) / 4.f) * 4.f) / 3.f)) / notches; } else { prop = 0.f;
--- a/widgets/Thumbwheel.h Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/Thumbwheel.h Fri Jun 26 14:13:31 2015 +0100 @@ -41,7 +41,7 @@ void setRangeMapper(RangeMapper *mapper); // I take ownership, will delete const RangeMapper *getRangeMapper() const { return m_rangeMapper; } - float getMappedValue() const; + double getMappedValue() const; void setShowToolTip(bool show); @@ -61,7 +61,7 @@ void setTracking(bool tracking); void setShowScale(bool show); void setValue(int value); - void setMappedValue(float mappedValue); + void setMappedValue(double mappedValue); void scroll(bool up); void resetToDefault(); @@ -82,7 +82,7 @@ int m_max; int m_default; int m_value; - float m_mappedValue; + double m_mappedValue; bool m_noMappedUpdate; float m_rotation; Qt::Orientation m_orientation;
--- a/widgets/TipDialog.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/TipDialog.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -105,7 +105,7 @@ TipDialog::previous() { if (--m_tipNumber < 0) { - m_tipNumber = m_tips.size() - 1; + m_tipNumber = int(m_tips.size()) - 1; } showTip();
--- a/widgets/TransformFinder.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/TransformFinder.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -225,11 +225,11 @@ if (m_sortedResults.size() < sorted.size()) { m_infoLabel->setText (tr("Found %n description(s) containing <b>%1</b>, showing the first %2 only", - 0, sorted.size()).arg(text).arg(m_sortedResults.size())); + 0, int(sorted.size())).arg(text).arg(m_sortedResults.size())); } else { m_infoLabel->setText (tr("Found %n description(s) containing <b>%1</b>", - 0, sorted.size()).arg(text)); + 0, int(sorted.size())).arg(text)); } return;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/UnitConverter.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -0,0 +1,401 @@ +/* -*- 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. +*/ + +#include "UnitConverter.h" + +#include <QSpinBox> +#include <QComboBox> +#include <QDoubleSpinBox> +#include <QLabel> +#include <QDialogButtonBox> +#include <QGridLayout> +#include <QTabWidget> + +#include "base/Debug.h" +#include "base/Pitch.h" +#include "base/Preferences.h" + +using namespace std; + +static QString pianoNotes[] = { + "C", "C# / Db", "D", "D# / Eb", "E", + "F", "F# / Gb", "G", "G# / Ab", "A", "A# / Bb", "B" +}; + +UnitConverter::UnitConverter(QWidget *parent) : + QDialog(parent) +{ + QGridLayout *maingrid = new QGridLayout; + setLayout(maingrid); + + QTabWidget *tabs = new QTabWidget; + maingrid->addWidget(tabs, 0, 0); + + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Close); + maingrid->addWidget(bb, 1, 0); + connect(bb, SIGNAL(rejected()), this, SLOT(close())); + + QFrame *frame = new QFrame; + tabs->addTab(frame, tr("Pitch")); + + QGridLayout *grid = new QGridLayout; + frame->setLayout(grid); + + m_freq = new QDoubleSpinBox; + m_freq->setSuffix(QString(" Hz")); + m_freq->setDecimals(6); + m_freq->setMinimum(1e-3); + m_freq->setMaximum(1e6); + m_freq->setValue(440); + connect(m_freq, SIGNAL(valueChanged(double)), + this, SLOT(freqChanged())); + + // The min and max range values for all the remaining controls are + // determined by the min and max Hz above + + m_midi = new QSpinBox; + m_midi->setMinimum(-156); + m_midi->setMaximum(203); + connect(m_midi, SIGNAL(valueChanged(int)), + this, SLOT(midiChanged())); + + m_note = new QComboBox; + for (int i = 0; i < 12; ++i) { + m_note->addItem(pianoNotes[i]); + } + connect(m_note, SIGNAL(currentIndexChanged(int)), + this, SLOT(noteChanged())); + + m_octave = new QSpinBox; + m_octave->setMinimum(-14); + m_octave->setMaximum(15); + connect(m_octave, SIGNAL(valueChanged(int)), + this, SLOT(octaveChanged())); + + m_cents = new QDoubleSpinBox; + m_cents->setSuffix(tr(" cents")); + m_cents->setDecimals(4); + m_cents->setMinimum(-50); + m_cents->setMaximum(50); + connect(m_cents, SIGNAL(valueChanged(double)), + this, SLOT(centsChanged())); + + int row = 0; + + grid->addWidget(new QLabel(tr("In 12-tone Equal Temperament:")), row, 0, 1, 9); + + ++row; + + grid->setRowMinimumHeight(row, 8); + + ++row; + + grid->addWidget(m_freq, row, 0, 2, 1, Qt::AlignRight | Qt::AlignVCenter); + grid->addWidget(new QLabel(tr("=")), row, 1, 2, 1, Qt::AlignHCenter | Qt::AlignVCenter); + + grid->addWidget(new QLabel(tr("+")), row, 7, 2, 1, Qt::AlignHCenter | Qt::AlignVCenter); + grid->addWidget(m_cents, row, 8, 2, 1, Qt::AlignLeft | Qt::AlignVCenter); + + grid->addWidget(new QLabel(tr("Piano note")), row, 2, 1, 2); + grid->addWidget(m_note, row, 4); + grid->addWidget(new QLabel(tr("in octave")), row, 5); + grid->addWidget(m_octave, row, 6); + + ++row; + + grid->addWidget(new QLabel(tr("MIDI pitch")), row, 2, 1, 2); + grid->addWidget(m_midi, row, 4); + + ++row; + + grid->setRowStretch(row, 20); + grid->setRowMinimumHeight(row, 8); + + ++row; + + m_pitchPrefsLabel = new QLabel; + grid->addWidget(m_pitchPrefsLabel, row, 0, 1, 9); + + ++row; + + grid->addWidget + (new QLabel(tr("Note that only pitches in the range 0 to 127 are valid " + "in the MIDI protocol.")), + row, 0, 1, 9); + + ++row; + + frame = new QFrame; + tabs->addTab(frame, tr("Tempo")); + + grid = new QGridLayout; + frame->setLayout(grid); + + m_samples = new QDoubleSpinBox; + m_samples->setSuffix(QString(" samples")); + m_samples->setDecimals(2); + m_samples->setMinimum(1); + m_samples->setMaximum(1e8); + m_samples->setValue(22050); + connect(m_samples, SIGNAL(valueChanged(double)), + this, SLOT(samplesChanged())); + + m_period = new QDoubleSpinBox; + m_period->setSuffix(QString(" ms")); + m_period->setDecimals(4); + m_period->setMinimum(1e-3); + m_period->setMaximum(100000); + m_period->setValue(500); + connect(m_period, SIGNAL(valueChanged(double)), + this, SLOT(periodChanged())); + + m_bpm = new QDoubleSpinBox; + m_bpm->setSuffix(QString(" bpm")); + m_bpm->setDecimals(4); + m_bpm->setMinimum(0.1); + m_bpm->setMaximum(1e6); + m_bpm->setValue(120); + connect(m_bpm, SIGNAL(valueChanged(double)), + this, SLOT(bpmChanged())); + + m_tempofreq = new QDoubleSpinBox; + m_tempofreq->setSuffix(QString(" beats/sec")); + m_tempofreq->setDecimals(4); + m_tempofreq->setMinimum(1e-3); + m_tempofreq->setMaximum(1e5); + m_tempofreq->setValue(0.5); + + connect(m_tempofreq, SIGNAL(valueChanged(double)), + this, SLOT(tempofreqChanged())); + + m_samplerate = new QComboBox; + QList<int> rates; + rates << 8000; + for (int i = 1; i <= 16; i *= 2) { + rates << 11025 * i << 12000 * i; + } + foreach (int r, rates) { + m_samplerate->addItem(QString("%1 Hz").arg(r)); + } + connect(m_samplerate, SIGNAL(currentIndexChanged(int)), + this, SLOT(samplerateChanged())); + m_samplerate->setCurrentText("44100 Hz"); + + connect(Preferences::getInstance(), + SIGNAL(propertyChanged(PropertyContainer::PropertyName)), + this, SLOT(preferenceChanged(PropertyContainer::PropertyName))); + + row = 0; + + grid->setRowStretch(row, 20); + grid->setRowMinimumHeight(row, 8); + + ++row; + + grid->addWidget(new QLabel(tr("Beat period")), row, 0, 2, 1, Qt::AlignVCenter); + grid->addWidget(m_period, row, 1); + grid->addWidget(new QLabel(tr("=")), row, 2, 2, 1, Qt::AlignVCenter); + + grid->addWidget(m_tempofreq, row, 3); + + grid->addWidget(new QLabel(tr("at")), row, 4, 2, 1, Qt::AlignVCenter); + grid->addWidget(m_samplerate, row, 5, 2, 1, Qt::AlignVCenter); + + ++row; + + grid->addWidget(m_samples, row, 1); + grid->addWidget(m_bpm, row, 3); + + ++row; + + grid->setRowStretch(row, 20); + grid->setRowMinimumHeight(row, 8); + + updatePitchesFromFreq(); + updatePitchPrefsLabel(); + updateTempiFromSamples(); +} + +UnitConverter::~UnitConverter() +{ +} + +void +UnitConverter::setTo(QSpinBox *box, int value) +{ + box->blockSignals(true); + if (value < box->minimum() || value > box->maximum()) { + QPalette p; + p.setColor(QPalette::Text, Qt::red); + box->setPalette(p); + } else { + box->setPalette(QPalette()); + } + box->setValue(value); + box->blockSignals(false); +} + +void +UnitConverter::setTo(QDoubleSpinBox *box, double value) +{ + box->blockSignals(true); + if (value < box->minimum() || value > box->maximum()) { + QPalette p; + p.setColor(QPalette::Text, Qt::red); + box->setPalette(p); + } else { + box->setPalette(QPalette()); + } + box->setValue(value); + box->blockSignals(false); +} + +void +UnitConverter::preferenceChanged(PropertyContainer::PropertyName) +{ + updatePitchesFromFreq(); + updatePitchPrefsLabel(); +} + +void +UnitConverter::updatePitchPrefsLabel() +{ + m_pitchPrefsLabel->setText + (tr("With concert-A tuning frequency at %1 Hz, and " + "middle C residing in octave %2.\n" + "(These can be changed in the application preferences.)") + .arg(Preferences::getInstance()->getTuningFrequency()) + .arg(Preferences::getInstance()->getOctaveOfMiddleC())); +} + +void +UnitConverter::freqChanged() +{ + updatePitchesFromFreq(); +} + +void +UnitConverter::midiChanged() +{ + double freq = Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value()); + m_freq->setValue(freq); +} + +void +UnitConverter::noteChanged() +{ + int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(), + m_octave->value()); + double freq = Pitch::getFrequencyForPitch(pitch, m_cents->value()); + m_freq->setValue(freq); +} + +void +UnitConverter::octaveChanged() +{ + int pitch = Pitch::getPitchForNoteAndOctave(m_note->currentIndex(), + m_octave->value()); + double freq = Pitch::getFrequencyForPitch(pitch, m_cents->value()); + m_freq->setValue(freq); +} + +void +UnitConverter::centsChanged() +{ + double freq = Pitch::getFrequencyForPitch(m_midi->value(), m_cents->value()); + m_freq->setValue(freq); +} + +void +UnitConverter::updatePitchesFromFreq() +{ + double cents = 0; + int pitch = Pitch::getPitchForFrequency(m_freq->value(), ¢s); + int note, octave; + Pitch::getNoteAndOctaveForPitch(pitch, note, octave); + + cerr << "pitch " << pitch << " note " << note << " octave " << octave << " cents " << cents << endl; + + setTo(m_midi, pitch); + setTo(m_cents, cents); + setTo(m_octave, octave); + + m_note->blockSignals(true); + m_note->setCurrentIndex(note); + m_note->blockSignals(false); +} + +void +UnitConverter::samplesChanged() +{ + updateTempiFromSamples(); +} + +void +UnitConverter::periodChanged() +{ + double rate = getSampleRate(); + double sec = m_period->value() / 1000.0; + double samples = rate * sec; + m_samples->setValue(samples); +} + +void +UnitConverter::bpmChanged() +{ + double rate = getSampleRate(); + double sec = 60.0 / m_bpm->value(); + double samples = rate * sec; + m_samples->setValue(samples); +} + +void +UnitConverter::tempofreqChanged() +{ + double rate = getSampleRate(); + double samples = rate / m_tempofreq->value(); + m_samples->setValue(samples); +} + +void +UnitConverter::samplerateChanged() +{ + // Preserve the beat period in seconds, here, not in samples + periodChanged(); +} + +double +UnitConverter::getSampleRate() +{ + return double(atoi(m_samplerate->currentText().toLocal8Bit().data())); +} + +void +UnitConverter::updateTempiFromSamples() +{ + double samples = m_samples->value(); + double rate = getSampleRate(); + + cerr << samples << " samples at rate " << rate << endl; + + double sec = samples / rate; + double hz = rate / samples; + double bpm = 60.0 / sec; + + setTo(m_bpm, bpm); + setTo(m_period, sec * 1000.0); + setTo(m_tempofreq, hz); +} + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgets/UnitConverter.h Fri Jun 26 14:13:31 2015 +0100 @@ -0,0 +1,73 @@ +/* -*- 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 UNIT_CONVERTER_H +#define UNIT_CONVERTER_H + +#include <QDialog> + +#include "base/PropertyContainer.h" + +class QSpinBox; +class QDoubleSpinBox; +class QComboBox; +class QLabel; + +class UnitConverter : public QDialog +{ + Q_OBJECT + +public: + UnitConverter(QWidget *parent = 0); + virtual ~UnitConverter(); + +private slots: + void freqChanged(); + void midiChanged(); + void noteChanged(); + void octaveChanged(); + void centsChanged(); + + void samplesChanged(); + void periodChanged(); + void bpmChanged(); + void tempofreqChanged(); + void samplerateChanged(); + + void preferenceChanged(PropertyContainer::PropertyName); + +private: + QDoubleSpinBox *m_freq; + QSpinBox *m_midi; + QComboBox *m_note; + QSpinBox *m_octave; + QDoubleSpinBox *m_cents; + QLabel *m_pitchPrefsLabel; + void updatePitchesFromFreq(); + void updatePitchPrefsLabel(); + + QDoubleSpinBox *m_samples; + QDoubleSpinBox *m_period; + QDoubleSpinBox *m_bpm; + QDoubleSpinBox *m_tempofreq; + QComboBox *m_samplerate; + void updateTempiFromSamples(); + + double getSampleRate(); + + void setTo(QSpinBox *, int); + void setTo(QDoubleSpinBox *, double); +}; + +#endif
--- a/widgets/WindowShapePreview.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/WindowShapePreview.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -32,7 +32,7 @@ WindowShapePreview::WindowShapePreview(QWidget *parent) : QFrame(parent), - m_windowType(WindowType(999)) + m_windowType(HanningWindow) { QHBoxLayout *layout = new QHBoxLayout; layout->setMargin(0); @@ -51,7 +51,7 @@ WindowShapePreview::updateLabels() { int step = 24; - int peak = 48; + float peak = 48; int w = step * 4, h = 64; WindowType type = m_windowType; Window<float> windower = Window<float>(type, step * 2); @@ -62,8 +62,8 @@ QPainterPath path; - path.moveTo(0, h - peak + 1); - path.lineTo(w, h - peak + 1); + path.moveTo(0, float(h) - peak + 1); + path.lineTo(w, float(h) - peak + 1); timePainter.setPen(Qt::gray); timePainter.setRenderHint(QPainter::Antialiasing, true); @@ -84,7 +84,7 @@ } } for (int i = 0; i < w; ++i) { - int y = h - int(peak * acc[i] + 0.001) + 1; + int y = h - int(peak * acc[i] + 0.001f) + 1; if (i == 0) path.moveTo(i, y); else path.lineTo(i, y); } @@ -150,7 +150,7 @@ float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; float db = mindb; if (power > 0) { - db = 20 * log10(power); + db = 20.f * log10f(power); if (first || db > maxdb) maxdb = db; if (first || db < mindb) mindb = db; first = false; @@ -167,8 +167,8 @@ // float ly = h - ((-80.f + -mindb) / maxval) * peak + 1; - path.moveTo(0, h - peak + 1); - path.lineTo(fw, h - peak + 1); + path.moveTo(0, float(h) - peak + 1); + path.lineTo(fw, float(h) - peak + 1); freqPainter.setPen(Qt::gray); freqPainter.setRenderHint(QPainter::Antialiasing, true); @@ -181,12 +181,12 @@ for (int i = 0; i < fftsize/2; ++i) { float power = output[i][0] * output[i][0] + output[i][1] * output[i][1]; - float db = 20 * log10(power); + float db = 20.f * log10f(power); float val = db + -mindb; if (val < 0) val = 0; float norm = val / maxval; - float x = (fw / float(fftsize/2)) * i; - float y = h - norm * peak + 1; + float x = (float(fw) / float(fftsize/2)) * float(i); + float y = float(h) - norm * peak + 1; if (i == 0) path.moveTo(x, y); else path.lineTo(x, y); } @@ -209,7 +209,6 @@ void WindowShapePreview::setWindowType(WindowType type) { - if (m_windowType == type) return; m_windowType = type; updateLabels(); }
--- a/widgets/WindowTypeSelector.cpp Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/WindowTypeSelector.cpp Fri Jun 26 14:13:31 2015 +0100 @@ -22,9 +22,23 @@ #include "base/Preferences.h" -WindowTypeSelector::WindowTypeSelector(WindowType defaultType, QWidget *parent) : - QFrame(parent), - m_windowType(WindowType(999)) +WindowTypeSelector::WindowTypeSelector(WindowType defaultType) +{ + init(defaultType); +} + +WindowTypeSelector::WindowTypeSelector() +{ + Preferences *prefs = Preferences::getInstance(); + int min = 0, max = 0, deflt = 0; + WindowType type = + WindowType(prefs->getPropertyRangeAndValue("Window Type", &min, &max, + &deflt)); + init(type); +} + +void +WindowTypeSelector::init(WindowType defaultType) { QVBoxLayout *layout = new QVBoxLayout; layout->setMargin(0); @@ -48,15 +62,10 @@ m_windowShape = new WindowShapePreview; m_windowCombo = new QComboBox; - int min = 0, max = 0, deflt = 0, i = 0; int window = int(defaultType); - if (window == 999) { - window = prefs->getPropertyRangeAndValue("Window Type", &min, &max, - &deflt); - } int index = 0; - for (i = 0; i <= 8; ++i) { + for (int i = 0; i <= 8; ++i) { m_windowCombo->addItem(prefs->getPropertyValueLabel("Window Type", m_windows[i])); if (m_windows[i] == window) index = i; @@ -69,7 +78,9 @@ connect(m_windowCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(windowIndexChanged(int))); - windowIndexChanged(index); + + m_windowType = defaultType; + m_windowShape->setWindowType(m_windowType); } WindowTypeSelector::~WindowTypeSelector()
--- a/widgets/WindowTypeSelector.h Fri Sep 12 11:38:55 2014 +0100 +++ b/widgets/WindowTypeSelector.h Fri Jun 26 14:13:31 2015 +0100 @@ -28,8 +28,8 @@ Q_OBJECT public: - WindowTypeSelector(WindowType defaultType = WindowType(999), // 999 -> get from preferences - QWidget *parent = 0); + WindowTypeSelector(WindowType defaultType); + WindowTypeSelector(); // get window type from preferences virtual ~WindowTypeSelector(); WindowType getWindowType() const; @@ -48,6 +48,8 @@ WindowShapePreview *m_windowShape; WindowType *m_windows; WindowType m_windowType; + + void init(WindowType type); }; #endif