annotate data/model/BasicCompressedDenseThreeDimensionalModel.h @ 1793:f0ffc88a36b3 time-frequency-boxes

Add duration-and-extent type, which corresponds to a box model
author Chris Cannam
date Wed, 25 Sep 2019 11:06:59 +0100
parents d484490cdf69
children c546429d4c2f
rev   line source
Chris@1777 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@1777 2
Chris@1777 3 /*
Chris@1777 4 Sonic Visualiser
Chris@1777 5 An audio file viewer and annotation editor.
Chris@1777 6 Centre for Digital Music, Queen Mary, University of London.
Chris@1777 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@1777 8
Chris@1777 9 This program is free software; you can redistribute it and/or
Chris@1777 10 modify it under the terms of the GNU General Public License as
Chris@1777 11 published by the Free Software Foundation; either version 2 of the
Chris@1777 12 License, or (at your option) any later version. See the file
Chris@1777 13 COPYING included with this distribution for more information.
Chris@1777 14 */
Chris@1777 15
Chris@1777 16 #ifndef SV_BASIC_COMPRESSED_DENSE_THREE_DIMENSIONAL_MODEL_H
Chris@1777 17 #define SV_BASIC_COMPRESSED_DENSE_THREE_DIMENSIONAL_MODEL_H
Chris@1777 18
Chris@1777 19 #include "DenseThreeDimensionalModel.h"
Chris@1777 20
Chris@1777 21 #include <QReadWriteLock>
Chris@1777 22
Chris@1777 23 #include <vector>
Chris@1777 24
Chris@1777 25 class BasicCompressedDenseThreeDimensionalModel : public DenseThreeDimensionalModel
Chris@1777 26 {
Chris@1777 27 Q_OBJECT
Chris@1777 28
Chris@1777 29 public:
Chris@1777 30
Chris@1777 31 // BasicCompressedDenseThreeDimensionalModel supports a basic
Chris@1777 32 // compression method that reduces the size of multirate data
Chris@1777 33 // (e.g. wavelet transform outputs) that are stored as plain 3d
Chris@1777 34 // grids by about 60% or thereabouts. However, it can only be
Chris@1777 35 // used for models whose columns are set in order from 0 and never
Chris@1777 36 // subsequently changed. For a model that is actually going to be
Chris@1777 37 // edited, you need an EditableDenseThreeDimensionalModel.
Chris@1777 38
Chris@1777 39 BasicCompressedDenseThreeDimensionalModel(sv_samplerate_t sampleRate,
Chris@1777 40 int resolution,
Chris@1777 41 int height,
Chris@1777 42 bool notifyOnAdd = true);
Chris@1777 43
Chris@1777 44 bool isOK() const override;
Chris@1777 45 bool isReady(int *completion = 0) const override;
Chris@1777 46 void setCompletion(int completion, bool update = true);
Chris@1777 47 int getCompletion() const override;
Chris@1777 48
Chris@1777 49 sv_samplerate_t getSampleRate() const override;
Chris@1777 50 sv_frame_t getStartFrame() const override;
Chris@1777 51 sv_frame_t getTrueEndFrame() const override;
Chris@1777 52
Chris@1777 53 /**
Chris@1777 54 * Set the frame offset of the first column.
Chris@1777 55 */
Chris@1777 56 virtual void setStartFrame(sv_frame_t);
Chris@1777 57
Chris@1777 58 /**
Chris@1777 59 * Return the number of sample frames covered by each set of bins.
Chris@1777 60 */
Chris@1777 61 int getResolution() const override;
Chris@1777 62
Chris@1777 63 /**
Chris@1777 64 * Set the number of sample frames covered by each set of bins.
Chris@1777 65 */
Chris@1777 66 virtual void setResolution(int sz);
Chris@1777 67
Chris@1777 68 /**
Chris@1777 69 * Return the number of columns.
Chris@1777 70 */
Chris@1777 71 int getWidth() const override;
Chris@1777 72
Chris@1777 73 /**
Chris@1777 74 * Return the number of bins in each column.
Chris@1777 75 */
Chris@1777 76 int getHeight() const override;
Chris@1777 77
Chris@1777 78 /**
Chris@1777 79 * Set the number of bins in each column.
Chris@1777 80 *
Chris@1777 81 * You can set (via setColumn) a vector of any length as a column,
Chris@1777 82 * but any column being retrieved will be resized to this height
Chris@1777 83 * (or the height that was supplied to the constructor, if this is
Chris@1777 84 * never called) on retrieval. That is, the model owner determines
Chris@1777 85 * the height of the model at a single stroke; the columns
Chris@1777 86 * themselves don't have any effect on the height of the model.
Chris@1777 87 */
Chris@1777 88 virtual void setHeight(int sz);
Chris@1777 89
Chris@1777 90 /**
Chris@1777 91 * Return the minimum value of the value in each bin.
Chris@1777 92 */
Chris@1777 93 float getMinimumLevel() const override;
Chris@1777 94
Chris@1777 95 /**
Chris@1777 96 * Set the minimum value of the value in a bin.
Chris@1777 97 */
Chris@1777 98 virtual void setMinimumLevel(float sz);
Chris@1777 99
Chris@1777 100 /**
Chris@1777 101 * Return the maximum value of the value in each bin.
Chris@1777 102 */
Chris@1777 103 float getMaximumLevel() const override;
Chris@1777 104
Chris@1777 105 /**
Chris@1777 106 * Set the maximum value of the value in a bin.
Chris@1777 107 */
Chris@1777 108 virtual void setMaximumLevel(float sz);
Chris@1777 109
Chris@1777 110 /**
Chris@1777 111 * Get the set of bin values at the given column.
Chris@1777 112 */
Chris@1777 113 Column getColumn(int x) const override;
Chris@1777 114
Chris@1777 115 /**
Chris@1777 116 * Get a single value, from the n'th bin of the given column.
Chris@1777 117 */
Chris@1777 118 float getValueAt(int x, int n) const override;
Chris@1777 119
Chris@1777 120 /**
Chris@1777 121 * Set the entire set of bin values at the given column.
Chris@1777 122 */
Chris@1777 123 virtual void setColumn(int x, const Column &values);
Chris@1777 124
Chris@1777 125 /**
Chris@1777 126 * Return the name of bin n. This is a single label per bin that
Chris@1777 127 * does not vary from one column to the next.
Chris@1777 128 */
Chris@1777 129 QString getBinName(int n) const override;
Chris@1777 130
Chris@1777 131 /**
Chris@1777 132 * Set the name of bin n.
Chris@1777 133 */
Chris@1777 134 virtual void setBinName(int n, QString);
Chris@1777 135
Chris@1777 136 /**
Chris@1777 137 * Set the names of all bins.
Chris@1777 138 */
Chris@1777 139 virtual void setBinNames(std::vector<QString> names);
Chris@1777 140
Chris@1777 141 /**
Chris@1777 142 * Return true if the bins have values as well as names. (The
Chris@1777 143 * values may have been derived from the names, e.g. by parsing
Chris@1777 144 * numbers from them.) If this returns true, getBinValue() may be
Chris@1777 145 * used to retrieve the values.
Chris@1777 146 */
Chris@1777 147 bool hasBinValues() const override;
Chris@1777 148
Chris@1777 149 /**
Chris@1777 150 * Return the value of bin n, if any. This is a "vertical scale"
Chris@1777 151 * value which does not vary from one column to the next. This is
Chris@1777 152 * only meaningful if hasBinValues() returns true.
Chris@1777 153 */
Chris@1777 154 float getBinValue(int n) const override;
Chris@1777 155
Chris@1777 156 /**
Chris@1777 157 * Set the values of all bins (separate from their labels). These
Chris@1777 158 * are "vertical scale" values which do not vary from one column
Chris@1777 159 * to the next.
Chris@1777 160 */
Chris@1777 161 virtual void setBinValues(std::vector<float> values);
Chris@1777 162
Chris@1777 163 /**
Chris@1777 164 * Obtain the name of the unit of the values returned from
Chris@1777 165 * getBinValue(), if any.
Chris@1777 166 */
Chris@1777 167 QString getBinValueUnit() const override;
Chris@1777 168
Chris@1777 169 /**
Chris@1777 170 * Set the name of the unit of the values return from
Chris@1777 171 * getBinValue() if any.
Chris@1777 172 */
Chris@1777 173 virtual void setBinValueUnit(QString unit);
Chris@1777 174
Chris@1777 175 /**
Chris@1777 176 * Return true if the distribution of values in the bins is such
Chris@1777 177 * as to suggest a log scale (mapping to colour etc) may be better
Chris@1777 178 * than a linear one.
Chris@1777 179 */
Chris@1777 180 bool shouldUseLogValueScale() const override;
Chris@1777 181
Chris@1777 182 QString getTypeName() const override { return tr("Editable Dense 3-D"); }
Chris@1777 183
Chris@1777 184 QString toDelimitedDataString(QString delimiter,
Chris@1777 185 DataExportOptions options,
Chris@1777 186 sv_frame_t startFrame,
Chris@1777 187 sv_frame_t duration) const override;
Chris@1777 188
Chris@1777 189 void toXml(QTextStream &out,
Chris@1777 190 QString indent = "",
Chris@1777 191 QString extraAttributes = "") const override;
Chris@1777 192
Chris@1777 193 protected:
Chris@1777 194 typedef std::vector<Column> ValueMatrix;
Chris@1777 195 ValueMatrix m_data;
Chris@1777 196
Chris@1777 197 // m_trunc is used for simple compression. If at least the top N
Chris@1777 198 // elements of column x (for N = some proportion of the column
Chris@1777 199 // height) are equal to those of an earlier column x', then
Chris@1777 200 // m_trunc[x] will contain x-x' and column x will be truncated so
Chris@1777 201 // as to remove the duplicate elements. If the equal elements are
Chris@1777 202 // at the bottom, then m_trunc[x] will contain x'-x (a negative
Chris@1777 203 // value). If m_trunc[x] is 0 then the whole of column x is
Chris@1777 204 // stored.
Chris@1777 205 std::vector<signed char> m_trunc;
Chris@1777 206 void truncateAndStore(int index, const Column & values);
Chris@1777 207 Column expandAndRetrieve(int index) const;
Chris@1777 208 Column rightHeight(const Column &c) const;
Chris@1777 209
Chris@1777 210 std::vector<QString> m_binNames;
Chris@1777 211 std::vector<float> m_binValues;
Chris@1777 212 QString m_binValueUnit;
Chris@1777 213
Chris@1777 214 sv_frame_t m_startFrame;
Chris@1777 215 sv_samplerate_t m_sampleRate;
Chris@1777 216 int m_resolution;
Chris@1777 217 int m_yBinCount;
Chris@1777 218 float m_minimum;
Chris@1777 219 float m_maximum;
Chris@1777 220 bool m_haveExtents;
Chris@1777 221 bool m_notifyOnAdd;
Chris@1777 222 sv_frame_t m_sinceLastNotifyMin;
Chris@1777 223 sv_frame_t m_sinceLastNotifyMax;
Chris@1777 224 int m_completion;
Chris@1777 225
Chris@1777 226 mutable QReadWriteLock m_lock;
Chris@1777 227 };
Chris@1777 228
Chris@1777 229 #endif