Mercurial > hg > svapp
comparison framework/Document.h @ 683:0736beb8b852 by-id
Toward updating Document for ModelById
author | Chris Cannam |
---|---|
date | Wed, 03 Jul 2019 13:01:26 +0100 |
parents | 1f18e0f64af8 |
children | e0b0f3e163ca |
comparison
equal
deleted
inserted
replaced
682:161063152ddd | 683:0736beb8b852 |
---|---|
93 | 93 |
94 /** | 94 /** |
95 * Create and return a new layer associated with the given model, | 95 * Create and return a new layer associated with the given model, |
96 * and register the model as an imported model. | 96 * and register the model as an imported model. |
97 */ | 97 */ |
98 Layer *createImportedLayer(Model *); | 98 Layer *createImportedLayer(ModelId); |
99 | 99 |
100 /** | 100 /** |
101 * Create and return a new layer of the given type, with an | 101 * Create and return a new layer of the given type, with an |
102 * appropriate empty model. If the given type is not one for | 102 * appropriate empty model. If the given type is not one for |
103 * which an empty model can meaningfully be created, return 0. | 103 * which an empty model can meaningfully be created, return 0. |
181 void deleteLayer(Layer *, bool force = false); | 181 void deleteLayer(Layer *, bool force = false); |
182 | 182 |
183 /** | 183 /** |
184 * Set the main model (the source for playback sample rate, etc) | 184 * Set the main model (the source for playback sample rate, etc) |
185 * to the given wave file model. This will regenerate any derived | 185 * to the given wave file model. This will regenerate any derived |
186 * models that were based on the previous main model. | 186 * models that were based on the previous main model. The model |
187 */ | 187 * must have been added to ModelById already, and Document will |
188 void setMainModel(WaveFileModel *); | 188 * take responsibility for releasing it later. |
189 */ | |
190 void setMainModel(ModelId); // a WaveFileModel | |
189 | 191 |
190 /** | 192 /** |
191 * Get the main model (the source for playback sample rate, etc). | 193 * Get the main model (the source for playback sample rate, etc). |
192 */ | 194 */ |
193 WaveFileModel *getMainModel() { return m_mainModel; } | 195 ModelId getMainModel() { return m_mainModel; } |
194 | |
195 /** | |
196 * Get the main model (the source for playback sample rate, etc). | |
197 */ | |
198 const WaveFileModel *getMainModel() const { return m_mainModel; } | |
199 | 196 |
200 std::vector<Model *> getTransformInputModels(); | 197 std::vector<ModelId> getTransformInputModels(); |
201 | 198 |
202 bool isKnownModel(const Model *) const; | 199 //??? investigate & document |
200 bool isKnownModel(ModelId) const; | |
203 | 201 |
204 /** | 202 /** |
205 * Add a derived model associated with the given transform, | 203 * Add a derived model associated with the given transform, |
206 * running the transform and returning the resulting model. | 204 * running the transform and returning the resulting model. |
207 */ | 205 * The model is added to ModelById before returning. |
208 Model *addDerivedModel(const Transform &transform, | 206 */ |
209 const ModelTransformer::Input &input, | 207 ModelId addDerivedModel(const Transform &transform, |
210 QString &returnedMessage); | 208 const ModelTransformer::Input &input, |
209 QString &returnedMessage); | |
211 | 210 |
212 /** | 211 /** |
213 * Add derived models associated with the given set of related | 212 * Add derived models associated with the given set of related |
214 * transforms, running the transforms and returning the resulting | 213 * transforms, running the transforms and returning the resulting |
215 * models. | 214 * models. The models are added to ModelById before returning. |
216 */ | 215 */ |
217 friend class AdditionalModelConverter; | 216 friend class AdditionalModelConverter; |
218 std::vector<Model *> addDerivedModels(const Transforms &transforms, | 217 std::vector<ModelId> addDerivedModels(const Transforms &transforms, |
219 const ModelTransformer::Input &input, | 218 const ModelTransformer::Input &input, |
220 QString &returnedMessage, | 219 QString &returnedMessage, |
221 AdditionalModelConverter *); | 220 AdditionalModelConverter *); |
222 | 221 |
223 /** | 222 /** |
224 * Add a derived model associated with the given transform. This | 223 * Add a derived model associated with the given transform. This |
225 * is necessary to register any derived model that was not created | 224 * is necessary to register any derived model that was not created |
226 * by the document using createDerivedModel or createDerivedLayer. | 225 * by the document using createDerivedModel or |
226 * createDerivedLayer. The model must have been added to ModelById | |
227 * already, and Document will take responsibility for releasing it | |
228 * later. | |
227 */ | 229 */ |
228 void addAlreadyDerivedModel(const Transform &transform, | 230 void addAlreadyDerivedModel(const Transform &transform, |
229 const ModelTransformer::Input &input, | 231 const ModelTransformer::Input &input, |
230 Model *outputModelToAdd); | 232 ModelId outputModelToAdd); |
231 | 233 |
232 /** | 234 /** |
233 * Add an imported (non-derived, non-main) model. This is | 235 * Add an imported (non-derived, non-main) model. This is |
234 * necessary to register any imported model that is associated | 236 * necessary to register any imported model that is associated |
235 * with a layer. | 237 * with a layer. The model must have been added to ModelById |
236 */ | 238 * already, and Document will take responsibility for releasing it |
237 void addImportedModel(Model *); | 239 * later. |
240 */ | |
241 void addImportedModel(ModelId); | |
238 | 242 |
239 /** | 243 /** |
244 *!!! todo: do we still need this to be separate? | |
245 * | |
240 * Add an aggregate model (one which represents a set of component | 246 * Add an aggregate model (one which represents a set of component |
241 * wave models as one model per channel in a single wave | 247 * wave models as one model per channel in a single wave |
242 * model). Aggregate models are unusual in that they are created | 248 * model). Aggregate models are unusual in that they are created |
243 * for a single transform each and have no refcount. (This | 249 * for a single transform each and have no refcount. (This |
244 * probably isn't ideal!) They are recorded separately from other | 250 * probably isn't ideal!) They are recorded separately from other |
245 * models, and will be deleted if any of their component models | 251 * models, and will be deleted if any of their component models |
246 * are removed. | 252 * are removed. |
247 */ | 253 * |
248 void addAggregateModel(AggregateWaveModel *); | 254 * The model must have been added to ModelById already, and |
255 * Document will take responsibility for releasing it later. | |
256 */ | |
257 void addAggregateModel(ModelId); // an AggregateWaveModel | |
249 | 258 |
250 /** | 259 /** |
251 * Associate the given model with the given layer. The model must | 260 * Associate the given model with the given layer. The model must |
252 * have already been registered using one of the addXXModel | 261 * have already been registered using one of the addXXModel |
253 * methods above. | 262 * methods above. |
254 */ | 263 */ |
255 void setModel(Layer *, Model *); | 264 void setModel(Layer *, ModelId); |
256 | 265 |
257 /** | 266 /** |
258 * Set the given layer to use the given channel of its model (-1 | 267 * Set the given layer to use the given channel of its model (-1 |
259 * means all available channels). | 268 * means all available channels). |
260 */ | 269 */ |
318 | 327 |
319 // Emitted when a layer is first added to a view, or when it is | 328 // Emitted when a layer is first added to a view, or when it is |
320 // last removed from a view | 329 // last removed from a view |
321 void layerInAView(Layer *, bool); | 330 void layerInAView(Layer *, bool); |
322 | 331 |
323 void modelAdded(Model *); | 332 void modelAdded(ModelId); |
324 void mainModelChanged(WaveFileModel *); // emitted after modelAdded | 333 void mainModelChanged(ModelId); // a WaveFileModel; emitted after modelAdded |
325 void modelAboutToBeDeleted(Model *); | |
326 | 334 |
327 void modelGenerationFailed(QString transformName, QString message); | 335 void modelGenerationFailed(QString transformName, QString message); |
328 void modelGenerationWarning(QString transformName, QString message); | 336 void modelGenerationWarning(QString transformName, QString message); |
329 void modelRegenerationFailed(QString layerName, QString transformName, | 337 void modelRegenerationFailed(QString layerName, QString transformName, |
330 QString message); | 338 QString message); |
331 void modelRegenerationWarning(QString layerName, QString transformName, | 339 void modelRegenerationWarning(QString layerName, QString transformName, |
332 QString message); | 340 QString message); |
333 | 341 |
334 void alignmentComplete(AlignmentModel *); | 342 void alignmentComplete(ModelId); // an AlignmentModel |
335 void alignmentFailed(QString message); | 343 void alignmentFailed(QString message); |
336 | 344 |
337 void activity(QString); | 345 void activity(QString); |
338 | 346 |
339 protected slots: | 347 protected slots: |
340 void aggregateModelInvalidated(); | 348 //!!! void aggregateModelInvalidated(); |
341 void performDeferredAlignment(); | 349 void performDeferredAlignment(); |
342 | 350 |
343 protected: | 351 protected: |
344 void releaseModel(Model *model); | 352 void releaseModel(ModelId model); |
345 | 353 |
346 /** | 354 /** |
347 * If model is suitable for alignment, align it against the main | 355 * If model is suitable for alignment, align it against the main |
348 * model and store the alignment in the model. If the model has an | 356 * model and store the alignment in the model. If the model has an |
349 * alignment already for the current main model, leave it | 357 * alignment already for the current main model, leave it |
350 * unchanged unless forceRecalculate is true. | 358 * unchanged unless forceRecalculate is true. |
351 */ | 359 */ |
352 void alignModel(Model *, bool forceRecalculate = false); | 360 void alignModel(ModelId, bool forceRecalculate = false); |
353 | 361 |
354 /* | 362 /* |
355 * Every model that is in use by a layer in the document must be | 363 * Every model that is in use by a layer in the document must be |
356 * found in either m_mainModel or m_models. We own and control | 364 * found in either m_mainModel or m_models. We own and control |
357 * the lifespan of all of these models. | 365 * the lifespan of all of these models. |
360 /** | 368 /** |
361 * The model that provides the underlying sample rate, etc. This | 369 * The model that provides the underlying sample rate, etc. This |
362 * model is not reference counted for layers, and is not freed | 370 * model is not reference counted for layers, and is not freed |
363 * unless it is replaced or the document is deleted. | 371 * unless it is replaced or the document is deleted. |
364 */ | 372 */ |
365 WaveFileModel *m_mainModel; | 373 ModelId m_mainModel; // a WaveFileModel |
366 | 374 |
367 struct ModelRecord | 375 struct ModelRecord |
368 { | 376 { |
369 // Information associated with a non-main model. If this | 377 // Information associated with a non-main model. If this |
370 // model is derived from another, then source will be non-NULL | 378 // model is derived from another, then source will be |
371 // and the transform name will be set appropriately. If the | 379 // something other than None and the transform name will be |
372 // transform name is set but source is NULL, then there was a | 380 // set appropriately. If the transform is set but source is |
373 // transform involved but the (target) model has been modified | 381 // None, then there was a transform involved but the (target) |
374 // since being generated from it. | 382 // model has been modified since being generated from it. |
375 | 383 |
376 // This does not use ModelTransformer::Input, because it would | 384 // This does not use ModelTransformer::Input, because it would |
377 // be confusing to have Input objects hanging around with NULL | 385 // be confusing to have Input objects hanging around with None |
378 // models in them. | 386 // models in them. |
379 | 387 |
380 Model *model; | 388 ModelId source; // may be None |
381 const Model *source; | |
382 int channel; | 389 int channel; |
383 Transform transform; | 390 Transform transform; |
384 bool additional; | 391 bool additional; |
385 | |
386 // Count of the number of layers using this model. | |
387 int refcount; | |
388 }; | 392 }; |
389 | 393 |
390 // This used to be a map<Model *, ModelRecord>, but a vector | 394 // These must be stored in increasing order of id (as in the |
391 // ensures that models are consistently recorded in order of | 395 // ordered std::map), to ensure repeatability for automated tests |
392 // creation rather than at the whim of heap allocation, and that's | 396 std::map<ModelId, ModelRecord> m_models; |
393 // useful for automated testing. We don't expect ever to have so | 397 std::set<ModelId> m_aggregateModels; |
394 // many models that there is any significant overhead there. | |
395 typedef std::vector<ModelRecord> ModelList; | |
396 ModelList m_models; | |
397 | |
398 ModelList::iterator findModelInList(Model *m) { | |
399 for (ModelList::iterator i = m_models.begin(); | |
400 i != m_models.end(); ++i) { | |
401 if (i->model == m) { | |
402 return i; | |
403 } | |
404 } | |
405 return m_models.end(); | |
406 } | |
407 | 398 |
408 void deleteModelFromList(Model *m) { | |
409 ModelList keep; | |
410 bool found = false; | |
411 for (const ModelRecord &rec: m_models) { | |
412 if (rec.model == m) { | |
413 found = true; | |
414 m->aboutToDelete(); | |
415 emit modelAboutToBeDeleted(m); | |
416 } else { | |
417 keep.push_back(rec); | |
418 } | |
419 } | |
420 m_models = keep; | |
421 if (found) { | |
422 delete m; | |
423 } | |
424 } | |
425 | |
426 /** | 399 /** |
427 * Add an extra derived model (returned at the end of processing a | 400 * Add an extra derived model (returned at the end of processing a |
428 * transform). | 401 * transform). |
429 */ | 402 */ |
430 void addAdditionalModel(Model *); | 403 void addAdditionalModel(ModelId); |
431 | 404 |
432 std::set<Model *> m_aggregateModels; | |
433 | |
434 class AddLayerCommand : public Command | 405 class AddLayerCommand : public Command |
435 { | 406 { |
436 public: | 407 public: |
437 AddLayerCommand(Document *d, View *view, Layer *layer); | 408 AddLayerCommand(Document *d, View *view, Layer *layer); |
438 virtual ~AddLayerCommand(); | 409 virtual ~AddLayerCommand(); |
473 | 444 |
474 void addToLayerViewMap(Layer *, View *); | 445 void addToLayerViewMap(Layer *, View *); |
475 void removeFromLayerViewMap(Layer *, View *); | 446 void removeFromLayerViewMap(Layer *, View *); |
476 | 447 |
477 QString getUniqueLayerName(QString candidate); | 448 QString getUniqueLayerName(QString candidate); |
478 void writeBackwardCompatibleDerivation(QTextStream &, QString, Model *, | 449 void writeBackwardCompatibleDerivation(QTextStream &, QString, ModelId, |
479 const ModelRecord &) const; | 450 const ModelRecord &) const; |
480 | 451 |
481 void toXml(QTextStream &, QString, QString, bool asTemplate) const; | 452 void toXml(QTextStream &, QString, QString, bool asTemplate) const; |
482 void writePlaceholderMainModel(QTextStream &, QString) const; | 453 void writePlaceholderMainModel(QTextStream &, QString) const; |
483 | 454 |
484 std::vector<Layer *> createLayersForDerivedModels(std::vector<Model *>, | 455 std::vector<Layer *> createLayersForDerivedModels(std::vector<ModelId>, |
485 QStringList names); | 456 QStringList names); |
486 | 457 |
487 /** | 458 /** |
488 * And these are the layers. We also control the lifespans of | 459 * And these are the layers. We also control the lifespans of |
489 * these (usually through the commands used to add and remove them). | 460 * these (usually through the commands used to add and remove them). |