comparison data/model/Dense3DModelPeakCache.cpp @ 1739:565575463752 by-id

Some work on models and transformers
author Chris Cannam
date Wed, 26 Jun 2019 14:59:09 +0100
parents 70e172e6cc59
children 6d09d68165a4
comparison
equal deleted inserted replaced
1738:4abc0f08adf9 1739:565575463752
17 17
18 #include "base/Profiler.h" 18 #include "base/Profiler.h"
19 19
20 #include "base/HitCount.h" 20 #include "base/HitCount.h"
21 21
22 Dense3DModelPeakCache::Dense3DModelPeakCache(const DenseThreeDimensionalModel *source, 22 Dense3DModelPeakCache::Dense3DModelPeakCache(ModelId sourceId,
23 int columnsPerPeak) : 23 int columnsPerPeak) :
24 m_source(source), 24 m_source(sourceId),
25 m_columnsPerPeak(columnsPerPeak) 25 m_columnsPerPeak(columnsPerPeak)
26 { 26 {
27 m_cache = new EditableDenseThreeDimensionalModel 27 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
28 (source->getSampleRate(), 28 if (!source) {
29 getResolution(), 29 SVCERR << "WARNING: Dense3DModelPeakCache constructed for unknown or wrong-type source model id " << m_source << endl;
30 source->getHeight(), 30 m_source = {};
31 EditableDenseThreeDimensionalModel::NoCompression, 31 return;
32 false); 32 }
33 33
34 connect(source, SIGNAL(modelChanged()), 34 m_cache.reset(new EditableDenseThreeDimensionalModel
35 (source->getSampleRate(),
36 source->getResolution() * m_columnsPerPeak,
37 source->getHeight(),
38 EditableDenseThreeDimensionalModel::NoCompression,
39 false));
40
41 connect(source.get(), SIGNAL(modelChanged()),
35 this, SLOT(sourceModelChanged())); 42 this, SLOT(sourceModelChanged()));
36 connect(source, SIGNAL(aboutToBeDeleted()),
37 this, SLOT(sourceModelAboutToBeDeleted()));
38 } 43 }
39 44
40 Dense3DModelPeakCache::~Dense3DModelPeakCache() 45 Dense3DModelPeakCache::~Dense3DModelPeakCache()
41 { 46 {
42 if (m_cache) m_cache->aboutToDelete();
43 delete m_cache;
44 } 47 }
45 48
46 Dense3DModelPeakCache::Column 49 Dense3DModelPeakCache::Column
47 Dense3DModelPeakCache::getColumn(int column) const 50 Dense3DModelPeakCache::getColumn(int column) const
48 { 51 {
49 if (!m_source) return Column();
50 if (!haveColumn(column)) fillColumn(column); 52 if (!haveColumn(column)) fillColumn(column);
51 return m_cache->getColumn(column); 53 return m_cache->getColumn(column);
52 } 54 }
53 55
54 float 56 float
55 Dense3DModelPeakCache::getValueAt(int column, int n) const 57 Dense3DModelPeakCache::getValueAt(int column, int n) const
56 { 58 {
57 if (!m_source) return 0.f;
58 if (!haveColumn(column)) fillColumn(column); 59 if (!haveColumn(column)) fillColumn(column);
59 return m_cache->getValueAt(column, n); 60 return m_cache->getValueAt(column, n);
60 } 61 }
61 62
62 void 63 void
63 Dense3DModelPeakCache::sourceModelChanged() 64 Dense3DModelPeakCache::sourceModelChanged()
64 { 65 {
65 if (!m_source) return;
66 if (m_coverage.size() > 0) { 66 if (m_coverage.size() > 0) {
67 // The last peak may have come from an incomplete read, which 67 // The last peak may have come from an incomplete read, which
68 // may since have been filled, so reset it 68 // may since have been filled, so reset it
69 m_coverage[m_coverage.size()-1] = false; 69 m_coverage[m_coverage.size()-1] = false;
70 } 70 }
71 m_coverage.resize(getWidth(), false); // retaining data 71 m_coverage.resize(getWidth(), false); // retaining data
72 }
73
74 void
75 Dense3DModelPeakCache::sourceModelAboutToBeDeleted()
76 {
77 m_source = nullptr;
78 } 72 }
79 73
80 bool 74 bool
81 Dense3DModelPeakCache::haveColumn(int column) const 75 Dense3DModelPeakCache::haveColumn(int column) const
82 { 76 {
102 m_coverage[m_coverage.size()-1] = false; 96 m_coverage[m_coverage.size()-1] = false;
103 } 97 }
104 m_coverage.resize(column + 1, false); 98 m_coverage.resize(column + 1, false);
105 } 99 }
106 100
107 int sourceWidth = m_source->getWidth(); 101 auto source = ModelById::getAs<DenseThreeDimensionalModel>(m_source);
102 if (!source) return;
103
104 int sourceWidth = source->getWidth();
108 105
109 Column peak; 106 Column peak;
110 int n = 0; 107 int n = 0;
111 for (int i = 0; i < m_columnsPerPeak; ++i) { 108 for (int i = 0; i < m_columnsPerPeak; ++i) {
112 109
113 int sourceColumn = column * m_columnsPerPeak + i; 110 int sourceColumn = column * m_columnsPerPeak + i;
114 if (sourceColumn >= sourceWidth) break; 111 if (sourceColumn >= sourceWidth) break;
115 112
116 Column here = m_source->getColumn(sourceColumn); 113 Column here = source->getColumn(sourceColumn);
117 114
118 // cerr << "Dense3DModelPeakCache::fillColumn(" << column << "): source col " 115 // cerr << "Dense3DModelPeakCache::fillColumn(" << column << "): source col "
119 // << sourceColumn << " of " << sourceWidth 116 // << sourceColumn << " of " << sourceWidth
120 // << " returned " << here.size() << " elts" << endl; 117 // << " returned " << here.size() << " elts" << endl;
121 118