annotate framework/SVFileReader.cpp @ 649:284cb118368e single-point

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