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@150
|
22 #include "base/XmlExportable.h"
|
Chris@391
|
23 #include "base/Playable.h"
|
Chris@1038
|
24 #include "base/BaseTypes.h"
|
Chris@1060
|
25 #include "base/DataExportOptions.h"
|
Chris@150
|
26
|
Chris@179
|
27 class ZoomConstraint;
|
Chris@319
|
28 class AlignmentModel;
|
Chris@179
|
29
|
Chris@1500
|
30 typedef int ModelId;
|
Chris@1500
|
31
|
Chris@150
|
32 /**
|
Chris@150
|
33 * Model is the base class for all data models that represent any sort
|
Chris@150
|
34 * of data on a time scale based on an audio frame rate.
|
Chris@150
|
35 */
|
Chris@150
|
36
|
Chris@179
|
37 class Model : public QObject,
|
Chris@1429
|
38 public XmlExportable,
|
Chris@391
|
39 public Playable
|
Chris@150
|
40 {
|
Chris@150
|
41 Q_OBJECT
|
Chris@150
|
42
|
Chris@150
|
43 public:
|
Chris@150
|
44 virtual ~Model();
|
Chris@150
|
45
|
Chris@150
|
46 /**
|
Chris@150
|
47 * Return true if the model was constructed successfully. Classes
|
Chris@150
|
48 * that refer to the model should always test this before use.
|
Chris@150
|
49 */
|
Chris@150
|
50 virtual bool isOK() const = 0;
|
Chris@150
|
51
|
Chris@150
|
52 /**
|
Chris@150
|
53 * Return the first audio frame spanned by the model.
|
Chris@150
|
54 */
|
Chris@1038
|
55 virtual sv_frame_t getStartFrame() const = 0;
|
Chris@150
|
56
|
Chris@150
|
57 /**
|
Chris@1611
|
58 * Return the audio frame at the end of the model, i.e. the final
|
Chris@1611
|
59 * frame contained within the model plus 1 (or plus the model's
|
Chris@1611
|
60 * "resolution" granularity, if more than 1). The end frame minus
|
Chris@1611
|
61 * the start frame should yield the total duration in frames
|
Chris@1451
|
62 * spanned by the model. This is consistent with the definition of
|
Chris@1451
|
63 * the end frame of a Selection object.
|
Chris@150
|
64 */
|
Chris@1038
|
65 virtual sv_frame_t getEndFrame() const = 0;
|
Chris@150
|
66
|
Chris@150
|
67 /**
|
Chris@150
|
68 * Return the frame rate in frames per second.
|
Chris@150
|
69 */
|
Chris@1040
|
70 virtual sv_samplerate_t getSampleRate() const = 0;
|
Chris@150
|
71
|
Chris@150
|
72 /**
|
Chris@297
|
73 * Return the frame rate of the underlying material, if the model
|
Chris@297
|
74 * itself has already been resampled.
|
Chris@297
|
75 */
|
Chris@1040
|
76 virtual sv_samplerate_t getNativeRate() const { return getSampleRate(); }
|
Chris@297
|
77
|
Chris@297
|
78 /**
|
Chris@333
|
79 * Return the "work title" of the model, if known.
|
Chris@333
|
80 */
|
Chris@333
|
81 virtual QString getTitle() const;
|
Chris@333
|
82
|
Chris@333
|
83 /**
|
Chris@333
|
84 * Return the "artist" or "maker" of the model, if known.
|
Chris@333
|
85 */
|
Chris@333
|
86 virtual QString getMaker() const;
|
Chris@333
|
87
|
Chris@333
|
88 /**
|
Chris@345
|
89 * Return the location of the data in this model (e.g. source
|
Chris@345
|
90 * URL). This should not normally be returned for editable models
|
Chris@345
|
91 * that have been edited.
|
Chris@345
|
92 */
|
Chris@345
|
93 virtual QString getLocation() const;
|
Chris@345
|
94
|
Chris@345
|
95 /**
|
Chris@345
|
96 * Return the type of the model. For display purposes only.
|
Chris@345
|
97 */
|
Chris@345
|
98 virtual QString getTypeName() const = 0;
|
Chris@345
|
99
|
Chris@345
|
100 /**
|
cannam@1452
|
101 * Return true if this is a sparse model.
|
cannam@1452
|
102 */
|
cannam@1452
|
103 virtual bool isSparse() const { return false; }
|
Chris@1500
|
104
|
Chris@1500
|
105 /**
|
Chris@1500
|
106 * Return an id for this model. The id is guaranteed to be a
|
Chris@1500
|
107 * unique identifier for this model among all models that may ever
|
Chris@1500
|
108 * exist within this single run of the application.
|
Chris@1500
|
109 */
|
Chris@1500
|
110 ModelId getId() const { return m_id; }
|
cannam@1452
|
111
|
cannam@1452
|
112 /**
|
Chris@923
|
113 * Mark the model as abandoning. This means that the application
|
Chris@923
|
114 * no longer needs it, so it can stop doing any background
|
Chris@923
|
115 * calculations it may be involved in. Note that as far as the
|
Chris@923
|
116 * model API is concerned, this does nothing more than tell the
|
Chris@923
|
117 * model to return true from isAbandoning(). The actual response
|
Chris@923
|
118 * to this will depend on the model's context -- it's possible
|
Chris@923
|
119 * nothing at all will change.
|
Chris@923
|
120 */
|
Chris@923
|
121 virtual void abandon() {
|
Chris@923
|
122 m_abandoning = true;
|
Chris@923
|
123 }
|
Chris@923
|
124
|
Chris@923
|
125 /**
|
Chris@923
|
126 * Query whether the model has been marked as abandoning.
|
Chris@923
|
127 */
|
Chris@923
|
128 virtual bool isAbandoning() const {
|
Chris@923
|
129 return m_abandoning;
|
Chris@923
|
130 }
|
Chris@923
|
131
|
Chris@150
|
132 /**
|
Chris@150
|
133 * Return true if the model has finished loading or calculating
|
Chris@150
|
134 * all its data, for a model that is capable of calculating in a
|
Chris@150
|
135 * background thread. The default implementation is appropriate
|
Chris@150
|
136 * for a thread that does not background any work but carries out
|
Chris@150
|
137 * all its calculation from the constructor or accessors.
|
Chris@150
|
138 *
|
Chris@150
|
139 * If "completion" is non-NULL, this function should return
|
Chris@150
|
140 * through it an estimated percentage value showing how far
|
Chris@150
|
141 * through the background operation it thinks it is (for progress
|
Chris@150
|
142 * reporting). If it has no way to calculate progress, it may
|
Chris@1133
|
143 * return the special value COMPLETION_UNKNOWN. See also
|
Chris@1133
|
144 * getCompletion().
|
Chris@150
|
145 */
|
Chris@150
|
146 virtual bool isReady(int *completion = 0) const {
|
Chris@1429
|
147 bool ok = isOK();
|
Chris@1429
|
148 if (completion) *completion = (ok ? 100 : 0);
|
Chris@1429
|
149 return ok;
|
Chris@150
|
150 }
|
Chris@150
|
151 static const int COMPLETION_UNKNOWN;
|
Chris@150
|
152
|
Chris@179
|
153 /**
|
Chris@179
|
154 * If this model imposes a zoom constraint, i.e. some limit to the
|
Chris@179
|
155 * set of resolutions at which its data can meaningfully be
|
Chris@179
|
156 * displayed, then return it.
|
Chris@179
|
157 */
|
Chris@179
|
158 virtual const ZoomConstraint *getZoomConstraint() const {
|
Chris@179
|
159 return 0;
|
Chris@179
|
160 }
|
Chris@179
|
161
|
Chris@297
|
162 /**
|
Chris@297
|
163 * If this model was derived from another, return the model it was
|
Chris@297
|
164 * derived from. The assumption is that the source model's
|
Chris@297
|
165 * alignment will also apply to this model, unless some other
|
Chris@319
|
166 * property (such as a specific alignment model set on this model)
|
Chris@319
|
167 * indicates otherwise.
|
Chris@297
|
168 */
|
Chris@297
|
169 virtual Model *getSourceModel() const {
|
Chris@297
|
170 return m_sourceModel;
|
Chris@297
|
171 }
|
Chris@297
|
172
|
Chris@297
|
173 /**
|
Chris@297
|
174 * Set the source model for this model.
|
Chris@297
|
175 */
|
Chris@319
|
176 virtual void setSourceModel(Model *model);
|
Chris@319
|
177
|
Chris@319
|
178 /**
|
Chris@319
|
179 * Specify an aligment between this model's timeline and that of a
|
Chris@319
|
180 * reference model. The alignment model records both the
|
Chris@319
|
181 * reference and the alignment. This model takes ownership of the
|
Chris@319
|
182 * alignment model.
|
Chris@319
|
183 */
|
Chris@319
|
184 virtual void setAlignment(AlignmentModel *alignment);
|
Chris@319
|
185
|
Chris@319
|
186 /**
|
Chris@407
|
187 * Retrieve the alignment model for this model. This is not a
|
Chris@407
|
188 * generally useful function, as the alignment you really want may
|
Chris@407
|
189 * be performed by the source model instead. You should normally
|
Chris@407
|
190 * use getAlignmentReference, alignToReference and
|
Chris@407
|
191 * alignFromReference instead of this. The main intended
|
Chris@407
|
192 * application for this function is in streaming out alignments to
|
Chris@407
|
193 * the session file.
|
Chris@407
|
194 */
|
Chris@407
|
195 virtual const AlignmentModel *getAlignment() const;
|
Chris@407
|
196
|
Chris@407
|
197 /**
|
Chris@319
|
198 * Return the reference model for the current alignment timeline,
|
Chris@319
|
199 * if any.
|
Chris@319
|
200 */
|
Chris@319
|
201 virtual const Model *getAlignmentReference() const;
|
Chris@319
|
202
|
Chris@319
|
203 /**
|
Chris@319
|
204 * Return the frame number of the reference model that corresponds
|
Chris@319
|
205 * to the given frame number in this model.
|
Chris@319
|
206 */
|
Chris@1038
|
207 virtual sv_frame_t alignToReference(sv_frame_t frame) const;
|
Chris@319
|
208
|
Chris@319
|
209 /**
|
Chris@319
|
210 * Return the frame number in this model that corresponds to the
|
Chris@319
|
211 * given frame number of the reference model.
|
Chris@319
|
212 */
|
Chris@1038
|
213 virtual sv_frame_t alignFromReference(sv_frame_t referenceFrame) const;
|
Chris@319
|
214
|
Chris@319
|
215 /**
|
Chris@319
|
216 * Return the completion percentage for the alignment model: 100
|
Chris@319
|
217 * if there is no alignment model or it has been entirely
|
Chris@319
|
218 * calculated, or less than 100 if it is still being calculated.
|
Chris@319
|
219 */
|
Chris@319
|
220 virtual int getAlignmentCompletion() const;
|
Chris@297
|
221
|
Chris@558
|
222 /**
|
Chris@558
|
223 * Set the event, feature, or signal type URI for the features
|
Chris@558
|
224 * contained in this model, according to the Audio Features RDF
|
Chris@558
|
225 * ontology.
|
Chris@558
|
226 */
|
Chris@558
|
227 void setRDFTypeURI(QString uri) { m_typeUri = uri; }
|
Chris@558
|
228
|
Chris@558
|
229 /**
|
Chris@558
|
230 * Retrieve the event, feature, or signal type URI for the
|
Chris@558
|
231 * features contained in this model, if previously set with
|
Chris@558
|
232 * setRDFTypeURI.
|
Chris@558
|
233 */
|
Chris@558
|
234 QString getRDFTypeURI() const { return m_typeUri; }
|
Chris@558
|
235
|
Chris@1580
|
236 void toXml(QTextStream &stream,
|
Chris@1608
|
237 QString indent = "",
|
Chris@1608
|
238 QString extraAttributes = "") const override;
|
Chris@150
|
239
|
Chris@838
|
240 virtual QString toDelimitedDataString(QString delimiter) const {
|
Chris@1072
|
241 return toDelimitedDataStringSubset
|
Chris@1451
|
242 (delimiter, getStartFrame(), getEndFrame());
|
Chris@838
|
243 }
|
Chris@1060
|
244 virtual QString toDelimitedDataStringWithOptions(QString delimiter, DataExportOptions opts) const {
|
Chris@1072
|
245 return toDelimitedDataStringSubsetWithOptions
|
Chris@1451
|
246 (delimiter, opts, getStartFrame(), getEndFrame());
|
Chris@1060
|
247 }
|
Chris@1038
|
248 virtual QString toDelimitedDataStringSubset(QString, sv_frame_t /* f0 */, sv_frame_t /* f1 */) const {
|
Chris@838
|
249 return "";
|
Chris@838
|
250 }
|
Chris@1060
|
251 virtual QString toDelimitedDataStringSubsetWithOptions(QString delimiter, DataExportOptions, sv_frame_t f0, sv_frame_t f1) const {
|
Chris@1060
|
252 // Default implementation supports no options
|
Chris@1060
|
253 return toDelimitedDataStringSubset(delimiter, f0, f1);
|
Chris@1060
|
254 }
|
Chris@150
|
255
|
Chris@319
|
256 public slots:
|
Chris@319
|
257 void aboutToDelete();
|
Chris@319
|
258 void sourceModelAboutToBeDeleted();
|
Chris@319
|
259
|
Chris@150
|
260 signals:
|
Chris@150
|
261 /**
|
Chris@150
|
262 * Emitted when a model has been edited (or more data retrieved
|
Chris@150
|
263 * from cache, in the case of a cached model that generates slowly)
|
Chris@150
|
264 */
|
Chris@150
|
265 void modelChanged();
|
Chris@150
|
266
|
Chris@150
|
267 /**
|
Chris@150
|
268 * Emitted when a model has been edited (or more data retrieved
|
Chris@150
|
269 * from cache, in the case of a cached model that generates slowly)
|
Chris@150
|
270 */
|
Chris@1038
|
271 void modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame);
|
Chris@150
|
272
|
Chris@150
|
273 /**
|
Chris@150
|
274 * Emitted when some internal processing has advanced a stage, but
|
Chris@150
|
275 * the model has not changed externally. Views should respond by
|
Chris@150
|
276 * updating any progress meters or other monitoring, but not
|
Chris@150
|
277 * refreshing the actual view.
|
Chris@150
|
278 */
|
Chris@150
|
279 void completionChanged();
|
Chris@150
|
280
|
Chris@319
|
281 /**
|
Chris@411
|
282 * Emitted when internal processing is complete (i.e. when
|
Chris@411
|
283 * isReady() would return true, with completion at 100).
|
Chris@411
|
284 */
|
Chris@411
|
285 void ready();
|
Chris@411
|
286
|
Chris@411
|
287 /**
|
Chris@319
|
288 * Emitted when the completion percentage changes for the
|
Chris@319
|
289 * calculation of this model's alignment model.
|
Chris@319
|
290 */
|
Chris@319
|
291 void alignmentCompletionChanged();
|
Chris@319
|
292
|
Chris@319
|
293 /**
|
Chris@319
|
294 * Emitted when something notifies this model (through calling
|
Chris@319
|
295 * aboutToDelete() that it is about to delete it. Note that this
|
Chris@319
|
296 * depends on an external agent such as a Document object or
|
Chris@319
|
297 * owning model telling the model that it is about to delete it;
|
Chris@319
|
298 * there is nothing in the model to guarantee that this signal
|
Chris@319
|
299 * will be emitted before the actual deletion.
|
Chris@319
|
300 */
|
Chris@319
|
301 void aboutToBeDeleted();
|
Chris@319
|
302
|
Chris@150
|
303 protected:
|
Chris@1500
|
304 Model() :
|
Chris@1500
|
305 m_id(getNextId()),
|
Chris@923
|
306 m_sourceModel(0),
|
Chris@923
|
307 m_alignment(0),
|
Chris@923
|
308 m_abandoning(false),
|
Chris@923
|
309 m_aboutToDelete(false) { }
|
Chris@150
|
310
|
Chris@150
|
311 // Not provided.
|
Chris@150
|
312 Model(const Model &);
|
Chris@150
|
313 Model &operator=(const Model &);
|
Chris@297
|
314
|
Chris@1500
|
315 const ModelId m_id;
|
Chris@297
|
316 Model *m_sourceModel;
|
Chris@319
|
317 AlignmentModel *m_alignment;
|
Chris@558
|
318 QString m_typeUri;
|
Chris@923
|
319 bool m_abandoning;
|
Chris@319
|
320 bool m_aboutToDelete;
|
Chris@1500
|
321
|
Chris@1500
|
322 int getNextId();
|
Chris@150
|
323 };
|
Chris@150
|
324
|
Chris@150
|
325 #endif
|