Ardour  8.12
disk_io.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
4  *
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.
9  *
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.
14  *
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.
18  */
19 
20 #ifndef __ardour_disk_io_h__
21 #define __ardour_disk_io_h__
22 
23 #include <vector>
24 #include <string>
25 #include <exception>
26 
27 #include "pbd/ringbufferNPT.h"
28 #include "pbd/rcu.h"
29 
30 #include "ardour/midi_buffer.h"
31 #include "ardour/processor.h"
32 #include "ardour/rt_midibuffer.h"
33 
34 namespace PBD {
35  template<class T> class PlaybackBuffer;
36 }
37 
38 namespace ARDOUR {
39 
40 class AudioFileSource;
41 class AudioPlaylist;
42 class Location;
43 class MidiPlaylist;
44 class Playlist;
45 class Track;
46 class Session;
47 
48 template<typename T> class MidiRingBuffer;
49 
51 {
52 public:
53  enum Flag {
54  Recordable = 0x1,
55  Hidden = 0x2,
56  NonLayered = 0x8 // deprecated (kept only for enum compat)
57  };
58 
59  static const std::string state_node_name;
60 
61  DiskIOProcessor (Session&, Track&, const std::string& name, Flag f, Temporal::TimeDomainProvider const &);
62 
63  virtual ~DiskIOProcessor ();
64 
66 
70 
75  virtual float buffer_load() const = 0;
76 
77  void set_flag (Flag f) { _flags = Flag (_flags | f); }
78  void unset_flag (Flag f) { _flags = Flag (_flags & ~f); }
79 
80  bool hidden() const { return _flags & Hidden; }
81  bool recordable() const { return _flags & Recordable; }
82 
84 
85  virtual void punch_in() {}
86  virtual void punch_out() {}
87 
88  bool slaved() const { return _slaved; }
89  void set_slaved(bool yn) { _slaved = yn; }
90 
91  PBD::Signal0<void> SpeedChanged;
92  PBD::Signal0<void> ReverseChanged;
93 
94  int set_state (const XMLNode&, int version);
95 
96  int add_channel (uint32_t how_many);
97  int remove_channel (uint32_t how_many);
98 
99  bool need_butler() const { return _need_butler; }
100 
101  std::shared_ptr<Playlist> get_playlist (DataType dt) const { return _playlists[dt]; }
102  std::shared_ptr<MidiPlaylist> midi_playlist() const;
103  std::shared_ptr<AudioPlaylist> audio_playlist() const;
104 
105  virtual void playlist_modified () {}
106  virtual int use_playlist (DataType, std::shared_ptr<Playlist>);
107 
108  virtual void adjust_buffering() = 0;
109 
110 protected:
111  friend class Auditioner;
112  virtual int seek (samplepos_t which_sample, bool complete_refill = false) = 0;
113  virtual void configuration_changed () = 0;
114 
115 protected:
117  bool _slaved;
122 
123  void init ();
124 
125  Glib::Threads::Mutex state_lock;
126 
128  samplecnt_t& read_chunk_size,
129  samplecnt_t& read_buffer_size,
130  samplecnt_t& write_chunk_size,
131  samplecnt_t& write_buffer_size);
132 
134  CaptureStart = 0,
135  CaptureEnd
136  };
137 
141  };
142 
146  struct ChannelInfo : public boost::noncopyable {
147 
148  ChannelInfo (samplecnt_t buffer_size);
149  virtual ~ChannelInfo ();
150 
156 
162 
163  /* used only by capture */
164  std::shared_ptr<AudioFileSource> write_source;
166 
167  /* used in the butler thread only */
169 
170  virtual void resize (samplecnt_t) = 0;
171  };
172 
173  typedef std::vector<ChannelInfo*> ChannelList;
175 
176  virtual int add_channel_to (std::shared_ptr<ChannelList>, uint32_t how_many) = 0;
177  int remove_channel_from (std::shared_ptr<ChannelList>, uint32_t how_many);
178 
179  std::shared_ptr<Playlist> _playlists[DataType::num_types];
181 
182  virtual void playlist_changed (const PBD::PropertyChange&) {}
183  virtual void playlist_deleted (std::weak_ptr<Playlist>);
184  virtual void playlist_ranges_moved (std::list<Temporal::RangeMove> const &, bool) {}
185 
186  /* The MIDI stuff */
187 
189 
190  static void get_location_times (const Location* location, timepos_t* start, timepos_t* end, timecnt_t* length);
191 };
192 
193 } // namespace ARDOUR
194 
195 #endif /* __ardour_disk_io_h__ */
static const uint32_t num_types
Definition: data_type.h:62
static void get_location_times(const Location *location, timepos_t *start, timepos_t *end, timecnt_t *length)
virtual float buffer_load() const =0
bool configure_io(ChanCount in, ChanCount out)
std::shared_ptr< MidiPlaylist > midi_playlist() const
int set_state(const XMLNode &, int version)
bool hidden() const
Definition: disk_io.h:80
virtual int seek(samplepos_t which_sample, bool complete_refill=false)=0
bool slaved() const
Definition: disk_io.h:88
std::shared_ptr< Playlist > get_playlist(DataType dt) const
Definition: disk_io.h:101
std::shared_ptr< AudioPlaylist > audio_playlist() const
virtual int use_playlist(DataType, std::shared_ptr< Playlist >)
virtual void non_realtime_locate(samplepos_t)
bool can_support_io_configuration(const ChanCount &in, ChanCount &out)
PBD::ScopedConnectionList playlist_connections
Definition: disk_io.h:180
MidiRingBuffer< samplepos_t > * _midi_buf
Definition: disk_io.h:188
static const std::string state_node_name
Definition: disk_io.h:59
int set_block_size(pframes_t)
Glib::Threads::Mutex state_lock
Definition: disk_io.h:125
void unset_flag(Flag f)
Definition: disk_io.h:78
SerializedRCUManager< ChannelList > channels
Definition: disk_io.h:174
int remove_channel(uint32_t how_many)
static void set_buffering_parameters(BufferingPreset bp)
virtual void playlist_modified()
Definition: disk_io.h:105
int add_channel(uint32_t how_many)
virtual void playlist_ranges_moved(std::list< Temporal::RangeMove > const &, bool)
Definition: disk_io.h:184
virtual void playlist_changed(const PBD::PropertyChange &)
Definition: disk_io.h:182
std::vector< ChannelInfo * > ChannelList
Definition: disk_io.h:173
int remove_channel_from(std::shared_ptr< ChannelList >, uint32_t how_many)
virtual void configuration_changed()=0
PBD::Signal0< void > SpeedChanged
Definition: disk_io.h:91
PBD::Signal0< void > ReverseChanged
Definition: disk_io.h:92
DiskIOProcessor(Session &, Track &, const std::string &name, Flag f, Temporal::TimeDomainProvider const &)
bool recordable() const
Definition: disk_io.h:81
void set_flag(Flag f)
Definition: disk_io.h:77
virtual void playlist_deleted(std::weak_ptr< Playlist >)
virtual void adjust_buffering()=0
static bool get_buffering_presets(BufferingPreset bp, samplecnt_t &read_chunk_size, samplecnt_t &read_buffer_size, samplecnt_t &write_chunk_size, samplecnt_t &write_buffer_size)
void set_slaved(bool yn)
Definition: disk_io.h:89
virtual void punch_out()
Definition: disk_io.h:86
samplepos_t playback_sample
Definition: disk_io.h:119
bool need_butler() const
Definition: disk_io.h:99
virtual void punch_in()
Definition: disk_io.h:85
virtual int add_channel_to(std::shared_ptr< ChannelList >, uint32_t how_many)=0
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
PBD::PropertyDescriptor< timecnt_t > length
PBD::PropertyDescriptor< timepos_t > start
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
Temporal::samplepos_t samplepos_t
DebugBits MidiRingBuffer
Definition: axis_view.h:42
samplepos_t capture_val
The start or end file sample position.
Definition: disk_io.h:140
PBD::RingBufferNPT< Sample > * wbuf
Definition: disk_io.h:160
virtual void resize(samplecnt_t)=0
PBD::RingBufferNPT< Sample >::rw_vector rw_vector
Definition: disk_io.h:161
PBD::RingBufferNPT< CaptureTransition > * capture_transition_buf
Definition: disk_io.h:165
PBD::PlaybackBuffer< Sample > * rbuf
Definition: disk_io.h:155
ChannelInfo(samplecnt_t buffer_size)
std::shared_ptr< AudioFileSource > write_source
Definition: disk_io.h:164