summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/export_channel.h
blob: d9e39c88505717053b4c944c69758101a88217a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
    Copyright (C) 2008 Paul Davis
    Author: Sakari Bergen

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __ardour_export_channel_h__
#define __ardour_export_channel_h__

#include <ardour/audioregion.h>
#include <ardour/audio_track.h>
#include <ardour/buffer_set.h>

#include <set>

#include <boost/shared_ptr.hpp>
#include <sigc++/signal.h>

namespace ARDOUR {

class Session;

/// Export channel base class interface for different source types
class ExportChannel
{
  public:
	virtual void read (Sample * data, nframes_t frames) const = 0;
	virtual bool empty () const = 0;
	
	/// Adds state to node passed
	virtual void get_state (XMLNode * node) const = 0;
	
	/// Sets state from node passed
	virtual void set_state (XMLNode * node, Session & session) = 0;
	
	// Operator< must be defined for usage in e.g. std::map or std::set to disallow duplicates when necessary
	virtual bool operator< (ExportChannel const & other) const = 0;
};

/// Safe pointer for storing ExportChannels in ordered STL containers
class ExportChannelPtr : public boost::shared_ptr<ExportChannel>
{
  public:
	ExportChannelPtr () {}
	template<typename Y> explicit ExportChannelPtr (Y * ptr) : boost::shared_ptr<ExportChannel> (ptr) {}

	bool operator< (ExportChannelPtr const & other) const { return **this < *other; }
};

/// Basic export channel that reads from AudioPorts
class PortExportChannel : public ExportChannel
{
  public:
	typedef std::set<AudioPort *> PortSet;

	PortExportChannel () {}
	
	virtual void read (Sample * data, nframes_t frames) const;
	virtual bool empty () const { return ports.empty(); }
	
	virtual void get_state (XMLNode * node) const;
	virtual void set_state (XMLNode * node, Session & session);
	
	virtual bool operator< (ExportChannel const & other) const;

	void add_port (AudioPort * port) { ports.insert (port); }
	PortSet const & get_ports () { return ports; }

  private:
	PortSet ports;
};

/// Handles RegionExportChannels and does actual reading from region
class RegionExportChannelFactory : public sigc::trackable
{
  public:
	enum Type {
		Raw,
		Fades,
		Processed
	};
	
	RegionExportChannelFactory (Session * session, AudioRegion const & region, AudioTrack & track, Type type);
	~RegionExportChannelFactory ();

	ExportChannelPtr create (uint32_t channel);
	void read (uint32_t channel, Sample * data, nframes_t frames_to_read);
	
  private:

	int new_cycle_started () { buffers_up_to_date = false; return 0; }
	void update_buffers (nframes_t frames);

	AudioRegion const & region;
	AudioTrack & track;
	Type type;

	nframes_t frames_per_cycle;
	size_t n_channels;
	BufferSet buffers;
	bool buffers_up_to_date;
	nframes_t region_start;
	nframes_t position;
	
	Sample * mixdown_buffer;
	Sample * gain_buffer;
};

/// Export channel that reads from region channel
class RegionExportChannel : public ExportChannel
{
	friend class RegionExportChannelFactory;

  public:
	virtual void read (Sample * data, nframes_t frames_to_read) const { factory.read (channel, data, frames_to_read); }
	virtual void get_state (XMLNode * node) const {};
	virtual void set_state (XMLNode * node, Session & session) {};
	virtual bool empty () const { return false; }
	// Region export should never have duplicate channels, so there need not be any semantics here
	virtual bool operator< (ExportChannel const & other) const { return this < &other; }

  private:

	RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel) :
	  factory (factory),
	  channel (channel)
	{}
	
	RegionExportChannelFactory & factory;
	uint32_t channel;
};

} // namespace ARDOUR

#endif