svgui
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _LAYER_FACTORY_H_ 00017 #define _LAYER_FACTORY_H_ 00018 00019 #include <QString> 00020 #include <set> 00021 00022 class Layer; 00023 class Model; 00024 class Clipboard; 00025 00026 class LayerFactory 00027 { 00028 public: 00029 enum LayerType { 00030 00031 // Standard layers 00032 Waveform, 00033 Spectrogram, 00034 TimeRuler, 00035 TimeInstants, 00036 TimeValues, 00037 Notes, 00038 FlexiNotes, 00039 Regions, 00040 Text, 00041 Image, 00042 Colour3DPlot, 00043 Spectrum, 00044 Slice, 00045 00046 // Layers with different initial parameters 00047 MelodicRangeSpectrogram, 00048 PeakFrequencySpectrogram, 00049 00050 // Not-a-layer-type 00051 UnknownLayer = 255 00052 }; 00053 00054 static LayerFactory *getInstance(); 00055 00056 virtual ~LayerFactory(); 00057 00058 typedef std::set<LayerType> LayerTypeSet; 00059 LayerTypeSet getValidLayerTypes(Model *model); 00060 LayerTypeSet getValidEmptyLayerTypes(); 00061 00062 LayerType getLayerType(const Layer *); 00063 00064 Layer *createLayer(LayerType type); 00065 00066 void setLayerDefaultProperties(LayerType type, Layer *layer); 00067 00068 QString getLayerPresentationName(LayerType type); 00069 00070 bool isLayerSliceable(const Layer *); 00071 00072 void setModel(Layer *layer, Model *model); 00073 Model *createEmptyModel(LayerType type, Model *baseModel); 00074 00075 int getChannel(Layer *layer); 00076 void setChannel(Layer *layer, int channel); 00077 00078 QString getLayerIconName(LayerType); 00079 QString getLayerTypeName(LayerType); 00080 LayerType getLayerTypeForName(QString); 00081 00082 LayerType getLayerTypeForClipboardContents(const Clipboard &); 00083 00084 protected: 00085 template <typename LayerClass, typename ModelClass> 00086 bool trySetModel(Layer *layerBase, Model *modelBase) { 00087 LayerClass *layer = dynamic_cast<LayerClass *>(layerBase); 00088 if (!layer) return false; 00089 ModelClass *model = dynamic_cast<ModelClass *>(modelBase); 00090 if (!model) return false; 00091 layer->setModel(model); 00092 return true; 00093 } 00094 00095 static LayerFactory *m_instance; 00096 }; 00097 00098 #endif 00099