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@147
|
23 #include "RangeSummarisableTimeValueModel.h"
|
Chris@147
|
24 #include "PowerOfSqrtTwoZoomConstraint.h"
|
Chris@147
|
25
|
Chris@147
|
26 #include <stdlib.h>
|
Chris@147
|
27
|
Chris@147
|
28 class AudioFileReader;
|
Chris@147
|
29
|
Chris@179
|
30 class WaveFileModel : public RangeSummarisableTimeValueModel
|
Chris@147
|
31 {
|
Chris@147
|
32 Q_OBJECT
|
Chris@147
|
33
|
Chris@147
|
34 public:
|
Chris@147
|
35 WaveFileModel(QString path);
|
Chris@211
|
36 WaveFileModel(QString path, QString originalLocation);
|
Chris@211
|
37 WaveFileModel(QString originalLocation, AudioFileReader *reader);
|
Chris@147
|
38 ~WaveFileModel();
|
Chris@147
|
39
|
Chris@147
|
40 bool isOK() const;
|
Chris@147
|
41 bool isReady(int *) const;
|
Chris@147
|
42
|
Chris@179
|
43 const ZoomConstraint *getZoomConstraint() const { return &m_zoomConstraint; }
|
Chris@179
|
44
|
Chris@147
|
45 size_t getFrameCount() const;
|
Chris@147
|
46 size_t getChannelCount() const;
|
Chris@147
|
47 size_t getSampleRate() const;
|
Chris@147
|
48
|
Chris@147
|
49 virtual Model *clone() const;
|
Chris@147
|
50
|
Chris@147
|
51 float getValueMinimum() const { return -1.0f; }
|
Chris@147
|
52 float getValueMaximum() const { return 1.0f; }
|
Chris@147
|
53
|
Chris@147
|
54 virtual size_t getStartFrame() const { return 0; }
|
Chris@147
|
55 virtual size_t getEndFrame() const { return getFrameCount(); }
|
Chris@147
|
56
|
Chris@147
|
57 virtual size_t getValues(int channel, size_t start, size_t end,
|
Chris@147
|
58 float *buffer) const;
|
Chris@147
|
59
|
Chris@147
|
60 virtual size_t getValues(int channel, size_t start, size_t end,
|
Chris@147
|
61 double *buffer) const;
|
Chris@147
|
62
|
Chris@225
|
63 virtual void getRanges(size_t channel, size_t start, size_t end,
|
Chris@225
|
64 RangeBlock &ranges,
|
Chris@225
|
65 size_t &blockSize) const;
|
Chris@147
|
66
|
Chris@147
|
67 virtual Range getRange(size_t channel, size_t start, size_t end) const;
|
Chris@147
|
68
|
Chris@163
|
69 virtual void toXml(QTextStream &out,
|
Chris@163
|
70 QString indent = "",
|
Chris@163
|
71 QString extraAttributes = "") const;
|
Chris@163
|
72
|
Chris@147
|
73 virtual QString toXmlString(QString indent = "",
|
Chris@147
|
74 QString extraAttributes = "") const;
|
Chris@147
|
75
|
Chris@147
|
76 protected slots:
|
Chris@147
|
77 void fillTimerTimedOut();
|
Chris@147
|
78 void cacheFilled();
|
Chris@147
|
79
|
Chris@147
|
80 protected:
|
Chris@147
|
81 void initialize();
|
Chris@147
|
82
|
Chris@147
|
83 class RangeCacheFillThread : public Thread
|
Chris@147
|
84 {
|
Chris@147
|
85 public:
|
Chris@147
|
86 RangeCacheFillThread(WaveFileModel &model) :
|
Chris@175
|
87 m_model(model), m_fillExtent(0),
|
Chris@175
|
88 m_frameCount(model.getFrameCount()) { }
|
Chris@147
|
89
|
Chris@147
|
90 size_t getFillExtent() const { return m_fillExtent; }
|
Chris@147
|
91 virtual void run();
|
Chris@147
|
92
|
Chris@147
|
93 protected:
|
Chris@147
|
94 WaveFileModel &m_model;
|
Chris@147
|
95 size_t m_fillExtent;
|
Chris@175
|
96 size_t m_frameCount;
|
Chris@147
|
97 };
|
Chris@147
|
98
|
Chris@147
|
99 void fillCache();
|
Chris@147
|
100
|
Chris@147
|
101 QString m_path;
|
Chris@147
|
102 AudioFileReader *m_reader;
|
Chris@175
|
103 bool m_myReader;
|
Chris@147
|
104
|
Chris@147
|
105 RangeBlock m_cache[2]; // interleaved at two base resolutions
|
Chris@147
|
106 mutable QMutex m_mutex;
|
Chris@147
|
107 RangeCacheFillThread *m_fillThread;
|
Chris@147
|
108 QTimer *m_updateTimer;
|
Chris@147
|
109 size_t m_lastFillExtent;
|
Chris@147
|
110 bool m_exiting;
|
Chris@179
|
111 static PowerOfSqrtTwoZoomConstraint m_zoomConstraint;
|
Chris@147
|
112 };
|
Chris@147
|
113
|
Chris@147
|
114 #endif
|