remove all remaining vestiges of per-track varispeed from libardour
[ardour.git] / libs / ardour / ardour / disk_reader.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_reader_h__
21 #define __ardour_disk_reader_h__
22
23 #include "ardour/disk_io.h"
24 #include "ardour/midi_buffer.h"
25
26 namespace ARDOUR
27 {
28
29 class Playlist;
30 class AudioPlaylist;
31 class MidiPlaylist;
32 template<typename T> class MidiRingBuffer;
33
34 class LIBARDOUR_API DiskReader : public DiskIOProcessor
35 {
36   public:
37         DiskReader (Session&, std::string const & name, DiskIOProcessor::Flag f = DiskIOProcessor::Flag (0));
38         ~DiskReader ();
39
40         bool set_name (std::string const & str);
41
42         static framecnt_t chunk_frames() { return _chunk_frames; }
43         static framecnt_t default_chunk_frames ();
44         static void set_chunk_frames (framecnt_t n) { _chunk_frames = n; }
45
46         void run (BufferSet& /*bufs*/, framepos_t /*start_frame*/, framepos_t /*end_frame*/, double speed, pframes_t /*nframes*/, bool /*result_required*/);
47         void realtime_handle_transport_stopped ();
48         void realtime_locate ();
49         int overwrite_existing_buffers ();
50         void set_pending_overwrite (bool yn);
51
52         framecnt_t roll_delay() const { return _roll_delay; }
53         void set_roll_delay (framecnt_t);
54
55         virtual XMLNode& state (bool full);
56         int set_state (const XMLNode&, int version);
57
58         PBD::Signal0<void>            AlignmentStyleChanged;
59
60         float buffer_load() const;
61
62         void move_processor_automation (boost::weak_ptr<Processor>, std::list<Evoral::RangeMove<framepos_t> > const &);
63
64         /* called by the Butler in a non-realtime context */
65
66         int do_refill () {
67                 return refill (_mixdown_buffer, _gain_buffer, 0);
68         }
69
70         /** For non-butler contexts (allocates temporary working buffers)
71          *
72          * This accessible method has a default argument; derived classes
73          * must inherit the virtual method that we call which does NOT
74          * have a default argument, to avoid complications with inheritance
75          */
76         int do_refill_with_alloc (bool partial_fill = true) {
77                 return _do_refill_with_alloc (partial_fill);
78         }
79
80         bool pending_overwrite () const { return _pending_overwrite; }
81
82         // Working buffers for do_refill (butler thread)
83         static void allocate_working_buffers();
84         static void free_working_buffers();
85
86         void adjust_buffering ();
87
88         int can_internal_playback_seek (framecnt_t distance);
89         int internal_playback_seek (framecnt_t distance);
90         int seek (framepos_t frame, bool complete_refill = false);
91
92         static PBD::Signal0<void> Underrun;
93
94         void playlist_modified ();
95         void reset_tracker ();
96
97         static void set_midi_readahead_frames (framecnt_t frames_ahead) { midi_readahead = frames_ahead; }
98
99   protected:
100         friend class Track;
101         friend class MidiTrack;
102
103         void resolve_tracker (Evoral::EventSink<framepos_t>& buffer, framepos_t time);
104         boost::shared_ptr<MidiBuffer> get_gui_feed_buffer () const;
105
106         void playlist_changed (const PBD::PropertyChange&);
107         int use_playlist (DataType, boost::shared_ptr<Playlist>);
108         void playlist_ranges_moved (std::list< Evoral::RangeMove<framepos_t> > const &, bool);
109
110   private:
111         /** The number of frames by which this diskstream's output should be delayed
112             with respect to the transport frame.  This is used for latency compensation.
113         */
114         framecnt_t   _roll_delay;
115         framepos_t    overwrite_frame;
116         off_t         overwrite_offset;
117         bool          _pending_overwrite;
118         bool          overwrite_queued;
119         IOChange      input_change_pending;
120         framecnt_t    wrap_buffer_size;
121         MonitorChoice   _monitoring_choice;
122
123         int _do_refill_with_alloc (bool partial_fill);
124
125         static framecnt_t _chunk_frames;
126         static framecnt_t midi_readahead;
127
128         /* The MIDI stuff */
129
130         /** A buffer that we use to put newly-arrived MIDI data in for
131             the GUI to read (so that it can update itself).
132         */
133         MidiBuffer                   _gui_feed_buffer;
134         mutable Glib::Threads::Mutex _gui_feed_buffer_mutex;
135
136         int audio_read (Sample* buf, Sample* mixdown_buffer, float* gain_buffer,
137                         framepos_t& start, framecnt_t cnt,
138                         int channel, bool reversed);
139         int midi_read (framepos_t& start, framecnt_t cnt, bool reversed);
140
141         static Sample* _mixdown_buffer;
142         static gain_t* _gain_buffer;
143
144         int refill (Sample* mixdown_buffer, float* gain_buffer, framecnt_t fill_level);
145         int refill_audio (Sample *mixdown_buffer, float *gain_buffer, framecnt_t fill_level);
146         int refill_midi ();
147
148         frameoffset_t calculate_playback_distance (pframes_t);
149
150         void get_playback (MidiBuffer& dst, framecnt_t nframes);
151         void flush_playback (framepos_t start, framepos_t end);
152 };
153
154 } // namespace
155
156 #endif /* __ardour_disk_reader_h__ */