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