NO-OP: whitespace
[ardour.git] / libs / ardour / process_thread.cc
1 /*
2  * Copyright (C) 2010-2012 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2011-2012 David Robillard <d@drobilla.net>
4  * Copyright (C) 2013-2017 Robin Gareus <robin@gareus.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20
21 #include <iostream>
22
23 #include "ardour/ardour.h"
24 #include "ardour/buffer.h"
25 #include "ardour/buffer_manager.h"
26 #include "ardour/buffer_set.h"
27 #include "ardour/process_thread.h"
28 #include "ardour/thread_buffers.h"
29
30 using namespace ARDOUR;
31 using namespace Glib;
32 using namespace std;
33
34 static void
35 release_thread_buffer (void* arg)
36 {
37         BufferManager::put_thread_buffers ((ThreadBuffers*) arg);
38 }
39
40 Glib::Threads::Private<ThreadBuffers> ProcessThread::_private_thread_buffers (release_thread_buffer);
41
42 void
43 ProcessThread::init ()
44 {
45         /* denormal protection is per thread */
46         ARDOUR::setup_fpu ();
47 }
48
49 ProcessThread::ProcessThread ()
50 {
51         init ();
52 }
53
54 ProcessThread::~ProcessThread ()
55 {
56 }
57
58 void
59 ProcessThread::get_buffers ()
60 {
61         ThreadBuffers* tb = BufferManager::get_thread_buffers ();
62
63         assert (tb);
64         _private_thread_buffers.set (tb);
65 }
66
67 void
68 ProcessThread::drop_buffers ()
69 {
70         ThreadBuffers* tb = _private_thread_buffers.get();
71         assert (tb);
72         BufferManager::put_thread_buffers (tb);
73         _private_thread_buffers.set (0);
74 }
75
76 BufferSet&
77 ProcessThread::get_silent_buffers (ChanCount count)
78 {
79         ThreadBuffers* tb = _private_thread_buffers.get();
80         assert (tb);
81
82         BufferSet* sb = tb->silent_buffers;
83         assert (sb);
84
85         assert(sb->available() >= count);
86         sb->set_count(count);
87
88         for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
89                 for (size_t i= 0; i < count.get(*t); ++i) {
90                         sb->get_available(*t, i).clear();
91                 }
92         }
93
94         return *sb;
95 }
96
97 BufferSet&
98 ProcessThread::get_scratch_buffers (ChanCount count, bool silence)
99 {
100         ThreadBuffers* tb = _private_thread_buffers.get();
101         assert (tb);
102
103         BufferSet* sb = tb->scratch_buffers;
104         assert (sb);
105
106         if (count != ChanCount::ZERO) {
107                 assert(sb->available() >= count);
108                 sb->set_count (count);
109         } else {
110                 sb->set_count (sb->available());
111         }
112
113         if (silence) {
114                 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
115                         for (uint32_t i = 0; i < sb->count().get(*t); ++i) {
116                                 sb->get_available (*t, i).clear();
117                         }
118                 }
119         }
120
121         return *sb;
122 }
123
124 BufferSet&
125 ProcessThread::get_noinplace_buffers (ChanCount count)
126 {
127         ThreadBuffers* tb = _private_thread_buffers.get();
128         assert (tb);
129
130         BufferSet* sb = tb->noinplace_buffers;
131         assert (sb);
132
133         if (count != ChanCount::ZERO) {
134                 assert(sb->available() >= count);
135                 sb->set_count (count);
136         } else {
137                 sb->set_count (sb->available());
138         }
139
140         return *sb;
141 }
142
143 BufferSet&
144 ProcessThread::get_route_buffers (ChanCount count, bool silence)
145 {
146         ThreadBuffers* tb = _private_thread_buffers.get();
147         assert (tb);
148
149         BufferSet* sb = tb->route_buffers;
150         assert (sb);
151
152         if (count != ChanCount::ZERO) {
153                 assert(sb->available() >= count);
154                 sb->set_count (count);
155         } else {
156                 sb->set_count (sb->available());
157         }
158
159         if (silence) {
160                 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
161                         for (uint32_t i = 0; i < sb->count().get(*t); ++i) {
162                                 sb->get_available (*t, i).clear();
163                         }
164                 }
165         }
166
167         return *sb;
168 }
169
170 BufferSet&
171 ProcessThread::get_mix_buffers (ChanCount count)
172 {
173         ThreadBuffers* tb = _private_thread_buffers.get();
174         assert (tb);
175
176         BufferSet* mb = tb->mix_buffers;
177
178         assert (mb);
179         assert (mb->available() >= count);
180         mb->set_count(count);
181         return *mb;
182 }
183
184 gain_t*
185 ProcessThread::gain_automation_buffer()
186 {
187         ThreadBuffers* tb = _private_thread_buffers.get();
188         assert (tb);
189
190         gain_t *g =  tb->gain_automation_buffer;
191         assert (g);
192         return g;
193 }
194
195 gain_t*
196 ProcessThread::trim_automation_buffer()
197 {
198         ThreadBuffers* tb = _private_thread_buffers.get();
199         assert (tb);
200
201         gain_t *g =  tb->trim_automation_buffer;
202         assert (g);
203         return g;
204 }
205
206 gain_t*
207 ProcessThread::send_gain_automation_buffer()
208 {
209         ThreadBuffers* tb = _private_thread_buffers.get();
210         assert (tb);
211
212         gain_t* g = tb->send_gain_automation_buffer;
213         assert (g);
214         return g;
215 }
216
217 gain_t*
218 ProcessThread::scratch_automation_buffer()
219 {
220         ThreadBuffers* tb = _private_thread_buffers.get();
221         assert (tb);
222
223         gain_t* g = tb->scratch_automation_buffer;
224         assert (g);
225         return g;
226 }
227
228 pan_t**
229 ProcessThread::pan_automation_buffer()
230 {
231         ThreadBuffers* tb = _private_thread_buffers.get();
232         assert (tb);
233
234         pan_t** p = tb->pan_automation_buffer;
235         assert (p);
236         return p;
237 }