Dense3DModelPeakCache.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2009 QMUL.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef DENSE_3D_MODEL_PEAK_CACHE_H
17 #define DENSE_3D_MODEL_PEAK_CACHE_H
18 
21 
32 {
33  Q_OBJECT
34 
35 public:
36  Dense3DModelPeakCache(ModelId source, // a DenseThreeDimensionalModel
37  int columnsPerPeak);
39 
40  bool isOK() const override {
41  auto source = ModelById::get(m_source);
42  return source && source->isOK();
43  }
44 
45  sv_samplerate_t getSampleRate() const override {
46  auto source = ModelById::get(m_source);
47  return source ? source->getSampleRate() : 0;
48  }
49 
50  sv_frame_t getStartFrame() const override {
51  auto source = ModelById::get(m_source);
52  return source ? source->getStartFrame() : 0;
53  }
54 
55  sv_frame_t getTrueEndFrame() const override {
56  auto source = ModelById::get(m_source);
57  return source ? source->getTrueEndFrame() : 0;
58  }
59 
60  int getResolution() const override {
61  auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
62  return source ? source->getResolution() * m_columnsPerPeak : 1;
63  }
64 
65  virtual int getColumnsPerPeak() const {
66  return m_columnsPerPeak;
67  }
68 
69  int getWidth() const override {
70  auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
71  if (!source) return 0;
72  int sourceWidth = source->getWidth();
73  if ((sourceWidth % m_columnsPerPeak) == 0) {
74  return sourceWidth / m_columnsPerPeak;
75  } else {
76  return sourceWidth / m_columnsPerPeak + 1;
77  }
78  }
79 
80  int getHeight() const override {
81  auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
82  return source ? source->getHeight() : 0;
83  }
84 
85  float getMinimumLevel() const override {
86  auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
87  return source ? source->getMinimumLevel() : 0.f;
88  }
89 
90  float getMaximumLevel() const override {
91  auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
92  return source ? source->getMaximumLevel() : 1.f;
93  }
94 
101  Column getColumn(int col) const override;
102 
103  float getValueAt(int col, int n) const override;
104 
105  QString getBinName(int n) const override {
106  auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
107  return source ? source->getBinName(n) : "";
108  }
109 
110  bool shouldUseLogValueScale() const override {
111  auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
112  return source ? source->shouldUseLogValueScale() : false;
113  }
114 
115  QString getTypeName() const override { return tr("Dense 3-D Peak Cache"); }
116 
117  int getCompletion() const override {
118  auto source = ModelById::get(m_source);
119  return source ? source->getCompletion() : 100;
120  }
121 
122  QVector<QString>
124  return {};
125  }
126 
127  QVector<QVector<QString>>
129  return {};
130  }
131 
132 protected slots:
134 
135 private:
138 
139  mutable std::vector<Column> m_cache;
140  mutable std::vector<bool> m_coverage; // bool for space efficiency
141  // (vector of bool is a bitmap)
143 
144  bool haveColumn(int column) const;
145  void fillColumn(int column) const;
146 };
147 
148 
149 #endif
int getResolution() const override
Return the number of sample frames covered by each column of bins.
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
A DenseThreeDimensionalModel that represents a reduction in the time dimension of another DenseThreeD...
QString getTypeName() const override
Return the type of the model.
QVector< QString > getStringExportHeaders(DataExportOptions) const override
Return a label for each column that would be written by toStringExportRows.
int getHeight() const override
Return the number of bins in each column.
QString getBinName(int n) const override
Get the name of a given bin (i.e.
float getValueAt(int col, int n) const override
Get the single data point from the n&#39;th bin of the given column.
int getWidth() const override
Return the number of columns of bins in the model.
std::vector< Column > m_cache
sv_frame_t getStartFrame() const override
Return the first audio frame spanned by the model.
Dense3DModelPeakCache(ModelId source, int columnsPerPeak)
bool shouldUseLogValueScale() const override
Estimate whether a logarithmic scale might be appropriate for the value scale.
sv_samplerate_t getSampleRate() const override
Return the frame rate in frames per second.
float getMinimumLevel() const override
Return the minimum permissible value in each bin.
Column getColumn(int col) const override
Retrieve the peaks column at peak-cache column number col.
QVector< QVector< QString > > toStringExportRows(DataExportOptions, sv_frame_t, sv_frame_t) const override
Emit events starting within the given range as string rows ready for conversion to an e...
sv_frame_t getTrueEndFrame() const override
Return the audio frame at the end of the model.
std::vector< bool > m_coverage
virtual int getColumnsPerPeak() const
bool haveColumn(int column) const
int getCompletion() const override
Return an estimated percentage value showing how far through any background operation used to calcula...
void fillColumn(int column) const
float getMaximumLevel() const override
Return the maximum permissible value in each bin.
Definition: ById.h:115
bool isOK() const override
Return true if the model was constructed successfully.
static std::shared_ptr< Item > get(Id id)
Definition: ById.h:251
int DataExportOptions