annotate data/model/Model.h @ 301:73537d900d4b

* Add MIDI file export (closes FR#1643721)
author Chris Cannam
date Thu, 04 Oct 2007 11:52:38 +0000
parents c022976d18e8
children 70a232b1f12a
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@290 24 typedef std::vector<float> SampleBlock;
Chris@290 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@297 63 * Return the frame rate of the underlying material, if the model
Chris@297 64 * itself has already been resampled.
Chris@297 65 */
Chris@297 66 virtual size_t getNativeRate() const { return getSampleRate(); }
Chris@297 67
Chris@297 68 /**
Chris@150 69 * Return a copy of this model.
Chris@150 70 *
Chris@150 71 * If the model is not editable, this may be effectively a shallow
Chris@150 72 * copy. If the model is editable, however, this operation must
Chris@150 73 * properly copy all of the model's editable data.
Chris@150 74 *
Chris@150 75 * In general this operation is not useful for non-editable dense
Chris@150 76 * models such as waveforms, because there may be no efficient
Chris@150 77 * copy operation implemented -- for such models it is better not
Chris@150 78 * to copy at all.
Chris@150 79 *
Chris@150 80 * Caller owns the returned value.
Chris@150 81 */
Chris@150 82 virtual Model *clone() const = 0;
Chris@150 83
Chris@150 84 /**
Chris@150 85 * Return true if the model has finished loading or calculating
Chris@150 86 * all its data, for a model that is capable of calculating in a
Chris@150 87 * background thread. The default implementation is appropriate
Chris@150 88 * for a thread that does not background any work but carries out
Chris@150 89 * all its calculation from the constructor or accessors.
Chris@150 90 *
Chris@150 91 * If "completion" is non-NULL, this function should return
Chris@150 92 * through it an estimated percentage value showing how far
Chris@150 93 * through the background operation it thinks it is (for progress
Chris@150 94 * reporting). If it has no way to calculate progress, it may
Chris@150 95 * return the special value COMPLETION_UNKNOWN.
Chris@150 96 */
Chris@150 97 virtual bool isReady(int *completion = 0) const {
Chris@150 98 bool ok = isOK();
Chris@150 99 if (completion) *completion = (ok ? 100 : 0);
Chris@150 100 return ok;
Chris@150 101 }
Chris@150 102 static const int COMPLETION_UNKNOWN;
Chris@150 103
Chris@179 104 /**
Chris@179 105 * If this model imposes a zoom constraint, i.e. some limit to the
Chris@179 106 * set of resolutions at which its data can meaningfully be
Chris@179 107 * displayed, then return it.
Chris@179 108 */
Chris@179 109 virtual const ZoomConstraint *getZoomConstraint() const {
Chris@179 110 return 0;
Chris@179 111 }
Chris@179 112
Chris@297 113 /**
Chris@297 114 * If this model was derived from another, return the model it was
Chris@297 115 * derived from. The assumption is that the source model's
Chris@297 116 * alignment will also apply to this model, unless some other
Chris@297 117 * property indicates otherwise.
Chris@297 118 */
Chris@297 119 virtual Model *getSourceModel() const {
Chris@297 120 return m_sourceModel;
Chris@297 121 }
Chris@297 122
Chris@297 123 /**
Chris@297 124 * Set the source model for this model.
Chris@297 125 */
Chris@297 126 //!!! No way to handle source model deletion &c yet
Chris@297 127 virtual void setSourceModel(Model *model) {
Chris@297 128 m_sourceModel = model;
Chris@297 129 }
Chris@297 130
Chris@150 131 virtual void toXml(QTextStream &stream,
Chris@150 132 QString indent = "",
Chris@150 133 QString extraAttributes = "") const;
Chris@150 134
Chris@150 135 virtual QString toXmlString(QString indent = "",
Chris@150 136 QString extraAttributes = "") const;
Chris@150 137
Chris@150 138 virtual QString toDelimitedDataString(QString) const { return ""; }
Chris@150 139
Chris@150 140 signals:
Chris@150 141 /**
Chris@150 142 * Emitted when a model has been edited (or more data retrieved
Chris@150 143 * from cache, in the case of a cached model that generates slowly)
Chris@150 144 */
Chris@150 145 void modelChanged();
Chris@150 146
Chris@150 147 /**
Chris@150 148 * Emitted when a model has been edited (or more data retrieved
Chris@150 149 * from cache, in the case of a cached model that generates slowly)
Chris@150 150 */
Chris@150 151 void modelChanged(size_t startFrame, size_t endFrame);
Chris@150 152
Chris@150 153 /**
Chris@150 154 * Emitted when some internal processing has advanced a stage, but
Chris@150 155 * the model has not changed externally. Views should respond by
Chris@150 156 * updating any progress meters or other monitoring, but not
Chris@150 157 * refreshing the actual view.
Chris@150 158 */
Chris@150 159 void completionChanged();
Chris@150 160
Chris@150 161 protected:
Chris@297 162 Model() : m_sourceModel(0) { }
Chris@150 163
Chris@150 164 // Not provided.
Chris@150 165 Model(const Model &);
Chris@150 166 Model &operator=(const Model &);
Chris@297 167
Chris@297 168 Model *m_sourceModel;
Chris@150 169 };
Chris@150 170
Chris@150 171 #endif