svcore  1.9
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 _MODEL_H_
17 #define _MODEL_H_
18 
19 #include <vector>
20 #include <QObject>
21 
22 #include "base/XmlExportable.h"
23 #include "base/Playable.h"
24 
25 typedef std::vector<float> SampleBlock;
26 
27 class ZoomConstraint;
28 class AlignmentModel;
29 
35 class Model : public QObject,
36  public XmlExportable,
37  public Playable
38 {
39  Q_OBJECT
40 
41 public:
42  virtual ~Model();
43 
48  virtual bool isOK() const = 0;
49 
53  virtual int getStartFrame() const = 0;
54 
58  virtual int getEndFrame() const = 0;
59 
63  virtual int getSampleRate() const = 0;
64 
69  virtual int getNativeRate() const { return getSampleRate(); }
70 
74  virtual QString getTitle() const;
75 
79  virtual QString getMaker() const;
80 
86  virtual QString getLocation() const;
87 
91  virtual QString getTypeName() const = 0;
92 
107  virtual Model *clone() const = 0;
108 
118  virtual void abandon() {
119  m_abandoning = true;
120  }
121 
125  virtual bool isAbandoning() const {
126  return m_abandoning;
127  }
128 
142  virtual bool isReady(int *completion = 0) const {
143  bool ok = isOK();
144  if (completion) *completion = (ok ? 100 : 0);
145  return ok;
146  }
147  static const int COMPLETION_UNKNOWN;
148 
154  virtual const ZoomConstraint *getZoomConstraint() const {
155  return 0;
156  }
157 
165  virtual Model *getSourceModel() const {
166  return m_sourceModel;
167  }
168 
172  virtual void setSourceModel(Model *model);
173 
180  virtual void setAlignment(AlignmentModel *alignment);
181 
191  virtual const AlignmentModel *getAlignment() const;
192 
197  virtual const Model *getAlignmentReference() const;
198 
203  virtual int alignToReference(int frame) const;
204 
209  virtual int alignFromReference(int referenceFrame) const;
210 
216  virtual int getAlignmentCompletion() const;
217 
223  void setRDFTypeURI(QString uri) { m_typeUri = uri; }
224 
230  QString getRDFTypeURI() const { return m_typeUri; }
231 
232  virtual void toXml(QTextStream &stream,
233  QString indent = "",
234  QString extraAttributes = "") const;
235 
236  virtual QString toDelimitedDataString(QString delimiter) const {
237  return toDelimitedDataStringSubset(delimiter, getStartFrame(), getEndFrame());
238  }
239  virtual QString toDelimitedDataStringSubset(QString, int /* f0 */, int /* f1 */) const {
240  return "";
241  }
242 
243 public slots:
244  void aboutToDelete();
246 
247 signals:
252  void modelChanged();
253 
258  void modelChangedWithin(int startFrame, int endFrame);
259 
266  void completionChanged();
267 
272  void ready();
273 
279 
288  void aboutToBeDeleted();
289 
290 protected:
291  Model() :
292  m_sourceModel(0),
293  m_alignment(0),
294  m_abandoning(false),
295  m_aboutToDelete(false) { }
296 
297  // Not provided.
298  Model(const Model &);
299  Model &operator=(const Model &);
300 
303  QString m_typeUri;
306 };
307 
308 #endif
void aboutToBeDeleted()
Emitted when something notifies this model (through calling aboutToDelete() that it is about to delet...
virtual ~Model()
Definition: Model.cpp:25
virtual QString getMaker() const
Return the "artist" or "maker" of the model, if known.
Definition: Model.cpp:160
void setRDFTypeURI(QString uri)
Set the event, feature, or signal type URI for the features contained in this model,...
Definition: Model.h:223
static const int COMPLETION_UNKNOWN
Definition: Model.h:147
void ready()
Emitted when internal processing is complete (i.e.
virtual int getNativeRate() const
Return the frame rate of the underlying material, if the model itself has already been resampled.
Definition: Model.h:69
bool m_aboutToDelete
Definition: Model.h:305
virtual int getStartFrame() const =0
Return the first audio frame spanned by the model.
AlignmentModel * m_alignment
Definition: Model.h:302
void completionChanged()
Emitted when some internal processing has advanced a stage, but the model has not changed externally.
std::vector< float > SampleBlock
Definition: Model.h:25
virtual const ZoomConstraint * getZoomConstraint() const
If this model imposes a zoom constraint, i.e.
Definition: Model.h:154
void modelChangedWithin(int startFrame, int endFrame)
Emitted when a model has been edited (or more data retrieved from cache, in the case of a cached mode...
virtual QString getLocation() const
Return the location of the data in this model (e.g.
Definition: Model.cpp:167
virtual bool isReady(int *completion=0) const
Return true if the model has finished loading or calculating all its data, for a model that is capabl...
Definition: Model.h:142
void alignmentCompletionChanged()
Emitted when the completion percentage changes for the calculation of this model's alignment model.
virtual void toXml(QTextStream &stream, QString indent="", QString extraAttributes="") const
Stream this exportable object out to XML on a text stream.
Definition: Model.cpp:174
virtual const AlignmentModel * getAlignment() const
Retrieve the alignment model for this model.
Definition: Model.cpp:94
virtual bool isOK() const =0
Return true if the model was constructed successfully.
virtual void setSourceModel(Model *model)
Set the source model for this model.
Definition: Model.cpp:42
virtual int alignFromReference(int referenceFrame) const
Return the frame number in this model that corresponds to the given frame number of the reference mod...
Definition: Model.cpp:125
virtual Model * clone() const =0
Return a copy of this model.
virtual QString getTypeName() const =0
Return the type of the model.
virtual void setAlignment(AlignmentModel *alignment)
Specify an aligment between this model's timeline and that of a reference model.
Definition: Model.cpp:82
void modelChanged()
Emitted when a model has been edited (or more data retrieved from cache, in the case of a cached mode...
virtual int getSampleRate() const =0
Return the frame rate in frames per second.
Model()
Definition: Model.h:291
virtual QString toDelimitedDataStringSubset(QString, int, int) const
Definition: Model.h:239
Model is the base class for all data models that represent any sort of data on a time scale based on ...
Definition: Model.h:35
virtual QString toDelimitedDataString(QString delimiter) const
Definition: Model.h:236
virtual int alignToReference(int frame) const
Return the frame number of the reference model that corresponds to the given frame number in this mod...
Definition: Model.cpp:110
virtual Model * getSourceModel() const
If this model was derived from another, return the model it was derived from.
Definition: Model.h:165
virtual int getEndFrame() const =0
Return the last audio frame spanned by the model.
void aboutToDelete()
Definition: Model.cpp:60
virtual QString getTitle() const
Return the "work title" of the model, if known.
Definition: Model.cpp:153
Model * m_sourceModel
Definition: Model.h:301
ZoomConstraint is a simple interface that describes a limitation on the available zoom sizes for a vi...
QString getRDFTypeURI() const
Retrieve the event, feature, or signal type URI for the features contained in this model,...
Definition: Model.h:230
bool m_abandoning
Definition: Model.h:304
Model & operator=(const Model &)
void sourceModelAboutToBeDeleted()
Definition: Model.cpp:76
virtual void abandon()
Mark the model as abandoning.
Definition: Model.h:118
virtual const Model * getAlignmentReference() const
Return the reference model for the current alignment timeline, if any.
Definition: Model.cpp:100
virtual bool isAbandoning() const
Query whether the model has been marked as abandoning.
Definition: Model.h:125
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:139
QString m_typeUri
Definition: Model.h:303