fix up file renaming code a little bit
[ArdourMidi.git] / libs / ardour / audio_port.cc
blob71ec7c6289f201160d75c49d708761ea52a42279
1 /*
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.
19 #include <cassert>
20 #include "ardour/audio_port.h"
21 #include "ardour/audioengine.h"
22 #include "ardour/data_type.h"
23 #include "ardour/audio_buffer.h"
25 using namespace ARDOUR;
26 using namespace std;
28 AudioPort::AudioPort (const std::string& name, Flags flags)
29 : Port (name, DataType::AUDIO, flags)
30 , _buffer (new AudioBuffer (0))
32 assert (name.find_first_of (':') == string::npos);
35 AudioPort::~AudioPort ()
37 delete _buffer;
40 void
41 AudioPort::cycle_start (nframes_t nframes)
43 /* caller must hold process lock */
45 /* get_buffer() must only be run on outputs here in cycle_start().
47 Inputs must be done in the correct processing order, which
48 requires interleaving with route processing. that will
49 happen when Port::get_buffer() is called.
52 if (sends_output()) {
54 /* Notice that cycle_start() is always run with the *entire* process cycle frame count,
55 so we do not bother to apply _port_offset here - we always want the address of the
56 entire JACK port buffer. We are not collecting data here - just noting the
57 address where we will write data later in the process cycle.
60 _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes), nframes);
61 _buffer->prepare ();
65 void
66 AudioPort::cycle_end (nframes_t nframes)
68 if (sends_output() && !_buffer->written()) {
69 _buffer->silence (nframes);
73 void
74 AudioPort::cycle_split ()
78 AudioBuffer&
79 AudioPort::get_audio_buffer (nframes_t nframes, nframes_t offset)
81 /* caller must hold process lock */
83 if (receives_input ()) {
85 /* Get a pointer to the audio data @ offset + _port_offset within the JACK port buffer and store
86 it in our _buffer member.
88 Note that offset is expected to be zero in almost all cases.
91 _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes) + offset + _port_offset, nframes);
94 /* output ports set their _buffer data information during ::cycle_start()
97 return *_buffer;
100 size_t
101 AudioPort::raw_buffer_size (nframes_t nframes) const
103 return nframes * sizeof (Sample);