annotate layer/LayerFactory.cpp @ 13:01849cd277e6

* Hook up tool selection buttons to switch the cursor mode * Implement simple and multi-selection, snapping to the resolution of the current layer. You can't actually do anything with a selection yet
author Chris Cannam
date Mon, 23 Jan 2006 17:02:57 +0000
parents 2d5005f2b3d9
children 0183ebb725ca
rev   line source
Chris@0 1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@5 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 #include "LayerFactory.h"
Chris@0 11
Chris@0 12 #include "WaveformLayer.h"
Chris@0 13 #include "SpectrogramLayer.h"
Chris@0 14 #include "TimeRulerLayer.h"
Chris@0 15 #include "TimeInstantLayer.h"
Chris@0 16 #include "TimeValueLayer.h"
Chris@0 17 #include "Colour3DPlotLayer.h"
Chris@0 18
Chris@0 19 #include "model/RangeSummarisableTimeValueModel.h"
Chris@0 20 #include "model/DenseTimeValueModel.h"
Chris@0 21 #include "model/SparseOneDimensionalModel.h"
Chris@0 22 #include "model/SparseTimeValueModel.h"
Chris@0 23 #include "model/DenseThreeDimensionalModel.h"
Chris@0 24
Chris@0 25 LayerFactory *
Chris@0 26 LayerFactory::m_instance = new LayerFactory;
Chris@0 27
Chris@0 28 LayerFactory *
Chris@0 29 LayerFactory::instance()
Chris@0 30 {
Chris@0 31 return m_instance;
Chris@0 32 }
Chris@0 33
Chris@0 34 LayerFactory::~LayerFactory()
Chris@0 35 {
Chris@0 36 }
Chris@0 37
Chris@0 38 QString
Chris@0 39 LayerFactory::getLayerPresentationName(LayerType type)
Chris@0 40 {
Chris@0 41 switch (type) {
Chris@0 42 case Waveform: return Layer::tr("Waveform");
Chris@0 43 case Spectrogram: return Layer::tr("Spectrogram");
Chris@0 44 case TimeRuler: return Layer::tr("Ruler");
Chris@0 45 case TimeInstants: return Layer::tr("Time Instants");
Chris@0 46 case TimeValues: return Layer::tr("Time Values");
Chris@0 47 case Colour3DPlot: return Layer::tr("Colour 3D Plot");
Chris@0 48
Chris@0 49 case MelodicRangeSpectrogram:
Chris@0 50 // The user can change all the parameters of this after the
Chris@0 51 // fact -- there's nothing permanently melodic-range about it
Chris@0 52 // that should be encoded in its name
Chris@0 53 return Layer::tr("Spectrogram");
Chris@11 54
Chris@11 55 default: break;
Chris@0 56 }
Chris@0 57
Chris@0 58 return Layer::tr("Layer");
Chris@0 59 }
Chris@0 60
Chris@0 61 LayerFactory::LayerTypeSet
Chris@0 62 LayerFactory::getValidLayerTypes(Model *model)
Chris@0 63 {
Chris@0 64 LayerTypeSet types;
Chris@0 65
Chris@0 66 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) {
Chris@0 67 types.insert(Colour3DPlot);
Chris@0 68 }
Chris@0 69
Chris@0 70 if (dynamic_cast<DenseTimeValueModel *>(model)) {
Chris@0 71 types.insert(Spectrogram);
Chris@0 72 types.insert(MelodicRangeSpectrogram);
Chris@0 73 }
Chris@0 74
Chris@0 75 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
Chris@0 76 types.insert(Waveform);
Chris@0 77 }
Chris@0 78
Chris@0 79 if (dynamic_cast<SparseOneDimensionalModel *>(model)) {
Chris@0 80 types.insert(TimeInstants);
Chris@0 81 }
Chris@0 82
Chris@0 83 if (dynamic_cast<SparseTimeValueModel *>(model)) {
Chris@0 84 types.insert(TimeValues);
Chris@0 85 }
Chris@0 86
Chris@0 87 // We don't count TimeRuler here as it doesn't actually display
Chris@0 88 // the data, although it can be backed by any model
Chris@0 89
Chris@0 90 return types;
Chris@0 91 }
Chris@0 92
Chris@0 93 LayerFactory::LayerType
Chris@6 94 LayerFactory::getLayerType(const Layer *layer)
Chris@0 95 {
Chris@6 96 if (dynamic_cast<const WaveformLayer *>(layer)) return Waveform;
Chris@6 97 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram;
Chris@6 98 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler;
Chris@6 99 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants;
Chris@6 100 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
Chris@6 101 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
Chris@6 102 return UnknownLayer;
Chris@6 103 }
Chris@6 104
Chris@6 105 QString
Chris@6 106 LayerFactory::getLayerTypeName(LayerType type)
Chris@6 107 {
Chris@6 108 switch (type) {
Chris@6 109 case Waveform: return "waveform";
Chris@6 110 case Spectrogram: return "spectrogram";
Chris@6 111 case TimeRuler: return "timeruler";
Chris@6 112 case TimeInstants: return "timeinstants";
Chris@6 113 case TimeValues: return "timevalues";
Chris@6 114 case Colour3DPlot: return "colour3dplot";
Chris@6 115 default: return "unknown";
Chris@6 116 }
Chris@6 117 }
Chris@6 118
Chris@6 119 LayerFactory::LayerType
Chris@6 120 LayerFactory::getLayerTypeForName(QString name)
Chris@6 121 {
Chris@6 122 if (name == "waveform") return Waveform;
Chris@6 123 if (name == "spectrogram") return Spectrogram;
Chris@6 124 if (name == "timeruler") return TimeRuler;
Chris@6 125 if (name == "timeinstants") return TimeInstants;
Chris@6 126 if (name == "timevalues") return TimeValues;
Chris@6 127 if (name == "colour3dplot") return Colour3DPlot;
Chris@0 128 return UnknownLayer;
Chris@0 129 }
Chris@0 130
Chris@0 131 void
Chris@0 132 LayerFactory::setModel(Layer *layer, Model *model)
Chris@0 133 {
Chris@0 134 if (trySetModel<WaveformLayer, RangeSummarisableTimeValueModel>(layer, model))
Chris@0 135 return;
Chris@0 136
Chris@0 137 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
Chris@0 138 return;
Chris@0 139
Chris@0 140 if (trySetModel<TimeRulerLayer, Model>(layer, model))
Chris@0 141 return;
Chris@0 142
Chris@0 143 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model))
Chris@0 144 return;
Chris@0 145
Chris@0 146 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model))
Chris@0 147 return;
Chris@0 148
Chris@0 149 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
Chris@0 150 return;
Chris@0 151
Chris@0 152 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
Chris@0 153 return;
Chris@0 154 }
Chris@0 155
Chris@0 156 Layer *
Chris@0 157 LayerFactory::createLayer(LayerType type, View *view,
Chris@0 158 Model *model, int channel)
Chris@0 159 {
Chris@0 160 Layer *layer = 0;
Chris@0 161
Chris@0 162 switch (type) {
Chris@0 163
Chris@0 164 case Waveform:
Chris@0 165 layer = new WaveformLayer(view);
Chris@0 166 static_cast<WaveformLayer *>(layer)->setChannel(channel);
Chris@0 167 break;
Chris@0 168
Chris@0 169 case Spectrogram:
Chris@0 170 layer = new SpectrogramLayer(view);
Chris@0 171 static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
Chris@0 172 break;
Chris@0 173
Chris@0 174 case TimeRuler:
Chris@0 175 layer = new TimeRulerLayer(view);
Chris@0 176 break;
Chris@0 177
Chris@0 178 case TimeInstants:
Chris@0 179 layer = new TimeInstantLayer(view);
Chris@0 180 break;
Chris@0 181
Chris@0 182 case TimeValues:
Chris@0 183 layer = new TimeValueLayer(view);
Chris@0 184 break;
Chris@0 185
Chris@0 186 case Colour3DPlot:
Chris@0 187 layer = new Colour3DPlotLayer(view);
Chris@0 188 break;
Chris@0 189
Chris@0 190 case MelodicRangeSpectrogram:
Chris@0 191 layer = new SpectrogramLayer(view, SpectrogramLayer::MelodicRange);
Chris@0 192 static_cast<SpectrogramLayer *>(layer)->setChannel(channel);
Chris@0 193 break;
Chris@11 194
Chris@11 195 default: break;
Chris@0 196 }
Chris@0 197
Chris@0 198 if (!layer) {
Chris@0 199 std::cerr << "LayerFactory::createLayer: Unknown layer type "
Chris@0 200 << type << std::endl;
Chris@0 201 } else {
Chris@8 202 if (model) setModel(layer, model);
Chris@0 203 std::cerr << "LayerFactory::createLayer: Setting object name "
Chris@0 204 << getLayerPresentationName(type).toStdString() << " on " << layer << std::endl;
Chris@0 205 layer->setObjectName(getLayerPresentationName(type));
Chris@0 206 }
Chris@0 207
Chris@0 208 return layer;
Chris@0 209 }
Chris@0 210