WritableWaveFileModel.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 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 WRITABLE_WAVE_FILE_MODEL_H
17 #define WRITABLE_WAVE_FILE_MODEL_H
18 
19 #include "WaveFileModel.h"
20 #include "ReadOnlyWaveFileModel.h"
22 
23 class WavFileWriter;
24 class WavFileReader;
25 
27 {
28  Q_OBJECT
29 
30 public:
31  enum class Normalisation { None, Peak };
32 
46  WritableWaveFileModel(QString path,
47  sv_samplerate_t sampleRate,
48  int channels,
49  Normalisation normalisation);
50 
65  int channels,
66  Normalisation normalisation);
67 
77  int channels);
78 
80 
103  virtual bool addSamples(const float *const *samples, sv_frame_t count);
104 
110  void updateModel();
111 
125  void setWriteProportion(int proportion);
126 
131  void writeComplete();
132 
133  static const int PROPORTION_UNKNOWN;
134 
139  int getWriteProportion() const;
140 
141  bool isOK() const override;
142 
149  int getCompletion() const override { return 100; }
150 
151  const ZoomConstraint *getZoomConstraint() const override {
153  return &zc;
154  }
155 
156  sv_frame_t getFrameCount() const override;
157  int getChannelCount() const override { return m_channels; }
158  sv_samplerate_t getSampleRate() const override { return m_sampleRate; }
159  sv_samplerate_t getNativeRate() const override { return m_sampleRate; }
160 
161  QString getTitle() const override {
162  if (m_model) return m_model->getTitle();
163  else return "";
164  }
165  QString getMaker() const override {
166  if (m_model) return m_model->getMaker();
167  else return "";
168  }
169  QString getLocation() const override {
170  if (m_model) return m_model->getLocation();
171  else return "";
172  }
173 
174  float getValueMinimum() const override { return -1.0f; }
175  float getValueMaximum() const override { return 1.0f; }
176 
177  sv_frame_t getStartFrame() const override { return m_startFrame; }
178  sv_frame_t getTrueEndFrame() const override { return m_startFrame + getFrameCount(); }
179 
180  void setStartFrame(sv_frame_t startFrame) override;
181 
182  floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const override;
183 
184  std::vector<floatvec_t> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const override;
185 
186  int getSummaryBlockSize(int desired) const override;
187 
188  void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
189  RangeBlock &ranges, int &blockSize) const override;
190 
191  Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const override;
192 
193  QString getTypeName() const override { return tr("Writable Wave File"); }
194 
195  void toXml(QTextStream &out,
196  QString indent = "",
197  QString extraAttributes = "") const override;
198 
199 signals:
200  void writeCompleted(ModelId);
201 
202 protected slots:
205 
206 protected:
208 
215 
224  QString m_targetPath;
225 
233 
234 private:
235  void init(QString path = "");
236  void normaliseToTarget();
237 };
238 
239 #endif
240 
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
int getSummaryBlockSize(int desired) const override
ReadOnlyWaveFileModel * m_model
void writeCompleted(ModelId)
int64_t sv_frame_t
Frame index, the unit of our time axis.
Definition: BaseTypes.h:31
void writeComplete()
Indicate that writing is complete.
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...
int getWriteProportion() const
Get the proportion of the file which has been written so far, as a percentage.
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...
Reader for audio files using libsndfile.
Definition: WavFileReader.h:41
float getValueMaximum() const override
Return the minimum possible value found in this model type.
sv_frame_t getTrueEndFrame() const override
Return the audio frame at the end of the model.
QString getMaker() const override
Return the "artist" or "maker" of the model, if known.
void setWriteProportion(int proportion)
Set the proportion of the file which has been written so far, as a percentage.
void init(QString path="")
QString getMaker() const override
Return the "artist" or "maker" of the model, if known.
std::vector< float, breakfastquay::StlAllocator< float > > floatvec_t
Definition: BaseTypes.h:53
void setStartFrame(sv_frame_t startFrame) override
QString getTypeName() const override
Return the type of the model.
void componentModelChangedWithin(ModelId, sv_frame_t, sv_frame_t)
WavFileWriter * m_temporaryWriter
When normalising, this writer is used to write verbatim samples to the temporary file prior to normal...
static const int PROPORTION_UNKNOWN
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...
QString getLocation() const override
Return the location of the data in this model (e.g.
QString getTitle() const override
Return the "work title" of the model, if known.
WavFileWriter * m_targetWriter
When not normalising, this writer is used to write verbatim samples direct to the target file...
WritableWaveFileModel(QString path, sv_samplerate_t sampleRate, int channels, Normalisation normalisation)
Create a WritableWaveFileModel of the given sample rate and channel count, storing data in a new floa...
int getChannelCount() const override
Return the number of distinct channels for this model.
sv_frame_t getStartFrame() const override
Return the first audio frame spanned by the model.
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...
QString getLocation() const override
Return the location of the data in this model (e.g.
void toXml(QTextStream &out, QString indent="", QString extraAttributes="") const override
Stream this exportable object out to XML on a text stream.
bool isOK() const override
Return true if the model was constructed successfully.
QString getTitle() const override
Return the "work title" of the model, if known.
const ZoomConstraint * getZoomConstraint() const override
If this model imposes a zoom constraint, i.e.
float getValueMinimum() const override
Return the minimum possible value found in this model type.
void updateModel()
Tell the model to update its own (read) view of the (written) file.
ZoomConstraint is a simple interface that describes a limitation on the available zoom sizes for a vi...
sv_frame_t getFrameCount() const override
int getCompletion() const override
Return the generation completion percentage of this model.
sv_samplerate_t getNativeRate() const override
Return the frame rate of the underlying material, if the model itself has already been resampled...
Definition: ById.h:115
sv_samplerate_t getSampleRate() const override
Return the frame rate in frames per second.
virtual bool addSamples(const float *const *samples, sv_frame_t count)
Call addSamples to append a block of samples to the end of the file.