comparison layer/LayerFactory.cpp @ 1486:ac0a8addabcf

Merge from branch by-id
author Chris Cannam
date Wed, 17 Jul 2019 14:25:16 +0100
parents f2525e6cbdf1
children 0fa155b84bac
comparison
equal deleted inserted replaced
1468:de41a11cabc2 1486:ac0a8addabcf
131 } 131 }
132 return false; 132 return false;
133 } 133 }
134 134
135 LayerFactory::LayerTypeSet 135 LayerFactory::LayerTypeSet
136 LayerFactory::getValidLayerTypes(Model *model) 136 LayerFactory::getValidLayerTypes(ModelId modelId)
137 { 137 {
138 LayerTypeSet types; 138 LayerTypeSet types;
139 139
140 if (dynamic_cast<DenseThreeDimensionalModel *>(model)) { 140 if (ModelById::getAs<DenseThreeDimensionalModel>(modelId)) {
141 types.insert(Colour3DPlot); 141 types.insert(Colour3DPlot);
142 types.insert(Slice); 142 types.insert(Slice);
143 } 143 }
144 144
145 if (dynamic_cast<RangeSummarisableTimeValueModel *>(model)) { 145 if (ModelById::getAs<RangeSummarisableTimeValueModel>(modelId)) {
146 types.insert(Waveform); 146 types.insert(Waveform);
147 } 147 }
148 148
149 if (dynamic_cast<DenseTimeValueModel *>(model)) { 149 if (ModelById::getAs<DenseTimeValueModel>(modelId)) {
150 types.insert(Spectrogram); 150 types.insert(Spectrogram);
151 types.insert(MelodicRangeSpectrogram); 151 types.insert(MelodicRangeSpectrogram);
152 types.insert(PeakFrequencySpectrogram); 152 types.insert(PeakFrequencySpectrogram);
153 } 153 }
154 154
155 if (dynamic_cast<SparseOneDimensionalModel *>(model)) { 155 if (ModelById::getAs<SparseOneDimensionalModel>(modelId)) {
156 types.insert(TimeInstants); 156 types.insert(TimeInstants);
157 } 157 }
158 158
159 if (dynamic_cast<SparseTimeValueModel *>(model)) { 159 if (ModelById::getAs<SparseTimeValueModel>(modelId)) {
160 types.insert(TimeValues); 160 types.insert(TimeValues);
161 } 161 }
162 162
163 if (dynamic_cast<NoteModel *>(model)) { 163 if (ModelById::getAs<NoteModel>(modelId)) {
164 NoteModel *nm = dynamic_cast<NoteModel *>(model); 164 auto nm = ModelById::getAs<NoteModel>(modelId);
165 if (nm->getSubtype() == NoteModel::FLEXI_NOTE) { 165 if (nm && nm->getSubtype() == NoteModel::FLEXI_NOTE) {
166 types.insert(FlexiNotes); 166 types.insert(FlexiNotes);
167 } else { 167 } else {
168 types.insert(Notes); 168 types.insert(Notes);
169 } 169 }
170 } 170 }
171 171
172 if (dynamic_cast<RegionModel *>(model)) { 172 if (ModelById::getAs<RegionModel>(modelId)) {
173 types.insert(Regions); 173 types.insert(Regions);
174 } 174 }
175 175
176 if (dynamic_cast<TextModel *>(model)) { 176 if (ModelById::getAs<TextModel>(modelId)) {
177 types.insert(Text); 177 types.insert(Text);
178 } 178 }
179 179
180 if (dynamic_cast<ImageModel *>(model)) { 180 if (ModelById::getAs<ImageModel>(modelId)) {
181 types.insert(Image); 181 types.insert(Image);
182 } 182 }
183 183
184 if (dynamic_cast<DenseTimeValueModel *>(model)) { 184 if (ModelById::getAs<DenseTimeValueModel>(modelId)) {
185 types.insert(Spectrum); 185 types.insert(Spectrum);
186 } 186 }
187 187
188 // We don't count TimeRuler here as it doesn't actually display 188 // We don't count TimeRuler here as it doesn't actually display
189 // the data, although it can be backed by any model 189 // the data, although it can be backed by any model
298 if (name == "slice") return Slice; 298 if (name == "slice") return Slice;
299 return UnknownLayer; 299 return UnknownLayer;
300 } 300 }
301 301
302 void 302 void
303 LayerFactory::setModel(Layer *layer, Model *model) 303 LayerFactory::setModel(Layer *layer, ModelId model)
304 { 304 {
305 // if (trySetModel<WaveformLayer, RangeSummarisableTimeValueModel>(layer, model))
306 // return;
307
308 if (trySetModel<WaveformLayer, WaveFileModel>(layer, model)) 305 if (trySetModel<WaveformLayer, WaveFileModel>(layer, model))
309 return; 306 return;
310 307
311 if (trySetModel<WaveformLayer, WritableWaveFileModel>(layer, model)) 308 if (trySetModel<WaveformLayer, WritableWaveFileModel>(layer, model))
312 return; 309 return;
339 return; 336 return;
340 337
341 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model)) 338 if (trySetModel<Colour3DPlotLayer, DenseThreeDimensionalModel>(layer, model))
342 return; 339 return;
343 340
344 if (trySetModel<SpectrogramLayer, DenseTimeValueModel>(layer, model))
345 return;
346
347 if (trySetModel<SpectrumLayer, DenseTimeValueModel>(layer, model)) 341 if (trySetModel<SpectrumLayer, DenseTimeValueModel>(layer, model))
348 return; 342 return;
349 343 }
350 // if (trySetModel<SliceLayer, DenseThreeDimensionalModel>(layer, model)) 344
351 // return; 345 std::shared_ptr<Model>
352 } 346 LayerFactory::createEmptyModel(LayerType layerType, ModelId baseModelId)
353 347 {
354 Model * 348 auto baseModel = ModelById::get(baseModelId);
355 LayerFactory::createEmptyModel(LayerType layerType, Model *baseModel) 349 if (!baseModel) return {};
356 { 350
351 sv_samplerate_t rate = baseModel->getSampleRate();
352
357 if (layerType == TimeInstants) { 353 if (layerType == TimeInstants) {
358 return new SparseOneDimensionalModel(baseModel->getSampleRate(), 1); 354 return std::make_shared<SparseOneDimensionalModel>(rate, 1);
359 } else if (layerType == TimeValues) { 355 } else if (layerType == TimeValues) {
360 return new SparseTimeValueModel(baseModel->getSampleRate(), 1, true); 356 return std::make_shared<SparseTimeValueModel>(rate, 1, true);
361 } else if (layerType == FlexiNotes) { 357 } else if (layerType == FlexiNotes) {
362 return new NoteModel(baseModel->getSampleRate(), 1, true); 358 return std::make_shared<NoteModel>(rate, 1, true);
363 } else if (layerType == Notes) { 359 } else if (layerType == Notes) {
364 return new NoteModel(baseModel->getSampleRate(), 1, true); 360 return std::make_shared<NoteModel>(rate, 1, true);
365 } else if (layerType == Regions) { 361 } else if (layerType == Regions) {
366 return new RegionModel(baseModel->getSampleRate(), 1, true); 362 return std::make_shared<RegionModel>(rate, 1, true);
367 } else if (layerType == Text) { 363 } else if (layerType == Text) {
368 return new TextModel(baseModel->getSampleRate(), 1, true); 364 return std::make_shared<TextModel>(rate, 1, true);
369 } else if (layerType == Image) { 365 } else if (layerType == Image) {
370 return new ImageModel(baseModel->getSampleRate(), 1, true); 366 return std::make_shared<ImageModel>(rate, 1, true);
371 } else { 367 } else {
372 return nullptr; 368 return {};
373 } 369 }
374 } 370 }
375 371
376 int 372 int
377 LayerFactory::getChannel(Layer *layer) 373 LayerFactory::getChannel(Layer *layer)