BasicCompressedDenseThreeDimensionalModel.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam and QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_BASIC_COMPRESSED_DENSE_THREE_DIMENSIONAL_MODEL_H
17 #define SV_BASIC_COMPRESSED_DENSE_THREE_DIMENSIONAL_MODEL_H
18 
20 
21 #include <QReadWriteLock>
22 
23 #include <vector>
24 
26 {
27  Q_OBJECT
28 
29 public:
30 
31  // BasicCompressedDenseThreeDimensionalModel supports a basic
32  // compression method that reduces the size of multirate data
33  // (e.g. wavelet transform outputs) that are stored as plain 3d
34  // grids by about 60% or thereabouts. However, it can only be
35  // used for models whose columns are set in order from 0 and never
36  // subsequently changed. For a model that is actually going to be
37  // edited, you need an EditableDenseThreeDimensionalModel.
38 
40  int resolution,
41  int height,
42  bool notifyOnAdd = true);
43 
44  bool isOK() const override;
45  bool isReady(int *completion = 0) const override;
46  void setCompletion(int completion, bool update = true);
47  int getCompletion() const override;
48 
49  sv_samplerate_t getSampleRate() const override;
50  sv_frame_t getStartFrame() const override;
51  sv_frame_t getTrueEndFrame() const override;
52 
56  virtual void setStartFrame(sv_frame_t);
57 
61  int getResolution() const override;
62 
66  virtual void setResolution(int sz);
67 
71  int getWidth() const override;
72 
76  int getHeight() const override;
77 
88  virtual void setHeight(int sz);
89 
93  float getMinimumLevel() const override;
94 
98  virtual void setMinimumLevel(float sz);
99 
103  float getMaximumLevel() const override;
104 
108  virtual void setMaximumLevel(float sz);
109 
113  Column getColumn(int x) const override;
114 
118  float getValueAt(int x, int n) const override;
119 
123  virtual void setColumn(int x, const Column &values);
124 
129  QString getBinName(int n) const override;
130 
134  virtual void setBinName(int n, QString);
135 
139  virtual void setBinNames(std::vector<QString> names);
140 
147  bool hasBinValues() const override;
148 
154  float getBinValue(int n) const override;
155 
161  virtual void setBinValues(std::vector<float> values);
162 
167  QString getBinValueUnit() const override;
168 
173  virtual void setBinValueUnit(QString unit);
174 
180  bool shouldUseLogValueScale() const override;
181 
182  QString getTypeName() const override { return tr("Editable Dense 3-D"); }
183 
184  QVector<QString>
185  getStringExportHeaders(DataExportOptions options) const override;
186 
187  QVector<QVector<QString>>
189  sv_frame_t startFrame,
190  sv_frame_t duration) const override;
191 
192  void toXml(QTextStream &out,
193  QString indent = "",
194  QString extraAttributes = "") const override;
195 
196 protected:
197  typedef std::vector<Column> ValueMatrix;
198  ValueMatrix m_data;
199 
200  // m_trunc is used for simple compression. If at least the top N
201  // elements of column x (for N = some proportion of the column
202  // height) are equal to those of an earlier column x', then
203  // m_trunc[x] will contain x-x' and column x will be truncated so
204  // as to remove the duplicate elements. If the equal elements are
205  // at the bottom, then m_trunc[x] will contain x'-x (a negative
206  // value). If m_trunc[x] is 0 then the whole of column x is
207  // stored.
208  std::vector<signed char> m_trunc;
209  void truncateAndStore(int index, const Column & values);
210  Column expandAndRetrieve(int index) const;
211  Column rightHeight(const Column &c) const;
212 
213  std::vector<QString> m_binNames;
214  std::vector<float> m_binValues;
215  QString m_binValueUnit;
216 
221  float m_minimum;
222  float m_maximum;
228 
229  mutable QReadWriteLock m_lock;
230 };
231 
232 #endif
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
QVector< QVector< QString > > toStringExportRows(DataExportOptions options, sv_frame_t startFrame, sv_frame_t duration) const override
Emit events starting within the given range as string rows ready for conversion to an e...
virtual void setBinValues(std::vector< float > values)
Set the values of all bins (separate from their labels).
sv_samplerate_t getSampleRate() const override
Return the frame rate in frames per second.
bool isOK() const override
Return true if the model was constructed successfully.
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const override
Stream this exportable object out to XML on a text stream.
float getMaximumLevel() const override
Return the maximum value of the value in each bin.
virtual void setResolution(int sz)
Set the number of sample frames covered by each set of bins.
virtual void setBinValueUnit(QString unit)
Set the name of the unit of the values return from getBinValue() if any.
virtual void setBinName(int n, QString)
Set the name of bin n.
virtual void setStartFrame(sv_frame_t)
Set the frame offset of the first column.
virtual void setBinNames(std::vector< QString > names)
Set the names of all bins.
QVector< QString > getStringExportHeaders(DataExportOptions options) const override
Return a label for each column that would be written by toStringExportRows.
float getMinimumLevel() const override
Return the minimum value of the value in each bin.
float getValueAt(int x, int n) const override
Get a single value, from the n&#39;th bin of the given column.
QString getBinName(int n) const override
Return the name of bin n.
int getResolution() const override
Return the number of sample frames covered by each set of bins.
bool hasBinValues() const override
Return true if the bins have values as well as names.
bool shouldUseLogValueScale() const override
Return true if the distribution of values in the bins is such as to suggest a log scale (mapping to c...
sv_frame_t getTrueEndFrame() const override
Return the audio frame at the end of the model.
virtual void setMinimumLevel(float sz)
Set the minimum value of the value in a bin.
int getWidth() const override
Return the number of columns.
Column getColumn(int x) const override
Get the set of bin values at the given column.
virtual void setHeight(int sz)
Set the number of bins in each column.
virtual void setMaximumLevel(float sz)
Set the maximum value of the value in a bin.
QString getBinValueUnit() const override
Obtain the name of the unit of the values returned from getBinValue(), if any.
QString getTypeName() const override
Return the type of the model.
virtual void setColumn(int x, const Column &values)
Set the entire set of bin values at the given column.
sv_frame_t getStartFrame() const override
Return the first audio frame spanned by the model.
float getBinValue(int n) const override
Return the value of bin n, if any.
int getCompletion() const override
Return an estimated percentage value showing how far through any background operation used to calcula...
BasicCompressedDenseThreeDimensionalModel(sv_samplerate_t sampleRate, int resolution, int height, bool notifyOnAdd=true)
bool isReady(int *completion=0) const override
Return true if the model has finished loading or calculating all its data, for a model that is capabl...
int getHeight() const override
Return the number of bins in each column.
int DataExportOptions