/*
- Copyright (C) 2006 Paul Davis
-
+ Copyright (C) 2006 Paul Davis
+
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
-
+
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
-
+
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
675 Mass Ave, Cambridge, MA 02139, USA.
using namespace std;
-namespace ARDOUR {
+using namespace ARDOUR;
+PBD::Signal0<void> Metering::Meter;
/** Get peaks from @a bufs
* Input acceptance is lenient - the first n buffers from @a bufs will
* be set to 0.
*/
void
-PeakMeter::run_in_place (BufferSet& bufs, nframes_t start_frame, nframes_t end_frame, nframes_t nframes)
+PeakMeter::run (BufferSet& bufs, framepos_t /*start_frame*/, framepos_t /*end_frame*/, pframes_t nframes, bool)
{
- const uint32_t n_audio = min(_configured_input.n_audio(), bufs.count().n_audio());
- const uint32_t n_midi = min(_configured_input.n_midi(), bufs.count().n_midi());
-
+ if (!_active && !_pending_active) {
+ return;
+ }
+
+ // cerr << "meter " << name() << " runs with " << bufs.available() << " inputs\n";
+
+ const uint32_t n_audio = min (current_meters.n_audio(), bufs.count().n_audio());
+ const uint32_t n_midi = min (current_meters.n_midi(), bufs.count().n_midi());
+
uint32_t n = 0;
-
+
// Meter MIDI in to the first n_midi peaks
for (uint32_t i = 0; i < n_midi; ++i, ++n) {
float val = 0.0f;
for (MidiBuffer::iterator e = bufs.get_midi(i).begin(); e != bufs.get_midi(i).end(); ++e) {
- const Evoral::MIDIEvent<nframes_t> ev(*e, false);
+ const Evoral::MIDIEvent<framepos_t> ev(*e, false);
if (ev.is_note_on()) {
const float this_vel = log(ev.buffer()[2] / 127.0 * (M_E*M_E-M_E) + M_E) - 1.0;
if (this_vel > val) {
}
}
}
- _peak_power[n] = val;
+ _peak_power[n] = max (val, _peak_power[n]);
}
// Meter audio in to the rest of the peaks
for (uint32_t i = 0; i < n_audio; ++i, ++n) {
- _peak_power[n] = compute_peak (bufs.get_audio(i).data(), nframes, _peak_power[n]);
+ _peak_power[n] = compute_peak (bufs.get_audio(i).data(), nframes, _peak_power[n]);
}
// Zero any excess peaks
for (uint32_t i = n; i < _peak_power.size(); ++i) {
_peak_power[i] = 0.0f;
}
+
+ _active = _pending_active;
}
void
if (out != in) { // always 1:1
return false;
}
-
- uint32_t limit = in.n_total();
-
+
+ current_meters = in;
+
+ reset_max_channels (in);
+
+ return Processor::configure_io (in, out);
+}
+
+void
+PeakMeter::reflect_inputs (const ChanCount& in)
+{
+ current_meters = in;
+}
+
+void
+PeakMeter::reset_max_channels (const ChanCount& chn)
+{
+ uint32_t const limit = chn.n_total();
+
while (_peak_power.size() > limit) {
_peak_power.pop_back();
_visible_peak_power.pop_back();
assert(_peak_power.size() == limit);
assert(_visible_peak_power.size() == limit);
assert(_max_peak_power.size() == limit);
-
- return Processor::configure_io (in, out);
}
/** To be driven by the Meter signal from IO.
- * Caller MUST hold io_lock!
+ * Caller MUST hold its own processor_lock to prevent reconfiguration
+ * of meter size during this call.
*/
+
void
PeakMeter::meter ()
{
+ if (!_active) {
+ return;
+ }
+
assert(_visible_peak_power.size() == _peak_power.size());
- const size_t limit = _peak_power.size();
+ const size_t limit = min (_peak_power.size(), (size_t) current_meters.n_total ());
for (size_t n = 0; n < limit; ++n) {
- /* XXX we should use atomic exchange here */
-
/* grab peak since last read */
- float new_peak = _peak_power[n];
- _peak_power[n] = 0;
-
+ float new_peak = _peak_power[n]; /* XXX we should use atomic exchange from here ... */
+ _peak_power[n] = 0; /* ... to here */
+
/* compute new visible value using falloff */
if (new_peak > 0.0) {
- new_peak = coefficient_to_dB (new_peak);
+ new_peak = fast_coefficient_to_dB (new_peak);
} else {
new_peak = minus_infinity();
}
-
+
/* update max peak */
-
+
_max_peak_power[n] = std::max (new_peak, _max_peak_power[n]);
-
+
if (Config->get_meter_falloff() == 0.0f || new_peak > _visible_peak_power[n]) {
_visible_peak_power[n] = new_peak;
} else {
XMLNode&
PeakMeter::state (bool full_state)
{
- return get_state();
+ XMLNode& node (Processor::state (full_state));
+ node.add_property("type", "meter");
+ return node;
}
-XMLNode&
-PeakMeter::get_state()
-{
- XMLNode* node = new XMLNode(state_node_name);
- node->add_property("type", "meter");
- return *node;
-}
-} // namespace ARDOUR