Don't move automation to follow region when a region has only been trimmed rather...
[ArdourMidi.git] / libs / ardour / ardour / export_channel.h
blob51ecabee25c8156e74d3cc2530c0f80d5199c3c4
1 /*
2 Copyright (C) 2008 Paul Davis
3 Author: Sakari Bergen
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 <set>
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"
33 namespace ARDOUR {
35 class Session;
36 class AudioTrack;
37 class AudioPort;
39 /// Export channel base class interface for different source types
40 class ExportChannel : public boost::less_than_comparable<ExportChannel>
42 public:
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>
63 public:
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
73 public:
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; }
89 private:
90 PortSet ports;
93 /// Handles RegionExportChannels and does actual reading from region
94 class RegionExportChannelFactory
96 public:
97 enum Type {
98 Raw,
99 Fades,
100 Processed
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);
109 private:
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;
115 AudioTrack & track;
116 Type type;
118 nframes_t frames_per_cycle;
119 size_t n_channels;
120 BufferSet buffers;
121 bool buffers_up_to_date;
122 nframes_t region_start;
123 nframes_t position;
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;
136 public:
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; }
144 private:
146 RegionExportChannel (RegionExportChannelFactory & factory, uint32_t channel)
147 : factory (factory)
148 , channel (channel)
151 RegionExportChannelFactory & factory;
152 uint32_t channel;
155 } // namespace ARDOUR
157 #endif