Small steps towards rolling backwards..
[ardour.git] / libs / ardour / polarity_processor.cc
1 /*
2  * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #include "ardour/audio_buffer.h"
20 #include "ardour/phase_control.h"
21 #include "ardour/polarity_processor.h"
22
23 #include "pbd/i18n.h"
24
25 using namespace ARDOUR;
26 using namespace PBD;
27
28 PolarityProcessor::PolarityProcessor (Session& s, boost::shared_ptr<PhaseControl> control)
29         : Processor(s, "Polarity")
30         , _control (control)
31 {
32 }
33
34 bool
35 PolarityProcessor::can_support_io_configuration (const ChanCount& in, ChanCount& out)
36 {
37         out = in;
38         return true;
39 }
40
41 bool
42 PolarityProcessor::configure_io (ChanCount in, ChanCount out)
43 {
44         if (out != in) { // always 1:1
45                 return false;
46         }
47
48         return Processor::configure_io (in, out);
49 }
50
51 void
52 PolarityProcessor::run (BufferSet& bufs, samplepos_t /*start_sample*/, samplepos_t /*end_sample*/, double /*speed*/, pframes_t nframes, bool)
53 {
54         if (!_active && !_pending_active) {
55                 return;
56         }
57         _active = _pending_active;
58
59         if (_control->none()) {
60                 return;
61         }
62         int chn = 0;
63
64         for (BufferSet::audio_iterator i = bufs.audio_begin(); i != bufs.audio_end(); ++i, ++chn) {
65                 Sample* const sp = i->data();
66                 if (_control->inverted (chn)) {
67                         for (pframes_t nx = 0; nx < nframes; ++nx) {
68                                 sp[nx] = -sp[nx];
69                         }
70                 }
71         }
72 }
73
74 XMLNode&
75 PolarityProcessor::state ()
76 {
77         XMLNode& node (Processor::state ());
78         node.set_property("type", "polarity");
79         return node;
80 }