Ardour  9.0-pre0-582-g084a23a80d
tmp_file_sync.h
Go to the documentation of this file.
1 #ifndef AUDIOGRAPHER_TMP_FILE_SYNC_H
2 #define AUDIOGRAPHER_TMP_FILE_SYNC_H
3 
4 #include <cstdio>
5 #include <string>
6 
7 #include <glib.h>
8 #include "pbd/gstdio_compat.h"
9 
10 #include "sndfile_writer.h"
11 #include "sndfile_reader.h"
12 #include "tmp_file.h"
13 
14 namespace AudioGrapher
15 {
16 
18 template<typename T = DefaultSampleType>
20  : public TmpFile<T>
21 {
22  public:
23 
25  TmpFileSync (char * filename_template, int format, ChannelCount channels, samplecnt_t samplerate)
26  : SndfileHandle (g_mkstemp(filename_template), true, SndfileBase::ReadWrite, format, channels, samplerate)
27  , filename (filename_template)
28  {}
29 
31  : SndfileHandle (fileno (tmpfile()), true, SndfileBase::ReadWrite, format, channels, samplerate)
32  {}
33 
34  TmpFileSync (TmpFileSync const & other) : SndfileHandle (other) {}
35  using SndfileHandle::operator=;
36 
38  {
39  /* explicitly close first, some OS (yes I'm looking at you windows)
40  * cannot delete files that are still open
41  */
42  if (!filename.empty()) {
44  std::remove(filename.c_str());
45  }
46  }
47 
48  void process (ProcessContext<T> const & c)
49  {
51 
54  }
55  }
56 
57  using Sink<T>::process;
58 
59  private:
60  std::string filename;
61 };
62 
63 } // namespace
64 
65 #endif // AUDIOGRAPHER_TMP_FILE_SYNC_H
bool has_flag(Flag flag) const
Base class for all classes using libsndfile.
Definition: sndfile_base.h:13
int samplerate(void) const
Definition: sndfile.hh:103
int channels(void) const
Definition: sndfile.hh:102
int format(void) const
Definition: sndfile.hh:101
virtual void process(ProcessContext< T > const &c)
Writes data to file.
A temporary file deleted after this class is destructed.
Definition: tmp_file_sync.h:21
TmpFileSync(char *filename_template, int format, ChannelCount channels, samplecnt_t samplerate)
filename_template must match the requirements for mkstemp, i.e. end in "XXXXXX"
Definition: tmp_file_sync.h:25
TmpFileSync(int format, ChannelCount channels, samplecnt_t samplerate)
Definition: tmp_file_sync.h:30
TmpFileSync(TmpFileSync const &other)
Definition: tmp_file_sync.h:34
void process(ProcessContext< T > const &c)
Definition: tmp_file_sync.h:48
A temporary file deleted after this class is destructed.
Definition: tmp_file.h:21
PBD::Signal< void()> FileFlushed
Definition: tmp_file.h:24