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"
39 class LIBARDOUR_API DiskIOProcessor : public Processor
49 static const std::string state_node_name;
51 DiskIOProcessor (Session&, const std::string& name, Flag f);
53 static void set_buffering_parameters (BufferingPreset bp);
55 /** @return A number between 0 and 1, where 0 indicates that the playback buffer
56 * is dry (ie the disk subsystem could not keep up) and 1 indicates that the
59 virtual float playback_buffer_load() const = 0;
60 virtual float capture_buffer_load() const = 0;
62 void set_flag (Flag f) { _flags = Flag (_flags | f); }
63 void unset_flag (Flag f) { _flags = Flag (_flags & ~f); }
65 bool hidden() const { return _flags & Hidden; }
66 bool recordable() const { return _flags & Recordable; }
67 bool non_layered() const { return _flags & NonLayered; }
68 bool reversed() const { return _actual_speed < 0.0f; }
69 double speed() const { return _visible_speed; }
71 ChanCount n_channels() { return _n_channels; }
73 void non_realtime_set_speed ();
74 bool realtime_set_speed (double sp, bool global);
76 virtual void punch_in() {}
77 virtual void punch_out() {}
79 virtual float buffer_load() const = 0;
81 bool slaved() const { return _slaved; }
82 void set_slaved(bool yn) { _slaved = yn; }
84 int set_loop (Location *loc);
86 PBD::Signal1<void,Location *> LoopSet;
87 PBD::Signal0<void> SpeedChanged;
88 PBD::Signal0<void> ReverseChanged;
90 int set_state (const XMLNode&, int version);
92 int add_channel (uint32_t how_many);
93 int remove_channel (uint32_t how_many);
95 bool need_butler() const { return _need_butler; }
98 friend class Auditioner;
99 virtual int seek (framepos_t which_sample, bool complete_refill = false) = 0;
103 uint32_t i_am_the_modifier;
104 ChanCount _n_channels;
105 double _visible_speed;
106 double _actual_speed;
108 double _target_speed;
109 /* items needed for speed change logic */
110 bool _buffer_reallocation_required;
113 Location* loop_location;
115 framecnt_t wrap_buffer_size;
116 framecnt_t speed_buffer_size;
119 Glib::Threads::Mutex state_lock;
121 static bool get_buffering_presets (BufferingPreset bp,
122 framecnt_t& read_chunk_size,
123 framecnt_t& read_buffer_size,
124 framecnt_t& write_chunk_size,
125 framecnt_t& write_buffer_size);
127 virtual void allocate_temporary_buffers () = 0;
129 /** Information about one audio channel, playback or capture
130 * (depending on the derived class)
132 struct ChannelInfo : public boost::noncopyable {
134 ChannelInfo (framecnt_t buffer_size,
135 framecnt_t speed_buffer_size,
136 framecnt_t wrap_buffer_size);
140 Sample *speed_buffer;
141 Sample *current_buffer;
143 /** A ringbuffer for data to be played back, written to in the
144 butler thread, read from in the process thread.
146 PBD::RingBufferNPT<Sample>* buf;
148 Sample* scrub_buffer;
149 Sample* scrub_forward_buffer;
150 Sample* scrub_reverse_buffer;
152 PBD::RingBufferNPT<Sample>::rw_vector read_vector;
154 void resize (framecnt_t);
157 typedef std::vector<ChannelInfo*> ChannelList;
158 SerializedRCUManager<ChannelList> channels;
160 int add_channel_to (boost::shared_ptr<ChannelList>, uint32_t how_many);
161 int remove_channel_from (boost::shared_ptr<ChannelList>, uint32_t how_many);
163 CubicInterpolation interpolation;
167 } // namespace ARDOUR
169 #endif /* __ardour_disk_io_h__ */