# HG changeset patch # User Chris Cannam # Date 1537368104 -3600 # Node ID 5360f7aba1893a488039cd972c2f3230c1a298e2 # Parent 2f3a77472c8c7b0c303b9a535e0bf358380e2648 Pull out ZoomLevel, add inexact frame/pixel conversion functions and streaming diff -r 2f3a77472c8c -r 5360f7aba189 base/BaseTypes.h --- a/base/BaseTypes.h Tue Sep 18 16:28:56 2018 +0100 +++ b/base/BaseTypes.h Wed Sep 19 15:41:44 2018 +0100 @@ -55,62 +55,5 @@ typedef std::vector, breakfastquay::StlAllocator>> complexvec_t; -/** Display zoom level. Can be an integer number of samples per pixel, - * or an integer number of pixels per sample. - */ -struct ZoomLevel { - - enum Zone { - FramesPerPixel, // zoomed out (as in classic SV) - PixelsPerFrame // zoomed in beyond 1-1 (interpolating the waveform) - }; - Zone zone; - int level; - - ZoomLevel(Zone z, int l) : zone(z), level(l) { } - - bool operator<(const ZoomLevel &other) const { - if (zone == FramesPerPixel) { - if (other.zone == zone) { - return level < other.level; - } else { - return false; - } - } else { - if (other.zone == zone) { - return level > other.level; - } else { - return false; - } - } - } - - bool operator==(const ZoomLevel &other) const { - return (zone == other.zone && level == other.level); - } - - ZoomLevel incremented() const { - if (zone == FramesPerPixel) { - return { zone, level + 1 }; - } else if (level == 1) { - return { FramesPerPixel, 2 }; - } else if (level == 2) { - return { FramesPerPixel, 1 }; - } else { - return { zone, level - 1 }; - } - } - - ZoomLevel decremented() const { - if (zone == PixelsPerFrame) { - return { zone, level + 1 }; - } else if (level == 1) { - return { PixelsPerFrame, 2 }; - } else { - return { zone, level - 1 }; - } - } -}; - #endif diff -r 2f3a77472c8c -r 5360f7aba189 base/ZoomConstraint.h --- a/base/ZoomConstraint.h Tue Sep 18 16:28:56 2018 +0100 +++ b/base/ZoomConstraint.h Wed Sep 19 15:41:44 2018 +0100 @@ -18,7 +18,7 @@ #include -#include "BaseTypes.h" +#include "ZoomLevel.h" /** * ZoomConstraint is a simple interface that describes a limitation on diff -r 2f3a77472c8c -r 5360f7aba189 base/ZoomLevel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/ZoomLevel.cpp Wed Sep 19 15:41:44 2018 +0100 @@ -0,0 +1,25 @@ +/* -*- 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 "ZoomLevel.h" + +std::ostream &operator<<(std::ostream &s, const ZoomLevel &z) { + if (z.zone == ZoomLevel::PixelsPerFrame) { + s << "1/" << z.level; + } else { + s << z.level; + } + return s; +} + diff -r 2f3a77472c8c -r 5360f7aba189 base/ZoomLevel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/ZoomLevel.h Wed Sep 19 15:41:44 2018 +0100 @@ -0,0 +1,98 @@ +/* -*- 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 SV_ZOOM_LEVEL_H +#define SV_ZOOM_LEVEL_H + +#include + +/** Display zoom level. Can be an integer number of samples per pixel, + * or an integer number of pixels per sample. + */ +struct ZoomLevel { + + enum Zone { + FramesPerPixel, // zoomed out (as in classic SV) + PixelsPerFrame // zoomed in beyond 1-1 (interpolating the waveform) + }; + Zone zone; + int level; + + ZoomLevel() : zone(FramesPerPixel), level(1) { } + ZoomLevel(Zone z, int lev) : zone(z), level(lev) { } + + bool operator<(const ZoomLevel &other) const { + if (zone == FramesPerPixel) { + if (other.zone == zone) { + return level < other.level; + } else { + return false; + } + } else { + if (other.zone == zone) { + return level > other.level; + } else { + return false; + } + } + } + + bool operator==(const ZoomLevel &other) const { + return (zone == other.zone && level == other.level); + } + + ZoomLevel incremented() const { + if (zone == FramesPerPixel) { + return { zone, level + 1 }; + } else if (level == 1) { + return { FramesPerPixel, 2 }; + } else if (level == 2) { + return { FramesPerPixel, 1 }; + } else { + return { zone, level - 1 }; + } + } + + ZoomLevel decremented() const { + if (zone == PixelsPerFrame) { + return { zone, level + 1 }; + } else if (level == 1) { + return { PixelsPerFrame, 2 }; + } else { + return { zone, level - 1 }; + } + } + + /// Inexact + double framesToPixels(double frames) const { + if (zone == PixelsPerFrame) { + return frames * level; + } else { + return frames / level; + } + } + + /// Inexact + double pixelsToFrames(double pixels) const { + if (zone == PixelsPerFrame) { + return pixels / level; + } else { + return pixels * level; + } + } +}; + +std::ostream &operator<<(std::ostream &s, const ZoomLevel &z); + +#endif diff -r 2f3a77472c8c -r 5360f7aba189 files.pri --- a/files.pri Tue Sep 18 16:28:56 2018 +0100 +++ b/files.pri Wed Sep 19 15:41:44 2018 +0100 @@ -43,6 +43,7 @@ base/Window.h \ base/XmlExportable.h \ base/ZoomConstraint.h \ + base/ZoomLevel.h \ data/fileio/AudioFileReader.h \ data/fileio/AudioFileReaderFactory.h \ data/fileio/AudioFileSizeEstimator.h \ @@ -175,6 +176,7 @@ base/UnitDatabase.cpp \ base/ViewManagerBase.cpp \ base/XmlExportable.cpp \ + base/ZoomLevel.cpp \ data/fileio/AudioFileReader.cpp \ data/fileio/AudioFileReaderFactory.cpp \ data/fileio/AudioFileSizeEstimator.cpp \