From b22e0b208492bc3d47789c38aa39688b6ad504ac Mon Sep 17 00:00:00 2001 From: Ewoud Date: Thu, 15 Feb 2024 17:50:20 +0100 Subject: [PATCH] Add Waverly2D effect + default 50% blending of effects --- src/App/AppEffects.h | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/App/AppLeds.h | 10 +++++----- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/App/AppEffects.h b/src/App/AppEffects.h index 5c550ab7..c64a0126 100644 --- a/src/App/AppEffects.h +++ b/src/App/AppEffects.h @@ -719,6 +719,51 @@ class ScrollingText2D: public Effect { }; +class Waverly2D: public Effect { +public: + const char * name() { + return "Waverly 2D"; + } + + void loop(Leds &leds) { + CRGBPalette16 pal = getPalette(leds.rowNr); + uint8_t amplification = mdl->getValue("Amplification", leds.rowNr); + uint8_t sensitivity = mdl->getValue("Sensitivity", leds.rowNr); + bool noClouds = mdl->getValue("No Clouds", leds.rowNr); + // bool soundPressure = mdl->getValue("Sound Pressure", leds.rowNr); + // bool agcDebug = mdl->getValue("AGC debug", leds.rowNr); + + leds.fadeToBlackBy(amplification); + // if (agcDebug && soundPressure) soundPressure = false; // only one of the two at any time + // if ((soundPressure) && (wledAudioMod->sync.volumeSmth > 0.5f)) wledAudioMod->sync.volumeSmth = wledAudioMod->sync.soundPressure; // show sound pressure instead of volume + // if (agcDebug) wledAudioMod->sync.volumeSmth = 255.0 - wledAudioMod->sync.agcSensitivity; // show AGC level instead of volume + + long t = now / 2; + Coord3D pos; + for (pos.x = 0; pos.x < leds.size.x; pos.x++) { + uint16_t thisVal = wledAudioMod->sync.volumeSmth*sensitivity/64 * inoise8(pos.x * 45 , t , t)/64; // WLEDMM back to SR code + uint16_t thisMax = min(map(thisVal, 0, 512, 0, leds.size.y), (long)leds.size.x); + + for (pos.y = 0; pos.y < thisMax; pos.y++) { + if (!noClouds) + leds.addPixelColor(pos, ColorFromPalette(pal, map(pos.y, 0, thisMax, 250, 0), 255, LINEARBLEND)); + leds.addPixelColor(leds.XY((leds.size.x - 1) - pos.x, (leds.size.y - 1) - pos.y), ColorFromPalette(pal, map(pos.y, 0, thisMax, 250, 0), 255, LINEARBLEND)); + } + } + leds.blur2d(16); + + } + void controls(JsonObject parentVar, Leds &leds) { + addPalette(parentVar, 4); + ui->initSlider(parentVar, "Amplification", 128); + ui->initSlider(parentVar, "Sensitivity", 128); + ui->initCheckBox(parentVar, "No Clouds"); + // ui->initCheckBox(parentVar, "Sound Pressure"); + // ui->initCheckBox(parentVar, "AGC debug"); + } +}; + + #ifdef STARMOD_USERMOD_WLEDAUDIO class GEQEffect:public Effect { @@ -973,6 +1018,7 @@ class Effects { effects.push_back(new BouncingBalls1D); effects.push_back(new RingRandomFlow); effects.push_back(new ScrollingText2D); + effects.push_back(new Waverly2D); #ifdef STARMOD_USERMOD_WLEDAUDIO effects.push_back(new GEQEffect); effects.push_back(new AudioRings); diff --git a/src/App/AppLeds.h b/src/App/AppLeds.h index aea109b5..f204f61e 100644 --- a/src/App/AppLeds.h +++ b/src/App/AppLeds.h @@ -102,14 +102,14 @@ class Leds { // maps the virtual led to the physical led(s) and assign a color to it - void setPixelColor(uint16_t indexV, CRGB color, uint8_t blendAmount = 0); - void setPixelColor(Coord3D pixel, CRGB color, uint8_t blendAmount = 0) {setPixelColor(XYZ(pixel), color, blendAmount);} + void setPixelColor(uint16_t indexV, CRGB color, uint8_t blendAmount = 128); + void setPixelColor(Coord3D pixel, CRGB color, uint8_t blendAmount = 128) {setPixelColor(XYZ(pixel), color, blendAmount);} CRGB getPixelColor(uint16_t indexV); + CRGB getPixelColor(Coord3D pixel) {return getPixelColor(XYZ(pixel));} - void addPixelColor(uint16_t indexV, CRGB color) { - setPixelColor(indexV, getPixelColor(indexV) + color); - } + void addPixelColor(uint16_t indexV, CRGB color) {setPixelColor(indexV, getPixelColor(indexV) + color);} + void addPixelColor(Coord3D pixel, CRGB color) {setPixelColor(pixel, getPixelColor(pixel) + color);} void fadeToBlackBy(uint8_t fadeBy = 255); void fill_solid(const struct CRGB& color);