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