Chris@49
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@52
|
4 Sonic Visualiser
|
Chris@52
|
5 An audio file viewer and annotation editor.
|
Chris@52
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@52
|
7 This file copyright 2006 Chris Cannam.
|
Chris@0
|
8
|
Chris@52
|
9 This program is free software; you can redistribute it and/or
|
Chris@52
|
10 modify it under the terms of the GNU General Public License as
|
Chris@52
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@52
|
12 License, or (at your option) any later version. See the file
|
Chris@52
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #ifndef _MODEL_H_
|
Chris@0
|
17 #define _MODEL_H_
|
Chris@0
|
18
|
Chris@0
|
19 #include <vector>
|
Chris@0
|
20 #include <QObject>
|
Chris@0
|
21
|
Chris@3
|
22 #include "XmlExportable.h"
|
Chris@3
|
23
|
Chris@0
|
24 typedef std::vector<float> SampleBlock;
|
Chris@0
|
25
|
Chris@0
|
26 /**
|
Chris@0
|
27 * Model is the base class for all data models that represent any sort
|
Chris@0
|
28 * of data on a time scale based on an audio frame rate.
|
Chris@0
|
29 */
|
Chris@0
|
30
|
Chris@3
|
31 class Model : virtual public QObject,
|
Chris@3
|
32 public XmlExportable
|
Chris@0
|
33 {
|
Chris@0
|
34 Q_OBJECT
|
Chris@0
|
35
|
Chris@0
|
36 public:
|
Chris@30
|
37 virtual ~Model();
|
Chris@30
|
38
|
Chris@0
|
39 /**
|
Chris@0
|
40 * Return true if the model was constructed successfully. Classes
|
Chris@0
|
41 * that refer to the model should always test this before use.
|
Chris@0
|
42 */
|
Chris@0
|
43 virtual bool isOK() const = 0;
|
Chris@0
|
44
|
Chris@0
|
45 /**
|
Chris@0
|
46 * Return the first audio frame spanned by the model.
|
Chris@0
|
47 */
|
Chris@0
|
48 virtual size_t getStartFrame() const = 0;
|
Chris@0
|
49
|
Chris@0
|
50 /**
|
Chris@0
|
51 * Return the last audio frame spanned by the model.
|
Chris@0
|
52 */
|
Chris@0
|
53 virtual size_t getEndFrame() const = 0;
|
Chris@0
|
54
|
Chris@0
|
55 /**
|
Chris@0
|
56 * Return the frame rate in frames per second.
|
Chris@0
|
57 */
|
Chris@0
|
58 virtual size_t getSampleRate() const = 0;
|
Chris@0
|
59
|
Chris@0
|
60 /**
|
Chris@0
|
61 * Return a copy of this model.
|
Chris@0
|
62 *
|
Chris@0
|
63 * If the model is not editable, this may be effectively a shallow
|
Chris@0
|
64 * copy. If the model is editable, however, this operation must
|
Chris@0
|
65 * properly copy all of the model's editable data.
|
Chris@0
|
66 *
|
Chris@0
|
67 * In general this operation is not useful for non-editable dense
|
Chris@0
|
68 * models such as waveforms, because there may be no efficient
|
Chris@0
|
69 * copy operation implemented -- for such models it is better not
|
Chris@0
|
70 * to copy at all.
|
Chris@0
|
71 *
|
Chris@0
|
72 * Caller owns the returned value.
|
Chris@0
|
73 */
|
Chris@0
|
74 virtual Model *clone() const = 0;
|
Chris@0
|
75
|
Chris@0
|
76 /**
|
Chris@0
|
77 * Return true if the model has finished loading or calculating
|
Chris@0
|
78 * all its data, for a model that is capable of calculating in a
|
Chris@0
|
79 * background thread. The default implementation is appropriate
|
Chris@0
|
80 * for a thread that does not background any work but carries out
|
Chris@0
|
81 * all its calculation from the constructor or accessors.
|
Chris@0
|
82 *
|
Chris@0
|
83 * If "completion" is non-NULL, this function should return
|
Chris@0
|
84 * through it an estimated percentage value showing how far
|
Chris@0
|
85 * through the background operation it thinks it is (for progress
|
Chris@0
|
86 * reporting). If it has no way to calculate progress, it may
|
Chris@0
|
87 * return the special value COMPLETION_UNKNOWN.
|
Chris@0
|
88 */
|
Chris@0
|
89 virtual bool isReady(int *completion = 0) const {
|
Chris@0
|
90 bool ok = isOK();
|
Chris@0
|
91 if (completion) *completion = (ok ? 100 : 0);
|
Chris@0
|
92 return ok;
|
Chris@0
|
93 }
|
Chris@0
|
94 static const int COMPLETION_UNKNOWN;
|
Chris@0
|
95
|
Chris@146
|
96 virtual void toXml(QTextStream &stream,
|
Chris@146
|
97 QString indent = "",
|
Chris@146
|
98 QString extraAttributes = "") const;
|
Chris@146
|
99
|
Chris@3
|
100 virtual QString toXmlString(QString indent = "",
|
Chris@3
|
101 QString extraAttributes = "") const;
|
Chris@3
|
102
|
Chris@76
|
103 virtual QString toDelimitedDataString(QString) const { return ""; }
|
Chris@76
|
104
|
Chris@0
|
105 signals:
|
Chris@0
|
106 /**
|
Chris@0
|
107 * Emitted when a model has been edited (or more data retrieved
|
Chris@0
|
108 * from cache, in the case of a cached model that generates slowly)
|
Chris@0
|
109 */
|
Chris@0
|
110 void modelChanged();
|
Chris@0
|
111
|
Chris@0
|
112 /**
|
Chris@0
|
113 * Emitted when a model has been edited (or more data retrieved
|
Chris@0
|
114 * from cache, in the case of a cached model that generates slowly)
|
Chris@0
|
115 */
|
Chris@0
|
116 void modelChanged(size_t startFrame, size_t endFrame);
|
Chris@0
|
117
|
Chris@0
|
118 /**
|
Chris@0
|
119 * Emitted when some internal processing has advanced a stage, but
|
Chris@0
|
120 * the model has not changed externally. Views should respond by
|
Chris@0
|
121 * updating any progress meters or other monitoring, but not
|
Chris@0
|
122 * refreshing the actual view.
|
Chris@0
|
123 */
|
Chris@0
|
124 void completionChanged();
|
Chris@0
|
125
|
Chris@0
|
126 protected:
|
Chris@0
|
127 Model() { }
|
Chris@0
|
128
|
Chris@0
|
129 // Not provided.
|
Chris@0
|
130 Model(const Model &);
|
Chris@0
|
131 Model &operator=(const Model &);
|
Chris@0
|
132 };
|
Chris@0
|
133
|
Chris@0
|
134 #endif
|