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