annotate data/model/Model.h @ 191:86766fef5467

* Fix slowness in serving FFT values to feature extraction plugin transform (failure to call resume() on FFT model) * Fix failure to update completion from time/value model
author Chris Cannam
date Tue, 17 Oct 2006 13:49:31 +0000
parents 0ed2b2e26b44
children 20028c634494
rev   line source
Chris@150 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@150 2
Chris@150 3 /*
Chris@150 4 Sonic Visualiser
Chris@150 5 An audio file viewer and annotation editor.
Chris@150 6 Centre for Digital Music, Queen Mary, University of London.
Chris@150 7 This file copyright 2006 Chris Cannam.
Chris@150 8
Chris@150 9 This program is free software; you can redistribute it and/or
Chris@150 10 modify it under the terms of the GNU General Public License as
Chris@150 11 published by the Free Software Foundation; either version 2 of the
Chris@150 12 License, or (at your option) any later version. See the file
Chris@150 13 COPYING included with this distribution for more information.
Chris@150 14 */
Chris@150 15
Chris@150 16 #ifndef _MODEL_H_
Chris@150 17 #define _MODEL_H_
Chris@150 18
Chris@150 19 #include <vector>
Chris@150 20 #include <QObject>
Chris@150 21
Chris@150 22 #include "base/XmlExportable.h"
Chris@150 23
Chris@150 24 typedef std::vector<float> SampleBlock;
Chris@150 25
Chris@179 26 class ZoomConstraint;
Chris@179 27
Chris@150 28 /**
Chris@150 29 * Model is the base class for all data models that represent any sort
Chris@150 30 * of data on a time scale based on an audio frame rate.
Chris@150 31 */
Chris@150 32
Chris@179 33 class Model : public QObject,
Chris@150 34 public XmlExportable
Chris@150 35 {
Chris@150 36 Q_OBJECT
Chris@150 37
Chris@150 38 public:
Chris@150 39 virtual ~Model();
Chris@150 40
Chris@150 41 /**
Chris@150 42 * Return true if the model was constructed successfully. Classes
Chris@150 43 * that refer to the model should always test this before use.
Chris@150 44 */
Chris@150 45 virtual bool isOK() const = 0;
Chris@150 46
Chris@150 47 /**
Chris@150 48 * Return the first audio frame spanned by the model.
Chris@150 49 */
Chris@150 50 virtual size_t getStartFrame() const = 0;
Chris@150 51
Chris@150 52 /**
Chris@150 53 * Return the last audio frame spanned by the model.
Chris@150 54 */
Chris@150 55 virtual size_t getEndFrame() const = 0;
Chris@150 56
Chris@150 57 /**
Chris@150 58 * Return the frame rate in frames per second.
Chris@150 59 */
Chris@150 60 virtual size_t getSampleRate() const = 0;
Chris@150 61
Chris@150 62 /**
Chris@150 63 * Return a copy of this model.
Chris@150 64 *
Chris@150 65 * If the model is not editable, this may be effectively a shallow
Chris@150 66 * copy. If the model is editable, however, this operation must
Chris@150 67 * properly copy all of the model's editable data.
Chris@150 68 *
Chris@150 69 * In general this operation is not useful for non-editable dense
Chris@150 70 * models such as waveforms, because there may be no efficient
Chris@150 71 * copy operation implemented -- for such models it is better not
Chris@150 72 * to copy at all.
Chris@150 73 *
Chris@150 74 * Caller owns the returned value.
Chris@150 75 */
Chris@150 76 virtual Model *clone() const = 0;
Chris@150 77
Chris@150 78 /**
Chris@150 79 * Return true if the model has finished loading or calculating
Chris@150 80 * all its data, for a model that is capable of calculating in a
Chris@150 81 * background thread. The default implementation is appropriate
Chris@150 82 * for a thread that does not background any work but carries out
Chris@150 83 * all its calculation from the constructor or accessors.
Chris@150 84 *
Chris@150 85 * If "completion" is non-NULL, this function should return
Chris@150 86 * through it an estimated percentage value showing how far
Chris@150 87 * through the background operation it thinks it is (for progress
Chris@150 88 * reporting). If it has no way to calculate progress, it may
Chris@150 89 * return the special value COMPLETION_UNKNOWN.
Chris@150 90 */
Chris@150 91 virtual bool isReady(int *completion = 0) const {
Chris@150 92 bool ok = isOK();
Chris@150 93 if (completion) *completion = (ok ? 100 : 0);
Chris@150 94 return ok;
Chris@150 95 }
Chris@150 96 static const int COMPLETION_UNKNOWN;
Chris@150 97
Chris@179 98 /**
Chris@179 99 * If this model imposes a zoom constraint, i.e. some limit to the
Chris@179 100 * set of resolutions at which its data can meaningfully be
Chris@179 101 * displayed, then return it.
Chris@179 102 */
Chris@179 103 virtual const ZoomConstraint *getZoomConstraint() const {
Chris@179 104 return 0;
Chris@179 105 }
Chris@179 106
Chris@150 107 virtual void toXml(QTextStream &stream,
Chris@150 108 QString indent = "",
Chris@150 109 QString extraAttributes = "") const;
Chris@150 110
Chris@150 111 virtual QString toXmlString(QString indent = "",
Chris@150 112 QString extraAttributes = "") const;
Chris@150 113
Chris@150 114 virtual QString toDelimitedDataString(QString) const { return ""; }
Chris@150 115
Chris@150 116 signals:
Chris@150 117 /**
Chris@150 118 * Emitted when a model has been edited (or more data retrieved
Chris@150 119 * from cache, in the case of a cached model that generates slowly)
Chris@150 120 */
Chris@150 121 void modelChanged();
Chris@150 122
Chris@150 123 /**
Chris@150 124 * Emitted when a model has been edited (or more data retrieved
Chris@150 125 * from cache, in the case of a cached model that generates slowly)
Chris@150 126 */
Chris@150 127 void modelChanged(size_t startFrame, size_t endFrame);
Chris@150 128
Chris@150 129 /**
Chris@150 130 * Emitted when some internal processing has advanced a stage, but
Chris@150 131 * the model has not changed externally. Views should respond by
Chris@150 132 * updating any progress meters or other monitoring, but not
Chris@150 133 * refreshing the actual view.
Chris@150 134 */
Chris@150 135 void completionChanged();
Chris@150 136
Chris@150 137 protected:
Chris@150 138 Model() { }
Chris@150 139
Chris@150 140 // Not provided.
Chris@150 141 Model(const Model &);
Chris@150 142 Model &operator=(const Model &);
Chris@150 143 };
Chris@150 144
Chris@150 145 #endif