merge AudioDiskstream playback code into DiskReader
[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 class Location;
34
35 class LIBARDOUR_API DiskIOProcessor : public Processor
36 {
37   public:
38         enum Flag {
39                 Recordable  = 0x1,
40                 Hidden      = 0x2,
41                 Destructive = 0x4,
42                 NonLayered   = 0x8
43         };
44
45         static const std::string state_node_name;
46
47         DiskIOProcessor (Session&, const std::string& name, Flag f);
48
49         static void set_buffering_parameters (BufferingPreset bp);
50
51         /** @return A number between 0 and 1, where 0 indicates that the playback buffer
52          *  is dry (ie the disk subsystem could not keep up) and 1 indicates that the
53          *  buffer is full.
54          */
55         virtual float playback_buffer_load() const = 0;
56         virtual float capture_buffer_load() const = 0;
57
58         void set_flag (Flag f)   { _flags = Flag (_flags | f); }
59         void unset_flag (Flag f) { _flags = Flag (_flags & ~f); }
60
61         bool           hidden()      const { return _flags & Hidden; }
62         bool           recordable()  const { return _flags & Recordable; }
63         bool           non_layered()  const { return _flags & NonLayered; }
64         bool           reversed()    const { return _actual_speed < 0.0f; }
65         double         speed()       const { return _visible_speed; }
66
67         ChanCount n_channels() { return _n_channels; }
68
69         void non_realtime_set_speed ();
70         bool realtime_set_speed (double sp, bool global);
71
72         virtual void punch_in()  {}
73         virtual void punch_out() {}
74
75         virtual float buffer_load() const = 0;
76
77         bool slaved() const      { return _slaved; }
78         void set_slaved(bool yn) { _slaved = yn; }
79
80         int set_loop (Location *loc);
81
82         PBD::Signal1<void,Location *> LoopSet;
83         PBD::Signal0<void>            SpeedChanged;
84         PBD::Signal0<void>            ReverseChanged;
85
86         int set_state (const XMLNode&, int version);
87
88   protected:
89         friend class Auditioner;
90         virtual int  seek (framepos_t which_sample, bool complete_refill = false) = 0;
91
92   protected:
93         Flag         _flags;
94         uint32_t i_am_the_modifier;
95         ChanCount    _n_channels;
96         double       _visible_speed;
97         double       _actual_speed;
98         double       _speed;
99         double       _target_speed;
100         /* items needed for speed change logic */
101         bool         _buffer_reallocation_required;
102         bool         _seek_required;
103         bool         _slaved;
104         Location*     loop_location;
105         bool          in_set_state;
106         framecnt_t    wrap_buffer_size;
107         framecnt_t    speed_buffer_size;
108
109         Glib::Threads::Mutex state_lock;
110
111         static bool get_buffering_presets (BufferingPreset bp,
112                                            framecnt_t& read_chunk_size,
113                                            framecnt_t& read_buffer_size,
114                                            framecnt_t& write_chunk_size,
115                                            framecnt_t& write_buffer_size);
116
117         virtual void allocate_temporary_buffers () = 0;
118 };
119
120 } // namespace ARDOUR
121
122 #endif /* __ardour_disk_io_h__ */