Ardour  9.0-pre0-582-g084a23a80d
disk_writer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017-2018 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2017 Paul Davis <paul@linuxaudiosystems.com>
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 <atomic>
23 #include <list>
24 #include <vector>
25 #include <optional>
26 
27 #include "ardour/disk_io.h"
29 #include "ardour/midi_buffer.h"
30 
31 namespace ARDOUR
32 {
33 class AudioFileSource;
34 class SMFSource;
35 class MidiSource;
36 
38 {
39 public:
40  DiskWriter (Session&, Track&, std::string const& name,
43 
44  bool set_name (std::string const& str);
45  std::string display_name () const;
46 
47  bool recordable () const { return _flags & Recordable; }
48 
49  static samplecnt_t chunk_samples () { return _chunk_samples; }
51  static void set_chunk_samples (samplecnt_t n) { _chunk_samples = n; }
52 
53  void run (BufferSet& /*bufs*/, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/,
54  double speed, pframes_t /*nframes*/, bool /*result_required*/);
55 
58 
59  int set_state (const XMLNode&, int version);
60 
61  bool set_write_source_name (const std::string& str);
62 
63  std::string write_source_name () const;
64 
65  std::shared_ptr<AudioFileSource> audio_write_source (uint32_t n = 0) {
66  std::shared_ptr<ChannelList const> c = channels.reader ();
67  if (n < c->size ()) {
68  return (*c)[n]->write_source;
69  }
70  return std::shared_ptr<AudioFileSource> ();
71  }
72 
73  std::shared_ptr<SMFSource> midi_write_source () const { return _midi_write_source; }
74 
75  std::string steal_write_source_name ();
76  int use_new_write_source (DataType, uint32_t n = 0);
77  void reset_write_sources (bool mark_write_complete);
78 
79  AlignStyle alignment_style () const { return _alignment_style; }
80  void set_align_style (AlignStyle, bool force = false);
81 
83 
85 
86  std::list<std::shared_ptr<Source> >& last_capture_sources () { return _last_capture_sources; }
87 
88  bool record_enabled () const { return _record_enabled.load(); }
89  bool record_safe () const { return _record_safe.load(); }
90 
91  void set_record_enabled (bool yn);
92  void set_record_safe (bool yn);
94 
98 
99  samplepos_t get_capture_start_sample (uint32_t n = 0) const;
100  samplecnt_t get_captured_samples (uint32_t n = 0) const;
101 
102  float buffer_load () const;
103 
104  int seek (samplepos_t sample, bool complete_refill);
105 
106  static PBD::Signal<void()> Overrun;
107 
109 
114  PBD::Signal<void(std::weak_ptr<MidiSource> )> DataRecorded;
115 
118 
119  void transport_looped (samplepos_t transport_sample);
120  void transport_stopped_wallclock (struct tm&, time_t, bool abort);
121 
123 
124  std::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
125 
126 protected:
127  friend class Track;
128 
131  : DiskIOProcessor::ChannelInfo (buffer_size)
132  {
133  resize (buffer_size);
134  }
136  };
137 
138  virtual XMLNode& state () const;
139 
140  int use_playlist (DataType, std::shared_ptr<Playlist>);
141 
142  int do_flush (RunContext context, bool force = false);
143 
145 
146 private:
148 
149  int add_channel_to (std::shared_ptr<ChannelList>, uint32_t how_many);
150 
155 
158 
160  samplecnt_t nframes, samplecnt_t& rec_nframes,
161  samplecnt_t& rec_offset);
162 
163  void check_record_status (samplepos_t transport_sample, double speed, bool can_record);
164  void finish_capture (std::shared_ptr<ChannelList const> c);
165  void reset_capture ();
166 
168 
170  mutable Glib::Threads::Mutex capture_info_lock;
171 
173 
174  std::optional<samplepos_t> _capture_start_sample;
175 
184  std::string _write_source_name;
187 
190 
191  std::atomic<int> _record_enabled;
192  std::atomic<int> _record_safe;
193  std::atomic<int> _samples_pending_write;
194  std::atomic<int> _num_captured_loops;
195 
196  std::shared_ptr<SMFSource> _midi_write_source;
197 
198  std::list<std::shared_ptr<Source> > _last_capture_sources;
199  std::vector<std::shared_ptr<AudioFileSource> > capturing_sources;
200 
205  mutable Glib::Threads::Mutex _gui_feed_reset_mutex;
206 };
207 
208 } // namespace
209 
void run(BufferSet &, samplepos_t, samplepos_t, double speed, pframes_t, bool)
void transport_stopped_wallclock(struct tm &, time_t, bool abort)
int do_flush(RunContext context, bool force=false)
void disengage_record_enable()
PBD::Signal< void()> RecordSafeChanged
Definition: disk_writer.h:117
int set_state(const XMLNode &, int version)
void set_note_mode(NoteMode m)
AlignStyle _alignment_style
Definition: disk_writer.h:183
bool set_name(std::string const &str)
bool record_safe() const
Definition: disk_writer.h:89
AlignStyle alignment_style() const
Definition: disk_writer.h:79
DiskWriter(Session &, Track &, std::string const &name, DiskIOProcessor::Flag f=DiskIOProcessor::Flag(0))
static samplecnt_t default_chunk_samples()
static PBD::Signal< void()> Overrun
Definition: disk_writer.h:106
CaptureInfos capture_info
Definition: disk_writer.h:169
XrunPositions _xruns
Definition: disk_writer.h:179
std::shared_ptr< SMFSource > _midi_write_source
Definition: disk_writer.h:196
samplepos_t _first_recordable_sample
Definition: disk_writer.h:180
void disengage_record_safe()
void realtime_handle_transport_stopped()
void non_realtime_locate(samplepos_t)
std::vector< std::shared_ptr< AudioFileSource > > capturing_sources
Definition: disk_writer.h:199
float buffer_load() const
void configuration_changed()
std::optional< samplepos_t > _capture_start_sample
Definition: disk_writer.h:174
void engage_record_enable()
int use_playlist(DataType, std::shared_ptr< Playlist >)
void transport_looped(samplepos_t transport_sample)
PBD::Signal< void()> AlignmentStyleChanged
Definition: disk_writer.h:82
std::shared_ptr< AudioFileSource > audio_write_source(uint32_t n=0)
Definition: disk_writer.h:65
std::shared_ptr< SMFSource > midi_write_source() const
Definition: disk_writer.h:73
samplepos_t _accumulated_capture_offset
Definition: disk_writer.h:186
static samplecnt_t chunk_samples()
Definition: disk_writer.h:49
std::atomic< int > _record_enabled
Definition: disk_writer.h:191
bool configure_io(ChanCount in, ChanCount out)
Glib::Threads::Mutex _gui_feed_reset_mutex
Definition: disk_writer.h:205
std::atomic< int > _record_safe
Definition: disk_writer.h:192
void loop(samplepos_t)
int use_new_write_source(DataType, uint32_t n=0)
samplecnt_t _capture_captured
Definition: disk_writer.h:176
void set_record_safe(bool yn)
samplepos_t _last_recordable_sample
Definition: disk_writer.h:181
samplepos_t current_capture_end() const
static void set_chunk_samples(samplecnt_t n)
Definition: disk_writer.h:51
std::atomic< int > _samples_pending_write
Definition: disk_writer.h:193
Glib::Threads::Mutex capture_info_lock
Definition: disk_writer.h:170
samplepos_t _transport_loop_sample
Definition: disk_writer.h:189
PBD::Signal< void()> RecordEnableChanged
Definition: disk_writer.h:116
samplecnt_t get_captured_samples(uint32_t n=0) const
bool record_enabled() const
Definition: disk_writer.h:88
void set_align_style(AlignStyle, bool force=false)
std::string _write_source_name
Definition: disk_writer.h:184
std::string steal_write_source_name()
std::list< std::shared_ptr< Source > > _last_capture_sources
Definition: disk_writer.h:198
PBD::Signal< void(std::weak_ptr< MidiSource >)> DataRecorded
Definition: disk_writer.h:114
void set_record_enabled(bool yn)
bool prep_record_disable()
virtual XMLNode & state() const
void reset_write_sources(bool mark_write_complete)
samplepos_t current_capture_start() const
std::shared_ptr< MidiBuffer > get_gui_feed_buffer() const
void check_record_status(samplepos_t transport_sample, double speed, bool can_record)
int add_channel_to(std::shared_ptr< ChannelList >, uint32_t how_many)
std::string display_name() const
bool set_write_source_name(const std::string &str)
void calculate_record_range(Temporal::OverlapType ot, samplepos_t transport_sample, samplecnt_t nframes, samplecnt_t &rec_nframes, samplecnt_t &rec_offset)
samplepos_t get_capture_start_sample(uint32_t n=0) const
int seek(samplepos_t sample, bool complete_refill)
samplepos_t get_capture_start_sample_locked(uint32_t n=0) const
bool recordable() const
Definition: disk_writer.h:47
std::string write_source_name() const
void finish_capture(std::shared_ptr< ChannelList const > c)
static samplecnt_t _chunk_samples
Definition: disk_writer.h:147
std::atomic< int > _num_captured_loops
Definition: disk_writer.h:194
std::list< std::shared_ptr< Source > > & last_capture_sources()
Definition: disk_writer.h:86
EventRingBuffer< samplepos_t > _gui_feed_fifo
Definition: disk_writer.h:204
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
uint32_t pframes_t
Temporal::samplecnt_t samplecnt_t
std::vector< samplepos_t > XrunPositions
std::vector< CaptureInfo * > CaptureInfos
Temporal::samplepos_t samplepos_t
WriterChannelInfo(samplecnt_t buffer_size)
Definition: disk_writer.h:130