Fix some compiling warnings and errors in OS X
[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 <ardour/audioregion.h>
25 #include <ardour/audio_track.h>
26 #include <ardour/buffer_set.h>
27
28 #include <set>
29
30 #include <boost/shared_ptr.hpp>
31 #include <sigc++/signal.h>
32
33 namespace ARDOUR {
34
35 class Session;
36
37 /// Export channel base class interface for different source types
38 class ExportChannel
39 {
40   public:
41
42         virtual ~ExportChannel () {}
43
44         virtual void read (Sample * data, nframes_t frames) const = 0;
45         virtual bool empty () const = 0;
46         
47         /// Adds state to node passed
48         virtual void get_state (XMLNode * node) const = 0;
49         
50         /// Sets state from node passed
51         virtual void set_state (XMLNode * node, Session & session) = 0;
52         
53         // Operator< must be defined for usage in e.g. std::map or std::set to disallow duplicates when necessary
54         virtual bool operator< (ExportChannel const & other) const = 0;
55 };
56
57 /// Safe pointer for storing ExportChannels in ordered STL containers
58 class ExportChannelPtr : public boost::shared_ptr<ExportChannel>
59 {
60   public:
61         ExportChannelPtr () {}
62         template<typename Y> explicit ExportChannelPtr (Y * ptr) : boost::shared_ptr<ExportChannel> (ptr) {}
63
64         bool operator< (ExportChannelPtr const & other) const { return **this < *other; }
65 };
66
67 /// Basic export channel that reads from AudioPorts
68 class PortExportChannel : public ExportChannel
69 {
70   public:
71         typedef std::set<AudioPort *> PortSet;
72
73         PortExportChannel () {}
74         
75         void read (Sample * data, nframes_t frames) const;
76         bool empty () const { return ports.empty(); }
77         
78         void get_state (XMLNode * node) const;
79         void set_state (XMLNode * node, Session & session);
80         
81         bool operator< (ExportChannel const & other) const;
82
83         void add_port (AudioPort * port) { ports.insert (port); }
84         PortSet const & get_ports () { return ports; }
85
86   private:
87         PortSet ports;
88 };
89
90 /// Handles RegionExportChannels and does actual reading from region
91 class RegionExportChannelFactory : public sigc::trackable
92 {
93   public:
94         enum Type {
95                 Raw,
96                 Fades,
97                 Processed
98         };
99         
100         RegionExportChannelFactory (Session * session, AudioRegion const & region, AudioTrack & track, Type type);
101         ~RegionExportChannelFactory ();
102
103         ExportChannelPtr create (uint32_t channel);
104         void read (uint32_t channel, Sample * data, nframes_t frames_to_read);
105         
106   private:
107
108         int new_cycle_started () { buffers_up_to_date = false; return 0; }
109         void update_buffers (nframes_t frames);
110
111         AudioRegion const & region;
112         AudioTrack & track;
113         Type type;
114
115         nframes_t frames_per_cycle;
116         size_t n_channels;
117         BufferSet buffers;
118         bool buffers_up_to_date;
119         nframes_t region_start;
120         nframes_t position;
121         
122         Sample * mixdown_buffer;
123         Sample * gain_buffer;
124 };
125
126 /// Export channel that reads from region channel
127 class RegionExportChannel : public ExportChannel
128 {
129         friend class RegionExportChannelFactory;
130
131   public:
132         void read (Sample * data, nframes_t frames_to_read) const { factory.read (channel, data, frames_to_read); }
133         void get_state (XMLNode * node) const {};
134         void set_state (XMLNode * node, Session & session) {};
135         bool empty () const { return false; }
136         // Region export should never have duplicate channels, so there need not be any semantics here
137         bool operator< (ExportChannel const & other) const { return this < &other; }
138
139   private:
140
141         RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel) :
142           factory (factory),
143           channel (channel)
144         {}
145         
146         RegionExportChannelFactory & factory;
147         uint32_t channel;
148 };
149
150 } // namespace ARDOUR
151
152 #endif