annotate data/model/RangeSummarisableTimeValueModel.h @ 1719:6af7bd6aaf79 3.3-stable

Branch
author Chris Cannam
date Tue, 21 May 2019 17:14:23 +0100
parents c01cbe41aeb5
children c3b5564cfb78
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@1326 16 #ifndef SV_RANGE_SUMMARISABLE_TIME_VALUE_MODEL_H
Chris@1326 17 #define SV_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
chris@769 23 #include <stdint.h>
chris@769 24
Chris@147 25 /**
Chris@147 26 * Base class for models containing dense two-dimensional data (value
Chris@147 27 * against time) that may be meaningfully represented in a zoomed view
Chris@147 28 * using min/max range summaries. Audio waveform data is an obvious
Chris@147 29 * example: think "peaks and minima" for "ranges".
Chris@147 30 */
Chris@147 31
Chris@179 32 class RangeSummarisableTimeValueModel : public DenseTimeValueModel
Chris@147 33 {
Chris@147 34 Q_OBJECT
Chris@147 35
Chris@147 36 public:
Chris@319 37 RangeSummarisableTimeValueModel() { }
Chris@297 38
Chris@410 39 class Range
Chris@410 40 {
Chris@410 41 public:
Chris@410 42 Range() :
Chris@1053 43 m_new(true), m_min(0.f), m_max(0.f), m_absmean(0.f) { }
Chris@410 44 Range(const Range &r) :
Chris@1053 45 m_new(true), m_min(r.m_min), m_max(r.m_max), m_absmean(r.m_absmean) { }
Chris@410 46 Range(float min, float max, float absmean) :
Chris@1053 47 m_new(true), m_min(min), m_max(max), m_absmean(absmean) { }
Chris@410 48
Chris@410 49 float min() const { return m_min; }
Chris@410 50 float max() const { return m_max; }
Chris@410 51 float absmean() const { return m_absmean; }
Chris@410 52
Chris@1053 53 void setMin(float min) { m_min = min; m_new = false; }
Chris@1053 54 void setMax(float max) { m_max = max; m_new = false; }
Chris@410 55 void setAbsmean(float absmean) { m_absmean = absmean; }
Chris@410 56
Chris@1053 57 void sample(float s) {
Chris@1053 58 if (m_new) {
Chris@1053 59 m_min = s;
Chris@1053 60 m_max = s;
Chris@1053 61 m_new = false;
Chris@1053 62 } else {
Chris@1053 63 if (s < m_min) m_min = s;
Chris@1053 64 if (s > m_max) m_max = s;
Chris@1053 65 }
Chris@1053 66 }
Chris@1053 67
Chris@410 68 private:
Chris@1053 69 bool m_new;
Chris@410 70 float m_min;
Chris@410 71 float m_max;
Chris@410 72 float m_absmean;
Chris@410 73 };
Chris@147 74
Chris@147 75 typedef std::vector<Range> RangeBlock;
Chris@147 76
Chris@147 77 /**
Chris@300 78 * Return ranges from the given start frame, corresponding to the
Chris@300 79 * given number of underlying sample frames, summarised at the
Chris@300 80 * given block size. duration / blockSize ranges should ideally
Chris@300 81 * be returned.
Chris@147 82 *
Chris@147 83 * If the given block size is not supported by this model
Chris@147 84 * (according to its zoom constraint), also modify the blockSize
Chris@147 85 * parameter so as to return the block size that was actually
Chris@147 86 * obtained.
Chris@147 87 */
Chris@1038 88 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
Chris@300 89 RangeBlock &ranges,
Chris@929 90 int &blockSize) const = 0;
Chris@147 91
Chris@147 92 /**
Chris@300 93 * Return the range from the given start frame, corresponding to
Chris@300 94 * the given number of underlying sample frames, summarised at a
Chris@300 95 * block size equal to the distance between start and end frames.
Chris@147 96 */
Chris@1038 97 virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const = 0;
Chris@345 98
Chris@929 99 virtual int getSummaryBlockSize(int desired) const = 0;
Chris@377 100
Chris@1580 101 QString getTypeName() const override { return tr("Range-Summarisable Time-Value"); }
Chris@147 102 };
Chris@147 103
Chris@147 104 #endif
Chris@147 105