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__
26 #include <boost/signals2.hpp>
27 #include <boost/shared_ptr.hpp>
28 #include <boost/operators.hpp>
30 #include "ardour/audioregion.h"
31 #include "ardour/buffer_set.h"
39 /// Export channel base class interface for different source types
40 class ExportChannel
: public boost::less_than_comparable
<ExportChannel
>
44 virtual ~ExportChannel () {}
46 virtual void read (Sample
* data
, nframes_t frames
) const = 0;
47 virtual bool empty () const = 0;
49 /// Adds state to node passed
50 virtual void get_state (XMLNode
* node
) const = 0;
52 /// Sets state from node passed
53 virtual void set_state (XMLNode
* node
, Session
& session
) = 0;
55 // Operator< must be defined for usage in e.g. std::map or std::set to disallow duplicates when necessary
56 virtual bool operator< (ExportChannel
const & other
) const = 0;
59 /// Safe pointer for storing ExportChannels in ordered STL containers
60 class ExportChannelPtr
: public boost::shared_ptr
<ExportChannel
>
61 , public boost::less_than_comparable
<ExportChannel
>
64 ExportChannelPtr () {}
65 template<typename Y
> explicit ExportChannelPtr (Y
* ptr
) : boost::shared_ptr
<ExportChannel
> (ptr
) {}
67 bool operator< (ExportChannelPtr
const & other
) const { return **this < *other
; }
70 /// Basic export channel that reads from AudioPorts
71 class PortExportChannel
: public ExportChannel
74 typedef std::set
<AudioPort
*> PortSet
;
76 PortExportChannel () {}
78 void read (Sample
* data
, nframes_t frames
) const;
79 bool empty () const { return ports
.empty(); }
81 void get_state (XMLNode
* node
) const;
82 void set_state (XMLNode
* node
, Session
& session
);
84 bool operator< (ExportChannel
const & other
) const;
86 void add_port (AudioPort
* port
) { ports
.insert (port
); }
87 PortSet
const & get_ports () { return ports
; }
93 /// Handles RegionExportChannels and does actual reading from region
94 class RegionExportChannelFactory
103 RegionExportChannelFactory (Session
* session
, AudioRegion
const & region
, AudioTrack
& track
, Type type
);
104 ~RegionExportChannelFactory ();
106 ExportChannelPtr
create (uint32_t channel
);
107 void read (uint32_t channel
, Sample
* data
, nframes_t frames_to_read
);
111 int new_cycle_started (nframes_t
) { buffers_up_to_date
= false; return 0; }
112 void update_buffers (nframes_t frames
);
114 AudioRegion
const & region
;
118 nframes_t frames_per_cycle
;
121 bool buffers_up_to_date
;
122 nframes_t region_start
;
125 Sample
* mixdown_buffer
;
126 Sample
* gain_buffer
;
128 PBD::ScopedConnection export_connection
;
131 /// Export channel that reads from region channel
132 class RegionExportChannel
: public ExportChannel
134 friend class RegionExportChannelFactory
;
137 void read (Sample
* data
, nframes_t frames_to_read
) const { factory
.read (channel
, data
, frames_to_read
); }
138 void get_state (XMLNode
* /*node*/) const {};
139 void set_state (XMLNode
* /*node*/, Session
& /*session*/) {};
140 bool empty () const { return false; }
141 // Region export should never have duplicate channels, so there need not be any semantics here
142 bool operator< (ExportChannel
const & other
) const { return this < &other
; }
146 RegionExportChannel (RegionExportChannelFactory
& factory
, uint32_t channel
)
151 RegionExportChannelFactory
& factory
;
155 } // namespace ARDOUR