VulcanoLE/src/VulcanoLE/Scripts/Loudness.cpp

50 lines
1.5 KiB
C++

#include <VulcanoLE/Scripts/Loudness.h>
namespace VIZ {
Loudness::Loudness(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : VIZ(pGrabber, pVulcan121) {}
void Loudness::onSetup() {
keyboard->sendToLEDs({ 0, 0, 0, 0 });
grabber->requestMode = AudioGrabber::ReqMode::PEAK;
usleep(100000);
}
void Loudness::onTick(float delta) {
Vulcan121::fadeOutMap(data, tailFactor);
stereoSample val = grabber->getLoudness();
val.l = val.l > 1.0f ? 1.0f : val.l;
val.r = val.r > 1.0f ? 1.0f : val.r;
setForChannel(val.l, 0);
setForChannel(val.r, 1);
keyboard->sendLedMap(data, false);
}
const char *Loudness::name() {
return m_name.c_str();
}
void Loudness::setForChannel(float value, int channel) {
// because we have stereo we need to move on the rows
int offset = channel == 0 ? 1 : 3;
int until = channel == 0 ? 3 : 5;
colours[channel].a = value * 128.0;
for (int i = offset; i < until; ++i) {
auto row = keyboard->getRow(i);
int to = row->count * value;
for (int j = 0; j < to; ++j) {
auto index = row->index[j];
data[0].key[index] = colours[channel];
}
}
drawFrame(0);
drawFrame(5);
}
void Loudness::drawFrame(int toRow) {
auto row = keyboard->getRow(toRow);
for (int j = 0; j < row->count; ++j) {
auto index = row->index[j];
data[0].key[index] = colours[2];
}
}
}