comparison framework/Document.h @ 329:f72d58d1ccb0 tonioni

Adapt additional models created during a transform so they can be returned through a callback in an async method
author Chris Cannam
date Wed, 29 Jan 2014 17:32:47 +0000
parents 1e61f0c26593
children 0c37405cf579
comparison
equal deleted inserted replaced
327:d2c13ec0f148 329:f72d58d1ccb0
27 27
28 class Model; 28 class Model;
29 class Layer; 29 class Layer;
30 class View; 30 class View;
31 class WaveFileModel; 31 class WaveFileModel;
32
33 class AdditionalModelConverter;
32 34
33 /** 35 /**
34 * A Sonic Visualiser document consists of a set of data models, and 36 * A Sonic Visualiser document consists of a set of data models, and
35 * also the visualisation layers used to display them. Changes to the 37 * also the visualisation layers used to display them. Changes to the
36 * layers and their layout need to be stored and managed in much the 38 * layers and their layout need to be stored and managed in much the
119 121
120 /** 122 /**
121 * Create and return suitable layers for the given transforms, 123 * Create and return suitable layers for the given transforms,
122 * which must be identical apart from the output (i.e. must use 124 * which must be identical apart from the output (i.e. must use
123 * the same plugin and configuration). The layers are returned in 125 * the same plugin and configuration). The layers are returned in
124 * the same order as the transformed are supplied. 126 * the same order as the transforms are supplied.
125 */ 127 */
126 std::vector<Layer *> createDerivedLayers(const Transforms &, 128 std::vector<Layer *> createDerivedLayers(const Transforms &,
127 const ModelTransformer::Input &); 129 const ModelTransformer::Input &);
130
131 class LayerCreationHandler {
132 public:
133 virtual ~LayerCreationHandler() { }
134
135 /**
136 * The primary layers are those corresponding 1-1 to the input
137 * models, listed in the same order as the input models. The
138 * additional layers vector contains any layers (from all
139 * models) that were returned separately at the end of
140 * processing.
141 */
142 virtual void layersCreated(std::vector<Layer *> primary,
143 std::vector<Layer *> additional) = 0;
144 };
145
146 /**
147 * Create suitable layers for the given transforms, which must be
148 * identical apart from the output (i.e. must use the same plugin
149 * and configuration). This method returns after initialising the
150 * transformer process, and the layers are returned through a
151 * subsequent call to the provided handler (which must be non-null).
152 */
153 void createDerivedLayersAsync(const Transforms &,
154 const ModelTransformer::Input &,
155 LayerCreationHandler *handler);
128 156
129 /** 157 /**
130 * Delete the given layer, and also its associated model if no 158 * Delete the given layer, and also its associated model if no
131 * longer used by any other layer. In general, this should be the 159 * longer used by any other layer. In general, this should be the
132 * only method used to delete layers -- doing so directly is a bit 160 * only method used to delete layers -- doing so directly is a bit
166 /** 194 /**
167 * Add derived models associated with the given set of related 195 * Add derived models associated with the given set of related
168 * transforms, running the transforms and returning the resulting 196 * transforms, running the transforms and returning the resulting
169 * models. 197 * models.
170 */ 198 */
199 friend class AdditionalModelConverter;
171 std::vector<Model *> addDerivedModels(const Transforms &transforms, 200 std::vector<Model *> addDerivedModels(const Transforms &transforms,
172 const ModelTransformer::Input &input, 201 const ModelTransformer::Input &input,
173 QString &returnedMessage); 202 QString &returnedMessage,
203 AdditionalModelConverter *);
174 204
175 /** 205 /**
176 * Add a derived model associated with the given transform. This 206 * Add a derived model associated with the given transform. This
177 * is necessary to register any derived model that was not created 207 * is necessary to register any derived model that was not created
178 * by the document using createDerivedModel or createDerivedLayer. 208 * by the document using createDerivedModel or createDerivedLayer.
179 */ 209 */
180 void addDerivedModel(const Transform &transform, 210 void addAlreadyDerivedModel(const Transform &transform,
181 const ModelTransformer::Input &input, 211 const ModelTransformer::Input &input,
182 Model *outputModelToAdd); 212 Model *outputModelToAdd);
183 213
184 /** 214 /**
185 * Add an imported (non-derived, non-main) model. This is 215 * Add an imported (non-derived, non-main) model. This is
186 * necessary to register any imported model that is associated 216 * necessary to register any imported model that is associated
187 * with a layer. 217 * with a layer.
296 // models in them. 326 // models in them.
297 327
298 const Model *source; 328 const Model *source;
299 int channel; 329 int channel;
300 Transform transform; 330 Transform transform;
331 bool additional;
301 332
302 // Count of the number of layers using this model. 333 // Count of the number of layers using this model.
303 int refcount; 334 int refcount;
304 }; 335 };
305 336
306 typedef std::map<Model *, ModelRecord> ModelMap; 337 typedef std::map<Model *, ModelRecord> ModelMap;
307 ModelMap m_models; 338 ModelMap m_models;
339
340 /**
341 * Add an extra derived model (returned at the end of processing a
342 * transform).
343 */
344 void addAdditionalModel(Model *);
308 345
309 class AddLayerCommand : public Command 346 class AddLayerCommand : public Command
310 { 347 {
311 public: 348 public:
312 AddLayerCommand(Document *d, View *view, Layer *layer); 349 AddLayerCommand(Document *d, View *view, Layer *layer);
355 static TransformId getAlignmentTransformName(); 392 static TransformId getAlignmentTransformName();
356 393
357 void toXml(QTextStream &, QString, QString, bool asTemplate) const; 394 void toXml(QTextStream &, QString, QString, bool asTemplate) const;
358 void writePlaceholderMainModel(QTextStream &, QString) const; 395 void writePlaceholderMainModel(QTextStream &, QString) const;
359 396
397 std::vector<Layer *> createLayersForDerivedModels(std::vector<Model *>,
398 QStringList names);
399
360 /** 400 /**
361 * And these are the layers. We also control the lifespans of 401 * And these are the layers. We also control the lifespans of
362 * these (usually through the commands used to add and remove them). 402 * these (usually through the commands used to add and remove them).
363 */ 403 */
364 typedef std::set<Layer *> LayerSet; 404 typedef std::set<Layer *> LayerSet;