Chris@45
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@45
|
2
|
Chris@45
|
3 /*
|
Chris@45
|
4 Sonic Visualiser
|
Chris@45
|
5 An audio file viewer and annotation editor.
|
Chris@45
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@45
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@45
|
8
|
Chris@45
|
9 This program is free software; you can redistribute it and/or
|
Chris@45
|
10 modify it under the terms of the GNU General Public License as
|
Chris@45
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@45
|
12 License, or (at your option) any later version. See the file
|
Chris@45
|
13 COPYING included with this distribution for more information.
|
Chris@45
|
14 */
|
Chris@45
|
15
|
Chris@45
|
16 #include "SVFileReader.h"
|
Chris@45
|
17
|
Chris@45
|
18 #include "layer/Layer.h"
|
Chris@45
|
19 #include "view/View.h"
|
Chris@45
|
20 #include "base/PlayParameters.h"
|
Chris@45
|
21 #include "base/PlayParameterRepository.h"
|
Chris@116
|
22 #include "base/Preferences.h"
|
Chris@45
|
23
|
Chris@45
|
24 #include "data/fileio/AudioFileReaderFactory.h"
|
Chris@45
|
25 #include "data/fileio/FileSource.h"
|
Chris@45
|
26
|
Chris@170
|
27 #include "data/fileio/FileFinder.h"
|
Chris@109
|
28
|
Chris@479
|
29 #include "data/model/ReadOnlyWaveFileModel.h"
|
Chris@45
|
30 #include "data/model/EditableDenseThreeDimensionalModel.h"
|
Chris@45
|
31 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@45
|
32 #include "data/model/SparseTimeValueModel.h"
|
Chris@45
|
33 #include "data/model/NoteModel.h"
|
Chris@137
|
34 #include "data/model/RegionModel.h"
|
Chris@45
|
35 #include "data/model/TextModel.h"
|
Chris@45
|
36 #include "data/model/ImageModel.h"
|
Chris@111
|
37 #include "data/model/AlignmentModel.h"
|
Chris@629
|
38 #include "data/model/AggregateWaveModel.h"
|
Chris@45
|
39
|
Chris@106
|
40 #include "transform/TransformFactory.h"
|
Chris@72
|
41
|
Chris@45
|
42 #include "view/Pane.h"
|
Chris@45
|
43
|
Chris@109
|
44 #include "widgets/ProgressDialog.h"
|
Chris@109
|
45
|
Chris@45
|
46 #include "Document.h"
|
Chris@45
|
47
|
Chris@45
|
48 #include <QString>
|
Chris@45
|
49 #include <QMessageBox>
|
Chris@45
|
50 #include <QFileDialog>
|
Chris@45
|
51
|
Chris@45
|
52 #include <iostream>
|
Chris@45
|
53
|
Chris@45
|
54 SVFileReader::SVFileReader(Document *document,
|
Chris@595
|
55 SVFileReaderPaneCallback &callback,
|
Chris@45
|
56 QString location) :
|
Chris@45
|
57 m_document(document),
|
Chris@45
|
58 m_paneCallback(callback),
|
Chris@45
|
59 m_location(location),
|
Chris@636
|
60 m_currentPane(nullptr),
|
Chris@685
|
61 m_currentDataset(XmlExportable::NO_ID),
|
Chris@636
|
62 m_currentLayer(nullptr),
|
Chris@685
|
63 m_pendingDerivedModel(XmlExportable::NO_ID),
|
Chris@636
|
64 m_currentPlayParameters(nullptr),
|
Chris@410
|
65 m_currentTransformChannel(0),
|
Chris@410
|
66 m_currentTransformIsNewStyle(true),
|
Chris@45
|
67 m_datasetSeparator(" "),
|
Chris@45
|
68 m_inRow(false),
|
Chris@45
|
69 m_inLayer(false),
|
Chris@45
|
70 m_inView(false),
|
Chris@410
|
71 m_inData(false),
|
Chris@410
|
72 m_inSelections(false),
|
Chris@45
|
73 m_rowNumber(0),
|
Chris@45
|
74 m_ok(false)
|
Chris@45
|
75 {
|
Chris@45
|
76 }
|
Chris@45
|
77
|
Chris@45
|
78 void
|
Chris@45
|
79 SVFileReader::parse(const QString &xmlData)
|
Chris@45
|
80 {
|
Chris@45
|
81 QXmlInputSource inputSource;
|
Chris@45
|
82 inputSource.setData(xmlData);
|
Chris@45
|
83 parse(inputSource);
|
Chris@45
|
84 }
|
Chris@45
|
85
|
Chris@45
|
86 void
|
Chris@45
|
87 SVFileReader::parse(QXmlInputSource &inputSource)
|
Chris@45
|
88 {
|
Chris@45
|
89 QXmlSimpleReader reader;
|
Chris@45
|
90 reader.setContentHandler(this);
|
Chris@45
|
91 reader.setErrorHandler(this);
|
Chris@45
|
92 m_ok = reader.parse(inputSource);
|
Chris@45
|
93 }
|
Chris@45
|
94
|
Chris@45
|
95 bool
|
Chris@45
|
96 SVFileReader::isOK()
|
Chris@45
|
97 {
|
Chris@45
|
98 return m_ok;
|
Chris@45
|
99 }
|
Chris@595
|
100
|
Chris@45
|
101 SVFileReader::~SVFileReader()
|
Chris@45
|
102 {
|
Chris@45
|
103 if (!m_awaitingDatasets.empty()) {
|
Chris@601
|
104 SVCERR << "WARNING: SV-XML: File ended with "
|
Chris@595
|
105 << m_awaitingDatasets.size() << " unfilled model dataset(s)"
|
Chris@595
|
106 << endl;
|
Chris@45
|
107 }
|
Chris@45
|
108
|
Chris@685
|
109 std::set<ModelId> unaddedModels;
|
Chris@45
|
110
|
Chris@685
|
111 for (auto i: m_models) {
|
Chris@685
|
112 if (m_addedModels.find(i.second) == m_addedModels.end()) {
|
Chris@685
|
113 unaddedModels.insert(i.second);
|
Chris@595
|
114 }
|
Chris@45
|
115 }
|
Chris@45
|
116
|
Chris@45
|
117 if (!unaddedModels.empty()) {
|
Chris@601
|
118 SVCERR << "WARNING: SV-XML: File contained "
|
Chris@685
|
119 << unaddedModels.size() << " unused models"
|
Chris@685
|
120 << endl;
|
Chris@685
|
121 for (auto m: unaddedModels) {
|
Chris@685
|
122 ModelById::release(m);
|
Chris@595
|
123 }
|
Chris@685
|
124 }
|
Chris@685
|
125
|
Chris@685
|
126 if (!m_paths.empty()) {
|
Chris@685
|
127 SVCERR << "WARNING: SV-XML: File contained "
|
Chris@685
|
128 << m_paths.size() << " unused paths"
|
Chris@685
|
129 << endl;
|
Chris@685
|
130 for (auto p: m_paths) {
|
Chris@685
|
131 delete p.second;
|
Chris@685
|
132 }
|
Chris@685
|
133 }
|
Chris@45
|
134 }
|
Chris@45
|
135
|
Chris@45
|
136 bool
|
Chris@45
|
137 SVFileReader::startElement(const QString &, const QString &,
|
Chris@595
|
138 const QString &qName,
|
Chris@595
|
139 const QXmlAttributes &attributes)
|
Chris@45
|
140 {
|
Chris@45
|
141 QString name = qName.toLower();
|
Chris@45
|
142
|
Chris@45
|
143 bool ok = false;
|
Chris@45
|
144
|
Chris@45
|
145 // Valid element names:
|
Chris@45
|
146 //
|
Chris@45
|
147 // sv
|
Chris@45
|
148 // data
|
Chris@45
|
149 // dataset
|
Chris@45
|
150 // display
|
Chris@45
|
151 // derivation
|
Chris@45
|
152 // playparameters
|
Chris@45
|
153 // layer
|
Chris@45
|
154 // model
|
Chris@45
|
155 // point
|
Chris@45
|
156 // row
|
Chris@45
|
157 // view
|
Chris@45
|
158 // window
|
Chris@72
|
159 // plugin
|
Chris@72
|
160 // transform
|
Chris@72
|
161 // selections
|
Chris@72
|
162 // selection
|
Chris@72
|
163 // measurement
|
Chris@45
|
164
|
Chris@45
|
165 if (name == "sv") {
|
Chris@45
|
166
|
Chris@595
|
167 // nothing needed
|
Chris@595
|
168 ok = true;
|
Chris@45
|
169
|
Chris@45
|
170 } else if (name == "data") {
|
Chris@45
|
171
|
Chris@595
|
172 // nothing needed
|
Chris@595
|
173 m_inData = true;
|
Chris@595
|
174 ok = true;
|
Chris@45
|
175
|
Chris@45
|
176 } else if (name == "display") {
|
Chris@45
|
177
|
Chris@595
|
178 // nothing needed
|
Chris@595
|
179 ok = true;
|
Chris@45
|
180
|
Chris@45
|
181 } else if (name == "window") {
|
Chris@45
|
182
|
Chris@595
|
183 ok = readWindow(attributes);
|
Chris@45
|
184
|
Chris@45
|
185 } else if (name == "model") {
|
Chris@45
|
186
|
Chris@595
|
187 ok = readModel(attributes);
|
Chris@45
|
188
|
Chris@45
|
189 } else if (name == "dataset") {
|
Chris@595
|
190
|
Chris@595
|
191 ok = readDatasetStart(attributes);
|
Chris@45
|
192
|
Chris@45
|
193 } else if (name == "bin") {
|
Chris@595
|
194
|
Chris@595
|
195 ok = addBinToDataset(attributes);
|
Chris@45
|
196
|
Chris@45
|
197 } else if (name == "point") {
|
Chris@595
|
198
|
Chris@595
|
199 ok = addPointToDataset(attributes);
|
Chris@45
|
200
|
Chris@45
|
201 } else if (name == "row") {
|
Chris@45
|
202
|
Chris@595
|
203 ok = addRowToDataset(attributes);
|
Chris@45
|
204
|
Chris@45
|
205 } else if (name == "layer") {
|
Chris@45
|
206
|
Chris@45
|
207 addUnaddedModels(); // all models must be specified before first layer
|
Chris@595
|
208 ok = readLayer(attributes);
|
Chris@45
|
209
|
Chris@45
|
210 } else if (name == "view") {
|
Chris@45
|
211
|
Chris@595
|
212 m_inView = true;
|
Chris@595
|
213 ok = readView(attributes);
|
Chris@45
|
214
|
Chris@45
|
215 } else if (name == "derivation") {
|
Chris@45
|
216
|
Chris@629
|
217 makeAggregateModels(); // must be done before derivations that use them
|
Chris@595
|
218 ok = readDerivation(attributes);
|
Chris@45
|
219
|
Chris@45
|
220 } else if (name == "playparameters") {
|
Chris@45
|
221
|
Chris@45
|
222 ok = readPlayParameters(attributes);
|
Chris@45
|
223
|
Chris@45
|
224 } else if (name == "plugin") {
|
Chris@45
|
225
|
Chris@595
|
226 ok = readPlugin(attributes);
|
Chris@45
|
227
|
Chris@45
|
228 } else if (name == "selections") {
|
Chris@45
|
229
|
Chris@595
|
230 m_inSelections = true;
|
Chris@595
|
231 ok = true;
|
Chris@45
|
232
|
Chris@45
|
233 } else if (name == "selection") {
|
Chris@45
|
234
|
Chris@595
|
235 ok = readSelection(attributes);
|
Chris@45
|
236
|
Chris@45
|
237 } else if (name == "measurement") {
|
Chris@45
|
238
|
Chris@45
|
239 ok = readMeasurement(attributes);
|
Chris@45
|
240
|
Chris@72
|
241 } else if (name == "transform") {
|
Chris@72
|
242
|
Chris@72
|
243 ok = readTransform(attributes);
|
Chris@72
|
244
|
Chris@72
|
245 } else if (name == "parameter") {
|
Chris@72
|
246
|
Chris@72
|
247 ok = readParameter(attributes);
|
Chris@72
|
248
|
Chris@45
|
249 } else {
|
Chris@601
|
250 SVCERR << "WARNING: SV-XML: Unexpected element \""
|
Chris@294
|
251 << name << "\"" << endl;
|
Chris@45
|
252 }
|
Chris@45
|
253
|
Chris@45
|
254 if (!ok) {
|
Chris@601
|
255 SVCERR << "WARNING: SV-XML: Failed to completely process element \""
|
Chris@595
|
256 << name << "\"" << endl;
|
Chris@45
|
257 }
|
Chris@45
|
258
|
Chris@45
|
259 return true;
|
Chris@45
|
260 }
|
Chris@45
|
261
|
Chris@45
|
262 bool
|
Chris@45
|
263 SVFileReader::characters(const QString &text)
|
Chris@45
|
264 {
|
Chris@45
|
265 bool ok = false;
|
Chris@45
|
266
|
Chris@45
|
267 if (m_inRow) {
|
Chris@595
|
268 ok = readRowData(text);
|
Chris@595
|
269 if (!ok) {
|
Chris@601
|
270 SVCERR << "WARNING: SV-XML: Failed to read row data content for row " << m_rowNumber << endl;
|
Chris@595
|
271 }
|
Chris@45
|
272 }
|
Chris@45
|
273
|
Chris@45
|
274 return true;
|
Chris@45
|
275 }
|
Chris@45
|
276
|
Chris@45
|
277 bool
|
Chris@45
|
278 SVFileReader::endElement(const QString &, const QString &,
|
Chris@595
|
279 const QString &qName)
|
Chris@45
|
280 {
|
Chris@45
|
281 QString name = qName.toLower();
|
Chris@45
|
282
|
Chris@45
|
283 if (name == "dataset") {
|
Chris@45
|
284
|
Chris@685
|
285 if (m_currentDataset != XmlExportable::NO_ID) {
|
Chris@595
|
286
|
Chris@595
|
287 bool foundInAwaiting = false;
|
Chris@45
|
288
|
Chris@685
|
289 for (auto i: m_awaitingDatasets) {
|
Chris@685
|
290 if (i.second == m_currentDataset) {
|
Chris@685
|
291 m_awaitingDatasets.erase(i.first);
|
Chris@595
|
292 foundInAwaiting = true;
|
Chris@595
|
293 break;
|
Chris@595
|
294 }
|
Chris@595
|
295 }
|
Chris@45
|
296
|
Chris@595
|
297 if (!foundInAwaiting) {
|
Chris@601
|
298 SVCERR << "WARNING: SV-XML: Dataset precedes model, or no model uses dataset" << endl;
|
Chris@595
|
299 }
|
Chris@595
|
300 }
|
Chris@45
|
301
|
Chris@685
|
302 m_currentDataset = XmlExportable::NO_ID;
|
Chris@45
|
303
|
Chris@45
|
304 } else if (name == "data") {
|
Chris@45
|
305
|
Chris@45
|
306 addUnaddedModels();
|
Chris@595
|
307 m_inData = false;
|
Chris@45
|
308
|
Chris@45
|
309 } else if (name == "derivation") {
|
Chris@45
|
310
|
Chris@685
|
311 if (m_currentDerivedModel.isNone()) {
|
Chris@685
|
312 if (m_pendingDerivedModel == XmlExportable::NO_ID) {
|
Chris@685
|
313 SVCERR << "WARNING: SV-XML: No valid output model id "
|
Chris@685
|
314 << "for derivation" << endl;
|
Chris@685
|
315 } else if (haveModel(m_pendingDerivedModel)) {
|
Chris@601
|
316 SVCERR << "WARNING: SV-XML: Derivation has existing model "
|
Chris@685
|
317 << m_pendingDerivedModel
|
Chris@685
|
318 << " as target, not regenerating" << endl;
|
Chris@45
|
319 } else {
|
Chris@78
|
320 QString message;
|
Chris@685
|
321 m_currentDerivedModel = m_models[m_pendingDerivedModel] =
|
Chris@72
|
322 m_document->addDerivedModel
|
Chris@72
|
323 (m_currentTransform,
|
Chris@72
|
324 ModelTransformer::Input(m_currentTransformSource,
|
Chris@78
|
325 m_currentTransformChannel),
|
Chris@78
|
326 message);
|
Chris@685
|
327 if (m_currentDerivedModel.isNone()) {
|
Chris@79
|
328 emit modelRegenerationFailed(tr("(derived model in SV-XML)"),
|
Chris@79
|
329 m_currentTransform.getIdentifier(),
|
Chris@79
|
330 message);
|
Chris@79
|
331 } else if (message != "") {
|
Chris@79
|
332 emit modelRegenerationWarning(tr("(derived model in SV-XML)"),
|
Chris@79
|
333 m_currentTransform.getIdentifier(),
|
Chris@79
|
334 message);
|
Chris@79
|
335 }
|
Chris@45
|
336 }
|
Chris@45
|
337 } else {
|
Chris@329
|
338 m_document->addAlreadyDerivedModel
|
Chris@72
|
339 (m_currentTransform,
|
Chris@72
|
340 ModelTransformer::Input(m_currentTransformSource,
|
Chris@72
|
341 m_currentTransformChannel),
|
Chris@72
|
342 m_currentDerivedModel);
|
Chris@45
|
343 }
|
Chris@45
|
344
|
Chris@45
|
345 m_addedModels.insert(m_currentDerivedModel);
|
Chris@685
|
346 m_currentDerivedModel = {};
|
Chris@685
|
347 m_pendingDerivedModel = XmlExportable::NO_ID;
|
Chris@685
|
348 m_currentTransformSource = {};
|
Chris@72
|
349 m_currentTransform = Transform();
|
Chris@72
|
350 m_currentTransformChannel = -1;
|
Chris@45
|
351
|
Chris@45
|
352 } else if (name == "row") {
|
Chris@595
|
353 m_inRow = false;
|
Chris@45
|
354 } else if (name == "layer") {
|
Chris@45
|
355 m_inLayer = false;
|
Chris@45
|
356 } else if (name == "view") {
|
Chris@595
|
357 m_inView = false;
|
Chris@45
|
358 } else if (name == "selections") {
|
Chris@595
|
359 m_inSelections = false;
|
Chris@45
|
360 } else if (name == "playparameters") {
|
Chris@636
|
361 m_currentPlayParameters = nullptr;
|
Chris@45
|
362 }
|
Chris@45
|
363
|
Chris@45
|
364 return true;
|
Chris@45
|
365 }
|
Chris@45
|
366
|
Chris@45
|
367 bool
|
Chris@45
|
368 SVFileReader::error(const QXmlParseException &exception)
|
Chris@45
|
369 {
|
Chris@45
|
370 m_errorString =
|
Chris@595
|
371 QString("ERROR: SV-XML: %1 at line %2, column %3")
|
Chris@595
|
372 .arg(exception.message())
|
Chris@595
|
373 .arg(exception.lineNumber())
|
Chris@595
|
374 .arg(exception.columnNumber());
|
Chris@601
|
375 SVCERR << m_errorString << endl;
|
Chris@45
|
376 return QXmlDefaultHandler::error(exception);
|
Chris@45
|
377 }
|
Chris@45
|
378
|
Chris@45
|
379 bool
|
Chris@45
|
380 SVFileReader::fatalError(const QXmlParseException &exception)
|
Chris@45
|
381 {
|
Chris@45
|
382 m_errorString =
|
Chris@595
|
383 QString("FATAL ERROR: SV-XML: %1 at line %2, column %3")
|
Chris@595
|
384 .arg(exception.message())
|
Chris@595
|
385 .arg(exception.lineNumber())
|
Chris@595
|
386 .arg(exception.columnNumber());
|
Chris@601
|
387 SVCERR << m_errorString << endl;
|
Chris@45
|
388 return QXmlDefaultHandler::fatalError(exception);
|
Chris@45
|
389 }
|
Chris@45
|
390
|
Chris@45
|
391
|
Chris@595
|
392 #define READ_MANDATORY(TYPE, NAME, CONVERSION) \
|
Chris@45
|
393 TYPE NAME = attributes.value(#NAME).trimmed().CONVERSION(&ok); \
|
Chris@45
|
394 if (!ok) { \
|
Chris@601
|
395 SVCERR << "WARNING: SV-XML: Missing or invalid mandatory " #TYPE " attribute \"" #NAME "\"" << endl; \
|
Chris@595
|
396 return false; \
|
Chris@45
|
397 }
|
Chris@45
|
398
|
Chris@45
|
399 bool
|
Chris@576
|
400 SVFileReader::readWindow(const QXmlAttributes &)
|
Chris@45
|
401 {
|
Chris@576
|
402 // The window element contains window dimensions, which we used to
|
Chris@576
|
403 // read and size the window accordingly. This was a Bad Idea [tm]
|
Chris@576
|
404 // and we now do nothing instead. See #1769 Loading window
|
Chris@576
|
405 // dimensions from session file is a really bad idea
|
Chris@45
|
406 return true;
|
Chris@45
|
407 }
|
Chris@45
|
408
|
Chris@45
|
409 void
|
Chris@629
|
410 SVFileReader::makeAggregateModels()
|
Chris@629
|
411 {
|
Chris@685
|
412 std::map<ExportId, PendingAggregateRec> stillPending;
|
Chris@629
|
413
|
Chris@629
|
414 for (auto p: m_pendingAggregates) {
|
Chris@629
|
415
|
Chris@629
|
416 int id = p.first;
|
Chris@629
|
417 const PendingAggregateRec &rec = p.second;
|
Chris@629
|
418 bool skip = false;
|
Chris@629
|
419
|
Chris@629
|
420 AggregateWaveModel::ChannelSpecList specs;
|
Chris@685
|
421 for (ExportId componentId: rec.components) {
|
Chris@629
|
422 bool found = false;
|
Chris@629
|
423 if (m_models.find(componentId) != m_models.end()) {
|
Chris@685
|
424 ModelId modelId = m_models[componentId];
|
Chris@685
|
425 auto rs = ModelById::getAs<RangeSummarisableTimeValueModel>
|
Chris@685
|
426 (modelId);
|
Chris@629
|
427 if (rs) {
|
Chris@629
|
428 specs.push_back(AggregateWaveModel::ModelChannelSpec
|
Chris@685
|
429 (modelId, -1));
|
Chris@629
|
430 found = true;
|
Chris@685
|
431 } else {
|
Chris@685
|
432 SVDEBUG << "SVFileReader::makeAggregateModels: "
|
Chris@685
|
433 << "Component model id " << componentId
|
Chris@685
|
434 << "in aggregate model id " << id
|
Chris@685
|
435 << "does not appear to be convertible to "
|
Chris@685
|
436 << "RangeSummarisableTimeValueModel"
|
Chris@685
|
437 << endl;
|
Chris@629
|
438 }
|
Chris@629
|
439 }
|
Chris@629
|
440 if (!found) {
|
Chris@685
|
441 SVDEBUG << "SVFileReader::makeAggregateModels: "
|
Chris@629
|
442 << "Unknown component model id "
|
Chris@629
|
443 << componentId << " in aggregate model id " << id
|
Chris@629
|
444 << ", hoping we won't be needing it just yet"
|
Chris@629
|
445 << endl;
|
Chris@629
|
446 skip = true;
|
Chris@629
|
447 }
|
Chris@629
|
448 }
|
Chris@629
|
449
|
Chris@629
|
450 if (skip) {
|
Chris@629
|
451 stillPending[id] = rec;
|
Chris@629
|
452 } else {
|
Chris@685
|
453 auto model = std::make_shared<AggregateWaveModel>(specs);
|
Chris@629
|
454 model->setObjectName(rec.name);
|
Chris@685
|
455 m_models[id] = ModelById::add(model);
|
Chris@629
|
456
|
Chris@685
|
457 SVDEBUG << "SVFileReader::makeAggregateModels: created aggregate "
|
Chris@685
|
458 << "model id " << id << " with " << specs.size()
|
Chris@685
|
459 << " components" << endl;
|
Chris@629
|
460 }
|
Chris@629
|
461 }
|
Chris@629
|
462
|
Chris@629
|
463 m_pendingAggregates = stillPending;
|
Chris@629
|
464 }
|
Chris@629
|
465
|
Chris@629
|
466 void
|
Chris@45
|
467 SVFileReader::addUnaddedModels()
|
Chris@45
|
468 {
|
Chris@629
|
469 makeAggregateModels();
|
Chris@662
|
470
|
Chris@685
|
471 for (auto i: m_models) {
|
Chris@662
|
472
|
Chris@685
|
473 ModelId modelId = i.second;
|
Chris@685
|
474
|
Chris@685
|
475 if (m_addedModels.find(modelId) != m_addedModels.end()) {
|
Chris@662
|
476 // already added this one
|
Chris@662
|
477 continue;
|
Chris@45
|
478 }
|
Chris@685
|
479
|
Chris@685
|
480 //!!! todo: review this (i.e. who causes the release of what)
|
Chris@662
|
481
|
Chris@685
|
482 // don't want to add alignment models to the document, because
|
Chris@685
|
483 // their lifespans are entirely dictated by the models that
|
Chris@685
|
484 // "own" them even though they were read independently from
|
Chris@685
|
485 // the .sv file. (pity we don't have a nicer way to handle
|
Chris@685
|
486 // this)
|
Chris@685
|
487 if (!ModelById::isa<AlignmentModel>(modelId)) {
|
Chris@685
|
488 m_document->addImportedModel(modelId);
|
Chris@212
|
489 }
|
Chris@662
|
490
|
Chris@685
|
491 // but we add all models including alignment ones to the added
|
Chris@685
|
492 // set, so they don't get released by our own destructor
|
Chris@685
|
493 m_addedModels.insert(modelId);
|
Chris@45
|
494 }
|
Chris@45
|
495 }
|
Chris@45
|
496
|
Chris@45
|
497 bool
|
Chris@45
|
498 SVFileReader::readModel(const QXmlAttributes &attributes)
|
Chris@45
|
499 {
|
Chris@45
|
500 bool ok = false;
|
Chris@45
|
501
|
Chris@45
|
502 READ_MANDATORY(int, id, toInt);
|
Chris@45
|
503
|
Chris@45
|
504 if (haveModel(id)) {
|
Chris@601
|
505 SVCERR << "WARNING: SV-XML: Ignoring duplicate model id " << id
|
Chris@595
|
506 << endl;
|
Chris@595
|
507 return false;
|
Chris@45
|
508 }
|
Chris@45
|
509
|
Chris@45
|
510 QString name = attributes.value("name");
|
Chris@45
|
511
|
Chris@233
|
512 SVDEBUG << "SVFileReader::readModel: model name \"" << name << "\"" << endl;
|
Chris@45
|
513
|
Chris@436
|
514 READ_MANDATORY(double, sampleRate, toDouble);
|
Chris@45
|
515
|
Chris@45
|
516 QString type = attributes.value("type").trimmed();
|
Chris@362
|
517 bool isMainModel = (attributes.value("mainModel").trimmed() == "true");
|
Chris@45
|
518
|
Chris@45
|
519 if (type == "wavefile") {
|
Chris@595
|
520
|
Chris@636
|
521 WaveFileModel *model = nullptr;
|
Chris@45
|
522 FileFinder *ff = FileFinder::getInstance();
|
Chris@45
|
523 QString originalPath = attributes.value("file");
|
Chris@45
|
524 QString path = ff->find(FileFinder::AudioFile,
|
Chris@45
|
525 originalPath, m_location);
|
Chris@45
|
526
|
Chris@248
|
527 SVDEBUG << "Wave file originalPath = " << originalPath << ", path = "
|
Chris@248
|
528 << path << endl;
|
Chris@248
|
529
|
Chris@109
|
530 ProgressDialog dialog(tr("Opening file or URL..."), true, 2000);
|
Chris@109
|
531 FileSource file(path, &dialog);
|
Chris@45
|
532 file.waitForStatus();
|
Chris@45
|
533
|
Chris@45
|
534 if (!file.isOK()) {
|
Chris@601
|
535 SVCERR << "SVFileReader::readModel: Failed to retrieve file \"" << path << "\" for wave file model: " << file.getErrorString() << endl;
|
Chris@45
|
536 } else if (!file.isAvailable()) {
|
Chris@601
|
537 SVCERR << "SVFileReader::readModel: Failed to retrieve file \"" << path << "\" for wave file model: Source unavailable" << endl;
|
Chris@45
|
538 } else {
|
Chris@45
|
539
|
Chris@45
|
540 file.waitForData();
|
Chris@116
|
541
|
Chris@436
|
542 sv_samplerate_t rate = sampleRate;
|
Chris@116
|
543
|
Chris@360
|
544 if (Preferences::getInstance()->getFixedSampleRate() != 0) {
|
Chris@360
|
545 rate = Preferences::getInstance()->getFixedSampleRate();
|
Chris@362
|
546 } else if (rate == 0 &&
|
Chris@362
|
547 !isMainModel &&
|
Chris@360
|
548 Preferences::getInstance()->getResampleOnLoad()) {
|
Chris@685
|
549 auto mm = ModelById::getAs<WaveFileModel>
|
Chris@685
|
550 (m_document->getMainModel());
|
Chris@116
|
551 if (mm) rate = mm->getSampleRate();
|
Chris@116
|
552 }
|
Chris@116
|
553
|
Chris@479
|
554 model = new ReadOnlyWaveFileModel(file, rate);
|
Chris@45
|
555 if (!model->isOK()) {
|
Chris@45
|
556 delete model;
|
Chris@636
|
557 model = nullptr;
|
Chris@45
|
558 }
|
Chris@45
|
559 }
|
Chris@45
|
560
|
Chris@601
|
561 if (!model) {
|
Chris@601
|
562 m_document->setIncomplete(true);
|
Chris@601
|
563 return false;
|
Chris@601
|
564 }
|
Chris@45
|
565
|
Chris@45
|
566 model->setObjectName(name);
|
Chris@685
|
567
|
Chris@685
|
568 ModelId modelId = model->getId();
|
Chris@685
|
569 ModelById::add(std::shared_ptr<Model>(model));
|
Chris@685
|
570 m_models[id] = modelId;
|
Chris@685
|
571
|
Chris@595
|
572 if (isMainModel) {
|
Chris@685
|
573 m_document->setMainModel(modelId);
|
Chris@685
|
574 m_addedModels.insert(modelId);
|
Chris@595
|
575 }
|
Chris@595
|
576 // Derived models will be added when their derivation
|
Chris@595
|
577 // is found.
|
Chris@45
|
578
|
Chris@595
|
579 return true;
|
Chris@45
|
580
|
Chris@629
|
581 } else if (type == "aggregatewave") {
|
Chris@629
|
582
|
Chris@629
|
583 QString components = attributes.value("components");
|
Chris@629
|
584 QStringList componentIdStrings = components.split(",");
|
Chris@629
|
585 std::vector<int> componentIds;
|
Chris@685
|
586 for (auto cidStr: componentIdStrings) {
|
Chris@629
|
587 bool ok = false;
|
Chris@685
|
588 int cid = cidStr.toInt(&ok);
|
Chris@629
|
589 if (!ok) {
|
Chris@685
|
590 SVCERR << "SVFileReader::readModel: Failed to convert component model id from part \"" << cidStr << "\" in \"" << components << "\"" << endl;
|
Chris@629
|
591 } else {
|
Chris@685
|
592 componentIds.push_back(cid);
|
Chris@629
|
593 }
|
Chris@629
|
594 }
|
Chris@629
|
595 PendingAggregateRec rec { name, sampleRate, componentIds };
|
Chris@629
|
596 m_pendingAggregates[id] = rec;
|
Chris@629
|
597
|
Chris@629
|
598 // The aggregate model will be constructed from its pending
|
Chris@629
|
599 // record in makeAggregateModels; it can't happen here because
|
Chris@629
|
600 // the component models might not all have been observed yet
|
Chris@629
|
601 // (an unfortunate accident of the way the file is written)
|
Chris@629
|
602
|
Chris@629
|
603 return true;
|
Chris@629
|
604
|
Chris@45
|
605 } else if (type == "dense") {
|
Chris@595
|
606
|
Chris@595
|
607 READ_MANDATORY(int, dimensions, toInt);
|
Chris@595
|
608
|
Chris@595
|
609 // Currently the only dense model we support here is the dense
|
Chris@595
|
610 // 3d model. Dense time-value models are always file-backed
|
Chris@595
|
611 // waveform data, at this point, and they come in as wavefile
|
Chris@595
|
612 // models.
|
Chris@595
|
613
|
Chris@595
|
614 if (dimensions == 3) {
|
Chris@595
|
615
|
Chris@595
|
616 READ_MANDATORY(int, windowSize, toInt);
|
Chris@595
|
617 READ_MANDATORY(int, yBinCount, toInt);
|
Chris@595
|
618
|
Chris@685
|
619 auto model = std::make_shared<EditableDenseThreeDimensionalModel>
|
Chris@153
|
620 (sampleRate, windowSize, yBinCount,
|
Chris@153
|
621 EditableDenseThreeDimensionalModel::NoCompression);
|
Chris@685
|
622
|
Chris@685
|
623 model->setObjectName(name);
|
Chris@685
|
624 m_models[id] = ModelById::add(model);
|
Chris@595
|
625
|
Chris@595
|
626 float minimum = attributes.value("minimum").trimmed().toFloat(&ok);
|
Chris@595
|
627 if (ok) model->setMinimumLevel(minimum);
|
Chris@595
|
628
|
Chris@595
|
629 float maximum = attributes.value("maximum").trimmed().toFloat(&ok);
|
Chris@595
|
630 if (ok) model->setMaximumLevel(maximum);
|
Chris@45
|
631
|
Chris@595
|
632 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@595
|
633 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@45
|
634
|
Chris@181
|
635 int startFrame = attributes.value("startFrame").trimmed().toInt(&ok);
|
Chris@181
|
636 if (ok) model->setStartFrame(startFrame);
|
Chris@181
|
637
|
Chris@595
|
638 return true;
|
Chris@45
|
639
|
Chris@595
|
640 } else {
|
Chris@45
|
641
|
Chris@601
|
642 SVCERR << "WARNING: SV-XML: Unexpected dense model dimension ("
|
Chris@595
|
643 << dimensions << ")" << endl;
|
Chris@595
|
644 }
|
Chris@45
|
645 } else if (type == "sparse") {
|
Chris@45
|
646
|
Chris@595
|
647 READ_MANDATORY(int, dimensions, toInt);
|
Chris@595
|
648
|
Chris@595
|
649 if (dimensions == 1) {
|
Chris@595
|
650
|
Chris@595
|
651 READ_MANDATORY(int, resolution, toInt);
|
Chris@685
|
652
|
Chris@45
|
653 if (attributes.value("subtype") == "image") {
|
Chris@45
|
654
|
Chris@45
|
655 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
|
Chris@685
|
656 auto model = std::make_shared<ImageModel>
|
Chris@685
|
657 (sampleRate, resolution, notifyOnAdd);
|
Chris@45
|
658 model->setObjectName(name);
|
Chris@685
|
659 m_models[id] = ModelById::add(model);
|
Chris@45
|
660
|
Chris@45
|
661 } else {
|
Chris@45
|
662
|
Chris@685
|
663 auto model = std::make_shared<SparseOneDimensionalModel>
|
Chris@45
|
664 (sampleRate, resolution);
|
Chris@45
|
665 model->setObjectName(name);
|
Chris@685
|
666 m_models[id] = ModelById::add(model);
|
Chris@45
|
667 }
|
Chris@45
|
668
|
Chris@595
|
669 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@595
|
670 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@45
|
671
|
Chris@595
|
672 return true;
|
Chris@45
|
673
|
Chris@595
|
674 } else if (dimensions == 2 || dimensions == 3) {
|
Chris@595
|
675
|
Chris@595
|
676 READ_MANDATORY(int, resolution, toInt);
|
Chris@45
|
677
|
Chris@45
|
678 bool haveMinMax = true;
|
Chris@595
|
679 float minimum = attributes.value("minimum").trimmed().toFloat(&ok);
|
Chris@45
|
680 if (!ok) haveMinMax = false;
|
Chris@595
|
681 float maximum = attributes.value("maximum").trimmed().toFloat(&ok);
|
Chris@45
|
682 if (!ok) haveMinMax = false;
|
Chris@45
|
683
|
Chris@595
|
684 float valueQuantization =
|
Chris@595
|
685 attributes.value("valueQuantization").trimmed().toFloat(&ok);
|
Chris@45
|
686
|
Chris@595
|
687 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
|
Chris@45
|
688
|
Chris@45
|
689 QString units = attributes.value("units");
|
Chris@45
|
690
|
Chris@595
|
691 if (dimensions == 2) {
|
Chris@595
|
692 if (attributes.value("subtype") == "text") {
|
Chris@685
|
693 auto model = std::make_shared<TextModel>
|
Chris@595
|
694 (sampleRate, resolution, notifyOnAdd);
|
Chris@45
|
695 model->setObjectName(name);
|
Chris@685
|
696 m_models[id] = ModelById::add(model);
|
Chris@111
|
697 } else if (attributes.value("subtype") == "path") {
|
Chris@685
|
698 // Paths are no longer actually models
|
Chris@685
|
699 Path *path = new Path(sampleRate, resolution);
|
Chris@685
|
700 m_paths[id] = path;
|
Chris@595
|
701 } else {
|
Chris@685
|
702 std::shared_ptr<SparseTimeValueModel> model;
|
Chris@45
|
703 if (haveMinMax) {
|
Chris@685
|
704 model = std::make_shared<SparseTimeValueModel>
|
Chris@685
|
705 (sampleRate, resolution, minimum, maximum,
|
Chris@685
|
706 notifyOnAdd);
|
Chris@45
|
707 } else {
|
Chris@685
|
708 model = std::make_shared<SparseTimeValueModel>
|
Chris@45
|
709 (sampleRate, resolution, notifyOnAdd);
|
Chris@45
|
710 }
|
Chris@45
|
711 model->setScaleUnits(units);
|
Chris@45
|
712 model->setObjectName(name);
|
Chris@685
|
713 m_models[id] = ModelById::add(model);
|
Chris@595
|
714 }
|
Chris@595
|
715 } else {
|
Chris@137
|
716 if (attributes.value("subtype") == "region") {
|
Chris@685
|
717 std::shared_ptr<RegionModel> model;
|
Chris@137
|
718 if (haveMinMax) {
|
Chris@685
|
719 model = std::make_shared<RegionModel>
|
Chris@685
|
720 (sampleRate, resolution, minimum, maximum,
|
Chris@685
|
721 notifyOnAdd);
|
Chris@137
|
722 } else {
|
Chris@685
|
723 model = std::make_shared<RegionModel>
|
Chris@137
|
724 (sampleRate, resolution, notifyOnAdd);
|
Chris@137
|
725 }
|
Chris@137
|
726 model->setValueQuantization(valueQuantization);
|
Chris@137
|
727 model->setScaleUnits(units);
|
Chris@137
|
728 model->setObjectName(name);
|
Chris@685
|
729 m_models[id] = ModelById::add(model);
|
Chris@343
|
730 } else if (attributes.value("subtype") == "flexinote") {
|
Chris@685
|
731 std::shared_ptr<NoteModel> model;
|
Chris@343
|
732 if (haveMinMax) {
|
Chris@685
|
733 model = std::make_shared<NoteModel>
|
Chris@646
|
734 (sampleRate, resolution, minimum, maximum,
|
Chris@646
|
735 notifyOnAdd,
|
Chris@646
|
736 NoteModel::FLEXI_NOTE);
|
Chris@343
|
737 } else {
|
Chris@685
|
738 model = std::make_shared<NoteModel>
|
Chris@646
|
739 (sampleRate, resolution, notifyOnAdd,
|
Chris@646
|
740 NoteModel::FLEXI_NOTE);
|
Chris@343
|
741 }
|
Chris@343
|
742 model->setValueQuantization(valueQuantization);
|
Chris@343
|
743 model->setScaleUnits(units);
|
Chris@343
|
744 model->setObjectName(name);
|
Chris@685
|
745 m_models[id] = ModelById::add(model);
|
Chris@45
|
746 } else {
|
Chris@137
|
747 // note models written out by SV 1.3 and earlier
|
Chris@137
|
748 // have no subtype, so we can't test that
|
Chris@685
|
749 std::shared_ptr<NoteModel> model;
|
Chris@137
|
750 if (haveMinMax) {
|
Chris@685
|
751 model = std::make_shared<NoteModel>
|
Chris@137
|
752 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
|
Chris@137
|
753 } else {
|
Chris@685
|
754 model = std::make_shared<NoteModel>
|
Chris@137
|
755 (sampleRate, resolution, notifyOnAdd);
|
Chris@137
|
756 }
|
Chris@137
|
757 model->setValueQuantization(valueQuantization);
|
Chris@137
|
758 model->setScaleUnits(units);
|
Chris@137
|
759 model->setObjectName(name);
|
Chris@685
|
760 m_models[id] = ModelById::add(model);
|
Chris@45
|
761 }
|
Chris@137
|
762 }
|
Chris@45
|
763
|
Chris@595
|
764 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@595
|
765 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@45
|
766
|
Chris@595
|
767 return true;
|
Chris@45
|
768
|
Chris@595
|
769 } else {
|
Chris@45
|
770
|
Chris@601
|
771 SVCERR << "WARNING: SV-XML: Unexpected sparse model dimension ("
|
Chris@595
|
772 << dimensions << ")" << endl;
|
Chris@595
|
773 }
|
Chris@111
|
774
|
Chris@111
|
775 } else if (type == "alignment") {
|
Chris@111
|
776
|
Chris@111
|
777 READ_MANDATORY(int, reference, toInt);
|
Chris@111
|
778 READ_MANDATORY(int, aligned, toInt);
|
Chris@111
|
779 READ_MANDATORY(int, path, toInt);
|
Chris@111
|
780
|
Chris@685
|
781 ModelId refModel, alignedModel;
|
Chris@685
|
782 Path *pathPtr = nullptr;
|
Chris@111
|
783
|
Chris@111
|
784 if (m_models.find(reference) != m_models.end()) {
|
Chris@111
|
785 refModel = m_models[reference];
|
Chris@111
|
786 } else {
|
Chris@601
|
787 SVCERR << "WARNING: SV-XML: Unknown reference model id "
|
Chris@111
|
788 << reference << " in alignment model id " << id
|
Chris@293
|
789 << endl;
|
Chris@111
|
790 }
|
Chris@111
|
791
|
Chris@111
|
792 if (m_models.find(aligned) != m_models.end()) {
|
Chris@111
|
793 alignedModel = m_models[aligned];
|
Chris@111
|
794 } else {
|
Chris@601
|
795 SVCERR << "WARNING: SV-XML: Unknown aligned model id "
|
Chris@111
|
796 << aligned << " in alignment model id " << id
|
Chris@293
|
797 << endl;
|
Chris@111
|
798 }
|
Chris@111
|
799
|
Chris@685
|
800 if (m_paths.find(path) != m_paths.end()) {
|
Chris@685
|
801 pathPtr = m_paths[path];
|
Chris@111
|
802 } else {
|
Chris@685
|
803 SVCERR << "WARNING: SV-XML: Unknown path id "
|
Chris@111
|
804 << path << " in alignment model id " << id
|
Chris@293
|
805 << endl;
|
Chris@111
|
806 }
|
Chris@111
|
807
|
Chris@685
|
808 if (!refModel.isNone() && !alignedModel.isNone() && pathPtr) {
|
Chris@685
|
809 auto model = std::make_shared<AlignmentModel>
|
Chris@685
|
810 (refModel, alignedModel, ModelId());
|
Chris@685
|
811 model->setPath(*pathPtr);
|
Chris@685
|
812 model->setObjectName(name);
|
Chris@685
|
813 m_models[id] = ModelById::add(model);
|
Chris@685
|
814 if (auto am = ModelById::get(alignedModel)) {
|
Chris@685
|
815 am->setAlignment(m_models[id]);
|
Chris@111
|
816 }
|
Chris@111
|
817 return true;
|
Chris@111
|
818 }
|
Chris@685
|
819
|
Chris@685
|
820 if (pathPtr) {
|
Chris@685
|
821 delete pathPtr;
|
Chris@685
|
822 m_paths.erase(path);
|
Chris@685
|
823 }
|
Chris@111
|
824
|
Chris@45
|
825 } else {
|
Chris@45
|
826
|
Chris@590
|
827 SVCERR << "WARNING: SV-XML: Unexpected model type \""
|
Chris@590
|
828 << type << "\" for model id " << id << endl;
|
Chris@45
|
829 }
|
Chris@45
|
830
|
Chris@45
|
831 return false;
|
Chris@45
|
832 }
|
Chris@45
|
833
|
Chris@45
|
834 bool
|
Chris@45
|
835 SVFileReader::readView(const QXmlAttributes &attributes)
|
Chris@45
|
836 {
|
Chris@45
|
837 QString type = attributes.value("type");
|
Chris@636
|
838 m_currentPane = nullptr;
|
Chris@45
|
839
|
Chris@45
|
840 if (type != "pane") {
|
Chris@601
|
841 SVCERR << "WARNING: SV-XML: Unexpected view type \""
|
Chris@595
|
842 << type << "\"" << endl;
|
Chris@595
|
843 return false;
|
Chris@45
|
844 }
|
Chris@45
|
845
|
Chris@45
|
846 m_currentPane = m_paneCallback.addPane();
|
Chris@45
|
847
|
Chris@630
|
848 SVDEBUG << "SVFileReader::addPane: pane is " << m_currentPane << endl;
|
Chris@342
|
849
|
Chris@45
|
850 if (!m_currentPane) {
|
Chris@601
|
851 SVCERR << "WARNING: SV-XML: Internal error: Failed to add pane!"
|
Chris@595
|
852 << endl;
|
Chris@595
|
853 return false;
|
Chris@45
|
854 }
|
Chris@45
|
855
|
Chris@45
|
856 bool ok = false;
|
Chris@45
|
857
|
Chris@45
|
858 View *view = m_currentPane;
|
Chris@45
|
859
|
Chris@45
|
860 // The view properties first
|
Chris@45
|
861
|
Chris@366
|
862 READ_MANDATORY(int, centre, toInt);
|
Chris@366
|
863 READ_MANDATORY(int, zoom, toInt);
|
Chris@45
|
864 READ_MANDATORY(int, followPan, toInt);
|
Chris@45
|
865 READ_MANDATORY(int, followZoom, toInt);
|
Chris@45
|
866 QString tracking = attributes.value("tracking");
|
Chris@45
|
867
|
Chris@624
|
868 ZoomLevel zoomLevel;
|
Chris@624
|
869 int deepZoom = attributes.value("deepZoom").trimmed().toInt(&ok);
|
Chris@624
|
870 if (ok && zoom == 1 && deepZoom > 1) {
|
Chris@624
|
871 zoomLevel = { ZoomLevel::PixelsPerFrame, deepZoom };
|
Chris@624
|
872 } else {
|
Chris@624
|
873 zoomLevel = { ZoomLevel::FramesPerPixel, zoom };
|
Chris@624
|
874 }
|
Chris@624
|
875
|
Chris@45
|
876 // Specify the follow modes before we set the actual values
|
Chris@45
|
877 view->setFollowGlobalPan(followPan);
|
Chris@45
|
878 view->setFollowGlobalZoom(followZoom);
|
Chris@45
|
879 view->setPlaybackFollow(tracking == "scroll" ? PlaybackScrollContinuous :
|
Chris@595
|
880 tracking == "page" ? PlaybackScrollPageWithCentre :
|
Chris@595
|
881 tracking == "daw" ? PlaybackScrollPage
|
Chris@595
|
882 : PlaybackIgnore);
|
Chris@45
|
883
|
Chris@45
|
884 // Then set these values
|
Chris@45
|
885 view->setCentreFrame(centre);
|
Chris@624
|
886 view->setZoomLevel(zoomLevel);
|
Chris@45
|
887
|
Chris@45
|
888 // And pane properties
|
Chris@45
|
889 READ_MANDATORY(int, centreLineVisible, toInt);
|
Chris@45
|
890 m_currentPane->setCentreLineVisible(centreLineVisible);
|
Chris@45
|
891
|
Chris@45
|
892 int height = attributes.value("height").toInt(&ok);
|
Chris@45
|
893 if (ok) {
|
Chris@595
|
894 m_currentPane->resize(m_currentPane->width(), height);
|
Chris@45
|
895 }
|
Chris@45
|
896
|
Chris@45
|
897 return true;
|
Chris@45
|
898 }
|
Chris@45
|
899
|
Chris@45
|
900 bool
|
Chris@45
|
901 SVFileReader::readLayer(const QXmlAttributes &attributes)
|
Chris@45
|
902 {
|
Chris@45
|
903 QString type = attributes.value("type");
|
Chris@45
|
904
|
Chris@45
|
905 int id;
|
Chris@45
|
906 bool ok = false;
|
Chris@45
|
907 id = attributes.value("id").trimmed().toInt(&ok);
|
Chris@45
|
908
|
Chris@45
|
909 if (!ok) {
|
Chris@601
|
910 SVCERR << "WARNING: SV-XML: No layer id for layer of type \""
|
Chris@595
|
911 << type
|
Chris@595
|
912 << "\"" << endl;
|
Chris@595
|
913 return false;
|
Chris@45
|
914 }
|
Chris@45
|
915
|
Chris@636
|
916 Layer *layer = nullptr;
|
Chris@45
|
917 bool isNewLayer = false;
|
Chris@45
|
918
|
Chris@45
|
919 // Layers are expected to be defined in layer elements in the data
|
Chris@45
|
920 // section, and referred to in layer elements in the view
|
Chris@45
|
921 // sections. So if we're in the data section, we expect this
|
Chris@45
|
922 // layer not to exist already; if we're in the view section, we
|
Chris@45
|
923 // expect it to exist.
|
Chris@45
|
924
|
Chris@45
|
925 if (m_inData) {
|
Chris@45
|
926
|
Chris@595
|
927 if (m_layers.find(id) != m_layers.end()) {
|
Chris@601
|
928 SVCERR << "WARNING: SV-XML: Ignoring duplicate layer id " << id
|
Chris@595
|
929 << " in data section" << endl;
|
Chris@595
|
930 return false;
|
Chris@595
|
931 }
|
Chris@45
|
932
|
Chris@595
|
933 layer = m_layers[id] = m_document->createLayer
|
Chris@595
|
934 (LayerFactory::getInstance()->getLayerTypeForName(type));
|
Chris@45
|
935
|
Chris@595
|
936 if (layer) {
|
Chris@595
|
937 m_layers[id] = layer;
|
Chris@595
|
938 isNewLayer = true;
|
Chris@595
|
939 }
|
Chris@45
|
940
|
Chris@45
|
941 } else {
|
Chris@45
|
942
|
Chris@595
|
943 if (!m_currentPane) {
|
Chris@601
|
944 SVCERR << "WARNING: SV-XML: No current pane for layer " << id
|
Chris@595
|
945 << " in view section" << endl;
|
Chris@595
|
946 return false;
|
Chris@595
|
947 }
|
Chris@45
|
948
|
Chris@595
|
949 if (m_layers.find(id) != m_layers.end()) {
|
Chris@595
|
950
|
Chris@595
|
951 layer = m_layers[id];
|
Chris@595
|
952
|
Chris@595
|
953 } else {
|
Chris@601
|
954 SVCERR << "WARNING: SV-XML: Layer id " << id
|
Chris@595
|
955 << " in view section has not been defined -- defining it here"
|
Chris@595
|
956 << endl;
|
Chris@45
|
957
|
Chris@595
|
958 layer = m_document->createLayer
|
Chris@595
|
959 (LayerFactory::getInstance()->getLayerTypeForName(type));
|
Chris@45
|
960
|
Chris@595
|
961 if (layer) {
|
Chris@595
|
962 m_layers[id] = layer;
|
Chris@595
|
963 isNewLayer = true;
|
Chris@595
|
964 }
|
Chris@595
|
965 }
|
Chris@45
|
966 }
|
Chris@595
|
967
|
Chris@45
|
968 if (!layer) {
|
Chris@601
|
969 SVCERR << "WARNING: SV-XML: Failed to add layer of type \""
|
Chris@595
|
970 << type
|
Chris@595
|
971 << "\"" << endl;
|
Chris@595
|
972 return false;
|
Chris@45
|
973 }
|
Chris@45
|
974
|
Chris@45
|
975 if (isNewLayer) {
|
Chris@45
|
976
|
Chris@595
|
977 QString name = attributes.value("name");
|
Chris@595
|
978 layer->setObjectName(name);
|
Chris@45
|
979
|
Chris@89
|
980 QString presentationName = attributes.value("presentationName");
|
Chris@89
|
981 layer->setPresentationName(presentationName);
|
Chris@89
|
982
|
Chris@595
|
983 int modelId;
|
Chris@595
|
984 bool modelOk = false;
|
Chris@595
|
985 modelId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@45
|
986
|
Chris@595
|
987 if (modelOk) {
|
Chris@595
|
988 if (haveModel(modelId)) {
|
Chris@685
|
989 m_document->setModel(layer, m_models[modelId]);
|
Chris@595
|
990 } else {
|
Chris@601
|
991 SVCERR << "WARNING: SV-XML: Unknown model id " << modelId
|
Chris@685
|
992 << " in layer definition" << endl;
|
Chris@451
|
993 if (!layer->canExistWithoutModel()) {
|
Chris@451
|
994 // Don't add a layer with an unknown model id
|
Chris@451
|
995 // unless it explicitly supports this state
|
Chris@451
|
996 m_document->deleteLayer(layer);
|
Chris@636
|
997 m_layers[id] = layer = nullptr;
|
Chris@451
|
998 return false;
|
Chris@451
|
999 }
|
Chris@451
|
1000 }
|
Chris@595
|
1001 }
|
Chris@45
|
1002
|
Chris@447
|
1003 if (layer) layer->setProperties(attributes);
|
Chris@45
|
1004 }
|
Chris@45
|
1005
|
Chris@447
|
1006 if (!m_inData && m_currentPane && layer) {
|
Chris@45
|
1007
|
Chris@45
|
1008 QString visible = attributes.value("visible");
|
Chris@45
|
1009 bool dormant = (visible == "false");
|
Chris@45
|
1010
|
Chris@45
|
1011 // We need to do this both before and after adding the layer
|
Chris@45
|
1012 // to the view -- we need it to be dormant if appropriate
|
Chris@45
|
1013 // before it's actually added to the view so that any property
|
Chris@45
|
1014 // box gets the right state when it's added, but the add layer
|
Chris@45
|
1015 // command sets dormant to false because it assumes it may be
|
Chris@45
|
1016 // restoring a previously dormant layer, so we need to set it
|
Chris@45
|
1017 // again afterwards too. Hm
|
Chris@45
|
1018 layer->setLayerDormant(m_currentPane, dormant);
|
Chris@45
|
1019
|
Chris@595
|
1020 m_document->addLayerToView(m_currentPane, layer);
|
Chris@45
|
1021
|
Chris@45
|
1022 layer->setLayerDormant(m_currentPane, dormant);
|
Chris@45
|
1023 }
|
Chris@45
|
1024
|
Chris@45
|
1025 m_currentLayer = layer;
|
Chris@636
|
1026 m_inLayer = (layer != nullptr);
|
Chris@45
|
1027
|
Chris@45
|
1028 return true;
|
Chris@45
|
1029 }
|
Chris@45
|
1030
|
Chris@45
|
1031 bool
|
Chris@45
|
1032 SVFileReader::readDatasetStart(const QXmlAttributes &attributes)
|
Chris@45
|
1033 {
|
Chris@45
|
1034 bool ok = false;
|
Chris@45
|
1035
|
Chris@45
|
1036 READ_MANDATORY(int, id, toInt);
|
Chris@45
|
1037 READ_MANDATORY(int, dimensions, toInt);
|
Chris@45
|
1038
|
Chris@45
|
1039 if (m_awaitingDatasets.find(id) == m_awaitingDatasets.end()) {
|
Chris@601
|
1040 SVCERR << "WARNING: SV-XML: Unwanted dataset " << id << endl;
|
Chris@595
|
1041 return false;
|
Chris@45
|
1042 }
|
Chris@45
|
1043
|
Chris@685
|
1044 int awaitingId = m_awaitingDatasets[id];
|
Chris@685
|
1045
|
Chris@685
|
1046 ModelId modelId;
|
Chris@685
|
1047 Path *path = nullptr;
|
Chris@45
|
1048
|
Chris@685
|
1049 if (haveModel(awaitingId)) {
|
Chris@685
|
1050 modelId = m_models[awaitingId];
|
Chris@685
|
1051 } else if (m_paths.find(awaitingId) != m_paths.end()) {
|
Chris@685
|
1052 path = m_paths[awaitingId];
|
Chris@45
|
1053 } else {
|
Chris@685
|
1054 SVCERR << "WARNING: SV-XML: Internal error: Unknown model or path "
|
Chris@685
|
1055 << modelId << " awaiting dataset " << id << endl;
|
Chris@595
|
1056 return false;
|
Chris@45
|
1057 }
|
Chris@45
|
1058
|
Chris@45
|
1059 bool good = false;
|
Chris@45
|
1060
|
Chris@45
|
1061 switch (dimensions) {
|
Chris@45
|
1062 case 1:
|
Chris@685
|
1063 good =
|
Chris@685
|
1064 (ModelById::isa<SparseOneDimensionalModel>(modelId) ||
|
Chris@685
|
1065 ModelById::isa<ImageModel>(modelId));
|
Chris@595
|
1066 break;
|
Chris@45
|
1067
|
Chris@45
|
1068 case 2:
|
Chris@685
|
1069 good =
|
Chris@685
|
1070 (ModelById::isa<SparseTimeValueModel>(modelId) ||
|
Chris@685
|
1071 ModelById::isa<TextModel>(modelId) ||
|
Chris@685
|
1072 path);
|
Chris@595
|
1073 break;
|
Chris@45
|
1074
|
Chris@45
|
1075 case 3:
|
Chris@685
|
1076 if (ModelById::isa<EditableDenseThreeDimensionalModel>(modelId)) {
|
Chris@685
|
1077 good = true;
|
Chris@595
|
1078 m_datasetSeparator = attributes.value("separator");
|
Chris@685
|
1079 } else {
|
Chris@685
|
1080 good =
|
Chris@685
|
1081 (ModelById::isa<NoteModel>(modelId) ||
|
Chris@685
|
1082 ModelById::isa<RegionModel>(modelId));
|
Chris@595
|
1083 }
|
Chris@595
|
1084 break;
|
Chris@45
|
1085 }
|
Chris@45
|
1086
|
Chris@45
|
1087 if (!good) {
|
Chris@601
|
1088 SVCERR << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions or inappropriate type for " << dimensions << "-D dataset " << id << endl;
|
Chris@685
|
1089 m_currentDataset = XmlExportable::NO_ID;
|
Chris@595
|
1090 return false;
|
Chris@45
|
1091 }
|
Chris@45
|
1092
|
Chris@685
|
1093 m_currentDataset = awaitingId;
|
Chris@45
|
1094 return true;
|
Chris@45
|
1095 }
|
Chris@45
|
1096
|
Chris@45
|
1097 bool
|
Chris@45
|
1098 SVFileReader::addPointToDataset(const QXmlAttributes &attributes)
|
Chris@45
|
1099 {
|
Chris@45
|
1100 bool ok = false;
|
Chris@45
|
1101
|
Chris@45
|
1102 READ_MANDATORY(int, frame, toInt);
|
Chris@45
|
1103
|
Chris@685
|
1104 if (m_paths.find(m_currentDataset) != m_paths.end()) {
|
Chris@685
|
1105 Path *path = m_paths[m_currentDataset];
|
Chris@685
|
1106 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok);
|
Chris@685
|
1107 path->add(PathPoint(frame, mapframe));
|
Chris@685
|
1108 return ok;
|
Chris@685
|
1109 }
|
Chris@45
|
1110
|
Chris@685
|
1111 if (!haveModel(m_currentDataset)) {
|
Chris@685
|
1112 SVCERR << "WARNING: SV-XML: Point element found in non-point dataset"
|
Chris@685
|
1113 << endl;
|
Chris@685
|
1114 return false;
|
Chris@685
|
1115 }
|
Chris@685
|
1116
|
Chris@685
|
1117 ModelId modelId = m_models[m_currentDataset];
|
Chris@45
|
1118
|
Chris@685
|
1119 if (auto sodm = ModelById::getAs<SparseOneDimensionalModel>(modelId)) {
|
Chris@595
|
1120 QString label = attributes.value("label");
|
Chris@651
|
1121 sodm->add(Event(frame, label));
|
Chris@595
|
1122 return true;
|
Chris@45
|
1123 }
|
Chris@45
|
1124
|
Chris@685
|
1125 if (auto stvm = ModelById::getAs<SparseTimeValueModel>(modelId)) {
|
Chris@595
|
1126 float value = 0.0;
|
Chris@595
|
1127 value = attributes.value("value").trimmed().toFloat(&ok);
|
Chris@595
|
1128 QString label = attributes.value("label");
|
Chris@649
|
1129 stvm->add(Event(frame, value, label));
|
Chris@595
|
1130 return ok;
|
Chris@45
|
1131 }
|
Chris@595
|
1132
|
Chris@685
|
1133 if (auto nm = ModelById::getAs<NoteModel>(modelId)) {
|
Chris@595
|
1134 float value = 0.0;
|
Chris@595
|
1135 value = attributes.value("value").trimmed().toFloat(&ok);
|
Chris@595
|
1136 int duration = 0;
|
Chris@595
|
1137 duration = attributes.value("duration").trimmed().toInt(&ok);
|
Chris@595
|
1138 QString label = attributes.value("label");
|
Chris@61
|
1139 float level = attributes.value("level").trimmed().toFloat(&ok);
|
Chris@61
|
1140 if (!ok) { // level is optional
|
Chris@61
|
1141 level = 1.f;
|
Chris@61
|
1142 ok = true;
|
Chris@61
|
1143 }
|
Chris@646
|
1144 nm->add(Event(frame, value, duration, level, label));
|
Chris@595
|
1145 return ok;
|
Chris@343
|
1146 }
|
Chris@343
|
1147
|
Chris@685
|
1148 if (auto rm = ModelById::getAs<RegionModel>(modelId)) {
|
Chris@595
|
1149 float value = 0.0;
|
Chris@595
|
1150 value = attributes.value("value").trimmed().toFloat(&ok);
|
Chris@595
|
1151 int duration = 0;
|
Chris@595
|
1152 duration = attributes.value("duration").trimmed().toInt(&ok);
|
Chris@595
|
1153 QString label = attributes.value("label");
|
Chris@648
|
1154 rm->add(Event(frame, value, duration, label));
|
Chris@595
|
1155 return ok;
|
Chris@137
|
1156 }
|
Chris@137
|
1157
|
Chris@685
|
1158 if (auto tm = ModelById::getAs<TextModel>(modelId)) {
|
Chris@595
|
1159 float height = 0.0;
|
Chris@595
|
1160 height = attributes.value("height").trimmed().toFloat(&ok);
|
Chris@595
|
1161 QString label = attributes.value("label");
|
Chris@652
|
1162 tm->add(Event(frame, height, label));
|
Chris@595
|
1163 return ok;
|
Chris@45
|
1164 }
|
Chris@45
|
1165
|
Chris@685
|
1166 if (auto im = ModelById::getAs<ImageModel>(modelId)) {
|
Chris@595
|
1167 QString image = attributes.value("image");
|
Chris@595
|
1168 QString label = attributes.value("label");
|
Chris@653
|
1169 im->add(Event(frame).withURI(image).withLabel(label));
|
Chris@595
|
1170 return ok;
|
Chris@45
|
1171 }
|
Chris@45
|
1172
|
Chris@685
|
1173 SVCERR << "WARNING: SV-XML: Point element found in non-point dataset"
|
Chris@685
|
1174 << endl;
|
Chris@45
|
1175
|
Chris@45
|
1176 return false;
|
Chris@45
|
1177 }
|
Chris@45
|
1178
|
Chris@45
|
1179 bool
|
Chris@45
|
1180 SVFileReader::addBinToDataset(const QXmlAttributes &attributes)
|
Chris@45
|
1181 {
|
Chris@685
|
1182 if (!haveModel(m_currentDataset)) {
|
Chris@685
|
1183 SVCERR << "WARNING: SV-XML: Bin definition found in incompatible dataset"
|
Chris@685
|
1184 << endl;
|
Chris@685
|
1185 return false;
|
Chris@685
|
1186 }
|
Chris@685
|
1187
|
Chris@685
|
1188 ModelId modelId = m_models[m_currentDataset];
|
Chris@45
|
1189
|
Chris@685
|
1190 if (auto dtdm = ModelById::getAs<EditableDenseThreeDimensionalModel>
|
Chris@685
|
1191 (modelId)) {
|
Chris@45
|
1192
|
Chris@595
|
1193 bool ok = false;
|
Chris@595
|
1194 int n = attributes.value("number").trimmed().toInt(&ok);
|
Chris@595
|
1195 if (!ok) {
|
Chris@601
|
1196 SVCERR << "WARNING: SV-XML: Missing or invalid bin number"
|
Chris@595
|
1197 << endl;
|
Chris@595
|
1198 return false;
|
Chris@595
|
1199 }
|
Chris@45
|
1200
|
Chris@595
|
1201 QString name = attributes.value("name");
|
Chris@595
|
1202 dtdm->setBinName(n, name);
|
Chris@595
|
1203 return true;
|
Chris@45
|
1204 }
|
Chris@45
|
1205
|
Chris@685
|
1206 SVCERR << "WARNING: SV-XML: Bin definition found in incompatible dataset"
|
Chris@685
|
1207 << endl;
|
Chris@45
|
1208
|
Chris@45
|
1209 return false;
|
Chris@45
|
1210 }
|
Chris@45
|
1211
|
Chris@45
|
1212
|
Chris@45
|
1213 bool
|
Chris@45
|
1214 SVFileReader::addRowToDataset(const QXmlAttributes &attributes)
|
Chris@45
|
1215 {
|
Chris@45
|
1216 m_inRow = false;
|
Chris@45
|
1217
|
Chris@45
|
1218 bool ok = false;
|
Chris@45
|
1219 m_rowNumber = attributes.value("n").trimmed().toInt(&ok);
|
Chris@45
|
1220 if (!ok) {
|
Chris@601
|
1221 SVCERR << "WARNING: SV-XML: Missing or invalid row number"
|
Chris@595
|
1222 << endl;
|
Chris@595
|
1223 return false;
|
Chris@45
|
1224 }
|
Chris@45
|
1225
|
Chris@45
|
1226 m_inRow = true;
|
Chris@45
|
1227
|
Chris@601
|
1228 // SVCERR << "SV-XML: In row " << m_rowNumber << endl;
|
Chris@45
|
1229
|
Chris@45
|
1230 return true;
|
Chris@45
|
1231 }
|
Chris@45
|
1232
|
Chris@45
|
1233 bool
|
Chris@45
|
1234 SVFileReader::readRowData(const QString &text)
|
Chris@45
|
1235 {
|
Chris@685
|
1236 if (!haveModel(m_currentDataset)) {
|
Chris@685
|
1237 SVCERR << "WARNING: SV-XML: Row data found in non-row dataset" << endl;
|
Chris@685
|
1238 return false;
|
Chris@685
|
1239 }
|
Chris@685
|
1240
|
Chris@685
|
1241 ModelId modelId = m_models[m_currentDataset];
|
Chris@45
|
1242 bool warned = false;
|
Chris@45
|
1243
|
Chris@685
|
1244 if (auto dtdm = ModelById::getAs<EditableDenseThreeDimensionalModel>
|
Chris@685
|
1245 (modelId)) {
|
Chris@685
|
1246
|
Chris@595
|
1247 QStringList data = text.split(m_datasetSeparator);
|
Chris@45
|
1248
|
Chris@595
|
1249 DenseThreeDimensionalModel::Column values;
|
Chris@45
|
1250
|
Chris@595
|
1251 for (QStringList::iterator i = data.begin(); i != data.end(); ++i) {
|
Chris@45
|
1252
|
Chris@595
|
1253 if (int(values.size()) == dtdm->getHeight()) {
|
Chris@595
|
1254 if (!warned) {
|
Chris@601
|
1255 SVCERR << "WARNING: SV-XML: Too many y-bins in 3-D dataset row "
|
Chris@595
|
1256 << m_rowNumber << endl;
|
Chris@595
|
1257 warned = true;
|
Chris@595
|
1258 }
|
Chris@595
|
1259 }
|
Chris@45
|
1260
|
Chris@595
|
1261 bool ok;
|
Chris@595
|
1262 float value = i->toFloat(&ok);
|
Chris@595
|
1263 if (!ok) {
|
Chris@601
|
1264 SVCERR << "WARNING: SV-XML: Bad floating-point value "
|
Chris@595
|
1265 << i->toLocal8Bit().data()
|
Chris@595
|
1266 << " in row data" << endl;
|
Chris@595
|
1267 } else {
|
Chris@595
|
1268 values.push_back(value);
|
Chris@595
|
1269 }
|
Chris@595
|
1270 }
|
Chris@45
|
1271
|
Chris@595
|
1272 dtdm->setColumn(m_rowNumber, values);
|
Chris@595
|
1273 return true;
|
Chris@45
|
1274 }
|
Chris@45
|
1275
|
Chris@601
|
1276 SVCERR << "WARNING: SV-XML: Row data found in non-row dataset" << endl;
|
Chris@45
|
1277 return false;
|
Chris@45
|
1278 }
|
Chris@45
|
1279
|
Chris@45
|
1280 bool
|
Chris@45
|
1281 SVFileReader::readDerivation(const QXmlAttributes &attributes)
|
Chris@45
|
1282 {
|
Chris@685
|
1283 int modelExportId = 0;
|
Chris@45
|
1284 bool modelOk = false;
|
Chris@685
|
1285 modelExportId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@45
|
1286
|
Chris@45
|
1287 if (!modelOk) {
|
Chris@601
|
1288 SVCERR << "WARNING: SV-XML: No model id specified for derivation" << endl;
|
Chris@595
|
1289 return false;
|
Chris@45
|
1290 }
|
Chris@45
|
1291
|
Chris@685
|
1292 if (haveModel(modelExportId)) {
|
Chris@685
|
1293 m_currentDerivedModel = m_models[modelExportId];
|
Chris@45
|
1294 } else {
|
Chris@45
|
1295 // we'll regenerate the model when the derivation element ends
|
Chris@685
|
1296 m_currentDerivedModel = {};
|
Chris@45
|
1297 }
|
Chris@45
|
1298
|
Chris@685
|
1299 m_pendingDerivedModel = modelExportId;
|
Chris@45
|
1300
|
Chris@45
|
1301 int sourceId = 0;
|
Chris@45
|
1302 bool sourceOk = false;
|
Chris@45
|
1303 sourceId = attributes.value("source").trimmed().toInt(&sourceOk);
|
Chris@45
|
1304
|
Chris@45
|
1305 if (sourceOk && haveModel(sourceId)) {
|
Chris@72
|
1306 m_currentTransformSource = m_models[sourceId];
|
Chris@45
|
1307 } else {
|
Chris@585
|
1308 SVDEBUG << "NOTE: SV-XML: Can't find a model with id " << sourceId
|
Chris@585
|
1309 << " for derivation source, falling back to main model" << endl;
|
Chris@72
|
1310 m_currentTransformSource = m_document->getMainModel();
|
Chris@45
|
1311 }
|
Chris@45
|
1312
|
Chris@72
|
1313 m_currentTransform = Transform();
|
Chris@45
|
1314
|
Chris@45
|
1315 bool ok = false;
|
Chris@45
|
1316 int channel = attributes.value("channel").trimmed().toInt(&ok);
|
Chris@72
|
1317 if (ok) m_currentTransformChannel = channel;
|
Chris@72
|
1318 else m_currentTransformChannel = -1;
|
Chris@45
|
1319
|
Chris@72
|
1320 QString type = attributes.value("type");
|
Chris@72
|
1321
|
Chris@72
|
1322 if (type == "transform") {
|
Chris@72
|
1323 m_currentTransformIsNewStyle = true;
|
Chris@72
|
1324 return true;
|
Chris@72
|
1325 } else {
|
Chris@72
|
1326 m_currentTransformIsNewStyle = false;
|
Chris@233
|
1327 SVDEBUG << "NOTE: SV-XML: Reading old-style derivation element"
|
Chris@229
|
1328 << endl;
|
Chris@72
|
1329 }
|
Chris@72
|
1330
|
Chris@72
|
1331 QString transformId = attributes.value("transform");
|
Chris@72
|
1332
|
Chris@72
|
1333 m_currentTransform.setIdentifier(transformId);
|
Chris@45
|
1334
|
Chris@45
|
1335 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok);
|
Chris@72
|
1336 if (ok) m_currentTransform.setStepSize(stepSize);
|
Chris@45
|
1337
|
Chris@45
|
1338 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok);
|
Chris@72
|
1339 if (ok) m_currentTransform.setBlockSize(blockSize);
|
Chris@45
|
1340
|
Chris@45
|
1341 int windowType = attributes.value("windowType").trimmed().toInt(&ok);
|
Chris@72
|
1342 if (ok) m_currentTransform.setWindowType(WindowType(windowType));
|
Chris@72
|
1343
|
Chris@685
|
1344 auto currentTransformSourceModel = ModelById::get(m_currentTransformSource);
|
Chris@685
|
1345 if (!currentTransformSourceModel) return true;
|
Chris@685
|
1346
|
Chris@685
|
1347 sv_samplerate_t sampleRate = currentTransformSourceModel->getSampleRate();
|
Chris@45
|
1348
|
Chris@45
|
1349 QString startFrameStr = attributes.value("startFrame");
|
Chris@45
|
1350 QString durationStr = attributes.value("duration");
|
Chris@45
|
1351
|
Chris@366
|
1352 int startFrame = 0;
|
Chris@366
|
1353 int duration = 0;
|
Chris@45
|
1354
|
Chris@45
|
1355 if (startFrameStr != "") {
|
Chris@45
|
1356 startFrame = startFrameStr.trimmed().toInt(&ok);
|
Chris@45
|
1357 if (!ok) startFrame = 0;
|
Chris@45
|
1358 }
|
Chris@45
|
1359 if (durationStr != "") {
|
Chris@45
|
1360 duration = durationStr.trimmed().toInt(&ok);
|
Chris@45
|
1361 if (!ok) duration = 0;
|
Chris@45
|
1362 }
|
Chris@45
|
1363
|
Chris@72
|
1364 m_currentTransform.setStartTime
|
Chris@685
|
1365 (RealTime::frame2RealTime(startFrame, sampleRate));
|
Chris@72
|
1366
|
Chris@72
|
1367 m_currentTransform.setDuration
|
Chris@685
|
1368 (RealTime::frame2RealTime(duration, sampleRate));
|
Chris@45
|
1369
|
Chris@45
|
1370 return true;
|
Chris@45
|
1371 }
|
Chris@45
|
1372
|
Chris@45
|
1373 bool
|
Chris@45
|
1374 SVFileReader::readPlayParameters(const QXmlAttributes &attributes)
|
Chris@45
|
1375 {
|
Chris@636
|
1376 m_currentPlayParameters = nullptr;
|
Chris@45
|
1377
|
Chris@685
|
1378 int modelExportId = 0;
|
Chris@45
|
1379 bool modelOk = false;
|
Chris@685
|
1380 modelExportId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@45
|
1381
|
Chris@45
|
1382 if (!modelOk) {
|
Chris@601
|
1383 SVCERR << "WARNING: SV-XML: No model id specified for play parameters" << endl;
|
Chris@595
|
1384 return false;
|
Chris@45
|
1385 }
|
Chris@45
|
1386
|
Chris@685
|
1387 if (haveModel(modelExportId)) {
|
Chris@45
|
1388
|
Chris@45
|
1389 bool ok = false;
|
Chris@45
|
1390
|
Chris@45
|
1391 PlayParameters *parameters = PlayParameterRepository::getInstance()->
|
Chris@685
|
1392 getPlayParameters(m_models[modelExportId].untyped);
|
Chris@45
|
1393
|
Chris@45
|
1394 if (!parameters) {
|
Chris@601
|
1395 SVCERR << "WARNING: SV-XML: Play parameters for model "
|
Chris@685
|
1396 << modelExportId
|
Chris@45
|
1397 << " not found - has model been added to document?"
|
Chris@293
|
1398 << endl;
|
Chris@45
|
1399 return false;
|
Chris@45
|
1400 }
|
Chris@45
|
1401
|
Chris@45
|
1402 bool muted = (attributes.value("mute").trimmed() == "true");
|
Chris@45
|
1403 parameters->setPlayMuted(muted);
|
Chris@45
|
1404
|
Chris@45
|
1405 float pan = attributes.value("pan").toFloat(&ok);
|
Chris@45
|
1406 if (ok) parameters->setPlayPan(pan);
|
Chris@45
|
1407
|
Chris@45
|
1408 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@45
|
1409 if (ok) parameters->setPlayGain(gain);
|
Chris@45
|
1410
|
Chris@309
|
1411 QString clipId = attributes.value("clipId");
|
Chris@309
|
1412 if (clipId != "") parameters->setPlayClipId(clipId);
|
Chris@45
|
1413
|
Chris@45
|
1414 m_currentPlayParameters = parameters;
|
Chris@45
|
1415
|
Chris@685
|
1416 // SVCERR << "Current play parameters for model: " << m_models[modelExportId] << ": " << m_currentPlayParameters << endl;
|
Chris@45
|
1417
|
Chris@45
|
1418 } else {
|
Chris@45
|
1419
|
Chris@685
|
1420 SVCERR << "WARNING: SV-XML: Unknown model " << modelExportId
|
Chris@685
|
1421 << " for play parameters" << endl;
|
Chris@45
|
1422 return false;
|
Chris@45
|
1423 }
|
Chris@45
|
1424
|
Chris@45
|
1425 return true;
|
Chris@45
|
1426 }
|
Chris@45
|
1427
|
Chris@45
|
1428 bool
|
Chris@45
|
1429 SVFileReader::readPlugin(const QXmlAttributes &attributes)
|
Chris@45
|
1430 {
|
Chris@685
|
1431 if (m_pendingDerivedModel != XmlExportable::NO_ID) {
|
Chris@308
|
1432 return readPluginForTransform(attributes);
|
Chris@308
|
1433 } else if (m_currentPlayParameters) {
|
Chris@308
|
1434 return readPluginForPlayback(attributes);
|
Chris@308
|
1435 } else {
|
Chris@601
|
1436 SVCERR << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << endl;
|
Chris@45
|
1437 return false;
|
Chris@45
|
1438 }
|
Chris@308
|
1439 }
|
Chris@45
|
1440
|
Chris@308
|
1441 bool
|
Chris@308
|
1442 SVFileReader::readPluginForTransform(const QXmlAttributes &attributes)
|
Chris@308
|
1443 {
|
Chris@308
|
1444 if (m_currentTransformIsNewStyle) {
|
Chris@308
|
1445 // Not needed, we have the transform element instead
|
Chris@72
|
1446 return true;
|
Chris@72
|
1447 }
|
Chris@72
|
1448
|
Chris@45
|
1449 QString configurationXml = "<plugin";
|
Chris@308
|
1450
|
Chris@45
|
1451 for (int i = 0; i < attributes.length(); ++i) {
|
Chris@45
|
1452 configurationXml += QString(" %1=\"%2\"")
|
Chris@45
|
1453 .arg(attributes.qName(i))
|
Chris@45
|
1454 .arg(XmlExportable::encodeEntities(attributes.value(i)));
|
Chris@45
|
1455 }
|
Chris@45
|
1456
|
Chris@45
|
1457 configurationXml += "/>";
|
Chris@45
|
1458
|
Chris@308
|
1459 TransformFactory::getInstance()->
|
Chris@308
|
1460 setParametersFromPluginConfigurationXml(m_currentTransform,
|
Chris@308
|
1461 configurationXml);
|
Chris@308
|
1462 return true;
|
Chris@308
|
1463 }
|
Chris@308
|
1464
|
Chris@308
|
1465 bool
|
Chris@308
|
1466 SVFileReader::readPluginForPlayback(const QXmlAttributes &attributes)
|
Chris@308
|
1467 {
|
Chris@308
|
1468 // Obsolete but supported for compatibility
|
Chris@308
|
1469
|
Chris@308
|
1470 QString ident = attributes.value("identifier");
|
Chris@308
|
1471 if (ident == "sample_player") {
|
Chris@309
|
1472 QString clipId = attributes.value("program");
|
Chris@309
|
1473 if (clipId != "") m_currentPlayParameters->setPlayClipId(clipId);
|
Chris@45
|
1474 }
|
Chris@45
|
1475
|
Chris@45
|
1476 return true;
|
Chris@45
|
1477 }
|
Chris@45
|
1478
|
Chris@45
|
1479 bool
|
Chris@72
|
1480 SVFileReader::readTransform(const QXmlAttributes &attributes)
|
Chris@72
|
1481 {
|
Chris@685
|
1482 if (m_pendingDerivedModel == XmlExportable::NO_ID) {
|
Chris@601
|
1483 SVCERR << "WARNING: SV-XML: Transform found outside derivation" << endl;
|
Chris@72
|
1484 return false;
|
Chris@72
|
1485 }
|
Chris@72
|
1486
|
Chris@82
|
1487 m_currentTransform = Transform();
|
Chris@72
|
1488 m_currentTransform.setFromXmlAttributes(attributes);
|
Chris@72
|
1489 return true;
|
Chris@72
|
1490 }
|
Chris@72
|
1491
|
Chris@72
|
1492 bool
|
Chris@72
|
1493 SVFileReader::readParameter(const QXmlAttributes &attributes)
|
Chris@72
|
1494 {
|
Chris@685
|
1495 if (m_pendingDerivedModel == XmlExportable::NO_ID) {
|
Chris@601
|
1496 SVCERR << "WARNING: SV-XML: Parameter found outside derivation" << endl;
|
Chris@72
|
1497 return false;
|
Chris@72
|
1498 }
|
Chris@72
|
1499
|
Chris@72
|
1500 QString name = attributes.value("name");
|
Chris@72
|
1501 if (name == "") {
|
Chris@601
|
1502 SVCERR << "WARNING: SV-XML: Ignoring nameless transform parameter"
|
Chris@293
|
1503 << endl;
|
Chris@72
|
1504 return false;
|
Chris@72
|
1505 }
|
Chris@72
|
1506
|
Chris@72
|
1507 float value = attributes.value("value").trimmed().toFloat();
|
Chris@72
|
1508
|
Chris@72
|
1509 m_currentTransform.setParameter(name, value);
|
Chris@72
|
1510 return true;
|
Chris@72
|
1511 }
|
Chris@72
|
1512
|
Chris@72
|
1513 bool
|
Chris@45
|
1514 SVFileReader::readSelection(const QXmlAttributes &attributes)
|
Chris@45
|
1515 {
|
Chris@45
|
1516 bool ok;
|
Chris@45
|
1517
|
Chris@45
|
1518 READ_MANDATORY(int, start, toInt);
|
Chris@45
|
1519 READ_MANDATORY(int, end, toInt);
|
Chris@45
|
1520
|
Chris@45
|
1521 m_paneCallback.addSelection(start, end);
|
Chris@45
|
1522
|
Chris@45
|
1523 return true;
|
Chris@45
|
1524 }
|
Chris@45
|
1525
|
Chris@45
|
1526 bool
|
Chris@45
|
1527 SVFileReader::readMeasurement(const QXmlAttributes &attributes)
|
Chris@45
|
1528 {
|
Chris@233
|
1529 SVDEBUG << "SVFileReader::readMeasurement: inLayer "
|
Chris@229
|
1530 << m_inLayer << ", layer " << m_currentLayer << endl;
|
Chris@45
|
1531
|
Chris@45
|
1532 if (!m_inLayer) {
|
Chris@601
|
1533 SVCERR << "WARNING: SV-XML: Measurement found outside layer" << endl;
|
Chris@45
|
1534 return false;
|
Chris@45
|
1535 }
|
Chris@45
|
1536
|
Chris@45
|
1537 m_currentLayer->addMeasurementRect(attributes);
|
Chris@45
|
1538 return true;
|
Chris@45
|
1539 }
|
Chris@45
|
1540
|
Chris@45
|
1541 SVFileReaderPaneCallback::~SVFileReaderPaneCallback()
|
Chris@45
|
1542 {
|
Chris@45
|
1543 }
|
Chris@45
|
1544
|
Chris@140
|
1545
|
Chris@140
|
1546 class SVFileIdentifier : public QXmlDefaultHandler
|
Chris@140
|
1547 {
|
Chris@140
|
1548 public:
|
Chris@140
|
1549 SVFileIdentifier() :
|
Chris@140
|
1550 m_inSv(false),
|
Chris@140
|
1551 m_inData(false),
|
Chris@140
|
1552 m_type(SVFileReader::UnknownFileType)
|
Chris@140
|
1553 { }
|
Chris@633
|
1554 ~SVFileIdentifier() override { }
|
Chris@140
|
1555
|
Chris@140
|
1556 void parse(QXmlInputSource &source) {
|
Chris@140
|
1557 QXmlSimpleReader reader;
|
Chris@140
|
1558 reader.setContentHandler(this);
|
Chris@140
|
1559 reader.setErrorHandler(this);
|
Chris@140
|
1560 reader.parse(source);
|
Chris@140
|
1561 }
|
Chris@140
|
1562
|
Chris@140
|
1563 SVFileReader::FileType getType() const { return m_type; }
|
Chris@140
|
1564
|
Chris@633
|
1565 bool startElement(const QString &,
|
Chris@595
|
1566 const QString &,
|
Chris@595
|
1567 const QString &qName,
|
Chris@633
|
1568 const QXmlAttributes& atts) override
|
Chris@140
|
1569 {
|
Chris@140
|
1570 QString name = qName.toLower();
|
Chris@140
|
1571
|
Chris@140
|
1572 // SV session files have an sv element containing a data
|
Chris@140
|
1573 // element containing a model element with mainModel="true".
|
Chris@140
|
1574
|
Chris@140
|
1575 // If the sv element is present but the rest does not satisfy,
|
Chris@140
|
1576 // then it's (probably) an SV layer file.
|
Chris@140
|
1577
|
Chris@140
|
1578 // Otherwise, it's of unknown type.
|
Chris@140
|
1579
|
Chris@140
|
1580 if (name == "sv") {
|
Chris@140
|
1581 m_inSv = true;
|
Chris@140
|
1582 if (m_type == SVFileReader::UnknownFileType) {
|
Chris@140
|
1583 m_type = SVFileReader::SVLayerFile;
|
Chris@140
|
1584 }
|
Chris@140
|
1585 return true;
|
Chris@140
|
1586 } else if (name == "data") {
|
Chris@140
|
1587 if (!m_inSv) return true;
|
Chris@140
|
1588 m_inData = true;
|
Chris@140
|
1589 } else if (name == "model") {
|
Chris@140
|
1590 if (!m_inData) return true;
|
Chris@140
|
1591 if (atts.value("mainModel").trimmed() == "true") {
|
Chris@140
|
1592 if (m_type == SVFileReader::SVLayerFile) {
|
Chris@140
|
1593 m_type = SVFileReader::SVSessionFile;
|
Chris@140
|
1594 return false; // done
|
Chris@140
|
1595 }
|
Chris@140
|
1596 }
|
Chris@140
|
1597 }
|
Chris@140
|
1598 return true;
|
Chris@140
|
1599 }
|
Chris@140
|
1600
|
Chris@633
|
1601 bool endElement(const QString &,
|
Chris@595
|
1602 const QString &,
|
Chris@633
|
1603 const QString &qName) override
|
Chris@140
|
1604 {
|
Chris@140
|
1605 QString name = qName.toLower();
|
Chris@140
|
1606
|
Chris@140
|
1607 if (name == "sv") {
|
Chris@140
|
1608 if (m_inSv) {
|
Chris@140
|
1609 m_inSv = false;
|
Chris@140
|
1610 return false; // done
|
Chris@140
|
1611 }
|
Chris@140
|
1612 } else if (name == "data") {
|
Chris@140
|
1613 if (m_inData) {
|
Chris@140
|
1614 m_inData = false;
|
Chris@140
|
1615 return false; // also done, nothing after the first
|
Chris@140
|
1616 // data element is of use here
|
Chris@140
|
1617 }
|
Chris@140
|
1618 }
|
Chris@140
|
1619 return true;
|
Chris@140
|
1620 }
|
Chris@140
|
1621
|
Chris@140
|
1622 private:
|
Chris@140
|
1623 bool m_inSv;
|
Chris@140
|
1624 bool m_inData;
|
Chris@140
|
1625 SVFileReader::FileType m_type;
|
Chris@140
|
1626 };
|
Chris@140
|
1627
|
Chris@140
|
1628
|
Chris@140
|
1629 SVFileReader::FileType
|
Chris@140
|
1630 SVFileReader::identifyXmlFile(QString path)
|
Chris@140
|
1631 {
|
Chris@140
|
1632 QFile file(path);
|
Chris@140
|
1633 SVFileIdentifier identifier;
|
Chris@140
|
1634 QXmlInputSource source(&file);
|
Chris@140
|
1635 identifier.parse(source);
|
Chris@140
|
1636 return identifier.getType();
|
Chris@140
|
1637 }
|
Chris@140
|
1638
|
Chris@140
|
1639
|
Chris@140
|
1640
|