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__
24 #include <ardour/audioregion.h>
25 #include <ardour/audio_track.h>
26 #include <ardour/buffer_set.h>
30 #include <boost/shared_ptr.hpp>
31 #include <sigc++/signal.h>
37 /// Export channel base class interface for different source types
42 virtual ~ExportChannel () {}
44 virtual void read (Sample * data, nframes_t frames) const = 0;
45 virtual bool empty () const = 0;
47 /// Adds state to node passed
48 virtual void get_state (XMLNode * node) const = 0;
50 /// Sets state from node passed
51 virtual void set_state (XMLNode * node, Session & session) = 0;
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;
57 /// Safe pointer for storing ExportChannels in ordered STL containers
58 class ExportChannelPtr : public boost::shared_ptr<ExportChannel>
61 ExportChannelPtr () {}
62 template<typename Y> explicit ExportChannelPtr (Y * ptr) : boost::shared_ptr<ExportChannel> (ptr) {}
64 bool operator< (ExportChannelPtr const & other) const { return **this < *other; }
67 /// Basic export channel that reads from AudioPorts
68 class PortExportChannel : public ExportChannel
71 typedef std::set<AudioPort *> PortSet;
73 PortExportChannel () {}
75 void read (Sample * data, nframes_t frames) const;
76 bool empty () const { return ports.empty(); }
78 void get_state (XMLNode * node) const;
79 void set_state (XMLNode * node, Session & session);
81 bool operator< (ExportChannel const & other) const;
83 void add_port (AudioPort * port) { ports.insert (port); }
84 PortSet const & get_ports () { return ports; }
90 /// Handles RegionExportChannels and does actual reading from region
91 class RegionExportChannelFactory : public sigc::trackable
100 RegionExportChannelFactory (Session * session, AudioRegion const & region, AudioTrack & track, Type type);
101 ~RegionExportChannelFactory ();
103 ExportChannelPtr create (uint32_t channel);
104 void read (uint32_t channel, Sample * data, nframes_t frames_to_read);
108 int new_cycle_started () { buffers_up_to_date = false; return 0; }
109 void update_buffers (nframes_t frames);
111 AudioRegion const & region;
115 nframes_t frames_per_cycle;
118 bool buffers_up_to_date;
119 nframes_t region_start;
122 Sample * mixdown_buffer;
123 Sample * gain_buffer;
126 /// Export channel that reads from region channel
127 class RegionExportChannel : public ExportChannel
129 friend class RegionExportChannelFactory;
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; }
141 RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel) :
146 RegionExportChannelFactory & factory;
150 } // namespace ARDOUR