Chris@297
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@297
|
2
|
Chris@297
|
3 /*
|
Chris@297
|
4 Sonic Visualiser
|
Chris@297
|
5 An audio file viewer and annotation editor.
|
Chris@297
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@297
|
7 This file copyright 2007 QMUL.
|
Chris@297
|
8
|
Chris@297
|
9 This program is free software; you can redistribute it and/or
|
Chris@297
|
10 modify it under the terms of the GNU General Public License as
|
Chris@297
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@297
|
12 License, or (at your option) any later version. See the file
|
Chris@297
|
13 COPYING included with this distribution for more information.
|
Chris@297
|
14 */
|
Chris@297
|
15
|
Chris@297
|
16 #include "AggregateWaveModel.h"
|
Chris@297
|
17
|
Chris@297
|
18 #include <iostream>
|
Chris@297
|
19
|
Chris@314
|
20 #include <QTextStream>
|
Chris@314
|
21
|
Chris@1096
|
22 using namespace std;
|
Chris@1096
|
23
|
Chris@1556
|
24 //#define DEBUG_AGGREGATE_WAVE_FILE_MODEL 1
|
Chris@1556
|
25
|
Chris@297
|
26 PowerOfSqrtTwoZoomConstraint
|
Chris@297
|
27 AggregateWaveModel::m_zoomConstraint;
|
Chris@297
|
28
|
Chris@297
|
29 AggregateWaveModel::AggregateWaveModel(ChannelSpecList channelSpecs) :
|
Chris@1389
|
30 m_components(channelSpecs),
|
Chris@1389
|
31 m_invalidated(false)
|
Chris@297
|
32 {
|
Chris@297
|
33 for (ChannelSpecList::const_iterator i = channelSpecs.begin();
|
Chris@297
|
34 i != channelSpecs.end(); ++i) {
|
Chris@1389
|
35
|
Chris@1389
|
36 connect(i->model, SIGNAL(aboutToBeDeleted()),
|
Chris@1389
|
37 this, SLOT(componentModelAboutToBeDeleted()));
|
Chris@1389
|
38
|
Chris@297
|
39 if (i->model->getSampleRate() !=
|
Chris@297
|
40 channelSpecs.begin()->model->getSampleRate()) {
|
Chris@690
|
41 SVDEBUG << "AggregateWaveModel::AggregateWaveModel: WARNING: Component models do not all have the same sample rate" << endl;
|
Chris@297
|
42 break;
|
Chris@297
|
43 }
|
Chris@297
|
44 }
|
Chris@297
|
45 }
|
Chris@297
|
46
|
Chris@297
|
47 AggregateWaveModel::~AggregateWaveModel()
|
Chris@297
|
48 {
|
Chris@1686
|
49 SVDEBUG << "AggregateWaveModel::~AggregateWaveModel" << endl;
|
Chris@297
|
50 }
|
Chris@297
|
51
|
Chris@1389
|
52 void
|
Chris@1389
|
53 AggregateWaveModel::componentModelAboutToBeDeleted()
|
Chris@1389
|
54 {
|
Chris@1389
|
55 SVDEBUG << "AggregateWaveModel::componentModelAboutToBeDeleted: invalidating"
|
Chris@1389
|
56 << endl;
|
Chris@1389
|
57 m_components.clear();
|
Chris@1389
|
58 m_invalidated = true;
|
Chris@1390
|
59 emit modelInvalidated();
|
Chris@1389
|
60 }
|
Chris@1389
|
61
|
Chris@297
|
62 bool
|
Chris@297
|
63 AggregateWaveModel::isOK() const
|
Chris@297
|
64 {
|
Chris@1686
|
65 if (m_invalidated || m_components.empty()) {
|
Chris@1389
|
66 return false;
|
Chris@1389
|
67 }
|
Chris@297
|
68 for (ChannelSpecList::const_iterator i = m_components.begin();
|
Chris@297
|
69 i != m_components.end(); ++i) {
|
Chris@1389
|
70 if (!i->model->isOK()) {
|
Chris@1389
|
71 return false;
|
Chris@1389
|
72 }
|
Chris@297
|
73 }
|
Chris@297
|
74 return true;
|
Chris@297
|
75 }
|
Chris@297
|
76
|
Chris@297
|
77 bool
|
Chris@297
|
78 AggregateWaveModel::isReady(int *completion) const
|
Chris@297
|
79 {
|
Chris@297
|
80 if (completion) *completion = 100;
|
Chris@1389
|
81
|
Chris@297
|
82 bool ready = true;
|
Chris@297
|
83 for (ChannelSpecList::const_iterator i = m_components.begin();
|
Chris@297
|
84 i != m_components.end(); ++i) {
|
Chris@297
|
85 int completionHere = 100;
|
Chris@1556
|
86 if (!i->model->isReady(&completionHere)) {
|
Chris@1556
|
87 ready = false;
|
Chris@1556
|
88 }
|
Chris@297
|
89 if (completion && completionHere < *completion) {
|
Chris@297
|
90 *completion = completionHere;
|
Chris@297
|
91 }
|
Chris@297
|
92 }
|
Chris@1556
|
93
|
Chris@1556
|
94 #ifdef DEBUG_AGGREGATE_WAVE_FILE_MODEL
|
Chris@1556
|
95 SVDEBUG << "AggregateWaveModel(" << objectName()
|
Chris@1556
|
96 << ")::isReady: returning " << ready << endl;
|
Chris@1556
|
97 #endif
|
Chris@1556
|
98
|
Chris@297
|
99 return ready;
|
Chris@297
|
100 }
|
Chris@297
|
101
|
Chris@1038
|
102 sv_frame_t
|
Chris@297
|
103 AggregateWaveModel::getFrameCount() const
|
Chris@297
|
104 {
|
Chris@1038
|
105 sv_frame_t count = 0;
|
Chris@297
|
106 for (ChannelSpecList::const_iterator i = m_components.begin();
|
Chris@297
|
107 i != m_components.end(); ++i) {
|
Chris@1389
|
108 sv_frame_t thisCount =
|
Chris@1389
|
109 i->model->getEndFrame() - i->model->getStartFrame();
|
Chris@297
|
110 if (thisCount > count) count = thisCount;
|
Chris@297
|
111 }
|
Chris@297
|
112 return count;
|
Chris@297
|
113 }
|
Chris@297
|
114
|
Chris@929
|
115 int
|
Chris@297
|
116 AggregateWaveModel::getChannelCount() const
|
Chris@297
|
117 {
|
Chris@1038
|
118 return int(m_components.size());
|
Chris@297
|
119 }
|
Chris@297
|
120
|
Chris@1040
|
121 sv_samplerate_t
|
Chris@297
|
122 AggregateWaveModel::getSampleRate() const
|
Chris@297
|
123 {
|
Chris@1686
|
124 if (m_invalidated || m_components.empty()) return 0;
|
Chris@297
|
125 return m_components.begin()->model->getSampleRate();
|
Chris@297
|
126 }
|
Chris@297
|
127
|
Chris@1326
|
128 floatvec_t
|
Chris@1096
|
129 AggregateWaveModel::getData(int channel, sv_frame_t start, sv_frame_t count) const
|
Chris@297
|
130 {
|
Chris@1686
|
131 if (m_invalidated || m_components.empty()) return {};
|
Chris@1686
|
132
|
Chris@297
|
133 int ch0 = channel, ch1 = channel;
|
Chris@297
|
134 if (channel == -1) {
|
Chris@297
|
135 ch0 = 0;
|
Chris@297
|
136 ch1 = getChannelCount()-1;
|
Chris@297
|
137 }
|
Chris@297
|
138
|
Chris@1326
|
139 floatvec_t result(count, 0.f);
|
Chris@1038
|
140 sv_frame_t longest = 0;
|
Chris@1008
|
141
|
Chris@297
|
142 for (int c = ch0; c <= ch1; ++c) {
|
Chris@1096
|
143
|
Chris@1096
|
144 auto here = m_components[c].model->getData(m_components[c].channel,
|
Chris@1096
|
145 start, count);
|
Chris@1100
|
146 if (sv_frame_t(here.size()) > longest) {
|
Chris@1100
|
147 longest = sv_frame_t(here.size());
|
Chris@1008
|
148 }
|
Chris@1096
|
149 for (sv_frame_t i = 0; in_range_for(here, i); ++i) {
|
Chris@1096
|
150 result[i] += here[i];
|
Chris@297
|
151 }
|
Chris@297
|
152 }
|
Chris@297
|
153
|
Chris@1096
|
154 result.resize(longest);
|
Chris@1096
|
155 return result;
|
Chris@297
|
156 }
|
Chris@363
|
157
|
Chris@1326
|
158 vector<floatvec_t>
|
Chris@1086
|
159 AggregateWaveModel::getMultiChannelData(int fromchannel, int tochannel,
|
Chris@1096
|
160 sv_frame_t start, sv_frame_t count) const
|
Chris@363
|
161 {
|
Chris@1038
|
162 sv_frame_t min = count;
|
Chris@363
|
163
|
Chris@1326
|
164 vector<floatvec_t> result;
|
Chris@1096
|
165
|
Chris@929
|
166 for (int c = fromchannel; c <= tochannel; ++c) {
|
Chris@1096
|
167 auto here = getData(c, start, count);
|
Chris@1100
|
168 if (sv_frame_t(here.size()) < min) {
|
Chris@1100
|
169 min = sv_frame_t(here.size());
|
Chris@1100
|
170 }
|
Chris@1096
|
171 result.push_back(here);
|
Chris@1096
|
172 }
|
Chris@1096
|
173
|
Chris@1096
|
174 if (min < count) {
|
Chris@1096
|
175 for (auto &v : result) v.resize(min);
|
Chris@363
|
176 }
|
Chris@363
|
177
|
Chris@1096
|
178 return result;
|
Chris@363
|
179 }
|
Chris@377
|
180
|
Chris@929
|
181 int
|
Chris@929
|
182 AggregateWaveModel::getSummaryBlockSize(int desired) const
|
Chris@377
|
183 {
|
Chris@377
|
184 //!!! complete
|
Chris@377
|
185 return desired;
|
Chris@377
|
186 }
|
Chris@297
|
187
|
Chris@297
|
188 void
|
Chris@1038
|
189 AggregateWaveModel::getSummaries(int, sv_frame_t, sv_frame_t,
|
Chris@929
|
190 RangeBlock &, int &) const
|
Chris@297
|
191 {
|
Chris@297
|
192 //!!! complete
|
Chris@297
|
193 }
|
Chris@297
|
194
|
Chris@297
|
195 AggregateWaveModel::Range
|
Chris@1038
|
196 AggregateWaveModel::getSummary(int, sv_frame_t, sv_frame_t) const
|
Chris@297
|
197 {
|
Chris@297
|
198 //!!! complete
|
Chris@297
|
199 return Range();
|
Chris@297
|
200 }
|
Chris@297
|
201
|
Chris@929
|
202 int
|
Chris@297
|
203 AggregateWaveModel::getComponentCount() const
|
Chris@297
|
204 {
|
Chris@1038
|
205 return int(m_components.size());
|
Chris@297
|
206 }
|
Chris@297
|
207
|
Chris@297
|
208 AggregateWaveModel::ModelChannelSpec
|
Chris@929
|
209 AggregateWaveModel::getComponent(int c) const
|
Chris@297
|
210 {
|
Chris@297
|
211 return m_components[c];
|
Chris@297
|
212 }
|
Chris@297
|
213
|
Chris@297
|
214 void
|
Chris@297
|
215 AggregateWaveModel::componentModelChanged()
|
Chris@297
|
216 {
|
Chris@297
|
217 emit modelChanged();
|
Chris@297
|
218 }
|
Chris@297
|
219
|
Chris@297
|
220 void
|
Chris@1038
|
221 AggregateWaveModel::componentModelChangedWithin(sv_frame_t start, sv_frame_t end)
|
Chris@297
|
222 {
|
Chris@947
|
223 emit modelChangedWithin(start, end);
|
Chris@297
|
224 }
|
Chris@297
|
225
|
Chris@297
|
226 void
|
Chris@297
|
227 AggregateWaveModel::componentModelCompletionChanged()
|
Chris@297
|
228 {
|
Chris@297
|
229 emit completionChanged();
|
Chris@297
|
230 }
|
Chris@297
|
231
|
Chris@297
|
232 void
|
Chris@1391
|
233 AggregateWaveModel::toXml(QTextStream &out,
|
Chris@1391
|
234 QString indent,
|
Chris@1391
|
235 QString extraAttributes) const
|
Chris@297
|
236 {
|
Chris@1391
|
237 QStringList componentStrings;
|
Chris@1391
|
238 for (const auto &c: m_components) {
|
Chris@1677
|
239 componentStrings.push_back(QString("%1").arg(c.model->getExportId()));
|
Chris@1391
|
240 }
|
Chris@1391
|
241 Model::toXml(out, indent,
|
Chris@1391
|
242 QString("type=\"aggregatewave\" components=\"%1\" %2")
|
Chris@1391
|
243 .arg(componentStrings.join(","))
|
Chris@1391
|
244 .arg(extraAttributes));
|
Chris@297
|
245 }
|
Chris@297
|
246
|