Make export channels own their buffers + some other small code tidy-ups. Preparation...
[ardour.git] / libs / ardour / ardour / export_channel.h
index 4fe1efa294e1be5a1c3b8c2c50414578df9250d1..34d626397674cd26b5f36d8690a7dd6fb95b26b9 100644 (file)
 #ifndef __ardour_export_channel_h__
 #define __ardour_export_channel_h__
 
-#include "ardour/audioregion.h"
-#include "ardour/buffer_set.h"
-
 #include <set>
 
+#include <boost/signals2.hpp>
 #include <boost/shared_ptr.hpp>
-#include <sigc++/signal.h>
+#include <boost/scoped_array.hpp>
+#include <boost/operators.hpp>
+
+#include "pbd/signals.h"
+
+#include "ardour/buffer_set.h"
 
 namespace ARDOUR {
 
 class Session;
 class AudioTrack;
 class AudioPort;
+class AudioRegion;
 
 /// Export channel base class interface for different source types
-class ExportChannel
+class ExportChannel : public boost::less_than_comparable<ExportChannel>
 {
   public:
 
        virtual ~ExportChannel () {}
 
-       virtual void read (Sample * data, nframes_t frames) const = 0;
+       virtual void set_max_buffer_size(framecnt_t frames) { }
+
+       virtual void read (Sample *& data, framecnt_t frames) const = 0;
        virtual bool empty () const = 0;
-       
+
        /// Adds state to node passed
        virtual void get_state (XMLNode * node) const = 0;
-       
+
        /// Sets state from node passed
        virtual void set_state (XMLNode * node, Session & session) = 0;
-       
+
        // Operator< must be defined for usage in e.g. std::map or std::set to disallow duplicates when necessary
        virtual bool operator< (ExportChannel const & other) const = 0;
 };
 
 /// Safe pointer for storing ExportChannels in ordered STL containers
 class ExportChannelPtr : public boost::shared_ptr<ExportChannel>
+                       , public boost::less_than_comparable<ExportChannel>
 {
   public:
        ExportChannelPtr () {}
@@ -71,14 +78,15 @@ class PortExportChannel : public ExportChannel
   public:
        typedef std::set<AudioPort *> PortSet;
 
-       PortExportChannel () {}
-       
-       void read (Sample * data, nframes_t frames) const;
+       PortExportChannel ();
+       void set_max_buffer_size(framecnt_t frames);
+
+       void read (Sample *& data, framecnt_t frames) const;
        bool empty () const { return ports.empty(); }
-       
+
        void get_state (XMLNode * node) const;
        void set_state (XMLNode * node, Session & session);
-       
+
        bool operator< (ExportChannel const & other) const;
 
        void add_port (AudioPort * port) { ports.insert (port); }
@@ -86,10 +94,12 @@ class PortExportChannel : public ExportChannel
 
   private:
        PortSet ports;
+       boost::scoped_array<Sample> buffer;
+       framecnt_t buffer_size;
 };
 
 /// Handles RegionExportChannels and does actual reading from region
-class RegionExportChannelFactory : public sigc::trackable
+class RegionExportChannelFactory 
 {
   public:
        enum Type {
@@ -97,31 +107,33 @@ class RegionExportChannelFactory : public sigc::trackable
                Fades,
                Processed
        };
-       
+
        RegionExportChannelFactory (Session * session, AudioRegion const & region, AudioTrack & track, Type type);
        ~RegionExportChannelFactory ();
 
        ExportChannelPtr create (uint32_t channel);
-       void read (uint32_t channel, Sample * data, nframes_t frames_to_read);
-       
+       void read (uint32_t channel, Sample *& data, framecnt_t frames_to_read);
+
   private:
 
-       int new_cycle_started () { buffers_up_to_date = false; return 0; }
-       void update_buffers (nframes_t frames);
+       int new_cycle_started (framecnt_t) { buffers_up_to_date = false; return 0; }
+       void update_buffers (framecnt_t frames);
 
        AudioRegion const & region;
        AudioTrack & track;
        Type type;
 
-       nframes_t frames_per_cycle;
+       framecnt_t frames_per_cycle;
        size_t n_channels;
        BufferSet buffers;
        bool buffers_up_to_date;
-       nframes_t region_start;
-       nframes_t position;
-       
-       Sample * mixdown_buffer;
-       Sample * gain_buffer;
+       framecnt_t region_start;
+       framecnt_t position;
+
+       boost::scoped_array<Sample> mixdown_buffer;
+       boost::scoped_array<Sample> gain_buffer;
+
+       PBD::ScopedConnection export_connection;
 };
 
 /// Export channel that reads from region channel
@@ -130,7 +142,7 @@ class RegionExportChannel : public ExportChannel
        friend class RegionExportChannelFactory;
 
   public:
-       void read (Sample * data, nframes_t frames_to_read) const { factory.read (channel, data, frames_to_read); }
+       void read (Sample *& data, framecnt_t frames_to_read) const { factory.read (channel, data, frames_to_read); }
        void get_state (XMLNode * /*node*/) const {};
        void set_state (XMLNode * /*node*/, Session & /*session*/) {};
        bool empty () const { return false; }
@@ -139,11 +151,11 @@ class RegionExportChannel : public ExportChannel
 
   private:
 
-       RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel) :
-         factory (factory),
-         channel (channel)
+       RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel)
+               : factory (factory)
+               , channel (channel)
        {}
-       
+
        RegionExportChannelFactory & factory;
        uint32_t channel;
 };