blazoncek/WLED

2D GEQ: show top row, add nr of bands, remove center sliders, remove 2d centerbars

Closed this issue · 0 comments

Please replace 2d_GEQ with this:

uint16_t WS2812FX::mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma.
if (!isMatrix) return mode_static(); // not a 2D set-up

int NUMB_BANDS = map(SEGMENT.custom1, 0, 255, 1, 16);

const uint16_t cols = SEGMENT.virtualWidth();
const uint16_t rows = SEGMENT.virtualHeight();
const uint16_t dataSize = sizeof(CRGB) * SEGMENT.width() * SEGMENT.height(); // using width*height prevents reallocation if mirroring is enabled

if (!SEGENV.allocateData(dataSize + cols*sizeof(uint16_t))) return mode_static(); //allocation failed
CRGB leds = reinterpret_cast<CRGB>(SEGENV.data);
uint16_t previousBarHeight = reinterpret_cast<uint16_t>(SEGENV.data + dataSize);

uint8_t *fftResult = nullptr;
um_data_t um_data;
if (usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
fftResult = (uint8_t
)um_data->u_data[8];
} else {
// add support for no audio data
}
if (!fftResult) return mode_static();

//static int previousBarHeight[64]; //array of previous bar heights per frequency band
if (SEGENV.call == 0) for (uint16_t i=0; i<cols; i++) previousBarHeight[i] = 0;

fadeToBlackBy(leds, 96+(SEGMENT.speed>>2));

bool rippleTime = false;
if (millis() - SEGENV.step >= (256 - SEGMENT.intensity)) {
SEGENV.step = millis();
rippleTime = true;
}

uint16_t xCount = cols;

for (uint16_t x=0; x < xCount; x++) {
uint8_t band = map(x, 0, xCount-1, 0, NUMB_BANDS - 1);
uint16_t barHeight = map(fftResult[band], 0, 255, 0, rows);
if (barHeight > previousBarHeight[x]) previousBarHeight[x] = barHeight; //drive the peak up

uint16_t yStartBar = 0;
uint16_t yStartPeak = 0;

for (uint16_t y=0; y < rows; y++) {
  uint16_t colorIndex;
  if (SEGMENT.custom2 > 128) { //color_vertical / color bars toggle 
   colorIndex = map(y, 0, rows - 1, 0, 255);
  } else
    colorIndex = band * 17;

  CRGB heightColor = color_from_palette(colorIndex, false, PALETTE_SOLID_WRAP, 0);
  CRGB ledColor = CRGB::Black; //if not part of bars or peak, make black (not fade to black)

  //bar
  if (y >= yStartBar && y < yStartBar + barHeight)
    ledColor = heightColor;

  //low and high peak (must exist && on peak position && only below if centered_horizontal effect)
  //bool isYPeak = (centered_horizontal && y==yStartPeak) || y==(yStartPeak + previousBarHeight[x]);
  bool isYPeak = (y==yStartPeak || y==yStartPeak + previousBarHeight[x]-1) && (y!=yStartPeak);
  if ((previousBarHeight[x] > 0) && isYPeak)
    ledColor = SEGCOLOR(2)==CRGB::Black ? heightColor : CRGB(SEGCOLOR(2)); //low peak

  leds[XY(x, rows - 1 - y)] += ledColor;
}

if (rippleTime && previousBarHeight[x]>0) previousBarHeight[x] --;    //delay/ripple effect

}

setPixels(leds);
return FRAMETIME;
} // mode_2DGEQ()
static const char *_data_FX_MODE_2DGEQ PROGMEM = " ♫ 2D GEQ@Bar speed,Ripple decay,# of bands=255,Color bars=64;!,,Peak Color;!=11";