don't display internal returns to user
[ardour.git] / libs / ardour / internal_return.cc
1 /*
2     Copyright (C) 2009 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 <glibmm/thread.h>
20
21 #include "pbd/failed_constructor.h"
22
23 #include "ardour/internal_return.h"
24 #include "ardour/mute_master.h"
25 #include "ardour/session.h"
26
27 using namespace std;
28 using namespace ARDOUR;
29
30 PBD::Signal1<void,nframes_t> InternalReturn::CycleStart;
31
32 InternalReturn::InternalReturn (Session& s)
33         : Return (s, true)
34         , user_count (0)
35 {
36         CycleStart.connect_same_thread (*this, boost::bind (&InternalReturn::cycle_start, this, _1));
37         _display_to_user = false;
38 }
39
40 void
41 InternalReturn::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_frame*/, nframes_t nframes, bool)
42 {
43         if (!_active && !_pending_active) {
44                 return;
45         }
46
47         /* no lock here, just atomic fetch */
48
49         if (g_atomic_int_get(&user_count) == 0) {
50                 /* nothing to do - nobody is feeding us anything */
51                 return;
52         }
53
54         bufs.merge_from (buffers, nframes);
55         _active = _pending_active;
56 }
57
58 bool
59 InternalReturn::configure_io (ChanCount in, ChanCount out)
60 {
61         IOProcessor::configure_io (in, out);
62         allocate_buffers (_session.engine().frames_per_cycle());
63         return true;
64 }
65
66 int
67 InternalReturn::set_block_size (nframes_t nframes)
68 {
69         allocate_buffers (nframes);
70         return 0;
71 }
72
73 void
74 InternalReturn::allocate_buffers (nframes_t nframes)
75 {
76         buffers.ensure_buffers (_configured_input, nframes);
77         buffers.set_count (_configured_input);
78 }
79
80 BufferSet*
81 InternalReturn::get_buffers ()
82 {
83         Glib::Mutex::Lock lm (_session.engine().process_lock());
84         /* use of g_atomic here is just for code consistency - its protected by the lock
85            for writing.
86         */
87         g_atomic_int_inc (&user_count);
88         return &buffers;
89 }
90
91 void
92 InternalReturn::release_buffers ()
93 {
94         Glib::Mutex::Lock lm (_session.engine().process_lock());
95         if (user_count) {
96                 /* use of g_atomic here is just for code consistency - its protected by the lock
97                    for writing.
98                 */
99                 (void) g_atomic_int_dec_and_test (&user_count);
100         }
101 }
102
103 void
104 InternalReturn::cycle_start (nframes_t nframes)
105 {
106         /* called from process cycle - no lock necessary */
107         if (user_count) {
108                 /* don't bother with this if nobody is going to feed us anything */
109                 buffers.silence (nframes, 0);
110         }
111 }
112
113 XMLNode&
114 InternalReturn::state (bool full)
115 {
116         XMLNode& node (Return::state (full));
117         /* override type */
118         node.add_property("type", "intreturn");
119         return node;
120 }
121
122 XMLNode&
123 InternalReturn::get_state()
124 {
125         return state (true);
126 }
127
128 int
129 InternalReturn::set_state (const XMLNode& node, int version)
130 {
131         return Return::set_state (node, version);
132 }
133
134 bool
135 InternalReturn::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
136 {
137         out = in;
138         return true;
139 }
140