comparison layer/LayerFactory.cpp @ 193:57c2350a8c40

* Add slice layers (so you can display a slice of a colour 3d plot as if it were a spectrum) * Make spectrum layer a subclass of slice layer
author Chris Cannam
date Fri, 26 Jan 2007 16:59:57 +0000
parents b32282fefccd
children 447cb52adc6b
comparison
equal deleted inserted replaced
192:fcc043f75c41 193:57c2350a8c40
22 #include "TimeValueLayer.h" 22 #include "TimeValueLayer.h"
23 #include "NoteLayer.h" 23 #include "NoteLayer.h"
24 #include "TextLayer.h" 24 #include "TextLayer.h"
25 #include "Colour3DPlotLayer.h" 25 #include "Colour3DPlotLayer.h"
26 #include "SpectrumLayer.h" 26 #include "SpectrumLayer.h"
27 #include "SliceLayer.h"
28 #include "SliceableLayer.h"
27 29
28 #include "data/model/RangeSummarisableTimeValueModel.h" 30 #include "data/model/RangeSummarisableTimeValueModel.h"
29 #include "data/model/DenseTimeValueModel.h" 31 #include "data/model/DenseTimeValueModel.h"
30 #include "data/model/SparseOneDimensionalModel.h" 32 #include "data/model/SparseOneDimensionalModel.h"
31 #include "data/model/SparseTimeValueModel.h" 33 #include "data/model/SparseTimeValueModel.h"
59 case TimeValues: return Layer::tr("Time Values"); 61 case TimeValues: return Layer::tr("Time Values");
60 case Notes: return Layer::tr("Notes"); 62 case Notes: return Layer::tr("Notes");
61 case Text: return Layer::tr("Text"); 63 case Text: return Layer::tr("Text");
62 case Colour3DPlot: return Layer::tr("Colour 3D Plot"); 64 case Colour3DPlot: return Layer::tr("Colour 3D Plot");
63 case Spectrum: return Layer::tr("Spectrum"); 65 case Spectrum: return Layer::tr("Spectrum");
66 case Slice: return Layer::tr("Time Slice");
64 67
65 case MelodicRangeSpectrogram: 68 case MelodicRangeSpectrogram:
66 // The user can change all the parameters of this after the 69 // The user can change all the parameters of this after the
67 // fact -- there's nothing permanently melodic-range about it 70 // fact -- there's nothing permanently melodic-range about it
68 // that should be encoded in its name 71 // that should be encoded in its name
76 } 79 }
77 80
78 return Layer::tr("Layer"); 81 return Layer::tr("Layer");
79 } 82 }
80 83
84 bool
85 LayerFactory::isLayerSliceable(const Layer *layer)
86 {
87 if (dynamic_cast<const SliceableLayer *>(layer)) {
88 if (dynamic_cast<const SpectrogramLayer *>(layer)) {
89
90 //!!! We can create slices of spectrograms, but there's a
91 // problem managing the models. The source model for the
92 // slice layer has to be one of the spectrogram's FFT
93 // models -- that's fine, except that we can't store &
94 // recall the slice layer with a reference to that model
95 // because the model is internal to the spectrogram layer
96 // and the document has no record of it. We would need
97 // some other way of managing models that are used in this
98 // way. For the moment we just don't allow slices of
99 // spectrograms -- and provide a spectrum layer for this
100 // instead.
101 //
102 // This business needs a bit more thought -- either come
103 // up with a sensible way to deal with that stuff, or
104 // simplify the existing slice layer logic so that it
105 // doesn't have to deal with models disappearing on it at
106 // all (and use the normal Document setModel mechanism to
107 // set its sliceable model instead of the fancy pants
108 // nonsense it's doing at the moment).
109
110 return false;
111 }
112 return true;
113 }
114 return false;
115 }
116
81 LayerFactory::LayerTypeSet 117 LayerFactory::LayerTypeSet
82 LayerFactory::getValidLayerTypes(Model *model) 118 LayerFactory::getValidLayerTypes(Model *model)
83 { 119 {
84 LayerTypeSet types; 120 LayerTypeSet types;
85 121
86 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) { 122 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) {
87 types.insert(Colour3DPlot); 123 types.insert(Colour3DPlot);
124 types.insert(Slice);
125 }
126
127 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
128 types.insert(Waveform);
88 } 129 }
89 130
90 if (dynamic_cast<DenseTimeValueModel *>(model)) { 131 if (dynamic_cast<DenseTimeValueModel *>(model)) {
91 types.insert(Spectrogram); 132 types.insert(Spectrogram);
92 types.insert(MelodicRangeSpectrogram); 133 types.insert(MelodicRangeSpectrogram);
93 types.insert(PeakFrequencySpectrogram); 134 types.insert(PeakFrequencySpectrogram);
94 }
95
96 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) {
97 types.insert(Waveform);
98 } 135 }
99 136
100 if (dynamic_cast<SparseOneDimensionalModel *>(model)) { 137 if (dynamic_cast<SparseOneDimensionalModel *>(model)) {
101 types.insert(TimeInstants); 138 types.insert(TimeInstants);
102 } 139 }
145 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues; 182 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
146 if (dynamic_cast<const NoteLayer *>(layer)) return Notes; 183 if (dynamic_cast<const NoteLayer *>(layer)) return Notes;
147 if (dynamic_cast<const TextLayer *>(layer)) return Text; 184 if (dynamic_cast<const TextLayer *>(layer)) return Text;
148 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot; 185 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
149 if (dynamic_cast<const SpectrumLayer *>(layer)) return Spectrum; 186 if (dynamic_cast<const SpectrumLayer *>(layer)) return Spectrum;
187 if (dynamic_cast<const SliceLayer *>(layer)) return Slice;
150 return UnknownLayer; 188 return UnknownLayer;
151 } 189 }
152 190
153 QString 191 QString
154 LayerFactory::getLayerIconName(LayerType type) 192 LayerFactory::getLayerIconName(LayerType type)
161 case TimeValues: return "values"; 199 case TimeValues: return "values";
162 case Notes: return "notes"; 200 case Notes: return "notes";
163 case Text: return "text"; 201 case Text: return "text";
164 case Colour3DPlot: return "colour3d"; 202 case Colour3DPlot: return "colour3d";
165 case Spectrum: return "spectrum"; 203 case Spectrum: return "spectrum";
204 case Slice: return "spectrum";
166 default: return "unknown"; 205 default: return "unknown";
167 } 206 }
168 } 207 }
169 208
170 QString 209 QString
178 case TimeValues: return "timevalues"; 217 case TimeValues: return "timevalues";
179 case Notes: return "notes"; 218 case Notes: return "notes";
180 case Text: return "text"; 219 case Text: return "text";
181 case Colour3DPlot: return "colour3dplot"; 220 case Colour3DPlot: return "colour3dplot";
182 case Spectrum: return "spectrum"; 221 case Spectrum: return "spectrum";
222 case Slice: return "slice";
183 default: return "unknown"; 223 default: return "unknown";
184 } 224 }
185 } 225 }
186 226
187 LayerFactory::LayerType 227 LayerFactory::LayerType
194 if (name == "timevalues") return TimeValues; 234 if (name == "timevalues") return TimeValues;
195 if (name == "notes") return Notes; 235 if (name == "notes") return Notes;
196 if (name == "text") return Text; 236 if (name == "text") return Text;
197 if (name == "colour3dplot") return Colour3DPlot; 237 if (name == "colour3dplot") return Colour3DPlot;
198 if (name == "spectrum") return Spectrum; 238 if (name == "spectrum") return Spectrum;
239 if (name == "slice") return Slice;
199 return UnknownLayer; 240 return UnknownLayer;
200 } 241 }
201 242
202 void 243 void
203 LayerFactory::setModel(Layer *layer, Model *model) 244 LayerFactory::setModel(Layer *layer, Model *model)
235 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model)) 276 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
236 return; 277 return;
237 278
238 if (trySetModel<SpectrumLayer, DenseTimeValueModel>(layer, model)) 279 if (trySetModel<SpectrumLayer, DenseTimeValueModel>(layer, model))
239 return; 280 return;
281
282 // if (trySetModel<SliceLayer, DenseThreeDimensionalModel>(layer, model))
283 // return;
240 } 284 }
241 285
242 Model * 286 Model *
243 LayerFactory::createEmptyModel(LayerType layerType, Model *baseModel) 287 LayerFactory::createEmptyModel(LayerType layerType, Model *baseModel)
244 { 288 {
323 367
324 case Spectrum: 368 case Spectrum:
325 layer = new SpectrumLayer; 369 layer = new SpectrumLayer;
326 break; 370 break;
327 371
372 case Slice:
373 layer = new SliceLayer;
374 break;
375
328 case MelodicRangeSpectrogram: 376 case MelodicRangeSpectrogram:
329 layer = new SpectrogramLayer(SpectrogramLayer::MelodicRange); 377 layer = new SpectrogramLayer(SpectrogramLayer::MelodicRange);
330 break; 378 break;
331 379
332 case PeakFrequencySpectrogram: 380 case PeakFrequencySpectrogram: