Mercurial > hg > svgui
comparison layer/LayerFactory.cpp @ 411:96e4d7b9e165
* Add region model and layer; improve assignment of model types to
feature extraction transforms with duration
author | Chris Cannam |
---|---|
date | Thu, 18 Sep 2008 16:08:14 +0000 |
parents | d58701996fae |
children | 1fe7951a61e8 |
comparison
equal
deleted
inserted
replaced
410:33b7f5e54d60 | 411:96e4d7b9e165 |
---|---|
19 #include "SpectrogramLayer.h" | 19 #include "SpectrogramLayer.h" |
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 "RegionLayer.h" | |
24 #include "TextLayer.h" | 25 #include "TextLayer.h" |
25 #include "ImageLayer.h" | 26 #include "ImageLayer.h" |
26 #include "Colour3DPlotLayer.h" | 27 #include "Colour3DPlotLayer.h" |
27 #include "SpectrumLayer.h" | 28 #include "SpectrumLayer.h" |
28 #include "SliceLayer.h" | 29 #include "SliceLayer.h" |
33 #include "data/model/RangeSummarisableTimeValueModel.h" | 34 #include "data/model/RangeSummarisableTimeValueModel.h" |
34 #include "data/model/DenseTimeValueModel.h" | 35 #include "data/model/DenseTimeValueModel.h" |
35 #include "data/model/SparseOneDimensionalModel.h" | 36 #include "data/model/SparseOneDimensionalModel.h" |
36 #include "data/model/SparseTimeValueModel.h" | 37 #include "data/model/SparseTimeValueModel.h" |
37 #include "data/model/NoteModel.h" | 38 #include "data/model/NoteModel.h" |
39 #include "data/model/RegionModel.h" | |
38 #include "data/model/TextModel.h" | 40 #include "data/model/TextModel.h" |
39 #include "data/model/ImageModel.h" | 41 #include "data/model/ImageModel.h" |
40 #include "data/model/DenseThreeDimensionalModel.h" | 42 #include "data/model/DenseThreeDimensionalModel.h" |
41 #include "data/model/WaveFileModel.h" | 43 #include "data/model/WaveFileModel.h" |
42 #include "data/model/WritableWaveFileModel.h" | 44 #include "data/model/WritableWaveFileModel.h" |
69 case Spectrogram: return Layer::tr("Spectrogram"); | 71 case Spectrogram: return Layer::tr("Spectrogram"); |
70 case TimeRuler: return Layer::tr("Ruler"); | 72 case TimeRuler: return Layer::tr("Ruler"); |
71 case TimeInstants: return Layer::tr("Time Instants"); | 73 case TimeInstants: return Layer::tr("Time Instants"); |
72 case TimeValues: return Layer::tr("Time Values"); | 74 case TimeValues: return Layer::tr("Time Values"); |
73 case Notes: return Layer::tr("Notes"); | 75 case Notes: return Layer::tr("Notes"); |
76 case Regions: return Layer::tr("Regions"); | |
74 case Text: return Layer::tr("Text"); | 77 case Text: return Layer::tr("Text"); |
75 case Image: return Layer::tr("Images"); | 78 case Image: return Layer::tr("Images"); |
76 case Colour3DPlot: return Layer::tr("Colour 3D Plot"); | 79 case Colour3DPlot: return Layer::tr("Colour 3D Plot"); |
77 case Spectrum: return Layer::tr("Spectrum"); | 80 case Spectrum: return Layer::tr("Spectrum"); |
78 case Slice: return Layer::tr("Time Slice"); | 81 case Slice: return Layer::tr("Time Slice"); |
150 types.insert(TimeInstants); | 153 types.insert(TimeInstants); |
151 } | 154 } |
152 | 155 |
153 if (dynamic_cast<SparseTimeValueModel *>(model)) { | 156 if (dynamic_cast<SparseTimeValueModel *>(model)) { |
154 types.insert(TimeValues); | 157 types.insert(TimeValues); |
155 | 158 } |
156 } | 159 |
157 if (dynamic_cast<NoteModel *>(model)) { | 160 if (dynamic_cast<NoteModel *>(model)) { |
158 types.insert(Notes); | 161 types.insert(Notes); |
162 } | |
163 | |
164 if (dynamic_cast<RegionModel *>(model)) { | |
165 types.insert(Regions); | |
159 } | 166 } |
160 | 167 |
161 if (dynamic_cast<TextModel *>(model)) { | 168 if (dynamic_cast<TextModel *>(model)) { |
162 types.insert(Text); | 169 types.insert(Text); |
163 } | 170 } |
181 { | 188 { |
182 LayerTypeSet types; | 189 LayerTypeSet types; |
183 types.insert(TimeInstants); | 190 types.insert(TimeInstants); |
184 types.insert(TimeValues); | 191 types.insert(TimeValues); |
185 types.insert(Notes); | 192 types.insert(Notes); |
193 types.insert(Regions); | |
186 types.insert(Text); | 194 types.insert(Text); |
187 types.insert(Image); | 195 types.insert(Image); |
188 //!!! and in principle Colour3DPlot -- now that's a challenge | 196 //!!! and in principle Colour3DPlot -- now that's a challenge |
189 return types; | 197 return types; |
190 } | 198 } |
196 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram; | 204 if (dynamic_cast<const SpectrogramLayer *>(layer)) return Spectrogram; |
197 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler; | 205 if (dynamic_cast<const TimeRulerLayer *>(layer)) return TimeRuler; |
198 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants; | 206 if (dynamic_cast<const TimeInstantLayer *>(layer)) return TimeInstants; |
199 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues; | 207 if (dynamic_cast<const TimeValueLayer *>(layer)) return TimeValues; |
200 if (dynamic_cast<const NoteLayer *>(layer)) return Notes; | 208 if (dynamic_cast<const NoteLayer *>(layer)) return Notes; |
209 if (dynamic_cast<const RegionLayer *>(layer)) return Regions; | |
201 if (dynamic_cast<const TextLayer *>(layer)) return Text; | 210 if (dynamic_cast<const TextLayer *>(layer)) return Text; |
202 if (dynamic_cast<const ImageLayer *>(layer)) return Image; | 211 if (dynamic_cast<const ImageLayer *>(layer)) return Image; |
203 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot; | 212 if (dynamic_cast<const Colour3DPlotLayer *>(layer)) return Colour3DPlot; |
204 if (dynamic_cast<const SpectrumLayer *>(layer)) return Spectrum; | 213 if (dynamic_cast<const SpectrumLayer *>(layer)) return Spectrum; |
205 if (dynamic_cast<const SliceLayer *>(layer)) return Slice; | 214 if (dynamic_cast<const SliceLayer *>(layer)) return Slice; |
214 case Spectrogram: return "spectrogram"; | 223 case Spectrogram: return "spectrogram"; |
215 case TimeRuler: return "timeruler"; | 224 case TimeRuler: return "timeruler"; |
216 case TimeInstants: return "instants"; | 225 case TimeInstants: return "instants"; |
217 case TimeValues: return "values"; | 226 case TimeValues: return "values"; |
218 case Notes: return "notes"; | 227 case Notes: return "notes"; |
228 case Regions: return "regions"; | |
219 case Text: return "text"; | 229 case Text: return "text"; |
220 case Image: return "image"; | 230 case Image: return "image"; |
221 case Colour3DPlot: return "colour3d"; | 231 case Colour3DPlot: return "colour3d"; |
222 case Spectrum: return "spectrum"; | 232 case Spectrum: return "spectrum"; |
223 case Slice: return "spectrum"; | 233 case Slice: return "spectrum"; |
235 case Spectrogram: return "spectrogram"; | 245 case Spectrogram: return "spectrogram"; |
236 case TimeRuler: return "timeruler"; | 246 case TimeRuler: return "timeruler"; |
237 case TimeInstants: return "timeinstants"; | 247 case TimeInstants: return "timeinstants"; |
238 case TimeValues: return "timevalues"; | 248 case TimeValues: return "timevalues"; |
239 case Notes: return "notes"; | 249 case Notes: return "notes"; |
250 case Regions: return "regions"; | |
240 case Text: return "text"; | 251 case Text: return "text"; |
241 case Image: return "image"; | 252 case Image: return "image"; |
242 case Colour3DPlot: return "colour3dplot"; | 253 case Colour3DPlot: return "colour3dplot"; |
243 case Spectrum: return "spectrum"; | 254 case Spectrum: return "spectrum"; |
244 case Slice: return "slice"; | 255 case Slice: return "slice"; |
255 if (name == "spectrogram") return Spectrogram; | 266 if (name == "spectrogram") return Spectrogram; |
256 if (name == "timeruler") return TimeRuler; | 267 if (name == "timeruler") return TimeRuler; |
257 if (name == "timeinstants") return TimeInstants; | 268 if (name == "timeinstants") return TimeInstants; |
258 if (name == "timevalues") return TimeValues; | 269 if (name == "timevalues") return TimeValues; |
259 if (name == "notes") return Notes; | 270 if (name == "notes") return Notes; |
271 if (name == "regions") return Regions; | |
260 if (name == "text") return Text; | 272 if (name == "text") return Text; |
261 if (name == "image") return Image; | 273 if (name == "image") return Image; |
262 if (name == "colour3dplot") return Colour3DPlot; | 274 if (name == "colour3dplot") return Colour3DPlot; |
263 if (name == "spectrum") return Spectrum; | 275 if (name == "spectrum") return Spectrum; |
264 if (name == "slice") return Slice; | 276 if (name == "slice") return Slice; |
290 return; | 302 return; |
291 | 303 |
292 if (trySetModel<NoteLayer, NoteModel>(layer, model)) | 304 if (trySetModel<NoteLayer, NoteModel>(layer, model)) |
293 return; | 305 return; |
294 | 306 |
307 if (trySetModel<RegionLayer, RegionModel>(layer, model)) | |
308 return; | |
309 | |
295 if (trySetModel<TextLayer, TextModel>(layer, model)) | 310 if (trySetModel<TextLayer, TextModel>(layer, model)) |
296 return; | 311 return; |
297 | 312 |
298 if (trySetModel<ImageLayer, ImageModel>(layer, model)) | 313 if (trySetModel<ImageLayer, ImageModel>(layer, model)) |
299 return; | 314 return; |
318 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1); | 333 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1); |
319 } else if (layerType == TimeValues) { | 334 } else if (layerType == TimeValues) { |
320 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true); | 335 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true); |
321 } else if (layerType == Notes) { | 336 } else if (layerType == Notes) { |
322 return new NoteModel(baseModel->getSampleRate(), 1, true); | 337 return new NoteModel(baseModel->getSampleRate(), 1, true); |
338 } else if (layerType == Regions) { | |
339 return new RegionModel(baseModel->getSampleRate(), 1, true); | |
323 } else if (layerType == Text) { | 340 } else if (layerType == Text) { |
324 return new TextModel(baseModel->getSampleRate(), 1, true); | 341 return new TextModel(baseModel->getSampleRate(), 1, true); |
325 } else if (layerType == Image) { | 342 } else if (layerType == Image) { |
326 return new ImageModel(baseModel->getSampleRate(), 1, true); | 343 return new ImageModel(baseModel->getSampleRate(), 1, true); |
327 } else { | 344 } else { |
385 layer = new TimeValueLayer; | 402 layer = new TimeValueLayer; |
386 break; | 403 break; |
387 | 404 |
388 case Notes: | 405 case Notes: |
389 layer = new NoteLayer; | 406 layer = new NoteLayer; |
407 break; | |
408 | |
409 case Regions: | |
410 layer = new RegionLayer; | |
390 break; | 411 break; |
391 | 412 |
392 case Text: | 413 case Text: |
393 layer = new TextLayer; | 414 layer = new TextLayer; |
394 break; | 415 break; |
490 const Clipboard::PointList &contents = clip.getPoints(); | 511 const Clipboard::PointList &contents = clip.getPoints(); |
491 | 512 |
492 bool haveFrame = false; | 513 bool haveFrame = false; |
493 bool haveValue = false; | 514 bool haveValue = false; |
494 bool haveDuration = false; | 515 bool haveDuration = false; |
516 bool haveLevel = false; | |
495 | 517 |
496 for (Clipboard::PointList::const_iterator i = contents.begin(); | 518 for (Clipboard::PointList::const_iterator i = contents.begin(); |
497 i != contents.end(); ++i) { | 519 i != contents.end(); ++i) { |
498 if (i->haveFrame()) haveFrame = true; | 520 if (i->haveFrame()) haveFrame = true; |
499 if (i->haveValue()) haveValue = true; | 521 if (i->haveValue()) haveValue = true; |
500 if (i->haveDuration()) haveDuration = true; | 522 if (i->haveDuration()) haveDuration = true; |
501 } | 523 if (i->haveLevel()) haveLevel = true; |
502 | 524 } |
503 if (haveFrame && haveValue && haveDuration) return Notes; | 525 |
526 if (haveFrame && haveValue && haveDuration && haveLevel) return Notes; | |
527 if (haveFrame && haveValue && haveDuration) return Regions; | |
504 if (haveFrame && haveValue) return TimeValues; | 528 if (haveFrame && haveValue) return TimeValues; |
505 return TimeInstants; | 529 return TimeInstants; |
506 } | 530 } |
507 | 531 |