Mercurial > hg > svcore
comparison data/model/WaveFileModel.h @ 1124:efea94b04d5a 3.0-integration
Merge from branch recording
author | Chris Cannam |
---|---|
date | Thu, 20 Aug 2015 13:15:19 +0100 |
parents | 4d9816ba0ebe b9faee02afa5 |
children | 22fe34dd7f26 |
comparison
equal
deleted
inserted
replaced
1118:fbc43d5dc3d1 | 1124:efea94b04d5a |
---|---|
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 std::vector<float> getData(int channel, sv_frame_t start, sv_frame_t count) const; | |
66 | |
67 virtual std::vector<std::vector<float>> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; | |
68 | |
69 virtual int getSummaryBlockSize(int desired) const; | |
70 | |
71 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count, | |
72 RangeBlock &ranges, | |
73 int &blockSize) const; | |
74 | |
75 virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const; | |
76 | |
77 QString getTypeName() const { return tr("Wave File"); } | |
78 | |
79 virtual void toXml(QTextStream &out, | |
80 QString indent = "", | |
81 QString extraAttributes = "") const; | |
82 | |
83 protected slots: | |
84 void fillTimerTimedOut(); | |
85 void cacheFilled(); | |
86 | |
87 protected: | 44 protected: |
88 void initialize(); | 45 WaveFileModel() { } // only accessible from subclasses |
89 | |
90 class RangeCacheFillThread : public Thread | |
91 { | |
92 public: | |
93 RangeCacheFillThread(WaveFileModel &model) : | |
94 m_model(model), m_fillExtent(0), | |
95 m_frameCount(model.getFrameCount()) { } | |
96 | |
97 sv_frame_t getFillExtent() const { return m_fillExtent; } | |
98 virtual void run(); | |
99 | |
100 protected: | |
101 WaveFileModel &m_model; | |
102 sv_frame_t m_fillExtent; | |
103 sv_frame_t m_frameCount; | |
104 }; | |
105 | |
106 void fillCache(); | |
107 | |
108 FileSource m_source; | |
109 QString m_path; | |
110 AudioFileReader *m_reader; | |
111 bool m_myReader; | |
112 | |
113 sv_frame_t m_startFrame; | |
114 | |
115 RangeBlock m_cache[2]; // interleaved at two base resolutions | |
116 mutable QMutex m_mutex; | |
117 RangeCacheFillThread *m_fillThread; | |
118 QTimer *m_updateTimer; | |
119 sv_frame_t m_lastFillExtent; | |
120 bool m_exiting; | |
121 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint; | |
122 | |
123 mutable std::vector<float> m_directRead; | |
124 mutable sv_frame_t m_lastDirectReadStart; | |
125 mutable sv_frame_t m_lastDirectReadCount; | |
126 mutable QMutex m_directReadMutex; | |
127 }; | 46 }; |
128 | 47 |
129 #endif | 48 #endif |