Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@52: This file copyright 2006 Chris Cannam. Chris@0: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: COPYING included with this distribution for more information. Chris@0: */ Chris@0: Chris@0: #ifndef _MODEL_H_ Chris@0: #define _MODEL_H_ Chris@0: Chris@0: #include Chris@0: #include Chris@0: Chris@3: #include "XmlExportable.h" Chris@3: Chris@0: typedef std::vector SampleBlock; Chris@0: Chris@0: /** Chris@0: * Model is the base class for all data models that represent any sort Chris@0: * of data on a time scale based on an audio frame rate. Chris@0: */ Chris@0: Chris@3: class Model : virtual public QObject, Chris@3: public XmlExportable Chris@0: { Chris@0: Q_OBJECT Chris@0: Chris@0: public: Chris@30: virtual ~Model(); Chris@30: Chris@0: /** Chris@0: * Return true if the model was constructed successfully. Classes Chris@0: * that refer to the model should always test this before use. Chris@0: */ Chris@0: virtual bool isOK() const = 0; Chris@0: Chris@0: /** Chris@0: * Return the first audio frame spanned by the model. Chris@0: */ Chris@0: virtual size_t getStartFrame() const = 0; Chris@0: Chris@0: /** Chris@0: * Return the last audio frame spanned by the model. Chris@0: */ Chris@0: virtual size_t getEndFrame() const = 0; Chris@0: Chris@0: /** Chris@0: * Return the frame rate in frames per second. Chris@0: */ Chris@0: virtual size_t getSampleRate() const = 0; Chris@0: Chris@0: /** Chris@0: * Return a copy of this model. Chris@0: * Chris@0: * If the model is not editable, this may be effectively a shallow Chris@0: * copy. If the model is editable, however, this operation must Chris@0: * properly copy all of the model's editable data. Chris@0: * Chris@0: * In general this operation is not useful for non-editable dense Chris@0: * models such as waveforms, because there may be no efficient Chris@0: * copy operation implemented -- for such models it is better not Chris@0: * to copy at all. Chris@0: * Chris@0: * Caller owns the returned value. Chris@0: */ Chris@0: virtual Model *clone() const = 0; Chris@0: Chris@0: /** Chris@0: * Return true if the model has finished loading or calculating Chris@0: * all its data, for a model that is capable of calculating in a Chris@0: * background thread. The default implementation is appropriate Chris@0: * for a thread that does not background any work but carries out Chris@0: * all its calculation from the constructor or accessors. Chris@0: * Chris@0: * If "completion" is non-NULL, this function should return Chris@0: * through it an estimated percentage value showing how far Chris@0: * through the background operation it thinks it is (for progress Chris@0: * reporting). If it has no way to calculate progress, it may Chris@0: * return the special value COMPLETION_UNKNOWN. Chris@0: */ Chris@0: virtual bool isReady(int *completion = 0) const { Chris@0: bool ok = isOK(); Chris@0: if (completion) *completion = (ok ? 100 : 0); Chris@0: return ok; Chris@0: } Chris@0: static const int COMPLETION_UNKNOWN; Chris@0: Chris@146: virtual void toXml(QTextStream &stream, Chris@146: QString indent = "", Chris@146: QString extraAttributes = "") const; Chris@146: Chris@3: virtual QString toXmlString(QString indent = "", Chris@3: QString extraAttributes = "") const; Chris@3: Chris@76: virtual QString toDelimitedDataString(QString) const { return ""; } Chris@76: Chris@0: signals: Chris@0: /** Chris@0: * Emitted when a model has been edited (or more data retrieved Chris@0: * from cache, in the case of a cached model that generates slowly) Chris@0: */ Chris@0: void modelChanged(); Chris@0: Chris@0: /** Chris@0: * Emitted when a model has been edited (or more data retrieved Chris@0: * from cache, in the case of a cached model that generates slowly) Chris@0: */ Chris@0: void modelChanged(size_t startFrame, size_t endFrame); Chris@0: Chris@0: /** Chris@0: * Emitted when some internal processing has advanced a stage, but Chris@0: * the model has not changed externally. Views should respond by Chris@0: * updating any progress meters or other monitoring, but not Chris@0: * refreshing the actual view. Chris@0: */ Chris@0: void completionChanged(); Chris@0: Chris@0: protected: Chris@0: Model() { } Chris@0: Chris@0: // Not provided. Chris@0: Model(const Model &); Chris@0: Model &operator=(const Model &); Chris@0: }; Chris@0: Chris@0: #endif