annotate data/model/DenseThreeDimensionalModel.h @ 533:55ad231c9db7

* try some qvectors
author Chris Cannam
date Thu, 22 Jan 2009 17:58:33 +0000
parents 83eae5239db6
children fa32590f5a61
rev   line source
Chris@147 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@147 2
Chris@147 3 /*
Chris@147 4 Sonic Visualiser
Chris@147 5 An audio file viewer and annotation editor.
Chris@147 6 Centre for Digital Music, Queen Mary, University of London.
Chris@202 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@147 8
Chris@147 9 This program is free software; you can redistribute it and/or
Chris@147 10 modify it under the terms of the GNU General Public License as
Chris@147 11 published by the Free Software Foundation; either version 2 of the
Chris@147 12 License, or (at your option) any later version. See the file
Chris@147 13 COPYING included with this distribution for more information.
Chris@147 14 */
Chris@147 15
Chris@147 16 #ifndef _DENSE_THREE_DIMENSIONAL_MODEL_H_
Chris@147 17 #define _DENSE_THREE_DIMENSIONAL_MODEL_H_
Chris@147 18
Chris@150 19 #include "Model.h"
Chris@500 20 #include "TabularModel.h"
Chris@147 21 #include "base/ZoomConstraint.h"
Chris@500 22 #include "base/RealTime.h"
Chris@147 23
Chris@147 24 #include <QMutex>
Chris@533 25 #include <QVector>
Chris@147 26
Chris@500 27 class DenseThreeDimensionalModel : public Model,
Chris@500 28 public TabularModel
Chris@147 29 {
Chris@147 30 Q_OBJECT
Chris@147 31
Chris@147 32 public:
Chris@147 33 /**
Chris@182 34 * Return the number of sample frames covered by each column of bins.
Chris@147 35 */
Chris@152 36 virtual size_t getResolution() const = 0;
Chris@147 37
Chris@147 38 /**
Chris@182 39 * Return the number of columns of bins in the model.
Chris@147 40 */
Chris@182 41 virtual size_t getWidth() const = 0;
Chris@147 42
Chris@147 43 /**
Chris@182 44 * Return the number of bins in each column.
Chris@182 45 */
Chris@182 46 virtual size_t getHeight() const = 0;
Chris@182 47
Chris@182 48 /**
Chris@182 49 * Return the minimum permissible value in each bin.
Chris@147 50 */
Chris@152 51 virtual float getMinimumLevel() const = 0;
Chris@147 52
Chris@147 53 /**
Chris@182 54 * Return the maximum permissible value in each bin.
Chris@147 55 */
Chris@152 56 virtual float getMaximumLevel() const = 0;
Chris@147 57
Chris@182 58 /**
Chris@182 59 * Return true if there are data available for the given column.
Chris@223 60 * This should return true only if getColumn(column) would not
Chris@223 61 * have to do any substantial work to calculate its return values.
Chris@223 62 * If this function returns false, it may still be possible to
Chris@223 63 * retrieve the column, but its values may have to be calculated.
Chris@182 64 */
Chris@182 65 virtual bool isColumnAvailable(size_t column) const = 0;
Chris@182 66
Chris@533 67 typedef QVector<float> Column;
Chris@147 68
Chris@147 69 /**
Chris@182 70 * Get data from the given column of bin values.
Chris@147 71 */
Chris@533 72 virtual Column getColumn(size_t column) const = 0;
Chris@147 73
Chris@147 74 /**
Chris@182 75 * Get the single data point from the n'th bin of the given column.
Chris@147 76 */
Chris@182 77 virtual float getValueAt(size_t column, size_t n) const = 0;
Chris@147 78
Chris@182 79 /**
Chris@182 80 * Get the name of a given bin (i.e. a label to associate with
Chris@182 81 * that bin across all columns).
Chris@182 82 */
Chris@152 83 virtual QString getBinName(size_t n) const = 0;
Chris@147 84
Chris@182 85 /**
Chris@478 86 * Estimate whether a logarithmic scale might be appropriate for
Chris@478 87 * the value scale.
Chris@478 88 */
Chris@478 89 virtual bool shouldUseLogValueScale() const = 0;
Chris@478 90
Chris@478 91 /**
Chris@182 92 * Utility function to query whether a given bin is greater than
Chris@182 93 * its (vertical) neighbours.
Chris@182 94 */
Chris@182 95 bool isLocalPeak(size_t x, size_t y) {
Chris@182 96 float value = getValueAt(x, y);
Chris@182 97 if (y > 0 && value < getValueAt(x, y - 1)) return false;
Chris@182 98 if (y < getHeight() - 1 && value < getValueAt(x, y + 1)) return false;
Chris@182 99 return true;
Chris@182 100 }
Chris@182 101
Chris@182 102 /**
Chris@182 103 * Utility function to query whether a given bin is greater than a
Chris@182 104 * certain threshold.
Chris@182 105 */
Chris@182 106 bool isOverThreshold(size_t x, size_t y, float threshold) {
Chris@182 107 return getValueAt(x, y) > threshold;
Chris@182 108 }
Chris@182 109
Chris@345 110 QString getTypeName() const { return tr("Dense 3-D"); }
Chris@345 111
Chris@152 112 virtual int getCompletion() const = 0;
Chris@147 113
Chris@500 114 /*
Chris@500 115 TabularModel methods.
Chris@500 116 This class is non-editable -- subclasses may be editable.
Chris@500 117 Row and column are transposed for the tabular view (which is
Chris@500 118 "on its side").
Chris@500 119 */
Chris@500 120
Chris@500 121 virtual int getRowCount() const { return getWidth(); }
Chris@500 122 virtual int getColumnCount() const { return getHeight() + 2; }
Chris@500 123
Chris@500 124 virtual QString getHeading(int column) const
Chris@500 125 {
Chris@500 126 switch (column) {
Chris@500 127 case 0: return tr("Time");
Chris@500 128 case 1: return tr("Frame");
Chris@500 129 default: return getBinName(column - 2);
Chris@500 130 }
Chris@500 131 }
Chris@500 132
Chris@500 133 virtual QVariant getData(int row, int column, int role) const
Chris@500 134 {
Chris@500 135 switch (column) {
Chris@500 136 case 0: {
Chris@500 137 RealTime rt = RealTime::frame2RealTime(row * getResolution(),
Chris@500 138 getSampleRate());
Chris@500 139 return rt.toText().c_str();
Chris@500 140 }
Chris@500 141 case 1:
Chris@500 142 return int(row * getResolution());
Chris@500 143 default:
Chris@500 144 return getValueAt(row, column - 2);
Chris@500 145 }
Chris@500 146 }
Chris@500 147
Chris@500 148 virtual bool isColumnTimeValue(int col) const {
Chris@500 149 return col < 2;
Chris@500 150 }
Chris@500 151 virtual SortType getSortType(int col) const {
Chris@500 152 return SortNumeric;
Chris@500 153 }
Chris@500 154
Chris@500 155 virtual long getFrameForRow(int row) const {
Chris@500 156 return row * getSampleRate();
Chris@500 157 }
Chris@500 158 virtual int getRowForFrame(long frame) const {
Chris@500 159 return frame / getSampleRate();
Chris@500 160 }
Chris@500 161
Chris@147 162 protected:
Chris@152 163 DenseThreeDimensionalModel() { }
Chris@147 164 };
Chris@147 165
Chris@147 166 #endif