4819b632935eab16711b8a1b59d971fe53c7ec74
[ardour.git] / libs / ardour / ardour / disk_io.h
1 /*
2     Copyright (C) 2009-2016 Paul Davis
3
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.
8
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.
13
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.
17
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 "ardour/processor.h"
28
29 namespace ARDOUR {
30
31 class Session;
32 class Route;
33
34 class LIBARDOUR_API DiskIOProcessor : public Processor
35 {
36   public:
37         static const std::string state_node_name;
38
39         DiskIOProcessor(Session&, const std::string& name);
40
41         void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, double speed, pframes_t /*nframes*/, bool /*result_required*/) {}
42         void silence (framecnt_t /*nframes*/, framepos_t /*start_frame*/) {}
43
44         bool configure_io (ChanCount in, ChanCount out);
45         bool can_support_io_configuration (const ChanCount& in, ChanCount& out) = 0;
46         ChanCount input_streams () const { return _configured_input; }
47         ChanCount output_streams() const { return _configured_output; }
48
49         virtual void realtime_handle_transport_stopped () {}
50         virtual void realtime_locate () {}
51
52         /* note: derived classes should implement state(), NOT get_state(), to allow
53            us to merge C++ inheritance and XML lack-of-inheritance reasonably
54            smoothly.
55          */
56
57         virtual XMLNode& state (bool full);
58         XMLNode& get_state (void);
59         int set_state (const XMLNode&, int version);
60
61         static framecnt_t disk_read_frames() { return disk_read_chunk_frames; }
62         static framecnt_t disk_write_frames() { return disk_write_chunk_frames; }
63         static void set_disk_read_chunk_frames (framecnt_t n) { disk_read_chunk_frames = n; }
64         static void set_disk_write_chunk_frames (framecnt_t n) { disk_write_chunk_frames = n; }
65         static framecnt_t default_disk_read_chunk_frames ();
66         static framecnt_t default_disk_write_chunk_frames ();
67
68         static void set_buffering_parameters (BufferingPreset bp);
69
70 protected:
71         static framecnt_t disk_read_chunk_frames;
72         static framecnt_t disk_write_chunk_frames;
73
74         uint32_t i_am_the_modifier;
75
76         Track*       _track;
77         ChanCount    _n_channels;
78
79         double       _visible_speed;
80         double       _actual_speed;
81         /* items needed for speed change logic */
82         bool         _buffer_reallocation_required;
83         bool         _seek_required;
84         bool         _slaved;
85         Location*     loop_location;
86         double        _speed;
87         double        _target_speed;
88         bool          in_set_state;
89
90         Glib::Threads::Mutex state_lock;
91         Flag _flags;
92 };
93
94 class LIBARDOUR_API DiskReader : public DiskIOProcessor
95 {
96   public:
97         DiskReader (Session&, std::string const & name);
98         ~DiskReader ();
99
100   private:
101         boost::shared_ptr<Playlist> _playlist;
102
103         framepos_t    overwrite_frame;
104         off_t         overwrite_offset;
105         bool          _pending_overwrite;
106         bool          overwrite_queued;
107         IOChange      input_change_pending;
108         framecnt_t    wrap_buffer_size;
109         framecnt_t    speed_buffer_size;
110
111         double        _speed;
112         double        _target_speed;
113
114         /** The next frame position that we should be reading from in our playlist */
115         framepos_t     file_frame;
116         framepos_t     playback_sample;
117
118         PBD::ScopedConnectionList playlist_connections;
119         PBD::ScopedConnection ic_connection;
120 };
121
122 class LIBARDOUR_API DiskWriter : public DiskIOProcessor
123 {
124   public:
125         DiskWriter (Session&, std::string const & name);
126         ~DiskWriter ();
127
128   private:
129         std::vector<CaptureInfo*> capture_info;
130         mutable Glib::Threads::Mutex capture_info_lock;
131
132         double       _visible_speed;
133         double       _actual_speed;
134         /* items needed for speed change logic */
135         bool         _buffer_reallocation_required;
136         bool         _seek_required;
137
138         /** Start of currently running capture in session frames */
139         framepos_t    capture_start_frame;
140         framecnt_t    capture_captured;
141         bool          was_recording;
142         framecnt_t    adjust_capture_position;
143         framecnt_t   _capture_offset;
144         framepos_t    first_recordable_frame;
145         framepos_t    last_recordable_frame;
146         int           last_possibly_recording;
147         AlignStyle   _alignment_style;
148         AlignChoice  _alignment_choice;
149         framecnt_t    wrap_buffer_size;
150         framecnt_t    speed_buffer_size;
151
152         std::string   _write_source_name;
153
154         PBD::ScopedConnection ic_connection;
155 };
156
157
158 } // namespace ARDOUR
159
160 #endif /* __ardour_processor_h__ */