Model.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7  This file copyright 2006 Chris Cannam.
8 
9  This program is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License as
11  published by the Free Software Foundation; either version 2 of the
12  License, or (at your option) any later version. See the file
13  COPYING included with this distribution for more information.
14 */
15 
16 #ifndef SV_MODEL_H
17 #define SV_MODEL_H
18 
19 #include <vector>
20 #include <atomic>
21 
22 #include <QObject>
23 #include <QMutex>
24 
25 #include "base/ById.h"
26 #include "base/XmlExportable.h"
27 #include "base/Playable.h"
28 #include "base/BaseTypes.h"
29 #include "base/DataExportOptions.h"
30 
31 class ZoomConstraint;
32 class AlignmentModel;
33 
51 class Model : public QObject,
52  public WithTypedId<Model>,
53  public XmlExportable,
54  public Playable
55 {
56  Q_OBJECT
57 
58 public:
59  typedef Id ModelId;
60 
61  virtual ~Model();
62 
67  virtual bool isOK() const = 0;
68 
72  virtual sv_frame_t getStartFrame() const = 0;
73 
88  sv_frame_t trueEnd = getTrueEndFrame();
89  if (m_extendTo > trueEnd) {
90  return m_extendTo;
91  } else {
92  return trueEnd;
93  }
94  }
95 
101  virtual sv_frame_t getTrueEndFrame() const = 0;
102 
110  m_extendTo = to;
111  }
112 
116  virtual sv_samplerate_t getSampleRate() const = 0;
117 
122  virtual sv_samplerate_t getNativeRate() const { return getSampleRate(); }
123 
127  virtual QString getTitle() const;
128 
132  virtual QString getMaker() const;
133 
139  virtual QString getLocation() const;
140 
144  virtual QString getTypeName() const = 0;
145 
149  virtual bool isSparse() const { return false; }
150 
169  virtual bool isReady(int *cp = nullptr) const {
170  int c = getCompletion();
171  if (cp) *cp = c;
172  if (!isOK()) return false;
173  else return (c == 100);
174  }
175 
189  virtual int getCompletion() const = 0;
190 
196  virtual const ZoomConstraint *getZoomConstraint() const {
197  return 0;
198  }
199 
207  virtual ModelId getSourceModel() const {
208  return m_sourceModel;
209  }
210 
214  virtual void setSourceModel(ModelId model);
215 
221  virtual void setAlignment(ModelId alignmentModel);
222 
232  virtual const ModelId getAlignment() const;
233 
238  virtual const ModelId getAlignmentReference() const;
239 
244  virtual sv_frame_t alignToReference(sv_frame_t frame) const;
245 
250  virtual sv_frame_t alignFromReference(sv_frame_t referenceFrame) const;
251 
257  virtual int getAlignmentCompletion() const;
258 
264  void setRDFTypeURI(QString uri) { m_typeUri = uri; }
265 
271  QString getRDFTypeURI() const { return m_typeUri; }
272 
273  void toXml(QTextStream &stream,
274  QString indent = "",
275  QString extraAttributes = "") const override;
276 
281  virtual QVector<QString>
282  getStringExportHeaders(DataExportOptions options) const = 0;
283 
288  virtual QVector<QVector<QString>>
290  sv_frame_t startFrame,
291  sv_frame_t duration) const = 0;
292 
293 signals:
298  void modelChanged(ModelId myId);
299 
304  void modelChangedWithin(ModelId myId, sv_frame_t startFrame, sv_frame_t endFrame);
305 
312  void completionChanged(ModelId myId);
313 
318  void ready(ModelId myId);
319 
325  void alignmentCompletionChanged(ModelId myId);
326 
327 private slots:
328  void alignmentModelCompletionChanged(ModelId);
329 
330 protected:
331  Model() : m_extendTo(0) { }
332 
333  // Not provided.
334  Model(const Model &) =delete;
335  Model &operator=(const Model &) =delete;
336 
337  mutable QMutex m_mutex;
338  ModelId m_sourceModel;
340  QString m_typeUri;
341  std::atomic<sv_frame_t> m_extendTo;
342 };
343 
346 
347 #endif
QString getRDFTypeURI() const
Retrieve the event, feature, or signal type URI for the features contained in this model...
Definition: Model.h:271
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
void alignmentCompletionChanged(ModelId myId)
Emitted when the completion percentage changes for the calculation of this model&#39;s alignment model...
void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const override
Stream this exportable object out to XML on a text stream.
Definition: Model.cpp:204
virtual ModelId getSourceModel() const
If this model was derived from another, return the id of the model it was derived from...
Definition: Model.h:207
virtual sv_frame_t alignFromReference(sv_frame_t referenceFrame) const
Return the frame number in this model that corresponds to the given frame number of the reference mod...
Definition: Model.cpp:116
virtual void setAlignment(ModelId alignmentModel)
Specify an alignment between this model&#39;s timeline and that of a reference model. ...
Definition: Model.cpp:45
virtual const ZoomConstraint * getZoomConstraint() const
If this model imposes a zoom constraint, i.e.
Definition: Model.h:196
virtual sv_frame_t getTrueEndFrame() const =0
Return the audio frame at the end of the model.
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
virtual ~Model()
Definition: Model.cpp:25
virtual int getAlignmentCompletion() const
Return the completion percentage for the alignment model: 100 if there is no alignment model or it ha...
Definition: Model.cpp:141
void setRDFTypeURI(QString uri)
Set the event, feature, or signal type URI for the features contained in this model, according to the Audio Features RDF ontology.
Definition: Model.h:264
TypedById< Model, Model::Id > ModelById
Definition: Model.h:345
void ready(ModelId myId)
Emitted when internal processing is complete (i.e.
void alignmentModelCompletionChanged(ModelId)
Definition: Model.cpp:66
virtual QString getLocation() const
Return the location of the data in this model (e.g.
Definition: Model.cpp:195
void extendEndFrame(sv_frame_t to)
Extend the end of the model.
Definition: Model.h:109
virtual QString getMaker() const
Return the "artist" or "maker" of the model, if known.
Definition: Model.cpp:186
sv_frame_t getEndFrame() const
Return the audio frame at the end of the model, i.e.
Definition: Model.h:87
virtual bool isReady(int *cp=nullptr) const
Return true if the model has finished loading or calculating all its data, for a model that is capabl...
Definition: Model.h:169
virtual bool isOK() const =0
Return true if the model was constructed successfully.
virtual const ModelId getAlignmentReference() const
Return the reference model for the current alignment timeline, if any.
Definition: Model.cpp:79
virtual QString getTypeName() const =0
Return the type of the model.
virtual QVector< QString > getStringExportHeaders(DataExportOptions options) const =0
Return a label for each column that would be written by toStringExportRows.
ModelId m_sourceModel
Definition: Model.h:338
Model & operator=(const Model &)=delete
virtual QVector< QVector< QString > > toStringExportRows(DataExportOptions options, sv_frame_t startFrame, sv_frame_t duration) const =0
Emit events starting within the given range as string rows ready for conversion to an e...
virtual sv_samplerate_t getSampleRate() const =0
Return the frame rate in frames per second.
std::atomic< sv_frame_t > m_extendTo
Definition: Model.h:341
Model()
Definition: Model.h:331
Model is the base class for all data models that represent any sort of data on a time scale based on ...
Definition: Model.h:51
ModelId m_alignmentModel
Definition: Model.h:339
void completionChanged(ModelId myId)
Emitted when some internal processing has advanced a stage, but the model has not changed externally...
QMutex m_mutex
Definition: Model.h:337
virtual bool isSparse() const
Return true if this is a sparse model.
Definition: Model.h:149
Id ModelId
Definition: Model.h:59
virtual void setSourceModel(ModelId model)
Set the source model for this model.
Definition: Model.cpp:31
virtual sv_frame_t getStartFrame() const =0
Return the first audio frame spanned by the model.
void modelChangedWithin(ModelId myId, sv_frame_t startFrame, sv_frame_t endFrame)
Emitted when a model has been edited (or more data retrieved from cache, in the case of a cached mode...
virtual sv_samplerate_t getNativeRate() const
Return the frame rate of the underlying material, if the model itself has already been resampled...
Definition: Model.h:122
virtual QString getTitle() const
Return the "work title" of the model, if known.
Definition: Model.cpp:177
ZoomConstraint is a simple interface that describes a limitation on the available zoom sizes for a vi...
virtual int getCompletion() const =0
Return an estimated percentage value showing how far through any background operation used to calcula...
virtual const ModelId getAlignment() const
Retrieve the alignment model for this model.
Definition: Model.cpp:72
virtual sv_frame_t alignToReference(sv_frame_t frame) const
Return the frame number of the reference model that corresponds to the given frame number in this mod...
Definition: Model.cpp:88
Definition: ById.h:115
void modelChanged(ModelId myId)
Emitted when a model has been edited (or more data retrieved from cache, in the case of a cached mode...
int DataExportOptions
QString m_typeUri
Definition: Model.h:340