svcore  1.9
WritableWaveFileModel.h
Go to the documentation of this file.
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
00002 
00003 /*
00004     Sonic Visualiser
00005     An audio file viewer and annotation editor.
00006     Centre for Digital Music, Queen Mary, University of London.
00007     This file copyright 2006 QMUL.
00008     
00009     This program is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU General Public License as
00011     published by the Free Software Foundation; either version 2 of the
00012     License, or (at your option) any later version.  See the file
00013     COPYING included with this distribution for more information.
00014 */
00015 
00016 #ifndef _WRITABLE_WAVE_FILE_MODEL_H_
00017 #define _WRITABLE_WAVE_FILE_MODEL_H_
00018 
00019 #include "WaveFileModel.h"
00020 
00021 class WavFileWriter;
00022 class WavFileReader;
00023 
00024 class WritableWaveFileModel : public RangeSummarisableTimeValueModel
00025 {
00026     Q_OBJECT
00027 
00028 public:
00029     WritableWaveFileModel(int sampleRate, int channels, QString path = "");
00030     ~WritableWaveFileModel();
00031 
00038     virtual bool addSamples(float **samples, int count);
00039     
00040     bool isOK() const;
00041     bool isReady(int *) const;
00042 
00043     virtual void setCompletion(int completion); // percentage
00044     virtual int getCompletion() const { return m_completion; }
00045 
00046     const ZoomConstraint *getZoomConstraint() const {
00047         static PowerOfSqrtTwoZoomConstraint zc;
00048         return &zc;
00049     }
00050 
00051     int getFrameCount() const;
00052     int getChannelCount() const { return m_channels; }
00053     int getSampleRate() const { return m_sampleRate; }
00054 
00055     virtual Model *clone() const;
00056 
00057     float getValueMinimum() const { return -1.0f; }
00058     float getValueMaximum() const { return  1.0f; }
00059 
00060     virtual int getStartFrame() const { return m_startFrame; }
00061     virtual int getEndFrame() const { return m_startFrame + getFrameCount(); }
00062 
00063     void setStartFrame(int startFrame);
00064 
00065     virtual int getData(int channel, int start, int count,
00066                            float *buffer) const;
00067 
00068     virtual int getData(int channel, int start, int count,
00069                            double *buffer) const;
00070 
00071     virtual int getData(int fromchannel, int tochannel,
00072                            int start, int count,
00073                            float **buffer) const;
00074 
00075     virtual int getSummaryBlockSize(int desired) const;
00076 
00077     virtual void getSummaries(int channel, int start, int count,
00078                               RangeBlock &ranges, int &blockSize) const;
00079 
00080     virtual Range getSummary(int channel, int start, int count) const;
00081 
00082     QString getTypeName() const { return tr("Writable Wave File"); }
00083 
00084     virtual void toXml(QTextStream &out,
00085                        QString indent = "",
00086                        QString extraAttributes = "") const;
00087 
00088 protected:
00089     WaveFileModel *m_model;
00090     WavFileWriter *m_writer;
00091     WavFileReader *m_reader;
00092     int m_sampleRate;
00093     int m_channels;
00094     int m_frameCount;
00095     int m_startFrame;
00096     int m_completion;
00097 };
00098 
00099 #endif
00100