62 lines
1.6 KiB
C++
62 lines
1.6 KiB
C++
#include <VulcanoLE/Scripts/PoliceLike.h>
|
|
|
|
namespace VIZ {
|
|
PoliceLike::PoliceLike(AudioGrabber *pGrabber, Vulcan121 *pVulcan121) : VIZ(pGrabber, pVulcan121) {
|
|
|
|
}
|
|
|
|
void PoliceLike::onSetup() {
|
|
keyboard->sendToLEDs({ 0, 0, 0, 0 });
|
|
grabber->requestMode = AudioGrabber::ReqMode::FFT;
|
|
usleep(100000);
|
|
}
|
|
|
|
void PoliceLike::onTick(float delta) {
|
|
auto map = Vulcan121::createEmptyLEDMap();
|
|
auto data = grabber->fft.getData()->leftChannel;
|
|
auto val = 0.0;
|
|
for (int i = 1; i < 3; ++i) {
|
|
if (data[i] > val) {
|
|
val = data[i];
|
|
}
|
|
}
|
|
switchOnPeak(val);
|
|
tick++;
|
|
int colorInd = left ? 0 : 1;
|
|
colors[colorInd].a = val;
|
|
int colOff = left ? 0 : 9;
|
|
int max = left ? 10 : 12;
|
|
for (int i = 0; i < max; ++i) {
|
|
auto col = keyboard->getColumn(i + colOff);
|
|
for (int j = 0; j < col->count; ++j) {
|
|
map[0].key[col->index[j]] = colors[colorInd];
|
|
}
|
|
}
|
|
keyboard->sendLedMap(map, true);
|
|
}
|
|
|
|
void PoliceLike::switchOnPeak(double peak) {
|
|
if (tick < 3) {
|
|
return;
|
|
}
|
|
if (peak < 20) {
|
|
lastPeak = -1;
|
|
return;
|
|
}
|
|
// we dont have any data! reset ;)
|
|
if (lastPeak == -1) {
|
|
lastPeak = peak;
|
|
return;
|
|
}
|
|
lastPeak -= decayRate;
|
|
if (peak > 100 && peak > lastPeak + threshold) {
|
|
left = !left;
|
|
lastPeak = peak;
|
|
tick = 0;
|
|
}
|
|
}
|
|
|
|
const char *PoliceLike::name() {
|
|
return m_name.c_str();
|
|
}
|
|
} |