fix initialization of gain for Listen internal sends (to monitor bus); remove pannabl...
[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/audio_buffer.h"
24 #include "ardour/internal_return.h"
25 #include "ardour/mute_master.h"
26 #include "ardour/session.h"
27 #include "ardour/internal_send.h"
28
29 using namespace std;
30 using namespace ARDOUR;
31
32 PBD::Signal1<void, pframes_t> InternalReturn::CycleStart;
33
34 InternalReturn::InternalReturn (Session& s)
35         : Return (s, true)
36 {
37         CycleStart.connect_same_thread (*this, boost::bind (&InternalReturn::cycle_start, this, _1));
38         _display_to_user = false;
39 }
40
41 void
42 InternalReturn::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_frame*/, pframes_t nframes, bool)
43 {
44         if (!_active && !_pending_active) {
45                 return;
46         }
47
48         /* _sends is only modified with the process lock held, so this is ok, I think */
49
50         for (list<InternalSend*>::iterator i = _sends.begin(); i != _sends.end(); ++i) {
51                 if ((*i)->active ()) {
52                         bufs.merge_from ((*i)->get_buffers(), nframes);
53                 }
54         }
55
56 #if 0
57         if (_session.transport_rolling()) {
58                 for (BufferSet::audio_iterator b = bufs.audio_begin(); b != bufs.audio_end(); ++b) {
59                         Sample* p = b->data ();
60                         for (pframes_t n = 0; n < nframes; ++n) {
61                                 if (p[n] != 0.0) {
62                                         cerr << "\tnon-zero data received\n";
63                                         break;
64                                 }
65                         }
66                 }
67         }
68 #endif
69
70
71         _active = _pending_active;
72 }
73
74 bool
75 InternalReturn::configure_io (ChanCount in, ChanCount out)
76 {
77         IOProcessor::configure_io (in, out);
78         allocate_buffers (_session.engine().frames_per_cycle());
79         return true;
80 }
81
82 int
83 InternalReturn::set_block_size (pframes_t nframes)
84 {
85         allocate_buffers (nframes);
86         return 0;
87 }
88
89 void
90 InternalReturn::allocate_buffers (pframes_t nframes)
91 {
92         buffers.ensure_buffers (_configured_input, nframes);
93         buffers.set_count (_configured_input);
94 }
95
96 void
97 InternalReturn::add_send (InternalSend* send)
98 {
99         Glib::Mutex::Lock lm (_session.engine().process_lock());
100         _sends.push_back (send);
101 }
102
103 void
104 InternalReturn::remove_send (InternalSend* send)
105 {
106         Glib::Mutex::Lock lm (_session.engine().process_lock());
107         _sends.remove (send);
108 }
109
110 void
111 InternalReturn::cycle_start (pframes_t nframes)
112 {
113         /* called from process cycle - no lock necessary */
114         if (!_sends.empty ()) {
115                 /* don't bother with this if nobody is going to feed us anything */
116                 buffers.silence (nframes, 0);
117         }
118 }
119
120 XMLNode&
121 InternalReturn::state (bool full)
122 {
123         XMLNode& node (Return::state (full));
124         /* override type */
125         node.add_property("type", "intreturn");
126         return node;
127 }
128
129 XMLNode&
130 InternalReturn::get_state()
131 {
132         return state (true);
133 }
134
135 int
136 InternalReturn::set_state (const XMLNode& node, int version)
137 {
138         return Return::set_state (node, version);
139 }
140
141 bool
142 InternalReturn::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
143 {
144         out = in;
145         return true;
146 }
147
148