2 * Copyright (C) 2016-2018 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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/midi_buffer.h"
32 #include "ardour/processor.h"
33 #include "ardour/rt_midibuffer.h"
36 template<class T> class PlaybackBuffer;
41 class AudioFileSource;
49 template<typename T> class MidiRingBuffer;
51 class LIBARDOUR_API DiskIOProcessor : public Processor
58 NonLayered = 0x8 // deprecated (kept only for enum compat)
61 static const std::string state_node_name;
63 DiskIOProcessor (Session&, const std::string& name, Flag f);
64 virtual ~DiskIOProcessor ();
66 void set_track (boost::shared_ptr<Track>);
69 static void set_buffering_parameters (BufferingPreset bp);
71 int set_block_size (pframes_t);
72 bool configure_io (ChanCount in, ChanCount out);
73 bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
75 /** @return A number between 0 and 1, where 0 indicates that the playback/capture buffer
76 * is dry (ie the disk subsystem could not keep up) and 1 indicates that the
79 virtual float buffer_load() const = 0;
81 void set_flag (Flag f) { _flags = Flag (_flags | f); }
82 void unset_flag (Flag f) { _flags = Flag (_flags & ~f); }
84 bool hidden() const { return _flags & Hidden; }
85 bool recordable() const { return _flags & Recordable; }
87 virtual void non_realtime_locate (samplepos_t);
89 virtual void punch_in() {}
90 virtual void punch_out() {}
92 bool slaved() const { return _slaved; }
93 void set_slaved(bool yn) { _slaved = yn; }
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;
122 samplepos_t playback_sample;
124 boost::shared_ptr<Track> _track;
128 Glib::Threads::Mutex state_lock;
130 static bool get_buffering_presets (BufferingPreset bp,
131 samplecnt_t& read_chunk_size,
132 samplecnt_t& read_buffer_size,
133 samplecnt_t& write_chunk_size,
134 samplecnt_t& write_buffer_size);
136 enum TransitionType {
141 struct CaptureTransition {
143 samplepos_t capture_val; ///< The start or end file sample position
146 /** Information about one audio channel, playback or capture
147 * (depending on the derived class)
149 struct ChannelInfo : public boost::noncopyable {
151 ChannelInfo (samplecnt_t buffer_size);
152 virtual ~ChannelInfo ();
154 /** A semi-random-access ringbuffers for data to be played back.
155 * written to in the butler thread, read from in the process
158 PBD::PlaybackBuffer<Sample>* rbuf;
160 /** A ringbuffer for data to be recorded back, written to in the
161 * process thread, read from in the butler thread.
163 PBD::RingBufferNPT<Sample>* wbuf;
164 PBD::RingBufferNPT<Sample>::rw_vector rw_vector;
166 /* used only by capture */
167 boost::shared_ptr<AudioFileSource> write_source;
168 PBD::RingBufferNPT<CaptureTransition>* capture_transition_buf;
170 /* used in the butler thread only */
171 samplecnt_t curr_capture_cnt;
173 virtual void resize (samplecnt_t) = 0;
176 typedef std::vector<ChannelInfo*> ChannelList;
177 SerializedRCUManager<ChannelList> channels;
179 virtual int add_channel_to (boost::shared_ptr<ChannelList>, uint32_t how_many) = 0;
180 int remove_channel_from (boost::shared_ptr<ChannelList>, uint32_t how_many);
182 boost::shared_ptr<Playlist> _playlists[DataType::num_types];
183 PBD::ScopedConnectionList playlist_connections;
185 virtual void playlist_changed (const PBD::PropertyChange&) {}
186 virtual void playlist_deleted (boost::weak_ptr<Playlist>);
187 virtual void playlist_ranges_moved (std::list< Evoral::RangeMove<samplepos_t> > const &, bool) {}
191 MidiRingBuffer<samplepos_t>* _midi_buf;
192 gint _samples_written_to_ringbuffer;
193 gint _samples_read_from_ringbuffer;
195 static void get_location_times (const Location* location, samplepos_t* start, samplepos_t* end, samplepos_t* length);
198 } // namespace ARDOUR
200 #endif /* __ardour_disk_io_h__ */