Mercurial > hg > svcore
comparison base/Model.h @ 0:da6937383da8
initial import
author | Chris Cannam |
---|---|
date | Tue, 10 Jan 2006 16:33:16 +0000 |
parents | |
children | d86891498eef |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:da6937383da8 |
---|---|
1 /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 A waveform viewer and audio annotation editor. | |
5 Chris Cannam, Queen Mary University of London, 2005 | |
6 | |
7 This is experimental software. Not for distribution. | |
8 */ | |
9 | |
10 #ifndef _MODEL_H_ | |
11 #define _MODEL_H_ | |
12 | |
13 #include <vector> | |
14 #include <QObject> | |
15 | |
16 typedef std::vector<float> SampleBlock; | |
17 | |
18 /** | |
19 * Model is the base class for all data models that represent any sort | |
20 * of data on a time scale based on an audio frame rate. | |
21 */ | |
22 | |
23 class Model : virtual public QObject | |
24 { | |
25 Q_OBJECT | |
26 | |
27 public: | |
28 /** | |
29 * Return true if the model was constructed successfully. Classes | |
30 * that refer to the model should always test this before use. | |
31 */ | |
32 virtual bool isOK() const = 0; | |
33 | |
34 /** | |
35 * Return the first audio frame spanned by the model. | |
36 */ | |
37 virtual size_t getStartFrame() const = 0; | |
38 | |
39 /** | |
40 * Return the last audio frame spanned by the model. | |
41 */ | |
42 virtual size_t getEndFrame() const = 0; | |
43 | |
44 /** | |
45 * Return the frame rate in frames per second. | |
46 */ | |
47 virtual size_t getSampleRate() const = 0; | |
48 | |
49 /** | |
50 * Return a copy of this model. | |
51 * | |
52 * If the model is not editable, this may be effectively a shallow | |
53 * copy. If the model is editable, however, this operation must | |
54 * properly copy all of the model's editable data. | |
55 * | |
56 * In general this operation is not useful for non-editable dense | |
57 * models such as waveforms, because there may be no efficient | |
58 * copy operation implemented -- for such models it is better not | |
59 * to copy at all. | |
60 * | |
61 * Caller owns the returned value. | |
62 */ | |
63 virtual Model *clone() const = 0; | |
64 | |
65 /** | |
66 * Return true if the model has finished loading or calculating | |
67 * all its data, for a model that is capable of calculating in a | |
68 * background thread. The default implementation is appropriate | |
69 * for a thread that does not background any work but carries out | |
70 * all its calculation from the constructor or accessors. | |
71 * | |
72 * If "completion" is non-NULL, this function should return | |
73 * through it an estimated percentage value showing how far | |
74 * through the background operation it thinks it is (for progress | |
75 * reporting). If it has no way to calculate progress, it may | |
76 * return the special value COMPLETION_UNKNOWN. | |
77 */ | |
78 virtual bool isReady(int *completion = 0) const { | |
79 bool ok = isOK(); | |
80 if (completion) *completion = (ok ? 100 : 0); | |
81 return ok; | |
82 } | |
83 static const int COMPLETION_UNKNOWN; | |
84 | |
85 signals: | |
86 /** | |
87 * Emitted when a model has been edited (or more data retrieved | |
88 * from cache, in the case of a cached model that generates slowly) | |
89 */ | |
90 void modelChanged(); | |
91 | |
92 /** | |
93 * Emitted when a model has been edited (or more data retrieved | |
94 * from cache, in the case of a cached model that generates slowly) | |
95 */ | |
96 void modelChanged(size_t startFrame, size_t endFrame); | |
97 | |
98 /** | |
99 * Emitted when some internal processing has advanced a stage, but | |
100 * the model has not changed externally. Views should respond by | |
101 * updating any progress meters or other monitoring, but not | |
102 * refreshing the actual view. | |
103 */ | |
104 void completionChanged(); | |
105 | |
106 protected: | |
107 Model() { } | |
108 | |
109 // Not provided. | |
110 Model(const Model &); | |
111 Model &operator=(const Model &); | |
112 }; | |
113 | |
114 #endif |