Give the _sends member of InternalReturn its own mutex,
[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 #include "ardour/audioengine.h"
29
30 using namespace std;
31 using namespace ARDOUR;
32
33 InternalReturn::InternalReturn (Session& s)
34         : Return (s, true)
35 {
36         _display_to_user = false;
37 }
38
39 void
40 InternalReturn::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_frame*/, pframes_t nframes, bool)
41 {
42         if (!_active && !_pending_active) {
43                 return;
44         }
45
46         Glib::Mutex::Lock lm (_sends_mutex, Glib::TRY_LOCK);
47         
48         if (lm.locked ()) {
49                 for (list<InternalSend*>::iterator i = _sends.begin(); i != _sends.end(); ++i) {
50                         if ((*i)->active ()) {
51                                 bufs.merge_from ((*i)->get_buffers(), nframes);
52                         }
53                 }
54         }
55
56         _active = _pending_active;
57 }
58
59 void
60 InternalReturn::add_send (InternalSend* send)
61 {
62         Glib::Mutex::Lock lm (_sends_mutex);
63         _sends.push_back (send);
64 }
65
66 void
67 InternalReturn::remove_send (InternalSend* send)
68 {
69         Glib::Mutex::Lock lm (_sends_mutex);
70         _sends.remove (send);
71 }
72
73 XMLNode&
74 InternalReturn::state (bool full)
75 {
76         XMLNode& node (Return::state (full));
77         /* override type */
78         node.add_property("type", "intreturn");
79         return node;
80 }
81
82 XMLNode&
83 InternalReturn::get_state()
84 {
85         return state (true);
86 }
87
88 bool
89 InternalReturn::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
90 {
91         out = in;
92         return true;
93 }
94
95 bool
96 InternalReturn::configure_io (ChanCount in, ChanCount out)
97 {
98         IOProcessor::configure_io (in, out);
99         return true;
100 }