Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 Sonic Visualiser
|
Chris@0
|
5 An audio file viewer and annotation editor.
|
Chris@0
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@77
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@0
|
8
|
Chris@0
|
9 This program is free software; you can redistribute it and/or
|
Chris@0
|
10 modify it under the terms of the GNU General Public License as
|
Chris@0
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@0
|
12 License, or (at your option) any later version. See the file
|
Chris@0
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "SVFileReader.h"
|
Chris@0
|
17
|
Chris@1
|
18 #include "layer/Layer.h"
|
Chris@1
|
19 #include "view/View.h"
|
Chris@0
|
20 #include "base/PlayParameters.h"
|
Chris@0
|
21 #include "base/PlayParameterRepository.h"
|
Chris@0
|
22
|
Chris@1
|
23 #include "data/fileio/AudioFileReaderFactory.h"
|
Chris@87
|
24 #include "data/fileio/FileFinder.h"
|
Chris@87
|
25 #include "data/fileio/RemoteFile.h"
|
Chris@0
|
26
|
Chris@1
|
27 #include "data/model/WaveFileModel.h"
|
Chris@3
|
28 #include "data/model/EditableDenseThreeDimensionalModel.h"
|
Chris@1
|
29 #include "data/model/SparseOneDimensionalModel.h"
|
Chris@1
|
30 #include "data/model/SparseTimeValueModel.h"
|
Chris@1
|
31 #include "data/model/NoteModel.h"
|
Chris@1
|
32 #include "data/model/TextModel.h"
|
Chris@0
|
33
|
Chris@1
|
34 #include "view/Pane.h"
|
Chris@0
|
35
|
Chris@1
|
36 #include "Document.h"
|
Chris@0
|
37
|
Chris@0
|
38 #include <QString>
|
Chris@0
|
39 #include <QMessageBox>
|
Chris@0
|
40 #include <QFileDialog>
|
Chris@0
|
41
|
Chris@0
|
42 #include <iostream>
|
Chris@0
|
43
|
Chris@0
|
44 SVFileReader::SVFileReader(Document *document,
|
Chris@87
|
45 SVFileReaderPaneCallback &callback,
|
Chris@87
|
46 QString location) :
|
Chris@0
|
47 m_document(document),
|
Chris@0
|
48 m_paneCallback(callback),
|
Chris@87
|
49 m_location(location),
|
Chris@0
|
50 m_currentPane(0),
|
Chris@0
|
51 m_currentDataset(0),
|
Chris@0
|
52 m_currentDerivedModel(0),
|
Chris@55
|
53 m_currentDerivedModelId(-1),
|
Chris@0
|
54 m_currentPlayParameters(0),
|
Chris@0
|
55 m_datasetSeparator(" "),
|
Chris@0
|
56 m_inRow(false),
|
Chris@154
|
57 m_inLayer(false),
|
Chris@154
|
58 m_inView(false),
|
Chris@0
|
59 m_rowNumber(0),
|
Chris@0
|
60 m_ok(false)
|
Chris@0
|
61 {
|
Chris@0
|
62 }
|
Chris@0
|
63
|
Chris@0
|
64 void
|
Chris@0
|
65 SVFileReader::parse(const QString &xmlData)
|
Chris@0
|
66 {
|
Chris@0
|
67 QXmlInputSource inputSource;
|
Chris@0
|
68 inputSource.setData(xmlData);
|
Chris@0
|
69 parse(inputSource);
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 void
|
Chris@0
|
73 SVFileReader::parse(QXmlInputSource &inputSource)
|
Chris@0
|
74 {
|
Chris@0
|
75 QXmlSimpleReader reader;
|
Chris@0
|
76 reader.setContentHandler(this);
|
Chris@0
|
77 reader.setErrorHandler(this);
|
Chris@0
|
78 m_ok = reader.parse(inputSource);
|
Chris@0
|
79 }
|
Chris@0
|
80
|
Chris@0
|
81 bool
|
Chris@0
|
82 SVFileReader::isOK()
|
Chris@0
|
83 {
|
Chris@0
|
84 return m_ok;
|
Chris@0
|
85 }
|
Chris@0
|
86
|
Chris@0
|
87 SVFileReader::~SVFileReader()
|
Chris@0
|
88 {
|
Chris@0
|
89 if (!m_awaitingDatasets.empty()) {
|
Chris@0
|
90 std::cerr << "WARNING: SV-XML: File ended with "
|
Chris@0
|
91 << m_awaitingDatasets.size() << " unfilled model dataset(s)"
|
Chris@0
|
92 << std::endl;
|
Chris@0
|
93 }
|
Chris@0
|
94
|
Chris@0
|
95 std::set<Model *> unaddedModels;
|
Chris@0
|
96
|
Chris@0
|
97 for (std::map<int, Model *>::iterator i = m_models.begin();
|
Chris@0
|
98 i != m_models.end(); ++i) {
|
Chris@0
|
99 if (m_addedModels.find(i->second) == m_addedModels.end()) {
|
Chris@0
|
100 unaddedModels.insert(i->second);
|
Chris@0
|
101 }
|
Chris@0
|
102 }
|
Chris@0
|
103
|
Chris@0
|
104 if (!unaddedModels.empty()) {
|
Chris@0
|
105 std::cerr << "WARNING: SV-XML: File contained "
|
Chris@0
|
106 << unaddedModels.size() << " unused models"
|
Chris@0
|
107 << std::endl;
|
Chris@0
|
108 while (!unaddedModels.empty()) {
|
Chris@0
|
109 delete *unaddedModels.begin();
|
Chris@0
|
110 unaddedModels.erase(unaddedModels.begin());
|
Chris@0
|
111 }
|
Chris@0
|
112 }
|
Chris@0
|
113 }
|
Chris@0
|
114
|
Chris@0
|
115 bool
|
Chris@0
|
116 SVFileReader::startElement(const QString &, const QString &,
|
Chris@0
|
117 const QString &qName,
|
Chris@0
|
118 const QXmlAttributes &attributes)
|
Chris@0
|
119 {
|
Chris@0
|
120 QString name = qName.toLower();
|
Chris@0
|
121
|
Chris@0
|
122 bool ok = false;
|
Chris@0
|
123
|
Chris@0
|
124 // Valid element names:
|
Chris@0
|
125 //
|
Chris@0
|
126 // sv
|
Chris@0
|
127 // data
|
Chris@0
|
128 // dataset
|
Chris@0
|
129 // display
|
Chris@0
|
130 // derivation
|
Chris@0
|
131 // playparameters
|
Chris@0
|
132 // layer
|
Chris@0
|
133 // model
|
Chris@0
|
134 // point
|
Chris@0
|
135 // row
|
Chris@0
|
136 // view
|
Chris@0
|
137 // window
|
Chris@0
|
138
|
Chris@0
|
139 if (name == "sv") {
|
Chris@0
|
140
|
Chris@0
|
141 // nothing needed
|
Chris@0
|
142 ok = true;
|
Chris@0
|
143
|
Chris@0
|
144 } else if (name == "data") {
|
Chris@0
|
145
|
Chris@0
|
146 // nothing needed
|
Chris@0
|
147 m_inData = true;
|
Chris@0
|
148 ok = true;
|
Chris@0
|
149
|
Chris@0
|
150 } else if (name == "display") {
|
Chris@0
|
151
|
Chris@0
|
152 // nothing needed
|
Chris@0
|
153 ok = true;
|
Chris@0
|
154
|
Chris@0
|
155 } else if (name == "window") {
|
Chris@0
|
156
|
Chris@0
|
157 ok = readWindow(attributes);
|
Chris@0
|
158
|
Chris@0
|
159 } else if (name == "model") {
|
Chris@0
|
160
|
Chris@0
|
161 ok = readModel(attributes);
|
Chris@0
|
162
|
Chris@0
|
163 } else if (name == "dataset") {
|
Chris@0
|
164
|
Chris@0
|
165 ok = readDatasetStart(attributes);
|
Chris@0
|
166
|
Chris@0
|
167 } else if (name == "bin") {
|
Chris@0
|
168
|
Chris@0
|
169 ok = addBinToDataset(attributes);
|
Chris@0
|
170
|
Chris@0
|
171 } else if (name == "point") {
|
Chris@0
|
172
|
Chris@0
|
173 ok = addPointToDataset(attributes);
|
Chris@0
|
174
|
Chris@0
|
175 } else if (name == "row") {
|
Chris@0
|
176
|
Chris@0
|
177 ok = addRowToDataset(attributes);
|
Chris@0
|
178
|
Chris@0
|
179 } else if (name == "layer") {
|
Chris@0
|
180
|
Chris@0
|
181 addUnaddedModels(); // all models must be specified before first layer
|
Chris@0
|
182 ok = readLayer(attributes);
|
Chris@0
|
183
|
Chris@0
|
184 } else if (name == "view") {
|
Chris@0
|
185
|
Chris@0
|
186 m_inView = true;
|
Chris@0
|
187 ok = readView(attributes);
|
Chris@0
|
188
|
Chris@0
|
189 } else if (name == "derivation") {
|
Chris@0
|
190
|
Chris@0
|
191 ok = readDerivation(attributes);
|
Chris@0
|
192
|
Chris@0
|
193 } else if (name == "playparameters") {
|
Chris@0
|
194
|
Chris@0
|
195 ok = readPlayParameters(attributes);
|
Chris@0
|
196
|
Chris@0
|
197 } else if (name == "plugin") {
|
Chris@0
|
198
|
Chris@0
|
199 ok = readPlugin(attributes);
|
Chris@0
|
200
|
Chris@0
|
201 } else if (name == "selections") {
|
Chris@0
|
202
|
Chris@0
|
203 m_inSelections = true;
|
Chris@0
|
204 ok = true;
|
Chris@0
|
205
|
Chris@0
|
206 } else if (name == "selection") {
|
Chris@0
|
207
|
Chris@0
|
208 ok = readSelection(attributes);
|
Chris@154
|
209
|
Chris@154
|
210 } else if (name == "measurement") {
|
Chris@154
|
211
|
Chris@154
|
212 ok = readMeasurement(attributes);
|
Chris@154
|
213
|
Chris@154
|
214 } else {
|
Chris@154
|
215 std::cerr << "WARNING: SV-XML: Unexpected element \""
|
Chris@154
|
216 << name.toLocal8Bit().data() << "\"" << std::endl;
|
Chris@0
|
217 }
|
Chris@0
|
218
|
Chris@0
|
219 if (!ok) {
|
Chris@0
|
220 std::cerr << "WARNING: SV-XML: Failed to completely process element \""
|
Chris@0
|
221 << name.toLocal8Bit().data() << "\"" << std::endl;
|
Chris@0
|
222 }
|
Chris@0
|
223
|
Chris@0
|
224 return true;
|
Chris@0
|
225 }
|
Chris@0
|
226
|
Chris@0
|
227 bool
|
Chris@0
|
228 SVFileReader::characters(const QString &text)
|
Chris@0
|
229 {
|
Chris@0
|
230 bool ok = false;
|
Chris@0
|
231
|
Chris@0
|
232 if (m_inRow) {
|
Chris@0
|
233 ok = readRowData(text);
|
Chris@0
|
234 if (!ok) {
|
Chris@0
|
235 std::cerr << "WARNING: SV-XML: Failed to read row data content for row " << m_rowNumber << std::endl;
|
Chris@0
|
236 }
|
Chris@0
|
237 }
|
Chris@0
|
238
|
Chris@0
|
239 return true;
|
Chris@0
|
240 }
|
Chris@0
|
241
|
Chris@0
|
242 bool
|
Chris@0
|
243 SVFileReader::endElement(const QString &, const QString &,
|
Chris@0
|
244 const QString &qName)
|
Chris@0
|
245 {
|
Chris@0
|
246 QString name = qName.toLower();
|
Chris@0
|
247
|
Chris@0
|
248 if (name == "dataset") {
|
Chris@0
|
249
|
Chris@0
|
250 if (m_currentDataset) {
|
Chris@0
|
251
|
Chris@0
|
252 bool foundInAwaiting = false;
|
Chris@0
|
253
|
Chris@0
|
254 for (std::map<int, int>::iterator i = m_awaitingDatasets.begin();
|
Chris@0
|
255 i != m_awaitingDatasets.end(); ++i) {
|
Chris@0
|
256 if (m_models[i->second] == m_currentDataset) {
|
Chris@0
|
257 m_awaitingDatasets.erase(i);
|
Chris@0
|
258 foundInAwaiting = true;
|
Chris@0
|
259 break;
|
Chris@0
|
260 }
|
Chris@0
|
261 }
|
Chris@0
|
262
|
Chris@0
|
263 if (!foundInAwaiting) {
|
Chris@0
|
264 std::cerr << "WARNING: SV-XML: Dataset precedes model, or no model uses dataset" << std::endl;
|
Chris@0
|
265 }
|
Chris@0
|
266 }
|
Chris@0
|
267
|
Chris@0
|
268 m_currentDataset = 0;
|
Chris@0
|
269
|
Chris@0
|
270 } else if (name == "data") {
|
Chris@0
|
271
|
Chris@0
|
272 addUnaddedModels();
|
Chris@0
|
273 m_inData = false;
|
Chris@0
|
274
|
Chris@0
|
275 } else if (name == "derivation") {
|
Chris@55
|
276
|
Chris@55
|
277 if (!m_currentDerivedModel) {
|
Chris@55
|
278 if (m_currentDerivedModel < 0) {
|
Chris@55
|
279 std::cerr << "WARNING: SV-XML: Bad derivation output model id "
|
Chris@55
|
280 << m_currentDerivedModelId << std::endl;
|
Chris@55
|
281 } else if (m_models[m_currentDerivedModelId]) {
|
Chris@55
|
282 std::cerr << "WARNING: SV-XML: Derivation has existing model "
|
Chris@55
|
283 << m_currentDerivedModelId
|
Chris@55
|
284 << " as target, not regenerating" << std::endl;
|
Chris@55
|
285 } else {
|
Chris@55
|
286 m_currentDerivedModel = m_models[m_currentDerivedModelId] =
|
Chris@55
|
287 m_document->addDerivedModel(m_currentTransform,
|
Chris@55
|
288 m_currentTransformSource,
|
Chris@55
|
289 m_currentTransformContext,
|
Chris@55
|
290 m_currentTransformConfiguration);
|
Chris@55
|
291 }
|
Chris@55
|
292 } else {
|
Chris@0
|
293 m_document->addDerivedModel(m_currentTransform,
|
Chris@55
|
294 m_currentTransformSource,
|
Chris@30
|
295 m_currentTransformContext,
|
Chris@0
|
296 m_currentDerivedModel,
|
Chris@0
|
297 m_currentTransformConfiguration);
|
Chris@0
|
298 }
|
Chris@0
|
299
|
Chris@55
|
300 m_addedModels.insert(m_currentDerivedModel);
|
Chris@55
|
301 m_currentDerivedModel = 0;
|
Chris@55
|
302 m_currentDerivedModelId = -1;
|
Chris@55
|
303 m_currentTransform = "";
|
Chris@55
|
304 m_currentTransformConfiguration = "";
|
Chris@55
|
305
|
Chris@0
|
306 } else if (name == "row") {
|
Chris@0
|
307 m_inRow = false;
|
Chris@154
|
308 } else if (name == "layer") {
|
Chris@154
|
309 m_inLayer = false;
|
Chris@0
|
310 } else if (name == "view") {
|
Chris@0
|
311 m_inView = false;
|
Chris@0
|
312 } else if (name == "selections") {
|
Chris@0
|
313 m_inSelections = false;
|
Chris@0
|
314 } else if (name == "playparameters") {
|
Chris@0
|
315 m_currentPlayParameters = 0;
|
Chris@0
|
316 }
|
Chris@0
|
317
|
Chris@0
|
318 return true;
|
Chris@0
|
319 }
|
Chris@0
|
320
|
Chris@0
|
321 bool
|
Chris@0
|
322 SVFileReader::error(const QXmlParseException &exception)
|
Chris@0
|
323 {
|
Chris@0
|
324 m_errorString =
|
Chris@0
|
325 QString("ERROR: SV-XML: %1 at line %2, column %3")
|
Chris@0
|
326 .arg(exception.message())
|
Chris@0
|
327 .arg(exception.lineNumber())
|
Chris@0
|
328 .arg(exception.columnNumber());
|
Chris@0
|
329 std::cerr << m_errorString.toLocal8Bit().data() << std::endl;
|
Chris@0
|
330 return QXmlDefaultHandler::error(exception);
|
Chris@0
|
331 }
|
Chris@0
|
332
|
Chris@0
|
333 bool
|
Chris@0
|
334 SVFileReader::fatalError(const QXmlParseException &exception)
|
Chris@0
|
335 {
|
Chris@0
|
336 m_errorString =
|
Chris@0
|
337 QString("FATAL ERROR: SV-XML: %1 at line %2, column %3")
|
Chris@0
|
338 .arg(exception.message())
|
Chris@0
|
339 .arg(exception.lineNumber())
|
Chris@0
|
340 .arg(exception.columnNumber());
|
Chris@0
|
341 std::cerr << m_errorString.toLocal8Bit().data() << std::endl;
|
Chris@0
|
342 return QXmlDefaultHandler::fatalError(exception);
|
Chris@0
|
343 }
|
Chris@0
|
344
|
Chris@0
|
345
|
Chris@0
|
346 #define READ_MANDATORY(TYPE, NAME, CONVERSION) \
|
Chris@0
|
347 TYPE NAME = attributes.value(#NAME).trimmed().CONVERSION(&ok); \
|
Chris@0
|
348 if (!ok) { \
|
Chris@0
|
349 std::cerr << "WARNING: SV-XML: Missing or invalid mandatory " #TYPE " attribute \"" #NAME "\"" << std::endl; \
|
Chris@0
|
350 return false; \
|
Chris@0
|
351 }
|
Chris@0
|
352
|
Chris@0
|
353 bool
|
Chris@0
|
354 SVFileReader::readWindow(const QXmlAttributes &attributes)
|
Chris@0
|
355 {
|
Chris@0
|
356 bool ok = false;
|
Chris@0
|
357
|
Chris@0
|
358 READ_MANDATORY(int, width, toInt);
|
Chris@0
|
359 READ_MANDATORY(int, height, toInt);
|
Chris@0
|
360
|
Chris@0
|
361 m_paneCallback.setWindowSize(width, height);
|
Chris@0
|
362 return true;
|
Chris@0
|
363 }
|
Chris@0
|
364
|
Chris@0
|
365 void
|
Chris@0
|
366 SVFileReader::addUnaddedModels()
|
Chris@0
|
367 {
|
Chris@0
|
368 std::set<Model *> unaddedModels;
|
Chris@0
|
369
|
Chris@0
|
370 for (std::map<int, Model *>::iterator i = m_models.begin();
|
Chris@0
|
371 i != m_models.end(); ++i) {
|
Chris@0
|
372 if (m_addedModels.find(i->second) == m_addedModels.end()) {
|
Chris@0
|
373 unaddedModels.insert(i->second);
|
Chris@0
|
374 }
|
Chris@0
|
375 }
|
Chris@0
|
376
|
Chris@0
|
377 for (std::set<Model *>::iterator i = unaddedModels.begin();
|
Chris@0
|
378 i != unaddedModels.end(); ++i) {
|
Chris@0
|
379 m_document->addImportedModel(*i);
|
Chris@0
|
380 m_addedModels.insert(*i);
|
Chris@0
|
381 }
|
Chris@0
|
382 }
|
Chris@0
|
383
|
Chris@0
|
384 bool
|
Chris@0
|
385 SVFileReader::readModel(const QXmlAttributes &attributes)
|
Chris@0
|
386 {
|
Chris@0
|
387 bool ok = false;
|
Chris@0
|
388
|
Chris@0
|
389 READ_MANDATORY(int, id, toInt);
|
Chris@0
|
390
|
Chris@0
|
391 if (m_models.find(id) != m_models.end()) {
|
Chris@0
|
392 std::cerr << "WARNING: SV-XML: Ignoring duplicate model id " << id
|
Chris@0
|
393 << std::endl;
|
Chris@0
|
394 return false;
|
Chris@0
|
395 }
|
Chris@0
|
396
|
Chris@0
|
397 QString name = attributes.value("name");
|
Chris@0
|
398
|
Chris@167
|
399 std::cerr << "SVFileReader::readModel: model name \"" << name.toStdString() << "\"" << std::endl;
|
Chris@167
|
400
|
Chris@0
|
401 READ_MANDATORY(int, sampleRate, toInt);
|
Chris@0
|
402
|
Chris@0
|
403 QString type = attributes.value("type").trimmed();
|
Chris@0
|
404 bool mainModel = (attributes.value("mainModel").trimmed() == "true");
|
Chris@55
|
405
|
Chris@0
|
406 if (type == "wavefile") {
|
Chris@0
|
407
|
Chris@87
|
408 WaveFileModel *model = 0;
|
Chris@88
|
409 FileFinder *ff = FileFinder::getInstance();
|
Chris@88
|
410 QString originalPath = attributes.value("file");
|
Chris@88
|
411 QString path = ff->find(FileFinder::AudioFile,
|
Chris@88
|
412 originalPath, m_location);
|
Chris@87
|
413 QUrl url(path);
|
Chris@87
|
414
|
Chris@87
|
415 if (RemoteFile::canHandleScheme(url)) {
|
Chris@87
|
416
|
Chris@87
|
417 RemoteFile rf(url);
|
Chris@87
|
418 rf.wait();
|
Chris@87
|
419
|
Chris@87
|
420 if (rf.isOK()) {
|
Chris@88
|
421
|
Chris@88
|
422 model = new WaveFileModel(rf.getLocalFilename(), path);
|
Chris@87
|
423 if (!model->isOK()) {
|
Chris@87
|
424 delete model;
|
Chris@87
|
425 model = 0;
|
Chris@87
|
426 //!!! and delete local file?
|
Chris@87
|
427 }
|
Chris@87
|
428 }
|
Chris@87
|
429 } else {
|
Chris@87
|
430
|
Chris@87
|
431 model = new WaveFileModel(path);
|
Chris@87
|
432 if (!model->isOK()) {
|
Chris@87
|
433 delete model;
|
Chris@87
|
434 model = 0;
|
Chris@87
|
435 }
|
Chris@87
|
436 }
|
Chris@87
|
437
|
Chris@87
|
438 if (!model) return false;
|
Chris@87
|
439
|
Chris@167
|
440 model->setObjectName(name);
|
Chris@0
|
441 m_models[id] = model;
|
Chris@0
|
442 if (mainModel) {
|
Chris@0
|
443 m_document->setMainModel(model);
|
Chris@0
|
444 m_addedModels.insert(model);
|
Chris@0
|
445 }
|
Chris@0
|
446 // Derived models will be added when their derivation
|
Chris@0
|
447 // is found.
|
Chris@0
|
448
|
Chris@0
|
449 return true;
|
Chris@0
|
450
|
Chris@0
|
451 } else if (type == "dense") {
|
Chris@0
|
452
|
Chris@0
|
453 READ_MANDATORY(int, dimensions, toInt);
|
Chris@0
|
454
|
Chris@55
|
455 // Currently the only dense model we support here is the dense
|
Chris@55
|
456 // 3d model. Dense time-value models are always file-backed
|
Chris@55
|
457 // waveform data, at this point, and they come in as wavefile
|
Chris@55
|
458 // models.
|
Chris@0
|
459
|
Chris@0
|
460 if (dimensions == 3) {
|
Chris@0
|
461
|
Chris@0
|
462 READ_MANDATORY(int, windowSize, toInt);
|
Chris@0
|
463 READ_MANDATORY(int, yBinCount, toInt);
|
Chris@0
|
464
|
Chris@3
|
465 EditableDenseThreeDimensionalModel *model =
|
Chris@3
|
466 new EditableDenseThreeDimensionalModel
|
Chris@3
|
467 (sampleRate, windowSize, yBinCount);
|
Chris@0
|
468
|
Chris@0
|
469 float minimum = attributes.value("minimum").trimmed().toFloat(&ok);
|
Chris@0
|
470 if (ok) model->setMinimumLevel(minimum);
|
Chris@0
|
471
|
Chris@0
|
472 float maximum = attributes.value("maximum").trimmed().toFloat(&ok);
|
Chris@0
|
473 if (ok) model->setMaximumLevel(maximum);
|
Chris@0
|
474
|
Chris@0
|
475 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@0
|
476 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@0
|
477
|
Chris@167
|
478 model->setObjectName(name);
|
Chris@0
|
479 m_models[id] = model;
|
Chris@0
|
480 return true;
|
Chris@0
|
481
|
Chris@0
|
482 } else {
|
Chris@0
|
483
|
Chris@0
|
484 std::cerr << "WARNING: SV-XML: Unexpected dense model dimension ("
|
Chris@0
|
485 << dimensions << ")" << std::endl;
|
Chris@0
|
486 }
|
Chris@0
|
487 } else if (type == "sparse") {
|
Chris@0
|
488
|
Chris@0
|
489 READ_MANDATORY(int, dimensions, toInt);
|
Chris@0
|
490
|
Chris@0
|
491 if (dimensions == 1) {
|
Chris@0
|
492
|
Chris@0
|
493 READ_MANDATORY(int, resolution, toInt);
|
Chris@0
|
494
|
Chris@0
|
495 SparseOneDimensionalModel *model = new SparseOneDimensionalModel
|
Chris@0
|
496 (sampleRate, resolution);
|
Chris@167
|
497 model->setObjectName(name);
|
Chris@0
|
498 m_models[id] = model;
|
Chris@0
|
499
|
Chris@0
|
500 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@0
|
501 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@0
|
502
|
Chris@0
|
503 return true;
|
Chris@0
|
504
|
Chris@0
|
505 } else if (dimensions == 2 || dimensions == 3) {
|
Chris@0
|
506
|
Chris@0
|
507 READ_MANDATORY(int, resolution, toInt);
|
Chris@0
|
508
|
Chris@167
|
509 bool haveMinMax = true;
|
Chris@0
|
510 float minimum = attributes.value("minimum").trimmed().toFloat(&ok);
|
Chris@167
|
511 if (!ok) haveMinMax = false;
|
Chris@0
|
512 float maximum = attributes.value("maximum").trimmed().toFloat(&ok);
|
Chris@167
|
513 if (!ok) haveMinMax = false;
|
Chris@167
|
514
|
Chris@0
|
515 float valueQuantization =
|
Chris@0
|
516 attributes.value("valueQuantization").trimmed().toFloat(&ok);
|
Chris@0
|
517
|
Chris@0
|
518 bool notifyOnAdd = (attributes.value("notifyOnAdd") == "true");
|
Chris@0
|
519
|
Chris@0
|
520 QString units = attributes.value("units");
|
Chris@0
|
521
|
Chris@0
|
522 if (dimensions == 2) {
|
Chris@0
|
523 if (attributes.value("subtype") == "text") {
|
Chris@0
|
524 TextModel *model = new TextModel
|
Chris@0
|
525 (sampleRate, resolution, notifyOnAdd);
|
Chris@167
|
526 model->setObjectName(name);
|
Chris@0
|
527 m_models[id] = model;
|
Chris@0
|
528 } else {
|
Chris@167
|
529 SparseTimeValueModel *model;
|
Chris@167
|
530 if (haveMinMax) {
|
Chris@167
|
531 model = new SparseTimeValueModel
|
Chris@167
|
532 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
|
Chris@167
|
533 } else {
|
Chris@167
|
534 model = new SparseTimeValueModel
|
Chris@167
|
535 (sampleRate, resolution, notifyOnAdd);
|
Chris@167
|
536 }
|
Chris@0
|
537 model->setScaleUnits(units);
|
Chris@167
|
538 model->setObjectName(name);
|
Chris@0
|
539 m_models[id] = model;
|
Chris@0
|
540 }
|
Chris@0
|
541 } else {
|
Chris@167
|
542 NoteModel *model;
|
Chris@167
|
543 if (haveMinMax) {
|
Chris@167
|
544 model = new NoteModel
|
Chris@167
|
545 (sampleRate, resolution, minimum, maximum, notifyOnAdd);
|
Chris@167
|
546 } else {
|
Chris@167
|
547 model = new NoteModel
|
Chris@167
|
548 (sampleRate, resolution, notifyOnAdd);
|
Chris@167
|
549 }
|
Chris@0
|
550 model->setValueQuantization(valueQuantization);
|
Chris@0
|
551 model->setScaleUnits(units);
|
Chris@167
|
552 model->setObjectName(name);
|
Chris@0
|
553 m_models[id] = model;
|
Chris@0
|
554 }
|
Chris@0
|
555
|
Chris@0
|
556 int dataset = attributes.value("dataset").trimmed().toInt(&ok);
|
Chris@0
|
557 if (ok) m_awaitingDatasets[dataset] = id;
|
Chris@0
|
558
|
Chris@0
|
559 return true;
|
Chris@0
|
560
|
Chris@0
|
561 } else {
|
Chris@0
|
562
|
Chris@0
|
563 std::cerr << "WARNING: SV-XML: Unexpected sparse model dimension ("
|
Chris@0
|
564 << dimensions << ")" << std::endl;
|
Chris@0
|
565 }
|
Chris@0
|
566 } else {
|
Chris@0
|
567
|
Chris@0
|
568 std::cerr << "WARNING: SV-XML: Unexpected model type \""
|
Chris@88
|
569 << type.toLocal8Bit().data() << "\" for model id " << id << std::endl;
|
Chris@0
|
570 }
|
Chris@0
|
571
|
Chris@0
|
572 return false;
|
Chris@0
|
573 }
|
Chris@0
|
574
|
Chris@0
|
575 bool
|
Chris@0
|
576 SVFileReader::readView(const QXmlAttributes &attributes)
|
Chris@0
|
577 {
|
Chris@0
|
578 QString type = attributes.value("type");
|
Chris@0
|
579 m_currentPane = 0;
|
Chris@0
|
580
|
Chris@0
|
581 if (type != "pane") {
|
Chris@0
|
582 std::cerr << "WARNING: SV-XML: Unexpected view type \""
|
Chris@0
|
583 << type.toLocal8Bit().data() << "\"" << std::endl;
|
Chris@0
|
584 return false;
|
Chris@0
|
585 }
|
Chris@0
|
586
|
Chris@0
|
587 m_currentPane = m_paneCallback.addPane();
|
Chris@0
|
588
|
Chris@0
|
589 if (!m_currentPane) {
|
Chris@0
|
590 std::cerr << "WARNING: SV-XML: Internal error: Failed to add pane!"
|
Chris@0
|
591 << std::endl;
|
Chris@0
|
592 return false;
|
Chris@0
|
593 }
|
Chris@0
|
594
|
Chris@0
|
595 bool ok = false;
|
Chris@0
|
596
|
Chris@0
|
597 View *view = m_currentPane;
|
Chris@0
|
598
|
Chris@0
|
599 // The view properties first
|
Chris@0
|
600
|
Chris@0
|
601 READ_MANDATORY(size_t, centre, toUInt);
|
Chris@0
|
602 READ_MANDATORY(size_t, zoom, toUInt);
|
Chris@0
|
603 READ_MANDATORY(int, followPan, toInt);
|
Chris@0
|
604 READ_MANDATORY(int, followZoom, toInt);
|
Chris@0
|
605 QString tracking = attributes.value("tracking");
|
Chris@0
|
606
|
Chris@0
|
607 // Specify the follow modes before we set the actual values
|
Chris@0
|
608 view->setFollowGlobalPan(followPan);
|
Chris@0
|
609 view->setFollowGlobalZoom(followZoom);
|
Chris@109
|
610 view->setPlaybackFollow(tracking == "scroll" ? PlaybackScrollContinuous :
|
Chris@109
|
611 tracking == "page" ? PlaybackScrollPage
|
Chris@109
|
612 : PlaybackIgnore);
|
Chris@0
|
613
|
Chris@0
|
614 // Then set these values
|
Chris@0
|
615 view->setCentreFrame(centre);
|
Chris@0
|
616 view->setZoomLevel(zoom);
|
Chris@0
|
617
|
Chris@0
|
618 // And pane properties
|
Chris@0
|
619 READ_MANDATORY(int, centreLineVisible, toInt);
|
Chris@0
|
620 m_currentPane->setCentreLineVisible(centreLineVisible);
|
Chris@0
|
621
|
Chris@0
|
622 int height = attributes.value("height").toInt(&ok);
|
Chris@0
|
623 if (ok) {
|
Chris@0
|
624 m_currentPane->resize(m_currentPane->width(), height);
|
Chris@0
|
625 }
|
Chris@0
|
626
|
Chris@0
|
627 return true;
|
Chris@0
|
628 }
|
Chris@0
|
629
|
Chris@0
|
630 bool
|
Chris@0
|
631 SVFileReader::readLayer(const QXmlAttributes &attributes)
|
Chris@0
|
632 {
|
Chris@0
|
633 QString type = attributes.value("type");
|
Chris@0
|
634
|
Chris@0
|
635 int id;
|
Chris@0
|
636 bool ok = false;
|
Chris@0
|
637 id = attributes.value("id").trimmed().toInt(&ok);
|
Chris@0
|
638
|
Chris@0
|
639 if (!ok) {
|
Chris@0
|
640 std::cerr << "WARNING: SV-XML: No layer id for layer of type \""
|
Chris@0
|
641 << type.toLocal8Bit().data()
|
Chris@0
|
642 << "\"" << std::endl;
|
Chris@0
|
643 return false;
|
Chris@0
|
644 }
|
Chris@0
|
645
|
Chris@0
|
646 Layer *layer = 0;
|
Chris@0
|
647 bool isNewLayer = false;
|
Chris@0
|
648
|
Chris@0
|
649 // Layers are expected to be defined in layer elements in the data
|
Chris@0
|
650 // section, and referred to in layer elements in the view
|
Chris@0
|
651 // sections. So if we're in the data section, we expect this
|
Chris@0
|
652 // layer not to exist already; if we're in the view section, we
|
Chris@0
|
653 // expect it to exist.
|
Chris@0
|
654
|
Chris@0
|
655 if (m_inData) {
|
Chris@0
|
656
|
Chris@0
|
657 if (m_layers.find(id) != m_layers.end()) {
|
Chris@0
|
658 std::cerr << "WARNING: SV-XML: Ignoring duplicate layer id " << id
|
Chris@0
|
659 << " in data section" << std::endl;
|
Chris@0
|
660 return false;
|
Chris@0
|
661 }
|
Chris@0
|
662
|
Chris@0
|
663 layer = m_layers[id] = m_document->createLayer
|
Chris@0
|
664 (LayerFactory::getInstance()->getLayerTypeForName(type));
|
Chris@0
|
665
|
Chris@0
|
666 if (layer) {
|
Chris@0
|
667 m_layers[id] = layer;
|
Chris@0
|
668 isNewLayer = true;
|
Chris@0
|
669 }
|
Chris@0
|
670
|
Chris@0
|
671 } else {
|
Chris@0
|
672
|
Chris@0
|
673 if (!m_currentPane) {
|
Chris@0
|
674 std::cerr << "WARNING: SV-XML: No current pane for layer " << id
|
Chris@0
|
675 << " in view section" << std::endl;
|
Chris@0
|
676 return false;
|
Chris@0
|
677 }
|
Chris@0
|
678
|
Chris@0
|
679 if (m_layers.find(id) != m_layers.end()) {
|
Chris@0
|
680
|
Chris@0
|
681 layer = m_layers[id];
|
Chris@0
|
682
|
Chris@0
|
683 } else {
|
Chris@0
|
684 std::cerr << "WARNING: SV-XML: Layer id " << id
|
Chris@0
|
685 << " in view section has not been defined -- defining it here"
|
Chris@0
|
686 << std::endl;
|
Chris@0
|
687
|
Chris@0
|
688 layer = m_document->createLayer
|
Chris@0
|
689 (LayerFactory::getInstance()->getLayerTypeForName(type));
|
Chris@0
|
690
|
Chris@0
|
691 if (layer) {
|
Chris@0
|
692 m_layers[id] = layer;
|
Chris@0
|
693 isNewLayer = true;
|
Chris@0
|
694 }
|
Chris@0
|
695 }
|
Chris@0
|
696 }
|
Chris@0
|
697
|
Chris@0
|
698 if (!layer) {
|
Chris@0
|
699 std::cerr << "WARNING: SV-XML: Failed to add layer of type \""
|
Chris@0
|
700 << type.toLocal8Bit().data()
|
Chris@0
|
701 << "\"" << std::endl;
|
Chris@0
|
702 return false;
|
Chris@0
|
703 }
|
Chris@0
|
704
|
Chris@0
|
705 if (isNewLayer) {
|
Chris@0
|
706
|
Chris@0
|
707 QString name = attributes.value("name");
|
Chris@0
|
708 layer->setObjectName(name);
|
Chris@0
|
709
|
Chris@0
|
710 int modelId;
|
Chris@0
|
711 bool modelOk = false;
|
Chris@0
|
712 modelId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@0
|
713
|
Chris@0
|
714 if (modelOk) {
|
Chris@0
|
715 if (m_models.find(modelId) != m_models.end()) {
|
Chris@0
|
716 Model *model = m_models[modelId];
|
Chris@0
|
717 m_document->setModel(layer, model);
|
Chris@0
|
718 } else {
|
Chris@0
|
719 std::cerr << "WARNING: SV-XML: Unknown model id " << modelId
|
Chris@0
|
720 << " in layer definition" << std::endl;
|
Chris@0
|
721 }
|
Chris@0
|
722 }
|
Chris@0
|
723
|
Chris@0
|
724 layer->setProperties(attributes);
|
Chris@0
|
725 }
|
Chris@0
|
726
|
Chris@0
|
727 if (!m_inData && m_currentPane) {
|
Chris@84
|
728
|
Chris@84
|
729 QString visible = attributes.value("visible");
|
Chris@84
|
730 bool dormant = (visible == "false");
|
Chris@84
|
731
|
Chris@84
|
732 // We need to do this both before and after adding the layer
|
Chris@84
|
733 // to the view -- we need it to be dormant if appropriate
|
Chris@84
|
734 // before it's actually added to the view so that any property
|
Chris@84
|
735 // box gets the right state when it's added, but the add layer
|
Chris@84
|
736 // command sets dormant to false because it assumes it may be
|
Chris@84
|
737 // restoring a previously dormant layer, so we need to set it
|
Chris@84
|
738 // again afterwards too. Hm
|
Chris@84
|
739 layer->setLayerDormant(m_currentPane, dormant);
|
Chris@84
|
740
|
Chris@0
|
741 m_document->addLayerToView(m_currentPane, layer);
|
Chris@84
|
742
|
Chris@84
|
743 layer->setLayerDormant(m_currentPane, dormant);
|
Chris@0
|
744 }
|
Chris@0
|
745
|
Chris@154
|
746 m_currentLayer = layer;
|
Chris@154
|
747 m_inLayer = true;
|
Chris@154
|
748
|
Chris@0
|
749 return true;
|
Chris@0
|
750 }
|
Chris@0
|
751
|
Chris@0
|
752 bool
|
Chris@0
|
753 SVFileReader::readDatasetStart(const QXmlAttributes &attributes)
|
Chris@0
|
754 {
|
Chris@0
|
755 bool ok = false;
|
Chris@0
|
756
|
Chris@0
|
757 READ_MANDATORY(int, id, toInt);
|
Chris@0
|
758 READ_MANDATORY(int, dimensions, toInt);
|
Chris@0
|
759
|
Chris@0
|
760 if (m_awaitingDatasets.find(id) == m_awaitingDatasets.end()) {
|
Chris@0
|
761 std::cerr << "WARNING: SV-XML: Unwanted dataset " << id << std::endl;
|
Chris@0
|
762 return false;
|
Chris@0
|
763 }
|
Chris@0
|
764
|
Chris@0
|
765 int modelId = m_awaitingDatasets[id];
|
Chris@0
|
766
|
Chris@0
|
767 Model *model = 0;
|
Chris@0
|
768 if (m_models.find(modelId) != m_models.end()) {
|
Chris@0
|
769 model = m_models[modelId];
|
Chris@0
|
770 } else {
|
Chris@0
|
771 std::cerr << "WARNING: SV-XML: Internal error: Unknown model " << modelId
|
Chris@0
|
772 << " expecting dataset " << id << std::endl;
|
Chris@0
|
773 return false;
|
Chris@0
|
774 }
|
Chris@0
|
775
|
Chris@0
|
776 bool good = false;
|
Chris@0
|
777
|
Chris@0
|
778 switch (dimensions) {
|
Chris@0
|
779 case 1:
|
Chris@0
|
780 if (dynamic_cast<SparseOneDimensionalModel *>(model)) good = true;
|
Chris@0
|
781 break;
|
Chris@0
|
782
|
Chris@0
|
783 case 2:
|
Chris@0
|
784 if (dynamic_cast<SparseTimeValueModel *>(model)) good = true;
|
Chris@0
|
785 else if (dynamic_cast<TextModel *>(model)) good = true;
|
Chris@0
|
786 break;
|
Chris@0
|
787
|
Chris@0
|
788 case 3:
|
Chris@0
|
789 if (dynamic_cast<NoteModel *>(model)) good = true;
|
Chris@3
|
790 else if (dynamic_cast<EditableDenseThreeDimensionalModel *>(model)) {
|
Chris@0
|
791 m_datasetSeparator = attributes.value("separator");
|
Chris@0
|
792 good = true;
|
Chris@0
|
793 }
|
Chris@0
|
794 break;
|
Chris@0
|
795 }
|
Chris@0
|
796
|
Chris@0
|
797 if (!good) {
|
Chris@0
|
798 std::cerr << "WARNING: SV-XML: Model id " << modelId << " has wrong number of dimensions for " << dimensions << "-D dataset " << id << std::endl;
|
Chris@0
|
799 m_currentDataset = 0;
|
Chris@0
|
800 return false;
|
Chris@0
|
801 }
|
Chris@0
|
802
|
Chris@0
|
803 m_currentDataset = model;
|
Chris@0
|
804 return true;
|
Chris@0
|
805 }
|
Chris@0
|
806
|
Chris@0
|
807 bool
|
Chris@0
|
808 SVFileReader::addPointToDataset(const QXmlAttributes &attributes)
|
Chris@0
|
809 {
|
Chris@0
|
810 bool ok = false;
|
Chris@0
|
811
|
Chris@0
|
812 READ_MANDATORY(int, frame, toInt);
|
Chris@0
|
813
|
Chris@0
|
814 SparseOneDimensionalModel *sodm = dynamic_cast<SparseOneDimensionalModel *>
|
Chris@0
|
815 (m_currentDataset);
|
Chris@0
|
816
|
Chris@0
|
817 if (sodm) {
|
Chris@0
|
818 QString label = attributes.value("label");
|
Chris@0
|
819 sodm->addPoint(SparseOneDimensionalModel::Point(frame, label));
|
Chris@0
|
820 return true;
|
Chris@0
|
821 }
|
Chris@0
|
822
|
Chris@0
|
823 SparseTimeValueModel *stvm = dynamic_cast<SparseTimeValueModel *>
|
Chris@0
|
824 (m_currentDataset);
|
Chris@0
|
825
|
Chris@0
|
826 if (stvm) {
|
Chris@0
|
827 float value = 0.0;
|
Chris@0
|
828 value = attributes.value("value").trimmed().toFloat(&ok);
|
Chris@0
|
829 QString label = attributes.value("label");
|
Chris@0
|
830 stvm->addPoint(SparseTimeValueModel::Point(frame, value, label));
|
Chris@0
|
831 return ok;
|
Chris@0
|
832 }
|
Chris@0
|
833
|
Chris@0
|
834 NoteModel *nm = dynamic_cast<NoteModel *>(m_currentDataset);
|
Chris@0
|
835
|
Chris@0
|
836 if (nm) {
|
Chris@0
|
837 float value = 0.0;
|
Chris@0
|
838 value = attributes.value("value").trimmed().toFloat(&ok);
|
Chris@137
|
839 size_t duration = 0;
|
Chris@137
|
840 duration = attributes.value("duration").trimmed().toUInt(&ok);
|
Chris@0
|
841 QString label = attributes.value("label");
|
Chris@0
|
842 nm->addPoint(NoteModel::Point(frame, value, duration, label));
|
Chris@0
|
843 return ok;
|
Chris@0
|
844 }
|
Chris@0
|
845
|
Chris@0
|
846 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset);
|
Chris@0
|
847
|
Chris@0
|
848 if (tm) {
|
Chris@0
|
849 float height = 0.0;
|
Chris@0
|
850 height = attributes.value("height").trimmed().toFloat(&ok);
|
Chris@0
|
851 QString label = attributes.value("label");
|
Chris@0
|
852 tm->addPoint(TextModel::Point(frame, height, label));
|
Chris@0
|
853 return ok;
|
Chris@0
|
854 }
|
Chris@0
|
855
|
Chris@0
|
856 std::cerr << "WARNING: SV-XML: Point element found in non-point dataset" << std::endl;
|
Chris@0
|
857
|
Chris@0
|
858 return false;
|
Chris@0
|
859 }
|
Chris@0
|
860
|
Chris@0
|
861 bool
|
Chris@0
|
862 SVFileReader::addBinToDataset(const QXmlAttributes &attributes)
|
Chris@0
|
863 {
|
Chris@3
|
864 EditableDenseThreeDimensionalModel *dtdm =
|
Chris@3
|
865 dynamic_cast<EditableDenseThreeDimensionalModel *>
|
Chris@0
|
866 (m_currentDataset);
|
Chris@0
|
867
|
Chris@0
|
868 if (dtdm) {
|
Chris@0
|
869
|
Chris@0
|
870 bool ok = false;
|
Chris@0
|
871 int n = attributes.value("number").trimmed().toInt(&ok);
|
Chris@0
|
872 if (!ok) {
|
Chris@0
|
873 std::cerr << "WARNING: SV-XML: Missing or invalid bin number"
|
Chris@0
|
874 << std::endl;
|
Chris@0
|
875 return false;
|
Chris@0
|
876 }
|
Chris@0
|
877
|
Chris@0
|
878 QString name = attributes.value("name");
|
Chris@0
|
879
|
Chris@0
|
880 dtdm->setBinName(n, name);
|
Chris@0
|
881 return true;
|
Chris@0
|
882 }
|
Chris@0
|
883
|
Chris@0
|
884 std::cerr << "WARNING: SV-XML: Bin definition found in incompatible dataset" << std::endl;
|
Chris@0
|
885
|
Chris@0
|
886 return false;
|
Chris@0
|
887 }
|
Chris@0
|
888
|
Chris@0
|
889
|
Chris@0
|
890 bool
|
Chris@0
|
891 SVFileReader::addRowToDataset(const QXmlAttributes &attributes)
|
Chris@0
|
892 {
|
Chris@0
|
893 m_inRow = false;
|
Chris@0
|
894
|
Chris@0
|
895 bool ok = false;
|
Chris@0
|
896 m_rowNumber = attributes.value("n").trimmed().toInt(&ok);
|
Chris@0
|
897 if (!ok) {
|
Chris@0
|
898 std::cerr << "WARNING: SV-XML: Missing or invalid row number"
|
Chris@0
|
899 << std::endl;
|
Chris@0
|
900 return false;
|
Chris@0
|
901 }
|
Chris@0
|
902
|
Chris@0
|
903 m_inRow = true;
|
Chris@0
|
904
|
Chris@0
|
905 // std::cerr << "SV-XML: In row " << m_rowNumber << std::endl;
|
Chris@0
|
906
|
Chris@0
|
907 return true;
|
Chris@0
|
908 }
|
Chris@0
|
909
|
Chris@0
|
910 bool
|
Chris@0
|
911 SVFileReader::readRowData(const QString &text)
|
Chris@0
|
912 {
|
Chris@3
|
913 EditableDenseThreeDimensionalModel *dtdm =
|
Chris@3
|
914 dynamic_cast<EditableDenseThreeDimensionalModel *>
|
Chris@0
|
915 (m_currentDataset);
|
Chris@0
|
916
|
Chris@0
|
917 bool warned = false;
|
Chris@0
|
918
|
Chris@0
|
919 if (dtdm) {
|
Chris@0
|
920 QStringList data = text.split(m_datasetSeparator);
|
Chris@0
|
921
|
Chris@51
|
922 DenseThreeDimensionalModel::Column values;
|
Chris@0
|
923
|
Chris@0
|
924 for (QStringList::iterator i = data.begin(); i != data.end(); ++i) {
|
Chris@0
|
925
|
Chris@51
|
926 if (values.size() == dtdm->getHeight()) {
|
Chris@0
|
927 if (!warned) {
|
Chris@0
|
928 std::cerr << "WARNING: SV-XML: Too many y-bins in 3-D dataset row "
|
Chris@0
|
929 << m_rowNumber << std::endl;
|
Chris@0
|
930 warned = true;
|
Chris@0
|
931 }
|
Chris@0
|
932 }
|
Chris@0
|
933
|
Chris@0
|
934 bool ok;
|
Chris@0
|
935 float value = i->toFloat(&ok);
|
Chris@0
|
936 if (!ok) {
|
Chris@0
|
937 std::cerr << "WARNING: SV-XML: Bad floating-point value "
|
Chris@0
|
938 << i->toLocal8Bit().data()
|
Chris@0
|
939 << " in row data" << std::endl;
|
Chris@0
|
940 } else {
|
Chris@0
|
941 values.push_back(value);
|
Chris@0
|
942 }
|
Chris@0
|
943 }
|
Chris@0
|
944
|
Chris@51
|
945 dtdm->setColumn(m_rowNumber, values);
|
Chris@0
|
946 return true;
|
Chris@0
|
947 }
|
Chris@0
|
948
|
Chris@0
|
949 std::cerr << "WARNING: SV-XML: Row data found in non-row dataset" << std::endl;
|
Chris@0
|
950
|
Chris@0
|
951 return false;
|
Chris@0
|
952 }
|
Chris@0
|
953
|
Chris@0
|
954 bool
|
Chris@0
|
955 SVFileReader::readDerivation(const QXmlAttributes &attributes)
|
Chris@0
|
956 {
|
Chris@0
|
957 int modelId = 0;
|
Chris@0
|
958 bool modelOk = false;
|
Chris@0
|
959 modelId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@0
|
960
|
Chris@0
|
961 if (!modelOk) {
|
Chris@0
|
962 std::cerr << "WARNING: SV-XML: No model id specified for derivation" << std::endl;
|
Chris@0
|
963 return false;
|
Chris@0
|
964 }
|
Chris@55
|
965
|
Chris@55
|
966 QString transform = attributes.value("transform");
|
Chris@55
|
967
|
Chris@55
|
968 if (m_models.find(modelId) != m_models.end()) {
|
Chris@55
|
969 m_currentDerivedModel = m_models[modelId];
|
Chris@55
|
970 } else {
|
Chris@55
|
971 // we'll regenerate the model when the derivation element ends
|
Chris@55
|
972 m_currentDerivedModel = 0;
|
Chris@55
|
973 }
|
Chris@0
|
974
|
Chris@55
|
975 m_currentDerivedModelId = modelId;
|
Chris@0
|
976
|
Chris@55
|
977 int sourceId = 0;
|
Chris@55
|
978 bool sourceOk = false;
|
Chris@55
|
979 sourceId = attributes.value("source").trimmed().toInt(&sourceOk);
|
Chris@0
|
980
|
Chris@55
|
981 if (sourceOk && m_models[sourceId]) {
|
Chris@55
|
982 m_currentTransformSource = m_models[sourceId];
|
Chris@55
|
983 } else {
|
Chris@55
|
984 m_currentTransformSource = m_document->getMainModel();
|
Chris@55
|
985 }
|
Chris@0
|
986
|
Chris@55
|
987 m_currentTransform = transform;
|
Chris@55
|
988 m_currentTransformConfiguration = "";
|
Chris@30
|
989
|
Chris@55
|
990 m_currentTransformContext = PluginTransform::ExecutionContext();
|
Chris@30
|
991
|
Chris@55
|
992 bool ok = false;
|
Chris@55
|
993 int channel = attributes.value("channel").trimmed().toInt(&ok);
|
Chris@55
|
994 if (ok) m_currentTransformContext.channel = channel;
|
Chris@30
|
995
|
Chris@55
|
996 int domain = attributes.value("domain").trimmed().toInt(&ok);
|
Chris@55
|
997 if (ok) m_currentTransformContext.domain = Vamp::Plugin::InputDomain(domain);
|
Chris@30
|
998
|
Chris@55
|
999 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok);
|
Chris@55
|
1000 if (ok) m_currentTransformContext.stepSize = stepSize;
|
Chris@30
|
1001
|
Chris@55
|
1002 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok);
|
Chris@55
|
1003 if (ok) m_currentTransformContext.blockSize = blockSize;
|
Chris@0
|
1004
|
Chris@55
|
1005 int windowType = attributes.value("windowType").trimmed().toInt(&ok);
|
Chris@55
|
1006 if (ok) m_currentTransformContext.windowType = WindowType(windowType);
|
Chris@0
|
1007
|
Chris@0
|
1008 return true;
|
Chris@0
|
1009 }
|
Chris@0
|
1010
|
Chris@0
|
1011 bool
|
Chris@0
|
1012 SVFileReader::readPlayParameters(const QXmlAttributes &attributes)
|
Chris@0
|
1013 {
|
Chris@0
|
1014 m_currentPlayParameters = 0;
|
Chris@0
|
1015
|
Chris@0
|
1016 int modelId = 0;
|
Chris@0
|
1017 bool modelOk = false;
|
Chris@0
|
1018 modelId = attributes.value("model").trimmed().toInt(&modelOk);
|
Chris@0
|
1019
|
Chris@0
|
1020 if (!modelOk) {
|
Chris@0
|
1021 std::cerr << "WARNING: SV-XML: No model id specified for play parameters" << std::endl;
|
Chris@0
|
1022 return false;
|
Chris@0
|
1023 }
|
Chris@0
|
1024
|
Chris@0
|
1025 if (m_models.find(modelId) != m_models.end()) {
|
Chris@0
|
1026
|
Chris@0
|
1027 bool ok = false;
|
Chris@0
|
1028
|
Chris@0
|
1029 PlayParameters *parameters = PlayParameterRepository::getInstance()->
|
Chris@0
|
1030 getPlayParameters(m_models[modelId]);
|
Chris@0
|
1031
|
Chris@0
|
1032 if (!parameters) {
|
Chris@0
|
1033 std::cerr << "WARNING: SV-XML: Play parameters for model "
|
Chris@0
|
1034 << modelId
|
Chris@0
|
1035 << " not found - has model been added to document?"
|
Chris@0
|
1036 << std::endl;
|
Chris@0
|
1037 return false;
|
Chris@0
|
1038 }
|
Chris@0
|
1039
|
Chris@0
|
1040 bool muted = (attributes.value("mute").trimmed() == "true");
|
Chris@83
|
1041 parameters->setPlayMuted(muted);
|
Chris@0
|
1042
|
Chris@0
|
1043 float pan = attributes.value("pan").toFloat(&ok);
|
Chris@0
|
1044 if (ok) parameters->setPlayPan(pan);
|
Chris@0
|
1045
|
Chris@0
|
1046 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@0
|
1047 if (ok) parameters->setPlayGain(gain);
|
Chris@0
|
1048
|
Chris@0
|
1049 QString pluginId = attributes.value("pluginId");
|
Chris@0
|
1050 if (pluginId != "") parameters->setPlayPluginId(pluginId);
|
Chris@0
|
1051
|
Chris@0
|
1052 m_currentPlayParameters = parameters;
|
Chris@0
|
1053
|
Chris@0
|
1054 // std::cerr << "Current play parameters for model: " << m_models[modelId] << ": " << m_currentPlayParameters << std::endl;
|
Chris@0
|
1055
|
Chris@0
|
1056 } else {
|
Chris@0
|
1057
|
Chris@0
|
1058 std::cerr << "WARNING: SV-XML: Unknown model " << modelId
|
Chris@0
|
1059 << " for play parameters" << std::endl;
|
Chris@0
|
1060 return false;
|
Chris@0
|
1061 }
|
Chris@0
|
1062
|
Chris@0
|
1063 return true;
|
Chris@0
|
1064 }
|
Chris@0
|
1065
|
Chris@0
|
1066 bool
|
Chris@0
|
1067 SVFileReader::readPlugin(const QXmlAttributes &attributes)
|
Chris@0
|
1068 {
|
Chris@55
|
1069 if (m_currentDerivedModelId < 0 && !m_currentPlayParameters) {
|
Chris@0
|
1070 std::cerr << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << std::endl;
|
Chris@0
|
1071 return false;
|
Chris@0
|
1072 }
|
Chris@0
|
1073
|
Chris@0
|
1074 QString configurationXml = "<plugin";
|
Chris@0
|
1075
|
Chris@0
|
1076 for (int i = 0; i < attributes.length(); ++i) {
|
Chris@0
|
1077 configurationXml += QString(" %1=\"%2\"")
|
Chris@55
|
1078 .arg(attributes.qName(i))
|
Chris@55
|
1079 .arg(XmlExportable::encodeEntities(attributes.value(i)));
|
Chris@0
|
1080 }
|
Chris@0
|
1081
|
Chris@0
|
1082 configurationXml += "/>";
|
Chris@0
|
1083
|
Chris@0
|
1084 if (m_currentPlayParameters) {
|
Chris@0
|
1085 m_currentPlayParameters->setPlayPluginConfiguration(configurationXml);
|
Chris@0
|
1086 } else {
|
Chris@0
|
1087 m_currentTransformConfiguration += configurationXml;
|
Chris@0
|
1088 }
|
Chris@0
|
1089
|
Chris@0
|
1090 return true;
|
Chris@0
|
1091 }
|
Chris@0
|
1092
|
Chris@0
|
1093 bool
|
Chris@0
|
1094 SVFileReader::readSelection(const QXmlAttributes &attributes)
|
Chris@0
|
1095 {
|
Chris@0
|
1096 bool ok;
|
Chris@0
|
1097
|
Chris@0
|
1098 READ_MANDATORY(int, start, toInt);
|
Chris@0
|
1099 READ_MANDATORY(int, end, toInt);
|
Chris@0
|
1100
|
Chris@0
|
1101 m_paneCallback.addSelection(start, end);
|
Chris@0
|
1102
|
Chris@0
|
1103 return true;
|
Chris@0
|
1104 }
|
Chris@0
|
1105
|
Chris@154
|
1106 bool
|
Chris@154
|
1107 SVFileReader::readMeasurement(const QXmlAttributes &attributes)
|
Chris@154
|
1108 {
|
Chris@154
|
1109 std::cerr << "SVFileReader::readMeasurement: inLayer "
|
Chris@154
|
1110 << m_inLayer << ", layer " << m_currentLayer << std::endl;
|
Chris@154
|
1111
|
Chris@154
|
1112 if (!m_inLayer) {
|
Chris@154
|
1113 std::cerr << "WARNING: SV-XML: Measurement found outside layer" << std::endl;
|
Chris@154
|
1114 return false;
|
Chris@154
|
1115 }
|
Chris@154
|
1116
|
Chris@154
|
1117 m_currentLayer->addMeasurementRect(attributes);
|
Chris@154
|
1118 return true;
|
Chris@154
|
1119 }
|
Chris@154
|
1120
|
Chris@137
|
1121 SVFileReaderPaneCallback::~SVFileReaderPaneCallback()
|
Chris@137
|
1122 {
|
Chris@137
|
1123 }
|
Chris@137
|
1124
|