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