comparison data/model/WaveFileModel.h @ 0:fc9323a41f5a

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