svcore  1.9
DenseThreeDimensionalModel.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 _DENSE_THREE_DIMENSIONAL_MODEL_H_
17 #define _DENSE_THREE_DIMENSIONAL_MODEL_H_
18 
19 #include "Model.h"
20 #include "TabularModel.h"
21 #include "base/ZoomConstraint.h"
22 #include "base/RealTime.h"
23 
24 #include <QMutex>
25 #include <QVector>
26 
28  public TabularModel
29 {
30  Q_OBJECT
31 
32 public:
36  virtual int getResolution() const = 0;
37 
41  virtual int getWidth() const = 0;
42 
46  virtual int getHeight() const = 0;
47 
51  virtual float getMinimumLevel() const = 0;
52 
56  virtual float getMaximumLevel() const = 0;
57 
65  virtual bool isColumnAvailable(int column) const = 0;
66 
67  typedef QVector<float> Column;
68 
72  virtual Column getColumn(int column) const = 0;
73 
77  virtual float getValueAt(int column, int n) const = 0;
78 
83  virtual QString getBinName(int n) const = 0;
84 
89  virtual bool hasBinValues() const { return false; }
90 
96  virtual float getBinValue(int n) const { return n; }
97 
102  virtual QString getBinValueUnit() const { return ""; }
103 
108  virtual bool shouldUseLogValueScale() const = 0;
109 
114  bool isLocalPeak(int x, int y) {
115  float value = getValueAt(x, y);
116  if (y > 0 && value < getValueAt(x, y - 1)) return false;
117  if (y < getHeight() - 1 && value < getValueAt(x, y + 1)) return false;
118  return true;
119  }
120 
125  bool isOverThreshold(int x, int y, float threshold) {
126  return getValueAt(x, y) > threshold;
127  }
128 
129  QString getTypeName() const { return tr("Dense 3-D"); }
130 
131  virtual int getCompletion() const = 0;
132 
133  /*
134  TabularModel methods.
135  This class is non-editable -- subclasses may be editable.
136  Row and column are transposed for the tabular view (which is
137  "on its side").
138  */
139 
140  virtual int getRowCount() const { return getWidth(); }
141  virtual int getColumnCount() const { return getHeight() + 2; }
142 
143  virtual QString getHeading(int column) const
144  {
145  switch (column) {
146  case 0: return tr("Time");
147  case 1: return tr("Frame");
148  default: return getBinName(column - 2);
149  }
150  }
151 
152  virtual QVariant getData(int row, int column, int) const
153  {
154  switch (column) {
155  case 0: {
157  getSampleRate());
158  return rt.toText().c_str();
159  }
160  case 1:
161  return int(row * getResolution());
162  default:
163  return getValueAt(row, column - 2);
164  }
165  }
166 
167  virtual bool isColumnTimeValue(int col) const {
168  return col < 2;
169  }
170  virtual SortType getSortType(int) const {
171  return SortNumeric;
172  }
173 
174  virtual long getFrameForRow(int row) const {
175  return row * getSampleRate();
176  }
177  virtual int getRowForFrame(long frame) const {
178  return frame / getSampleRate();
179  }
180 
181 protected:
183 };
184 
185 #endif
virtual int getWidth() const =0
Return the number of columns of bins in the model.
virtual int getCompletion() const =0
virtual QString getBinValueUnit() const
Obtain the name of the unit of the values returned from getBinValue(), if any.
virtual QString getHeading(int column) const
static RealTime frame2RealTime(long frame, unsigned int sampleRate)
Convert a sample frame at the given sample rate into a RealTime.
Definition: RealTime.cpp:450
std::string toText(bool fixedDp=false) const
Return a user-readable string to the nearest millisecond, in a form like HH:MM:SS....
Definition: RealTime.cpp:252
virtual float getValueAt(int column, int n) const =0
Get the single data point from the n'th bin of the given column.
virtual QVariant getData(int row, int column, int) const
virtual bool shouldUseLogValueScale() const =0
Estimate whether a logarithmic scale might be appropriate for the value scale.
bool isLocalPeak(int x, int y)
Utility function to query whether a given bin is greater than its (vertical) neighbours.
virtual bool isColumnTimeValue(int col) const
virtual long getFrameForRow(int row) const
virtual float getMinimumLevel() const =0
Return the minimum permissible value in each bin.
virtual bool hasBinValues() const
Return true if the bins have values as well as names.
QString getTypeName() const
Return the type of the model.
bool isOverThreshold(int x, int y, float threshold)
Utility function to query whether a given bin is greater than a certain threshold.
virtual int getResolution() const =0
Return the number of sample frames covered by each column of bins.
virtual int getSampleRate() const =0
Return the frame rate in frames per second.
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
TabularModel is an abstract base class for models that support direct access to data in a tabular for...
Definition: TabularModel.h:34
virtual Column getColumn(int column) const =0
Get data from the given column of bin values.
virtual SortType getSortType(int) const
virtual float getBinValue(int n) const
Return the value of bin n, if any.
virtual QString getBinName(int n) const =0
Get the name of a given bin (i.e.
virtual int getRowForFrame(long frame) const
virtual float getMaximumLevel() const =0
Return the maximum permissible value in each bin.
virtual int getHeight() const =0
Return the number of bins in each column.
virtual bool isColumnAvailable(int column) const =0
Return true if there are data available for the given column.
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...
Definition: RealTime.h:35