annotate data/model/RangeSummarisableTimeValueModel.h @ 792:a98af74f8e2f qt5

Look for qmake-qt5, not qt4
author Chris Cannam
date Fri, 26 Apr 2013 16:37:07 +0100
parents 8c5b0eec6fe9
children f3c98e89cf75
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@769 24 #include <stdint.h>
chris@769 25
Chris@147 26 /**
Chris@147 27 * Base class for models containing dense two-dimensional data (value
Chris@147 28 * against time) that may be meaningfully represented in a zoomed view
Chris@147 29 * using min/max range summaries. Audio waveform data is an obvious
Chris@147 30 * example: think "peaks and minima" for "ranges".
Chris@147 31 */
Chris@147 32
Chris@179 33 class RangeSummarisableTimeValueModel : public DenseTimeValueModel
Chris@147 34 {
Chris@147 35 Q_OBJECT
Chris@147 36
Chris@147 37 public:
Chris@319 38 RangeSummarisableTimeValueModel() { }
Chris@297 39
Chris@410 40 #define RANGE_USE_SHORT 1
Chris@410 41 #ifdef RANGE_USE_SHORT
Chris@410 42 class Range
Chris@147 43 {
Chris@410 44 public:
Chris@147 45 Range() :
Chris@410 46 m_min(0), m_max(0), m_absmean(0) { }
Chris@147 47 Range(const Range &r) :
Chris@410 48 m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
Chris@410 49 Range(float min, float max, float absmean)
Chris@410 50 { setMin(min); setMax(max); setAbsmean(absmean); }
Chris@410 51
Chris@410 52 float min() const { return i2f(m_min); }
Chris@410 53 float max() const { return i2f(m_max); }
Chris@410 54 float absmean() const { return i2f(m_absmean); }
Chris@410 55
Chris@410 56 void setMin(float min) { m_min = f2i(min); }
Chris@410 57 void setMax(float max) { m_max = f2i(max); }
Chris@410 58 void setAbsmean(float absmean) { m_absmean = f2i(absmean); }
Chris@410 59
Chris@410 60 private:
Chris@410 61 static inline int16_t f2i(float f) {
Chris@410 62 if (f > 1.f) f = 1.f;
Chris@410 63 if (f < -1.f) f = -1.f;
Chris@410 64 return int16_t(f * 32767.f);
Chris@410 65 }
Chris@410 66 static inline float i2f(int16_t i) {
Chris@410 67 return float(i) / 32767.f;
Chris@410 68 }
Chris@410 69
Chris@410 70 int16_t m_min;
Chris@410 71 int16_t m_max;
Chris@410 72 int16_t m_absmean;
Chris@147 73 };
Chris@410 74 #else
Chris@410 75 class Range
Chris@410 76 {
Chris@410 77 public:
Chris@410 78 Range() :
Chris@410 79 m_min(0.f), m_max(0.f), m_absmean(0.f) { }
Chris@410 80 Range(const Range &r) :
Chris@410 81 m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
Chris@410 82 Range(float min, float max, float absmean) :
Chris@410 83 m_min(min), m_max(max), m_absmean(absmean) { }
Chris@410 84
Chris@410 85 float min() const { return m_min; }
Chris@410 86 float max() const { return m_max; }
Chris@410 87 float absmean() const { return m_absmean; }
Chris@410 88
Chris@410 89 void setMin(float min) { m_min = min; }
Chris@410 90 void setMax(float max) { m_max = max; }
Chris@410 91 void setAbsmean(float absmean) { m_absmean = absmean; }
Chris@410 92
Chris@410 93 private:
Chris@410 94 float m_min;
Chris@410 95 float m_max;
Chris@410 96 float m_absmean;
Chris@410 97 };
Chris@410 98 #endif
Chris@147 99
Chris@147 100 typedef std::vector<Range> RangeBlock;
Chris@147 101
Chris@147 102 /**
Chris@300 103 * Return ranges from the given start frame, corresponding to the
Chris@300 104 * given number of underlying sample frames, summarised at the
Chris@300 105 * given block size. duration / blockSize ranges should ideally
Chris@300 106 * be returned.
Chris@147 107 *
Chris@147 108 * If the given block size is not supported by this model
Chris@147 109 * (according to its zoom constraint), also modify the blockSize
Chris@147 110 * parameter so as to return the block size that was actually
Chris@147 111 * obtained.
Chris@147 112 */
Chris@300 113 virtual void getSummaries(size_t channel, size_t start, size_t count,
Chris@300 114 RangeBlock &ranges,
Chris@300 115 size_t &blockSize) const = 0;
Chris@147 116
Chris@147 117 /**
Chris@300 118 * Return the range from the given start frame, corresponding to
Chris@300 119 * the given number of underlying sample frames, summarised at a
Chris@300 120 * block size equal to the distance between start and end frames.
Chris@147 121 */
Chris@300 122 virtual Range getSummary(size_t channel, size_t start, size_t count) const = 0;
Chris@345 123
Chris@377 124 virtual size_t getSummaryBlockSize(size_t desired) const = 0;
Chris@377 125
Chris@345 126 QString getTypeName() const { return tr("Range-Summarisable Time-Value"); }
Chris@147 127 };
Chris@147 128
Chris@147 129 #endif
Chris@147 130