Chris@545
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@545
|
2
|
Chris@545
|
3 /*
|
Chris@545
|
4 Sonic Visualiser
|
Chris@545
|
5 An audio file viewer and annotation editor.
|
Chris@545
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@545
|
7 This file copyright 2009 QMUL.
|
Chris@545
|
8
|
Chris@545
|
9 This program is free software; you can redistribute it and/or
|
Chris@545
|
10 modify it under the terms of the GNU General Public License as
|
Chris@545
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@545
|
12 License, or (at your option) any later version. See the file
|
Chris@545
|
13 COPYING included with this distribution for more information.
|
Chris@545
|
14 */
|
Chris@545
|
15
|
Chris@1191
|
16 #ifndef DENSE_3D_MODEL_PEAK_CACHE_H
|
Chris@1191
|
17 #define DENSE_3D_MODEL_PEAK_CACHE_H
|
Chris@545
|
18
|
Chris@545
|
19 #include "DenseThreeDimensionalModel.h"
|
Chris@545
|
20 #include "EditableDenseThreeDimensionalModel.h"
|
Chris@545
|
21
|
Chris@1778
|
22 /**
|
Chris@1778
|
23 * A DenseThreeDimensionalModel that represents a reduction in the
|
Chris@1778
|
24 * time dimension of another DenseThreeDimensionalModel. Each column
|
Chris@1778
|
25 * contains the peak values from a number of consecutive columns in
|
Chris@1778
|
26 * the source. Each column is populated from the source model when
|
Chris@1778
|
27 * first requested, and is returned from cache on subsequent requests.
|
Chris@1778
|
28 *
|
Chris@1778
|
29 * Dense3DModelPeakCache is not thread-safe.
|
Chris@1778
|
30 */
|
Chris@545
|
31 class Dense3DModelPeakCache : public DenseThreeDimensionalModel
|
Chris@545
|
32 {
|
Chris@546
|
33 Q_OBJECT
|
Chris@546
|
34
|
Chris@545
|
35 public:
|
Chris@1739
|
36 Dense3DModelPeakCache(ModelId source, // a DenseThreeDimensionalModel
|
Chris@929
|
37 int columnsPerPeak);
|
Chris@545
|
38 ~Dense3DModelPeakCache();
|
Chris@545
|
39
|
Chris@1580
|
40 bool isOK() const override {
|
Chris@1739
|
41 auto source = ModelById::get(m_source);
|
Chris@1739
|
42 return source && source->isOK();
|
Chris@546
|
43 }
|
Chris@546
|
44
|
Chris@1580
|
45 sv_samplerate_t getSampleRate() const override {
|
Chris@1739
|
46 auto source = ModelById::get(m_source);
|
Chris@1739
|
47 return source ? source->getSampleRate() : 0;
|
Chris@546
|
48 }
|
Chris@546
|
49
|
Chris@1580
|
50 sv_frame_t getStartFrame() const override {
|
Chris@1739
|
51 auto source = ModelById::get(m_source);
|
Chris@1739
|
52 return source ? source->getStartFrame() : 0;
|
Chris@546
|
53 }
|
Chris@546
|
54
|
Chris@1725
|
55 sv_frame_t getTrueEndFrame() const override {
|
Chris@1739
|
56 auto source = ModelById::get(m_source);
|
Chris@1739
|
57 return source ? source->getTrueEndFrame() : 0;
|
Chris@546
|
58 }
|
Chris@546
|
59
|
Chris@1580
|
60 int getResolution() const override {
|
Chris@1739
|
61 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
|
Chris@1739
|
62 return source ? source->getResolution() * m_columnsPerPeak : 1;
|
Chris@545
|
63 }
|
Chris@545
|
64
|
Chris@1190
|
65 virtual int getColumnsPerPeak() const {
|
Chris@1190
|
66 return m_columnsPerPeak;
|
Chris@1190
|
67 }
|
Chris@1190
|
68
|
Chris@1580
|
69 int getWidth() const override {
|
Chris@1739
|
70 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
|
Chris@1739
|
71 if (!source) return 0;
|
Chris@1739
|
72 int sourceWidth = source->getWidth();
|
Chris@1192
|
73 if ((sourceWidth % m_columnsPerPeak) == 0) {
|
Chris@1192
|
74 return sourceWidth / m_columnsPerPeak;
|
Chris@1192
|
75 } else {
|
Chris@1192
|
76 return sourceWidth / m_columnsPerPeak + 1;
|
Chris@1192
|
77 }
|
Chris@545
|
78 }
|
Chris@545
|
79
|
Chris@1580
|
80 int getHeight() const override {
|
Chris@1739
|
81 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
|
Chris@1739
|
82 return source ? source->getHeight() : 0;
|
Chris@545
|
83 }
|
Chris@545
|
84
|
Chris@1580
|
85 float getMinimumLevel() const override {
|
Chris@1739
|
86 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
|
Chris@1739
|
87 return source ? source->getMinimumLevel() : 0.f;
|
Chris@545
|
88 }
|
Chris@545
|
89
|
Chris@1580
|
90 float getMaximumLevel() const override {
|
Chris@1739
|
91 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
|
Chris@1739
|
92 return source ? source->getMaximumLevel() : 1.f;
|
Chris@545
|
93 }
|
Chris@545
|
94
|
Chris@1339
|
95 /**
|
Chris@1339
|
96 * Retrieve the peaks column at peak-cache column number col. This
|
Chris@1339
|
97 * will consist of the peak values in the underlying model from
|
Chris@1339
|
98 * columns (col * getColumnsPerPeak()) to ((col+1) *
|
Chris@1339
|
99 * getColumnsPerPeak() - 1) inclusive.
|
Chris@1339
|
100 */
|
Chris@1580
|
101 Column getColumn(int col) const override;
|
Chris@545
|
102
|
Chris@1580
|
103 float getValueAt(int col, int n) const override;
|
Chris@545
|
104
|
Chris@1580
|
105 QString getBinName(int n) const override {
|
Chris@1739
|
106 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
|
Chris@1739
|
107 return source ? source->getBinName(n) : "";
|
Chris@545
|
108 }
|
Chris@545
|
109
|
Chris@1580
|
110 bool shouldUseLogValueScale() const override {
|
Chris@1739
|
111 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
|
Chris@1739
|
112 return source ? source->shouldUseLogValueScale() : false;
|
Chris@545
|
113 }
|
Chris@545
|
114
|
Chris@1580
|
115 QString getTypeName() const override { return tr("Dense 3-D Peak Cache"); }
|
Chris@545
|
116
|
Chris@1580
|
117 int getCompletion() const override {
|
Chris@1739
|
118 auto source = ModelById::get(m_source);
|
Chris@1739
|
119 return source ? source->getCompletion() : 100;
|
Chris@545
|
120 }
|
Chris@545
|
121
|
Chris@1833
|
122 QVector<QString>
|
Chris@1833
|
123 getStringExportHeaders(DataExportOptions) const override {
|
Chris@1833
|
124 return {};
|
Chris@1815
|
125 }
|
Chris@1833
|
126
|
Chris@1833
|
127 QVector<QVector<QString>>
|
Chris@1833
|
128 toStringExportRows(DataExportOptions, sv_frame_t, sv_frame_t) const override {
|
Chris@1833
|
129 return {};
|
Chris@1679
|
130 }
|
Chris@1679
|
131
|
Chris@545
|
132 protected slots:
|
Chris@1752
|
133 void sourceModelChanged(ModelId);
|
Chris@545
|
134
|
Chris@545
|
135 private:
|
Chris@1739
|
136 ModelId m_source;
|
Chris@1190
|
137 int m_columnsPerPeak;
|
Chris@545
|
138
|
Chris@1837
|
139 mutable std::vector<Column> m_cache;
|
Chris@1778
|
140 mutable std::vector<bool> m_coverage; // bool for space efficiency
|
Chris@1778
|
141 // (vector of bool is a bitmap)
|
Chris@1778
|
142 mutable bool m_finalColumnIncomplete;
|
Chris@1778
|
143
|
Chris@929
|
144 bool haveColumn(int column) const;
|
Chris@929
|
145 void fillColumn(int column) const;
|
Chris@545
|
146 };
|
Chris@545
|
147
|
Chris@545
|
148
|
Chris@545
|
149 #endif
|