1 #ifndef AUDIOGRAPHER_CMDPIPE_WRITER_H
2 #define AUDIOGRAPHER_CMDPIPE_WRITER_H
6 #include <boost/format.hpp>
8 #include "audiographer/flag_debuggable.h"
9 #include "audiographer/sink.h"
10 #include "audiographer/types.h"
12 #include "pbd/signals.h"
13 #include "pbd/system_exec.h"
15 namespace AudioGrapher
18 /** Writer for audio files using libsndfile.
19 * Only short, int and float are valid template parameters
21 template <typename T = DefaultSampleType>
25 , public FlagDebuggable<>
28 CmdPipeWriter (PBD::SystemExec* proc, std::string const& path)
33 add_supported_flag (ProcessContext<T>::EndOfInput);
36 virtual ~CmdPipeWriter () {
40 samplecnt_t get_samples_written() const { return samples_written; }
41 void reset_samples_written_count() { samples_written = 0; }
48 virtual void process (ProcessContext<T> const & c)
50 check_flags (*this, c);
52 if (!_proc || !_proc->is_running()) {
53 throw Exception (*this, boost::str (boost::format
54 ("Target encoder process is not running")));
57 const size_t bytes_per_sample = sizeof (T);
58 samplecnt_t const written = _proc->write_to_stdin ((const void*) c.data(), c.samples() * bytes_per_sample) / bytes_per_sample;
59 samples_written += written;
61 if (throw_level (ThrowProcess) && written != c.samples()) {
62 throw Exception (*this, boost::str (boost::format
63 ("Could not write data to output file")));
66 if (c.has_flag(ProcessContext<T>::EndOfInput)) {
67 _proc->close_stdin ();
72 using Sink<T>::process;
74 PBD::Signal1<void, std::string> FileWritten;
77 CmdPipeWriter (CmdPipeWriter const & other) {}
79 samplecnt_t samples_written;
80 PBD::SystemExec* _proc;