no need to close a file that will not be removed (and has no name)
[ardour.git] / libs / audiographer / audiographer / sndfile / sndfile_writer.h
index aa06a2c3ef2a6a27f48a10ad099193259eaac315..984ec01d4126bfa180b83bfc3e4779241d2e7d81 100644 (file)
@@ -1,14 +1,17 @@
 #ifndef AUDIOGRAPHER_SNDFILE_WRITER_H
 #define AUDIOGRAPHER_SNDFILE_WRITER_H
 
-#include <boost/signals2.hpp>
-#include <boost/format.hpp>
 #include <string>
 
+#include <boost/format.hpp>
+
 #include "audiographer/flag_debuggable.h"
 #include "audiographer/sink.h"
 #include "audiographer/types.h"
 #include "audiographer/sndfile/sndfile_base.h"
+#include "audiographer/broadcast_info.h"
+
+#include "pbd/signals.h"
 
 namespace AudioGrapher
 {
@@ -24,17 +27,29 @@ class SndfileWriter
   , public FlagDebuggable<>
 {
   public:
-       SndfileWriter (std::string const & path, int format, ChannelCount channels, nframes_t samplerate)
+       SndfileWriter (std::string const & path, int format, ChannelCount channels, framecnt_t samplerate, boost::shared_ptr<BroadcastInfo> broadcast_info)
          : SndfileHandle (path, Write, format, channels, samplerate)
          , path (path)
        {
-               add_supported_flag (ProcessContext<T>::EndOfInput);
+               init();
+
+               if (broadcast_info) {
+                       broadcast_info->write_to_file (this);
+               }
        }
        
        virtual ~SndfileWriter () {}
        
-       SndfileWriter (SndfileWriter const & other) : SndfileHandle (other) {}
+       SndfileWriter (SndfileWriter const & other)
+               : SndfileHandle (other)
+       {
+               init();
+       }
+
        using SndfileHandle::operator=;
+
+       framecnt_t get_frames_written() const { return frames_written; }
+       void       reset_frames_written_count() { frames_written = 0; }
        
        /// Writes data to file
        void process (ProcessContext<T> const & c)
@@ -47,7 +62,9 @@ class SndfileWriter
                                % c.channels() % channels()));
                }
                
-               nframes_t written = write (c.data(), c.frames());
+               framecnt_t const written = write (c.data(), c.frames());
+               frames_written += written;
+
                if (throw_level (ThrowProcess) && written != c.frames()) {
                        throw Exception (*this, boost::str (boost::format
                                ("Could not write data to output file (%1%)")
@@ -62,19 +79,26 @@ class SndfileWriter
        
        using Sink<T>::process;
        
-       boost::signals2::signal<void (std::string)> FileWritten;
+       PBD::Signal1<void, std::string> FileWritten;
 
   protected:
        /// SndfileHandle has to be constructed directly by deriving classes
        SndfileWriter ()
        {
+               init();
+       }
+
+       void init()
+       {
+               frames_written = 0;
                add_supported_flag (ProcessContext<T>::EndOfInput);
        }
-       
+
   protected:
        std::string path;
+       framecnt_t frames_written;
 };
 
 } // namespace
 
-#endif // AUDIOGRAPHER_SNDFILE_WRITER_H
\ No newline at end of file
+#endif // AUDIOGRAPHER_SNDFILE_WRITER_H