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