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
41 virtual void read (Sample * data, nframes_t frames) const = 0;
42 virtual bool empty () const = 0;
44 /// Adds state to node passed
45 virtual void get_state (XMLNode * node) const = 0;
47 /// Sets state from node passed
48 virtual void set_state (XMLNode * node, Session & session) = 0;
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;
54 /// Safe pointer for storing ExportChannels in ordered STL containers
55 class ExportChannelPtr : public boost::shared_ptr<ExportChannel>
58 ExportChannelPtr () {}
59 template<typename Y> explicit ExportChannelPtr (Y * ptr) : boost::shared_ptr<ExportChannel> (ptr) {}
61 bool operator< (ExportChannelPtr const & other) const { return **this < *other; }
64 /// Basic export channel that reads from AudioPorts
65 class PortExportChannel : public ExportChannel
68 typedef std::set<AudioPort *> PortSet;
70 PortExportChannel () {}
72 virtual void read (Sample * data, nframes_t frames) const;
73 virtual bool empty () const { return ports.empty(); }
75 virtual void get_state (XMLNode * node) const;
76 virtual void set_state (XMLNode * node, Session & session);
78 virtual bool operator< (ExportChannel const & other) const;
80 void add_port (AudioPort * port) { ports.insert (port); }
81 PortSet const & get_ports () { return ports; }
87 /// Handles RegionExportChannels and does actual reading from region
88 class RegionExportChannelFactory : public sigc::trackable
96 RegionExportChannelFactory (Session * session, AudioRegion const & region, AudioTrack & track, Type type);
98 ExportChannelPtr create (uint32_t channel);
99 void read (uint32_t channel, Sample * data, nframes_t frames_to_read);
103 int new_cycle_started () { buffers_up_to_date = false; return 0; }
104 void update_buffers (nframes_t frames);
106 AudioRegion const & region;
110 nframes_t frames_per_cycle;
113 bool buffers_up_to_date;
114 nframes_t region_start;
118 /// Export channel that reads from region channel
119 class RegionExportChannel : public ExportChannel
121 friend class RegionExportChannelFactory;
124 virtual void read (Sample * data, nframes_t frames_to_read) const { factory.read (channel, data, frames_to_read); }
125 virtual void get_state (XMLNode * node) const {};
126 virtual void set_state (XMLNode * node, Session & session) {};
127 virtual bool empty () const { return false; }
128 // Region export should never have duplicate channels, so there need not be any semantics here
129 virtual bool operator< (ExportChannel const & other) const { return this < &other; }
133 RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel) :
138 RegionExportChannelFactory & factory;
142 } // namespace ARDOUR