fixes for 98% of all the warnings/errors reported by OS X gcc on tiger
[ardour.git] / libs / ardour / ardour / export_channel.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
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.
9
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.
14
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.
18
19 */
20
21 #ifndef __ardour_export_channel_h__
22 #define __ardour_export_channel_h__
23
24 #include <set>
25
26 #include <boost/signals2.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/scoped_array.hpp>
29
30 #include "pbd/signals.h"
31
32 #include "ardour/buffer_set.h"
33 #include "ardour/export_pointers.h"
34
35 namespace ARDOUR {
36
37 class Session;
38 class AudioTrack;
39 class AudioPort;
40 class AudioRegion;
41 class CapturingProcessor;
42
43 /// Export channel base class interface for different source types
44 class ExportChannel : public boost::less_than_comparable<ExportChannel>
45 {
46   public:
47
48         virtual ~ExportChannel () {}
49
50         virtual void set_max_buffer_size(framecnt_t) { }
51
52         virtual void read (Sample const *& data, framecnt_t frames) const = 0;
53         virtual bool empty () const = 0;
54
55         /// Adds state to node passed
56         virtual void get_state (XMLNode * node) const = 0;
57
58         /// Sets state from node passed
59         virtual void set_state (XMLNode * node, Session & session) = 0;
60
61         // Operator< must be defined for usage in e.g. std::map or std::set to disallow duplicates when necessary
62         virtual bool operator< (ExportChannel const & other) const = 0;
63 };
64
65 /// Basic export channel that reads from AudioPorts
66 class PortExportChannel : public ExportChannel
67 {
68   public:
69         typedef std::set<AudioPort *> PortSet;
70
71         PortExportChannel ();
72         void set_max_buffer_size(framecnt_t frames);
73
74         void read (Sample const *& data, framecnt_t frames) const;
75         bool empty () const { return ports.empty(); }
76
77         void get_state (XMLNode * node) const;
78         void set_state (XMLNode * node, Session & session);
79
80         bool operator< (ExportChannel const & other) const;
81
82         void add_port (AudioPort * port) { ports.insert (port); }
83         PortSet const & get_ports () { return ports; }
84
85   private:
86         PortSet ports;
87         boost::scoped_array<Sample> buffer;
88         framecnt_t buffer_size;
89 };
90
91
92 /// Handles RegionExportChannels and does actual reading from region
93 class RegionExportChannelFactory
94 {
95   public:
96         enum Type {
97                 Raw,
98                 Fades,
99                 Processed
100         };
101
102         RegionExportChannelFactory (Session * session, AudioRegion const & region, AudioTrack & track, Type type);
103         ~RegionExportChannelFactory ();
104
105         ExportChannelPtr create (uint32_t channel);
106         void read (uint32_t channel, Sample const *& data, framecnt_t frames_to_read);
107
108   private:
109
110         int new_cycle_started (framecnt_t) { buffers_up_to_date = false; return 0; }
111         void update_buffers (framecnt_t frames);
112
113         AudioRegion const & region;
114         AudioTrack & track;
115         Type type;
116
117         framecnt_t frames_per_cycle;
118         size_t n_channels;
119         BufferSet buffers;
120         bool buffers_up_to_date;
121         framecnt_t region_start;
122         framecnt_t position;
123
124         boost::scoped_array<Sample> mixdown_buffer;
125         boost::scoped_array<Sample> gain_buffer;
126
127         PBD::ScopedConnection export_connection;
128 };
129
130 /// Export channel that reads from region channel
131 class RegionExportChannel : public ExportChannel
132 {
133         friend class RegionExportChannelFactory;
134
135   public:
136         void read (Sample const *& data, framecnt_t frames_to_read) const { factory.read (channel, data, frames_to_read); }
137         void get_state (XMLNode * /*node*/) const {};
138         void set_state (XMLNode * /*node*/, Session & /*session*/) {};
139         bool empty () const { return false; }
140         // Region export should never have duplicate channels, so there need not be any semantics here
141         bool operator< (ExportChannel const & other) const { return this < &other; }
142
143   private:
144
145         RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel)
146                 : factory (factory)
147                 , channel (channel)
148         {}
149
150         RegionExportChannelFactory & factory;
151         uint32_t channel;
152 };
153
154 /// Export channel for exporting from different positions in a route
155 class RouteExportChannel : public ExportChannel
156 {
157         class ProcessorRemover; // fwd declaration
158
159   public:
160         RouteExportChannel(boost::shared_ptr<CapturingProcessor> processor, size_t channel,
161                            boost::shared_ptr<ProcessorRemover> remover);
162         ~RouteExportChannel();
163
164         static void create_from_route(std::list<ExportChannelPtr> & result, Route & route);
165
166   public: // ExportChannel interface
167         void set_max_buffer_size(framecnt_t frames);
168
169         void read (Sample const *& data, framecnt_t frames) const;
170         bool empty () const { return false; }
171
172         void get_state (XMLNode * node) const;
173         void set_state (XMLNode * node, Session & session);
174
175         bool operator< (ExportChannel const & other) const;
176
177   private:
178
179         // Removes the processor from the track when deleted
180         class ProcessorRemover {
181           public:
182                 ProcessorRemover (Route & route, boost::shared_ptr<CapturingProcessor> processor)
183                         : route (route), processor (processor) {}
184                 ~ProcessorRemover();
185           private:
186                 Route & route;
187                 boost::shared_ptr<CapturingProcessor> processor;
188         };
189
190         boost::shared_ptr<CapturingProcessor> processor;
191         size_t channel;
192         // Each channel keeps a ref to the remover. Last one alive
193         // will cause the processor to be removed on deletion.
194         boost::shared_ptr<ProcessorRemover> remover;
195 };
196
197 } // namespace ARDOUR
198
199 #endif