34 #include "base/Clipboard.h" 36 #include "data/model/RangeSummarisableTimeValueModel.h" 37 #include "data/model/DenseTimeValueModel.h" 38 #include "data/model/SparseOneDimensionalModel.h" 39 #include "data/model/SparseTimeValueModel.h" 40 #include "data/model/NoteModel.h" 41 #include "data/model/RegionModel.h" 42 #include "data/model/BoxModel.h" 43 #include "data/model/TextModel.h" 44 #include "data/model/ImageModel.h" 45 #include "data/model/DenseThreeDimensionalModel.h" 46 #include "data/model/WaveFileModel.h" 47 #include "data/model/WritableWaveFileModel.h" 49 #include <QDomDocument> 50 #include <QDomElement> 51 #include <QDomNamedNodeMap> 73 case Waveform:
return Layer::tr(
"Waveform");
75 case TimeRuler:
return Layer::tr(
"Ruler");
77 case TimeValues:
return Layer::tr(
"Time Values");
78 case Notes:
return Layer::tr(
"Notes");
79 case FlexiNotes:
return Layer::tr(
"Flexible Notes");
80 case Regions:
return Layer::tr(
"Regions");
81 case Boxes:
return Layer::tr(
"Boxes");
82 case Text:
return Layer::tr(
"Text");
83 case Image:
return Layer::tr(
"Images");
85 case Spectrum:
return Layer::tr(
"Spectrum");
86 case Slice:
return Layer::tr(
"Time Slice");
92 return Layer::tr(
"Spectrogram");
96 return Layer::tr(
"Spectrogram");
100 cerr <<
"WARNING: LayerFactory::getLayerPresentationName passed unknown layer" << endl;
101 return Layer::tr(
"Unknown Layer");
108 if (dynamic_cast<const SliceableLayer *>(layer)) {
109 if (dynamic_cast<const SpectrogramLayer *>(layer)) {
143 if (ModelById::getAs<DenseThreeDimensionalModel>(modelId)) {
148 if (ModelById::getAs<RangeSummarisableTimeValueModel>(modelId)) {
152 if (ModelById::getAs<DenseTimeValueModel>(modelId)) {
158 if (ModelById::getAs<SparseOneDimensionalModel>(modelId)) {
162 if (ModelById::getAs<SparseTimeValueModel>(modelId)) {
166 if (ModelById::getAs<NoteModel>(modelId)) {
167 auto nm = ModelById::getAs<NoteModel>(modelId);
168 if (nm && nm->getSubtype() == NoteModel::FLEXI_NOTE) {
175 if (ModelById::getAs<RegionModel>(modelId)) {
179 if (ModelById::getAs<BoxModel>(modelId)) {
183 if (ModelById::getAs<TextModel>(modelId)) {
187 if (ModelById::getAs<ImageModel>(modelId)) {
191 if (ModelById::getAs<DenseTimeValueModel>(modelId)) {
223 if (dynamic_cast<const WaveformLayer *>(layer))
return Waveform;
224 if (dynamic_cast<const SpectrogramLayer *>(layer))
return Spectrogram;
225 if (dynamic_cast<const TimeRulerLayer *>(layer))
return TimeRuler;
226 if (dynamic_cast<const TimeInstantLayer *>(layer))
return TimeInstants;
227 if (dynamic_cast<const TimeValueLayer *>(layer))
return TimeValues;
228 if (dynamic_cast<const FlexiNoteLayer *>(layer))
return FlexiNotes;
229 if (dynamic_cast<const NoteLayer *>(layer))
return Notes;
230 if (dynamic_cast<const RegionLayer *>(layer))
return Regions;
231 if (dynamic_cast<const BoxLayer *>(layer))
return Boxes;
232 if (dynamic_cast<const TextLayer *>(layer))
return Text;
233 if (dynamic_cast<const ImageLayer *>(layer))
return Image;
234 if (dynamic_cast<const Colour3DPlotLayer *>(layer))
return Colour3DPlot;
235 if (dynamic_cast<const SpectrumLayer *>(layer))
return Spectrum;
236 if (dynamic_cast<const SliceLayer *>(layer))
return Slice;
249 case Notes:
return "notes";
251 case Regions:
return "regions";
252 case Boxes:
return "boxes";
253 case Text:
return "text";
254 case Image:
return "image";
257 case Slice:
return "spectrum";
262 cerr <<
"WARNING: LayerFactory::getLayerIconName passed unknown layer" << endl;
276 case Notes:
return "notes";
278 case Regions:
return "regions";
279 case Boxes:
return "boxes";
280 case Text:
return "text";
281 case Image:
return "image";
284 case Slice:
return "slice";
289 cerr <<
"WARNING: LayerFactory::getLayerTypeName passed unknown layer" << endl;
297 if (name ==
"waveform")
return Waveform;
299 if (name ==
"timeruler")
return TimeRuler;
302 if (name ==
"notes")
return Notes;
304 if (name ==
"regions")
return Regions;
305 if (name ==
"boxes" || name ==
"timefrequencybox")
return Boxes;
306 if (name ==
"text")
return Text;
307 if (name ==
"image")
return Image;
309 if (name ==
"spectrum")
return Spectrum;
310 if (name ==
"slice")
return Slice;
319 if (trySetModel<WaveformLayer, WaveFileModel>(layer, model))
322 if (trySetModel<WaveformLayer, WritableWaveFileModel>(layer, model))
325 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
328 if (trySetModel<TimeRulerLayer, Model>(layer, model))
331 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model))
334 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
337 if (trySetModel<NoteLayer, NoteModel>(layer, model))
340 if (trySetModel<FlexiNoteLayer, NoteModel>(layer, model))
343 if (trySetModel<RegionLayer, RegionModel>(layer, model))
346 if (trySetModel<BoxLayer, BoxModel>(layer, model))
349 if (trySetModel<TextLayer, TextModel>(layer, model))
352 if (trySetModel<ImageLayer, ImageModel>(layer, model))
355 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
358 if (trySetModel<SpectrumLayer, DenseTimeValueModel>(layer, model))
362 std::shared_ptr<Model>
365 auto baseModel = ModelById::get(baseModelId);
366 if (!baseModel)
return {};
368 sv_samplerate_t rate = baseModel->getSampleRate();
371 return std::make_shared<SparseOneDimensionalModel>(rate, 1);
373 return std::make_shared<SparseTimeValueModel>(rate, 1,
true);
375 return std::make_shared<NoteModel>(rate, 1,
true);
376 }
else if (layerType ==
Notes) {
377 return std::make_shared<NoteModel>(rate, 1,
true);
378 }
else if (layerType ==
Regions) {
379 return std::make_shared<RegionModel>(rate, 1,
true);
380 }
else if (layerType ==
Boxes) {
381 return std::make_shared<BoxModel>(rate, 1,
true);
382 }
else if (layerType ==
Text) {
383 return std::make_shared<TextModel>(rate, 1,
true);
384 }
else if (layerType ==
Image) {
385 return std::make_shared<ImageModel>(rate, 1,
true);
394 if (dynamic_cast<WaveformLayer *>(layer)) {
397 if (dynamic_cast<SpectrogramLayer *>(layer)) {
406 if (dynamic_cast<WaveformLayer *>(layer)) {
410 if (dynamic_cast<SpectrogramLayer *>(layer)) {
414 if (dynamic_cast<SpectrumLayer *>(layer)) {
423 Layer *layer =
nullptr;
493 cerr <<
"WARNING: LayerFactory::createLayer passed unknown layer" << endl;
498 cerr <<
"LayerFactory::createLayer: Unknown layer type " 516 settings.beginGroup(
"LayerDefaults");
518 if (defaults ==
"")
return;
526 QDomDocument docOld, docNew;
527 QString oldXml = layer->toXmlString();
529 if (!docOld.setContent(oldXml,
false)) {
530 SVCERR <<
"LayerFactory::setLayerProperties: Failed to parse XML for existing layer properties! XML string is: " << oldXml << endl;
534 if (!docNew.setContent(newXml,
false)) {
535 SVCERR <<
"LayerFactory::setLayerProperties: Failed to parse XML: " << newXml << endl;
539 QXmlAttributes attrs;
541 QDomElement layerElt = docNew.firstChildElement(
"layer");
542 QDomNamedNodeMap attrNodes = layerElt.attributes();
544 for (
int i = 0; i < attrNodes.length(); ++i) {
545 QDomAttr attr = attrNodes.item(i).toAttr();
546 if (attr.isNull())
continue;
550 attrs.append(attr.name(),
"",
"", attr.value());
553 layerElt = docOld.firstChildElement(
"layer");
554 attrNodes = layerElt.attributes();
555 for (
int i = 0; i < attrNodes.length(); ++i) {
556 QDomAttr attr = attrNodes.item(i).toAttr();
557 if (attr.isNull())
continue;
558 if (attrs.value(attr.name()) ==
"") {
562 attrs.append(attr.name(),
"",
"", attr.value());
572 const EventVector &contents = clip.getPoints();
574 bool haveValue =
false;
575 bool haveDuration =
false;
576 bool haveLevel =
false;
578 for (EventVector::const_iterator i = contents.begin();
579 i != contents.end(); ++i) {
580 if (i->hasValue()) haveValue =
true;
581 if (i->hasDuration()) haveDuration =
true;
582 if (i->hasLevel()) haveLevel =
true;
585 if (haveValue && haveDuration && haveLevel)
return Notes;
586 if (haveValue && haveDuration)
return Regions;
static LayerFactory * getInstance()
QString getLayerIconName(LayerType)
The base class for visual representations of the data found in a Model.
virtual void setProperties(const QXmlAttributes &)=0
Set the particular properties of a layer (those specific to the subclass) from a set of XML attribute...
LayerTypeSet getValidLayerTypes(ModelId modelId)
SpectrogramLayer represents waveform data (obtained from a DenseTimeValueModel) in spectrogram form...
bool isLayerSliceable(const Layer *)
LayerType getLayerTypeForName(QString)
void setModel(Layer *layer, ModelId model)
This is a view that displays dense 3-D data (time, some sort of binned y-axis range, value) as a colour plot with value mapped to colour range.
LayerTypeSet getValidEmptyLayerTypes()
Return the set of layer types that an end user should be allowed to create, empty, for subsequent editing.
int getChannel(Layer *layer)
virtual void setObjectName(const QString &name)
QString getLayerPresentationName(LayerType type)
static LayerFactory * m_instance
void setChannel(Layer *layer, int channel)
Layer for displaying and editing notes, i.e.
Layer * createLayer(LayerType type)
void setLayerProperties(Layer *layer, QString xmlString)
Set the properties of a layer, from the XML string provided.
std::set< LayerType > LayerTypeSet
LayerType getLayerType(const Layer *)
LayerType getLayerTypeForClipboardContents(const Clipboard &)
QString getLayerTypeName(LayerType)
std::shared_ptr< Model > createEmptyModel(LayerType type, ModelId baseModel)
void setLayerDefaultProperties(LayerType type, Layer *layer)
Set the default properties of a layer, from the XML string contained in the LayerDefaults settings gr...