Use g_random_int instead of ::random for portability
[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_buffer.h"
24 #include "ardour/audio_port.h"
25 #include "ardour/data_type.h"
26
27 using namespace ARDOUR;
28 using namespace std;
29
30 AudioPort::AudioPort (const std::string& name, Flags flags)
31         : Port (name, DataType::AUDIO, flags)
32         , _buffer (new AudioBuffer (0))
33 {
34         assert (name.find_first_of (':') == string::npos);
35 }
36
37 AudioPort::~AudioPort ()
38 {
39         delete _buffer;
40 }
41
42 void
43 AudioPort::cycle_start (pframes_t nframes)
44 {
45         /* caller must hold process lock */
46
47         Port::cycle_start (nframes);
48
49         if (sends_output()) {
50                 _buffer->prepare ();
51         }
52 }
53
54 void
55 AudioPort::cycle_end (pframes_t)
56 {
57         if (sends_output() && !_buffer->written()) {
58                 /* we can't use nframes here because the current buffer capacity may
59                    be shorter than the full buffer size if we split the cycle.
60                 */
61                 if (_buffer->capacity () > 0) {
62                         _buffer->silence (_buffer->capacity());
63                 }
64         }
65 }
66
67 void
68 AudioPort::cycle_split ()
69 {
70 }
71
72 AudioBuffer&
73 AudioPort::get_audio_buffer (pframes_t nframes)
74 {
75         /* caller must hold process lock */
76         _buffer->set_data ((Sample *) jack_port_get_buffer (_jack_port, _cycle_nframes) +
77                            _global_port_buffer_offset + _port_buffer_offset, nframes);
78         return *_buffer;
79 }
80
81 Sample* 
82 AudioPort::engine_get_whole_audio_buffer ()
83 {
84         /* caller must hold process lock */
85         return (Sample *) jack_port_get_buffer (_jack_port, _cycle_nframes);
86 }
87
88
89
90