virtualize the way that AutomationController gets strings to display values, so that...
[ardour.git] / libs / ardour / panner.cc
1 /*
2     Copyright (C) 2004-2011 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 #include "ardour/audio_buffer.h"
21 #include "ardour/buffer_set.h"
22 #include "ardour/panner.h"
23 #include "ardour/pannable.h"
24 #include "ardour/session.h"
25 #include "ardour/utils.h"
26
27 using namespace std;
28 using namespace ARDOUR;
29
30 Panner::Panner (boost::shared_ptr<Pannable> p)
31         : _pannable (p)
32         , _mono (0)
33 {
34 }
35
36 Panner::~Panner ()
37 {
38 }
39
40 void
41 Panner::set_bypassed (bool yn)
42 {
43         if (yn != _bypassed) {
44                 _bypassed = yn;
45                 StateChanged ();
46         }
47 }
48
49 void
50 Panner::set_mono (bool yn)
51 {
52         if (yn != _mono) {
53                 _mono = yn;
54                 StateChanged ();
55         }
56 }
57
58 int
59 Panner::set_state (const XMLNode& node, int version)
60 {
61         const XMLProperty* prop;
62         XMLNodeConstIterator iter;
63
64         if ((prop = node.property (X_("mono")))) {
65                 set_mono (string_is_affirmative (prop->value()));
66         }
67
68         if ((prop = node.property (X_("bypassed"))) != 0) {
69                 set_bypassed (string_is_affirmative (prop->value()));
70         }
71
72         return 0;
73 }
74
75 XMLNode&
76 Panner::get_state ()
77 {
78         XMLNode* node = new XMLNode (X_("Panner"));
79
80         node->add_property (X_("mono"), (_mono ? "yes" : "no"));
81         node->add_property (X_("bypassed"), (bypassed() ? "yes" : "no"));
82
83         return *node;
84 }
85
86 void
87 Panner::distribute (BufferSet& ibufs, BufferSet& obufs, gain_t gain_coeff, pframes_t nframes)
88 {
89         uint32_t which = 0;
90
91         for (BufferSet::audio_iterator src = ibufs.audio_begin(); src != ibufs.audio_end(); ++src, ++which) {
92                 if (_mono) {
93                         /* we're in mono mode, so just pan the input to all outputs equally (XXX should we scale?) */
94                         for (BufferSet::audio_iterator o = obufs.audio_begin(); o != obufs.audio_end(); ++o) {
95                                 mix_buffers_with_gain ((*o).data(), (*src).data(), nframes, gain_coeff);
96                         }
97                 } else {
98                         /* normal mode, call the `real' distribute method */
99                         distribute_one (*src, obufs, gain_coeff, nframes, which);
100                 }
101         }
102 }
103
104 void
105 Panner::distribute_automated (BufferSet& ibufs, BufferSet& obufs,
106                               framepos_t start, framepos_t end, pframes_t nframes, pan_t** buffers)
107 {
108         uint32_t which = 0;
109
110         for (BufferSet::audio_iterator src = ibufs.audio_begin(); src != ibufs.audio_end(); ++src, ++which) {
111                 if (_mono) {
112                         /* we're in mono mode, so just pan the input to all outputs equally (XXX should we scale?) */
113                         for (BufferSet::audio_iterator o = obufs.audio_begin(); o != obufs.audio_end(); ++o) {
114                                 mix_buffers_with_gain ((*o).data(), (*src).data(), nframes, 1.0);
115                         }
116                 } else {
117                         /* normal mode, call the `real' distribute method */
118                         distribute_one_automated (*src, obufs, start, end, nframes, buffers, which);
119                 }
120         }
121 }
122
123 void
124 Panner::set_automation_style (AutoStyle style)
125 {
126         _pannable->set_automation_style (style);
127 }
128
129 void
130 Panner::set_automation_state (AutoState state)
131 {
132         _pannable->set_automation_state (state);
133 }
134
135 AutoState
136 Panner::automation_state () const
137 {
138         return _pannable->automation_state();
139 }
140
141 AutoStyle
142 Panner::automation_style () const
143 {
144         return _pannable->automation_style ();
145 }
146
147 bool
148 Panner::touching () const
149 {
150         return _pannable->touching ();
151 }
152
153 set<Evoral::Parameter> 
154 Panner::what_can_be_automated() const
155 {
156         return _pannable->what_can_be_automated ();
157 }
158
159 string
160 Panner::describe_parameter (Evoral::Parameter p)
161 {
162         return _pannable->describe_parameter (p);
163 }
164
165 string 
166 Panner::value_as_string (boost::shared_ptr<AutomationControl> ac) const
167 {
168         return _pannable->value_as_string (ac);
169 }