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_io_h__
21 #define __ardour_disk_io_h__
27 #include "pbd/ringbufferNPT.h"
30 #include "ardour/interpolation.h"
31 #include "ardour/processor.h"
35 class AudioFileSource;
44 template<typename T> class MidiRingBuffer;
46 class LIBARDOUR_API DiskIOProcessor : public Processor
56 static const std::string state_node_name;
58 DiskIOProcessor (Session&, const std::string& name, Flag f);
60 void set_route (boost::shared_ptr<Route>);
62 static void set_buffering_parameters (BufferingPreset bp);
64 int set_block_size (pframes_t);
65 bool configure_io (ChanCount in, ChanCount out);
66 bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
68 /** @return A number between 0 and 1, where 0 indicates that the playback buffer
69 * is dry (ie the disk subsystem could not keep up) and 1 indicates that the
72 virtual float playback_buffer_load() const = 0;
73 virtual float capture_buffer_load() const = 0;
75 void set_flag (Flag f) { _flags = Flag (_flags | f); }
76 void unset_flag (Flag f) { _flags = Flag (_flags & ~f); }
78 bool hidden() const { return _flags & Hidden; }
79 bool recordable() const { return _flags & Recordable; }
80 bool non_layered() const { return _flags & NonLayered; }
81 bool reversed() const { return _actual_speed < 0.0f; }
82 double speed() const { return _visible_speed; }
84 virtual void non_realtime_locate (framepos_t);
86 void non_realtime_set_speed ();
87 bool realtime_set_speed (double sp, bool global);
89 virtual void punch_in() {}
90 virtual void punch_out() {}
92 virtual float buffer_load() const = 0;
94 bool slaved() const { return _slaved; }
95 void set_slaved(bool yn) { _slaved = yn; }
97 int set_loop (Location *loc);
99 PBD::Signal1<void,Location *> LoopSet;
100 PBD::Signal0<void> SpeedChanged;
101 PBD::Signal0<void> ReverseChanged;
103 int set_state (const XMLNode&, int version);
105 int add_channel (uint32_t how_many);
106 int remove_channel (uint32_t how_many);
108 bool need_butler() const { return _need_butler; }
110 boost::shared_ptr<Playlist> get_playlist (DataType dt) const { return _playlists[dt]; }
111 boost::shared_ptr<MidiPlaylist> midi_playlist() const;
112 boost::shared_ptr<AudioPlaylist> audio_playlist() const;
114 virtual void playlist_modified () {}
115 virtual int use_playlist (DataType, boost::shared_ptr<Playlist>);
116 virtual int use_new_playlist (DataType);
117 virtual int use_copy_playlist (DataType);
119 PBD::Signal1<void,DataType> PlaylistChanged;
122 friend class Auditioner;
123 virtual int seek (framepos_t which_sample, bool complete_refill = false) = 0;
127 uint32_t i_am_the_modifier;
128 double _visible_speed;
129 double _actual_speed;
131 double _target_speed;
132 /* items needed for speed change logic */
133 bool _buffer_reallocation_required;
136 Location* loop_location;
138 framecnt_t wrap_buffer_size;
139 framecnt_t speed_buffer_size;
141 boost::shared_ptr<Route> _route;
145 Glib::Threads::Mutex state_lock;
147 static bool get_buffering_presets (BufferingPreset bp,
148 framecnt_t& read_chunk_size,
149 framecnt_t& read_buffer_size,
150 framecnt_t& write_chunk_size,
151 framecnt_t& write_buffer_size);
153 enum TransitionType {
158 struct CaptureTransition {
160 framepos_t capture_val; ///< The start or end file frame position
163 /** Information about one audio channel, playback or capture
164 * (depending on the derived class)
166 struct ChannelInfo : public boost::noncopyable {
168 ChannelInfo (framecnt_t buffer_size);
171 /** A ringbuffer for data to be played back, written to in the
172 butler thread, read from in the process thread.
174 PBD::RingBufferNPT<Sample>* buf;
176 Sample* scrub_buffer;
177 Sample* scrub_forward_buffer;
178 Sample* scrub_reverse_buffer;
180 PBD::RingBufferNPT<Sample>::rw_vector rw_vector;
182 /* used only by capture */
183 boost::shared_ptr<AudioFileSource> write_source;
184 PBD::RingBufferNPT<CaptureTransition> * capture_transition_buf;
185 // the following are used in the butler thread only
186 framecnt_t curr_capture_cnt;
188 void resize (framecnt_t);
191 typedef std::vector<ChannelInfo*> ChannelList;
192 SerializedRCUManager<ChannelList> channels;
194 int add_channel_to (boost::shared_ptr<ChannelList>, uint32_t how_many);
195 int remove_channel_from (boost::shared_ptr<ChannelList>, uint32_t how_many);
197 CubicInterpolation interpolation;
199 boost::shared_ptr<Playlist> _playlists[DataType::num_types];
200 PBD::ScopedConnectionList playlist_connections;
202 virtual void playlist_changed (const PBD::PropertyChange&) {}
203 virtual void playlist_deleted (boost::weak_ptr<Playlist>);
204 virtual void playlist_ranges_moved (std::list< Evoral::RangeMove<framepos_t> > const &, bool) {}
205 int find_and_use_playlist (DataType, std::string const &);
209 MidiRingBuffer<framepos_t>* _midi_buf;
210 gint _frames_written_to_ringbuffer;
211 gint _frames_read_from_ringbuffer;
212 CubicMidiInterpolation midi_interpolation;
215 } // namespace ARDOUR
217 #endif /* __ardour_disk_io_h__ */