ReadOnlyWaveFileModel.h
Go to the documentation of this file.
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 
29 
30 #include <stdlib.h>
31 
32 #include <atomic>
33 
34 class AudioFileReader;
35 
37 {
38  Q_OBJECT
39 
40 public:
45  ReadOnlyWaveFileModel(FileSource source, sv_samplerate_t targetRate = 0);
46 
54 
56 
57  bool isOK() const override;
58  bool isReady(int *) const override;
59  int getCompletion() const override {
60  int c = 0;
61  (void)isReady(&c);
62  return c;
63  }
64 
65  const ZoomConstraint *getZoomConstraint() const override { return &m_zoomConstraint; }
66 
67  sv_frame_t getFrameCount() const override;
68  int getChannelCount() const override;
69  sv_samplerate_t getSampleRate() const override;
70  sv_samplerate_t getNativeRate() const override;
71 
72  QString getTitle() const override;
73  QString getMaker() const override;
74  QString getLocation() const override;
75 
76  QString getLocalFilename() const;
77 
78  float getValueMinimum() const override { return -1.0f; }
79  float getValueMaximum() const override { return 1.0f; }
80 
81  sv_frame_t getStartFrame() const override { return m_startFrame; }
82  sv_frame_t getTrueEndFrame() const override { return m_startFrame + getFrameCount(); }
83 
84  void setStartFrame(sv_frame_t startFrame) override { m_startFrame = startFrame; }
85 
86  floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const override;
87 
88  std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const override;
89 
90  int getSummaryBlockSize(int desired) const override;
91 
92  void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
93  RangeBlock &ranges,
94  int &blockSize) const override;
95 
96  Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const override;
97 
98  QString getTypeName() const override { return tr("Wave File"); }
99 
100  void toXml(QTextStream &out,
101  QString indent = "",
102  QString extraAttributes = "") const override;
103 
104 protected slots:
105  void fillTimerTimedOut();
106  void cacheFilled();
107 
108 protected:
109  void initialize();
110 
112  {
113  public:
115  m_model(model), m_fillExtent(0),
116  m_frameCount(model.getFrameCount()) { }
117 
119  void run() override;
120 
121  protected:
125  };
126 
127  void fillCache();
128 
130  QString m_path;
133 
135 
136  RangeBlock m_cache[2]; // interleaved at two base resolutions
137  mutable QMutex m_mutex;
139  QTimer *m_updateTimer;
141  mutable int m_prevCompletion;
142  std::atomic<bool> m_exiting;
144 
148  mutable QMutex m_directReadMutex;
149 };
150 
151 #endif
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
std::atomic< bool > m_exiting
bool isReady(int *) const override
Return true if the model has finished loading or calculating all its data, for a model that is capabl...
const ZoomConstraint * getZoomConstraint() const override
If this model imposes a zoom constraint, i.e.
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
sv_frame_t getFrameCount() const override
RangeCacheFillThread * m_fillThread
int getCompletion() const override
Return an estimated percentage value showing how far through any background operation used to calcula...
sv_frame_t getTrueEndFrame() const override
Return the audio frame at the end of the model.
sv_samplerate_t getNativeRate() const override
Return the frame rate of the underlying material, if the model itself has already been resampled...
QString getMaker() const override
Return the "artist" or "maker" of the model, if known.
bool isOK() const override
Return true if the model was constructed successfully.
std::vector< float, breakfastquay::StlAllocator< float > > floatvec_t
Definition: BaseTypes.h:53
int getSummaryBlockSize(int desired) const override
RangeCacheFillThread(ReadOnlyWaveFileModel &model)
static PowerOfSqrtTwoZoomConstraint m_zoomConstraint
float getValueMaximum() const override
Return the minimum possible value found in this model type.
QString getTitle() const override
Return the "work title" of the model, if known.
FileSource is a class used to refer to the contents of a file that may be either local or at a remote...
Definition: FileSource.h:59
float getValueMinimum() const override
Return the minimum possible value found in this model type.
QString getTypeName() const override
Return the type of the model.
QString getLocation() const override
Return the location of the data in this model (e.g.
Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const override
Return the range from the given start frame, corresponding to the given number of underlying sample f...
void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const override
Stream this exportable object out to XML on a text stream.
Definition: Thread.h:24
sv_frame_t getStartFrame() const override
Return the first audio frame spanned by the model.
ZoomConstraint is a simple interface that describes a limitation on the available zoom sizes for a vi...
ReadOnlyWaveFileModel(FileSource source, sv_samplerate_t targetRate=0)
Construct a WaveFileModel from a source path and optional resampling target rate. ...
sv_samplerate_t getSampleRate() const override
Return the frame rate in frames per second.
void setStartFrame(sv_frame_t startFrame) override
int getChannelCount() const override
Return the number of distinct channels for this model.
floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const override
Get the specified set of samples from the given channel of the model in single-precision floating-poi...
void getSummaries(int channel, sv_frame_t start, sv_frame_t count, RangeBlock &ranges, int &blockSize) const override
Return ranges from the given start frame, corresponding to the given number of underlying sample fram...
std::vector< floatvec_t > getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const override
Get the specified set of samples from given contiguous range of channels of the model in single-preci...