1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 2 3 /* 4 Sonic Visualiser 5 An audio file viewer and annotation editor. 6 Centre for Digital Music, Queen Mary, University of London. 7 This file copyright 2006 Chris Cannam. 8 9 This program is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License as 11 published by the Free Software Foundation; either version 2 of the 12 License, or (at your option) any later version. See the file 13 COPYING included with this distribution for more information. 14 */ 15 16 #ifndef SV_LAYER_FACTORY_H 17 #define SV_LAYER_FACTORY_H 18 19 #include <QString> 20 #include <set> 21 22 #include "data/model/Model.h" 23 24 class Layer; 25 class Clipboard; 26 27 class LayerFactory 28 { 29 public: 30 enum LayerType { 31 32 // Standard layers 33 Waveform, 34 Spectrogram, 35 TimeRuler, 36 TimeInstants, 37 TimeValues, 38 Notes, 39 FlexiNotes, 40 Regions, 41 Boxes, 42 Text, 43 Image, 44 Colour3DPlot, 45 Spectrum, 46 Slice, 47 48 // Layers with different initial parameters 49 MelodicRangeSpectrogram, 50 PeakFrequencySpectrogram, 51 52 // Not-a-layer-type 53 UnknownLayer = 255 54 }; 55 56 static LayerFactory *getInstance(); 57 58 virtual ~LayerFactory(); 59 60 typedef std::set<LayerType> LayerTypeSet; 61 LayerTypeSet getValidLayerTypes(ModelId modelId); 62 63 /** 64 * Return the set of layer types that an end user should be 65 * allowed to create, empty, for subsequent editing. 66 */ 67 LayerTypeSet getValidEmptyLayerTypes(); 68 69 LayerType getLayerType(const Layer *); 70 71 Layer *createLayer(LayerType type); 72 73 /** 74 * Set the default properties of a layer, from the XML string 75 * contained in the LayerDefaults settings group for the given 76 * layer type. Leave unchanged any properties not mentioned in the 77 * settings. 78 */ 79 void setLayerDefaultProperties(LayerType type, Layer *layer); 80 81 /** 82 * Set the properties of a layer, from the XML string 83 * provided. Leave unchanged any properties not mentioned. 84 */ 85 void setLayerProperties(Layer *layer, QString xmlString); 86 87 QString getLayerPresentationName(LayerType type); 88 89 bool isLayerSliceable(const Layer *); 90 91 void setModel(Layer *layer, ModelId model); 92 std::shared_ptr<Model> createEmptyModel(LayerType type, ModelId baseModel); 93 94 int getChannel(Layer *layer); 95 void setChannel(Layer *layer, int channel); 96 97 QString getLayerIconName(LayerType); 98 QString getLayerTypeName(LayerType); 99 LayerType getLayerTypeForName(QString); 100 101 LayerType getLayerTypeForClipboardContents(const Clipboard &); 102 103 protected: 104 template <typename LayerClass, typename ModelClass> trySetModel(Layer * layerBase,ModelId modelId)105 bool trySetModel(Layer *layerBase, ModelId modelId) { 106 LayerClass *layer = dynamic_cast<LayerClass *>(layerBase); 107 if (!layer) return false; 108 if (!modelId.isNone()) { 109 auto model = ModelById::getAs<ModelClass>(modelId); 110 if (!model) return false; 111 } 112 layer->setModel(modelId); 113 return true; 114 } 115 116 static LayerFactory *m_instance; 117 }; 118 119 #endif 120 121