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