annotate data/model/Model.h @ 166:702fc936e6a6

* Pull transforms out of Layer menu (again) and into a separate Transforms menu * Add Recent Transforms submenu * Add effects and generators to the transforms menu (not yet implemented) as well as analysis plugins and data-from-effects (control output ports) * Add a nice dictionary-volume-style alphabetic subdivision of plugin names in plugins By Name menus
author Chris Cannam
date Fri, 22 Sep 2006 16:12:23 +0000
parents 4b2ea82fd0ed
children 0ed2b2e26b44
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@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@150 31 class Model : virtual 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@150 96 virtual void toXml(QTextStream &stream,
Chris@150 97 QString indent = "",
Chris@150 98 QString extraAttributes = "") const;
Chris@150 99
Chris@150 100 virtual QString toXmlString(QString indent = "",
Chris@150 101 QString extraAttributes = "") const;
Chris@150 102
Chris@150 103 virtual QString toDelimitedDataString(QString) const { return ""; }
Chris@150 104
Chris@150 105 signals:
Chris@150 106 /**
Chris@150 107 * Emitted when a model has been edited (or more data retrieved
Chris@150 108 * from cache, in the case of a cached model that generates slowly)
Chris@150 109 */
Chris@150 110 void modelChanged();
Chris@150 111
Chris@150 112 /**
Chris@150 113 * Emitted when a model has been edited (or more data retrieved
Chris@150 114 * from cache, in the case of a cached model that generates slowly)
Chris@150 115 */
Chris@150 116 void modelChanged(size_t startFrame, size_t endFrame);
Chris@150 117
Chris@150 118 /**
Chris@150 119 * Emitted when some internal processing has advanced a stage, but
Chris@150 120 * the model has not changed externally. Views should respond by
Chris@150 121 * updating any progress meters or other monitoring, but not
Chris@150 122 * refreshing the actual view.
Chris@150 123 */
Chris@150 124 void completionChanged();
Chris@150 125
Chris@150 126 protected:
Chris@150 127 Model() { }
Chris@150 128
Chris@150 129 // Not provided.
Chris@150 130 Model(const Model &);
Chris@150 131 Model &operator=(const Model &);
Chris@150 132 };
Chris@150 133
Chris@150 134 #endif