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@0: #ifndef _LAYER_FACTORY_H_
Chris@0: #define _LAYER_FACTORY_H_
Chris@0: 
Chris@0: #include <QString>
Chris@0: #include <set>
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@0: 	// Standard layers
Chris@0: 	Waveform,
Chris@0: 	Spectrogram,
Chris@0: 	TimeRuler,
Chris@0: 	TimeInstants,
Chris@0: 	TimeValues,
Chris@30: 	Notes,
matthiasm@622: 	FlexiNotes,
Chris@411: 	Regions,
Chris@35: 	Text,
Chris@303:         Image,
Chris@0: 	Colour3DPlot,
Chris@133:         Spectrum,
Chris@193:         Slice,
Chris@0: 
Chris@0: 	// Layers with different initial parameters
Chris@0: 	MelodicRangeSpectrogram,
Chris@37: 	PeakFrequencySpectrogram,
Chris@0: 
Chris@0: 	// Not-a-layer-type
Chris@0: 	UnknownLayer = 255
Chris@0:     };
Chris@0: 
Chris@125:     static LayerFactory *getInstance();
Chris@0:     
Chris@0:     virtual ~LayerFactory();
Chris@0: 
Chris@0:     typedef std::set<LayerType> LayerTypeSet;
Chris@0:     LayerTypeSet getValidLayerTypes(Model *model);
Chris@17:     LayerTypeSet getValidEmptyLayerTypes();
Chris@0: 
Chris@6:     LayerType getLayerType(const Layer *);
Chris@0: 
Chris@53:     Layer *createLayer(LayerType type);
Chris@0: 
Chris@326:     void setLayerDefaultProperties(LayerType type, Layer *layer);
Chris@326: 
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 <typename LayerClass, typename ModelClass>
Chris@0:     bool trySetModel(Layer *layerBase, Model *modelBase) {
Chris@0: 	LayerClass *layer = dynamic_cast<LayerClass *>(layerBase);
Chris@0: 	if (!layer) return false;
Chris@0: 	ModelClass *model = dynamic_cast<ModelClass *>(modelBase);
Chris@17: 	if (!model) return false;
Chris@0: 	layer->setModel(model);
Chris@0: 	return true;
Chris@0:     }
Chris@0: 
Chris@0:     static LayerFactory *m_instance;
Chris@0: };
Chris@0: 
Chris@0: #endif
Chris@0: