1 #ifndef AUDIOGRAPHER_TMP_FILE_SYNC_H
2 #define AUDIOGRAPHER_TMP_FILE_SYNC_H
8 #include "pbd/gstdio_compat.h"
10 #include "sndfile_writer.h"
11 #include "sndfile_reader.h"
14 namespace AudioGrapher
17 /// A temporary file deleted after this class is destructed
18 template<typename T = DefaultSampleType>
24 /// \a filename_template must match the requirements for mkstemp, i.e. end in "XXXXXX"
25 TmpFileSync (char * filename_template, int format, ChannelCount channels, framecnt_t samplerate)
26 : SndfileHandle (g_mkstemp(filename_template), true, SndfileBase::ReadWrite, format, channels, samplerate)
27 , filename (filename_template)
30 TmpFileSync (int format, ChannelCount channels, framecnt_t samplerate)
31 : SndfileHandle (fileno (tmpfile()), true, SndfileBase::ReadWrite, format, channels, samplerate)
34 TmpFileSync (TmpFileSync const & other) : SndfileHandle (other) {}
35 using SndfileHandle::operator=;
39 /* explicitly close first, some OS (yes I'm looking at you windows)
40 * cannot delete files that are still open
42 if (!filename.empty()) {
44 std::remove(filename.c_str());
48 void process (ProcessContext<T> const & c)
50 SndfileWriter<T>::process (c);
52 if (c.has_flag(ProcessContext<T>::EndOfInput)) {
53 TmpFile<T>::FileFlushed ();
57 using Sink<T>::process;
65 #endif // AUDIOGRAPHER_TMP_FILE_SYNC_H