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 SV_DENSE_THREE_DIMENSIONAL_MODEL_H
17 #define SV_DENSE_THREE_DIMENSIONAL_MODEL_H
18 
19 #include "Model.h"
20 #include "TabularModel.h"
21 #include "base/ColumnOp.h"
22 #include "base/ZoomConstraint.h"
23 #include "base/RealTime.h"
24 
25 #include <QMutex>
26 #include <QVector>
27 
29  public TabularModel
30 {
31  Q_OBJECT
32 
33 public:
37  virtual int getResolution() const = 0;
38 
42  virtual int getWidth() const = 0;
43 
47  virtual int getHeight() const = 0;
48 
52  virtual float getMinimumLevel() const = 0;
53 
57  virtual float getMaximumLevel() const = 0;
58 
60 
64  virtual Column getColumn(int column) const = 0;
65 
69  virtual float getValueAt(int column, int n) const = 0;
70 
75  virtual QString getBinName(int n) const = 0;
76 
81  virtual bool hasBinValues() const { return false; }
82 
88  virtual float getBinValue(int n) const { return float(n); }
89 
94  virtual QString getBinValueUnit() const { return ""; }
95 
100  virtual bool shouldUseLogValueScale() const = 0;
101 
106  bool isLocalPeak(int x, int y) {
107  float value = getValueAt(x, y);
108  if (y > 0 && value < getValueAt(x, y - 1)) return false;
109  if (y < getHeight() - 1 && value < getValueAt(x, y + 1)) return false;
110  return true;
111  }
112 
117  bool isOverThreshold(int x, int y, float threshold) {
118  return getValueAt(x, y) > threshold;
119  }
120 
121  QString getTypeName() const override { return tr("Dense 3-D"); }
122 
123  virtual int getCompletion() const override = 0;
124 
125  /*
126  TabularModel methods.
127  This class is non-editable -- subclasses may be editable.
128  Row and column are transposed for the tabular view (which is
129  "on its side").
130  */
131 
132  int getRowCount() const override { return getWidth(); }
133  int getColumnCount() const override { return getHeight() + 2; }
134 
135  bool isEditable() const override { return false; }
136  Command *getSetDataCommand(int, int, const QVariant &, int) override { return nullptr; }
137  Command *getInsertRowCommand(int) override { return nullptr; }
138  Command *getRemoveRowCommand(int) override { return nullptr; }
139 
140  QString getHeading(int column) const override
141  {
142  switch (column) {
143  case 0: return tr("Time");
144  case 1: return tr("Frame");
145  default:
146  QString name = getBinName(column - 2);
147  if (name == "") {
148  name = tr("(bin %1)").arg(column - 2);
149  }
150  return name;
151  }
152  }
153 
154  QVariant getData(int row, int column, int) const
155  override {
156  switch (column) {
157  case 0: {
159  (row * getResolution() + getStartFrame(), getSampleRate());
160  return rt.toText().c_str();
161  }
162  case 1:
163  return int(row * getResolution() + getStartFrame());
164  default:
165  return getValueAt(row, column - 2);
166  }
167  }
168 
169  bool isColumnTimeValue(int col) const override {
170  return col < 2;
171  }
172  SortType getSortType(int) const override {
173  return SortNumeric;
174  }
175 
176  sv_frame_t getFrameForRow(int row) const override {
177  return sv_frame_t(row) * getResolution() + getStartFrame();
178  }
179  int getRowForFrame(sv_frame_t frame) const override {
180  return int((frame - getStartFrame()) / getResolution());
181  }
182 
183 protected:
185 };
186 
187 #endif
virtual int getWidth() const =0
Return the number of columns of bins in the model.
int getColumnCount() const override
Return the number of columns (values/labels/etc per item).
QString getTypeName() const override
Return the type of the model.
virtual float getValueAt(int column, int n) const =0
Get the single data point from the n&#39;th bin of the given column.
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
static RealTime frame2RealTime(sv_frame_t frame, sv_samplerate_t sampleRate)
Convert a sample frame at the given sample rate into a RealTime.
Definition: RealTimeSV.cpp:498
virtual bool shouldUseLogValueScale() const =0
Estimate whether a logarithmic scale might be appropriate for the value scale.
virtual QString getBinValueUnit() const
Obtain the name of the unit of the values returned from getBinValue(), if any.
bool isEditable() const override
Return true if the model is user-editable, false otherwise.
Command * getSetDataCommand(int, int, const QVariant &, int) override
Return a command to set the value in the given cell, for the given role, to the contents of the suppl...
bool isLocalPeak(int x, int y)
Utility function to query whether a given bin is greater than its (vertical) neighbours.
int getRowCount() const override
Return the number of rows (items) in the model.
virtual float getMinimumLevel() const =0
Return the minimum permissible value in each bin.
sv_frame_t getFrameForRow(int row) const override
Return the frame time for the given row.
SortType getSortType(int) const override
Return the sort type (numeric or alphabetical) for the column.
int getRowForFrame(sv_frame_t frame) const override
Return the number of the first row whose frame time is not less than the given one.
bool isOverThreshold(int x, int y, float threshold)
Utility function to query whether a given bin is greater than a certain threshold.
Command * getRemoveRowCommand(int) override
Return a command to delete the row with the given index.
virtual int getResolution() const =0
Return the number of sample frames covered by each column of bins.
QString getHeading(int column) const override
Return the heading for a given column, e.g.
virtual float getBinValue(int n) const
Return the value of bin n, if any.
virtual bool hasBinValues() const
Return true if the bins have values as well as names.
virtual sv_samplerate_t getSampleRate() const =0
Return the frame rate in frames per second.
floatvec_t Column
Column type.
Definition: ColumnOp.h:56
Model is the base class for all data models that represent any sort of data on a time scale based on ...
Definition: Model.h:51
TabularModel is an abstract base class for models that support direct access to data in a tabular for...
Definition: TabularModel.h:35
virtual Column getColumn(int column) const =0
Get data from the given column of bin values.
QVariant getData(int row, int column, int) const override
Get the value in the given cell, for the given role.
virtual QString getBinName(int n) const =0
Get the name of a given bin (i.e.
virtual sv_frame_t getStartFrame() const =0
Return the first audio frame spanned by the model.
Command * getInsertRowCommand(int) override
Return a command to insert a new row before the row with the given index.
virtual int getCompletion() const override=0
Return an estimated percentage value showing how far through any background operation used to calcula...
virtual float getMaximumLevel() const =0
Return the maximum permissible value in each bin.
std::string toText(bool fixedDp=false) const
Return a user-readable string to the nearest millisecond, typically in a form like HH:MM:SS...
Definition: RealTimeSV.cpp:274
bool isColumnTimeValue(int col) const override
Return true if the column is the frame time of the item, or an alternative representation of it (i...
virtual int getHeight() const =0
Return the number of bins in each column.
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...
Definition: RealTime.h:42