[Re]-Implement Delayline flush.
[ardour.git] / libs / ardour / ardour / delayline.h
1 /*
2     Copyright (C) 2006, 2013 Paul Davis
3     Copyright (C) 2013, 2014 Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify it
6     under the terms of the GNU General Public License as published by the Free
7     Software Foundation; either version 2 of the License, or (at your option)
8     any later version.
9
10     This program is distributed in the hope that it will be useful, but WITHOUT
11     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13     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     675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifndef __ardour_delayline_h__
21 #define __ardour_delayline_h__
22
23 #include <boost/shared_ptr.hpp>
24 #include <boost/shared_array.hpp>
25
26 #include "ardour/types.h"
27 #include "ardour/processor.h"
28
29 namespace ARDOUR {
30
31 class BufferSet;
32 class ChanCount;
33 class Session;
34
35 /** Meters peaks on the input and stores them for access.
36  */
37 class LIBARDOUR_API DelayLine : public Processor {
38 public:
39
40   DelayLine (Session& s, const std::string& name);
41         ~DelayLine ();
42
43         bool set_name (const std::string& str);
44         bool set_delay (samplecnt_t signal_delay);
45         samplecnt_t delay () { return _pending_delay; }
46
47         /* processor interface */
48         bool display_to_user () const { return false; }
49         void run (BufferSet&, samplepos_t, samplepos_t, double, pframes_t, bool);
50         bool configure_io (ChanCount in, ChanCount out);
51         bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
52         void flush ();
53
54 protected:
55         XMLNode& state ();
56
57 private:
58         void allocate_pending_buffers (samplecnt_t, ChanCount const&);
59
60         void write_to_rb (Sample* rb, Sample* src, samplecnt_t); // honor _woff, _bsiz.
61         void read_from_rb (Sample* rb, Sample* dst, samplecnt_t); // honor _roff, _bsiz
62
63         friend class IO;
64
65         samplecnt_t    _bsiz;
66         samplecnt_t    _delay, _pending_delay;
67         sampleoffset_t _roff, _woff;
68         bool           _pending_flush;
69
70         typedef std::vector<boost::shared_array<Sample> > AudioDlyBuf;
71         typedef std::vector<boost::shared_array<MidiBuffer> > MidiDlyBuf;
72
73         AudioDlyBuf _buf;
74         boost::shared_ptr<MidiBuffer> _midi_buf;
75
76 #ifndef NDEBUG
77         Glib::Threads::Mutex _set_delay_mutex;
78 #endif
79 };
80
81 } // namespace ARDOUR
82
83 #endif // __ardour_meter_h__