svcore  1.9
Dense3DModelPeakCache.cpp
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 #include "Dense3DModelPeakCache.h"
17 
18 #include "base/Profiler.h"
19 
21  int columnsPerPeak) :
22  m_source(source),
23  m_resolution(columnsPerPeak)
24 {
25  m_coverage.resize(1); // otherwise it is simply invalid
26 
28  (source->getSampleRate(),
29  getResolution(),
30  source->getHeight(),
32  false);
33 
34  connect(source, SIGNAL(modelChanged()),
35  this, SLOT(sourceModelChanged()));
36  connect(source, SIGNAL(aboutToBeDeleted()),
37  this, SLOT(sourceModelAboutToBeDeleted()));
38 
39 }
40 
42 {
43  delete m_cache;
44 }
45 
46 bool
48 {
49  if (!m_source) return false;
50  if (haveColumn(column)) return true;
51  for (int i = m_resolution; i > 0; ) {
52  --i;
53  if (!m_source->isColumnAvailable(column * m_resolution + i)) {
54  return false;
55  }
56  }
57  return true;
58 }
59 
62 {
63  Profiler profiler("Dense3DModelPeakCache::getColumn");
64  if (!m_source) return Column();
65  if (!haveColumn(column)) fillColumn(column);
66  return m_cache->getColumn(column);
67 }
68 
69 float
70 Dense3DModelPeakCache::getValueAt(int column, int n) const
71 {
72  if (!m_source) return 0.f;
73  if (!haveColumn(column)) fillColumn(column);
74  return m_cache->getValueAt(column, n);
75 }
76 
77 void
79 {
80  if (!m_source) return;
81  if (m_coverage.size() > 0) {
82  // The last peak may have come from an incomplete read, which
83  // may since have been filled, so reset it
85  }
86  m_coverage.resize(getWidth()); // retaining data
87 }
88 
89 void
91 {
92  m_source = 0;
93 }
94 
95 bool
97 {
98  return column < (int)m_coverage.size() && m_coverage.get(column);
99 }
100 
101 void
103 {
104  Profiler profiler("Dense3DModelPeakCache::fillColumn");
105 
106  if (column >= (int)m_coverage.size()) {
107  // see note in sourceModelChanged
108  if (m_coverage.size() > 0) m_coverage.reset(m_coverage.size()-1);
109  m_coverage.resize(column + 1);
110  }
111 
112  Column peak;
113  for (int i = 0; i < int(m_resolution); ++i) {
114  Column here = m_source->getColumn(column * m_resolution + i);
115  if (i == 0) {
116  peak = here;
117  } else {
118  for (int j = 0; j < (int)peak.size() && j < (int)here.size(); ++j) {
119  if (here[j] > peak[j]) peak[j] = here[j];
120  }
121  }
122  }
123 
124  m_cache->setColumn(column, peak);
125  m_coverage.set(column);
126 }
127 
128 
void reset(size_t column)
void aboutToBeDeleted()
Emitted when something notifies this model (through calling aboutToDelete() that it is about to delet...
virtual float getValueAt(int column, int n) const
Get the single data point from the n'th bin of the given column.
DenseThreeDimensionalModel * m_source
size_t size() const
virtual float getValueAt(int x, int n) const
Get a single value, from the n'th bin of the given column.
EditableDenseThreeDimensionalModel * m_cache
void resize(size_t size)
virtual int getWidth() const
Return the number of columns of bins in the model.
bool haveColumn(int column) const
void modelChanged()
Emitted when a model has been edited (or more data retrieved from cache, in the case of a cached mode...
virtual Column getColumn(int x) const
Get the set of bin values at the given column.
virtual int getSampleRate() const =0
Return the frame rate in frames per second.
virtual bool isColumnAvailable(int column) const
Return true if there are data available for the given column.
virtual Column getColumn(int column) const =0
Get data from the given column of bin values.
bool get(size_t column) const
virtual int getResolution() const
Return the number of sample frames covered by each column of bins.
Dense3DModelPeakCache(DenseThreeDimensionalModel *source, int columnsPerPeak)
virtual int getHeight() const =0
Return the number of bins in each column.
virtual Column getColumn(int column) const
Get data from the given column of bin values.
virtual bool isColumnAvailable(int column) const =0
Return true if there are data available for the given column.
void fillColumn(int column) const
void set(size_t column)
virtual void setColumn(int x, const Column &values)
Set the entire set of bin values at the given column.
Profile point instance class.
Definition: Profiler.h:86