annotate data/model/Model.h @ 289:3020904de772

* Layer tree view updating when visibility / audibility changed (and layers updating when they are changed in view) -- still some problems when a model is loaded while the tree is visible * FFTW_MEASURE throughout -- it does turn out to make an appreciable difference sometimes
author Chris Cannam
date Thu, 16 Aug 2007 16:47:07 +0000
parents 20028c634494
children 92e8dbde73cd
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@179 24 class ZoomConstraint;
Chris@179 25
Chris@150 26 /**
Chris@150 27 * Model is the base class for all data models that represent any sort
Chris@150 28 * of data on a time scale based on an audio frame rate.
Chris@150 29 */
Chris@150 30
Chris@179 31 class Model : public QObject,
Chris@150 32 public XmlExportable
Chris@150 33 {
Chris@150 34 Q_OBJECT
Chris@150 35
Chris@150 36 public:
Chris@150 37 virtual ~Model();
Chris@150 38
Chris@150 39 /**
Chris@150 40 * Return true if the model was constructed successfully. Classes
Chris@150 41 * that refer to the model should always test this before use.
Chris@150 42 */
Chris@150 43 virtual bool isOK() const = 0;
Chris@150 44
Chris@150 45 /**
Chris@150 46 * Return the first audio frame spanned by the model.
Chris@150 47 */
Chris@150 48 virtual size_t getStartFrame() const = 0;
Chris@150 49
Chris@150 50 /**
Chris@150 51 * Return the last audio frame spanned by the model.
Chris@150 52 */
Chris@150 53 virtual size_t getEndFrame() const = 0;
Chris@150 54
Chris@150 55 /**
Chris@150 56 * Return the frame rate in frames per second.
Chris@150 57 */
Chris@150 58 virtual size_t getSampleRate() const = 0;
Chris@150 59
Chris@150 60 /**
Chris@150 61 * Return a copy of this model.
Chris@150 62 *
Chris@150 63 * If the model is not editable, this may be effectively a shallow
Chris@150 64 * copy. If the model is editable, however, this operation must
Chris@150 65 * properly copy all of the model's editable data.
Chris@150 66 *
Chris@150 67 * In general this operation is not useful for non-editable dense
Chris@150 68 * models such as waveforms, because there may be no efficient
Chris@150 69 * copy operation implemented -- for such models it is better not
Chris@150 70 * to copy at all.
Chris@150 71 *
Chris@150 72 * Caller owns the returned value.
Chris@150 73 */
Chris@150 74 virtual Model *clone() const = 0;
Chris@150 75
Chris@150 76 /**
Chris@150 77 * Return true if the model has finished loading or calculating
Chris@150 78 * all its data, for a model that is capable of calculating in a
Chris@150 79 * background thread. The default implementation is appropriate
Chris@150 80 * for a thread that does not background any work but carries out
Chris@150 81 * all its calculation from the constructor or accessors.
Chris@150 82 *
Chris@150 83 * If "completion" is non-NULL, this function should return
Chris@150 84 * through it an estimated percentage value showing how far
Chris@150 85 * through the background operation it thinks it is (for progress
Chris@150 86 * reporting). If it has no way to calculate progress, it may
Chris@150 87 * return the special value COMPLETION_UNKNOWN.
Chris@150 88 */
Chris@150 89 virtual bool isReady(int *completion = 0) const {
Chris@150 90 bool ok = isOK();
Chris@150 91 if (completion) *completion = (ok ? 100 : 0);
Chris@150 92 return ok;
Chris@150 93 }
Chris@150 94 static const int COMPLETION_UNKNOWN;
Chris@150 95
Chris@179 96 /**
Chris@179 97 * If this model imposes a zoom constraint, i.e. some limit to the
Chris@179 98 * set of resolutions at which its data can meaningfully be
Chris@179 99 * displayed, then return it.
Chris@179 100 */
Chris@179 101 virtual const ZoomConstraint *getZoomConstraint() const {
Chris@179 102 return 0;
Chris@179 103 }
Chris@179 104
Chris@150 105 virtual void toXml(QTextStream &stream,
Chris@150 106 QString indent = "",
Chris@150 107 QString extraAttributes = "") const;
Chris@150 108
Chris@150 109 virtual QString toXmlString(QString indent = "",
Chris@150 110 QString extraAttributes = "") const;
Chris@150 111
Chris@150 112 virtual QString toDelimitedDataString(QString) const { return ""; }
Chris@150 113
Chris@150 114 signals:
Chris@150 115 /**
Chris@150 116 * Emitted when a model has been edited (or more data retrieved
Chris@150 117 * from cache, in the case of a cached model that generates slowly)
Chris@150 118 */
Chris@150 119 void modelChanged();
Chris@150 120
Chris@150 121 /**
Chris@150 122 * Emitted when a model has been edited (or more data retrieved
Chris@150 123 * from cache, in the case of a cached model that generates slowly)
Chris@150 124 */
Chris@150 125 void modelChanged(size_t startFrame, size_t endFrame);
Chris@150 126
Chris@150 127 /**
Chris@150 128 * Emitted when some internal processing has advanced a stage, but
Chris@150 129 * the model has not changed externally. Views should respond by
Chris@150 130 * updating any progress meters or other monitoring, but not
Chris@150 131 * refreshing the actual view.
Chris@150 132 */
Chris@150 133 void completionChanged();
Chris@150 134
Chris@150 135 protected:
Chris@150 136 Model() { }
Chris@150 137
Chris@150 138 // Not provided.
Chris@150 139 Model(const Model &);
Chris@150 140 Model &operator=(const Model &);
Chris@150 141 };
Chris@150 142
Chris@150 143 #endif