2 Copyright (C) 2008 Paul Davis
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __ardour_export_channel_h__
22 #define __ardour_export_channel_h__
27 #include <boost/scoped_array.hpp>
28 #include <boost/shared_ptr.hpp>
30 #include "pbd/signals.h"
31 #include "pbd/ringbuffer.h"
33 #include "ardour/buffer_set.h"
34 #include "ardour/export_pointers.h"
42 class CapturingProcessor;
44 /// Export channel base class interface for different source types
45 class LIBARDOUR_API ExportChannel : public boost::less_than_comparable<ExportChannel>
49 virtual ~ExportChannel () {}
51 virtual void set_max_buffer_size(samplecnt_t) { }
53 virtual void read (Sample const *& data, samplecnt_t samples) const = 0;
54 virtual bool empty () const = 0;
56 /// Adds state to node passed
57 virtual void get_state (XMLNode * node) const = 0;
59 /// Sets state from node passed
60 virtual void set_state (XMLNode * node, Session & session) = 0;
62 // Operator< must be defined for usage in e.g. std::map or std::set to disallow duplicates when necessary
63 virtual bool operator< (ExportChannel const & other) const = 0;
66 /// Basic export channel that reads from AudioPorts
67 class LIBARDOUR_API PortExportChannel : public ExportChannel
70 typedef std::set<boost::weak_ptr<AudioPort> > PortSet;
73 ~PortExportChannel ();
75 void set_max_buffer_size(samplecnt_t samples);
77 void read (Sample const *& data, samplecnt_t samples) const;
78 bool empty () const { return ports.empty(); }
80 void get_state (XMLNode * node) const;
81 void set_state (XMLNode * node, Session & session);
83 bool operator< (ExportChannel const & other) const;
85 void add_port (boost::weak_ptr<AudioPort> port) { ports.insert (port); }
86 PortSet const & get_ports () { return ports; }
90 samplecnt_t _buffer_size;
91 boost::scoped_array<Sample> _buffer;
92 std::list <boost::shared_ptr<PBD::RingBuffer<Sample> > > _delaylines;
96 /// Handles RegionExportChannels and does actual reading from region
97 class LIBARDOUR_API RegionExportChannelFactory
107 RegionExportChannelFactory (Session * session, AudioRegion const & region, AudioTrack & track, Type type);
108 ~RegionExportChannelFactory ();
110 ExportChannelPtr create (uint32_t channel);
111 void read (uint32_t channel, Sample const *& data, samplecnt_t samples_to_read);
115 int new_cycle_started (samplecnt_t) { buffers_up_to_date = false; return 0; }
116 void update_buffers (samplecnt_t samples);
118 AudioRegion const & region;
122 samplecnt_t samples_per_cycle;
125 bool buffers_up_to_date;
126 samplecnt_t region_start;
127 samplecnt_t position;
129 boost::scoped_array<Sample> mixdown_buffer;
130 boost::scoped_array<Sample> gain_buffer;
132 PBD::ScopedConnection export_connection;
135 /// Export channel that reads from region channel
136 class LIBARDOUR_API RegionExportChannel : public ExportChannel
138 friend class RegionExportChannelFactory;
141 void read (Sample const *& data, samplecnt_t samples_to_read) const { factory.read (channel, data, samples_to_read); }
142 void get_state (XMLNode * /*node*/) const {};
143 void set_state (XMLNode * /*node*/, Session & /*session*/) {};
144 bool empty () const { return false; }
145 // Region export should never have duplicate channels, so there need not be any semantics here
146 bool operator< (ExportChannel const & other) const { return this < &other; }
150 RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel)
155 RegionExportChannelFactory & factory;
159 /// Export channel for exporting from different positions in a route
160 class LIBARDOUR_API RouteExportChannel : public ExportChannel
162 class ProcessorRemover; // fwd declaration
165 RouteExportChannel(boost::shared_ptr<CapturingProcessor> processor, size_t channel,
166 boost::shared_ptr<ProcessorRemover> remover);
167 ~RouteExportChannel();
169 static void create_from_route(std::list<ExportChannelPtr> & result, boost::shared_ptr<Route> route);
171 public: // ExportChannel interface
172 void set_max_buffer_size(samplecnt_t samples);
174 void read (Sample const *& data, samplecnt_t samples) const;
175 bool empty () const { return false; }
177 void get_state (XMLNode * node) const;
178 void set_state (XMLNode * node, Session & session);
180 bool operator< (ExportChannel const & other) const;
184 // Removes the processor from the track when deleted
185 class ProcessorRemover {
187 ProcessorRemover (boost::shared_ptr<Route> route, boost::shared_ptr<CapturingProcessor> processor)
188 : route (route), processor (processor) {}
191 boost::shared_ptr<Route> route;
192 boost::shared_ptr<CapturingProcessor> processor;
195 boost::shared_ptr<CapturingProcessor> processor;
197 // Each channel keeps a ref to the remover. Last one alive
198 // will cause the processor to be removed on deletion.
199 boost::shared_ptr<ProcessorRemover> remover;
202 } // namespace ARDOUR