svcore
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam and QMUL. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 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, int 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 int getFrameCount() const; 00047 int getChannelCount() const; 00048 int getSampleRate() const; 00049 int 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 int getStartFrame() const { return m_startFrame; } 00061 virtual int getEndFrame() const { return m_startFrame + getFrameCount(); } 00062 00063 void setStartFrame(int startFrame) { m_startFrame = startFrame; } 00064 00065 virtual int getData(int channel, int start, int count, 00066 float *buffer) const; 00067 00068 virtual int getData(int channel, int start, int count, 00069 double *buffer) const; 00070 00071 virtual int getData(int fromchannel, int tochannel, 00072 int start, int count, 00073 float **buffers) const; 00074 00075 virtual int getSummaryBlockSize(int desired) const; 00076 00077 virtual void getSummaries(int channel, int start, int count, 00078 RangeBlock &ranges, 00079 int &blockSize) const; 00080 00081 virtual Range getSummary(int channel, int start, int 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 protected slots: 00090 void fillTimerTimedOut(); 00091 void cacheFilled(); 00092 00093 protected: 00094 void initialize(); 00095 00096 class RangeCacheFillThread : public Thread 00097 { 00098 public: 00099 RangeCacheFillThread(WaveFileModel &model) : 00100 m_model(model), m_fillExtent(0), 00101 m_frameCount(model.getFrameCount()) { } 00102 00103 int getFillExtent() const { return m_fillExtent; } 00104 virtual void run(); 00105 00106 protected: 00107 WaveFileModel &m_model; 00108 int m_fillExtent; 00109 int m_frameCount; 00110 }; 00111 00112 void fillCache(); 00113 00114 FileSource m_source; 00115 QString m_path; 00116 AudioFileReader *m_reader; 00117 bool m_myReader; 00118 00119 int m_startFrame; 00120 00121 RangeBlock m_cache[2]; // interleaved at two base resolutions 00122 mutable QMutex m_mutex; 00123 RangeCacheFillThread *m_fillThread; 00124 QTimer *m_updateTimer; 00125 int m_lastFillExtent; 00126 bool m_exiting; 00127 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint; 00128 00129 mutable SampleBlock m_directRead; 00130 mutable int m_lastDirectReadStart; 00131 mutable int m_lastDirectReadCount; 00132 mutable QMutex m_directReadMutex; 00133 }; 00134 00135 #endif