annotate data/model/RangeSummarisableTimeValueModel.h @ 816:e2b535b35b5f tonioni

bugfixes to compile on Linux again
author gyorgyf
date Tue, 18 Jun 2013 22:18:10 +0100
parents 9c7ebf2cd956
children 8c5b0eec6fe9
rev   line source
Chris@147 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@147 2
Chris@147 3 /*
Chris@147 4 Sonic Visualiser
Chris@147 5 An audio file viewer and annotation editor.
Chris@147 6 Centre for Digital Music, Queen Mary, University of London.
Chris@297 7 This file copyright 2006-2007 Chris Cannam and QMUL.
Chris@147 8
Chris@147 9 This program is free software; you can redistribute it and/or
Chris@147 10 modify it under the terms of the GNU General Public License as
Chris@147 11 published by the Free Software Foundation; either version 2 of the
Chris@147 12 License, or (at your option) any later version. See the file
Chris@147 13 COPYING included with this distribution for more information.
Chris@147 14 */
Chris@147 15
Chris@147 16 #ifndef _RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H_
Chris@147 17 #define _RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H_
Chris@147 18
Chris@147 19 #include <QObject>
Chris@147 20
Chris@147 21 #include "DenseTimeValueModel.h"
Chris@147 22 #include "base/ZoomConstraint.h"
Chris@147 23
Chris@147 24 /**
Chris@147 25 * Base class for models containing dense two-dimensional data (value
Chris@147 26 * against time) that may be meaningfully represented in a zoomed view
Chris@147 27 * using min/max range summaries. Audio waveform data is an obvious
Chris@147 28 * example: think "peaks and minima" for "ranges".
Chris@147 29 */
Chris@147 30
Chris@179 31 class RangeSummarisableTimeValueModel : public DenseTimeValueModel
Chris@147 32 {
Chris@147 33 Q_OBJECT
Chris@147 34
Chris@147 35 public:
Chris@319 36 RangeSummarisableTimeValueModel() { }
Chris@297 37
Chris@410 38 #define RANGE_USE_SHORT 1
Chris@410 39 #ifdef RANGE_USE_SHORT
Chris@410 40 class Range
Chris@147 41 {
Chris@410 42 public:
Chris@147 43 Range() :
Chris@410 44 m_min(0), m_max(0), m_absmean(0) { }
Chris@147 45 Range(const Range &r) :
Chris@410 46 m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
Chris@410 47 Range(float min, float max, float absmean)
Chris@410 48 { setMin(min); setMax(max); setAbsmean(absmean); }
Chris@410 49
Chris@410 50 float min() const { return i2f(m_min); }
Chris@410 51 float max() const { return i2f(m_max); }
Chris@410 52 float absmean() const { return i2f(m_absmean); }
Chris@410 53
Chris@410 54 void setMin(float min) { m_min = f2i(min); }
Chris@410 55 void setMax(float max) { m_max = f2i(max); }
Chris@410 56 void setAbsmean(float absmean) { m_absmean = f2i(absmean); }
Chris@410 57
Chris@410 58 private:
Chris@410 59 static inline int16_t f2i(float f) {
Chris@410 60 if (f > 1.f) f = 1.f;
Chris@410 61 if (f < -1.f) f = -1.f;
Chris@410 62 return int16_t(f * 32767.f);
Chris@410 63 }
Chris@410 64 static inline float i2f(int16_t i) {
Chris@410 65 return float(i) / 32767.f;
Chris@410 66 }
Chris@410 67
Chris@410 68 int16_t m_min;
Chris@410 69 int16_t m_max;
Chris@410 70 int16_t m_absmean;
Chris@147 71 };
Chris@410 72 #else
Chris@410 73 class Range
Chris@410 74 {
Chris@410 75 public:
Chris@410 76 Range() :
Chris@410 77 m_min(0.f), m_max(0.f), m_absmean(0.f) { }
Chris@410 78 Range(const Range &r) :
Chris@410 79 m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
Chris@410 80 Range(float min, float max, float absmean) :
Chris@410 81 m_min(min), m_max(max), m_absmean(absmean) { }
Chris@410 82
Chris@410 83 float min() const { return m_min; }
Chris@410 84 float max() const { return m_max; }
Chris@410 85 float absmean() const { return m_absmean; }
Chris@410 86
Chris@410 87 void setMin(float min) { m_min = min; }
Chris@410 88 void setMax(float max) { m_max = max; }
Chris@410 89 void setAbsmean(float absmean) { m_absmean = absmean; }
Chris@410 90
Chris@410 91 private:
Chris@410 92 float m_min;
Chris@410 93 float m_max;
Chris@410 94 float m_absmean;
Chris@410 95 };
Chris@410 96 #endif
Chris@147 97
Chris@147 98 typedef std::vector<Range> RangeBlock;
Chris@147 99
Chris@147 100 /**
Chris@300 101 * Return ranges from the given start frame, corresponding to the
Chris@300 102 * given number of underlying sample frames, summarised at the
Chris@300 103 * given block size. duration / blockSize ranges should ideally
Chris@300 104 * be returned.
Chris@147 105 *
Chris@147 106 * If the given block size is not supported by this model
Chris@147 107 * (according to its zoom constraint), also modify the blockSize
Chris@147 108 * parameter so as to return the block size that was actually
Chris@147 109 * obtained.
Chris@147 110 */
Chris@300 111 virtual void getSummaries(size_t channel, size_t start, size_t count,
Chris@300 112 RangeBlock &ranges,
Chris@300 113 size_t &blockSize) const = 0;
Chris@147 114
Chris@147 115 /**
Chris@300 116 * Return the range from the given start frame, corresponding to
Chris@300 117 * the given number of underlying sample frames, summarised at a
Chris@300 118 * block size equal to the distance between start and end frames.
Chris@147 119 */
Chris@300 120 virtual Range getSummary(size_t channel, size_t start, size_t count) const = 0;
Chris@345 121
Chris@377 122 virtual size_t getSummaryBlockSize(size_t desired) const = 0;
Chris@377 123
Chris@345 124 QString getTypeName() const { return tr("Range-Summarisable Time-Value"); }
Chris@147 125 };
Chris@147 126
Chris@147 127 #endif
Chris@147 128