diff data/fileio/WavFileWriter.h @ 684:bcca512445f3

Provide option for WavFileWriter to write directly to target file, rather than always using a temporary; make use of it in WritableWaveFileModel so we can read from target file without having to close it first
author Chris Cannam
date Wed, 11 May 2011 11:04:35 +0100
parents 920e3880f7b4
children 59e7fe1b1003
line wrap: on
line diff
--- a/data/fileio/WavFileWriter.h	Wed May 11 11:04:02 2011 +0100
+++ b/data/fileio/WavFileWriter.h	Wed May 11 11:04:35 2011 +0100
@@ -27,7 +27,25 @@
 class WavFileWriter
 {
 public:
-    WavFileWriter(QString path, size_t sampleRate, size_t channels);
+    /**
+     * Specify the method used to open the destination file.
+     * 
+     * If WriteToTemporary, the destination will be opened as a
+     * temporary file which is moved to the target location when the
+     * WavFileWriter is closed or deleted (to avoid clobbering an
+     * existing file with a partially written replacement).
+     * 
+     * If WriteToTarget, the target file will be opened directly
+     * (necessary when e.g. doing a series of incremental writes to a
+     * file while keeping it open for reading).
+     */
+    enum FileWriteMode {
+        WriteToTemporary,
+        WriteToTarget
+    };
+
+    WavFileWriter(QString path, size_t sampleRate, size_t channels,
+                  FileWriteMode mode);
     virtual ~WavFileWriter();
 
     bool isOK() const;
@@ -50,6 +68,8 @@
     TempWriteFile *m_temp;
     SNDFILE *m_file;
     QString m_error;
+
+    QString getWriteFilename() const;
 };