Mercurial > hg > svgui
comparison layer/LayerFactory.cpp @ 1266:a34a2a25907c
Untabify
author | Chris Cannam |
---|---|
date | Thu, 01 Mar 2018 18:02:22 +0000 |
parents | b247d3ffcbb9 |
children | c8a6fd3f9dff |
comparison
equal
deleted
inserted
replaced
1265:6e724c81f18f | 1266:a34a2a25907c |
---|---|
82 case Colour3DPlot: return Layer::tr("Colour 3D Plot"); | 82 case Colour3DPlot: return Layer::tr("Colour 3D Plot"); |
83 case Spectrum: return Layer::tr("Spectrum"); | 83 case Spectrum: return Layer::tr("Spectrum"); |
84 case Slice: return Layer::tr("Time Slice"); | 84 case Slice: return Layer::tr("Time Slice"); |
85 | 85 |
86 case MelodicRangeSpectrogram: | 86 case MelodicRangeSpectrogram: |
87 // The user can change all the parameters of this after the | 87 // The user can change all the parameters of this after the |
88 // fact -- there's nothing permanently melodic-range about it | 88 // fact -- there's nothing permanently melodic-range about it |
89 // that should be encoded in its name | 89 // that should be encoded in its name |
90 return Layer::tr("Spectrogram"); | 90 return Layer::tr("Spectrogram"); |
91 | 91 |
92 case PeakFrequencySpectrogram: | 92 case PeakFrequencySpectrogram: |
93 // likewise | 93 // likewise |
94 return Layer::tr("Spectrogram"); | 94 return Layer::tr("Spectrogram"); |
95 | 95 |
96 case UnknownLayer: | 96 case UnknownLayer: |
97 default: | 97 default: |
98 cerr << "WARNING: LayerFactory::getLayerPresentationName passed unknown layer" << endl; | 98 cerr << "WARNING: LayerFactory::getLayerPresentationName passed unknown layer" << endl; |
99 return Layer::tr("Unknown Layer"); | 99 return Layer::tr("Unknown Layer"); |
137 LayerFactory::getValidLayerTypes(Model *model) | 137 LayerFactory::getValidLayerTypes(Model *model) |
138 { | 138 { |
139 LayerTypeSet types; | 139 LayerTypeSet types; |
140 | 140 |
141 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) { | 141 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) { |
142 types.insert(Colour3DPlot); | 142 types.insert(Colour3DPlot); |
143 types.insert(Slice); | 143 types.insert(Slice); |
144 } | 144 } |
145 | 145 |
146 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) { | 146 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) { |
147 types.insert(Waveform); | 147 types.insert(Waveform); |
148 } | 148 } |
149 | 149 |
150 if (dynamic_cast<DenseTimeValueModel *>(model)) { | 150 if (dynamic_cast<DenseTimeValueModel *>(model)) { |
151 types.insert(Spectrogram); | 151 types.insert(Spectrogram); |
152 types.insert(MelodicRangeSpectrogram); | 152 types.insert(MelodicRangeSpectrogram); |
153 types.insert(PeakFrequencySpectrogram); | 153 types.insert(PeakFrequencySpectrogram); |
154 } | 154 } |
155 | 155 |
156 if (dynamic_cast<SparseOneDimensionalModel *>(model)) { | 156 if (dynamic_cast<SparseOneDimensionalModel *>(model)) { |
157 types.insert(TimeInstants); | 157 types.insert(TimeInstants); |
158 } | 158 } |
159 | 159 |
160 if (dynamic_cast<SparseTimeValueModel *>(model)) { | 160 if (dynamic_cast<SparseTimeValueModel *>(model)) { |
161 types.insert(TimeValues); | 161 types.insert(TimeValues); |
162 } | 162 } |
163 | 163 |
164 if (dynamic_cast<NoteModel *>(model)) { | 164 if (dynamic_cast<NoteModel *>(model)) { |
165 types.insert(Notes); | 165 types.insert(Notes); |
166 } | 166 } |
167 | 167 |
168 // NOTE: GF: types is a set, so order of insertion does not matter | 168 // NOTE: GF: types is a set, so order of insertion does not matter |
169 if (dynamic_cast<FlexiNoteModel *>(model)) { | 169 if (dynamic_cast<FlexiNoteModel *>(model)) { |
170 types.insert(FlexiNotes); | 170 types.insert(FlexiNotes); |
171 } | 171 } |
172 | 172 |
173 if (dynamic_cast<RegionModel *>(model)) { | 173 if (dynamic_cast<RegionModel *>(model)) { |
174 types.insert(Regions); | 174 types.insert(Regions); |
175 } | 175 } |
176 | 176 |
177 if (dynamic_cast<TextModel *>(model)) { | 177 if (dynamic_cast<TextModel *>(model)) { |
178 types.insert(Text); | 178 types.insert(Text); |
179 } | 179 } |
180 | 180 |
181 if (dynamic_cast<ImageModel *>(model)) { | 181 if (dynamic_cast<ImageModel *>(model)) { |
182 types.insert(Image); | 182 types.insert(Image); |
183 } | 183 } |
184 | 184 |
185 if (dynamic_cast<DenseTimeValueModel *>(model)) { | 185 if (dynamic_cast<DenseTimeValueModel *>(model)) { |
186 types.insert(Spectrum); | 186 types.insert(Spectrum); |
187 } | 187 } |
302 | 302 |
303 void | 303 void |
304 LayerFactory::setModel(Layer *layer, Model *model) | 304 LayerFactory::setModel(Layer *layer, Model *model) |
305 { | 305 { |
306 // if (trySetModel<WaveformLayer, RangeSummarisableTimeValueModel>(layer, model)) | 306 // if (trySetModel<WaveformLayer, RangeSummarisableTimeValueModel>(layer, model)) |
307 // return; | 307 // return; |
308 | 308 |
309 if (trySetModel<WaveformLayer, WaveFileModel>(layer, model)) | 309 if (trySetModel<WaveformLayer, WaveFileModel>(layer, model)) |
310 return; | 310 return; |
311 | 311 |
312 if (trySetModel<WaveformLayer, WritableWaveFileModel>(layer, model)) | 312 if (trySetModel<WaveformLayer, WritableWaveFileModel>(layer, model)) |
313 return; | 313 return; |
314 | 314 |
315 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model)) | 315 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model)) |
316 return; | 316 return; |
317 | 317 |
318 if (trySetModel<TimeRulerLayer, Model>(layer, model)) | 318 if (trySetModel<TimeRulerLayer, Model>(layer, model)) |
319 return; | 319 return; |
320 | 320 |
321 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model)) | 321 if (trySetModel<TimeInstantLayer, SparseOneDimensionalModel>(layer, model)) |
322 return; | 322 return; |
323 | 323 |
324 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model)) | 324 if (trySetModel<TimeValueLayer, SparseTimeValueModel>(layer, model)) |
325 return; | 325 return; |
326 | 326 |
327 if (trySetModel<NoteLayer, NoteModel>(layer, model)) | 327 if (trySetModel<NoteLayer, NoteModel>(layer, model)) |
328 return; | 328 return; |
329 | 329 |
330 // GF: added FlexiNoteLayer | 330 // GF: added FlexiNoteLayer |
331 if (trySetModel<FlexiNoteLayer, FlexiNoteModel>(layer, model)) | 331 if (trySetModel<FlexiNoteLayer, FlexiNoteModel>(layer, model)) |
332 return; | 332 return; |
333 | 333 |
334 if (trySetModel<RegionLayer, RegionModel>(layer, model)) | 334 if (trySetModel<RegionLayer, RegionModel>(layer, model)) |
335 return; | 335 return; |
336 | 336 |
337 if (trySetModel<TextLayer, TextModel>(layer, model)) | 337 if (trySetModel<TextLayer, TextModel>(layer, model)) |
338 return; | 338 return; |
339 | 339 |
340 if (trySetModel<ImageLayer, ImageModel>(layer, model)) | 340 if (trySetModel<ImageLayer, ImageModel>(layer, model)) |
341 return; | 341 return; |
342 | 342 |
343 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model)) | 343 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model)) |
344 return; | 344 return; |
345 | 345 |
346 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model)) | 346 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model)) |
347 return; | 347 return; |
348 | 348 |
349 if (trySetModel<SpectrumLayer, DenseTimeValueModel>(layer, model)) | 349 if (trySetModel<SpectrumLayer, DenseTimeValueModel>(layer, model)) |
350 return; | 350 return; |
351 | 351 |
352 // if (trySetModel<SliceLayer, DenseThreeDimensionalModel>(layer, model)) | 352 // if (trySetModel<SliceLayer, DenseThreeDimensionalModel>(layer, model)) |
355 | 355 |
356 Model * | 356 Model * |
357 LayerFactory::createEmptyModel(LayerType layerType, Model *baseModel) | 357 LayerFactory::createEmptyModel(LayerType layerType, Model *baseModel) |
358 { | 358 { |
359 if (layerType == TimeInstants) { | 359 if (layerType == TimeInstants) { |
360 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1); | 360 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1); |
361 } else if (layerType == TimeValues) { | 361 } else if (layerType == TimeValues) { |
362 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true); | 362 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true); |
363 } else if (layerType == FlexiNotes) { | 363 } else if (layerType == FlexiNotes) { |
364 return new FlexiNoteModel(baseModel->getSampleRate(), 1, true); | 364 return new FlexiNoteModel(baseModel->getSampleRate(), 1, true); |
365 } else if (layerType == Notes) { | 365 } else if (layerType == Notes) { |
366 return new NoteModel(baseModel->getSampleRate(), 1, true); | 366 return new NoteModel(baseModel->getSampleRate(), 1, true); |
367 } else if (layerType == Regions) { | 367 } else if (layerType == Regions) { |
368 return new RegionModel(baseModel->getSampleRate(), 1, true); | 368 return new RegionModel(baseModel->getSampleRate(), 1, true); |
369 } else if (layerType == Text) { | 369 } else if (layerType == Text) { |
370 return new TextModel(baseModel->getSampleRate(), 1, true); | 370 return new TextModel(baseModel->getSampleRate(), 1, true); |
371 } else if (layerType == Image) { | 371 } else if (layerType == Image) { |
372 return new ImageModel(baseModel->getSampleRate(), 1, true); | 372 return new ImageModel(baseModel->getSampleRate(), 1, true); |
373 } else { | 373 } else { |
374 return 0; | 374 return 0; |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 int | 378 int |
379 LayerFactory::getChannel(Layer *layer) | 379 LayerFactory::getChannel(Layer *layer) |
380 { | 380 { |
381 if (dynamic_cast<WaveformLayer *>(layer)) { | 381 if (dynamic_cast<WaveformLayer *>(layer)) { |
382 return dynamic_cast<WaveformLayer *>(layer)->getChannel(); | 382 return dynamic_cast<WaveformLayer *>(layer)->getChannel(); |
383 } | 383 } |
384 if (dynamic_cast<SpectrogramLayer *>(layer)) { | 384 if (dynamic_cast<SpectrogramLayer *>(layer)) { |
385 return dynamic_cast<SpectrogramLayer *>(layer)->getChannel(); | 385 return dynamic_cast<SpectrogramLayer *>(layer)->getChannel(); |
386 } | 386 } |
387 return -1; | 387 return -1; |
388 } | 388 } |
389 | 389 |
390 void | 390 void |
391 LayerFactory::setChannel(Layer *layer, int channel) | 391 LayerFactory::setChannel(Layer *layer, int channel) |
392 { | 392 { |
393 if (dynamic_cast<WaveformLayer *>(layer)) { | 393 if (dynamic_cast<WaveformLayer *>(layer)) { |
394 dynamic_cast<WaveformLayer *>(layer)->setChannel(channel); | 394 dynamic_cast<WaveformLayer *>(layer)->setChannel(channel); |
395 return; | 395 return; |
396 } | 396 } |
397 if (dynamic_cast<SpectrogramLayer *>(layer)) { | 397 if (dynamic_cast<SpectrogramLayer *>(layer)) { |
398 dynamic_cast<SpectrogramLayer *>(layer)->setChannel(channel); | 398 dynamic_cast<SpectrogramLayer *>(layer)->setChannel(channel); |
399 return; | 399 return; |
400 } | 400 } |
401 if (dynamic_cast<SpectrumLayer *>(layer)) { | 401 if (dynamic_cast<SpectrumLayer *>(layer)) { |
402 dynamic_cast<SpectrumLayer *>(layer)->setChannel(channel); | 402 dynamic_cast<SpectrumLayer *>(layer)->setChannel(channel); |
403 return; | 403 return; |
404 } | 404 } |
405 } | 405 } |
406 | 406 |
407 Layer * | 407 Layer * |
408 LayerFactory::createLayer(LayerType type) | 408 LayerFactory::createLayer(LayerType type) |
410 Layer *layer = 0; | 410 Layer *layer = 0; |
411 | 411 |
412 switch (type) { | 412 switch (type) { |
413 | 413 |
414 case Waveform: | 414 case Waveform: |
415 layer = new WaveformLayer; | 415 layer = new WaveformLayer; |
416 break; | 416 break; |
417 | 417 |
418 case Spectrogram: | 418 case Spectrogram: |
419 layer = new SpectrogramLayer; | 419 layer = new SpectrogramLayer; |
420 break; | 420 break; |
421 | 421 |
422 case TimeRuler: | 422 case TimeRuler: |
423 layer = new TimeRulerLayer; | 423 layer = new TimeRulerLayer; |
424 break; | 424 break; |
425 | 425 |
426 case TimeInstants: | 426 case TimeInstants: |
427 layer = new TimeInstantLayer; | 427 layer = new TimeInstantLayer; |
428 break; | 428 break; |
429 | 429 |
430 case TimeValues: | 430 case TimeValues: |
431 layer = new TimeValueLayer; | 431 layer = new TimeValueLayer; |
432 break; | 432 break; |
433 | 433 |
434 case FlexiNotes: | 434 case FlexiNotes: |
435 layer = new FlexiNoteLayer; | 435 layer = new FlexiNoteLayer; |
436 break; | 436 break; |
437 | 437 |
438 case Notes: | 438 case Notes: |
439 layer = new NoteLayer; | 439 layer = new NoteLayer; |
440 break; | 440 break; |
441 | 441 |
442 case Regions: | 442 case Regions: |
443 layer = new RegionLayer; | 443 layer = new RegionLayer; |
444 break; | 444 break; |
445 | 445 |
446 case Text: | 446 case Text: |
447 layer = new TextLayer; | 447 layer = new TextLayer; |
448 break; | 448 break; |
449 | 449 |
450 case Image: | 450 case Image: |
451 layer = new ImageLayer; | 451 layer = new ImageLayer; |
452 break; | 452 break; |
453 | 453 |
454 case Colour3DPlot: | 454 case Colour3DPlot: |
455 layer = new Colour3DPlotLayer; | 455 layer = new Colour3DPlotLayer; |
456 break; | 456 break; |
457 | 457 |
458 case Spectrum: | 458 case Spectrum: |
459 layer = new SpectrumLayer; | 459 layer = new SpectrumLayer; |
460 break; | 460 break; |
461 | 461 |
462 case Slice: | 462 case Slice: |
463 layer = new SliceLayer; | 463 layer = new SliceLayer; |
464 break; | 464 break; |
465 | 465 |
466 case MelodicRangeSpectrogram: | 466 case MelodicRangeSpectrogram: |
467 layer = new SpectrogramLayer(SpectrogramLayer::MelodicRange); | 467 layer = new SpectrogramLayer(SpectrogramLayer::MelodicRange); |
468 break; | 468 break; |
469 | 469 |
470 case PeakFrequencySpectrogram: | 470 case PeakFrequencySpectrogram: |
471 layer = new SpectrogramLayer(SpectrogramLayer::MelodicPeaks); | 471 layer = new SpectrogramLayer(SpectrogramLayer::MelodicPeaks); |
472 break; | 472 break; |
473 | 473 |
474 case UnknownLayer: | 474 case UnknownLayer: |
475 default: | 475 default: |
476 cerr << "WARNING: LayerFactory::createLayer passed unknown layer" << endl; | 476 cerr << "WARNING: LayerFactory::createLayer passed unknown layer" << endl; |
477 break; | 477 break; |
478 } | 478 } |
479 | 479 |
480 if (!layer) { | 480 if (!layer) { |
481 cerr << "LayerFactory::createLayer: Unknown layer type " | 481 cerr << "LayerFactory::createLayer: Unknown layer type " |
482 << type << endl; | 482 << type << endl; |
483 } else { | 483 } else { |
484 // SVDEBUG << "LayerFactory::createLayer: Setting object name " | 484 // SVDEBUG << "LayerFactory::createLayer: Setting object name " |
485 // << getLayerPresentationName(type) << " on " << layer << endl; | 485 // << getLayerPresentationName(type) << " on " << layer << endl; |
486 layer->setObjectName(getLayerPresentationName(type)); | 486 layer->setObjectName(getLayerPresentationName(type)); |
487 setLayerDefaultProperties(type, layer); | 487 setLayerDefaultProperties(type, layer); |
488 } | 488 } |
489 | 489 |
490 return layer; | 490 return layer; |
491 } | 491 } |