annotate data/model/EditableDenseThreeDimensionalModel.h @ 535:3ccf48fb81d6

* make compression optional in editable dense 3d model, and some tweaks
author Chris Cannam
date Fri, 23 Jan 2009 14:00:29 +0000
parents 6038cb6fcd30
children beb51f558e9c
rev   line source
Chris@152 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@152 2
Chris@152 3 /*
Chris@152 4 Sonic Visualiser
Chris@152 5 An audio file viewer and annotation editor.
Chris@152 6 Centre for Digital Music, Queen Mary, University of London.
Chris@202 7 This file copyright 2006 Chris Cannam and QMUL.
Chris@152 8
Chris@152 9 This program is free software; you can redistribute it and/or
Chris@152 10 modify it under the terms of the GNU General Public License as
Chris@152 11 published by the Free Software Foundation; either version 2 of the
Chris@152 12 License, or (at your option) any later version. See the file
Chris@152 13 COPYING included with this distribution for more information.
Chris@152 14 */
Chris@152 15
Chris@152 16 #ifndef _EDITABLE_DENSE_THREE_DIMENSIONAL_MODEL_H_
Chris@152 17 #define _EDITABLE_DENSE_THREE_DIMENSIONAL_MODEL_H_
Chris@152 18
Chris@152 19 #include "DenseThreeDimensionalModel.h"
Chris@152 20
Chris@533 21 #include <vector>
Chris@533 22
Chris@152 23 class EditableDenseThreeDimensionalModel : public DenseThreeDimensionalModel
Chris@152 24 {
Chris@152 25 Q_OBJECT
Chris@152 26
Chris@152 27 public:
Chris@535 28
Chris@535 29 // EditableDenseThreeDimensionalModel supports a basic compression
Chris@535 30 // method that reduces the size of multirate data (e.g. wavelet
Chris@535 31 // transform outputs) that are stored as plain 3d grids by about
Chris@535 32 // 60% or thereabouts. However, it can only be used for models
Chris@535 33 // whose columns are set in order from 0 and never subsequently
Chris@535 34 // changed. If the model is going to be actually edited, it must
Chris@535 35 // have NoCompression.
Chris@535 36
Chris@535 37 enum CompressionType
Chris@535 38 {
Chris@535 39 NoCompression,
Chris@535 40 BasicMultirateCompression
Chris@535 41 };
Chris@535 42
Chris@152 43 EditableDenseThreeDimensionalModel(size_t sampleRate,
Chris@152 44 size_t resolution,
Chris@152 45 size_t yBinCount,
Chris@535 46 CompressionType compression,
Chris@152 47 bool notifyOnAdd = true);
Chris@152 48
Chris@152 49 virtual bool isOK() const;
Chris@152 50
Chris@152 51 virtual size_t getSampleRate() const;
Chris@152 52 virtual size_t getStartFrame() const;
Chris@152 53 virtual size_t getEndFrame() const;
Chris@152 54
Chris@152 55 virtual Model *clone() const;
Chris@152 56
Chris@152 57
Chris@152 58 /**
Chris@152 59 * Return the number of sample frames covered by each set of bins.
Chris@152 60 */
Chris@152 61 virtual size_t getResolution() const;
Chris@152 62
Chris@152 63 /**
Chris@152 64 * Set the number of sample frames covered by each set of bins.
Chris@152 65 */
Chris@152 66 virtual void setResolution(size_t sz);
Chris@152 67
Chris@152 68 /**
Chris@182 69 * Return the number of columns.
Chris@182 70 */
Chris@182 71 virtual size_t getWidth() const;
Chris@182 72
Chris@182 73 /**
Chris@152 74 * Return the number of bins in each set of bins.
Chris@152 75 */
Chris@182 76 virtual size_t getHeight() const;
Chris@152 77
Chris@152 78 /**
Chris@152 79 * Set the number of bins in each set of bins.
Chris@152 80 */
Chris@182 81 virtual void setHeight(size_t sz);
Chris@152 82
Chris@152 83 /**
Chris@152 84 * Return the minimum value of the value in each bin.
Chris@152 85 */
Chris@152 86 virtual float getMinimumLevel() const;
Chris@152 87
Chris@152 88 /**
Chris@152 89 * Set the minimum value of the value in a bin.
Chris@152 90 */
Chris@152 91 virtual void setMinimumLevel(float sz);
Chris@152 92
Chris@152 93 /**
Chris@152 94 * Return the maximum value of the value in each bin.
Chris@152 95 */
Chris@152 96 virtual float getMaximumLevel() const;
Chris@152 97
Chris@152 98 /**
Chris@152 99 * Set the maximum value of the value in a bin.
Chris@152 100 */
Chris@152 101 virtual void setMaximumLevel(float sz);
Chris@152 102
Chris@182 103 /**
Chris@182 104 * Return true if there are data available for the given column.
Chris@182 105 */
Chris@182 106 virtual bool isColumnAvailable(size_t x) const { return x < getWidth(); }
Chris@152 107
Chris@152 108 /**
Chris@182 109 * Get the set of bin values at the given column.
Chris@152 110 */
Chris@533 111 virtual Column getColumn(size_t x) const;
Chris@152 112
Chris@152 113 /**
Chris@182 114 * Get a single value, from the n'th bin of the given column.
Chris@152 115 */
Chris@182 116 virtual float getValueAt(size_t x, size_t n) const;
Chris@152 117
Chris@152 118 /**
Chris@182 119 * Set the entire set of bin values at the given column.
Chris@152 120 */
Chris@182 121 virtual void setColumn(size_t x, const Column &values);
Chris@152 122
Chris@152 123 virtual QString getBinName(size_t n) const;
Chris@152 124 virtual void setBinName(size_t n, QString);
Chris@152 125 virtual void setBinNames(std::vector<QString> names);
Chris@152 126
Chris@478 127 bool shouldUseLogValueScale() const;
Chris@478 128
Chris@333 129 virtual void setCompletion(int completion, bool update = true);
Chris@152 130 virtual int getCompletion() const { return m_completion; }
Chris@152 131
Chris@345 132 QString getTypeName() const { return tr("Editable Dense 3-D"); }
Chris@345 133
Chris@318 134 virtual QString toDelimitedDataString(QString delimiter) const;
Chris@318 135
Chris@152 136 virtual void toXml(QTextStream &out,
Chris@152 137 QString indent = "",
Chris@152 138 QString extraAttributes = "") const;
Chris@152 139
Chris@152 140 protected:
Chris@533 141 typedef QVector<Column> ValueMatrix;
Chris@152 142 ValueMatrix m_data;
Chris@152 143
Chris@535 144 // m_trunc is used for simple compression. If at least the top N
Chris@535 145 // elements of column x (for N = some proportion of the column
Chris@535 146 // height) are equal to those of an earlier column x', then
Chris@535 147 // m_trunc[x] will contain x-x' and column x will be truncated so
Chris@535 148 // as to remove the duplicate elements. If the equal elements are
Chris@535 149 // at the bottom, then m_trunc[x] will contain x'-x (a negative
Chris@535 150 // value). If m_trunc[x] is 0 then the whole of column x is
Chris@535 151 // stored.
Chris@535 152 std::vector<signed char> m_trunc;
Chris@534 153 void truncateAndStore(size_t index, const Column & values);
Chris@534 154 Column expandAndRetrieve(size_t index) const;
Chris@534 155
Chris@152 156 std::vector<QString> m_binNames;
Chris@152 157
Chris@152 158 size_t m_sampleRate;
Chris@152 159 size_t m_resolution;
Chris@152 160 size_t m_yBinCount;
Chris@535 161 CompressionType m_compression;
Chris@152 162 float m_minimum;
Chris@152 163 float m_maximum;
Chris@256 164 bool m_haveExtents;
Chris@152 165 bool m_notifyOnAdd;
Chris@152 166 long m_sinceLastNotifyMin;
Chris@152 167 long m_sinceLastNotifyMax;
Chris@152 168 int m_completion;
Chris@152 169
Chris@152 170 mutable QMutex m_mutex;
Chris@152 171 };
Chris@152 172
Chris@152 173 #endif