2 Copyright (C) 2009 Paul Davis
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.
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.
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.
19 #include <glibmm/thread.h>
21 #include "pbd/failed_constructor.h"
23 #include "ardour/internal_return.h"
24 #include "ardour/mute_master.h"
25 #include "ardour/session.h"
28 using namespace ARDOUR;
30 sigc::signal<void,nframes_t> InternalReturn::CycleStart;
32 InternalReturn::InternalReturn (Session& s)
36 CycleStart.connect (mem_fun (*this, &InternalReturn::cycle_start));
39 InternalReturn::InternalReturn (Session& s, const XMLNode& node)
40 : Return (s, node, true)
43 CycleStart.connect (mem_fun (*this, &InternalReturn::cycle_start));
47 InternalReturn::run (BufferSet& bufs, sframes_t /*start_frame*/, sframes_t /*end_frame*/, nframes_t nframes)
49 if (!_active && !_pending_active) {
53 /* no lock here, just atomic fetch */
55 if (g_atomic_int_get(&user_count) == 0) {
56 /* nothing to do - nobody is feeding us anything */
60 bufs.merge_from (buffers, nframes);
61 _active = _pending_active;
65 InternalReturn::configure_io (ChanCount in, ChanCount out)
67 IOProcessor::configure_io (in, out);
68 allocate_buffers (_session.engine().frames_per_cycle());
73 InternalReturn::set_block_size (nframes_t nframes)
75 allocate_buffers (nframes);
79 InternalReturn::allocate_buffers (nframes_t nframes)
81 buffers.ensure_buffers (_configured_input, nframes);
82 buffers.set_count (_configured_input);
86 InternalReturn::get_buffers ()
88 Glib::Mutex::Lock lm (_session.engine().process_lock());
89 /* use of g_atomic here is just for code consistency - its protected by the lock
92 g_atomic_int_inc (&user_count);
97 InternalReturn::release_buffers ()
99 Glib::Mutex::Lock lm (_session.engine().process_lock());
101 /* use of g_atomic here is just for code consistency - its protected by the lock
104 (void) g_atomic_int_dec_and_test (&user_count);
109 InternalReturn::cycle_start (nframes_t nframes)
111 /* called from process cycle - no lock necessary */
113 /* don't bother with this if nobody is going to feed us anything */
114 buffers.silence (nframes, 0);
119 InternalReturn::state (bool full)
121 XMLNode& node (Return::state (full));
123 node.add_property("type", "intreturn");
128 InternalReturn::get_state()
134 InternalReturn::set_state (const XMLNode& node, int version)
136 return Return::set_state (node, version);
140 InternalReturn::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
147 InternalReturn::visible () const