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
53 NonLayered = 0x8 // deprecated (kept only for enum compat)
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>);
63 static void set_buffering_parameters (BufferingPreset bp);
65 int set_block_size (pframes_t);
66 bool configure_io (ChanCount in, ChanCount out);
67 bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
69 /** @return A number between 0 and 1, where 0 indicates that the playback/capture buffer
70 * is dry (ie the disk subsystem could not keep up) and 1 indicates that the
73 virtual float 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; }
81 virtual void non_realtime_locate (samplepos_t);
83 void non_realtime_speed_change ();
84 bool realtime_speed_change ();
86 virtual void punch_in() {}
87 virtual void punch_out() {}
89 bool slaved() const { return _slaved; }
90 void set_slaved(bool yn) { _slaved = yn; }
92 int set_loop (Location *loc);
94 PBD::Signal1<void,Location *> LoopSet;
95 PBD::Signal0<void> SpeedChanged;
96 PBD::Signal0<void> ReverseChanged;
98 int set_state (const XMLNode&, int version);
100 int add_channel (uint32_t how_many);
101 int remove_channel (uint32_t how_many);
103 bool need_butler() const { return _need_butler; }
105 boost::shared_ptr<Playlist> get_playlist (DataType dt) const { return _playlists[dt]; }
106 boost::shared_ptr<MidiPlaylist> midi_playlist() const;
107 boost::shared_ptr<AudioPlaylist> audio_playlist() const;
109 virtual void playlist_modified () {}
110 virtual int use_playlist (DataType, boost::shared_ptr<Playlist>);
112 virtual void adjust_buffering() = 0;
115 friend class Auditioner;
116 virtual int seek (samplepos_t which_sample, bool complete_refill = false) = 0;
120 uint32_t i_am_the_modifier;
121 double _actual_speed;
122 double _target_speed;
123 /* items needed for speed change logic */
124 bool _buffer_reallocation_required;
127 Location* loop_location;
129 samplepos_t playback_sample;
130 samplecnt_t wrap_buffer_size;
131 samplecnt_t speed_buffer_size;
133 boost::shared_ptr<Route> _route;
137 Glib::Threads::Mutex state_lock;
139 static bool get_buffering_presets (BufferingPreset bp,
140 samplecnt_t& read_chunk_size,
141 samplecnt_t& read_buffer_size,
142 samplecnt_t& write_chunk_size,
143 samplecnt_t& write_buffer_size);
145 enum TransitionType {
150 struct CaptureTransition {
152 samplepos_t capture_val; ///< The start or end file sample position
155 /** Information about one audio channel, playback or capture
156 * (depending on the derived class)
158 struct ChannelInfo : public boost::noncopyable {
160 ChannelInfo (samplecnt_t buffer_size);
163 /** A ringbuffer for data to be played back, written to in the
164 butler thread, read from in the process thread.
166 PBD::RingBufferNPT<Sample>* buf;
168 Sample* scrub_buffer;
169 Sample* scrub_forward_buffer;
170 Sample* scrub_reverse_buffer;
172 PBD::RingBufferNPT<Sample>::rw_vector rw_vector;
174 /* used only by capture */
175 boost::shared_ptr<AudioFileSource> write_source;
176 PBD::RingBufferNPT<CaptureTransition> * capture_transition_buf;
177 // the following are used in the butler thread only
178 samplecnt_t curr_capture_cnt;
180 void resize (samplecnt_t);
183 typedef std::vector<ChannelInfo*> ChannelList;
184 SerializedRCUManager<ChannelList> channels;
186 int add_channel_to (boost::shared_ptr<ChannelList>, uint32_t how_many);
187 int remove_channel_from (boost::shared_ptr<ChannelList>, uint32_t how_many);
189 CubicInterpolation interpolation;
191 boost::shared_ptr<Playlist> _playlists[DataType::num_types];
192 PBD::ScopedConnectionList playlist_connections;
194 virtual void playlist_changed (const PBD::PropertyChange&) {}
195 virtual void playlist_deleted (boost::weak_ptr<Playlist>);
196 virtual void playlist_ranges_moved (std::list< Evoral::RangeMove<samplepos_t> > const &, bool) {}
200 MidiRingBuffer<samplepos_t>* _midi_buf;
201 gint _samples_written_to_ringbuffer;
202 gint _samples_read_from_ringbuffer;
203 CubicMidiInterpolation midi_interpolation;
205 static void get_location_times (const Location* location, samplepos_t* start, samplepos_t* end, samplepos_t* length);
208 } // namespace ARDOUR
210 #endif /* __ardour_disk_io_h__ */