fix all manner of wrongness with port buffer offsets
[ardour.git] / libs / ardour / 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
21 #include "pbd/stacktrace.h"
22
23 #include "ardour/audio_port.h"
24 #include "ardour/audioengine.h"
25 #include "ardour/data_type.h"
26 #include "ardour/audio_buffer.h"
27
28 using namespace ARDOUR;
29 using namespace std;
30
31 AudioPort::AudioPort (const std::string& name, Flags flags)
32         : Port (name, DataType::AUDIO, flags)
33         , _buffer (new AudioBuffer (0))
34 {
35         assert (name.find_first_of (':') == string::npos);
36 }
37
38 AudioPort::~AudioPort ()
39 {
40         delete _buffer;
41 }
42
43 void
44 AudioPort::cycle_start (pframes_t nframes)
45 {
46         /* caller must hold process lock */
47
48         if (sends_output()) {
49                 _buffer->prepare ();
50         }
51 }
52
53 void
54 AudioPort::cycle_end (pframes_t nframes)
55 {
56         if (sends_output() && !_buffer->written()) {
57                 _buffer->silence (nframes);
58         }
59 }
60
61 void
62 AudioPort::cycle_split ()
63 {
64 }
65
66 AudioBuffer&
67 AudioPort::get_audio_buffer (framecnt_t nframes)
68 {
69         /* caller must hold process lock */
70        _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes) + _port_offset, nframes);
71         return *_buffer;
72 }
73
74 size_t
75 AudioPort::raw_buffer_size (pframes_t nframes) const
76 {
77         return nframes * sizeof (Sample);
78 }
79