move ownership of an RT MIDI buffer from DiskIO to MidiPlaylist
[ardour.git] / libs / ardour / capturing_processor.cc
1 /*
2  * Copyright (C) 2011 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2013-2017 Robin Gareus <robin@gareus.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #include "ardour/capturing_processor.h"
22 #include "ardour/session.h"
23 #include "ardour/audioengine.h"
24
25 #include "pbd/i18n.h"
26
27 namespace ARDOUR {
28
29 CapturingProcessor::CapturingProcessor (Session & session, samplecnt_t latency)
30         : Processor (session, X_("capture point"))
31         , block_size (AudioEngine::instance()->samples_per_cycle())
32         , _latency (latency)
33 {
34         realloc_buffers ();
35 }
36
37 CapturingProcessor::~CapturingProcessor()
38 {
39 }
40
41 int
42 CapturingProcessor::set_block_size (pframes_t nframes)
43 {
44         block_size = nframes;
45         realloc_buffers();
46         return 0;
47 }
48
49 void
50 CapturingProcessor::run (BufferSet& bufs, samplepos_t, samplepos_t, double, pframes_t nframes, bool)
51 {
52         if (!active()) {
53                 _delaybuffers.flush ();
54                 return;
55         }
56         for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
57                 for (uint32_t b = 0; b < bufs.count().get (*t); ++b) {
58                         _delaybuffers.delay (*t, b, capture_buffers.get_available (*t, b), bufs.get_available (*t, b), nframes, 0, 0);
59                 }
60         }
61 }
62
63 bool
64 CapturingProcessor::configure_io (ChanCount in, ChanCount out)
65 {
66         Processor::configure_io (in, out);
67         _delaybuffers.set (out, _latency);
68         realloc_buffers();
69         return true;
70 }
71
72 bool
73 CapturingProcessor::can_support_io_configuration (const ChanCount& in, ChanCount& out)
74 {
75         out = in;
76         return true;
77 }
78
79 void
80 CapturingProcessor::realloc_buffers()
81 {
82         capture_buffers.ensure_buffers (_configured_input, block_size);
83         _delaybuffers.flush ();
84 }
85
86 XMLNode &
87 CapturingProcessor::state ()
88 {
89         XMLNode& node = Processor::state ();
90
91         node.set_property (X_("type"), X_("capture"));
92         return node;
93 }
94
95 } // namespace ARDOUR