2 Copyright (C) 2006 Paul Davis
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.
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.
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.
20 #include <ardour/audio_port.h>
21 #include <ardour/jack_audio_port.h>
22 #include <ardour/audioengine.h>
23 #include <ardour/data_type.h>
25 using namespace ARDOUR;
28 AudioPort::AudioPort (const std::string& name, Flags flgs, bool external, nframes_t capacity)
30 , BaseAudioPort (name, flgs)
31 , PortFacade (name, flgs)
33 if (!external || receives_input()) {
35 /* internal-only and input ports need their own buffers.
36 external output ports use the external port buffer.
39 _buffer = new AudioBuffer (capacity);
49 /* make the JackAudioPort create its own buffer. For input,
50 we will copy from it during cycle_start(). For output,
51 we will set up our buffer to point to its buffer, which
52 will in turn be using the JACK port buffer for data.
55 _ext_port = new JackAudioPort (name, flgs, 0);
58 _buffer = &dynamic_cast<JackAudioPort*>(_ext_port)->get_audio_buffer();
61 Port::set_name (_ext_port->name());
67 AudioPort::~AudioPort()
78 BaseAudioPort::reset();
87 AudioPort::cycle_start (nframes_t nframes, nframes_t offset)
89 /* caller must hold process lock */
92 _ext_port->cycle_start (nframes, offset);
95 if (_flags & IsInput) {
98 _buffer->read_from (dynamic_cast<BaseAudioPort*>(_ext_port)->get_audio_buffer(), nframes, offset);
100 if (!_connections.empty()) {
101 (*_mixdown) (_connections, _buffer, nframes, offset, false);
106 if (_connections.empty()) {
107 _buffer->silence (nframes, offset);
109 (*_mixdown) (_connections, _buffer, nframes, offset, true);
115 // XXX if we could get the output stage to not purely mix into, but also
116 // to initially overwrite the buffer, we could avoid this silence step.
118 _buffer->silence (nframes, offset);
123 AudioPort::cycle_end (nframes_t nframes, nframes_t offset)