LayerFactory.h

Go to the documentation of this file.
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         Text,
00039         Image,
00040         Colour3DPlot,
00041         Spectrum,
00042         Slice,
00043 
00044         // Layers with different initial parameters
00045         MelodicRangeSpectrogram,
00046         PeakFrequencySpectrogram,
00047 
00048         // Not-a-layer-type
00049         UnknownLayer = 255
00050     };
00051 
00052     static LayerFactory *getInstance();
00053     
00054     virtual ~LayerFactory();
00055 
00056     typedef std::set<LayerType> LayerTypeSet;
00057     LayerTypeSet getValidLayerTypes(Model *model);
00058     LayerTypeSet getValidEmptyLayerTypes();
00059 
00060     LayerType getLayerType(const Layer *);
00061 
00062     Layer *createLayer(LayerType type);
00063 
00064     void setLayerDefaultProperties(LayerType type, Layer *layer);
00065 
00066     QString getLayerPresentationName(LayerType type);
00067 
00068     bool isLayerSliceable(const Layer *);
00069 
00070     void setModel(Layer *layer, Model *model);
00071     Model *createEmptyModel(LayerType type, Model *baseModel);
00072 
00073     int getChannel(Layer *layer);
00074     void setChannel(Layer *layer, int channel);
00075 
00076     QString getLayerIconName(LayerType);
00077     QString getLayerTypeName(LayerType);
00078     LayerType getLayerTypeForName(QString);
00079 
00080     LayerType getLayerTypeForClipboardContents(const Clipboard &);
00081 
00082 protected:
00083     template <typename LayerClass, typename ModelClass>
00084     bool trySetModel(Layer *layerBase, Model *modelBase) {
00085         LayerClass *layer = dynamic_cast<LayerClass *>(layerBase);
00086         if (!layer) return false;
00087         ModelClass *model = dynamic_cast<ModelClass *>(modelBase);
00088         if (!model) return false;
00089         layer->setModel(model);
00090         return true;
00091     }
00092 
00093     static LayerFactory *m_instance;
00094 };
00095 
00096 #endif
00097 

Generated on Wed Feb 20 15:45:26 2008 for SonicVisualiser by  doxygen 1.5.1