comparison data/model/Model.h @ 1766:85b9b466a59f

Merge from branch by-id
author Chris Cannam
date Wed, 17 Jul 2019 14:24:51 +0100
parents ee7fd2c01d87
children aa0b56d72f27
comparison
equal deleted inserted replaced
1730:649ac57c5a2d 1766:85b9b466a59f
17 #define SV_MODEL_H 17 #define SV_MODEL_H
18 18
19 #include <vector> 19 #include <vector>
20 #include <QObject> 20 #include <QObject>
21 21
22 #include "base/ById.h"
22 #include "base/XmlExportable.h" 23 #include "base/XmlExportable.h"
23 #include "base/Playable.h" 24 #include "base/Playable.h"
24 #include "base/BaseTypes.h" 25 #include "base/BaseTypes.h"
25 #include "base/DataExportOptions.h" 26 #include "base/DataExportOptions.h"
26 27
27 class ZoomConstraint; 28 class ZoomConstraint;
28 class AlignmentModel; 29 class AlignmentModel;
29 30
30 typedef int ModelId;
31
32 /** 31 /**
33 * Model is the base class for all data models that represent any sort 32 * Model is the base class for all data models that represent any sort
34 * of data on a time scale based on an audio frame rate. 33 * of data on a time scale based on an audio frame rate.
35 */ 34 */
36
37 class Model : public QObject, 35 class Model : public QObject,
36 public WithTypedId<Model>,
38 public XmlExportable, 37 public XmlExportable,
39 public Playable 38 public Playable
40 { 39 {
41 Q_OBJECT 40 Q_OBJECT
42 41
43 public: 42 public:
43 typedef Id ModelId;
44
44 virtual ~Model(); 45 virtual ~Model();
45 46
46 /** 47 /**
47 * Return true if the model was constructed successfully. Classes 48 * Return true if the model was constructed successfully. Classes
48 * that refer to the model should always test this before use. 49 * that refer to the model should always test this before use.
130 * Return true if this is a sparse model. 131 * Return true if this is a sparse model.
131 */ 132 */
132 virtual bool isSparse() const { return false; } 133 virtual bool isSparse() const { return false; }
133 134
134 /** 135 /**
135 * Return an id for this model. The id is guaranteed to be a
136 * unique identifier for this model among all models that may ever
137 * exist within this single run of the application.
138 */
139 ModelId getId() const { return m_id; }
140
141 /**
142 * Mark the model as abandoning. This means that the application
143 * no longer needs it, so it can stop doing any background
144 * calculations it may be involved in. Note that as far as the
145 * model API is concerned, this does nothing more than tell the
146 * model to return true from isAbandoning(). The actual response
147 * to this will depend on the model's context -- it's possible
148 * nothing at all will change.
149 */
150 virtual void abandon() {
151 m_abandoning = true;
152 }
153
154 /**
155 * Query whether the model has been marked as abandoning.
156 */
157 virtual bool isAbandoning() const {
158 return m_abandoning;
159 }
160
161 /**
162 * Return true if the model has finished loading or calculating 136 * Return true if the model has finished loading or calculating
163 * all its data, for a model that is capable of calculating in a 137 * all its data, for a model that is capable of calculating in a
164 * background thread. 138 * background thread.
165 * 139 *
166 * If "completion" is non-NULL, return through it an estimated 140 * If "completion" is non-NULL, return through it an estimated
206 virtual const ZoomConstraint *getZoomConstraint() const { 180 virtual const ZoomConstraint *getZoomConstraint() const {
207 return 0; 181 return 0;
208 } 182 }
209 183
210 /** 184 /**
211 * If this model was derived from another, return the model it was 185 * If this model was derived from another, return the id of the
212 * derived from. The assumption is that the source model's 186 * model it was derived from. The assumption is that the source
213 * alignment will also apply to this model, unless some other 187 * model's alignment will also apply to this model, unless some
214 * property (such as a specific alignment model set on this model) 188 * other property (such as a specific alignment model set on this
215 * indicates otherwise. 189 * model) indicates otherwise.
216 */ 190 */
217 virtual Model *getSourceModel() const { 191 virtual ModelId getSourceModel() const {
218 return m_sourceModel; 192 return m_sourceModel;
219 } 193 }
220 194
221 /** 195 /**
222 * Set the source model for this model. 196 * Set the source model for this model.
223 */ 197 */
224 virtual void setSourceModel(Model *model); 198 virtual void setSourceModel(ModelId model);
225 199
226 /** 200 /**
227 * Specify an aligment between this model's timeline and that of a 201 * Specify an alignment between this model's timeline and that of
228 * reference model. The alignment model records both the 202 * a reference model. The alignment model, of type AlignmentModel,
229 * reference and the alignment. This model takes ownership of the 203 * records both the reference and the alignment.
230 * alignment model. 204 */
231 */ 205 virtual void setAlignment(ModelId alignmentModel);
232 virtual void setAlignment(AlignmentModel *alignment);
233 206
234 /** 207 /**
235 * Retrieve the alignment model for this model. This is not a 208 * Retrieve the alignment model for this model. This is not a
236 * generally useful function, as the alignment you really want may 209 * generally useful function, as the alignment you really want may
237 * be performed by the source model instead. You should normally 210 * be performed by the source model instead. You should normally
238 * use getAlignmentReference, alignToReference and 211 * use getAlignmentReference, alignToReference and
239 * alignFromReference instead of this. The main intended 212 * alignFromReference instead of this. The main intended
240 * application for this function is in streaming out alignments to 213 * application for this function is in streaming out alignments to
241 * the session file. 214 * the session file.
242 */ 215 */
243 virtual const AlignmentModel *getAlignment() const; 216 virtual const ModelId getAlignment() const;
244 217
245 /** 218 /**
246 * Return the reference model for the current alignment timeline, 219 * Return the reference model for the current alignment timeline,
247 * if any. 220 * if any.
248 */ 221 */
249 virtual const Model *getAlignmentReference() const; 222 virtual const ModelId getAlignmentReference() const;
250 223
251 /** 224 /**
252 * Return the frame number of the reference model that corresponds 225 * Return the frame number of the reference model that corresponds
253 * to the given frame number in this model. 226 * to the given frame number in this model.
254 */ 227 */
288 virtual QString toDelimitedDataString(QString delimiter, 261 virtual QString toDelimitedDataString(QString delimiter,
289 DataExportOptions options, 262 DataExportOptions options,
290 sv_frame_t startFrame, 263 sv_frame_t startFrame,
291 sv_frame_t duration) const = 0; 264 sv_frame_t duration) const = 0;
292 265
293 public slots:
294 void aboutToDelete();
295 void sourceModelAboutToBeDeleted();
296
297 signals: 266 signals:
298 /** 267 /**
299 * Emitted when a model has been edited (or more data retrieved 268 * Emitted when a model has been edited (or more data retrieved
300 * from cache, in the case of a cached model that generates slowly) 269 * from cache, in the case of a cached model that generates slowly)
301 */ 270 */
302 void modelChanged(); 271 void modelChanged(ModelId myId);
303 272
304 /** 273 /**
305 * Emitted when a model has been edited (or more data retrieved 274 * Emitted when a model has been edited (or more data retrieved
306 * from cache, in the case of a cached model that generates slowly) 275 * from cache, in the case of a cached model that generates slowly)
307 */ 276 */
308 void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame); 277 void modelChangedWithin(ModelId myId, sv_frame_t startFrame, sv_frame_t endFrame);
309 278
310 /** 279 /**
311 * Emitted when some internal processing has advanced a stage, but 280 * Emitted when some internal processing has advanced a stage, but
312 * the model has not changed externally. Views should respond by 281 * the model has not changed externally. Views should respond by
313 * updating any progress meters or other monitoring, but not 282 * updating any progress meters or other monitoring, but not
314 * refreshing the actual view. 283 * refreshing the actual view.
315 */ 284 */
316 void completionChanged(); 285 void completionChanged(ModelId myId);
317 286
318 /** 287 /**
319 * Emitted when internal processing is complete (i.e. when 288 * Emitted when internal processing is complete (i.e. when
320 * isReady() would return true, with completion at 100). 289 * isReady() would return true, with completion at 100).
321 */ 290 */
322 void ready(); 291 void ready(ModelId myId);
323 292
324 /** 293 /**
325 * Emitted when the completion percentage changes for the 294 * Emitted when the completion percentage changes for the
326 * calculation of this model's alignment model. 295 * calculation of this model's alignment model.
327 */ 296 */
328 void alignmentCompletionChanged(); 297 void alignmentCompletionChanged(ModelId myId);
329
330 /**
331 * Emitted when something notifies this model (through calling
332 * aboutToDelete() that it is about to delete it. Note that this
333 * depends on an external agent such as a Document object or
334 * owning model telling the model that it is about to delete it;
335 * there is nothing in the model to guarantee that this signal
336 * will be emitted before the actual deletion.
337 */
338 void aboutToBeDeleted();
339 298
340 protected: 299 protected:
341 Model() : 300 Model() :
342 m_id(getNextId()),
343 m_sourceModel(0),
344 m_alignment(0),
345 m_abandoning(false),
346 m_aboutToDelete(false),
347 m_extendTo(0) { } 301 m_extendTo(0) { }
348 302
349 // Not provided. 303 // Not provided.
350 Model(const Model &); 304 Model(const Model &) =delete;
351 Model &operator=(const Model &); 305 Model &operator=(const Model &) =delete;
352 306
353 const ModelId m_id; 307 ModelId m_sourceModel;
354 Model *m_sourceModel; 308 ModelId m_alignmentModel;
355 AlignmentModel *m_alignment;
356 QString m_typeUri; 309 QString m_typeUri;
357 bool m_abandoning;
358 bool m_aboutToDelete;
359 sv_frame_t m_extendTo; 310 sv_frame_t m_extendTo;
360
361 int getNextId();
362 }; 311 };
363 312
313 typedef Model::Id ModelId;
314 typedef TypedById<Model, Model::Id> ModelById;
315
364 #endif 316 #endif