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_writer_h__
21 #define __ardour_disk_writer_h__
28 #include "ardour/disk_io.h"
29 #include "ardour/midi_buffer.h"
34 class AudioFileSource;
38 class LIBARDOUR_API DiskWriter : public DiskIOProcessor
41 DiskWriter (Session&, std::string const & name, DiskIOProcessor::Flag f = DiskIOProcessor::Flag (0));
44 bool set_name (std::string const & str);
45 std::string display_name() const { return std::string (_("recorder")); }
47 virtual bool set_write_source_name (const std::string& str);
49 bool recordable() const { return _flags & Recordable; }
51 static samplecnt_t chunk_samples() { return _chunk_samples; }
52 static samplecnt_t default_chunk_samples ();
53 static void set_chunk_samples (samplecnt_t n) { _chunk_samples = n; }
55 void run (BufferSet& /*bufs*/, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double speed, pframes_t /*nframes*/, bool /*result_required*/);
56 void non_realtime_locate (samplepos_t);
57 void realtime_handle_transport_stopped ();
59 virtual XMLNode& state (bool full);
60 int set_state (const XMLNode&, int version);
62 std::string write_source_name () const {
63 if (_write_source_name.empty()) {
66 return _write_source_name;
70 boost::shared_ptr<AudioFileSource> audio_write_source (uint32_t n=0) {
71 boost::shared_ptr<ChannelList> c = channels.reader();
73 return (*c)[n]->write_source;
76 return boost::shared_ptr<AudioFileSource>();
79 boost::shared_ptr<SMFSource> midi_write_source () { return _midi_write_source; }
81 virtual std::string steal_write_source_name ();
82 int use_new_write_source (DataType, uint32_t n = 0);
83 void reset_write_sources (bool, bool force = false);
85 AlignStyle alignment_style() const { return _alignment_style; }
86 void set_align_style (AlignStyle, bool force=false);
88 PBD::Signal0<void> AlignmentStyleChanged;
90 void set_input_latency (samplecnt_t);
92 bool configure_io (ChanCount in, ChanCount out);
94 std::list<boost::shared_ptr<Source> >& last_capture_sources () { return _last_capture_sources; }
96 bool record_enabled() const { return g_atomic_int_get (const_cast<gint*>(&_record_enabled)); }
97 bool record_safe () const { return g_atomic_int_get (const_cast<gint*>(&_record_safe)); }
98 virtual void set_record_enabled (bool yn);
99 virtual void set_record_safe (bool yn);
101 bool destructive() const { return _flags & Destructive; }
102 int set_destructive (bool yn);
103 int set_non_layered (bool yn);
104 bool can_become_destructive (bool& requires_bounce) const;
106 /** @return Start position of currently-running capture (in session samples) */
107 samplepos_t current_capture_start() const { return capture_start_sample; }
108 samplepos_t current_capture_end() const { return capture_start_sample + capture_captured; }
109 samplepos_t get_capture_start_sample (uint32_t n = 0) const;
110 samplecnt_t get_captured_samples (uint32_t n = 0) const;
112 float buffer_load() const;
114 virtual void request_input_monitoring (bool) {}
115 virtual void ensure_input_monitoring (bool) {}
117 samplecnt_t capture_offset() const { return _capture_offset; }
118 virtual void set_capture_offset ();
120 int seek (samplepos_t sample, bool complete_refill);
122 static PBD::Signal0<void> Overrun;
124 void set_note_mode (NoteMode m);
126 /** Emitted when some MIDI data has been received for recording.
127 * Parameter is the source that it is destined for.
128 * A caller can get a copy of the data with get_gui_feed_buffer ()
130 PBD::Signal1<void, boost::weak_ptr<MidiSource> > DataRecorded;
132 PBD::Signal0<void> RecordEnableChanged;
133 PBD::Signal0<void> RecordSafeChanged;
135 void check_record_status (samplepos_t transport_sample, bool can_record);
137 void transport_looped (samplepos_t transport_sample);
138 void transport_stopped_wallclock (struct tm&, time_t, bool abort);
140 void adjust_buffering ();
144 int do_flush (RunContext context, bool force = false);
146 void get_input_sources ();
147 void prepare_record_status (samplepos_t /*capture_start_sample*/);
148 void set_align_style_from_io();
149 void setup_destructive_playlist ();
150 void use_destructive_playlist ();
151 void prepare_to_stop (samplepos_t transport_pos, samplepos_t audible_sample);
153 void engage_record_enable ();
154 void disengage_record_enable ();
155 void engage_record_safe ();
156 void disengage_record_safe ();
158 bool prep_record_enable ();
159 bool prep_record_disable ();
161 void calculate_record_range (
162 Evoral::OverlapType ot, samplepos_t transport_sample, samplecnt_t nframes,
163 samplecnt_t& rec_nframes, samplecnt_t& rec_offset
166 mutable Glib::Threads::Mutex capture_info_lock;
167 CaptureInfos capture_info;
170 gint _record_enabled;
172 samplepos_t capture_start_sample;
173 samplecnt_t capture_captured;
175 samplecnt_t adjust_capture_position;
176 samplecnt_t _capture_offset;
177 samplepos_t first_recordable_sample;
178 samplepos_t last_recordable_sample;
179 int last_possibly_recording;
180 AlignStyle _alignment_style;
181 std::string _write_source_name;
182 boost::shared_ptr<SMFSource> _midi_write_source;
184 std::list<boost::shared_ptr<Source> > _last_capture_sources;
185 std::vector<boost::shared_ptr<AudioFileSource> > capturing_sources;
187 static samplecnt_t _chunk_samples;
190 volatile gint _samples_pending_write;
191 volatile gint _num_captured_loops;
192 samplepos_t _accumulated_capture_offset;
194 /** A buffer that we use to put newly-arrived MIDI data in for
195 the GUI to read (so that it can update itself).
197 MidiBuffer _gui_feed_buffer;
198 mutable Glib::Threads::Mutex _gui_feed_buffer_mutex;
200 void finish_capture (boost::shared_ptr<ChannelList> c);
205 #endif /* __ardour_disk_writer_h__ */