Chris@175: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@175: Chris@175: /* Chris@175: Sonic Visualiser Chris@175: An audio file viewer and annotation editor. Chris@175: Centre for Digital Music, Queen Mary, University of London. Chris@202: This file copyright 2006 QMUL. Chris@175: Chris@175: This program is free software; you can redistribute it and/or Chris@175: modify it under the terms of the GNU General Public License as Chris@175: published by the Free Software Foundation; either version 2 of the Chris@175: License, or (at your option) any later version. See the file Chris@175: COPYING included with this distribution for more information. Chris@175: */ Chris@175: Chris@1122: #ifndef WRITABLE_WAVE_FILE_MODEL_H Chris@1122: #define WRITABLE_WAVE_FILE_MODEL_H Chris@175: Chris@175: #include "WaveFileModel.h" Chris@1122: #include "ReadOnlyWaveFileModel.h" Chris@1122: #include "PowerOfSqrtTwoZoomConstraint.h" Chris@175: Chris@175: class WavFileWriter; Chris@175: class WavFileReader; Chris@175: Chris@1122: class WritableWaveFileModel : public WaveFileModel Chris@175: { Chris@175: Q_OBJECT Chris@175: Chris@175: public: Chris@1040: WritableWaveFileModel(sv_samplerate_t sampleRate, int channels, QString path = ""); Chris@175: ~WritableWaveFileModel(); Chris@175: Chris@188: /** Chris@188: * Call addSamples to append a block of samples to the end of the Chris@1337: * file. Chris@1337: * Chris@1337: * This function only appends the samples to the file being Chris@1337: * written; it does not update the model's view of the samples in Chris@1337: * that file. That is, it updates the file on disc but the model Chris@1337: * itself does not change its content. This is because re-reading Chris@1337: * the file to update the model may be more expensive than adding Chris@1337: * the samples in the first place. If you are writing small Chris@1337: * numbers of samples repeatedly, you probably only want the model Chris@1337: * to update periodically rather than after every write. Chris@1337: * Chris@1337: * Call updateModel() periodically to tell the model to update its Chris@1337: * own view of the samples in the file being written. Chris@1337: * Chris@1337: * Call setWriteProportion() periodically if the file being Chris@1337: * written has known duration and you want the model to be able to Chris@1337: * report the write progress as a percentage. Chris@1337: * Chris@1337: * Call writeComplete() when the file has been completely written. Chris@188: */ Chris@1325: virtual bool addSamples(const float *const *samples, sv_frame_t count); Chris@1133: Chris@1133: /** Chris@1337: * Tell the model to update its own (read) view of the (written) Chris@1337: * file. May cause modelChanged() and modelChangedWithin() to be Chris@1337: * emitted. See the comment to addSamples above for rationale. Chris@1337: */ Chris@1337: void updateModel(); Chris@1337: Chris@1337: /** Chris@1133: * Set the proportion of the file which has been written so far, Chris@1133: * as a percentage. This may be used to indicate progress. Chris@1133: * Chris@1133: * Note that this differs from the "completion" percentage Chris@1133: * reported through isReady()/getCompletion(). That percentage is Chris@1133: * updated when "internal processing has advanced... but the model Chris@1133: * has not changed externally", i.e. it reports progress in Chris@1133: * calculating the initial state of a model. In contrast, an Chris@1133: * update to setWriteProportion corresponds to a change in the Chris@1133: * externally visible state of the model (i.e. it contains more Chris@1133: * data than before). Chris@1133: */ Chris@1133: void setWriteProportion(int proportion); Chris@1133: Chris@1133: /** Chris@1133: * Indicate that writing is complete. You should call this even if Chris@1337: * you have never called setWriteProportion() or updateModel(). Chris@1133: */ Chris@1133: void writeComplete(); Chris@1133: Chris@1133: static const int PROPORTION_UNKNOWN; Chris@1133: Chris@1133: /** Chris@1133: * Get the proportion of the file which has been written so far, Chris@1133: * as a percentage. Return PROPORTION_UNKNOWN if unknown. Chris@1133: */ Chris@1133: int getWriteProportion() const; Chris@175: Chris@175: bool isOK() const; Chris@175: bool isReady(int *) const; Chris@1133: Chris@1133: /** Chris@1133: * Return the generation completion percentage of this model. This Chris@1133: * is always 100, because the model is always in a complete state Chris@1133: * -- it just contains varying amounts of data depending on how Chris@1133: * much has been written. Chris@1133: */ Chris@1133: virtual int getCompletion() const { return 100; } Chris@188: Chris@179: const ZoomConstraint *getZoomConstraint() const { Chris@179: static PowerOfSqrtTwoZoomConstraint zc; Chris@179: return &zc; Chris@179: } Chris@179: Chris@1038: sv_frame_t getFrameCount() const; Chris@929: int getChannelCount() const { return m_channels; } Chris@1040: sv_samplerate_t getSampleRate() const { return m_sampleRate; } Chris@1122: sv_samplerate_t getNativeRate() const { return m_sampleRate; } Chris@1122: Chris@1122: QString getTitle() const { Chris@1122: if (m_model) return m_model->getTitle(); Chris@1122: else return ""; Chris@1122: } Chris@1122: QString getMaker() const { Chris@1122: if (m_model) return m_model->getMaker(); Chris@1122: else return ""; Chris@1122: } Chris@1122: QString getLocation() const { Chris@1122: if (m_model) return m_model->getLocation(); Chris@1122: else return ""; Chris@1122: } Chris@175: Chris@175: float getValueMinimum() const { return -1.0f; } Chris@175: float getValueMaximum() const { return 1.0f; } Chris@175: Chris@1038: virtual sv_frame_t getStartFrame() const { return m_startFrame; } Chris@1038: virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); } Chris@175: Chris@1038: void setStartFrame(sv_frame_t startFrame); Chris@175: Chris@1326: virtual floatvec_t getData(int channel, sv_frame_t start, sv_frame_t count) const; Chris@175: Chris@1326: virtual std::vector getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const; Chris@363: Chris@929: virtual int getSummaryBlockSize(int desired) const; Chris@377: Chris@1038: virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count, Chris@929: RangeBlock &ranges, int &blockSize) const; Chris@300: Chris@1038: virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const; Chris@175: Chris@345: QString getTypeName() const { return tr("Writable Wave File"); } Chris@345: Chris@175: virtual void toXml(QTextStream &out, Chris@175: QString indent = "", Chris@175: QString extraAttributes = "") const; Chris@175: Chris@175: protected: Chris@1122: ReadOnlyWaveFileModel *m_model; Chris@175: WavFileWriter *m_writer; Chris@175: WavFileReader *m_reader; Chris@1040: sv_samplerate_t m_sampleRate; Chris@929: int m_channels; Chris@1038: sv_frame_t m_frameCount; Chris@1038: sv_frame_t m_startFrame; Chris@1133: int m_proportion; Chris@175: }; Chris@175: Chris@175: #endif Chris@175: