Mercurial > hg > svcore
comparison data/model/Model.h @ 150:4b2ea82fd0ed
* Reorganising code base. This revision probably should compile once more.
author | Chris Cannam |
---|---|
date | Mon, 31 Jul 2006 14:05:22 +0000 |
parents | |
children | 0ed2b2e26b44 |
comparison
equal
deleted
inserted
replaced
149:3e4c384f518e | 150:4b2ea82fd0ed |
---|---|
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 | |
24 typedef std::vector<float> SampleBlock; | |
25 | |
26 /** | |
27 * Model is the base class for all data models that represent any sort | |
28 * of data on a time scale based on an audio frame rate. | |
29 */ | |
30 | |
31 class Model : virtual public QObject, | |
32 public XmlExportable | |
33 { | |
34 Q_OBJECT | |
35 | |
36 public: | |
37 virtual ~Model(); | |
38 | |
39 /** | |
40 * Return true if the model was constructed successfully. Classes | |
41 * that refer to the model should always test this before use. | |
42 */ | |
43 virtual bool isOK() const = 0; | |
44 | |
45 /** | |
46 * Return the first audio frame spanned by the model. | |
47 */ | |
48 virtual size_t getStartFrame() const = 0; | |
49 | |
50 /** | |
51 * Return the last audio frame spanned by the model. | |
52 */ | |
53 virtual size_t getEndFrame() const = 0; | |
54 | |
55 /** | |
56 * Return the frame rate in frames per second. | |
57 */ | |
58 virtual size_t getSampleRate() const = 0; | |
59 | |
60 /** | |
61 * Return a copy of this model. | |
62 * | |
63 * If the model is not editable, this may be effectively a shallow | |
64 * copy. If the model is editable, however, this operation must | |
65 * properly copy all of the model's editable data. | |
66 * | |
67 * In general this operation is not useful for non-editable dense | |
68 * models such as waveforms, because there may be no efficient | |
69 * copy operation implemented -- for such models it is better not | |
70 * to copy at all. | |
71 * | |
72 * Caller owns the returned value. | |
73 */ | |
74 virtual Model *clone() const = 0; | |
75 | |
76 /** | |
77 * Return true if the model has finished loading or calculating | |
78 * all its data, for a model that is capable of calculating in a | |
79 * background thread. The default implementation is appropriate | |
80 * for a thread that does not background any work but carries out | |
81 * all its calculation from the constructor or accessors. | |
82 * | |
83 * If "completion" is non-NULL, this function should return | |
84 * through it an estimated percentage value showing how far | |
85 * through the background operation it thinks it is (for progress | |
86 * reporting). If it has no way to calculate progress, it may | |
87 * return the special value COMPLETION_UNKNOWN. | |
88 */ | |
89 virtual bool isReady(int *completion = 0) const { | |
90 bool ok = isOK(); | |
91 if (completion) *completion = (ok ? 100 : 0); | |
92 return ok; | |
93 } | |
94 static const int COMPLETION_UNKNOWN; | |
95 | |
96 virtual void toXml(QTextStream &stream, | |
97 QString indent = "", | |
98 QString extraAttributes = "") const; | |
99 | |
100 virtual QString toXmlString(QString indent = "", | |
101 QString extraAttributes = "") const; | |
102 | |
103 virtual QString toDelimitedDataString(QString) const { return ""; } | |
104 | |
105 signals: | |
106 /** | |
107 * Emitted when a model has been edited (or more data retrieved | |
108 * from cache, in the case of a cached model that generates slowly) | |
109 */ | |
110 void modelChanged(); | |
111 | |
112 /** | |
113 * Emitted when a model has been edited (or more data retrieved | |
114 * from cache, in the case of a cached model that generates slowly) | |
115 */ | |
116 void modelChanged(size_t startFrame, size_t endFrame); | |
117 | |
118 /** | |
119 * Emitted when some internal processing has advanced a stage, but | |
120 * the model has not changed externally. Views should respond by | |
121 * updating any progress meters or other monitoring, but not | |
122 * refreshing the actual view. | |
123 */ | |
124 void completionChanged(); | |
125 | |
126 protected: | |
127 Model() { } | |
128 | |
129 // Not provided. | |
130 Model(const Model &); | |
131 Model &operator=(const Model &); | |
132 }; | |
133 | |
134 #endif |