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