svcore  1.9
EditableDenseThreeDimensionalModel.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 _EDITABLE_DENSE_THREE_DIMENSIONAL_MODEL_H_
17 #define _EDITABLE_DENSE_THREE_DIMENSIONAL_MODEL_H_
18 
20 
21 #include <QReadWriteLock>
22 
23 #include <vector>
24 
26 {
27  Q_OBJECT
28 
29 public:
30 
31  // EditableDenseThreeDimensionalModel supports a basic compression
32  // method that reduces the size of multirate data (e.g. wavelet
33  // transform outputs) that are stored as plain 3d grids by about
34  // 60% or thereabouts. However, it can only be used for models
35  // whose columns are set in order from 0 and never subsequently
36  // changed. If the model is going to be actually edited, it must
37  // have NoCompression.
38 
40  {
43  };
44 
46  int resolution,
47  int yBinCount,
48  CompressionType compression,
49  bool notifyOnAdd = true);
50 
51  virtual bool isOK() const;
52 
53  virtual int getSampleRate() const;
54  virtual int getStartFrame() const;
55  virtual int getEndFrame() const;
56 
57  virtual Model *clone() const;
58 
59 
63  virtual void setStartFrame(int);
64 
68  virtual int getResolution() const;
69 
73  virtual void setResolution(int sz);
74 
78  virtual int getWidth() const;
79 
83  virtual int getHeight() const;
84 
88  virtual void setHeight(int sz);
89 
93  virtual float getMinimumLevel() const;
94 
98  virtual void setMinimumLevel(float sz);
99 
103  virtual float getMaximumLevel() const;
104 
108  virtual void setMaximumLevel(float sz);
109 
113  virtual bool isColumnAvailable(int x) const { return x < getWidth(); }
114 
118  virtual Column getColumn(int x) const;
119 
123  virtual float getValueAt(int x, int n) const;
124 
128  virtual void setColumn(int x, const Column &values);
129 
134  virtual QString getBinName(int n) const;
135 
139  virtual void setBinName(int n, QString);
140 
144  virtual void setBinNames(std::vector<QString> names);
145 
152  virtual bool hasBinValues() const;
153 
159  virtual float getBinValue(int n) const;
160 
166  virtual void setBinValues(std::vector<float> values);
167 
172  virtual QString getBinValueUnit() const;
173 
178  virtual void setBinValueUnit(QString unit);
179 
185  bool shouldUseLogValueScale() const;
186 
187  virtual void setCompletion(int completion, bool update = true);
188  virtual int getCompletion() const { return m_completion; }
189 
190  QString getTypeName() const { return tr("Editable Dense 3-D"); }
191 
192  virtual QString toDelimitedDataString(QString delimiter) const;
193  virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const;
194 
195  virtual void toXml(QTextStream &out,
196  QString indent = "",
197  QString extraAttributes = "") const;
198 
199 protected:
200  typedef QVector<Column> ValueMatrix;
202 
203  // m_trunc is used for simple compression. If at least the top N
204  // elements of column x (for N = some proportion of the column
205  // height) are equal to those of an earlier column x', then
206  // m_trunc[x] will contain x-x' and column x will be truncated so
207  // as to remove the duplicate elements. If the equal elements are
208  // at the bottom, then m_trunc[x] will contain x'-x (a negative
209  // value). If m_trunc[x] is 0 then the whole of column x is
210  // stored.
211  std::vector<signed char> m_trunc;
212  void truncateAndStore(int index, const Column & values);
213  Column expandAndRetrieve(int index) const;
214 
215  std::vector<QString> m_binNames;
216  std::vector<float> m_binValues;
217  QString m_binValueUnit;
218 
224  float m_minimum;
225  float m_maximum;
231 
232  mutable QReadWriteLock m_lock;
233 };
234 
235 #endif
virtual bool isOK() const
Return true if the model was constructed successfully.
virtual void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
virtual void setMinimumLevel(float sz)
Set the minimum value of the value in a bin.
virtual bool isColumnAvailable(int x) const
Return true if there are data available for the given column.
virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
virtual QString getBinValueUnit() const
Obtain the name of the unit of the values returned from getBinValue(), if any.
virtual QString getBinName(int n) const
Return the name of bin n.
virtual void setBinName(int n, QString)
Set the name of bin n.
virtual float getValueAt(int x, int n) const
Get a single value, from the n'th bin of the given column.
virtual QString toDelimitedDataString(QString delimiter) const
virtual void setCompletion(int completion, bool update=true)
virtual int getStartFrame() const
Return the first audio frame spanned by the model.
virtual float getMinimumLevel() const
Return the minimum value of the value in each bin.
QString getTypeName() const
Return the type of the model.
EditableDenseThreeDimensionalModel(int sampleRate, int resolution, int yBinCount, CompressionType compression, bool notifyOnAdd=true)
virtual float getMaximumLevel() const
Return the maximum value of the value in each bin.
bool shouldUseLogValueScale() const
Return true if the distribution of values in the bins is such as to suggest a log scale (mapping to c...
virtual int getHeight() const
Return the number of bins in 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 setStartFrame(int)
Set the frame offset of the first column.
virtual Column getColumn(int x) const
Get the set of bin values at the given column.
virtual float getBinValue(int n) const
Return the value of bin n, if any.
virtual void setBinNames(std::vector< QString > names)
Set the names of all bins.
virtual int getResolution() const
Return the number of sample frames covered by each set of bins.
Model is the base class for all data models that represent any sort of data on a time scale based on ...
Definition: Model.h:35
virtual void setMaximumLevel(float sz)
Set the maximum value of the value in a bin.
void truncateAndStore(int index, const Column &values)
virtual int getSampleRate() const
Return the frame rate in frames per second.
virtual int getEndFrame() const
Return the last audio frame spanned by the model.
virtual Model * clone() const
Return a copy of this model.
virtual void setResolution(int sz)
Set the number of sample frames covered by each set of bins.
virtual void setBinValues(std::vector< float > values)
Set the values of all bins (separate from their labels).
virtual void setHeight(int sz)
Set the number of bins in each set of bins.
virtual void setColumn(int x, const Column &values)
Set the entire set of bin values at the given column.
virtual bool hasBinValues() const
Return true if the bins have values as well as names.
virtual int getWidth() const
Return the number of columns.