Chris@58: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@59: Sonic Visualiser Chris@59: An audio file viewer and annotation editor. Chris@59: Centre for Digital Music, Queen Mary, University of London. Chris@59: This file copyright 2006 Chris Cannam. Chris@0: Chris@59: This program is free software; you can redistribute it and/or Chris@59: modify it under the terms of the GNU General Public License as Chris@59: published by the Free Software Foundation; either version 2 of the Chris@59: License, or (at your option) any later version. See the file Chris@59: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@1311: #ifndef SV_LAYER_FACTORY_H Chris@1311: #define SV_LAYER_FACTORY_H Chris@0: Chris@0: #include Chris@0: #include Chris@0: Chris@0: class Layer; Chris@0: class Model; Chris@360: class Clipboard; Chris@0: Chris@0: class LayerFactory Chris@0: { Chris@0: public: Chris@0: enum LayerType { Chris@0: Chris@1266: // Standard layers Chris@1266: Waveform, Chris@1266: Spectrogram, Chris@1266: TimeRuler, Chris@1266: TimeInstants, Chris@1266: TimeValues, Chris@1266: Notes, Chris@1266: FlexiNotes, Chris@1266: Regions, Chris@1266: Text, Chris@303: Image, Chris@1266: Colour3DPlot, Chris@133: Spectrum, Chris@193: Slice, Chris@0: Chris@1266: // Layers with different initial parameters Chris@1266: MelodicRangeSpectrogram, Chris@1266: PeakFrequencySpectrogram, Chris@0: Chris@1266: // Not-a-layer-type Chris@1266: UnknownLayer = 255 Chris@0: }; Chris@0: Chris@125: static LayerFactory *getInstance(); Chris@0: Chris@0: virtual ~LayerFactory(); Chris@0: Chris@0: typedef std::set LayerTypeSet; Chris@0: LayerTypeSet getValidLayerTypes(Model *model); Chris@962: Chris@962: /** Chris@962: * Return the set of layer types that an end user should be Chris@962: * allowed to create, empty, for subsequent editing. Chris@962: */ Chris@17: LayerTypeSet getValidEmptyLayerTypes(); Chris@0: Chris@6: LayerType getLayerType(const Layer *); Chris@0: Chris@53: Layer *createLayer(LayerType type); Chris@0: Chris@1455: /** Chris@1455: * Set the default properties of a layer, from the XML string Chris@1455: * contained in the LayerDefaults settings group for the given Chris@1455: * layer type. Leave unchanged any properties not mentioned in the Chris@1455: * settings. Chris@1455: */ Chris@326: void setLayerDefaultProperties(LayerType type, Layer *layer); Chris@326: Chris@1455: /** Chris@1455: * Set the properties of a layer, from the XML string Chris@1455: * provided. Leave unchanged any properties not mentioned. Chris@1455: */ Chris@1455: void setLayerProperties(Layer *layer, QString xmlString); Chris@1455: Chris@0: QString getLayerPresentationName(LayerType type); Chris@0: Chris@193: bool isLayerSliceable(const Layer *); Chris@193: Chris@0: void setModel(Layer *layer, Model *model); Chris@17: Model *createEmptyModel(LayerType type, Model *baseModel); Chris@0: Chris@53: int getChannel(Layer *layer); Chris@53: void setChannel(Layer *layer, int channel); Chris@53: Chris@17: QString getLayerIconName(LayerType); Chris@6: QString getLayerTypeName(LayerType); Chris@6: LayerType getLayerTypeForName(QString); Chris@6: Chris@360: LayerType getLayerTypeForClipboardContents(const Clipboard &); Chris@360: Chris@0: protected: Chris@0: template Chris@0: bool trySetModel(Layer *layerBase, Model *modelBase) { Chris@1266: LayerClass *layer = dynamic_cast(layerBase); Chris@1266: if (!layer) return false; Chris@1266: ModelClass *model = dynamic_cast(modelBase); Chris@1266: if (!model) return false; Chris@1266: layer->setModel(model); Chris@1266: return true; Chris@0: } Chris@0: Chris@0: static LayerFactory *m_instance; Chris@0: }; Chris@0: Chris@0: #endif Chris@0: