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 _EDITABLE_DENSE_THREE_DIMENSIONAL_MODEL_H_ 00017 #define _EDITABLE_DENSE_THREE_DIMENSIONAL_MODEL_H_ 00018 00019 #include "DenseThreeDimensionalModel.h" 00020 00021 #include <QReadWriteLock> 00022 00023 #include <vector> 00024 00025 class EditableDenseThreeDimensionalModel : public DenseThreeDimensionalModel 00026 { 00027 Q_OBJECT 00028 00029 public: 00030 00031 // EditableDenseThreeDimensionalModel supports a basic compression 00032 // method that reduces the size of multirate data (e.g. wavelet 00033 // transform outputs) that are stored as plain 3d grids by about 00034 // 60% or thereabouts. However, it can only be used for models 00035 // whose columns are set in order from 0 and never subsequently 00036 // changed. If the model is going to be actually edited, it must 00037 // have NoCompression. 00038 00039 enum CompressionType 00040 { 00041 NoCompression, 00042 BasicMultirateCompression 00043 }; 00044 00045 EditableDenseThreeDimensionalModel(int sampleRate, 00046 int resolution, 00047 int yBinCount, 00048 CompressionType compression, 00049 bool notifyOnAdd = true); 00050 00051 virtual bool isOK() const; 00052 00053 virtual int getSampleRate() const; 00054 virtual int getStartFrame() const; 00055 virtual int getEndFrame() const; 00056 00057 virtual Model *clone() const; 00058 00059 00063 virtual void setStartFrame(int); 00064 00068 virtual int getResolution() const; 00069 00073 virtual void setResolution(int sz); 00074 00078 virtual int getWidth() const; 00079 00083 virtual int getHeight() const; 00084 00088 virtual void setHeight(int sz); 00089 00093 virtual float getMinimumLevel() const; 00094 00098 virtual void setMinimumLevel(float sz); 00099 00103 virtual float getMaximumLevel() const; 00104 00108 virtual void setMaximumLevel(float sz); 00109 00113 virtual bool isColumnAvailable(int x) const { return x < getWidth(); } 00114 00118 virtual Column getColumn(int x) const; 00119 00123 virtual float getValueAt(int x, int n) const; 00124 00128 virtual void setColumn(int x, const Column &values); 00129 00134 virtual QString getBinName(int n) const; 00135 00139 virtual void setBinName(int n, QString); 00140 00144 virtual void setBinNames(std::vector<QString> names); 00145 00152 virtual bool hasBinValues() const; 00153 00159 virtual float getBinValue(int n) const; 00160 00166 virtual void setBinValues(std::vector<float> values); 00167 00172 virtual QString getBinValueUnit() const; 00173 00178 virtual void setBinValueUnit(QString unit); 00179 00185 bool shouldUseLogValueScale() const; 00186 00187 virtual void setCompletion(int completion, bool update = true); 00188 virtual int getCompletion() const { return m_completion; } 00189 00190 QString getTypeName() const { return tr("Editable Dense 3-D"); } 00191 00192 virtual QString toDelimitedDataString(QString delimiter) const; 00193 virtual QString toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const; 00194 00195 virtual void toXml(QTextStream &out, 00196 QString indent = "", 00197 QString extraAttributes = "") const; 00198 00199 protected: 00200 typedef QVector<Column> ValueMatrix; 00201 ValueMatrix m_data; 00202 00203 // m_trunc is used for simple compression. If at least the top N 00204 // elements of column x (for N = some proportion of the column 00205 // height) are equal to those of an earlier column x', then 00206 // m_trunc[x] will contain x-x' and column x will be truncated so 00207 // as to remove the duplicate elements. If the equal elements are 00208 // at the bottom, then m_trunc[x] will contain x'-x (a negative 00209 // value). If m_trunc[x] is 0 then the whole of column x is 00210 // stored. 00211 std::vector<signed char> m_trunc; 00212 void truncateAndStore(int index, const Column & values); 00213 Column expandAndRetrieve(int index) const; 00214 00215 std::vector<QString> m_binNames; 00216 std::vector<float> m_binValues; 00217 QString m_binValueUnit; 00218 00219 int m_startFrame; 00220 int m_sampleRate; 00221 int m_resolution; 00222 int m_yBinCount; 00223 CompressionType m_compression; 00224 float m_minimum; 00225 float m_maximum; 00226 bool m_haveExtents; 00227 bool m_notifyOnAdd; 00228 long m_sinceLastNotifyMin; 00229 long m_sinceLastNotifyMax; 00230 int m_completion; 00231 00232 mutable QReadWriteLock m_lock; 00233 }; 00234 00235 #endif