annotate base/Model.h @ 30:a6ef94ecbe74

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