@@ -8101,15 +8101,36 @@ static const char _data_FX_MODE_WATERFALL[] PROGMEM = "Waterfall@!,Adjust color,
81018101
81028102#ifndef WLED_DISABLE_2D
81038103// ///////////////////////
8104- // ** 2D GEQ //
8104+ // 1D / 2D GEQ //
81058105// ///////////////////////
8106- uint16_t mode_2DGEQ (void ) { // By Will Tatam. Code reduction by Ewoud Wijma.
8107- if (!strip.isMatrix ) return mode_static (); // not a 2D set-up
8106+
8107+ // GEQ helper: either draws 2D, or flattens pixels to 1D
8108+ static void setFlatPixelXY (bool flatMode, int x, int y, uint32_t color, unsigned cols, unsigned rows, unsigned offset) {
8109+ if ((unsigned (x) >= cols) || (unsigned (y) >= rows)) return ; // skip invisible
8110+
8111+ if (!flatMode) SEGMENT.setPixelColorXY (x, y, color); // normal 2D
8112+ else {
8113+ y = rows - y -1 ; // reverse y
8114+ if (y & 0x01 ) y = (rows + y) / 2 ; // center bars: odd pixels to the right
8115+ else y = (rows - 1 - y) / 2 ; // even pixels to the left
8116+
8117+ int pix = x*rows + y + offset; // flatten -> transpose x y so that bars stay bars
8118+ if (unsigned (pix) >= SEGLEN) return ; // skip invisible
8119+ SEGMENT.setPixelColor (pix, color);
8120+ }
8121+ }
8122+
8123+ uint16_t mode_2DGEQ (void ) { // By Will Tatam. Code reduction by Ewoud Wijma. Flat Mode added by softhack007
8124+ // if (!strip.isMatrix) return mode_static(); // not a 2D set-up, not a problem
8125+ bool flatMode = !SEGMENT.is2D ();
81088126
81098127 const int NUM_BANDS = map2 (SEGMENT.custom1 , 0 , 255 , 1 , 16 );
8110- const uint16_t cols = SEGMENT.virtualWidth ();
8111- const uint16_t rows = SEGMENT.virtualHeight ();
8112- if ((cols <=1 ) || (rows <=1 )) return mode_static (); // not really a 2D set-up
8128+ const int vLength = SEGLEN; // for flat mode
8129+ const uint16_t cols = flatMode ? min (max (2 , NUM_BANDS), (vLength+1 )/2 ) : SEGMENT.virtualWidth ();
8130+ const uint16_t rows = flatMode ? vLength / cols : SEGMENT.virtualHeight ();
8131+ const unsigned offset = flatMode ? max (0 , (vLength - rows*cols +1 ) / 2 ) : 0 ; // flatmode: always center effect
8132+
8133+ if ((cols <=1 ) || (rows <=1 )) return mode_static (); // too small
81138134
81148135 if (!SEGENV.allocateData (cols*sizeof (uint16_t ))) return mode_static (); // allocation failed
81158136 uint16_t *previousBarHeight = reinterpret_cast <uint16_t *>(SEGENV.data ); // array of previous bar heights per frequency band
@@ -8175,7 +8196,7 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma.
81758196 if (barHeight > previousBarHeight[x]) previousBarHeight[x] = barHeight; // drive the peak up
81768197
81778198 uint32_t ledColor = BLACK;
8178- if ((! SEGMENT.check1 ) && (barHeight > 0 )) { // use faster drawLine when single-color bars are needed
8199+ if ((! SEGMENT.check1 ) && !flatMode && (barHeight > 0 )) { // use faster drawLine when single-color bars are needed
81798200 ledColor = SEGMENT.color_from_palette (colorIndex, false , PALETTE_SOLID_WRAP, 0 );
81808201 SEGMENT.drawLine (int (x), max (0 ,int (rows)-barHeight), int (x), int (rows-1 ), ledColor, false ); // max(0, ...) to prevent negative Y
81818202 } else {
@@ -8184,23 +8205,25 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma.
81848205 colorIndex = map (y, 0 , rows-1 , 0 , 255 );
81858206
81868207 ledColor = SEGMENT.color_from_palette (colorIndex, false , PALETTE_SOLID_WRAP, 0 );
8187- SEGMENT. setPixelColorXY ( x, rows-1 - y, ledColor);
8208+ setFlatPixelXY (flatMode, x, rows-1 - y, ledColor, cols, rows, offset );
81888209 } }
8189- if ((SEGMENT.intensity < 255 ) && (previousBarHeight[x] > 0 ) && (previousBarHeight[x] < rows)) // WLEDMM avoid "overshooting" into other segments
8190- SEGMENT. setPixelColorXY ( x, rows - previousBarHeight[x], (SEGCOLOR (2 ) != BLACK) ? SEGCOLOR (2 ) : ledColor);
8210+ if (!flatMode && (SEGMENT.intensity < 255 ) && (previousBarHeight[x] > 0 ) && (previousBarHeight[x] < rows)) // WLEDMM avoid "overshooting" into other segments - disable ripple pixels in 1D mode
8211+ setFlatPixelXY (flatMode, x, rows - previousBarHeight[x], (SEGCOLOR (2 ) != BLACK) ? SEGCOLOR (2 ) : ledColor, cols, rows, offset );
81918212
81928213 if (rippleTime && previousBarHeight[x]>0 ) previousBarHeight[x]--; // delay/ripple effect
81938214 }
81948215
81958216#ifdef SR_DEBUG
8217+ if (!flatMode) {
81968218 // WLEDMM: abuse top left/right pixels for peak detection debugging
81978219 SEGMENT.setPixelColorXY (cols-1 , 0 , (samplePeak > 0 ) ? GREEN : BLACK);
81988220 if (samplePeak > 0 ) SEGMENT.setPixelColorXY (0 , 0 , GREEN);
81998221 // WLEDMM end
8222+ }
82008223#endif
82018224 return FRAMETIME;
82028225} // mode_2DGEQ()
8203- static const char _data_FX_MODE_2DGEQ[] PROGMEM = " GEQ ☾@Fade speed,Ripple decay,# of bands,,,Color bars,Smooth bars ☾;!,,Peaks;!;2f ;c1=255,c2=64,pal=11,si=0" ; // Beatsin
8226+ static const char _data_FX_MODE_2DGEQ[] PROGMEM = " GEQ ☾@Fade speed,Ripple decay,# of bands,,,Color bars,Smooth bars ☾;!,,Peaks;!;12f ;c1=255,c2=64,pal=11,si=0" ; // Beatsin
82048227
82058228
82068229// ///////////////////////
0 commit comments