Chris@150
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@150
|
2
|
Chris@150
|
3 /*
|
Chris@150
|
4 Sonic Visualiser
|
Chris@150
|
5 An audio file viewer and annotation editor.
|
Chris@150
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@150
|
7 This file copyright 2006 Chris Cannam.
|
Chris@150
|
8
|
Chris@150
|
9 This program is free software; you can redistribute it and/or
|
Chris@150
|
10 modify it under the terms of the GNU General Public License as
|
Chris@150
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@150
|
12 License, or (at your option) any later version. See the file
|
Chris@150
|
13 COPYING included with this distribution for more information.
|
Chris@150
|
14 */
|
Chris@150
|
15
|
Chris@1500
|
16 #ifndef SV_MODEL_H
|
Chris@1500
|
17 #define SV_MODEL_H
|
Chris@150
|
18
|
Chris@150
|
19 #include <vector>
|
Chris@150
|
20 #include <QObject>
|
Chris@150
|
21
|
Chris@1731
|
22 #include "base/ById.h"
|
Chris@150
|
23 #include "base/XmlExportable.h"
|
Chris@391
|
24 #include "base/Playable.h"
|
Chris@1038
|
25 #include "base/BaseTypes.h"
|
Chris@1060
|
26 #include "base/DataExportOptions.h"
|
Chris@150
|
27
|
Chris@179
|
28 class ZoomConstraint;
|
Chris@319
|
29 class AlignmentModel;
|
Chris@179
|
30
|
Chris@150
|
31 /**
|
Chris@150
|
32 * Model is the base class for all data models that represent any sort
|
Chris@150
|
33 * of data on a time scale based on an audio frame rate.
|
Chris@150
|
34 */
|
Chris@179
|
35 class Model : public QObject,
|
Chris@1731
|
36 public WithId<Model>,
|
Chris@1429
|
37 public XmlExportable,
|
Chris@391
|
38 public Playable
|
Chris@150
|
39 {
|
Chris@150
|
40 Q_OBJECT
|
Chris@150
|
41
|
Chris@150
|
42 public:
|
Chris@150
|
43 virtual ~Model();
|
Chris@150
|
44
|
Chris@150
|
45 /**
|
Chris@150
|
46 * Return true if the model was constructed successfully. Classes
|
Chris@150
|
47 * that refer to the model should always test this before use.
|
Chris@150
|
48 */
|
Chris@150
|
49 virtual bool isOK() const = 0;
|
Chris@150
|
50
|
Chris@150
|
51 /**
|
Chris@150
|
52 * Return the first audio frame spanned by the model.
|
Chris@150
|
53 */
|
Chris@1038
|
54 virtual sv_frame_t getStartFrame() const = 0;
|
Chris@150
|
55
|
Chris@150
|
56 /**
|
Chris@1611
|
57 * Return the audio frame at the end of the model, i.e. the final
|
Chris@1659
|
58 * frame contained within the model plus 1 (rounded up to the
|
Chris@1659
|
59 * model's "resolution" granularity, if more than 1). The end
|
Chris@1659
|
60 * frame minus the start frame should yield the total duration in
|
Chris@1659
|
61 * frames (as a multiple of the resolution) spanned by the
|
Chris@1659
|
62 * model. This is broadly consistent with the definition of the
|
Chris@1659
|
63 * end frame of a Selection object.
|
Chris@1725
|
64 *
|
Chris@1725
|
65 * If the end has been extended by extendEndFrame() beyond the
|
Chris@1725
|
66 * true end frame, return the extended end instead. This is
|
Chris@1725
|
67 * usually the behaviour you want.
|
Chris@150
|
68 */
|
Chris@1725
|
69 sv_frame_t getEndFrame() const {
|
Chris@1725
|
70 sv_frame_t trueEnd = getTrueEndFrame();
|
Chris@1725
|
71 if (m_extendTo > trueEnd) {
|
Chris@1725
|
72 return m_extendTo;
|
Chris@1725
|
73 } else {
|
Chris@1725
|
74 return trueEnd;
|
Chris@1725
|
75 }
|
Chris@1725
|
76 }
|
Chris@1725
|
77
|
Chris@1725
|
78 /**
|
Chris@1725
|
79 * Return the audio frame at the end of the model. This is
|
Chris@1725
|
80 * identical to getEndFrame(), except that it ignores any extended
|
Chris@1725
|
81 * duration set with extendEndFrame().
|
Chris@1725
|
82 */
|
Chris@1725
|
83 virtual sv_frame_t getTrueEndFrame() const = 0;
|
Chris@1725
|
84
|
Chris@1725
|
85 /**
|
Chris@1725
|
86 * Extend the end of the model. If this is set to something beyond
|
Chris@1725
|
87 * the true end of the data within the model, then getEndFrame()
|
Chris@1725
|
88 * will return this value instead of the true end. (This is used
|
Chris@1725
|
89 * by the Tony application.)
|
Chris@1725
|
90 */
|
Chris@1725
|
91 void extendEndFrame(sv_frame_t to) {
|
Chris@1725
|
92 m_extendTo = to;
|
Chris@1725
|
93 }
|
Chris@150
|
94
|
Chris@150
|
95 /**
|
Chris@150
|
96 * Return the frame rate in frames per second.
|
Chris@150
|
97 */
|
Chris@1040
|
98 virtual sv_samplerate_t getSampleRate() const = 0;
|
Chris@150
|
99
|
Chris@150
|
100 /**
|
Chris@297
|
101 * Return the frame rate of the underlying material, if the model
|
Chris@297
|
102 * itself has already been resampled.
|
Chris@297
|
103 */
|
Chris@1040
|
104 virtual sv_samplerate_t getNativeRate() const { return getSampleRate(); }
|
Chris@297
|
105
|
Chris@297
|
106 /**
|
Chris@333
|
107 * Return the "work title" of the model, if known.
|
Chris@333
|
108 */
|
Chris@333
|
109 virtual QString getTitle() const;
|
Chris@333
|
110
|
Chris@333
|
111 /**
|
Chris@333
|
112 * Return the "artist" or "maker" of the model, if known.
|
Chris@333
|
113 */
|
Chris@333
|
114 virtual QString getMaker() const;
|
Chris@333
|
115
|
Chris@333
|
116 /**
|
Chris@345
|
117 * Return the location of the data in this model (e.g. source
|
Chris@345
|
118 * URL). This should not normally be returned for editable models
|
Chris@345
|
119 * that have been edited.
|
Chris@345
|
120 */
|
Chris@345
|
121 virtual QString getLocation() const;
|
Chris@345
|
122
|
Chris@345
|
123 /**
|
Chris@345
|
124 * Return the type of the model. For display purposes only.
|
Chris@345
|
125 */
|
Chris@345
|
126 virtual QString getTypeName() const = 0;
|
Chris@345
|
127
|
Chris@345
|
128 /**
|
cannam@1452
|
129 * Return true if this is a sparse model.
|
cannam@1452
|
130 */
|
cannam@1452
|
131 virtual bool isSparse() const { return false; }
|
Chris@1500
|
132
|
Chris@1500
|
133 /**
|
Chris@923
|
134 * Mark the model as abandoning. This means that the application
|
Chris@923
|
135 * no longer needs it, so it can stop doing any background
|
Chris@923
|
136 * calculations it may be involved in. Note that as far as the
|
Chris@923
|
137 * model API is concerned, this does nothing more than tell the
|
Chris@923
|
138 * model to return true from isAbandoning(). The actual response
|
Chris@923
|
139 * to this will depend on the model's context -- it's possible
|
Chris@923
|
140 * nothing at all will change.
|
Chris@923
|
141 */
|
Chris@923
|
142 virtual void abandon() {
|
Chris@923
|
143 m_abandoning = true;
|
Chris@923
|
144 }
|
Chris@923
|
145
|
Chris@923
|
146 /**
|
Chris@923
|
147 * Query whether the model has been marked as abandoning.
|
Chris@923
|
148 */
|
Chris@923
|
149 virtual bool isAbandoning() const {
|
Chris@923
|
150 return m_abandoning;
|
Chris@923
|
151 }
|
Chris@923
|
152
|
Chris@150
|
153 /**
|
Chris@150
|
154 * Return true if the model has finished loading or calculating
|
Chris@150
|
155 * all its data, for a model that is capable of calculating in a
|
Chris@1671
|
156 * background thread.
|
Chris@150
|
157 *
|
Chris@1671
|
158 * If "completion" is non-NULL, return through it an estimated
|
Chris@1671
|
159 * percentage value showing how far through the background
|
Chris@1671
|
160 * operation it thinks it is (for progress reporting). This should
|
Chris@1671
|
161 * be identical to the value returned by getCompletion().
|
Chris@1671
|
162 *
|
Chris@1671
|
163 * A model that carries out all its calculation from the
|
Chris@1671
|
164 * constructor or accessor functions would typically return true
|
Chris@1671
|
165 * (and completion == 100) as long as isOK() is true. Other models
|
Chris@1671
|
166 * may make the return value here depend on the internal
|
Chris@1671
|
167 * completion status.
|
Chris@1669
|
168 *
|
Chris@1669
|
169 * See also getCompletion().
|
Chris@150
|
170 */
|
Chris@1671
|
171 virtual bool isReady(int *cp = nullptr) const {
|
Chris@1671
|
172 int c = getCompletion();
|
Chris@1671
|
173 if (cp) *cp = c;
|
Chris@1671
|
174 if (!isOK()) return false;
|
Chris@1671
|
175 else return (c == 100);
|
Chris@150
|
176 }
|
Chris@1671
|
177
|
Chris@1671
|
178 /**
|
Chris@1671
|
179 * Return an estimated percentage value showing how far through
|
Chris@1671
|
180 * any background operation used to calculate or load the model
|
Chris@1671
|
181 * data the model thinks it is. Must return 100 when the model is
|
Chris@1671
|
182 * complete.
|
Chris@1671
|
183 *
|
Chris@1671
|
184 * A model that carries out all its calculation from the
|
Chris@1671
|
185 * constructor or accessor functions might return 0 if isOK() is
|
Chris@1671
|
186 * false and 100 if isOK() is true. Other models may make the
|
Chris@1671
|
187 * return value here depend on the internal completion status.
|
Chris@1671
|
188 *
|
Chris@1671
|
189 * See also isReady().
|
Chris@1671
|
190 */
|
Chris@1671
|
191 virtual int getCompletion() const = 0;
|
Chris@150
|
192
|
Chris@179
|
193 /**
|
Chris@179
|
194 * If this model imposes a zoom constraint, i.e. some limit to the
|
Chris@179
|
195 * set of resolutions at which its data can meaningfully be
|
Chris@179
|
196 * displayed, then return it.
|
Chris@179
|
197 */
|
Chris@179
|
198 virtual const ZoomConstraint *getZoomConstraint() const {
|
Chris@179
|
199 return 0;
|
Chris@179
|
200 }
|
Chris@179
|
201
|
Chris@297
|
202 /**
|
Chris@297
|
203 * If this model was derived from another, return the model it was
|
Chris@297
|
204 * derived from. The assumption is that the source model's
|
Chris@297
|
205 * alignment will also apply to this model, unless some other
|
Chris@319
|
206 * property (such as a specific alignment model set on this model)
|
Chris@319
|
207 * indicates otherwise.
|
Chris@297
|
208 */
|
Chris@297
|
209 virtual Model *getSourceModel() const {
|
Chris@297
|
210 return m_sourceModel;
|
Chris@297
|
211 }
|
Chris@297
|
212
|
Chris@297
|
213 /**
|
Chris@297
|
214 * Set the source model for this model.
|
Chris@297
|
215 */
|
Chris@319
|
216 virtual void setSourceModel(Model *model);
|
Chris@319
|
217
|
Chris@319
|
218 /**
|
Chris@319
|
219 * Specify an aligment between this model's timeline and that of a
|
Chris@319
|
220 * reference model. The alignment model records both the
|
Chris@319
|
221 * reference and the alignment. This model takes ownership of the
|
Chris@319
|
222 * alignment model.
|
Chris@319
|
223 */
|
Chris@319
|
224 virtual void setAlignment(AlignmentModel *alignment);
|
Chris@319
|
225
|
Chris@319
|
226 /**
|
Chris@407
|
227 * Retrieve the alignment model for this model. This is not a
|
Chris@407
|
228 * generally useful function, as the alignment you really want may
|
Chris@407
|
229 * be performed by the source model instead. You should normally
|
Chris@407
|
230 * use getAlignmentReference, alignToReference and
|
Chris@407
|
231 * alignFromReference instead of this. The main intended
|
Chris@407
|
232 * application for this function is in streaming out alignments to
|
Chris@407
|
233 * the session file.
|
Chris@407
|
234 */
|
Chris@407
|
235 virtual const AlignmentModel *getAlignment() const;
|
Chris@407
|
236
|
Chris@407
|
237 /**
|
Chris@319
|
238 * Return the reference model for the current alignment timeline,
|
Chris@319
|
239 * if any.
|
Chris@319
|
240 */
|
Chris@319
|
241 virtual const Model *getAlignmentReference() const;
|
Chris@319
|
242
|
Chris@319
|
243 /**
|
Chris@319
|
244 * Return the frame number of the reference model that corresponds
|
Chris@319
|
245 * to the given frame number in this model.
|
Chris@319
|
246 */
|
Chris@1038
|
247 virtual sv_frame_t alignToReference(sv_frame_t frame) const;
|
Chris@319
|
248
|
Chris@319
|
249 /**
|
Chris@319
|
250 * Return the frame number in this model that corresponds to the
|
Chris@319
|
251 * given frame number of the reference model.
|
Chris@319
|
252 */
|
Chris@1038
|
253 virtual sv_frame_t alignFromReference(sv_frame_t referenceFrame) const;
|
Chris@319
|
254
|
Chris@319
|
255 /**
|
Chris@319
|
256 * Return the completion percentage for the alignment model: 100
|
Chris@319
|
257 * if there is no alignment model or it has been entirely
|
Chris@319
|
258 * calculated, or less than 100 if it is still being calculated.
|
Chris@319
|
259 */
|
Chris@319
|
260 virtual int getAlignmentCompletion() const;
|
Chris@297
|
261
|
Chris@558
|
262 /**
|
Chris@558
|
263 * Set the event, feature, or signal type URI for the features
|
Chris@558
|
264 * contained in this model, according to the Audio Features RDF
|
Chris@558
|
265 * ontology.
|
Chris@558
|
266 */
|
Chris@558
|
267 void setRDFTypeURI(QString uri) { m_typeUri = uri; }
|
Chris@558
|
268
|
Chris@558
|
269 /**
|
Chris@558
|
270 * Retrieve the event, feature, or signal type URI for the
|
Chris@558
|
271 * features contained in this model, if previously set with
|
Chris@558
|
272 * setRDFTypeURI.
|
Chris@558
|
273 */
|
Chris@558
|
274 QString getRDFTypeURI() const { return m_typeUri; }
|
Chris@558
|
275
|
Chris@1580
|
276 void toXml(QTextStream &stream,
|
Chris@1608
|
277 QString indent = "",
|
Chris@1608
|
278 QString extraAttributes = "") const override;
|
Chris@150
|
279
|
Chris@1679
|
280 virtual QString toDelimitedDataString(QString delimiter,
|
Chris@1679
|
281 DataExportOptions options,
|
Chris@1679
|
282 sv_frame_t startFrame,
|
Chris@1679
|
283 sv_frame_t duration) const = 0;
|
Chris@150
|
284
|
Chris@319
|
285 public slots:
|
Chris@319
|
286 void aboutToDelete();
|
Chris@319
|
287 void sourceModelAboutToBeDeleted();
|
Chris@319
|
288
|
Chris@150
|
289 signals:
|
Chris@150
|
290 /**
|
Chris@150
|
291 * Emitted when a model has been edited (or more data retrieved
|
Chris@150
|
292 * from cache, in the case of a cached model that generates slowly)
|
Chris@150
|
293 */
|
Chris@150
|
294 void modelChanged();
|
Chris@150
|
295
|
Chris@150
|
296 /**
|
Chris@150
|
297 * Emitted when a model has been edited (or more data retrieved
|
Chris@150
|
298 * from cache, in the case of a cached model that generates slowly)
|
Chris@150
|
299 */
|
Chris@1038
|
300 void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame);
|
Chris@150
|
301
|
Chris@150
|
302 /**
|
Chris@150
|
303 * Emitted when some internal processing has advanced a stage, but
|
Chris@150
|
304 * the model has not changed externally. Views should respond by
|
Chris@150
|
305 * updating any progress meters or other monitoring, but not
|
Chris@150
|
306 * refreshing the actual view.
|
Chris@150
|
307 */
|
Chris@150
|
308 void completionChanged();
|
Chris@150
|
309
|
Chris@319
|
310 /**
|
Chris@411
|
311 * Emitted when internal processing is complete (i.e. when
|
Chris@411
|
312 * isReady() would return true, with completion at 100).
|
Chris@411
|
313 */
|
Chris@411
|
314 void ready();
|
Chris@411
|
315
|
Chris@411
|
316 /**
|
Chris@319
|
317 * Emitted when the completion percentage changes for the
|
Chris@319
|
318 * calculation of this model's alignment model.
|
Chris@319
|
319 */
|
Chris@319
|
320 void alignmentCompletionChanged();
|
Chris@319
|
321
|
Chris@319
|
322 /**
|
Chris@319
|
323 * Emitted when something notifies this model (through calling
|
Chris@319
|
324 * aboutToDelete() that it is about to delete it. Note that this
|
Chris@319
|
325 * depends on an external agent such as a Document object or
|
Chris@319
|
326 * owning model telling the model that it is about to delete it;
|
Chris@319
|
327 * there is nothing in the model to guarantee that this signal
|
Chris@319
|
328 * will be emitted before the actual deletion.
|
Chris@319
|
329 */
|
Chris@1732
|
330 //!!! our goal is to get rid of (the need for) this
|
Chris@319
|
331 void aboutToBeDeleted();
|
Chris@319
|
332
|
Chris@150
|
333 protected:
|
Chris@1500
|
334 Model() :
|
Chris@923
|
335 m_sourceModel(0),
|
Chris@923
|
336 m_alignment(0),
|
Chris@923
|
337 m_abandoning(false),
|
Chris@1725
|
338 m_aboutToDelete(false),
|
Chris@1725
|
339 m_extendTo(0) { }
|
Chris@150
|
340
|
Chris@150
|
341 // Not provided.
|
Chris@150
|
342 Model(const Model &);
|
Chris@150
|
343 Model &operator=(const Model &);
|
Chris@297
|
344
|
Chris@297
|
345 Model *m_sourceModel;
|
Chris@319
|
346 AlignmentModel *m_alignment;
|
Chris@558
|
347 QString m_typeUri;
|
Chris@923
|
348 bool m_abandoning;
|
Chris@319
|
349 bool m_aboutToDelete;
|
Chris@1725
|
350 sv_frame_t m_extendTo;
|
Chris@150
|
351 };
|
Chris@150
|
352
|
Chris@1731
|
353 typedef Model::Id ModelId;
|
Chris@1731
|
354 typedef StaticById<Model, ModelId> ModelById;
|
Chris@1731
|
355
|
Chris@150
|
356 #endif
|