1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Sonic Visualiser
An audio file viewer and annotation editor.
Centre for Digital Music, Queen Mary, University of London.
This file copyright 2006 Chris Cannam and QMUL.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
#ifndef SV_DENSE_THREE_DIMENSIONAL_MODEL_H
#define SV_DENSE_THREE_DIMENSIONAL_MODEL_H
#include "Model.h"
#include "TabularModel.h"
#include "base/ColumnOp.h"
#include "base/ZoomConstraint.h"
#include "base/RealTime.h"
#include <QMutex>
#include <QVector>
namespace sv {
class DenseThreeDimensionalModel : public Model,
public TabularModel
{
Q_OBJECT
public:
/**
* Return the number of sample frames covered by each column of bins.
*/
virtual int getResolution() const = 0;
/**
* Return the number of columns of bins in the model.
*/
virtual int getWidth() const = 0;
/**
* Return the number of bins in each column.
*/
virtual int getHeight() const = 0;
/**
* Return the minimum permissible value in each bin.
*/
virtual float getMinimumLevel() const = 0;
/**
* Return the maximum permissible value in each bin.
*/
virtual float getMaximumLevel() const = 0;
typedef ColumnOp::Column Column;
/**
* Get data from the given column of bin values.
*/
virtual Column getColumn(int column) const = 0;
/**
* Get data from the given column of bin values, within the given
* bin range.
*/
virtual Column getColumn(int column, int minbin, int nbins) const = 0;
/**
* Get the single data point from the n'th bin of the given column.
*/
virtual float getValueAt(int column, int n) const = 0;
/**
* Obtain the name of the unit of the values returned from
* getValueAt(), if any.
*/
virtual QString getValueUnit() const = 0;
/**
* Get the name of a given bin (i.e. a label to associate with
* that bin across all columns).
*/
virtual QString getBinName(int n) const = 0;
/**
* Return true if the bins have values as well as names. If this
* returns true, getBinValue() may be used to retrieve the values.
*/
virtual bool hasBinValues() const { return false; }
/**
* Return the value of bin n, if any. This is a "vertical scale"
* value which does not vary from one column to the next. This is
* only meaningful if hasBinValues() returns true.
*/
virtual float getBinValue(int n) const { return float(n); }
/**
* Obtain the name of the unit of the values returned from
* getBinValue(), if any.
*/
virtual QString getBinValueUnit() const { return ""; }
/**
* Estimate whether a logarithmic scale might be an appropriate
* default for the value scale.
*/
virtual bool shouldUseLogValueScale() const = 0;
/**
* Utility function to query whether a given bin is greater than
* its (vertical) neighbours.
*/
bool isLocalPeak(int x, int y) {
float value = getValueAt(x, y);
if (y > 0 && value < getValueAt(x, y - 1)) return false;
if (y < getHeight() - 1 && value < getValueAt(x, y + 1)) return false;
return true;
}
/**
* Utility function to query whether a given bin is greater than a
* certain threshold.
*/
bool isOverThreshold(int x, int y, float threshold) {
return getValueAt(x, y) > threshold;
}
QString getTypeName() const override { return tr("Dense 3-D"); }
virtual int getCompletion() const override = 0;
/*
TabularModel methods.
This class is non-editable -- subclasses may be editable.
Row and column are transposed for the tabular view (which is
"on its side").
*/
int getRowCount() const override { return getWidth(); }
int getColumnCount() const override { return getHeight() + 2; }
bool isEditable() const override { return false; }
Command *getSetDataCommand(int, int, const QVariant &, int) override { return nullptr; }
Command *getInsertRowCommand(int) override { return nullptr; }
Command *getRemoveRowCommand(int) override { return nullptr; }
QString getHeading(int column) const override
{
switch (column) {
case 0: return tr("Time");
case 1: return tr("Frame");
default:
QString name = getBinName(column - 2);
if (name == "") {
name = tr("(bin %1)").arg(column - 2);
}
return name;
}
}
QVariant getData(int row, int column, int) const
override {
switch (column) {
case 0: {
RealTime rt = RealTime::frame2RealTime
(row * getResolution() + getStartFrame(), getSampleRate());
return rt.toText().c_str();
}
case 1:
return int(row * getResolution() + getStartFrame());
default:
return getValueAt(row, column - 2);
}
}
bool isColumnTimeValue(int col) const override {
return col < 2;
}
SortType getSortType(int) const override {
return SortNumeric;
}
sv_frame_t getFrameForRow(int row) const override {
return sv_frame_t(row) * getResolution() + getStartFrame();
}
int getRowForFrame(sv_frame_t frame) const override {
return int((frame - getStartFrame()) / getResolution());
}
protected:
DenseThreeDimensionalModel() { }
};
} // end namespace sv
#endif
|