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@685
|
487 m_document->addImportedModel(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@685
|
567 ModelId modelId = model->getId();
|
Chris@685
|
568 ModelById::add(std::shared_ptr<Model>(model));
|
Chris@685
|
569 m_models[id] = modelId;
|
Chris@685
|
570
|
Chris@595
|
571 if (isMainModel) {
|
Chris@685
|
572 m_document->setMainModel(modelId);
|
Chris@685
|
573 m_addedModels.insert(modelId);
|
Chris@595
|
574 }
|
Chris@595
|
575 // Derived models will be added when their derivation
|
Chris@595
|
576 // is found.
|
Chris@45
|
577
|
Chris@595
|
578 return true;
|
Chris@45
|
579
|
Chris@629
|
580 } else if (type == "aggregatewave") {
|
Chris@629
|
581
|
Chris@629
|
582 QString components = attributes.value("components");
|
Chris@629
|
583 QStringList componentIdStrings = components.split(",");
|
Chris@629
|
584 std::vector<int> componentIds;
|
Chris@685
|
585 for (auto cidStr: componentIdStrings) {
|
Chris@629
|
586 bool ok = false;
|
Chris@685
|
587 int cid = cidStr.toInt(&ok);
|
Chris@629
|
588 if (!ok) {
|
Chris@685
|
589 SVCERR << "SVFileReader::readModel: Failed to convert component model id from part \"" << cidStr << "\" in \"" << components << "\"" << endl;
|
Chris@629
|
590 } else {
|
Chris@685
|
591 componentIds.push_back(cid);
|
Chris@629
|
592 }
|
Chris@629
|
593 }
|
Chris@629
|
594 PendingAggregateRec rec { name, sampleRate, componentIds };
|
Chris@629
|
595 m_pendingAggregates[id] = rec;
|
Chris@629
|
596
|
Chris@629
|
597 // The aggregate model will be constructed from its pending
|
Chris@629
|
598 // record in makeAggregateModels; it can't happen here because
|
Chris@629
|
599 // the component models might not all have been observed yet
|
Chris@629
|
600 // (an unfortunate accident of the way the file is written)
|
Chris@629
|
601
|
Chris@629
|
602 return true;
|
Chris@629
|
603
|
Chris@45
|
604 } else if (type == "dense") {
|
Chris@595
|
605
|
Chris@595
|
606 READ_MANDATORY(int, dimensions, toInt);
|
Chris@595
|
607
|
Chris@595
|
608 // Currently the only dense model we support here is the dense
|
Chris@595
|
609 // 3d model. Dense time-value models are always file-backed
|
Chris@595
|
610 // waveform data, at this point, and they come in as wavefile
|
Chris@595
|
611 // models.
|
Chris@595
|
612
|
Chris@595
|
613 if (dimensions == 3) {
|
Chris@595
|
614
|
Chris@595
|
615 READ_MANDATORY(int, windowSize, toInt);
|
Chris@595
|
616 READ_MANDATORY(int, yBinCount, toInt);
|
Chris@595
|
617
|
Chris@685
|
618 auto model = std::make_shared<EditableDenseThreeDimensionalModel>
|
Chris@153
|
619 (sampleRate, windowSize, yBinCount,
|
Chris@153
|
620 EditableDenseThreeDimensionalModel::NoCompression);
|
Chris@685
|
621
|
Chris@685
|
622 model->setObjectName(name);
|
Chris@685
|
623 m_models[id] = ModelById::add(model);
|
Chris@595
|
624
|
Chris@595
|
625 float minimum = attributes.value("minimum").trimmed().toFloat(&ok);
|
Chris@595
|
626 if (ok) model->setMinimumLevel(minimum);
|
Chris@595
|
627
|
Chris@595
|
628 float maximum = attributes.value("maximum").trimmed().toFloat(&ok);
|
Chris@595
|
629 if (ok) model->setMaximumLevel(maximum);
|
Chris@45
|
630
|
Chris@595
|
631 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@595
|
632 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@45
|
633
|
Chris@181
|
634 int startFrame = attributes.value("startFrame").trimmed().toInt(&ok);
|
Chris@181
|
635 if (ok) model->setStartFrame(startFrame);
|
Chris@181
|
636
|
Chris@595
|
637 return true;
|
Chris@45
|
638
|
Chris@595
|
639 } else {
|
Chris@45
|
640
|
Chris@601
|
641 SVCERR << "WARNING: SV-XML: Unexpected dense model dimension ("
|
Chris@595
|
642 << dimensions << ")" << endl;
|
Chris@595
|
643 }
|
Chris@45
|
644 } else if (type == "sparse") {
|
Chris@45
|
645
|
Chris@595
|
646 READ_MANDATORY(int, dimensions, toInt);
|
Chris@595
|
647
|
Chris@595
|
648 if (dimensions == 1) {
|
Chris@595
|
649
|
Chris@595
|
650 READ_MANDATORY(int, resolution, toInt);
|
Chris@685
|
651
|
Chris@45
|
652 if (attributes.value("subtype") == "image") {
|
Chris@45
|
653
|
Chris@45
|
654 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
|
Chris@685
|
655 auto model = std::make_shared<ImageModel>
|
Chris@685
|
656 (sampleRate, resolution, notifyOnAdd);
|
Chris@45
|
657 model->setObjectName(name);
|
Chris@685
|
658 m_models[id] = ModelById::add(model);
|
Chris@45
|
659
|
Chris@45
|
660 } else {
|
Chris@45
|
661
|
Chris@685
|
662 auto model = std::make_shared<SparseOneDimensionalModel>
|
Chris@45
|
663 (sampleRate, resolution);
|
Chris@45
|
664 model->setObjectName(name);
|
Chris@685
|
665 m_models[id] = ModelById::add(model);
|
Chris@45
|
666 }
|
Chris@45
|
667
|
Chris@595
|
668 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@595
|
669 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@45
|
670
|
Chris@595
|
671 return true;
|
Chris@45
|
672
|
Chris@595
|
673 } else if (dimensions == 2 || dimensions == 3) {
|
Chris@595
|
674
|
Chris@595
|
675 READ_MANDATORY(int, resolution, toInt);
|
Chris@45
|
676
|
Chris@45
|
677 bool haveMinMax = true;
|
Chris@595
|
678 float minimum = attributes.value("minimum").trimmed().toFloat(&ok);
|
Chris@45
|
679 if (!ok) haveMinMax = false;
|
Chris@595
|
680 float maximum = attributes.value("maximum").trimmed().toFloat(&ok);
|
Chris@45
|
681 if (!ok) haveMinMax = false;
|
Chris@45
|
682
|
Chris@595
|
683 float valueQuantization =
|
Chris@595
|
684 attributes.value("valueQuantization").trimmed().toFloat(&ok);
|
Chris@45
|
685
|
Chris@595
|
686 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
|
Chris@45
|
687
|
Chris@45
|
688 QString units = attributes.value("units");
|
Chris@45
|
689
|
Chris@595
|
690 if (dimensions == 2) {
|
Chris@595
|
691 if (attributes.value("subtype") == "text") {
|
Chris@685
|
692 auto model = std::make_shared<TextModel>
|
Chris@595
|
693 (sampleRate, resolution, notifyOnAdd);
|
Chris@45
|
694 model->setObjectName(name);
|
Chris@685
|
695 m_models[id] = ModelById::add(model);
|
Chris@111
|
696 } else if (attributes.value("subtype") == "path") {
|
Chris@685
|
697 // Paths are no longer actually models
|
Chris@685
|
698 Path *path = new Path(sampleRate, resolution);
|
Chris@685
|
699 m_paths[id] = path;
|
Chris@595
|
700 } else {
|
Chris@685
|
701 std::shared_ptr<SparseTimeValueModel> model;
|
Chris@45
|
702 if (haveMinMax) {
|
Chris@685
|
703 model = std::make_shared<SparseTimeValueModel>
|
Chris@685
|
704 (sampleRate, resolution, minimum, maximum,
|
Chris@685
|
705 notifyOnAdd);
|
Chris@45
|
706 } else {
|
Chris@685
|
707 model = std::make_shared<SparseTimeValueModel>
|
Chris@45
|
708 (sampleRate, resolution, notifyOnAdd);
|
Chris@45
|
709 }
|
Chris@45
|
710 model->setScaleUnits(units);
|
Chris@45
|
711 model->setObjectName(name);
|
Chris@685
|
712 m_models[id] = ModelById::add(model);
|
Chris@595
|
713 }
|
Chris@595
|
714 } else {
|
Chris@137
|
715 if (attributes.value("subtype") == "region") {
|
Chris@685
|
716 std::shared_ptr<RegionModel> model;
|
Chris@137
|
717 if (haveMinMax) {
|
Chris@685
|
718 model = std::make_shared<RegionModel>
|
Chris@685
|
719 (sampleRate, resolution, minimum, maximum,
|
Chris@685
|
720 notifyOnAdd);
|
Chris@137
|
721 } else {
|
Chris@685
|
722 model = std::make_shared<RegionModel>
|
Chris@137
|
723 (sampleRate, resolution, notifyOnAdd);
|
Chris@137
|
724 }
|
Chris@137
|
725 model->setValueQuantization(valueQuantization);
|
Chris@137
|
726 model->setScaleUnits(units);
|
Chris@137
|
727 model->setObjectName(name);
|
Chris@685
|
728 m_models[id] = ModelById::add(model);
|
Chris@343
|
729 } else if (attributes.value("subtype") == "flexinote") {
|
Chris@685
|
730 std::shared_ptr<NoteModel> model;
|
Chris@343
|
731 if (haveMinMax) {
|
Chris@685
|
732 model = std::make_shared<NoteModel>
|
Chris@646
|
733 (sampleRate, resolution, minimum, maximum,
|
Chris@646
|
734 notifyOnAdd,
|
Chris@646
|
735 NoteModel::FLEXI_NOTE);
|
Chris@343
|
736 } else {
|
Chris@685
|
737 model = std::make_shared<NoteModel>
|
Chris@646
|
738 (sampleRate, resolution, notifyOnAdd,
|
Chris@646
|
739 NoteModel::FLEXI_NOTE);
|
Chris@343
|
740 }
|
Chris@343
|
741 model->setValueQuantization(valueQuantization);
|
Chris@343
|
742 model->setScaleUnits(units);
|
Chris@343
|
743 model->setObjectName(name);
|
Chris@685
|
744 m_models[id] = ModelById::add(model);
|
Chris@45
|
745 } else {
|
Chris@137
|
746 // note models written out by SV 1.3 and earlier
|
Chris@137
|
747 // have no subtype, so we can't test that
|
Chris@685
|
748 std::shared_ptr<NoteModel> model;
|
Chris@137
|
749 if (haveMinMax) {
|
Chris@685
|
750 model = std::make_shared<NoteModel>
|
Chris@137
|
751 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
|
Chris@137
|
752 } else {
|
Chris@685
|
753 model = std::make_shared<NoteModel>
|
Chris@137
|
754 (sampleRate, resolution, notifyOnAdd);
|
Chris@137
|
755 }
|
Chris@137
|
756 model->setValueQuantization(valueQuantization);
|
Chris@137
|
757 model->setScaleUnits(units);
|
Chris@137
|
758 model->setObjectName(name);
|
Chris@685
|
759 m_models[id] = ModelById::add(model);
|
Chris@45
|
760 }
|
Chris@137
|
761 }
|
Chris@45
|
762
|
Chris@595
|
763 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@595
|
764 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@45
|
765
|
Chris@595
|
766 return true;
|
Chris@45
|
767
|
Chris@595
|
768 } else {
|
Chris@45
|
769
|
Chris@601
|
770 SVCERR << "WARNING: SV-XML: Unexpected sparse model dimension ("
|
Chris@595
|
771 << dimensions << ")" << endl;
|
Chris@595
|
772 }
|
Chris@111
|
773
|
Chris@111
|
774 } else if (type == "alignment") {
|
Chris@111
|
775
|
Chris@111
|
776 READ_MANDATORY(int, reference, toInt);
|
Chris@111
|
777 READ_MANDATORY(int, aligned, toInt);
|
Chris@111
|
778 READ_MANDATORY(int, path, toInt);
|
Chris@111
|
779
|
Chris@685
|
780 ModelId refModel, alignedModel;
|
Chris@685
|
781 Path *pathPtr = nullptr;
|
Chris@111
|
782
|
Chris@111
|
783 if (m_models.find(reference) != m_models.end()) {
|
Chris@111
|
784 refModel = m_models[reference];
|
Chris@111
|
785 } else {
|
Chris@601
|
786 SVCERR << "WARNING: SV-XML: Unknown reference model id "
|
Chris@111
|
787 << reference << " in alignment model id " << id
|
Chris@293
|
788 << endl;
|
Chris@111
|
789 }
|
Chris@111
|
790
|
Chris@111
|
791 if (m_models.find(aligned) != m_models.end()) {
|
Chris@111
|
792 alignedModel = m_models[aligned];
|
Chris@111
|
793 } else {
|
Chris@601
|
794 SVCERR << "WARNING: SV-XML: Unknown aligned model id "
|
Chris@111
|
795 << aligned << " in alignment model id " << id
|
Chris@293
|
796 << endl;
|
Chris@111
|
797 }
|
Chris@111
|
798
|
Chris@685
|
799 if (m_paths.find(path) != m_paths.end()) {
|
Chris@685
|
800 pathPtr = m_paths[path];
|
Chris@111
|
801 } else {
|
Chris@685
|
802 SVCERR << "WARNING: SV-XML: Unknown path id "
|
Chris@111
|
803 << path << " in alignment model id " << id
|
Chris@293
|
804 << endl;
|
Chris@111
|
805 }
|
Chris@111
|
806
|
Chris@685
|
807 if (!refModel.isNone() && !alignedModel.isNone() && pathPtr) {
|
Chris@685
|
808 auto model = std::make_shared<AlignmentModel>
|
Chris@685
|
809 (refModel, alignedModel, ModelId());
|
Chris@685
|
810 model->setPath(*pathPtr);
|
Chris@685
|
811 model->setObjectName(name);
|
Chris@685
|
812 m_models[id] = ModelById::add(model);
|
Chris@685
|
813 if (auto am = ModelById::get(alignedModel)) {
|
Chris@685
|
814 am->setAlignment(m_models[id]);
|
Chris@111
|
815 }
|
Chris@111
|
816 return true;
|
Chris@111
|
817 }
|
Chris@685
|
818
|
Chris@685
|
819 if (pathPtr) {
|
Chris@685
|
820 delete pathPtr;
|
Chris@685
|
821 m_paths.erase(path);
|
Chris@685
|
822 }
|
Chris@111
|
823
|
Chris@45
|
824 } else {
|
Chris@45
|
825
|
Chris@590
|
826 SVCERR << "WARNING: SV-XML: Unexpected model type \""
|
Chris@590
|
827 << type << "\" for model id " << id << endl;
|
Chris@45
|
828 }
|
Chris@45
|
829
|
Chris@45
|
830 return false;
|
Chris@45
|
831 }
|
Chris@45
|
832
|
Chris@45
|
833 bool
|
Chris@45
|
834 SVFileReader::readView(const QXmlAttributes &attributes)
|
Chris@45
|
835 {
|
Chris@45
|
836 QString type = attributes.value("type");
|
Chris@636
|
837 m_currentPane = nullptr;
|
Chris@45
|
838
|
Chris@45
|
839 if (type != "pane") {
|
Chris@601
|
840 SVCERR << "WARNING: SV-XML: Unexpected view type \""
|
Chris@595
|
841 << type << "\"" << endl;
|
Chris@595
|
842 return false;
|
Chris@45
|
843 }
|
Chris@45
|
844
|
Chris@45
|
845 m_currentPane = m_paneCallback.addPane();
|
Chris@45
|
846
|
Chris@630
|
847 SVDEBUG << "SVFileReader::addPane: pane is " << m_currentPane << endl;
|
Chris@342
|
848
|
Chris@45
|
849 if (!m_currentPane) {
|
Chris@601
|
850 SVCERR << "WARNING: SV-XML: Internal error: Failed to add pane!"
|
Chris@595
|
851 << endl;
|
Chris@595
|
852 return false;
|
Chris@45
|
853 }
|
Chris@45
|
854
|
Chris@45
|
855 bool ok = false;
|
Chris@45
|
856
|
Chris@45
|
857 View *view = m_currentPane;
|
Chris@45
|
858
|
Chris@45
|
859 // The view properties first
|
Chris@45
|
860
|
Chris@366
|
861 READ_MANDATORY(int, centre, toInt);
|
Chris@366
|
862 READ_MANDATORY(int, zoom, toInt);
|
Chris@45
|
863 READ_MANDATORY(int, followPan, toInt);
|
Chris@45
|
864 READ_MANDATORY(int, followZoom, toInt);
|
Chris@45
|
865 QString tracking = attributes.value("tracking");
|
Chris@45
|
866
|
Chris@624
|
867 ZoomLevel zoomLevel;
|
Chris@624
|
868 int deepZoom = attributes.value("deepZoom").trimmed().toInt(&ok);
|
Chris@624
|
869 if (ok && zoom == 1 && deepZoom > 1) {
|
Chris@624
|
870 zoomLevel = { ZoomLevel::PixelsPerFrame, deepZoom };
|
Chris@624
|
871 } else {
|
Chris@624
|
872 zoomLevel = { ZoomLevel::FramesPerPixel, zoom };
|
Chris@624
|
873 }
|
Chris@624
|
874
|
Chris@45
|
875 // Specify the follow modes before we set the actual values
|
Chris@45
|
876 view->setFollowGlobalPan(followPan);
|
Chris@45
|
877 view->setFollowGlobalZoom(followZoom);
|
Chris@45
|
878 view->setPlaybackFollow(tracking == "scroll" ? PlaybackScrollContinuous :
|
Chris@595
|
879 tracking == "page" ? PlaybackScrollPageWithCentre :
|
Chris@595
|
880 tracking == "daw" ? PlaybackScrollPage
|
Chris@595
|
881 : PlaybackIgnore);
|
Chris@45
|
882
|
Chris@45
|
883 // Then set these values
|
Chris@45
|
884 view->setCentreFrame(centre);
|
Chris@624
|
885 view->setZoomLevel(zoomLevel);
|
Chris@45
|
886
|
Chris@45
|
887 // And pane properties
|
Chris@45
|
888 READ_MANDATORY(int, centreLineVisible, toInt);
|
Chris@45
|
889 m_currentPane->setCentreLineVisible(centreLineVisible);
|
Chris@45
|
890
|
Chris@45
|
891 int height = attributes.value("height").toInt(&ok);
|
Chris@45
|
892 if (ok) {
|
Chris@595
|
893 m_currentPane->resize(m_currentPane->width(), height);
|
Chris@45
|
894 }
|
Chris@45
|
895
|
Chris@45
|
896 return true;
|
Chris@45
|
897 }
|
Chris@45
|
898
|
Chris@45
|
899 bool
|
Chris@45
|
900 SVFileReader::readLayer(const QXmlAttributes &attributes)
|
Chris@45
|
901 {
|
Chris@45
|
902 QString type = attributes.value("type");
|
Chris@45
|
903
|
Chris@45
|
904 int id;
|
Chris@45
|
905 bool ok = false;
|
Chris@45
|
906 id = attributes.value("id").trimmed().toInt(&ok);
|
Chris@45
|
907
|
Chris@45
|
908 if (!ok) {
|
Chris@601
|
909 SVCERR << "WARNING: SV-XML: No layer id for layer of type \""
|
Chris@595
|
910 << type
|
Chris@595
|
911 << "\"" << endl;
|
Chris@595
|
912 return false;
|
Chris@45
|
913 }
|
Chris@45
|
914
|
Chris@636
|
915 Layer *layer = nullptr;
|
Chris@45
|
916 bool isNewLayer = false;
|
Chris@45
|
917
|
Chris@45
|
918 // Layers are expected to be defined in layer elements in the data
|
Chris@45
|
919 // section, and referred to in layer elements in the view
|
Chris@45
|
920 // sections. So if we're in the data section, we expect this
|
Chris@45
|
921 // layer not to exist already; if we're in the view section, we
|
Chris@45
|
922 // expect it to exist.
|
Chris@45
|
923
|
Chris@45
|
924 if (m_inData) {
|
Chris@45
|
925
|
Chris@595
|
926 if (m_layers.find(id) != m_layers.end()) {
|
Chris@601
|
927 SVCERR << "WARNING: SV-XML: Ignoring duplicate layer id " << id
|
Chris@595
|
928 << " in data section" << endl;
|
Chris@595
|
929 return false;
|
Chris@595
|
930 }
|
Chris@45
|
931
|
Chris@595
|
932 layer = m_layers[id] = m_document->createLayer
|
Chris@595
|
933 (LayerFactory::getInstance()->getLayerTypeForName(type));
|
Chris@45
|
934
|
Chris@595
|
935 if (layer) {
|
Chris@595
|
936 m_layers[id] = layer;
|
Chris@595
|
937 isNewLayer = true;
|
Chris@595
|
938 }
|
Chris@45
|
939
|
Chris@45
|
940 } else {
|
Chris@45
|
941
|
Chris@595
|
942 if (!m_currentPane) {
|
Chris@601
|
943 SVCERR << "WARNING: SV-XML: No current pane for layer " << id
|
Chris@595
|
944 << " in view section" << endl;
|
Chris@595
|
945 return false;
|
Chris@595
|
946 }
|
Chris@45
|
947
|
Chris@595
|
948 if (m_layers.find(id) != m_layers.end()) {
|
Chris@595
|
949
|
Chris@595
|
950 layer = m_layers[id];
|
Chris@595
|
951
|
Chris@595
|
952 } else {
|
Chris@601
|
953 SVCERR << "WARNING: SV-XML: Layer id " << id
|
Chris@595
|
954 << " in view section has not been defined -- defining it here"
|
Chris@595
|
955 << endl;
|
Chris@45
|
956
|
Chris@595
|
957 layer = m_document->createLayer
|
Chris@595
|
958 (LayerFactory::getInstance()->getLayerTypeForName(type));
|
Chris@45
|
959
|
Chris@595
|
960 if (layer) {
|
Chris@595
|
961 m_layers[id] = layer;
|
Chris@595
|
962 isNewLayer = true;
|
Chris@595
|
963 }
|
Chris@595
|
964 }
|
Chris@45
|
965 }
|
Chris@595
|
966
|
Chris@45
|
967 if (!layer) {
|
Chris@601
|
968 SVCERR << "WARNING: SV-XML: Failed to add layer of type \""
|
Chris@595
|
969 << type
|
Chris@595
|
970 << "\"" << endl;
|
Chris@595
|
971 return false;
|
Chris@45
|
972 }
|
Chris@45
|
973
|
Chris@45
|
974 if (isNewLayer) {
|
Chris@45
|
975
|
Chris@595
|
976 QString name = attributes.value("name");
|
Chris@595
|
977 layer->setObjectName(name);
|
Chris@45
|
978
|
Chris@89
|
979 QString presentationName = attributes.value("presentationName");
|
Chris@89
|
980 layer->setPresentationName(presentationName);
|
Chris@89
|
981
|
Chris@595
|
982 int modelId;
|
Chris@595
|
983 bool modelOk = false;
|
Chris@595
|
984 modelId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@45
|
985
|
Chris@595
|
986 if (modelOk) {
|
Chris@595
|
987 if (haveModel(modelId)) {
|
Chris@685
|
988 m_document->setModel(layer, m_models[modelId]);
|
Chris@595
|
989 } else {
|
Chris@601
|
990 SVCERR << "WARNING: SV-XML: Unknown model id " << modelId
|
Chris@685
|
991 << " in layer definition" << endl;
|
Chris@451
|
992 if (!layer->canExistWithoutModel()) {
|
Chris@451
|
993 // Don't add a layer with an unknown model id
|
Chris@451
|
994 // unless it explicitly supports this state
|
Chris@451
|
995 m_document->deleteLayer(layer);
|
Chris@636
|
996 m_layers[id] = layer = nullptr;
|
Chris@451
|
997 return false;
|
Chris@451
|
998 }
|
Chris@451
|
999 }
|
Chris@595
|
1000 }
|
Chris@45
|
1001
|
Chris@447
|
1002 if (layer) layer->setProperties(attributes);
|
Chris@45
|
1003 }
|
Chris@45
|
1004
|
Chris@447
|
1005 if (!m_inData && m_currentPane && layer) {
|
Chris@45
|
1006
|
Chris@45
|
1007 QString visible = attributes.value("visible");
|
Chris@45
|
1008 bool dormant = (visible == "false");
|
Chris@45
|
1009
|
Chris@45
|
1010 // We need to do this both before and after adding the layer
|
Chris@45
|
1011 // to the view -- we need it to be dormant if appropriate
|
Chris@45
|
1012 // before it's actually added to the view so that any property
|
Chris@45
|
1013 // box gets the right state when it's added, but the add layer
|
Chris@45
|
1014 // command sets dormant to false because it assumes it may be
|
Chris@45
|
1015 // restoring a previously dormant layer, so we need to set it
|
Chris@45
|
1016 // again afterwards too. Hm
|
Chris@45
|
1017 layer->setLayerDormant(m_currentPane, dormant);
|
Chris@45
|
1018
|
Chris@595
|
1019 m_document->addLayerToView(m_currentPane, layer);
|
Chris@45
|
1020
|
Chris@45
|
1021 layer->setLayerDormant(m_currentPane, dormant);
|
Chris@45
|
1022 }
|
Chris@45
|
1023
|
Chris@45
|
1024 m_currentLayer = layer;
|
Chris@636
|
1025 m_inLayer = (layer != nullptr);
|
Chris@45
|
1026
|
Chris@45
|
1027 return true;
|
Chris@45
|
1028 }
|
Chris@45
|
1029
|
Chris@45
|
1030 bool
|
Chris@45
|
1031 SVFileReader::readDatasetStart(const QXmlAttributes &attributes)
|
Chris@45
|
1032 {
|
Chris@45
|
1033 bool ok = false;
|
Chris@45
|
1034
|
Chris@45
|
1035 READ_MANDATORY(int, id, toInt);
|
Chris@45
|
1036 READ_MANDATORY(int, dimensions, toInt);
|
Chris@45
|
1037
|
Chris@45
|
1038 if (m_awaitingDatasets.find(id) == m_awaitingDatasets.end()) {
|
Chris@601
|
1039 SVCERR << "WARNING: SV-XML: Unwanted dataset " << id << endl;
|
Chris@595
|
1040 return false;
|
Chris@45
|
1041 }
|
Chris@45
|
1042
|
Chris@685
|
1043 int awaitingId = m_awaitingDatasets[id];
|
Chris@685
|
1044
|
Chris@685
|
1045 ModelId modelId;
|
Chris@685
|
1046 Path *path = nullptr;
|
Chris@45
|
1047
|
Chris@685
|
1048 if (haveModel(awaitingId)) {
|
Chris@685
|
1049 modelId = m_models[awaitingId];
|
Chris@685
|
1050 } else if (m_paths.find(awaitingId) != m_paths.end()) {
|
Chris@685
|
1051 path = m_paths[awaitingId];
|
Chris@45
|
1052 } else {
|
Chris@685
|
1053 SVCERR << "WARNING: SV-XML: Internal error: Unknown model or path "
|
Chris@685
|
1054 << modelId << " awaiting dataset " << id << endl;
|
Chris@595
|
1055 return false;
|
Chris@45
|
1056 }
|
Chris@45
|
1057
|
Chris@45
|
1058 bool good = false;
|
Chris@45
|
1059
|
Chris@45
|
1060 switch (dimensions) {
|
Chris@45
|
1061 case 1:
|
Chris@685
|
1062 good =
|
Chris@685
|
1063 (ModelById::isa<SparseOneDimensionalModel>(modelId) ||
|
Chris@685
|
1064 ModelById::isa<ImageModel>(modelId));
|
Chris@595
|
1065 break;
|
Chris@45
|
1066
|
Chris@45
|
1067 case 2:
|
Chris@685
|
1068 good =
|
Chris@685
|
1069 (ModelById::isa<SparseTimeValueModel>(modelId) ||
|
Chris@685
|
1070 ModelById::isa<TextModel>(modelId) ||
|
Chris@685
|
1071 path);
|
Chris@595
|
1072 break;
|
Chris@45
|
1073
|
Chris@45
|
1074 case 3:
|
Chris@685
|
1075 if (ModelById::isa<EditableDenseThreeDimensionalModel>(modelId)) {
|
Chris@685
|
1076 good = true;
|
Chris@595
|
1077 m_datasetSeparator = attributes.value("separator");
|
Chris@685
|
1078 } else {
|
Chris@685
|
1079 good =
|
Chris@685
|
1080 (ModelById::isa<NoteModel>(modelId) ||
|
Chris@685
|
1081 ModelById::isa<RegionModel>(modelId));
|
Chris@595
|
1082 }
|
Chris@595
|
1083 break;
|
Chris@45
|
1084 }
|
Chris@45
|
1085
|
Chris@45
|
1086 if (!good) {
|
Chris@601
|
1087 SVCERR << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions or inappropriate type for " << dimensions << "-D dataset " << id << endl;
|
Chris@685
|
1088 m_currentDataset = XmlExportable::NO_ID;
|
Chris@595
|
1089 return false;
|
Chris@45
|
1090 }
|
Chris@45
|
1091
|
Chris@685
|
1092 m_currentDataset = awaitingId;
|
Chris@45
|
1093 return true;
|
Chris@45
|
1094 }
|
Chris@45
|
1095
|
Chris@45
|
1096 bool
|
Chris@45
|
1097 SVFileReader::addPointToDataset(const QXmlAttributes &attributes)
|
Chris@45
|
1098 {
|
Chris@45
|
1099 bool ok = false;
|
Chris@45
|
1100
|
Chris@45
|
1101 READ_MANDATORY(int, frame, toInt);
|
Chris@45
|
1102
|
Chris@685
|
1103 if (m_paths.find(m_currentDataset) != m_paths.end()) {
|
Chris@685
|
1104 Path *path = m_paths[m_currentDataset];
|
Chris@685
|
1105 int mapframe = attributes.value("mapframe").trimmed().toInt(&ok);
|
Chris@685
|
1106 path->add(PathPoint(frame, mapframe));
|
Chris@685
|
1107 return ok;
|
Chris@685
|
1108 }
|
Chris@45
|
1109
|
Chris@685
|
1110 if (!haveModel(m_currentDataset)) {
|
Chris@685
|
1111 SVCERR << "WARNING: SV-XML: Point element found in non-point dataset"
|
Chris@685
|
1112 << endl;
|
Chris@685
|
1113 return false;
|
Chris@685
|
1114 }
|
Chris@685
|
1115
|
Chris@685
|
1116 ModelId modelId = m_models[m_currentDataset];
|
Chris@45
|
1117
|
Chris@685
|
1118 if (auto sodm = ModelById::getAs<SparseOneDimensionalModel>(modelId)) {
|
Chris@595
|
1119 QString label = attributes.value("label");
|
Chris@651
|
1120 sodm->add(Event(frame, label));
|
Chris@595
|
1121 return true;
|
Chris@45
|
1122 }
|
Chris@45
|
1123
|
Chris@685
|
1124 if (auto stvm = ModelById::getAs<SparseTimeValueModel>(modelId)) {
|
Chris@595
|
1125 float value = 0.0;
|
Chris@595
|
1126 value = attributes.value("value").trimmed().toFloat(&ok);
|
Chris@595
|
1127 QString label = attributes.value("label");
|
Chris@649
|
1128 stvm->add(Event(frame, value, label));
|
Chris@595
|
1129 return ok;
|
Chris@45
|
1130 }
|
Chris@595
|
1131
|
Chris@685
|
1132 if (auto nm = ModelById::getAs<NoteModel>(modelId)) {
|
Chris@595
|
1133 float value = 0.0;
|
Chris@595
|
1134 value = attributes.value("value").trimmed().toFloat(&ok);
|
Chris@595
|
1135 int duration = 0;
|
Chris@595
|
1136 duration = attributes.value("duration").trimmed().toInt(&ok);
|
Chris@595
|
1137 QString label = attributes.value("label");
|
Chris@61
|
1138 float level = attributes.value("level").trimmed().toFloat(&ok);
|
Chris@61
|
1139 if (!ok) { // level is optional
|
Chris@61
|
1140 level = 1.f;
|
Chris@61
|
1141 ok = true;
|
Chris@61
|
1142 }
|
Chris@646
|
1143 nm->add(Event(frame, value, duration, level, label));
|
Chris@595
|
1144 return ok;
|
Chris@343
|
1145 }
|
Chris@343
|
1146
|
Chris@685
|
1147 if (auto rm = ModelById::getAs<RegionModel>(modelId)) {
|
Chris@595
|
1148 float value = 0.0;
|
Chris@595
|
1149 value = attributes.value("value").trimmed().toFloat(&ok);
|
Chris@595
|
1150 int duration = 0;
|
Chris@595
|
1151 duration = attributes.value("duration").trimmed().toInt(&ok);
|
Chris@595
|
1152 QString label = attributes.value("label");
|
Chris@648
|
1153 rm->add(Event(frame, value, duration, label));
|
Chris@595
|
1154 return ok;
|
Chris@137
|
1155 }
|
Chris@137
|
1156
|
Chris@685
|
1157 if (auto tm = ModelById::getAs<TextModel>(modelId)) {
|
Chris@595
|
1158 float height = 0.0;
|
Chris@595
|
1159 height = attributes.value("height").trimmed().toFloat(&ok);
|
Chris@595
|
1160 QString label = attributes.value("label");
|
Chris@652
|
1161 tm->add(Event(frame, height, label));
|
Chris@595
|
1162 return ok;
|
Chris@45
|
1163 }
|
Chris@45
|
1164
|
Chris@685
|
1165 if (auto im = ModelById::getAs<ImageModel>(modelId)) {
|
Chris@595
|
1166 QString image = attributes.value("image");
|
Chris@595
|
1167 QString label = attributes.value("label");
|
Chris@653
|
1168 im->add(Event(frame).withURI(image).withLabel(label));
|
Chris@595
|
1169 return ok;
|
Chris@45
|
1170 }
|
Chris@45
|
1171
|
Chris@685
|
1172 SVCERR << "WARNING: SV-XML: Point element found in non-point dataset"
|
Chris@685
|
1173 << endl;
|
Chris@45
|
1174
|
Chris@45
|
1175 return false;
|
Chris@45
|
1176 }
|
Chris@45
|
1177
|
Chris@45
|
1178 bool
|
Chris@45
|
1179 SVFileReader::addBinToDataset(const QXmlAttributes &attributes)
|
Chris@45
|
1180 {
|
Chris@685
|
1181 if (!haveModel(m_currentDataset)) {
|
Chris@685
|
1182 SVCERR << "WARNING: SV-XML: Bin definition found in incompatible dataset"
|
Chris@685
|
1183 << endl;
|
Chris@685
|
1184 return false;
|
Chris@685
|
1185 }
|
Chris@685
|
1186
|
Chris@685
|
1187 ModelId modelId = m_models[m_currentDataset];
|
Chris@45
|
1188
|
Chris@685
|
1189 if (auto dtdm = ModelById::getAs<EditableDenseThreeDimensionalModel>
|
Chris@685
|
1190 (modelId)) {
|
Chris@45
|
1191
|
Chris@595
|
1192 bool ok = false;
|
Chris@595
|
1193 int n = attributes.value("number").trimmed().toInt(&ok);
|
Chris@595
|
1194 if (!ok) {
|
Chris@601
|
1195 SVCERR << "WARNING: SV-XML: Missing or invalid bin number"
|
Chris@595
|
1196 << endl;
|
Chris@595
|
1197 return false;
|
Chris@595
|
1198 }
|
Chris@45
|
1199
|
Chris@595
|
1200 QString name = attributes.value("name");
|
Chris@595
|
1201 dtdm->setBinName(n, name);
|
Chris@595
|
1202 return true;
|
Chris@45
|
1203 }
|
Chris@45
|
1204
|
Chris@685
|
1205 SVCERR << "WARNING: SV-XML: Bin definition found in incompatible dataset"
|
Chris@685
|
1206 << endl;
|
Chris@45
|
1207
|
Chris@45
|
1208 return false;
|
Chris@45
|
1209 }
|
Chris@45
|
1210
|
Chris@45
|
1211
|
Chris@45
|
1212 bool
|
Chris@45
|
1213 SVFileReader::addRowToDataset(const QXmlAttributes &attributes)
|
Chris@45
|
1214 {
|
Chris@45
|
1215 m_inRow = false;
|
Chris@45
|
1216
|
Chris@45
|
1217 bool ok = false;
|
Chris@45
|
1218 m_rowNumber = attributes.value("n").trimmed().toInt(&ok);
|
Chris@45
|
1219 if (!ok) {
|
Chris@601
|
1220 SVCERR << "WARNING: SV-XML: Missing or invalid row number"
|
Chris@595
|
1221 << endl;
|
Chris@595
|
1222 return false;
|
Chris@45
|
1223 }
|
Chris@45
|
1224
|
Chris@45
|
1225 m_inRow = true;
|
Chris@45
|
1226
|
Chris@601
|
1227 // SVCERR << "SV-XML: In row " << m_rowNumber << endl;
|
Chris@45
|
1228
|
Chris@45
|
1229 return true;
|
Chris@45
|
1230 }
|
Chris@45
|
1231
|
Chris@45
|
1232 bool
|
Chris@45
|
1233 SVFileReader::readRowData(const QString &text)
|
Chris@45
|
1234 {
|
Chris@685
|
1235 if (!haveModel(m_currentDataset)) {
|
Chris@685
|
1236 SVCERR << "WARNING: SV-XML: Row data found in non-row dataset" << endl;
|
Chris@685
|
1237 return false;
|
Chris@685
|
1238 }
|
Chris@685
|
1239
|
Chris@685
|
1240 ModelId modelId = m_models[m_currentDataset];
|
Chris@45
|
1241 bool warned = false;
|
Chris@45
|
1242
|
Chris@685
|
1243 if (auto dtdm = ModelById::getAs<EditableDenseThreeDimensionalModel>
|
Chris@685
|
1244 (modelId)) {
|
Chris@685
|
1245
|
Chris@595
|
1246 QStringList data = text.split(m_datasetSeparator);
|
Chris@45
|
1247
|
Chris@595
|
1248 DenseThreeDimensionalModel::Column values;
|
Chris@45
|
1249
|
Chris@595
|
1250 for (QStringList::iterator i = data.begin(); i != data.end(); ++i) {
|
Chris@45
|
1251
|
Chris@595
|
1252 if (int(values.size()) == dtdm->getHeight()) {
|
Chris@595
|
1253 if (!warned) {
|
Chris@601
|
1254 SVCERR << "WARNING: SV-XML: Too many y-bins in 3-D dataset row "
|
Chris@595
|
1255 << m_rowNumber << endl;
|
Chris@595
|
1256 warned = true;
|
Chris@595
|
1257 }
|
Chris@595
|
1258 }
|
Chris@45
|
1259
|
Chris@595
|
1260 bool ok;
|
Chris@595
|
1261 float value = i->toFloat(&ok);
|
Chris@595
|
1262 if (!ok) {
|
Chris@601
|
1263 SVCERR << "WARNING: SV-XML: Bad floating-point value "
|
Chris@595
|
1264 << i->toLocal8Bit().data()
|
Chris@595
|
1265 << " in row data" << endl;
|
Chris@595
|
1266 } else {
|
Chris@595
|
1267 values.push_back(value);
|
Chris@595
|
1268 }
|
Chris@595
|
1269 }
|
Chris@45
|
1270
|
Chris@595
|
1271 dtdm->setColumn(m_rowNumber, values);
|
Chris@595
|
1272 return true;
|
Chris@45
|
1273 }
|
Chris@45
|
1274
|
Chris@601
|
1275 SVCERR << "WARNING: SV-XML: Row data found in non-row dataset" << endl;
|
Chris@45
|
1276 return false;
|
Chris@45
|
1277 }
|
Chris@45
|
1278
|
Chris@45
|
1279 bool
|
Chris@45
|
1280 SVFileReader::readDerivation(const QXmlAttributes &attributes)
|
Chris@45
|
1281 {
|
Chris@685
|
1282 int modelExportId = 0;
|
Chris@45
|
1283 bool modelOk = false;
|
Chris@685
|
1284 modelExportId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@45
|
1285
|
Chris@45
|
1286 if (!modelOk) {
|
Chris@601
|
1287 SVCERR << "WARNING: SV-XML: No model id specified for derivation" << endl;
|
Chris@595
|
1288 return false;
|
Chris@45
|
1289 }
|
Chris@45
|
1290
|
Chris@685
|
1291 if (haveModel(modelExportId)) {
|
Chris@685
|
1292 m_currentDerivedModel = m_models[modelExportId];
|
Chris@45
|
1293 } else {
|
Chris@45
|
1294 // we'll regenerate the model when the derivation element ends
|
Chris@685
|
1295 m_currentDerivedModel = {};
|
Chris@45
|
1296 }
|
Chris@45
|
1297
|
Chris@685
|
1298 m_pendingDerivedModel = modelExportId;
|
Chris@45
|
1299
|
Chris@45
|
1300 int sourceId = 0;
|
Chris@45
|
1301 bool sourceOk = false;
|
Chris@45
|
1302 sourceId = attributes.value("source").trimmed().toInt(&sourceOk);
|
Chris@45
|
1303
|
Chris@45
|
1304 if (sourceOk && haveModel(sourceId)) {
|
Chris@72
|
1305 m_currentTransformSource = m_models[sourceId];
|
Chris@45
|
1306 } else {
|
Chris@585
|
1307 SVDEBUG << "NOTE: SV-XML: Can't find a model with id " << sourceId
|
Chris@585
|
1308 << " for derivation source, falling back to main model" << endl;
|
Chris@72
|
1309 m_currentTransformSource = m_document->getMainModel();
|
Chris@45
|
1310 }
|
Chris@45
|
1311
|
Chris@72
|
1312 m_currentTransform = Transform();
|
Chris@45
|
1313
|
Chris@45
|
1314 bool ok = false;
|
Chris@45
|
1315 int channel = attributes.value("channel").trimmed().toInt(&ok);
|
Chris@72
|
1316 if (ok) m_currentTransformChannel = channel;
|
Chris@72
|
1317 else m_currentTransformChannel = -1;
|
Chris@45
|
1318
|
Chris@72
|
1319 QString type = attributes.value("type");
|
Chris@72
|
1320
|
Chris@72
|
1321 if (type == "transform") {
|
Chris@72
|
1322 m_currentTransformIsNewStyle = true;
|
Chris@72
|
1323 return true;
|
Chris@72
|
1324 } else {
|
Chris@72
|
1325 m_currentTransformIsNewStyle = false;
|
Chris@233
|
1326 SVDEBUG << "NOTE: SV-XML: Reading old-style derivation element"
|
Chris@229
|
1327 << endl;
|
Chris@72
|
1328 }
|
Chris@72
|
1329
|
Chris@72
|
1330 QString transformId = attributes.value("transform");
|
Chris@72
|
1331
|
Chris@72
|
1332 m_currentTransform.setIdentifier(transformId);
|
Chris@45
|
1333
|
Chris@45
|
1334 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok);
|
Chris@72
|
1335 if (ok) m_currentTransform.setStepSize(stepSize);
|
Chris@45
|
1336
|
Chris@45
|
1337 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok);
|
Chris@72
|
1338 if (ok) m_currentTransform.setBlockSize(blockSize);
|
Chris@45
|
1339
|
Chris@45
|
1340 int windowType = attributes.value("windowType").trimmed().toInt(&ok);
|
Chris@72
|
1341 if (ok) m_currentTransform.setWindowType(WindowType(windowType));
|
Chris@72
|
1342
|
Chris@685
|
1343 auto currentTransformSourceModel = ModelById::get(m_currentTransformSource);
|
Chris@685
|
1344 if (!currentTransformSourceModel) return true;
|
Chris@685
|
1345
|
Chris@685
|
1346 sv_samplerate_t sampleRate = currentTransformSourceModel->getSampleRate();
|
Chris@45
|
1347
|
Chris@45
|
1348 QString startFrameStr = attributes.value("startFrame");
|
Chris@45
|
1349 QString durationStr = attributes.value("duration");
|
Chris@45
|
1350
|
Chris@366
|
1351 int startFrame = 0;
|
Chris@366
|
1352 int duration = 0;
|
Chris@45
|
1353
|
Chris@45
|
1354 if (startFrameStr != "") {
|
Chris@45
|
1355 startFrame = startFrameStr.trimmed().toInt(&ok);
|
Chris@45
|
1356 if (!ok) startFrame = 0;
|
Chris@45
|
1357 }
|
Chris@45
|
1358 if (durationStr != "") {
|
Chris@45
|
1359 duration = durationStr.trimmed().toInt(&ok);
|
Chris@45
|
1360 if (!ok) duration = 0;
|
Chris@45
|
1361 }
|
Chris@45
|
1362
|
Chris@72
|
1363 m_currentTransform.setStartTime
|
Chris@685
|
1364 (RealTime::frame2RealTime(startFrame, sampleRate));
|
Chris@72
|
1365
|
Chris@72
|
1366 m_currentTransform.setDuration
|
Chris@685
|
1367 (RealTime::frame2RealTime(duration, sampleRate));
|
Chris@45
|
1368
|
Chris@45
|
1369 return true;
|
Chris@45
|
1370 }
|
Chris@45
|
1371
|
Chris@45
|
1372 bool
|
Chris@45
|
1373 SVFileReader::readPlayParameters(const QXmlAttributes &attributes)
|
Chris@45
|
1374 {
|
Chris@686
|
1375 m_currentPlayParameters = {};
|
Chris@45
|
1376
|
Chris@685
|
1377 int modelExportId = 0;
|
Chris@45
|
1378 bool modelOk = false;
|
Chris@685
|
1379 modelExportId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@45
|
1380
|
Chris@45
|
1381 if (!modelOk) {
|
Chris@601
|
1382 SVCERR << "WARNING: SV-XML: No model id specified for play parameters" << endl;
|
Chris@595
|
1383 return false;
|
Chris@45
|
1384 }
|
Chris@45
|
1385
|
Chris@685
|
1386 if (haveModel(modelExportId)) {
|
Chris@45
|
1387
|
Chris@45
|
1388 bool ok = false;
|
Chris@45
|
1389
|
Chris@686
|
1390 auto parameters = PlayParameterRepository::getInstance()->
|
Chris@685
|
1391 getPlayParameters(m_models[modelExportId].untyped);
|
Chris@45
|
1392
|
Chris@45
|
1393 if (!parameters) {
|
Chris@601
|
1394 SVCERR << "WARNING: SV-XML: Play parameters for model "
|
Chris@685
|
1395 << modelExportId
|
Chris@45
|
1396 << " not found - has model been added to document?"
|
Chris@293
|
1397 << endl;
|
Chris@45
|
1398 return false;
|
Chris@45
|
1399 }
|
Chris@45
|
1400
|
Chris@45
|
1401 bool muted = (attributes.value("mute").trimmed() == "true");
|
Chris@45
|
1402 parameters->setPlayMuted(muted);
|
Chris@45
|
1403
|
Chris@45
|
1404 float pan = attributes.value("pan").toFloat(&ok);
|
Chris@45
|
1405 if (ok) parameters->setPlayPan(pan);
|
Chris@45
|
1406
|
Chris@45
|
1407 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@45
|
1408 if (ok) parameters->setPlayGain(gain);
|
Chris@45
|
1409
|
Chris@309
|
1410 QString clipId = attributes.value("clipId");
|
Chris@309
|
1411 if (clipId != "") parameters->setPlayClipId(clipId);
|
Chris@45
|
1412
|
Chris@45
|
1413 m_currentPlayParameters = parameters;
|
Chris@45
|
1414
|
Chris@685
|
1415 // SVCERR << "Current play parameters for model: " << m_models[modelExportId] << ": " << m_currentPlayParameters << endl;
|
Chris@45
|
1416
|
Chris@45
|
1417 } else {
|
Chris@45
|
1418
|
Chris@685
|
1419 SVCERR << "WARNING: SV-XML: Unknown model " << modelExportId
|
Chris@685
|
1420 << " for play parameters" << endl;
|
Chris@45
|
1421 return false;
|
Chris@45
|
1422 }
|
Chris@45
|
1423
|
Chris@45
|
1424 return true;
|
Chris@45
|
1425 }
|
Chris@45
|
1426
|
Chris@45
|
1427 bool
|
Chris@45
|
1428 SVFileReader::readPlugin(const QXmlAttributes &attributes)
|
Chris@45
|
1429 {
|
Chris@685
|
1430 if (m_pendingDerivedModel != XmlExportable::NO_ID) {
|
Chris@308
|
1431 return readPluginForTransform(attributes);
|
Chris@308
|
1432 } else if (m_currentPlayParameters) {
|
Chris@308
|
1433 return readPluginForPlayback(attributes);
|
Chris@308
|
1434 } else {
|
Chris@601
|
1435 SVCERR << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << endl;
|
Chris@45
|
1436 return false;
|
Chris@45
|
1437 }
|
Chris@308
|
1438 }
|
Chris@45
|
1439
|
Chris@308
|
1440 bool
|
Chris@308
|
1441 SVFileReader::readPluginForTransform(const QXmlAttributes &attributes)
|
Chris@308
|
1442 {
|
Chris@308
|
1443 if (m_currentTransformIsNewStyle) {
|
Chris@308
|
1444 // Not needed, we have the transform element instead
|
Chris@72
|
1445 return true;
|
Chris@72
|
1446 }
|
Chris@72
|
1447
|
Chris@45
|
1448 QString configurationXml = "<plugin";
|
Chris@308
|
1449
|
Chris@45
|
1450 for (int i = 0; i < attributes.length(); ++i) {
|
Chris@45
|
1451 configurationXml += QString(" %1=\"%2\"")
|
Chris@45
|
1452 .arg(attributes.qName(i))
|
Chris@45
|
1453 .arg(XmlExportable::encodeEntities(attributes.value(i)));
|
Chris@45
|
1454 }
|
Chris@45
|
1455
|
Chris@45
|
1456 configurationXml += "/>";
|
Chris@45
|
1457
|
Chris@308
|
1458 TransformFactory::getInstance()->
|
Chris@308
|
1459 setParametersFromPluginConfigurationXml(m_currentTransform,
|
Chris@308
|
1460 configurationXml);
|
Chris@308
|
1461 return true;
|
Chris@308
|
1462 }
|
Chris@308
|
1463
|
Chris@308
|
1464 bool
|
Chris@308
|
1465 SVFileReader::readPluginForPlayback(const QXmlAttributes &attributes)
|
Chris@308
|
1466 {
|
Chris@308
|
1467 // Obsolete but supported for compatibility
|
Chris@308
|
1468
|
Chris@308
|
1469 QString ident = attributes.value("identifier");
|
Chris@308
|
1470 if (ident == "sample_player") {
|
Chris@309
|
1471 QString clipId = attributes.value("program");
|
Chris@309
|
1472 if (clipId != "") m_currentPlayParameters->setPlayClipId(clipId);
|
Chris@45
|
1473 }
|
Chris@45
|
1474
|
Chris@45
|
1475 return true;
|
Chris@45
|
1476 }
|
Chris@45
|
1477
|
Chris@45
|
1478 bool
|
Chris@72
|
1479 SVFileReader::readTransform(const QXmlAttributes &attributes)
|
Chris@72
|
1480 {
|
Chris@685
|
1481 if (m_pendingDerivedModel == XmlExportable::NO_ID) {
|
Chris@601
|
1482 SVCERR << "WARNING: SV-XML: Transform found outside derivation" << endl;
|
Chris@72
|
1483 return false;
|
Chris@72
|
1484 }
|
Chris@72
|
1485
|
Chris@82
|
1486 m_currentTransform = Transform();
|
Chris@72
|
1487 m_currentTransform.setFromXmlAttributes(attributes);
|
Chris@72
|
1488 return true;
|
Chris@72
|
1489 }
|
Chris@72
|
1490
|
Chris@72
|
1491 bool
|
Chris@72
|
1492 SVFileReader::readParameter(const QXmlAttributes &attributes)
|
Chris@72
|
1493 {
|
Chris@685
|
1494 if (m_pendingDerivedModel == XmlExportable::NO_ID) {
|
Chris@601
|
1495 SVCERR << "WARNING: SV-XML: Parameter found outside derivation" << endl;
|
Chris@72
|
1496 return false;
|
Chris@72
|
1497 }
|
Chris@72
|
1498
|
Chris@72
|
1499 QString name = attributes.value("name");
|
Chris@72
|
1500 if (name == "") {
|
Chris@601
|
1501 SVCERR << "WARNING: SV-XML: Ignoring nameless transform parameter"
|
Chris@293
|
1502 << endl;
|
Chris@72
|
1503 return false;
|
Chris@72
|
1504 }
|
Chris@72
|
1505
|
Chris@72
|
1506 float value = attributes.value("value").trimmed().toFloat();
|
Chris@72
|
1507
|
Chris@72
|
1508 m_currentTransform.setParameter(name, value);
|
Chris@72
|
1509 return true;
|
Chris@72
|
1510 }
|
Chris@72
|
1511
|
Chris@72
|
1512 bool
|
Chris@45
|
1513 SVFileReader::readSelection(const QXmlAttributes &attributes)
|
Chris@45
|
1514 {
|
Chris@45
|
1515 bool ok;
|
Chris@45
|
1516
|
Chris@45
|
1517 READ_MANDATORY(int, start, toInt);
|
Chris@45
|
1518 READ_MANDATORY(int, end, toInt);
|
Chris@45
|
1519
|
Chris@45
|
1520 m_paneCallback.addSelection(start, end);
|
Chris@45
|
1521
|
Chris@45
|
1522 return true;
|
Chris@45
|
1523 }
|
Chris@45
|
1524
|
Chris@45
|
1525 bool
|
Chris@45
|
1526 SVFileReader::readMeasurement(const QXmlAttributes &attributes)
|
Chris@45
|
1527 {
|
Chris@233
|
1528 SVDEBUG << "SVFileReader::readMeasurement: inLayer "
|
Chris@229
|
1529 << m_inLayer << ", layer " << m_currentLayer << endl;
|
Chris@45
|
1530
|
Chris@45
|
1531 if (!m_inLayer) {
|
Chris@601
|
1532 SVCERR << "WARNING: SV-XML: Measurement found outside layer" << endl;
|
Chris@45
|
1533 return false;
|
Chris@45
|
1534 }
|
Chris@45
|
1535
|
Chris@45
|
1536 m_currentLayer->addMeasurementRect(attributes);
|
Chris@45
|
1537 return true;
|
Chris@45
|
1538 }
|
Chris@45
|
1539
|
Chris@45
|
1540 SVFileReaderPaneCallback::~SVFileReaderPaneCallback()
|
Chris@45
|
1541 {
|
Chris@45
|
1542 }
|
Chris@45
|
1543
|
Chris@140
|
1544
|
Chris@140
|
1545 class SVFileIdentifier : public QXmlDefaultHandler
|
Chris@140
|
1546 {
|
Chris@140
|
1547 public:
|
Chris@140
|
1548 SVFileIdentifier() :
|
Chris@140
|
1549 m_inSv(false),
|
Chris@140
|
1550 m_inData(false),
|
Chris@140
|
1551 m_type(SVFileReader::UnknownFileType)
|
Chris@140
|
1552 { }
|
Chris@633
|
1553 ~SVFileIdentifier() override { }
|
Chris@140
|
1554
|
Chris@140
|
1555 void parse(QXmlInputSource &source) {
|
Chris@140
|
1556 QXmlSimpleReader reader;
|
Chris@140
|
1557 reader.setContentHandler(this);
|
Chris@140
|
1558 reader.setErrorHandler(this);
|
Chris@140
|
1559 reader.parse(source);
|
Chris@140
|
1560 }
|
Chris@140
|
1561
|
Chris@140
|
1562 SVFileReader::FileType getType() const { return m_type; }
|
Chris@140
|
1563
|
Chris@633
|
1564 bool startElement(const QString &,
|
Chris@595
|
1565 const QString &,
|
Chris@595
|
1566 const QString &qName,
|
Chris@633
|
1567 const QXmlAttributes& atts) override
|
Chris@140
|
1568 {
|
Chris@140
|
1569 QString name = qName.toLower();
|
Chris@140
|
1570
|
Chris@140
|
1571 // SV session files have an sv element containing a data
|
Chris@140
|
1572 // element containing a model element with mainModel="true".
|
Chris@140
|
1573
|
Chris@140
|
1574 // If the sv element is present but the rest does not satisfy,
|
Chris@140
|
1575 // then it's (probably) an SV layer file.
|
Chris@140
|
1576
|
Chris@140
|
1577 // Otherwise, it's of unknown type.
|
Chris@140
|
1578
|
Chris@140
|
1579 if (name == "sv") {
|
Chris@140
|
1580 m_inSv = true;
|
Chris@140
|
1581 if (m_type == SVFileReader::UnknownFileType) {
|
Chris@140
|
1582 m_type = SVFileReader::SVLayerFile;
|
Chris@140
|
1583 }
|
Chris@140
|
1584 return true;
|
Chris@140
|
1585 } else if (name == "data") {
|
Chris@140
|
1586 if (!m_inSv) return true;
|
Chris@140
|
1587 m_inData = true;
|
Chris@140
|
1588 } else if (name == "model") {
|
Chris@140
|
1589 if (!m_inData) return true;
|
Chris@140
|
1590 if (atts.value("mainModel").trimmed() == "true") {
|
Chris@140
|
1591 if (m_type == SVFileReader::SVLayerFile) {
|
Chris@140
|
1592 m_type = SVFileReader::SVSessionFile;
|
Chris@140
|
1593 return false; // done
|
Chris@140
|
1594 }
|
Chris@140
|
1595 }
|
Chris@140
|
1596 }
|
Chris@140
|
1597 return true;
|
Chris@140
|
1598 }
|
Chris@140
|
1599
|
Chris@633
|
1600 bool endElement(const QString &,
|
Chris@595
|
1601 const QString &,
|
Chris@633
|
1602 const QString &qName) override
|
Chris@140
|
1603 {
|
Chris@140
|
1604 QString name = qName.toLower();
|
Chris@140
|
1605
|
Chris@140
|
1606 if (name == "sv") {
|
Chris@140
|
1607 if (m_inSv) {
|
Chris@140
|
1608 m_inSv = false;
|
Chris@140
|
1609 return false; // done
|
Chris@140
|
1610 }
|
Chris@140
|
1611 } else if (name == "data") {
|
Chris@140
|
1612 if (m_inData) {
|
Chris@140
|
1613 m_inData = false;
|
Chris@140
|
1614 return false; // also done, nothing after the first
|
Chris@140
|
1615 // data element is of use here
|
Chris@140
|
1616 }
|
Chris@140
|
1617 }
|
Chris@140
|
1618 return true;
|
Chris@140
|
1619 }
|
Chris@140
|
1620
|
Chris@140
|
1621 private:
|
Chris@140
|
1622 bool m_inSv;
|
Chris@140
|
1623 bool m_inData;
|
Chris@140
|
1624 SVFileReader::FileType m_type;
|
Chris@140
|
1625 };
|
Chris@140
|
1626
|
Chris@140
|
1627
|
Chris@140
|
1628 SVFileReader::FileType
|
Chris@140
|
1629 SVFileReader::identifyXmlFile(QString path)
|
Chris@140
|
1630 {
|
Chris@140
|
1631 QFile file(path);
|
Chris@140
|
1632 SVFileIdentifier identifier;
|
Chris@140
|
1633 QXmlInputSource source(&file);
|
Chris@140
|
1634 identifier.parse(source);
|
Chris@140
|
1635 return identifier.getType();
|
Chris@140
|
1636 }
|
Chris@140
|
1637
|
Chris@140
|
1638
|
Chris@140
|
1639
|