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