comparison data/model/WaveFileModel.h @ 1122:b9faee02afa5 recording

Make WritableWaveFileModel a true WaveFileModel (and ReadOnlyWaveFileModel the other sort of it). Enable recording from an empty session using that.
author Chris Cannam
date Wed, 19 Aug 2015 17:03:31 +0100
parents 9f4505ac9072
children efea94b04d5a
comparison
equal deleted inserted replaced
1117:020277bfafcb 1122:b9faee02afa5
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 getMultiChannelData(int fromchannel, int tochannel,
69 sv_frame_t start, sv_frame_t count,
70 float **buffers) const;
71
72 virtual int getSummaryBlockSize(int desired) const;
73
74 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
75 RangeBlock &ranges,
76 int &blockSize) const;
77
78 virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const;
79
80 QString getTypeName() const { return tr("Wave File"); }
81
82 virtual void toXml(QTextStream &out,
83 QString indent = "",
84 QString extraAttributes = "") const;
85
86 protected slots:
87 void fillTimerTimedOut();
88 void cacheFilled();
89
90 protected: 44 protected:
91 void initialize(); 45 WaveFileModel() { } // only accessible from subclasses
92
93 class RangeCacheFillThread : public Thread
94 {
95 public:
96 RangeCacheFillThread(WaveFileModel &model) :
97 m_model(model), m_fillExtent(0),
98 m_frameCount(model.getFrameCount()) { }
99
100 sv_frame_t getFillExtent() const { return m_fillExtent; }
101 virtual void run();
102
103 protected:
104 WaveFileModel &m_model;
105 sv_frame_t m_fillExtent;
106 sv_frame_t m_frameCount;
107 };
108
109 void fillCache();
110
111 FileSource m_source;
112 QString m_path;
113 AudioFileReader *m_reader;
114 bool m_myReader;
115
116 sv_frame_t m_startFrame;
117
118 RangeBlock m_cache[2]; // interleaved at two base resolutions
119 mutable QMutex m_mutex;
120 RangeCacheFillThread *m_fillThread;
121 QTimer *m_updateTimer;
122 sv_frame_t m_lastFillExtent;
123 bool m_exiting;
124 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
125
126 mutable SampleBlock m_directRead;
127 mutable sv_frame_t m_lastDirectReadStart;
128 mutable sv_frame_t m_lastDirectReadCount;
129 mutable QMutex m_directReadMutex;
130 }; 46 };
131 47
132 #endif 48 #endif