annotate base/Model.h @ 0:da6937383da8

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