enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / libs / ardour / sidechain.cc
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2006 Paul Davis
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18  */
19
20 #include <algorithm>
21
22 #include "pbd/xml++.h"
23
24 #include "ardour/audioengine.h"
25 #include "ardour/buffer.h"
26 #include "ardour/buffer_set.h"
27 #include "ardour/io.h"
28 #include "ardour/session.h"
29 #include "ardour/sidechain.h"
30
31 #include "pbd/i18n.h"
32
33 using namespace ARDOUR;
34 using namespace PBD;
35
36
37 SideChain::SideChain (Session& s, const std::string& name)
38         : IOProcessor (s, true, false, name)
39 {
40 }
41
42 SideChain::~SideChain ()
43 {
44         disconnect ();
45 }
46
47 XMLNode&
48 SideChain::state (bool full)
49 {
50         XMLNode& node = IOProcessor::state (full);
51         node.add_property ("type", "sidechain");
52         return node;
53 }
54
55
56 int
57 SideChain::set_state (const XMLNode& node, int version)
58 {
59         IOProcessor::set_state (node, version);
60         return 0;
61 }
62
63 void
64 SideChain::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, double /*speed*/, pframes_t nframes, bool)
65 {
66         if (_input->n_ports () == ChanCount::ZERO) {
67                 // inplace pass-through
68                 return;
69         }
70
71         if (!_active && !_pending_active) {
72                 // zero buffers
73                 for (DataType::iterator t = DataType::begin (); t != DataType::end (); ++t) {
74                         for (uint32_t out = _configured_input.get (*t); out < bufs.count ().get (*t); ++out) {
75                                 bufs.get (*t, out).silence (nframes);
76                         }
77                 }
78                 return;
79         }
80
81         _input->collect_input (bufs, nframes, _configured_input);
82         bufs.set_count (_configured_output);
83
84         _active = _pending_active;
85 }
86
87 bool
88 SideChain::can_support_io_configuration (const ChanCount& in, ChanCount& out)
89 {
90         out = in + _input->n_ports ();
91         return true;
92 }
93
94 bool
95 SideChain::configure_io (ChanCount in, ChanCount out)
96 {
97         if (out != in + _input->n_ports ()) {
98                 /* disabled for now - see PluginInsert::configure_io() */
99                 // return false;
100         }
101         return Processor::configure_io (in, out);
102 }