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@147
|
16 #ifndef _WAVE_FILE_MODEL_H_
|
Chris@147
|
17 #define _WAVE_FILE_MODEL_H_
|
Chris@147
|
18
|
Chris@150
|
19 #include "base/Thread.h"
|
Chris@147
|
20 #include <QMutex>
|
Chris@147
|
21 #include <QTimer>
|
Chris@147
|
22
|
Chris@316
|
23 #include "data/fileio/RemoteFile.h"
|
Chris@316
|
24
|
Chris@147
|
25 #include "RangeSummarisableTimeValueModel.h"
|
Chris@147
|
26 #include "PowerOfSqrtTwoZoomConstraint.h"
|
Chris@147
|
27
|
Chris@147
|
28 #include <stdlib.h>
|
Chris@147
|
29
|
Chris@147
|
30 class AudioFileReader;
|
Chris@147
|
31
|
Chris@179
|
32 class WaveFileModel : public RangeSummarisableTimeValueModel
|
Chris@147
|
33 {
|
Chris@147
|
34 Q_OBJECT
|
Chris@147
|
35
|
Chris@147
|
36 public:
|
Chris@316
|
37 WaveFileModel(RemoteFile source, size_t targetRate = 0);
|
Chris@316
|
38 WaveFileModel(RemoteFile source, AudioFileReader *reader);
|
Chris@147
|
39 ~WaveFileModel();
|
Chris@147
|
40
|
Chris@147
|
41 bool isOK() const;
|
Chris@147
|
42 bool isReady(int *) const;
|
Chris@147
|
43
|
Chris@179
|
44 const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; }
|
Chris@179
|
45
|
Chris@147
|
46 size_t getFrameCount() const;
|
Chris@147
|
47 size_t getChannelCount() const;
|
Chris@147
|
48 size_t getSampleRate() const;
|
Chris@297
|
49 size_t getNativeRate() const;
|
Chris@147
|
50
|
Chris@147
|
51 virtual Model *clone() const;
|
Chris@147
|
52
|
Chris@147
|
53 float getValueMinimum() const { return -1.0f; }
|
Chris@147
|
54 float getValueMaximum() const { return 1.0f; }
|
Chris@147
|
55
|
Chris@300
|
56 virtual size_t getStartFrame() const { return m_startFrame; }
|
Chris@300
|
57 virtual size_t getEndFrame() const { return m_startFrame + getFrameCount(); }
|
Chris@147
|
58
|
Chris@300
|
59 void setStartFrame(size_t startFrame) { m_startFrame = startFrame; }
|
Chris@147
|
60
|
Chris@300
|
61 virtual size_t getData(int channel, size_t start, size_t count,
|
Chris@300
|
62 float *buffer) const;
|
Chris@147
|
63
|
Chris@300
|
64 virtual size_t getData(int channel, size_t start, size_t count,
|
Chris@300
|
65 double *buffer) const;
|
Chris@147
|
66
|
Chris@300
|
67 virtual void getSummaries(size_t channel, size_t start, size_t count,
|
Chris@300
|
68 RangeBlock &ranges,
|
Chris@300
|
69 size_t &blockSize) const;
|
Chris@300
|
70
|
Chris@300
|
71 virtual Range getSummary(size_t channel, size_t start, size_t count) const;
|
Chris@147
|
72
|
Chris@163
|
73 virtual void toXml(QTextStream &out,
|
Chris@163
|
74 QString indent = "",
|
Chris@163
|
75 QString extraAttributes = "") const;
|
Chris@163
|
76
|
Chris@239
|
77 signals:
|
Chris@239
|
78 void modelChanged();
|
Chris@258
|
79 void modelChanged(size_t, size_t);
|
Chris@239
|
80 void completionChanged();
|
Chris@239
|
81
|
Chris@147
|
82 protected slots:
|
Chris@147
|
83 void fillTimerTimedOut();
|
Chris@147
|
84 void cacheFilled();
|
Chris@147
|
85
|
Chris@147
|
86 protected:
|
Chris@147
|
87 void initialize();
|
Chris@147
|
88
|
Chris@147
|
89 class RangeCacheFillThread : public Thread
|
Chris@147
|
90 {
|
Chris@147
|
91 public:
|
Chris@147
|
92 RangeCacheFillThread(WaveFileModel &model) :
|
Chris@175
|
93 m_model(model), m_fillExtent(0),
|
Chris@175
|
94 m_frameCount(model.getFrameCount()) { }
|
Chris@147
|
95
|
Chris@147
|
96 size_t getFillExtent() const { return m_fillExtent; }
|
Chris@147
|
97 virtual void run();
|
Chris@147
|
98
|
Chris@147
|
99 protected:
|
Chris@147
|
100 WaveFileModel &m_model;
|
Chris@147
|
101 size_t m_fillExtent;
|
Chris@175
|
102 size_t m_frameCount;
|
Chris@147
|
103 };
|
Chris@147
|
104
|
Chris@147
|
105 void fillCache();
|
Chris@316
|
106
|
Chris@316
|
107 RemoteFile m_source;
|
Chris@147
|
108 QString m_path;
|
Chris@147
|
109 AudioFileReader *m_reader;
|
Chris@175
|
110 bool m_myReader;
|
Chris@147
|
111
|
Chris@300
|
112 size_t m_startFrame;
|
Chris@300
|
113
|
Chris@147
|
114 RangeBlock m_cache[2]; // interleaved at two base resolutions
|
Chris@147
|
115 mutable QMutex m_mutex;
|
Chris@147
|
116 RangeCacheFillThread *m_fillThread;
|
Chris@147
|
117 QTimer *m_updateTimer;
|
Chris@147
|
118 size_t m_lastFillExtent;
|
Chris@147
|
119 bool m_exiting;
|
Chris@179
|
120 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
|
Chris@147
|
121 };
|
Chris@147
|
122
|
Chris@147
|
123 #endif
|