comparison data/model/WritableWaveFileModel.h @ 1365:3382d914e110

Merge from branch 3.0-integration
author Chris Cannam
date Fri, 13 Jan 2017 10:29:44 +0000
parents 3dcd83595bc8
children 925d205c39b4
comparison
equal deleted inserted replaced
1272:6a7ea3bd0e10 1365:3382d914e110
11 published by the Free Software Foundation; either version 2 of the 11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #ifndef _WRITABLE_WAVE_FILE_MODEL_H_ 16 #ifndef WRITABLE_WAVE_FILE_MODEL_H
17 #define _WRITABLE_WAVE_FILE_MODEL_H_ 17 #define WRITABLE_WAVE_FILE_MODEL_H
18 18
19 #include "WaveFileModel.h" 19 #include "WaveFileModel.h"
20 #include "ReadOnlyWaveFileModel.h"
21 #include "PowerOfSqrtTwoZoomConstraint.h"
20 22
21 class WavFileWriter; 23 class WavFileWriter;
22 class WavFileReader; 24 class WavFileReader;
23 25
24 class WritableWaveFileModel : public RangeSummarisableTimeValueModel 26 class WritableWaveFileModel : public WaveFileModel
25 { 27 {
26 Q_OBJECT 28 Q_OBJECT
27 29
28 public: 30 public:
29 WritableWaveFileModel(sv_samplerate_t sampleRate, int channels, QString path = ""); 31 WritableWaveFileModel(sv_samplerate_t sampleRate, int channels, QString path = "");
30 ~WritableWaveFileModel(); 32 ~WritableWaveFileModel();
31 33
32 /** 34 /**
33 * Call addSamples to append a block of samples to the end of the 35 * Call addSamples to append a block of samples to the end of the
34 * file. Caller should also call setCompletion to update the 36 * file.
35 * progress of this file, if it has a known end point, and should 37 *
36 * call setCompletion(100) when the file has been written. 38 * This function only appends the samples to the file being
39 * written; it does not update the model's view of the samples in
40 * that file. That is, it updates the file on disc but the model
41 * itself does not change its content. This is because re-reading
42 * the file to update the model may be more expensive than adding
43 * the samples in the first place. If you are writing small
44 * numbers of samples repeatedly, you probably only want the model
45 * to update periodically rather than after every write.
46 *
47 * Call updateModel() periodically to tell the model to update its
48 * own view of the samples in the file being written.
49 *
50 * Call setWriteProportion() periodically if the file being
51 * written has known duration and you want the model to be able to
52 * report the write progress as a percentage.
53 *
54 * Call writeComplete() when the file has been completely written.
37 */ 55 */
38 virtual bool addSamples(float **samples, sv_frame_t count); 56 virtual bool addSamples(const float *const *samples, sv_frame_t count);
57
58 /**
59 * Tell the model to update its own (read) view of the (written)
60 * file. May cause modelChanged() and modelChangedWithin() to be
61 * emitted. See the comment to addSamples above for rationale.
62 */
63 void updateModel();
64
65 /**
66 * Set the proportion of the file which has been written so far,
67 * as a percentage. This may be used to indicate progress.
68 *
69 * Note that this differs from the "completion" percentage
70 * reported through isReady()/getCompletion(). That percentage is
71 * updated when "internal processing has advanced... but the model
72 * has not changed externally", i.e. it reports progress in
73 * calculating the initial state of a model. In contrast, an
74 * update to setWriteProportion corresponds to a change in the
75 * externally visible state of the model (i.e. it contains more
76 * data than before).
77 */
78 void setWriteProportion(int proportion);
79
80 /**
81 * Indicate that writing is complete. You should call this even if
82 * you have never called setWriteProportion() or updateModel().
83 */
84 void writeComplete();
85
86 static const int PROPORTION_UNKNOWN;
87
88 /**
89 * Get the proportion of the file which has been written so far,
90 * as a percentage. Return PROPORTION_UNKNOWN if unknown.
91 */
92 int getWriteProportion() const;
39 93
40 bool isOK() const; 94 bool isOK() const;
41 bool isReady(int *) const; 95 bool isReady(int *) const;
42 96
43 virtual void setCompletion(int completion); // percentage 97 /**
44 virtual int getCompletion() const { return m_completion; } 98 * Return the generation completion percentage of this model. This
99 * is always 100, because the model is always in a complete state
100 * -- it just contains varying amounts of data depending on how
101 * much has been written.
102 */
103 virtual int getCompletion() const { return 100; }
45 104
46 const ZoomConstraint *getZoomConstraint() const { 105 const ZoomConstraint *getZoomConstraint() const {
47 static PowerOfSqrtTwoZoomConstraint zc; 106 static PowerOfSqrtTwoZoomConstraint zc;
48 return &zc; 107 return &zc;
49 } 108 }
50 109
51 sv_frame_t getFrameCount() const; 110 sv_frame_t getFrameCount() const;
52 int getChannelCount() const { return m_channels; } 111 int getChannelCount() const { return m_channels; }
53 sv_samplerate_t getSampleRate() const { return m_sampleRate; } 112 sv_samplerate_t getSampleRate() const { return m_sampleRate; }
113 sv_samplerate_t getNativeRate() const { return m_sampleRate; }
114
115 QString getTitle() const {
116 if (m_model) return m_model->getTitle();
117 else return "";
118 }
119 QString getMaker() const {
120 if (m_model) return m_model->getMaker();
121 else return "";
122 }
123 QString getLocation() const {
124 if (m_model) return m_model->getLocation();
125 else return "";
126 }
54 127
55 float getValueMinimum() const { return -1.0f; } 128 float getValueMinimum() const { return -1.0f; }
56 float getValueMaximum() const { return 1.0f; } 129 float getValueMaximum() const { return 1.0f; }
57 130
58 virtual sv_frame_t getStartFrame() const { return m_startFrame; } 131 virtual sv_frame_t getStartFrame() const { return m_startFrame; }
59 virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); } 132 virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); }
60 133
61 void setStartFrame(sv_frame_t startFrame); 134 void setStartFrame(sv_frame_t startFrame);
62 135
63 virtual sv_frame_t getData(int channel, sv_frame_t start, sv_frame_t count, 136 virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const;
64 float *buffer) const;
65 137
66 virtual sv_frame_t getMultiChannelData(int fromchannel, int tochannel, 138 virtual std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const;
67 sv_frame_t start, sv_frame_t count,
68 float **buffer) const;
69 139
70 virtual int getSummaryBlockSize(int desired) const; 140 virtual int getSummaryBlockSize(int desired) const;
71 141
72 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count, 142 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
73 RangeBlock &ranges, int &blockSize) const; 143 RangeBlock &ranges, int &blockSize) const;
79 virtual void toXml(QTextStream &out, 149 virtual void toXml(QTextStream &out,
80 QString indent = "", 150 QString indent = "",
81 QString extraAttributes = "") const; 151 QString extraAttributes = "") const;
82 152
83 protected: 153 protected:
84 WaveFileModel *m_model; 154 ReadOnlyWaveFileModel *m_model;
85 WavFileWriter *m_writer; 155 WavFileWriter *m_writer;
86 WavFileReader *m_reader; 156 WavFileReader *m_reader;
87 sv_samplerate_t m_sampleRate; 157 sv_samplerate_t m_sampleRate;
88 int m_channels; 158 int m_channels;
89 sv_frame_t m_frameCount; 159 sv_frame_t m_frameCount;
90 sv_frame_t m_startFrame; 160 sv_frame_t m_startFrame;
91 int m_completion; 161 int m_proportion;
92 }; 162 };
93 163
94 #endif 164 #endif
95 165