2 Copyright (C) 2009-2016 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifndef __ardour_disk_reader_h__
21 #define __ardour_disk_reader_h__
23 #include "pbd/ringbufferNPT.h"
26 #include "ardour/disk_io.h"
27 #include "ardour/interpolation.h"
36 class LIBARDOUR_API DiskReader : public DiskIOProcessor
39 DiskReader (Session&, std::string const & name, DiskIOProcessor::Flag f = DiskIOProcessor::Flag (0));
42 bool set_name (std::string const & str);
44 static framecnt_t chunk_frames() { return _chunk_frames; }
45 static framecnt_t default_chunk_frames ();
46 static void set_chunk_frames (framecnt_t n) { _chunk_frames = n; }
48 void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, double speed, pframes_t /*nframes*/, bool /*result_required*/);
49 int set_block_size (pframes_t);
50 bool configure_io (ChanCount in, ChanCount out);
51 bool can_support_io_configuration (const ChanCount& in, ChanCount& out) = 0;
52 void realtime_handle_transport_stopped ();
53 void realtime_locate ();
54 void non_realtime_locate (framepos_t);
55 int overwrite_existing_buffers ();
56 void set_pending_overwrite (bool yn);
58 framecnt_t roll_delay() const { return _roll_delay; }
59 void set_roll_delay (framecnt_t);
61 virtual XMLNode& state (bool full);
62 int set_state (const XMLNode&, int version);
64 boost::shared_ptr<Playlist> playlist();
65 boost::shared_ptr<Playlist> get_playlist (DataType);
66 boost::shared_ptr<MidiPlaylist> midi_playlist();
67 boost::shared_ptr<AudioPlaylist> audio_playlist();
69 virtual void playlist_modified ();
70 virtual int use_playlist (boost::shared_ptr<Playlist>);
71 virtual int use_new_playlist ();
72 virtual int use_copy_playlist ();
74 PBD::Signal0<void> PlaylistChanged;
75 PBD::Signal0<void> AlignmentStyleChanged;
77 float buffer_load() const;
79 void move_processor_automation (boost::weak_ptr<Processor>, std::list<Evoral::RangeMove<framepos_t> > const &);
81 /* called by the Butler in a non-realtime context */
84 return _do_refill (_mixdown_buffer, _gain_buffer, 0);
87 /** For non-butler contexts (allocates temporary working buffers)
89 * This accessible method has a default argument; derived classes
90 * must inherit the virtual method that we call which does NOT
91 * have a default argument, to avoid complications with inheritance
93 int do_refill_with_alloc (bool partial_fill = true) {
94 return _do_refill_with_alloc (partial_fill);
97 bool pending_overwrite () const { return _pending_overwrite; }
99 virtual int find_and_use_playlist (std::string const &);
101 // Working buffers for do_refill (butler thread)
102 static void allocate_working_buffers();
103 static void free_working_buffers();
105 void adjust_buffering ();
107 int can_internal_playback_seek (framecnt_t distance);
108 int seek (framepos_t frame, bool complete_refill = false);
110 int add_channel (uint32_t how_many);
111 int remove_channel (uint32_t how_many);
113 PBD::Signal0<void> Underrun;
116 boost::shared_ptr<Playlist> _playlist;
118 virtual void playlist_changed (const PBD::PropertyChange&);
119 virtual void playlist_deleted (boost::weak_ptr<Playlist>);
120 virtual void playlist_ranges_moved (std::list< Evoral::RangeMove<framepos_t> > const &, bool);
124 typedef std::map<DataType,boost::shared_ptr<Playlist> > Playlists;
126 /** The number of frames by which this diskstream's output should be delayed
127 with respect to the transport frame. This is used for latency compensation.
129 framecnt_t _roll_delay;
130 Playlists _playlists;
131 framepos_t overwrite_frame;
132 off_t overwrite_offset;
133 bool _pending_overwrite;
134 bool overwrite_queued;
135 IOChange input_change_pending;
136 framecnt_t wrap_buffer_size;
137 framecnt_t speed_buffer_size;
138 framepos_t file_frame;
139 framepos_t playback_sample;
140 MonitorChoice _monitoring_choice;
142 PBD::ScopedConnectionList playlist_connections;
144 virtual int _do_refill_with_alloc (bool partial_fill);
146 static framecnt_t _chunk_frames;
148 /** Information about one of our channels */
149 struct ChannelInfo : public boost::noncopyable {
151 ChannelInfo (framecnt_t buffer_size,
152 framecnt_t speed_buffer_size,
153 framecnt_t wrap_buffer_size);
157 Sample *speed_buffer;
158 Sample *current_buffer;
160 /** A ringbuffer for data to be played back, written to in the
161 butler thread, read from in the process thread.
163 PBD::RingBufferNPT<Sample> *buf;
165 Sample* scrub_buffer;
166 Sample* scrub_forward_buffer;
167 Sample* scrub_reverse_buffer;
169 PBD::RingBufferNPT<Sample>::rw_vector read_vector;
171 void resize (framecnt_t);
174 typedef std::vector<ChannelInfo*> ChannelList;
175 SerializedRCUManager<ChannelList> channels;
177 CubicInterpolation interpolation;
179 int read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
180 framepos_t& start, framecnt_t cnt,
181 int channel, bool reversed);
183 static Sample* _mixdown_buffer;
184 static gain_t* _gain_buffer;
186 int _do_refill (Sample *mixdown_buffer, float *gain_buffer, framecnt_t fill_level);
188 int add_channel_to (boost::shared_ptr<ChannelList>, uint32_t how_many);
189 int remove_channel_from (boost::shared_ptr<ChannelList>, uint32_t how_many);
191 int internal_playback_seek (framecnt_t distance);
192 frameoffset_t calculate_playback_distance (pframes_t);
194 void allocate_temporary_buffers();
199 #endif /* __ardour_disk_reader_h__ */