Apply panners/automation patch from torbenh (Panner is-a Processor).
[ardour.git] / libs / ardour / internal_audio_port.cc
1 /*
2     Copyright (C) 2006 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 #include <cassert>
20 #include <ardour/internal_audio_port.h>
21 #include <ardour/audioengine.h>
22
23 using namespace ARDOUR;
24 using namespace std;
25
26 void
27 InternalAudioPort::default_mixdown (const list<InternalPort*>& ports, AudioBuffer& dest, nframes_t cnt, nframes_t offset)
28 {
29         list<InternalPort*>::const_iterator p = ports.begin();
30
31         dest.read_from ((dynamic_cast<AudioPort*>(*p))->get_audio_buffer(), cnt, offset);
32
33         for (; p != ports.end(); ++p) {
34                 dest.accumulate_from ((dynamic_cast<AudioPort*>(*p))->get_audio_buffer(), cnt, offset);
35         }
36 }
37
38 InternalAudioPort::InternalAudioPort(const string& name, Flags flags)
39         : Port (DataType::AUDIO, flags)
40         , AudioPort (flags, engine->frames_per_cycle())
41         , InternalPort (name, DataType::AUDIO, flags)
42 {
43         _mixdown = default_mixdown;
44 }
45
46 void 
47 InternalAudioPort::set_mixdown_function (void (*func)(const list<InternalPort*>&, AudioBuffer&, nframes_t, nframes_t))
48 {
49         _mixdown = func;
50 }
51
52 void
53 InternalAudioPort::reset ()
54 {
55         _buffer.resize (engine->frames_per_cycle());
56         _buffer.silence (_buffer.size());
57 }
58
59 AudioBuffer&
60 InternalAudioPort::get_audio_buffer ()
61 {
62         if (_connections.empty()) {
63                 return AudioPort::get_audio_buffer();
64         }
65
66         /* XXX what about offset/size being more dynamic ? */
67         
68         (*_mixdown) (_connections, _buffer, _buffer.size(), 0);
69
70         return _buffer;
71 }