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