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@1348
|
20 #include <QFile>
|
Chris@148
|
21
|
Chris@174
|
22 #include <sndfile.h>
|
Chris@174
|
23
|
Chris@1038
|
24 #include "base/BaseTypes.h"
|
Chris@1038
|
25
|
Chris@148
|
26 class DenseTimeValueModel;
|
Chris@148
|
27 class MultiSelection;
|
Chris@674
|
28 class TempWriteFile;
|
Chris@148
|
29
|
Chris@148
|
30 class WavFileWriter
|
Chris@148
|
31 {
|
Chris@148
|
32 public:
|
Chris@684
|
33 /**
|
Chris@684
|
34 * Specify the method used to open the destination file.
|
Chris@684
|
35 *
|
Chris@684
|
36 * If WriteToTemporary, the destination will be opened as a
|
Chris@684
|
37 * temporary file which is moved to the target location when the
|
Chris@684
|
38 * WavFileWriter is closed or deleted (to avoid clobbering an
|
Chris@684
|
39 * existing file with a partially written replacement).
|
Chris@684
|
40 *
|
Chris@684
|
41 * If WriteToTarget, the target file will be opened directly
|
Chris@684
|
42 * (necessary when e.g. doing a series of incremental writes to a
|
Chris@684
|
43 * file while keeping it open for reading).
|
Chris@684
|
44 */
|
Chris@684
|
45 enum FileWriteMode {
|
Chris@684
|
46 WriteToTemporary,
|
Chris@684
|
47 WriteToTarget
|
Chris@684
|
48 };
|
Chris@684
|
49
|
Chris@1040
|
50 WavFileWriter(QString path, sv_samplerate_t sampleRate, int channels,
|
Chris@684
|
51 FileWriteMode mode);
|
Chris@148
|
52 virtual ~WavFileWriter();
|
Chris@148
|
53
|
Chris@148
|
54 bool isOK() const;
|
Chris@148
|
55
|
Chris@148
|
56 virtual QString getError() const;
|
Chris@148
|
57
|
Chris@175
|
58 QString getPath() const { return m_path; }
|
Chris@175
|
59
|
Chris@174
|
60 bool writeModel(DenseTimeValueModel *source,
|
Chris@174
|
61 MultiSelection *selection = 0);
|
Chris@174
|
62
|
Chris@1325
|
63 bool writeSamples(const float *const *samples, sv_frame_t count); // count per channel
|
Chris@174
|
64
|
Chris@174
|
65 bool close();
|
Chris@148
|
66
|
Chris@148
|
67 protected:
|
Chris@148
|
68 QString m_path;
|
Chris@1040
|
69 sv_samplerate_t m_sampleRate;
|
Chris@929
|
70 int m_channels;
|
Chris@674
|
71 TempWriteFile *m_temp;
|
Chris@1348
|
72 SNDFILE *m_sndfile;
|
Chris@148
|
73 QString m_error;
|
Chris@1348
|
74 QFile *m_qfile;
|
Chris@684
|
75
|
Chris@684
|
76 QString getWriteFilename() const;
|
Chris@148
|
77 };
|
Chris@148
|
78
|
Chris@148
|
79
|
Chris@148
|
80 #endif
|