comparison layer/LayerFactory.cpp @ 303:46faec7aae12

* Phase 1 of an image layer.
author Chris Cannam
date Thu, 04 Oct 2007 16:34:11 +0000
parents 447cb52adc6b
children 4f4f38a11cd2
comparison
equal deleted inserted replaced
302:e9549ea3f825 303:46faec7aae12
20 #include "TimeRulerLayer.h" 20 #include "TimeRulerLayer.h"
21 #include "TimeInstantLayer.h" 21 #include "TimeInstantLayer.h"
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 "ImageLayer.h"
25 #include "Colour3DPlotLayer.h" 26 #include "Colour3DPlotLayer.h"
26 #include "SpectrumLayer.h" 27 #include "SpectrumLayer.h"
27 #include "SliceLayer.h" 28 #include "SliceLayer.h"
28 #include "SliceableLayer.h" 29 #include "SliceableLayer.h"
29 30
31 #include "data/model/DenseTimeValueModel.h" 32 #include "data/model/DenseTimeValueModel.h"
32 #include "data/model/SparseOneDimensionalModel.h" 33 #include "data/model/SparseOneDimensionalModel.h"
33 #include "data/model/SparseTimeValueModel.h" 34 #include "data/model/SparseTimeValueModel.h"
34 #include "data/model/NoteModel.h" 35 #include "data/model/NoteModel.h"
35 #include "data/model/TextModel.h" 36 #include "data/model/TextModel.h"
37 #include "data/model/ImageModel.h"
36 #include "data/model/DenseThreeDimensionalModel.h" 38 #include "data/model/DenseThreeDimensionalModel.h"
37 #include "data/model/WaveFileModel.h" 39 #include "data/model/WaveFileModel.h"
38 #include "data/model/WritableWaveFileModel.h" 40 #include "data/model/WritableWaveFileModel.h"
39 41
40 LayerFactory * 42 LayerFactory *
59 case TimeRuler: return Layer::tr("Ruler"); 61 case TimeRuler: return Layer::tr("Ruler");
60 case TimeInstants: return Layer::tr("Time Instants"); 62 case TimeInstants: return Layer::tr("Time Instants");
61 case TimeValues: return Layer::tr("Time Values"); 63 case TimeValues: return Layer::tr("Time Values");
62 case Notes: return Layer::tr("Notes"); 64 case Notes: return Layer::tr("Notes");
63 case Text: return Layer::tr("Text"); 65 case Text: return Layer::tr("Text");
66 case Image: return Layer::tr("Images");
64 case Colour3DPlot: return Layer::tr("Colour 3D Plot"); 67 case Colour3DPlot: return Layer::tr("Colour 3D Plot");
65 case Spectrum: return Layer::tr("Spectrum"); 68 case Spectrum: return Layer::tr("Spectrum");
66 case Slice: return Layer::tr("Time Slice"); 69 case Slice: return Layer::tr("Time Slice");
67 70
68 case MelodicRangeSpectrogram: 71 case MelodicRangeSpectrogram:
148 151
149 if (dynamic_cast<TextModel *>(model)) { 152 if (dynamic_cast<TextModel *>(model)) {
150 types.insert(Text); 153 types.insert(Text);
151 } 154 }
152 155
156 if (dynamic_cast<ImageModel *>(model)) {
157 types.insert(Image);
158 }
159
153 if (dynamic_cast<DenseTimeValueModel *>(model)) { 160 if (dynamic_cast<DenseTimeValueModel *>(model)) {
154 types.insert(Spectrum); 161 types.insert(Spectrum);
155 } 162 }
156 163
157 // We don't count TimeRuler here as it doesn't actually display 164 // We don't count TimeRuler here as it doesn't actually display
166 LayerTypeSet types; 173 LayerTypeSet types;
167 types.insert(TimeInstants); 174 types.insert(TimeInstants);
168 types.insert(TimeValues); 175 types.insert(TimeValues);
169 types.insert(Notes); 176 types.insert(Notes);
170 types.insert(Text); 177 types.insert(Text);
178 types.insert(Image);
171 //!!! and in principle Colour3DPlot -- now that's a challenge 179 //!!! and in principle Colour3DPlot -- now that's a challenge
172 return types; 180 return types;
173 } 181 }
174 182
175 LayerFactory::LayerType 183 LayerFactory::LayerType
180 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler; 188 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler;
181 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants; 189 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants;
182 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues; 190 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues;
183 if (dynamic_cast<const NoteLayer *>(layer)) return Notes; 191 if (dynamic_cast<const NoteLayer *>(layer)) return Notes;
184 if (dynamic_cast<const TextLayer *>(layer)) return Text; 192 if (dynamic_cast<const TextLayer *>(layer)) return Text;
193 if (dynamic_cast<const ImageLayer *>(layer)) return Image;
185 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot; 194 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot;
186 if (dynamic_cast<const SpectrumLayer *>(layer)) return Spectrum; 195 if (dynamic_cast<const SpectrumLayer *>(layer)) return Spectrum;
187 if (dynamic_cast<const SliceLayer *>(layer)) return Slice; 196 if (dynamic_cast<const SliceLayer *>(layer)) return Slice;
188 return UnknownLayer; 197 return UnknownLayer;
189 } 198 }
197 case TimeRuler: return "timeruler"; 206 case TimeRuler: return "timeruler";
198 case TimeInstants: return "instants"; 207 case TimeInstants: return "instants";
199 case TimeValues: return "values"; 208 case TimeValues: return "values";
200 case Notes: return "notes"; 209 case Notes: return "notes";
201 case Text: return "text"; 210 case Text: return "text";
211 case Image: return "image";
202 case Colour3DPlot: return "colour3d"; 212 case Colour3DPlot: return "colour3d";
203 case Spectrum: return "spectrum"; 213 case Spectrum: return "spectrum";
204 case Slice: return "spectrum"; 214 case Slice: return "spectrum";
205 default: return "unknown"; 215 default: return "unknown";
206 } 216 }
215 case TimeRuler: return "timeruler"; 225 case TimeRuler: return "timeruler";
216 case TimeInstants: return "timeinstants"; 226 case TimeInstants: return "timeinstants";
217 case TimeValues: return "timevalues"; 227 case TimeValues: return "timevalues";
218 case Notes: return "notes"; 228 case Notes: return "notes";
219 case Text: return "text"; 229 case Text: return "text";
230 case Image: return "image";
220 case Colour3DPlot: return "colour3dplot"; 231 case Colour3DPlot: return "colour3dplot";
221 case Spectrum: return "spectrum"; 232 case Spectrum: return "spectrum";
222 case Slice: return "slice"; 233 case Slice: return "slice";
223 default: return "unknown"; 234 default: return "unknown";
224 } 235 }
232 if (name == "timeruler") return TimeRuler; 243 if (name == "timeruler") return TimeRuler;
233 if (name == "timeinstants") return TimeInstants; 244 if (name == "timeinstants") return TimeInstants;
234 if (name == "timevalues") return TimeValues; 245 if (name == "timevalues") return TimeValues;
235 if (name == "notes") return Notes; 246 if (name == "notes") return Notes;
236 if (name == "text") return Text; 247 if (name == "text") return Text;
248 if (name == "image") return Image;
237 if (name == "colour3dplot") return Colour3DPlot; 249 if (name == "colour3dplot") return Colour3DPlot;
238 if (name == "spectrum") return Spectrum; 250 if (name == "spectrum") return Spectrum;
239 if (name == "slice") return Slice; 251 if (name == "slice") return Slice;
240 return UnknownLayer; 252 return UnknownLayer;
241 } 253 }
266 278
267 if (trySetModel<NoteLayer, NoteModel>(layer, model)) 279 if (trySetModel<NoteLayer, NoteModel>(layer, model))
268 return; 280 return;
269 281
270 if (trySetModel<TextLayer, TextModel>(layer, model)) 282 if (trySetModel<TextLayer, TextModel>(layer, model))
283 return;
284
285 if (trySetModel<ImageLayer, ImageModel>(layer, model))
271 return; 286 return;
272 287
273 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model)) 288 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
274 return; 289 return;
275 290
292 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true); 307 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true);
293 } else if (layerType == Notes) { 308 } else if (layerType == Notes) {
294 return new NoteModel(baseModel->getSampleRate(), 1, true); 309 return new NoteModel(baseModel->getSampleRate(), 1, true);
295 } else if (layerType == Text) { 310 } else if (layerType == Text) {
296 return new TextModel(baseModel->getSampleRate(), 1, true); 311 return new TextModel(baseModel->getSampleRate(), 1, true);
312 } else if (layerType == Image) {
313 return new ImageModel(baseModel->getSampleRate(), 1, true);
297 } else { 314 } else {
298 return 0; 315 return 0;
299 } 316 }
300 } 317 }
301 318
355 layer = new NoteLayer; 372 layer = new NoteLayer;
356 break; 373 break;
357 374
358 case Text: 375 case Text:
359 layer = new TextLayer; 376 layer = new TextLayer;
377 break;
378
379 case Image:
380 layer = new ImageLayer;
360 break; 381 break;
361 382
362 case Colour3DPlot: 383 case Colour3DPlot:
363 layer = new Colour3DPlotLayer; 384 layer = new Colour3DPlotLayer;
364 break; 385 break;