annotate framework/SVFileReader.cpp @ 662:ffd213b292f9 single-point

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