annotate data/model/WritableWaveFileModel.h @ 1247:8f076d02569a piper

Make SVDEBUG always write to a log file -- formerly this was disabled in NDEBUG builds. I think there's little use to that, it just means that we keep adding more cerr debug output because we aren't getting the log we need. And SVDEBUG logging is not usually used in tight loops, I don't think the performance overhead is too serious. Also update the About box.
author Chris Cannam
date Thu, 03 Nov 2016 14:57:00 +0000
parents e994747fb9dd
children 3aea4f7617bb
rev   line source
Chris@175 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@175 2
Chris@175 3 /*
Chris@175 4 Sonic Visualiser
Chris@175 5 An audio file viewer and annotation editor.
Chris@175 6 Centre for Digital Music, Queen Mary, University of London.
Chris@202 7 This file copyright 2006 QMUL.
Chris@175 8
Chris@175 9 This program is free software; you can redistribute it and/or
Chris@175 10 modify it under the terms of the GNU General Public License as
Chris@175 11 published by the Free Software Foundation; either version 2 of the
Chris@175 12 License, or (at your option) any later version. See the file
Chris@175 13 COPYING included with this distribution for more information.
Chris@175 14 */
Chris@175 15
Chris@1122 16 #ifndef WRITABLE_WAVE_FILE_MODEL_H
Chris@1122 17 #define WRITABLE_WAVE_FILE_MODEL_H
Chris@175 18
Chris@175 19 #include "WaveFileModel.h"
Chris@1122 20 #include "ReadOnlyWaveFileModel.h"
Chris@1122 21 #include "PowerOfSqrtTwoZoomConstraint.h"
Chris@175 22
Chris@175 23 class WavFileWriter;
Chris@175 24 class WavFileReader;
Chris@175 25
Chris@1122 26 class WritableWaveFileModel : public WaveFileModel
Chris@175 27 {
Chris@175 28 Q_OBJECT
Chris@175 29
Chris@175 30 public:
Chris@1040 31 WritableWaveFileModel(sv_samplerate_t sampleRate, int channels, QString path = "");
Chris@175 32 ~WritableWaveFileModel();
Chris@175 33
Chris@188 34 /**
Chris@188 35 * Call addSamples to append a block of samples to the end of the
Chris@1133 36 * file. Caller should also call setWriteProportion() to update
Chris@1133 37 * the progress of this file, if it has a known end point, and
Chris@1133 38 * should call writeComplete() when the file has been written.
Chris@188 39 */
Chris@1038 40 virtual bool addSamples(float **samples, sv_frame_t count);
Chris@1133 41
Chris@1133 42 /**
Chris@1133 43 * Set the proportion of the file which has been written so far,
Chris@1133 44 * as a percentage. This may be used to indicate progress.
Chris@1133 45 *
Chris@1133 46 * Note that this differs from the "completion" percentage
Chris@1133 47 * reported through isReady()/getCompletion(). That percentage is
Chris@1133 48 * updated when "internal processing has advanced... but the model
Chris@1133 49 * has not changed externally", i.e. it reports progress in
Chris@1133 50 * calculating the initial state of a model. In contrast, an
Chris@1133 51 * update to setWriteProportion corresponds to a change in the
Chris@1133 52 * externally visible state of the model (i.e. it contains more
Chris@1133 53 * data than before).
Chris@1133 54 */
Chris@1133 55 void setWriteProportion(int proportion);
Chris@1133 56
Chris@1133 57 /**
Chris@1133 58 * Indicate that writing is complete. You should call this even if
Chris@1133 59 * you have never called setWriteProportion().
Chris@1133 60 */
Chris@1133 61 void writeComplete();
Chris@1133 62
Chris@1133 63 static const int PROPORTION_UNKNOWN;
Chris@1133 64
Chris@1133 65 /**
Chris@1133 66 * Get the proportion of the file which has been written so far,
Chris@1133 67 * as a percentage. Return PROPORTION_UNKNOWN if unknown.
Chris@1133 68 */
Chris@1133 69 int getWriteProportion() const;
Chris@175 70
Chris@175 71 bool isOK() const;
Chris@175 72 bool isReady(int *) const;
Chris@1133 73
Chris@1133 74 /**
Chris@1133 75 * Return the generation completion percentage of this model. This
Chris@1133 76 * is always 100, because the model is always in a complete state
Chris@1133 77 * -- it just contains varying amounts of data depending on how
Chris@1133 78 * much has been written.
Chris@1133 79 */
Chris@1133 80 virtual int getCompletion() const { return 100; }
Chris@188 81
Chris@179 82 const ZoomConstraint *getZoomConstraint() const {
Chris@179 83 static PowerOfSqrtTwoZoomConstraint zc;
Chris@179 84 return &zc;
Chris@179 85 }
Chris@179 86
Chris@1038 87 sv_frame_t getFrameCount() const;
Chris@929 88 int getChannelCount() const { return m_channels; }
Chris@1040 89 sv_samplerate_t getSampleRate() const { return m_sampleRate; }
Chris@1122 90 sv_samplerate_t getNativeRate() const { return m_sampleRate; }
Chris@1122 91
Chris@1122 92 QString getTitle() const {
Chris@1122 93 if (m_model) return m_model->getTitle();
Chris@1122 94 else return "";
Chris@1122 95 }
Chris@1122 96 QString getMaker() const {
Chris@1122 97 if (m_model) return m_model->getMaker();
Chris@1122 98 else return "";
Chris@1122 99 }
Chris@1122 100 QString getLocation() const {
Chris@1122 101 if (m_model) return m_model->getLocation();
Chris@1122 102 else return "";
Chris@1122 103 }
Chris@175 104
Chris@175 105 float getValueMinimum() const { return -1.0f; }
Chris@175 106 float getValueMaximum() const { return 1.0f; }
Chris@175 107
Chris@1038 108 virtual sv_frame_t getStartFrame() const { return m_startFrame; }
Chris@1038 109 virtual sv_frame_t getEndFrame() const { return m_startFrame + getFrameCount(); }
Chris@175 110
Chris@1038 111 void setStartFrame(sv_frame_t startFrame);
Chris@175 112
Chris@1096 113 virtual std::vector<float> getData(int channel, sv_frame_t start, sv_frame_t count) const;
Chris@175 114
Chris@1096 115 virtual std::vector<std::vector<float>> getMultiChannelData(int fromchannel, int tochannel, sv_frame_t start, sv_frame_t count) const;
Chris@363 116
Chris@929 117 virtual int getSummaryBlockSize(int desired) const;
Chris@377 118
Chris@1038 119 virtual void getSummaries(int channel, sv_frame_t start, sv_frame_t count,
Chris@929 120 RangeBlock &ranges, int &blockSize) const;
Chris@300 121
Chris@1038 122 virtual Range getSummary(int channel, sv_frame_t start, sv_frame_t count) const;
Chris@175 123
Chris@345 124 QString getTypeName() const { return tr("Writable Wave File"); }
Chris@345 125
Chris@175 126 virtual void toXml(QTextStream &out,
Chris@175 127 QString indent = "",
Chris@175 128 QString extraAttributes = "") const;
Chris@175 129
Chris@175 130 protected:
Chris@1122 131 ReadOnlyWaveFileModel *m_model;
Chris@175 132 WavFileWriter *m_writer;
Chris@175 133 WavFileReader *m_reader;
Chris@1040 134 sv_samplerate_t m_sampleRate;
Chris@929 135 int m_channels;
Chris@1038 136 sv_frame_t m_frameCount;
Chris@1038 137 sv_frame_t m_startFrame;
Chris@1133 138 int m_proportion;
Chris@175 139 };
Chris@175 140
Chris@175 141 #endif
Chris@175 142