Update audiographer GPL boilerplate and (C) from git log
[ardour.git] / libs / audiographer / audiographer / sndfile / sndfile_writer.h
index 6e8ecc2567df3f01201ee8e2c4835cbc0b86f4a7..b106eba6a8efdb7fa67fd96b745ff6862d3c8020 100644 (file)
@@ -27,35 +27,39 @@ class SndfileWriter
   , public FlagDebuggable<>
 {
   public:
-       SndfileWriter (std::string const & path, int format, ChannelCount channels, framecnt_t samplerate, boost::shared_ptr<BroadcastInfo> broadcast_info)
+       SndfileWriter (std::string const & path, int format, ChannelCount channels, samplecnt_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) {}
+
        using SndfileHandle::operator=;
-       
+
+       samplecnt_t get_samples_written() const { return samples_written; }
+       void       reset_samples_written_count() { samples_written = 0; }
+
        /// Writes data to file
-       void process (ProcessContext<T> const & c)
+       virtual void process (ProcessContext<T> const & c)
        {
                check_flags (*this, c);
-               
+
                if (throw_level (ThrowStrict) && c.channels() != channels()) {
                        throw Exception (*this, boost::str (boost::format
                                ("Wrong number of channels given to process(), %1% instead of %2%")
                                % c.channels() % channels()));
                }
-               
-               framecnt_t const written = write (c.data(), c.frames());
-               if (throw_level (ThrowProcess) && written != c.frames()) {
+
+               samplecnt_t const written = write (c.data(), c.samples());
+               samples_written += written;
+
+               if (throw_level (ThrowProcess) && written != c.samples()) {
                        throw Exception (*this, boost::str (boost::format
                                ("Could not write data to output file (%1%)")
                                % strError()));
@@ -66,20 +70,34 @@ class SndfileWriter
                        FileWritten (path);
                }
        }
-       
+
        using Sink<T>::process;
-       
+
        PBD::Signal1<void, std::string> FileWritten;
 
   protected:
        /// SndfileHandle has to be constructed directly by deriving classes
        SndfileWriter ()
        {
+               init();
+       }
+
+       virtual void init()
+       {
+               if (SF_ERR_NO_ERROR != SndfileHandle::error ()) {
+                       throw Exception (*this, boost::str (boost::format
+                                               ("Could create output file (%1%)") % path));
+               }
+               samples_written = 0;
                add_supported_flag (ProcessContext<T>::EndOfInput);
        }
-       
+
   protected:
        std::string path;
+       samplecnt_t samples_written;
+
+       private:
+       SndfileWriter (SndfileWriter const & other) {}
 };
 
 } // namespace