comparison data/model/WaveFileModel.h @ 1126:39019ce29178 tony-2.0-integration

Merge through to branch for Tony 2.0
author Chris Cannam
date Thu, 20 Aug 2015 14:54:21 +0100
parents efea94b04d5a
children 22fe34dd7f26
comparison
equal deleted inserted replaced
1119:e22bfe8ca248 1126:39019ce29178
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #ifndef _WAVE_FILE_MODEL_H_ 16 #ifndef WAVE_FILE_MODEL_H
17 #define _WAVE_FILE_MODEL_H_ 17 #define WAVE_FILE_MODEL_H
18
19 #include "base/Thread.h"
20 #include <QMutex>
21 #include <QTimer>
22
23 #include "data/fileio/FileSource.h"
24 18
25 #include "RangeSummarisableTimeValueModel.h" 19 #include "RangeSummarisableTimeValueModel.h"
26 #include "PowerOfSqrtTwoZoomConstraint.h"
27 20
28 #include <stdlib.h> 21 #include <stdlib.h>
29
30 class AudioFileReader;
31 22
32 class WaveFileModel : public RangeSummarisableTimeValueModel 23 class WaveFileModel : public RangeSummarisableTimeValueModel
33 { 24 {
34 Q_OBJECT 25 Q_OBJECT
35 26
36 public: 27 public:
37 WaveFileModel(FileSource source, sv_samplerate_t targetRate = 0); 28 virtual ~WaveFileModel();
38 WaveFileModel(FileSource source, AudioFileReader *reader);
39 ~WaveFileModel();
40 29
41 bool isOK() const; 30 virtual sv_frame_t getFrameCount() const = 0;
42 bool isReady(int *) const; 31 virtual int getChannelCount() const = 0;
32 virtual sv_samplerate_t getSampleRate() const = 0;
33 virtual sv_samplerate_t getNativeRate() const = 0;
43 34
44 const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; } 35 virtual QString getTitle() const = 0;
36 virtual QString getMaker() const = 0;
37 virtual QString getLocation() const = 0;
45 38
46 sv_frame_t getFrameCount() const; 39 virtual sv_frame_t getStartFrame() const = 0;
47 int getChannelCount() const; 40 virtual sv_frame_t getEndFrame() const = 0;
48 sv_samplerate_t getSampleRate() const;
49 sv_samplerate_t getNativeRate() const;
50 41
51 QString getTitle() const; 42 virtual void setStartFrame(sv_frame_t startFrame) = 0;
52 QString getMaker() const;
53 QString getLocation() const;
54 43
55 QString getLocalFilename() const;
56
57 float getValueMinimum() const { return -1.0f; }
58 float getValueMaximum() const { return 1.0f; }
59
60 virtual sv_frame_t getStartFrame() const { return m_startFrame; }
61 virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); }
62
63 void setStartFrame(sv_frame_t startFrame) { m_startFrame = startFrame; }
64
65 virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
66 float *buffer) const;
67
68 virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
69 double *buffer) const;
70
71 virtual sv_frame_t getData(int fromchannel, int tochannel,
72 sv_frame_t start, sv_frame_t count,
73 float **buffers) const;
74
75 virtual int getSummaryBlockSize(int desired) const;
76
77 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
78 RangeBlock &ranges,
79 int &blockSize) const;
80
81 virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const;
82
83 QString getTypeName() const { return tr("Wave File"); }
84
85 virtual void toXml(QTextStream &out,
86 QString indent = "",
87 QString extraAttributes = "") const;
88
89 protected slots:
90 void fillTimerTimedOut();
91 void cacheFilled();
92
93 protected: 44 protected:
94 void initialize(); 45 WaveFileModel() { } // only accessible from subclasses
95
96 class RangeCacheFillThread : public Thread
97 {
98 public:
99 RangeCacheFillThread(WaveFileModel &model) :
100 m_model(model), m_fillExtent(0),
101 m_frameCount(model.getFrameCount()) { }
102
103 sv_frame_t getFillExtent() const { return m_fillExtent; }
104 virtual void run();
105
106 protected:
107 WaveFileModel &m_model;
108 sv_frame_t m_fillExtent;
109 sv_frame_t m_frameCount;
110 };
111
112 void fillCache();
113
114 FileSource m_source;
115 QString m_path;
116 AudioFileReader *m_reader;
117 bool m_myReader;
118
119 sv_frame_t m_startFrame;
120
121 RangeBlock m_cache[2]; // interleaved at two base resolutions
122 mutable QMutex m_mutex;
123 RangeCacheFillThread *m_fillThread;
124 QTimer *m_updateTimer;
125 sv_frame_t m_lastFillExtent;
126 bool m_exiting;
127 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
128
129 mutable SampleBlock m_directRead;
130 mutable sv_frame_t m_lastDirectReadStart;
131 mutable sv_frame_t m_lastDirectReadCount;
132 mutable QMutex m_directReadMutex;
133 }; 46 };
134 47
135 #endif 48 #endif