annotate base/Model.h @ 5:31c4ed2d5da6

* Hook up SV file i/o. You can now save and load sessions. Some problems -- gain is not reloaded correctly for waveforms, reloaded panes are not properly reconnected to the panner, and no doubt plenty of others.
author Chris Cannam
date Tue, 17 Jan 2006 17:45:55 +0000
parents 581f67f370f3
children a6ef94ecbe74
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@0 31 /**
Chris@0 32 * Return true if the model was constructed successfully. Classes
Chris@0 33 * that refer to the model should always test this before use.
Chris@0 34 */
Chris@0 35 virtual bool isOK() const = 0;
Chris@0 36
Chris@0 37 /**
Chris@0 38 * Return the first audio frame spanned by the model.
Chris@0 39 */
Chris@0 40 virtual size_t getStartFrame() const = 0;
Chris@0 41
Chris@0 42 /**
Chris@0 43 * Return the last audio frame spanned by the model.
Chris@0 44 */
Chris@0 45 virtual size_t getEndFrame() const = 0;
Chris@0 46
Chris@0 47 /**
Chris@0 48 * Return the frame rate in frames per second.
Chris@0 49 */
Chris@0 50 virtual size_t getSampleRate() const = 0;
Chris@0 51
Chris@0 52 /**
Chris@0 53 * Return a copy of this model.
Chris@0 54 *
Chris@0 55 * If the model is not editable, this may be effectively a shallow
Chris@0 56 * copy. If the model is editable, however, this operation must
Chris@0 57 * properly copy all of the model's editable data.
Chris@0 58 *
Chris@0 59 * In general this operation is not useful for non-editable dense
Chris@0 60 * models such as waveforms, because there may be no efficient
Chris@0 61 * copy operation implemented -- for such models it is better not
Chris@0 62 * to copy at all.
Chris@0 63 *
Chris@0 64 * Caller owns the returned value.
Chris@0 65 */
Chris@0 66 virtual Model *clone() const = 0;
Chris@0 67
Chris@0 68 /**
Chris@0 69 * Return true if the model has finished loading or calculating
Chris@0 70 * all its data, for a model that is capable of calculating in a
Chris@0 71 * background thread. The default implementation is appropriate
Chris@0 72 * for a thread that does not background any work but carries out
Chris@0 73 * all its calculation from the constructor or accessors.
Chris@0 74 *
Chris@0 75 * If "completion" is non-NULL, this function should return
Chris@0 76 * through it an estimated percentage value showing how far
Chris@0 77 * through the background operation it thinks it is (for progress
Chris@0 78 * reporting). If it has no way to calculate progress, it may
Chris@0 79 * return the special value COMPLETION_UNKNOWN.
Chris@0 80 */
Chris@0 81 virtual bool isReady(int *completion = 0) const {
Chris@0 82 bool ok = isOK();
Chris@0 83 if (completion) *completion = (ok ? 100 : 0);
Chris@0 84 return ok;
Chris@0 85 }
Chris@0 86 static const int COMPLETION_UNKNOWN;
Chris@0 87
Chris@3 88 virtual QString toXmlString(QString indent = "",
Chris@3 89 QString extraAttributes = "") const;
Chris@3 90
Chris@0 91 signals:
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();
Chris@0 97
Chris@0 98 /**
Chris@0 99 * Emitted when a model has been edited (or more data retrieved
Chris@0 100 * from cache, in the case of a cached model that generates slowly)
Chris@0 101 */
Chris@0 102 void modelChanged(size_t startFrame, size_t endFrame);
Chris@0 103
Chris@0 104 /**
Chris@0 105 * Emitted when some internal processing has advanced a stage, but
Chris@0 106 * the model has not changed externally. Views should respond by
Chris@0 107 * updating any progress meters or other monitoring, but not
Chris@0 108 * refreshing the actual view.
Chris@0 109 */
Chris@0 110 void completionChanged();
Chris@0 111
Chris@0 112 protected:
Chris@0 113 Model() { }
Chris@0 114
Chris@0 115 // Not provided.
Chris@0 116 Model(const Model &);
Chris@0 117 Model &operator=(const Model &);
Chris@0 118 };
Chris@0 119
Chris@0 120 #endif