Chris@148: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
Chris@148: 
Chris@148: /*
Chris@148:     Sonic Visualiser
Chris@148:     An audio file viewer and annotation editor.
Chris@148:     Centre for Digital Music, Queen Mary, University of London.
Chris@148:     This file copyright 2006 Chris Cannam.
Chris@148:     
Chris@148:     This program is free software; you can redistribute it and/or
Chris@148:     modify it under the terms of the GNU General Public License as
Chris@148:     published by the Free Software Foundation; either version 2 of the
Chris@148:     License, or (at your option) any later version.  See the file
Chris@148:     COPYING included with this distribution for more information.
Chris@148: */
Chris@148: 
Chris@1348: #ifndef SV_WAV_FILE_WRITER_H
Chris@1348: #define SV_WAV_FILE_WRITER_H
Chris@148: 
Chris@148: #include <QString>
Chris@1350: 
Chris@1350: #ifdef Q_OS_WIN
Chris@1350: #include <windows.h>
Chris@1350: #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
Chris@1350: #endif
Chris@148: 
Chris@174: #include <sndfile.h>
Chris@174: 
Chris@1038: #include "base/BaseTypes.h"
Chris@1038: 
Chris@148: class DenseTimeValueModel;
Chris@148: class MultiSelection;
Chris@674: class TempWriteFile;
Chris@148: 
Chris@148: class WavFileWriter
Chris@148: {
Chris@148: public:
Chris@684:     /**
Chris@684:      * Specify the method used to open the destination file.
Chris@684:      * 
Chris@684:      * If WriteToTemporary, the destination will be opened as a
Chris@684:      * temporary file which is moved to the target location when the
Chris@684:      * WavFileWriter is closed or deleted (to avoid clobbering an
Chris@684:      * existing file with a partially written replacement).
Chris@684:      * 
Chris@684:      * If WriteToTarget, the target file will be opened directly
Chris@684:      * (necessary when e.g. doing a series of incremental writes to a
Chris@684:      * file while keeping it open for reading).
Chris@684:      */
Chris@684:     enum FileWriteMode {
Chris@684:         WriteToTemporary,
Chris@684:         WriteToTarget
Chris@684:     };
Chris@684: 
Chris@1040:     WavFileWriter(QString path, sv_samplerate_t sampleRate, int channels,
Chris@684:                   FileWriteMode mode);
Chris@148:     virtual ~WavFileWriter();
Chris@148: 
Chris@148:     bool isOK() const;
Chris@148: 
Chris@148:     virtual QString getError() const;
Chris@148: 
Chris@175:     QString getPath() const { return m_path; }
Chris@175: 
Chris@174:     bool writeModel(DenseTimeValueModel *source,
Chris@174:                     MultiSelection *selection = 0);
Chris@174: 
Chris@1520:     /// Write samples from raw arrays; count is per-channel
Chris@1520:     bool writeSamples(const float *const *samples, sv_frame_t count);
Chris@1520: 
Chris@1520:     /// As writeSamples, but compatible with WavFileReader api. More expensive.
Chris@1520:     bool putInterleavedFrames(const floatvec_t &frames);
Chris@174: 
Chris@174:     bool close();
Chris@148: 
Chris@148: protected:
Chris@148:     QString m_path;
Chris@1040:     sv_samplerate_t m_sampleRate;
Chris@929:     int m_channels;
Chris@674:     TempWriteFile *m_temp;
Chris@1350:     SNDFILE *m_file;
Chris@148:     QString m_error;
Chris@684: 
Chris@684:     QString getWriteFilename() const;
Chris@148: };
Chris@148: 
Chris@148: 
Chris@148: #endif