852f27d38fdb8224c3d47f79b01f717ba1d7ad3b
[ardour.git] / libs / ardour / send.cc
1 /*
2     Copyright (C) 2000 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
20 #include <algorithm>
21
22 #include "pbd/xml++.h"
23
24 #include "ardour/send.h"
25 #include "ardour/session.h"
26 #include "ardour/port.h"
27 #include "ardour/audio_port.h"
28 #include "ardour/buffer_set.h"
29 #include "ardour/meter.h"
30 #include "ardour/panner.h"
31 #include "ardour/io.h"
32
33 #include "i18n.h"
34
35 using namespace ARDOUR;
36 using namespace PBD;
37
38 Send::Send (Session& s)
39         : Delivery (s, string_compose (_("send %1"), (_bitslot = s.next_send_id()) + 1), Delivery::Send)
40 {
41         ProcessorCreated (this); /* EMIT SIGNAL */
42 }
43
44 Send::Send (Session& s, const XMLNode& node)
45         : Delivery (s, "send", Delivery::Send)
46 {
47         if (set_state (node)) {
48                 throw failed_constructor();
49         }
50
51         ProcessorCreated (this); /* EMIT SIGNAL */
52 }
53
54 Send::~Send ()
55 {
56         GoingAway ();
57 }
58
59 XMLNode&
60 Send::get_state(void)
61 {
62         return state (true);
63 }
64
65 XMLNode&
66 Send::state(bool full)
67 {
68         XMLNode& node = IOProcessor::state(full);
69         char buf[32];
70         node.add_property ("type", "send");
71         snprintf (buf, sizeof (buf), "%" PRIu32, _bitslot);
72         node.add_property ("bitslot", buf);
73
74         return node;
75 }
76
77 int
78 Send::set_state(const XMLNode& node)
79 {
80         XMLNodeList nlist = node.children();
81         XMLNodeIterator niter;
82         const XMLProperty* prop;
83
84         if ((prop = node.property ("bitslot")) == 0) {
85                 _bitslot = _session.next_send_id();
86         } else {
87                 sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot);
88                 _session.mark_send_id (_bitslot);
89         }
90
91         const XMLNode* insert_node = &node;
92
93         /* Send has regular IO automation (gain, pan) */
94
95         for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
96                 if ((*niter)->name() == IOProcessor::state_node_name) {
97                         insert_node = *niter;
98                 } else if ((*niter)->name() == X_("Automation")) {
99                         // _io->set_automation_state (*(*niter), Evoral::Parameter(GainAutomation));
100                 }
101         }
102         
103         IOProcessor::set_state (*insert_node);
104
105         return 0;
106 }
107
108 bool
109 Send::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
110 {
111         if (_io->n_inputs() == ChanCount::ZERO && _io->n_outputs() == ChanCount::ZERO) {
112
113                 /* not configured yet, we can support anything */
114
115                 out = in;
116                 return true; /* we can support anything the first time we're asked */
117
118         } else {
119
120                 /* for a send, processor input corresponds to IO output */
121
122                 out = in;
123                 return true;
124         }
125
126         return false;
127 }
128
129 bool
130 Send::configure_io (ChanCount in, ChanCount out)
131 {
132         /* we're transparent no matter what.  fight the power. */
133
134         if (out != in) {
135                 return false;
136         }
137
138         if (_io->ensure_io (ChanCount::ZERO, in, false, this) != 0) {
139                 return false;
140         }
141
142         Processor::configure_io(in, out);
143         _io->reset_panner();
144
145         return true;
146 }
147
148 /** Set up the XML description of a send so that its name is unique.
149  *  @param state XML send state.
150  *  @param session Session.
151  */
152 void
153 Send::make_unique (XMLNode &state, Session &session)
154 {
155         uint32_t const bitslot = session.next_send_id() + 1;
156
157         char buf[32];
158         snprintf (buf, sizeof (buf), "%" PRIu32, bitslot);
159         state.property("bitslot")->set_value (buf);
160
161         std::string const name = string_compose (_("send %1"), bitslot);
162         
163         state.property("name")->set_value (name);
164
165         XMLNode* io = state.child ("IO");
166         if (io) {
167                 io->property("name")->set_value (name);
168         }
169 }