annotate data/fileio/WavFileWriter.h @ 1487:71202259002d

Round the zero-point value -- won't make a difference for longer fader widgets, but it's convenient for the level-pan widget when we have 0-10 and want zero at 8 rather than 7
author Chris Cannam
date Mon, 25 Jun 2018 14:12:27 +0100
parents 1bc6f70cb4c7
children 954d0cf29ca7
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@1325 67 bool writeSamples(const float *const *samples, sv_frame_t count); // count per channel
Chris@174 68
Chris@174 69 bool close();
Chris@148 70
Chris@148 71 protected:
Chris@148 72 QString m_path;
Chris@1040 73 sv_samplerate_t m_sampleRate;
Chris@929 74 int m_channels;
Chris@674 75 TempWriteFile *m_temp;
Chris@1350 76 SNDFILE *m_file;
Chris@148 77 QString m_error;
Chris@684 78
Chris@684 79 QString getWriteFilename() const;
Chris@148 80 };
Chris@148 81
Chris@148 82
Chris@148 83 #endif