Ardour  9.0-pre0-693-g8bf9aefe10
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 #pragma once
21 
22 #include <vector>
23 #include <string>
24 #include <exception>
25 
26 #include "pbd/ringbufferNPT.h"
27 #include "pbd/rcu.h"
28 
29 #include "ardour/midi_buffer.h"
30 #include "ardour/processor.h"
31 #include "ardour/rt_midibuffer.h"
32 #include "types.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 
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 {
147 
148  ChannelInfo (samplecnt_t buffer_size);
149  ChannelInfo (const ChannelInfo&) = delete;
150  ChannelInfo& operator= (const ChannelInfo&) = delete;
151  virtual ~ChannelInfo ();
152 
158 
164 
165  /* used only by capture */
166  std::shared_ptr<AudioFileSource> write_source;
167 
168  /* used in the butler thread only */
170 
171  virtual void resize (samplecnt_t) = 0;
172  };
173 
174  typedef std::vector<ChannelInfo*> ChannelList;
176 
177  virtual int add_channel_to (std::shared_ptr<ChannelList>, uint32_t how_many) = 0;
178  int remove_channel_from (std::shared_ptr<ChannelList>, uint32_t how_many);
179 
180  std::shared_ptr<Playlist> _playlists[DataType::num_types];
182 
183  virtual void playlist_changed (const PBD::PropertyChange&) {}
184  virtual void playlist_deleted (std::weak_ptr<Playlist>);
185  virtual void playlist_ranges_moved (std::list<Temporal::RangeMove> const &, bool) {}
186 
187  /* The MIDI stuff */
188 
190 
191  static void get_location_times (const Location* location, timepos_t* start, timepos_t* end, timecnt_t* length);
192 };
193 
194 } // namespace ARDOUR
195 
static const uint32_t num_types
Definition: data_type.h:61
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:181
MidiRingBuffer< samplepos_t > * _midi_buf
Definition: disk_io.h:189
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:175
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:185
virtual void playlist_changed(const PBD::PropertyChange &)
Definition: disk_io.h:183
std::vector< ChannelInfo * > ChannelList
Definition: disk_io.h:174
int remove_channel_from(std::shared_ptr< ChannelList >, uint32_t how_many)
virtual void configuration_changed()=0
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
PBD::Signal< void()> SpeedChanged
Definition: disk_io.h:91
PBD::Signal< void()> ReverseChanged
Definition: disk_io.h:92
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:162
ChannelInfo(const ChannelInfo &)=delete
virtual void resize(samplecnt_t)=0
PBD::RingBufferNPT< Sample >::rw_vector rw_vector
Definition: disk_io.h:163
PBD::PlaybackBuffer< Sample > * rbuf
Definition: disk_io.h:157
ChannelInfo(samplecnt_t buffer_size)
std::shared_ptr< AudioFileSource > write_source
Definition: disk_io.h:166