comparison data/model/ReadOnlyWaveFileModel.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 data/model/WaveFileModel.h@9f4505ac9072
children efea94b04d5a
comparison
equal deleted inserted replaced
1117:020277bfafcb 1122:b9faee02afa5
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7 This file copyright 2006 Chris Cannam and QMUL.
8
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information.
14 */
15
16 #ifndef READ_ONLY_WAVE_FILE_MODEL_H
17 #define READ_ONLY_WAVE_FILE_MODEL_H
18
19 #include "WaveFileModel.h"
20
21 #include "base/Thread.h"
22 #include <QMutex>
23 #include <QTimer>
24
25 #include "data/fileio/FileSource.h"
26
27 #include "RangeSummarisableTimeValueModel.h"
28 #include "PowerOfSqrtTwoZoomConstraint.h"
29
30 #include <stdlib.h>
31
32 class AudioFileReader;
33
34 class ReadOnlyWaveFileModel : public WaveFileModel
35 {
36 Q_OBJECT
37
38 public:
39 ReadOnlyWaveFileModel(FileSource source, sv_samplerate_t targetRate = 0);
40 ReadOnlyWaveFileModel(FileSource source, AudioFileReader *reader);
41 ~ReadOnlyWaveFileModel();
42
43 bool isOK() const;
44 bool isReady(int *) const;
45
46 const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; }
47
48 sv_frame_t getFrameCount() const;
49 int getChannelCount() const;
50 sv_samplerate_t getSampleRate() const;
51 sv_samplerate_t getNativeRate() const;
52
53 QString getTitle() const;
54 QString getMaker() const;
55 QString getLocation() const;
56
57 QString getLocalFilename() const;
58
59 float getValueMinimum() const { return -1.0f; }
60 float getValueMaximum() const { return 1.0f; }
61
62 virtual sv_frame_t getStartFrame() const { return m_startFrame; }
63 virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); }
64
65 void setStartFrame(sv_frame_t startFrame) { m_startFrame = startFrame; }
66
67 virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count,
68 float *buffer) const;
69
70 virtual sv_frame_t getMultiChannelData(int fromchannel, int tochannel,
71 sv_frame_t start, sv_frame_t count,
72 float **buffers) const;
73
74 virtual int getSummaryBlockSize(int desired) const;
75
76 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
77 RangeBlock &ranges,
78 int &blockSize) const;
79
80 virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const;
81
82 QString getTypeName() const { return tr("Wave File"); }
83
84 virtual void toXml(QTextStream &out,
85 QString indent = "",
86 QString extraAttributes = "") const;
87
88 protected slots:
89 void fillTimerTimedOut();
90 void cacheFilled();
91
92 protected:
93 void initialize();
94
95 class RangeCacheFillThread : public Thread
96 {
97 public:
98 RangeCacheFillThread(ReadOnlyWaveFileModel &model) :
99 m_model(model), m_fillExtent(0),
100 m_frameCount(model.getFrameCount()) { }
101
102 sv_frame_t getFillExtent() const { return m_fillExtent; }
103 virtual void run();
104
105 protected:
106 ReadOnlyWaveFileModel &m_model;
107 sv_frame_t m_fillExtent;
108 sv_frame_t m_frameCount;
109 };
110
111 void fillCache();
112
113 FileSource m_source;
114 QString m_path;
115 AudioFileReader *m_reader;
116 bool m_myReader;
117
118 sv_frame_t m_startFrame;
119
120 RangeBlock m_cache[2]; // interleaved at two base resolutions
121 mutable QMutex m_mutex;
122 RangeCacheFillThread *m_fillThread;
123 QTimer *m_updateTimer;
124 sv_frame_t m_lastFillExtent;
125 bool m_exiting;
126 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
127
128 mutable SampleBlock m_directRead;
129 mutable sv_frame_t m_lastDirectReadStart;
130 mutable sv_frame_t m_lastDirectReadCount;
131 mutable QMutex m_directReadMutex;
132 };
133
134 #endif