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 flags, bool external, nframes_t capacity)
30 , BaseAudioPort (name, flags)
31 , PortFacade (name, flags)
32 , _has_been_mixed_down( false )
34 if (!external || receives_input()) {
36 /* internal-only and input ports need their own buffers.
37 external output ports use the external port buffer.
40 _buffer = new AudioBuffer (capacity);
51 /* make the JackAudioPort create its own buffer. For input,
52 we will copy from it during cycle_start(). For output,
53 we will set up our buffer to point to its buffer, which
54 will in turn be using the JACK port buffer for data.
57 _ext_port = new JackAudioPort (name, flags, 0);
59 //if (sends_output()) {
60 // _buffer = &dynamic_cast<JackAudioPort*>(_ext_port)->get_audio_buffer( nframes, offset );
63 Port::set_name (_ext_port->name());
69 AudioPort::~AudioPort()
80 BaseAudioPort::reset();
89 AudioPort::cycle_start (nframes_t nframes, nframes_t offset)
91 /* caller must hold process lock */
94 _ext_port->cycle_start (nframes, offset);
96 _has_been_mixed_down = false;
100 AudioPort::get_audio_buffer( nframes_t nframes, nframes_t offset ) {
102 if (_has_been_mixed_down)
105 if (_flags & IsInput) {
108 _buffer->read_from (dynamic_cast<BaseAudioPort*>(_ext_port)->get_audio_buffer (nframes, offset), nframes, offset);
110 if (!_connections.empty()) {
111 (*_mixdown) (_connections, _buffer, nframes, offset, false);
116 if (_connections.empty()) {
117 _buffer->silence (nframes, offset);
119 (*_mixdown) (_connections, _buffer, nframes, offset, true);
125 // XXX if we could get the output stage to not purely mix into, but also
126 // to initially overwrite the buffer, we could avoid this silence step.
128 _buffer = & (dynamic_cast<BaseAudioPort*>(_ext_port)->get_audio_buffer( nframes, offset ));
131 _buffer->silence (nframes, offset);
134 _has_been_mixed_down = true;
140 AudioPort::cycle_end (nframes_t nframes, nframes_t offset)
142 _has_been_mixed_down=false;