comparison data/model/AggregateWaveModel.cpp @ 1732:87b4c596c0ef by-id

Experiment updating AggregateWaveModel
author Chris Cannam
date Fri, 21 Jun 2019 14:35:38 +0100
parents d08b560102a1
children dffc70996f54
comparison
equal deleted inserted replaced
1731:601851995f4b 1732:87b4c596c0ef
25 25
26 PowerOfSqrtTwoZoomConstraint 26 PowerOfSqrtTwoZoomConstraint
27 AggregateWaveModel::m_zoomConstraint; 27 AggregateWaveModel::m_zoomConstraint;
28 28
29 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) : 29 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) :
30 m_components(channelSpecs), 30 m_components(channelSpecs)
31 m_invalidated(false) 31 {
32 { 32 sv_samplerate_t overallRate = 0;
33 for (ChannelSpecList::const_iterator i = channelSpecs.begin(); 33
34 i != channelSpecs.end(); ++i) { 34 for (int channel = 0; in_range_for(m_components, channel); ++channel) {
35 35
36 connect(i->model, SIGNAL(aboutToBeDeleted()), 36 auto model = ModelById::getAs<RangeSummarisableTimeValueModel>
37 this, SLOT(componentModelAboutToBeDeleted())); 37 (m_components[channel].model);
38 38
39 if (i->model->getSampleRate() != 39 if (!model) {
40 channelSpecs.begin()->model->getSampleRate()) { 40 SVCERR << "AggregateWaveModel: WARNING: component for channel "
41 SVDEBUG << "AggregateWaveModel::AggregateWaveModel: WARNING: Component models do not all have the same sample rate" << endl; 41 << channel << " is not found or is of wrong model type"
42 break; 42 << endl;
43 continue;
44 }
45
46 sv_samplerate_t rate = model->getSampleRate();
47
48 if (!rate) {
49 SVCERR << "AggregateWaveModel: WARNING: component for channel "
50 << channel << " reports zero sample rate" << endl;
51
52 } else if (!overallRate) {
53
54 overallRate = rate;
55
56 } else if (rate != overallRate) {
57 SVCERR << "AggregateWaveModel: WARNING: component for channel "
58 << channel << " has different sample rate from earlier "
59 << "channels (has " << rate << ", expected " << overallRate
60 << ")" << endl;
43 } 61 }
44 } 62 }
45 } 63 }
46 64
47 AggregateWaveModel::~AggregateWaveModel() 65 AggregateWaveModel::~AggregateWaveModel()
48 { 66 {
49 SVDEBUG << "AggregateWaveModel::~AggregateWaveModel" << endl; 67 SVDEBUG << "AggregateWaveModel::~AggregateWaveModel" << endl;
50 }
51
52 void
53 AggregateWaveModel::componentModelAboutToBeDeleted()
54 {
55 SVDEBUG << "AggregateWaveModel::componentModelAboutToBeDeleted: invalidating"
56 << endl;
57 m_components.clear();
58 m_invalidated = true;
59 emit modelInvalidated();
60 } 68 }
61 69
62 bool 70 bool
63 AggregateWaveModel::isOK() const 71 AggregateWaveModel::isOK() const
64 { 72 {
65 if (m_invalidated || m_components.empty()) { 73 if (m_components.empty()) {
66 return false; 74 return false;
67 } 75 }
68 for (ChannelSpecList::const_iterator i = m_components.begin(); 76 for (const auto &c: m_components) {
69 i != m_components.end(); ++i) { 77 auto model = ModelById::get(c.model);
70 if (!i->model->isOK()) { 78 if (!model || !model->isOK()) {
71 return false; 79 return false;
72 } 80 }
73 } 81 }
74 return true; 82 return true;
75 } 83 }
78 AggregateWaveModel::isReady(int *completion) const 86 AggregateWaveModel::isReady(int *completion) const
79 { 87 {
80 if (completion) *completion = 100; 88 if (completion) *completion = 100;
81 89
82 bool ready = true; 90 bool ready = true;
83 for (ChannelSpecList::const_iterator i = m_components.begin(); 91 for (auto c: m_components) {
84 i != m_components.end(); ++i) {
85 int completionHere = 100; 92 int completionHere = 100;
86 if (!i->model->isReady(&completionHere)) { 93 auto model = ModelById::get(c.model);
94 if (!model) continue;
95 if (!model->isReady(&completionHere)) {
87 ready = false; 96 ready = false;
88 } 97 }
89 if (completion && completionHere < *completion) { 98 if (completion && completionHere < *completion) {
90 *completion = completionHere; 99 *completion = completionHere;
91 } 100 }
101 110
102 sv_frame_t 111 sv_frame_t
103 AggregateWaveModel::getFrameCount() const 112 AggregateWaveModel::getFrameCount() const
104 { 113 {
105 sv_frame_t count = 0; 114 sv_frame_t count = 0;
106 for (ChannelSpecList::const_iterator i = m_components.begin(); 115 for (auto c: m_components) {
107 i != m_components.end(); ++i) { 116 auto model = ModelById::get(c.model);
108 sv_frame_t thisCount = 117 if (!model) continue;
109 i->model->getEndFrame() - i->model->getStartFrame(); 118 sv_frame_t thisCount = model->getEndFrame() - model->getStartFrame();
110 if (thisCount > count) count = thisCount; 119 if (thisCount > count) count = thisCount;
111 } 120 }
112 return count; 121 return count;
113 } 122 }
114 123
119 } 128 }
120 129
121 sv_samplerate_t 130 sv_samplerate_t
122 AggregateWaveModel::getSampleRate() const 131 AggregateWaveModel::getSampleRate() const
123 { 132 {
124 if (m_invalidated || m_components.empty()) return 0; 133 if (m_components.empty()) return 0;
125 return m_components.begin()->model->getSampleRate(); 134 auto model = ModelById::get(m_components.begin()->model);
135 if (!model) return 0;
136 return model->getSampleRate();
126 } 137 }
127 138
128 floatvec_t 139 floatvec_t
129 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const 140 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
130 { 141 {
131 if (m_invalidated || m_components.empty()) return {}; 142 if (m_components.empty()) return {};
132 143
133 int ch0 = channel, ch1 = channel; 144 int ch0 = channel, ch1 = channel;
134 if (channel == -1) { 145 if (channel == -1) {
135 ch0 = 0; 146 ch0 = 0;
136 ch1 = getChannelCount()-1; 147 ch1 = getChannelCount()-1;
148 } else if (!in_range_for(m_components, channel)) {
149 return {};
137 } 150 }
138 151
139 floatvec_t result(count, 0.f); 152 floatvec_t result(count, 0.f);
140 sv_frame_t longest = 0; 153 sv_frame_t longest = 0;
141 154
142 for (int c = ch0; c <= ch1; ++c) { 155 for (int c = ch0; c <= ch1; ++c) {
143 156
144 auto here = m_components[c].model->getData(m_components[c].channel, 157 auto model = ModelById::getAs<RangeSummarisableTimeValueModel>
145 start, count); 158 (m_components[c].model);
159 if (!model) continue;
160
161 auto here = model->getData(m_components[c].channel, start, count);
146 if (sv_frame_t(here.size()) > longest) { 162 if (sv_frame_t(here.size()) > longest) {
147 longest = sv_frame_t(here.size()); 163 longest = sv_frame_t(here.size());
148 } 164 }
149 for (sv_frame_t i = 0; in_range_for(here, i); ++i) { 165 for (sv_frame_t i = 0; in_range_for(here, i); ++i) {
150 result[i] += here[i]; 166 result[i] += here[i];
234 QString indent, 250 QString indent,
235 QString extraAttributes) const 251 QString extraAttributes) const
236 { 252 {
237 QStringList componentStrings; 253 QStringList componentStrings;
238 for (const auto &c: m_components) { 254 for (const auto &c: m_components) {
239 componentStrings.push_back(QString("%1").arg(c.model->getExportId())); 255 auto model = ModelById::get(c.model);
256 if (!model) continue;
257 componentStrings.push_back(QString("%1").arg(model->getExportId()));
240 } 258 }
241 Model::toXml(out, indent, 259 Model::toXml(out, indent,
242 QString("type=\"aggregatewave\" components=\"%1\" %2") 260 QString("type=\"aggregatewave\" components=\"%1\" %2")
243 .arg(componentStrings.join(",")) 261 .arg(componentStrings.join(","))
244 .arg(extraAttributes)); 262 .arg(extraAttributes));