comparison layer/LayerFactory.cpp @ 1459:42c87368287c

Merge from branch single-point
author Chris Cannam
date Fri, 17 May 2019 10:02:52 +0100
parents 9e846af73f3e
children f2525e6cbdf1
comparison
equal deleted inserted replaced
1441:8d5bf4ab98ef 1459:42c87368287c
35 #include "data/model/RangeSummarisableTimeValueModel.h" 35 #include "data/model/RangeSummarisableTimeValueModel.h"
36 #include "data/model/DenseTimeValueModel.h" 36 #include "data/model/DenseTimeValueModel.h"
37 #include "data/model/SparseOneDimensionalModel.h" 37 #include "data/model/SparseOneDimensionalModel.h"
38 #include "data/model/SparseTimeValueModel.h" 38 #include "data/model/SparseTimeValueModel.h"
39 #include "data/model/NoteModel.h" 39 #include "data/model/NoteModel.h"
40 #include "data/model/FlexiNoteModel.h"
41 #include "data/model/RegionModel.h" 40 #include "data/model/RegionModel.h"
42 #include "data/model/TextModel.h" 41 #include "data/model/TextModel.h"
43 #include "data/model/ImageModel.h" 42 #include "data/model/ImageModel.h"
44 #include "data/model/DenseThreeDimensionalModel.h" 43 #include "data/model/DenseThreeDimensionalModel.h"
45 #include "data/model/WaveFileModel.h" 44 #include "data/model/WaveFileModel.h"
160 if (dynamic_cast<SparseTimeValueModel *>(model)) { 159 if (dynamic_cast<SparseTimeValueModel *>(model)) {
161 types.insert(TimeValues); 160 types.insert(TimeValues);
162 } 161 }
163 162
164 if (dynamic_cast<NoteModel *>(model)) { 163 if (dynamic_cast<NoteModel *>(model)) {
165 types.insert(Notes); 164 NoteModel *nm = dynamic_cast<NoteModel *>(model);
166 } 165 if (nm->getSubtype() == NoteModel::FLEXI_NOTE) {
167 166 types.insert(FlexiNotes);
168 // NOTE: GF: types is a set, so order of insertion does not matter 167 } else {
169 if (dynamic_cast<FlexiNoteModel *>(model)) { 168 types.insert(Notes);
170 types.insert(FlexiNotes); 169 }
171 } 170 }
172 171
173 if (dynamic_cast<RegionModel *>(model)) { 172 if (dynamic_cast<RegionModel *>(model)) {
174 types.insert(Regions); 173 types.insert(Regions);
175 } 174 }
325 return; 324 return;
326 325
327 if (trySetModel<NoteLayer, NoteModel>(layer, model)) 326 if (trySetModel<NoteLayer, NoteModel>(layer, model))
328 return; 327 return;
329 328
330 // GF: added FlexiNoteLayer 329 if (trySetModel<FlexiNoteLayer, NoteModel>(layer, model))
331 if (trySetModel<FlexiNoteLayer, FlexiNoteModel>(layer, model))
332 return; 330 return;
333 331
334 if (trySetModel<RegionLayer, RegionModel>(layer, model)) 332 if (trySetModel<RegionLayer, RegionModel>(layer, model))
335 return; 333 return;
336 334
359 if (layerType == TimeInstants) { 357 if (layerType == TimeInstants) {
360 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1); 358 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1);
361 } else if (layerType == TimeValues) { 359 } else if (layerType == TimeValues) {
362 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true); 360 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true);
363 } else if (layerType == FlexiNotes) { 361 } else if (layerType == FlexiNotes) {
364 return new FlexiNoteModel(baseModel->getSampleRate(), 1, true); 362 return new NoteModel(baseModel->getSampleRate(), 1, true);
365 } else if (layerType == Notes) { 363 } else if (layerType == Notes) {
366 return new NoteModel(baseModel->getSampleRate(), 1, true); 364 return new NoteModel(baseModel->getSampleRate(), 1, true);
367 } else if (layerType == Regions) { 365 } else if (layerType == Regions) {
368 return new RegionModel(baseModel->getSampleRate(), 1, true); 366 return new RegionModel(baseModel->getSampleRate(), 1, true);
369 } else if (layerType == Text) { 367 } else if (layerType == Text) {
497 495
498 QSettings settings; 496 QSettings settings;
499 settings.beginGroup("LayerDefaults"); 497 settings.beginGroup("LayerDefaults");
500 QString defaults = settings.value(getLayerTypeName(type), "").toString(); 498 QString defaults = settings.value(getLayerTypeName(type), "").toString();
501 if (defaults == "") return; 499 if (defaults == "") return;
502 500 setLayerProperties(layer, defaults);
503 // cerr << "defaults=\"" << defaults << "\"" << endl; 501 settings.endGroup();
504 502 }
505 QString xml = layer->toXmlString(); 503
504 void
505 LayerFactory::setLayerProperties(Layer *layer, QString newXml)
506 {
506 QDomDocument docOld, docNew; 507 QDomDocument docOld, docNew;
507 508 QString oldXml = layer->toXmlString();
508 if (docOld.setContent(xml, false) && 509
509 docNew.setContent(defaults, false)) { 510 if (!docOld.setContent(oldXml, false)) {
511 SVCERR << "LayerFactory::setLayerProperties: Failed to parse XML for existing layer properties! XML string is: " << oldXml << endl;
512 return;
513 }
514
515 if (!docNew.setContent(newXml, false)) {
516 SVCERR << "LayerFactory::setLayerProperties: Failed to parse XML: " << newXml << endl;
517 return;
518 }
510 519
511 QXmlAttributes attrs; 520 QXmlAttributes attrs;
512 521
513 QDomElement layerElt = docNew.firstChildElement("layer"); 522 QDomElement layerElt = docNew.firstChildElement("layer");
514 QDomNamedNodeMap attrNodes = layerElt.attributes(); 523 QDomNamedNodeMap attrNodes = layerElt.attributes();
515 524
516 for (int i = 0; i < attrNodes.length(); ++i) { 525 for (int i = 0; i < attrNodes.length(); ++i) {
517 QDomAttr attr = attrNodes.item(i).toAttr(); 526 QDomAttr attr = attrNodes.item(i).toAttr();
518 if (attr.isNull()) continue; 527 if (attr.isNull()) continue;
519 // cerr << "append \"" << attr.name() 528 // cerr << "append \"" << attr.name()
520 // << "\" -> \"" << attr.value() << "\"" 529 // << "\" -> \"" << attr.value() << "\""
521 // << endl; 530 // << endl;
522 attrs.append(attr.name(), "", "", attr.value()); 531 attrs.append(attr.name(), "", "", attr.value());
523 } 532 }
524 533
525 layerElt = docOld.firstChildElement("layer"); 534 layerElt = docOld.firstChildElement("layer");
526 attrNodes = layerElt.attributes(); 535 attrNodes = layerElt.attributes();
527 for (int i = 0; i < attrNodes.length(); ++i) { 536 for (int i = 0; i < attrNodes.length(); ++i) {
528 QDomAttr attr = attrNodes.item(i).toAttr(); 537 QDomAttr attr = attrNodes.item(i).toAttr();
529 if (attr.isNull()) continue; 538 if (attr.isNull()) continue;
530 if (attrs.value(attr.name()) == "") { 539 if (attrs.value(attr.name()) == "") {
531 // cerr << "append \"" << attr.name() 540 // cerr << "append \"" << attr.name()
532 // << "\" -> \"" << attr.value() << "\"" 541 // << "\" -> \"" << attr.value() << "\""
533 // << endl; 542 // << endl;
534 attrs.append(attr.name(), "", "", attr.value()); 543 attrs.append(attr.name(), "", "", attr.value());
535 }
536 } 544 }
537 545 }
538 layer->setProperties(attrs); 546
539 } 547 layer->setProperties(attrs);
540
541 settings.endGroup();
542 } 548 }
543 549
544 LayerFactory::LayerType 550 LayerFactory::LayerType
545 LayerFactory::getLayerTypeForClipboardContents(const Clipboard &clip) 551 LayerFactory::getLayerTypeForClipboardContents(const Clipboard &clip)
546 { 552 {
547 const Clipboard::PointList &contents = clip.getPoints(); 553 const EventVector &contents = clip.getPoints();
548 554
549 bool haveFrame = false;
550 bool haveValue = false; 555 bool haveValue = false;
551 bool haveDuration = false; 556 bool haveDuration = false;
552 bool haveLevel = false; 557 bool haveLevel = false;
553 558
554 for (Clipboard::PointList::const_iterator i = contents.begin(); 559 for (EventVector::const_iterator i = contents.begin();
555 i != contents.end(); ++i) { 560 i != contents.end(); ++i) {
556 if (i->haveFrame()) haveFrame = true; 561 if (i->hasValue()) haveValue = true;
557 if (i->haveValue()) haveValue = true; 562 if (i->hasDuration()) haveDuration = true;
558 if (i->haveDuration()) haveDuration = true; 563 if (i->hasLevel()) haveLevel = true;
559 if (i->haveLevel()) haveLevel = true; 564 }
560 } 565
561 566 if (haveValue && haveDuration && haveLevel) return Notes;
562 if (haveFrame && haveValue && haveDuration && haveLevel) return Notes; 567 if (haveValue && haveDuration) return Regions;
563 if (haveFrame && haveValue && haveDuration) return Regions; 568 if (haveValue) return TimeValues;
564 if (haveFrame && haveValue) return TimeValues;
565 return TimeInstants; 569 return TimeInstants;
566 } 570 }
567 571