annotate data/fileio/WavFileWriter.h @ 1700:c1208b211d8c single-point

Ensure test fails rather than crashing if this reader doesn't get created
author Chris Cannam <cannam@all-day-breakfast.com>
date Fri, 03 May 2019 15:02:09 +0100
parents 954d0cf29ca7
children
rev   line source
Chris@148 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@148 2
Chris@148 3 /*
Chris@148 4 Sonic Visualiser
Chris@148 5 An audio file viewer and annotation editor.
Chris@148 6 Centre for Digital Music, Queen Mary, University of London.
Chris@148 7 This file copyright 2006 Chris Cannam.
Chris@148 8
Chris@148 9 This program is free software; you can redistribute it and/or
Chris@148 10 modify it under the terms of the GNU General Public License as
Chris@148 11 published by the Free Software Foundation; either version 2 of the
Chris@148 12 License, or (at your option) any later version. See the file
Chris@148 13 COPYING included with this distribution for more information.
Chris@148 14 */
Chris@148 15
Chris@1348 16 #ifndef SV_WAV_FILE_WRITER_H
Chris@1348 17 #define SV_WAV_FILE_WRITER_H
Chris@148 18
Chris@148 19 #include <QString>
Chris@1350 20
Chris@1350 21 #ifdef Q_OS_WIN
Chris@1350 22 #include <windows.h>
Chris@1350 23 #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
Chris@1350 24 #endif
Chris@148 25
Chris@174 26 #include <sndfile.h>
Chris@174 27
Chris@1038 28 #include "base/BaseTypes.h"
Chris@1038 29
Chris@148 30 class DenseTimeValueModel;
Chris@148 31 class MultiSelection;
Chris@674 32 class TempWriteFile;
Chris@148 33
Chris@148 34 class WavFileWriter
Chris@148 35 {
Chris@148 36 public:
Chris@684 37 /**
Chris@684 38 * Specify the method used to open the destination file.
Chris@684 39 *
Chris@684 40 * If WriteToTemporary, the destination will be opened as a
Chris@684 41 * temporary file which is moved to the target location when the
Chris@684 42 * WavFileWriter is closed or deleted (to avoid clobbering an
Chris@684 43 * existing file with a partially written replacement).
Chris@684 44 *
Chris@684 45 * If WriteToTarget, the target file will be opened directly
Chris@684 46 * (necessary when e.g. doing a series of incremental writes to a
Chris@684 47 * file while keeping it open for reading).
Chris@684 48 */
Chris@684 49 enum FileWriteMode {
Chris@684 50 WriteToTemporary,
Chris@684 51 WriteToTarget
Chris@684 52 };
Chris@684 53
Chris@1040 54 WavFileWriter(QString path, sv_samplerate_t sampleRate, int channels,
Chris@684 55 FileWriteMode mode);
Chris@148 56 virtual ~WavFileWriter();
Chris@148 57
Chris@148 58 bool isOK() const;
Chris@148 59
Chris@148 60 virtual QString getError() const;
Chris@148 61
Chris@175 62 QString getPath() const { return m_path; }
Chris@175 63
Chris@174 64 bool writeModel(DenseTimeValueModel *source,
Chris@174 65 MultiSelection *selection = 0);
Chris@174 66
Chris@1520 67 /// Write samples from raw arrays; count is per-channel
Chris@1520 68 bool writeSamples(const float *const *samples, sv_frame_t count);
Chris@1520 69
Chris@1520 70 /// As writeSamples, but compatible with WavFileReader api. More expensive.
Chris@1520 71 bool putInterleavedFrames(const floatvec_t &frames);
Chris@174 72
Chris@174 73 bool close();
Chris@148 74
Chris@148 75 protected:
Chris@148 76 QString m_path;
Chris@1040 77 sv_samplerate_t m_sampleRate;
Chris@929 78 int m_channels;
Chris@674 79 TempWriteFile *m_temp;
Chris@1350 80 SNDFILE *m_file;
Chris@148 81 QString m_error;
Chris@684 82
Chris@684 83 QString getWriteFilename() const;
Chris@148 84 };
Chris@148 85
Chris@148 86
Chris@148 87 #endif