ardour
return.cc
Go to the documentation of this file.
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/amp.h"
25 #include "ardour/audioengine.h"
26 #include "ardour/buffer_set.h"
27 #include "ardour/io.h"
28 #include "ardour/meter.h"
29 #include "ardour/return.h"
30 #include "ardour/session.h"
31 
32 #include "i18n.h"
33 
34 using namespace ARDOUR;
35 using namespace PBD;
36 
37 std::string
38 Return::name_and_id_new_return (Session& s, uint32_t& bitslot)
39 {
40  bitslot = s.next_return_id();
41  return string_compose (_("return %1"), bitslot + 1);
42 }
43 
44 
45 Return::Return (Session& s, bool internal)
46  : IOProcessor (s, (internal ? false : true), false,
47  name_and_id_new_return (s, _bitslot))
48  , _metering (false)
49 {
50  /* never muted */
51 
52  _amp.reset (new Amp (_session));
53  _meter.reset (new PeakMeter (_session, name()));
54 }
55 
57 {
59 }
60 
61 XMLNode&
63 {
64  return state (true);
65 }
66 
67 XMLNode&
68 Return::state(bool full)
69 {
70  XMLNode& node = IOProcessor::state(full);
71  char buf[32];
72  node.add_property ("type", "return");
73  snprintf (buf, sizeof (buf), "%" PRIu32, _bitslot);
74  node.add_property ("bitslot", buf);
75 
76  return node;
77 }
78 
79 int
80 Return::set_state (const XMLNode& node, int version)
81 {
82  XMLNodeList nlist = node.children();
83  XMLNodeIterator niter;
84  const XMLProperty* prop;
85  const XMLNode* insert_node = &node;
86 
87  /* Return has regular IO automation (gain, pan) */
88 
89  for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
90  if ((*niter)->name() == "IOProcessor") {
91  insert_node = *niter;
92  } else if ((*niter)->name() == X_("Automation")) {
93  // _io->set_automation_state (*(*niter), Evoral::Parameter(GainAutomation));
94  }
95  }
96 
97  IOProcessor::set_state (*insert_node, version);
98 
99  if (!node.property ("ignore-bitslot")) {
100  if ((prop = node.property ("bitslot")) == 0) {
102  } else {
104  sscanf (prop->value().c_str(), "%" PRIu32, &_bitslot);
106  }
107  }
108 
109  return 0;
110 }
111 
112 void
113 Return::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool)
114 {
115  if ((!_active && !_pending_active) || _input->n_ports() == ChanCount::ZERO) {
116  return;
117  }
118 
119  _input->collect_input (bufs, nframes, _configured_input);
121 
122  // Can't automate gain for sends or returns yet because we need different buffers
123  // so that we don't overwrite the main automation data for the route amp
124  // _amp->setup_gain_automation (start_frame, end_frame, nframes);
125  _amp->run (bufs, start_frame, end_frame, nframes, true);
126 
127  if (_metering) {
128  if (_amp->gain_control()->get_value() == 0) {
129  _meter->reset();
130  } else {
131  _meter->run (bufs, start_frame, end_frame, nframes, true);
132  }
133  }
134 
136 }
137 
138 bool
140 {
141  out = in + _input->n_ports();
142  return true;
143 }
144 
145 bool
147 {
148  if (out != in + _input->n_ports()) {
149  return false;
150  }
151 
152  // Ensure there are enough buffers (since we add some)
153  if (_session.get_scratch_buffers(in).count() < out) {
156  }
157 
158  Processor::configure_io(in, out);
159 
160  return true;
161 }
162 
void run(BufferSet &bufs, framepos_t start_frame, framepos_t end_frame, pframes_t nframes, bool)
Definition: return.cc:113
XMLNodeList::iterator XMLNodeIterator
Definition: xml++.h:48
ARDOUR::Session & _session
bool can_support_io_configuration(const ChanCount &in, ChanCount &out)
Definition: return.cc:139
uint32_t _bitslot
Definition: return.h:74
const std::string & value() const
Definition: xml++.h:159
void set_count(const ChanCount &count)
Definition: buffer_set.h:93
uint32_t pframes_t
Definition: types.h:61
XMLNode & get_state(void)
Definition: return.cc:62
const XMLNodeList & children(const std::string &str=std::string()) const
Definition: xml++.cc:329
std::list< XMLNode * > XMLNodeList
Definition: xml++.h:44
bool configure_io(ChanCount in, ChanCount out)
Definition: return.cc:146
int set_state(const XMLNode &, int version)
ChanCount _configured_output
Definition: processor.h:132
#define _(Text)
Definition: i18n.h:11
#define X_(Text)
Definition: i18n.h:13
XMLProperty * property(const char *)
Definition: xml++.cc:413
bool _metering
Definition: return.h:66
uint32_t next_return_id()
Definition: session.cc:4421
int set_state(const XMLNode &, int version)
Definition: return.cc:80
Definition: amp.h:29
static PBD::Signal1< void, ChanCount > PortCountChanged
Definition: io.h:177
virtual bool configure_io(ChanCount in, ChanCount out)
Definition: processor.cc:246
int64_t framepos_t
Definition: types.h:66
XMLProperty * add_property(const char *name, const std::string &value)
XMLNode & state(bool full_state)
static std::string name_and_id_new_return(Session &, uint32_t &)
Definition: return.cc:38
Glib::Threads::Mutex & process_lock()
Definition: audioengine.h:132
boost::shared_ptr< IO > _input
Definition: io_processor.h:83
Definition: xml++.h:95
boost::shared_ptr< Amp > _amp
Definition: return.h:67
std::string name() const
const ChanCount & count() const
Definition: buffer_set.h:87
XMLNode & state(bool full)
Definition: return.cc:68
void mark_return_id(uint32_t)
Definition: session.cc:4465
Definition: debug.h:30
virtual ~Return()
Definition: return.cc:56
void unmark_return_id(uint32_t)
Definition: session.cc:4505
boost::shared_ptr< PeakMeter > _meter
Definition: return.h:68
static const ChanCount ZERO
Definition: chan_count.h:149
BufferSet & get_scratch_buffers(ChanCount count=ChanCount::ZERO, bool silence=true)
Definition: session.cc:4851
AudioEngine & engine()
Definition: session.h:546
Return(Session &, bool internal=false)
Definition: return.cc:45
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208
ChanCount _configured_input
Definition: processor.h:131