fix merge conflicts with master
[ardour.git] / libs / audiographer / audiographer / sndfile / tmp_file.h
index e312007247c9a3f3c3a5d27e5bbd0fa1861c5f5a..facb872abfe08feabeefd797a6ccaab1fb0f865b 100644 (file)
@@ -1,6 +1,12 @@
 #ifndef AUDIOGRAPHER_TMP_FILE_H
 #define AUDIOGRAPHER_TMP_FILE_H
 
+#include <cstdio>
+#include <string>
+
+#include <glib.h>
+#include <glib/gstdio.h>
+
 #include "sndfile_writer.h"
 #include "sndfile_reader.h"
 
@@ -12,16 +18,31 @@ template<typename T = DefaultSampleType>
 class TmpFile : public SndfileWriter<T>, public SndfileReader<T>
 {
   public:
-       
-       TmpFile (int format, ChannelCount channels, nframes_t samplerate)
+
+       /// \a filename_template must match the requirements for mkstemp, i.e. end in "XXXXXX"
+       TmpFile (char * filename_template, int format, ChannelCount channels, framecnt_t samplerate)
+               : SndfileHandle (g_mkstemp(filename_template), true, SndfileBase::ReadWrite, format, channels, samplerate)
+               , filename (filename_template)
+       {}
+
+       TmpFile (int format, ChannelCount channels, framecnt_t samplerate)
          : SndfileHandle (fileno (tmpfile()), true, SndfileBase::ReadWrite, format, channels, samplerate)
        {}
-       
+
        TmpFile (TmpFile const & other) : SndfileHandle (other) {}
        using SndfileHandle::operator=;
-       
+
+       ~TmpFile()
+       {
+               if (!filename.empty()) {
+                       std::remove(filename.c_str());
+               }
+       }
+
+  private:
+       std::string filename;
 };
 
 } // namespace
 
-#endif // AUDIOGRAPHER_TMP_FILE_H
\ No newline at end of file
+#endif // AUDIOGRAPHER_TMP_FILE_H