Remove internal ports.
[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 #include <ardour/audio_port.h>
21 #include <ardour/audioengine.h>
22 #include <ardour/data_type.h>
23 #include <ardour/audio_buffer.h>
24
25 using namespace ARDOUR;
26 using namespace std;
27
28 AudioPort::AudioPort (const std::string& name, Flags flags)
29         : Port (name, DataType::AUDIO, flags)
30         , _buffer_data_set (false)
31         , _buffer (new AudioBuffer (0))
32 {
33         assert (name.find_first_of (':') == string::npos);
34 }
35
36 AudioPort::~AudioPort ()
37 {
38         delete _buffer;
39 }
40
41 void
42 AudioPort::cycle_start (nframes_t nframes, nframes_t offset)
43 {
44         /* caller must hold process lock */
45
46         /* get_buffer() must only be run on outputs here in cycle_start().
47
48            Inputs must be done in the correct processing order, which 
49            requires interleaving with route processing. that will 
50            happen when Port::get_buffer() is called.
51         */
52
53         if (sends_output() && !_buffer_data_set) {
54                 
55                 _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes) + offset, nframes);
56                 _buffer_data_set = true;
57                 
58         }
59
60         if (receives_input()) {
61                 _buffer_data_set = false;
62         } else {
63                 _buffer->silence (nframes, offset);
64         }
65 }
66
67 AudioBuffer &
68 AudioPort::get_audio_buffer (nframes_t nframes, nframes_t offset)
69 {
70         /* caller must hold process lock */
71
72         if (receives_input () && !_buffer_data_set) {
73
74                 _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, nframes) + offset, nframes);
75                 
76         } 
77         
78         return *_buffer;
79 }
80
81 void
82 AudioPort::cycle_end (nframes_t nframes, nframes_t offset)
83 {
84        _buffer_data_set = false;
85 }