svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _DENSE_THREE_DIMENSIONAL_MODEL_H_ 00017 #define _DENSE_THREE_DIMENSIONAL_MODEL_H_ 00018 00019 #include "Model.h" 00020 #include "TabularModel.h" 00021 #include "base/ZoomConstraint.h" 00022 #include "base/RealTime.h" 00023 00024 #include <QMutex> 00025 #include <QVector> 00026 00027 class DenseThreeDimensionalModel : public Model, 00028 public TabularModel 00029 { 00030 Q_OBJECT 00031 00032 public: 00036 virtual int getResolution() const = 0; 00037 00041 virtual int getWidth() const = 0; 00042 00046 virtual int getHeight() const = 0; 00047 00051 virtual float getMinimumLevel() const = 0; 00052 00056 virtual float getMaximumLevel() const = 0; 00057 00065 virtual bool isColumnAvailable(int column) const = 0; 00066 00067 typedef QVector<float> Column; 00068 00072 virtual Column getColumn(int column) const = 0; 00073 00077 virtual float getValueAt(int column, int n) const = 0; 00078 00083 virtual QString getBinName(int n) const = 0; 00084 00089 virtual bool hasBinValues() const { return false; } 00090 00096 virtual float getBinValue(int n) const { return n; } 00097 00102 virtual QString getBinValueUnit() const { return ""; } 00103 00108 virtual bool shouldUseLogValueScale() const = 0; 00109 00114 bool isLocalPeak(int x, int y) { 00115 float value = getValueAt(x, y); 00116 if (y > 0 && value < getValueAt(x, y - 1)) return false; 00117 if (y < getHeight() - 1 && value < getValueAt(x, y + 1)) return false; 00118 return true; 00119 } 00120 00125 bool isOverThreshold(int x, int y, float threshold) { 00126 return getValueAt(x, y) > threshold; 00127 } 00128 00129 QString getTypeName() const { return tr("Dense 3-D"); } 00130 00131 virtual int getCompletion() const = 0; 00132 00133 /* 00134 TabularModel methods. 00135 This class is non-editable -- subclasses may be editable. 00136 Row and column are transposed for the tabular view (which is 00137 "on its side"). 00138 */ 00139 00140 virtual int getRowCount() const { return getWidth(); } 00141 virtual int getColumnCount() const { return getHeight() + 2; } 00142 00143 virtual QString getHeading(int column) const 00144 { 00145 switch (column) { 00146 case 0: return tr("Time"); 00147 case 1: return tr("Frame"); 00148 default: return getBinName(column - 2); 00149 } 00150 } 00151 00152 virtual QVariant getData(int row, int column, int) const 00153 { 00154 switch (column) { 00155 case 0: { 00156 RealTime rt = RealTime::frame2RealTime(row * getResolution(), 00157 getSampleRate()); 00158 return rt.toText().c_str(); 00159 } 00160 case 1: 00161 return int(row * getResolution()); 00162 default: 00163 return getValueAt(row, column - 2); 00164 } 00165 } 00166 00167 virtual bool isColumnTimeValue(int col) const { 00168 return col < 2; 00169 } 00170 virtual SortType getSortType(int) const { 00171 return SortNumeric; 00172 } 00173 00174 virtual long getFrameForRow(int row) const { 00175 return row * getSampleRate(); 00176 } 00177 virtual int getRowForFrame(long frame) const { 00178 return frame / getSampleRate(); 00179 } 00180 00181 protected: 00182 DenseThreeDimensionalModel() { } 00183 }; 00184 00185 #endif