00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _WAVE_FILE_MODEL_H_
00017 #define _WAVE_FILE_MODEL_H_
00018
00019 #include "base/Thread.h"
00020 #include <QMutex>
00021 #include <QTimer>
00022
00023 #include "data/fileio/FileSource.h"
00024
00025 #include "RangeSummarisableTimeValueModel.h"
00026 #include "PowerOfSqrtTwoZoomConstraint.h"
00027
00028 #include <stdlib.h>
00029
00030 class AudioFileReader;
00031
00032 class WaveFileModel : public RangeSummarisableTimeValueModel
00033 {
00034 Q_OBJECT
00035
00036 public:
00037 WaveFileModel(FileSource source, size_t targetRate = 0);
00038 WaveFileModel(FileSource source, AudioFileReader *reader);
00039 ~WaveFileModel();
00040
00041 bool isOK() const;
00042 bool isReady(int *) const;
00043
00044 const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; }
00045
00046 size_t getFrameCount() const;
00047 size_t getChannelCount() const;
00048 size_t getSampleRate() const;
00049 size_t getNativeRate() const;
00050
00051 QString getTitle() const;
00052 QString getMaker() const;
00053 QString getLocation() const;
00054
00055 virtual Model *clone() const;
00056
00057 float getValueMinimum() const { return -1.0f; }
00058 float getValueMaximum() const { return 1.0f; }
00059
00060 virtual size_t getStartFrame() const { return m_startFrame; }
00061 virtual size_t getEndFrame() const { return m_startFrame + getFrameCount(); }
00062
00063 void setStartFrame(size_t startFrame) { m_startFrame = startFrame; }
00064
00065 virtual size_t getData(int channel, size_t start, size_t count,
00066 float *buffer) const;
00067
00068 virtual size_t getData(int channel, size_t start, size_t count,
00069 double *buffer) const;
00070
00071 virtual size_t getData(size_t fromchannel, size_t tochannel,
00072 size_t start, size_t count,
00073 float **buffers) const;
00074
00075 virtual size_t getSummaryBlockSize(size_t desired) const;
00076
00077 virtual void getSummaries(size_t channel, size_t start, size_t count,
00078 RangeBlock &ranges,
00079 size_t &blockSize) const;
00080
00081 virtual Range getSummary(size_t channel, size_t start, size_t count) const;
00082
00083 QString getTypeName() const { return tr("Wave File"); }
00084
00085 virtual void toXml(QTextStream &out,
00086 QString indent = "",
00087 QString extraAttributes = "") const;
00088
00089 signals:
00090 void modelChanged();
00091 void modelChanged(size_t, size_t);
00092 void completionChanged();
00093
00094 protected slots:
00095 void fillTimerTimedOut();
00096 void cacheFilled();
00097
00098 protected:
00099 void initialize();
00100
00101 class RangeCacheFillThread : public Thread
00102 {
00103 public:
00104 RangeCacheFillThread(WaveFileModel &model) :
00105 m_model(model), m_fillExtent(0),
00106 m_frameCount(model.getFrameCount()) { }
00107
00108 size_t getFillExtent() const { return m_fillExtent; }
00109 virtual void run();
00110
00111 protected:
00112 WaveFileModel &m_model;
00113 size_t m_fillExtent;
00114 size_t m_frameCount;
00115 };
00116
00117 void fillCache();
00118
00119 FileSource m_source;
00120 QString m_path;
00121 AudioFileReader *m_reader;
00122 bool m_myReader;
00123
00124 size_t m_startFrame;
00125
00126 RangeBlock m_cache[2];
00127 mutable QMutex m_mutex;
00128 RangeCacheFillThread *m_fillThread;
00129 QTimer *m_updateTimer;
00130 size_t m_lastFillExtent;
00131 bool m_exiting;
00132 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
00133
00134 mutable SampleBlock m_directRead;
00135 mutable size_t m_lastDirectReadStart;
00136 mutable size_t m_lastDirectReadCount;
00137 mutable QMutex m_directReadMutex;
00138 };
00139
00140 #endif