#include "ardour/audio_buffer.h"
#include "ardour/runtime_functions.h"
-namespace ARDOUR {
+using namespace std;
+using namespace ARDOUR;
+
+sigc::signal<void> Metering::Meter;
+Glib::StaticMutex Metering::m_meter_signal_lock;
+
+sigc::connection
+Metering::connect (sigc::slot<void> the_slot)
+{
+ // SignalProcessor::Meter is emitted from another thread so the
+ // Meter signal must be protected.
+ Glib::Mutex::Lock guard (m_meter_signal_lock);
+ return Meter.connect (the_slot);
+}
+
+void
+Metering::disconnect (sigc::connection& c)
+{
+ Glib::Mutex::Lock guard (m_meter_signal_lock);
+ c.disconnect ();
+}
+
+/**
+ Update the meters.
+
+ The meter signal lock is taken to prevent modification of the
+ Meter signal while updating the meters, taking the meter signal
+ lock prior to taking the io_lock ensures that all IO will remain
+ valid while metering.
+*/
+void
+Metering::update_meters()
+{
+ Glib::Mutex::Lock guard (m_meter_signal_lock);
+ Meter(); /* EMIT SIGNAL */
+}
/** 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, sframes_t start_frame, sframes_t end_frame, nframes_t nframes)
{
+ 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());
+
uint32_t n = 0;
- uint32_t meterable = std::min(bufs.count().n_total(), (uint32_t)_peak_power.size());
- uint32_t limit = std::min (meterable, (uint32_t)bufs.count().n_midi());
-
- // Meter what we have (midi)
- for ( ; n < limit; ++n) {
- float val = 0;
-
- // GUI needs a better MIDI meter, not much information can be
- // expressed through peaks alone
- for (MidiBuffer::iterator i = bufs.get_midi(n).begin(); i != bufs.get_midi(n).end(); ++i) {
- const Evoral::MIDIEvent<nframes_t> ev(*i, false);
+
+ // 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);
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;
- //printf("V %d -> %f\n", (int)((Byte)ev.buffer[2]), this_vel);
- if (this_vel > val)
+ if (this_vel > val) {
val = this_vel;
+ }
} else {
val += 1.0 / bufs.get_midi(n).capacity();
- if (val > 1.0)
+ if (val > 1.0) {
val = 1.0;
+ }
}
}
-
_peak_power[n] = val;
-
}
-
- limit = std::min (meterable, bufs.count().n_audio());
- // Meter what we have (audio)
- for ( ; n < limit; ++n) {
- _peak_power[n] = compute_peak (bufs.get_audio(n).data(), nframes, _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]);
}
// Zero any excess peaks
- for (size_t n = meterable; n < _peak_power.size(); ++n) {
- _peak_power[n] = 0;
+ for (uint32_t i = n; i < _peak_power.size(); ++i) {
+ _peak_power[i] = 0.0f;
}
}
+PeakMeter::PeakMeter (Session& s, const XMLNode& node)
+ : Processor (s, node)
+{
+}
+
void
PeakMeter::reset ()
{
for (size_t i = 0; i < _peak_power.size(); ++i) {
- _peak_power[i] = 0;
+ _peak_power[i] = 0.0f;
}
}
}
}
+bool
+PeakMeter::can_support_io_configuration (const ChanCount& in, ChanCount& out) const
+{
+ out = in;
+ return true;
+}
+
bool
PeakMeter::configure_io (ChanCount in, ChanCount out)
{
- /* we're transparent no matter what. fight the power. */
- if (out != in) {
+ if (out != in) { // always 1:1
return false;
}
-
+
uint32_t limit = in.n_total();
-
+
while (_peak_power.size() > limit) {
_peak_power.pop_back();
_visible_peak_power.pop_back();
}
/** 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 ()
{
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 */
}
}
-} // namespace ARDOUR
+XMLNode&
+PeakMeter::state (bool full_state)
+{
+ XMLNode& node (Processor::state (full_state));
+ node.add_property("type", "meter");
+ return node;
+}
+