start removal of NoteFixer code
[ardour.git] / libs / ardour / buffer_manager.cc
1 /*
2  * Copyright (C) 2010-2012 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2010 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2011-2012 David Robillard <d@drobilla.net>
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 "pbd/compose.h"
24
25 #include "ardour/buffer_manager.h"
26 #include "ardour/thread_buffers.h"
27
28 using namespace ARDOUR;
29 using namespace PBD;
30
31 RingBufferNPT<ThreadBuffers*>* BufferManager::thread_buffers = 0;
32 std::list<ThreadBuffers*>* BufferManager::thread_buffers_list = 0;
33 Glib::Threads::Mutex BufferManager::rb_mutex;
34
35 using std::cerr;
36 using std::endl;
37
38 void
39 BufferManager::init (uint32_t size)
40 {
41         thread_buffers = new ThreadBufferFIFO (size+1); // must be one larger than requested
42         thread_buffers_list = new ThreadBufferList;
43
44         /* and populate with actual ThreadBuffers
45          */
46
47         for (uint32_t n = 0; n < size; ++n) {
48                 ThreadBuffers* ts = new ThreadBuffers;
49                 thread_buffers->write (&ts, 1);
50                 thread_buffers_list->push_back (ts);
51         }
52         // cerr << "Initialized thread buffers, readable count now " << thread_buffers->read_space() << endl;
53
54 }
55
56 ThreadBuffers*
57 BufferManager::get_thread_buffers ()
58 {
59         Glib::Threads::Mutex::Lock em (rb_mutex);
60         ThreadBuffers* tbp;
61
62         if (thread_buffers->read (&tbp, 1) == 1) {
63                 // cerr << "Got thread buffers, readable count now " << thread_buffers->read_space() << endl;
64                 return tbp;
65         }
66
67         return 0;
68 }
69
70 void
71 BufferManager::put_thread_buffers (ThreadBuffers* tbp)
72 {
73         Glib::Threads::Mutex::Lock em (rb_mutex);
74         thread_buffers->write (&tbp, 1);
75         // cerr << "Put back thread buffers, readable count now " << thread_buffers->read_space() << endl;
76 }
77
78 void
79 BufferManager::ensure_buffers (ChanCount howmany, size_t custom)
80 {
81         /* this is protected by the audioengine's process lock: we do not  */
82
83         for (ThreadBufferList::iterator i = thread_buffers_list->begin(); i != thread_buffers_list->end(); ++i) {
84                 (*i)->ensure_buffers (howmany, custom);
85         }
86 }