Chris@147: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@147: Chris@147: /* Chris@147: Sonic Visualiser Chris@147: An audio file viewer and annotation editor. Chris@147: Centre for Digital Music, Queen Mary, University of London. Chris@202: This file copyright 2006 Chris Cannam and QMUL. Chris@147: Chris@147: This program is free software; you can redistribute it and/or Chris@147: modify it under the terms of the GNU General Public License as Chris@147: published by the Free Software Foundation; either version 2 of the Chris@147: License, or (at your option) any later version. See the file Chris@147: COPYING included with this distribution for more information. Chris@147: */ Chris@147: Chris@147: #ifndef _WAVE_FILE_MODEL_H_ Chris@147: #define _WAVE_FILE_MODEL_H_ Chris@147: Chris@150: #include "base/Thread.h" Chris@147: #include Chris@147: #include Chris@147: Chris@147: #include "RangeSummarisableTimeValueModel.h" Chris@147: #include "PowerOfSqrtTwoZoomConstraint.h" Chris@147: Chris@147: #include Chris@147: Chris@147: class AudioFileReader; Chris@147: Chris@179: class WaveFileModel : public RangeSummarisableTimeValueModel Chris@147: { Chris@147: Q_OBJECT Chris@147: Chris@147: public: Chris@147: WaveFileModel(QString path); Chris@211: WaveFileModel(QString path, QString originalLocation); Chris@211: WaveFileModel(QString originalLocation, AudioFileReader *reader); Chris@147: ~WaveFileModel(); Chris@147: Chris@147: bool isOK() const; Chris@147: bool isReady(int *) const; Chris@147: Chris@179: const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; } Chris@179: Chris@147: size_t getFrameCount() const; Chris@147: size_t getChannelCount() const; Chris@147: size_t getSampleRate() const; Chris@147: Chris@147: virtual Model *clone() const; Chris@147: Chris@147: float getValueMinimum() const { return -1.0f; } Chris@147: float getValueMaximum() const { return 1.0f; } Chris@147: Chris@147: virtual size_t getStartFrame() const { return 0; } Chris@147: virtual size_t getEndFrame() const { return getFrameCount(); } Chris@147: Chris@147: virtual size_t getValues(int channel, size_t start, size_t end, Chris@147: float *buffer) const; Chris@147: Chris@147: virtual size_t getValues(int channel, size_t start, size_t end, Chris@147: double *buffer) const; Chris@147: Chris@225: virtual void getRanges(size_t channel, size_t start, size_t end, Chris@225: RangeBlock &ranges, Chris@225: size_t &blockSize) const; Chris@147: Chris@147: virtual Range getRange(size_t channel, size_t start, size_t end) const; Chris@147: Chris@163: virtual void toXml(QTextStream &out, Chris@163: QString indent = "", Chris@163: QString extraAttributes = "") const; Chris@163: Chris@147: virtual QString toXmlString(QString indent = "", Chris@147: QString extraAttributes = "") const; Chris@147: Chris@147: protected slots: Chris@147: void fillTimerTimedOut(); Chris@147: void cacheFilled(); Chris@147: Chris@147: protected: Chris@147: void initialize(); Chris@147: Chris@147: class RangeCacheFillThread : public Thread Chris@147: { Chris@147: public: Chris@147: RangeCacheFillThread(WaveFileModel &model) : Chris@175: m_model(model), m_fillExtent(0), Chris@175: m_frameCount(model.getFrameCount()) { } Chris@147: Chris@147: size_t getFillExtent() const { return m_fillExtent; } Chris@147: virtual void run(); Chris@147: Chris@147: protected: Chris@147: WaveFileModel &m_model; Chris@147: size_t m_fillExtent; Chris@175: size_t m_frameCount; Chris@147: }; Chris@147: Chris@147: void fillCache(); Chris@147: Chris@147: QString m_path; Chris@147: AudioFileReader *m_reader; Chris@175: bool m_myReader; Chris@147: Chris@147: RangeBlock m_cache[2]; // interleaved at two base resolutions Chris@147: mutable QMutex m_mutex; Chris@147: RangeCacheFillThread *m_fillThread; Chris@147: QTimer *m_updateTimer; Chris@147: size_t m_lastFillExtent; Chris@147: bool m_exiting; Chris@179: static PowerOfSqrtTwoZoomConstraint m_zoomConstraint; Chris@147: }; Chris@147: Chris@147: #endif