Multiple additions:

- transparent leds[] for getPixelColor()
- sample 2D Black Hole for trnasparent leds[]
- conditional audio compile (WLED_NO_AUDIO)

Bugfix:
- effect filtering
This commit is contained in:
Blaz Kristan 2022-08-01 22:01:24 +02:00
parent 118bcbd6a6
commit 7ca1d99412
10 changed files with 906 additions and 842 deletions

View File

@ -403,7 +403,7 @@ uint16_t scan(bool dual)
uint16_t mode_scan(void) {
return scan(false);
}
static const char *_data_FX_MODE_SCAN PROGMEM = "Scan@!,# of dots;!,!,;!;1d";
static const char *_data_FX_MODE_SCAN PROGMEM = "Scan@!,# of dots;!,!,!;!;1d";
/*
@ -412,7 +412,7 @@ static const char *_data_FX_MODE_SCAN PROGMEM = "Scan@!,# of dots;!,!,;!;1d";
uint16_t mode_dual_scan(void) {
return scan(true);
}
static const char *_data_FX_MODE_DUAL_SCAN PROGMEM = "Scan Dual@!,# of dots;!,!,;!;1d";
static const char *_data_FX_MODE_DUAL_SCAN PROGMEM = "Scan Dual@!,# of dots;!,!,!;!;1d";
/*
@ -4565,41 +4565,48 @@ uint16_t mode_2DBlackHole(void) { // By: Stepko https://editor.soulma
const uint16_t cols = SEGMENT.virtualWidth();
const uint16_t rows = SEGMENT.virtualHeight();
const uint16_t dataSize = sizeof(CRGB) * SEGMENT.length(); // using width*height prevents reallocation if mirroring is enabled
//const uint16_t dataSize = sizeof(CRGB) * SEGMENT.length(); // using width*height prevents reallocation if mirroring is enabled
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
CRGB *leds = reinterpret_cast<CRGB*>(SEGENV.data);
//if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
//CRGB *leds = reinterpret_cast<CRGB*>(SEGENV.data);
uint16_t x, y;
// initialize on first call
if (SEGENV.call == 0) {
SEGMENT.fill_solid(leds, CRGB::Black);
SEGMENT.setUpLeds();
SEGMENT.fill(BLACK);
//SEGMENT.fill_solid(leds, CRGB::Black);
}
SEGMENT.fadeToBlackBy(leds, 16 + (SEGMENT.speed>>3)); // create fading trails
SEGMENT.fadeToBlackBy(16 + (SEGMENT.speed>>3)); // create fading trails
//SEGMENT.fadeToBlackBy(leds, 16 + (SEGMENT.speed>>3)); // create fading trails
float t = (float)(millis())/128; // timebase
// outer stars
for (size_t i = 0; i < 8; i++) {
x = beatsin8(SEGMENT.custom1>>3, 0, cols - 1, 0, ((i % 2) ? 128 : 0) + t * i);
y = beatsin8(SEGMENT.intensity>>3, 0, rows - 1, 0, ((i % 2) ? 192 : 64) + t * i);
leds[XY(x,y)] += CHSV(i*32, 255, 255);
SEGMENT.setPixelColorXY(x, y, CHSV(i*32, 255, 255));
//leds[XY(x,y)] += CHSV(i*32, 255, 255);
}
// inner stars
for (size_t i = 0; i < 4; i++) {
x = beatsin8(SEGMENT.custom2>>3, cols/4, cols - 1 - cols/4, 0, ((i % 2) ? 128 : 0) + t * i);
y = beatsin8(SEGMENT.custom3>>3, rows/4, rows - 1 - rows/4, 0, ((i % 2) ? 192 : 64) + t * i);
leds[XY(x,y)] += CHSV(i*32, 255, 255);
SEGMENT.setPixelColorXY(x, y, CHSV(i*32, 255, 255));
//leds[XY(x,y)] += CHSV(i*32, 255, 255);
}
// central white dot
leds[XY(cols/2,rows/2)] = CHSV(0,0,255);
SEGMENT.setPixelColorXY(cols/2, rows/2, CHSV(0, 0, 255));
//leds[XY()] = CHSV(0,0,255);
// blur everything a bit
SEGMENT.blur2d(leds, 16);
SEGMENT.blur(16);
//SEGMENT.blur2d(leds, 16);
SEGMENT.setPixels(leds);
//SEGMENT.setPixels(leds);
return FRAMETIME;
} // mode_2DBlackHole()
static const char *_data_FX_MODE_2DBLACKHOLE PROGMEM = "Black Hole@Fade rate,Outer Y freq.,Outer X freq.,Inner X freq.,Inner Y freq.;;2d";
static const char *_data_FX_MODE_2DBLACKHOLE PROGMEM = "Black Hole@Fade rate,Outer Y freq.,Outer X freq.,Inner X freq.,Inner Y freq.;;;2d";
////////////////////////////
@ -5957,6 +5964,7 @@ static const char *_data_FX_MODE_2DDRIFTROSE PROGMEM = "Drift Rose@Fade,Blur;;;2
#endif // WLED_DISABLE_2D
#ifndef WLED_NO_AUDIO
///////////////////////////////////////////////////////////////////////////////
/******************** audio enhanced routines ************************/
///////////////////////////////////////////////////////////////////////////////
@ -6019,7 +6027,9 @@ uint16_t mode_ripplepeak(void) { // * Ripple peak. By Andrew Tuli
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t samplePeak = *(uint8_t*)um_data->u_data[5];
#ifdef ESP32
float FFT_MajorPeak = *(float*) um_data->u_data[6];
#endif
uint8_t *maxVol = (uint8_t*)um_data->u_data[9];
uint8_t *binNum = (uint8_t*)um_data->u_data[10];
@ -7418,6 +7428,7 @@ uint16_t mode_2DAkemi(void) {
static const char *_data_FX_MODE_2DAKEMI PROGMEM = "Akemi@Color speed,Dance;Head palette,Arms & Legs,Eyes & Mouth;Face palette;ssim=0,2d,fr"; //beatsin
#endif // WLED_DISABLE_2D
#endif // WLED_NO_AUDIO
//////////////////////////////////////////////////////////////////////////////////////////
// mode data
@ -7583,12 +7594,16 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_2DMETABALLS, &mode_2Dmetaballs, _data_FX_MODE_2DMETABALLS);
addEffect(FX_MODE_2DPULSER, &mode_2DPulser, _data_FX_MODE_2DPULSER);
addEffect(FX_MODE_2DSUNRADIATION, &mode_2DSunradiation, _data_FX_MODE_2DSUNRADIATION);
#ifndef WLED_NO_AUDIO
addEffect(FX_MODE_2DWAVERLY, &mode_2DWaverly, _data_FX_MODE_2DWAVERLY);
#endif
addEffect(FX_MODE_2DDRIFT, &mode_2DDrift, _data_FX_MODE_2DDRIFT);
addEffect(FX_MODE_2DCOLOREDBURSTS, &mode_2DColoredBursts, _data_FX_MODE_2DCOLOREDBURSTS);
addEffect(FX_MODE_2DTARTAN, &mode_2Dtartan, _data_FX_MODE_2DTARTAN);
addEffect(FX_MODE_2DPOLARLIGHTS, &mode_2DPolarLights, _data_FX_MODE_2DPOLARLIGHTS);
#ifndef WLED_NO_AUDIO
addEffect(FX_MODE_2DSWIRL, &mode_2DSwirl, _data_FX_MODE_2DSWIRL);
#endif
addEffect(FX_MODE_2DLISSAJOUS, &mode_2DLissajous, _data_FX_MODE_2DLISSAJOUS);
addEffect(FX_MODE_2DFRIZZLES, &mode_2DFrizzles, _data_FX_MODE_2DFRIZZLES);
addEffect(FX_MODE_2DPLASMABALL, &mode_2DPlasmaball, _data_FX_MODE_2DPLASMABALL);
@ -7596,8 +7611,11 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_2DSINDOTS, &mode_2DSindots, _data_FX_MODE_2DSINDOTS);
addEffect(FX_MODE_2DDNASPIRAL, &mode_2DDNASpiral, _data_FX_MODE_2DDNASPIRAL);
addEffect(FX_MODE_2DBLACKHOLE, &mode_2DBlackHole, _data_FX_MODE_2DBLACKHOLE);
#ifndef WLED_NO_AUDIO
addEffect(FX_MODE_2DAKEMI, &mode_2DAkemi, _data_FX_MODE_2DAKEMI);
#endif
#endif
#ifndef WLED_NO_AUDIO
addEffect(FX_MODE_PIXELWAVE, &mode_pixelwave, _data_FX_MODE_PIXELWAVE);
addEffect(FX_MODE_JUGGLES, &mode_juggles, _data_FX_MODE_JUGGLES);
addEffect(FX_MODE_MATRIPIX, &mode_matripix, _data_FX_MODE_MATRIPIX);
@ -7611,10 +7629,14 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_MIDNOISE, &mode_midnoise, _data_FX_MODE_MIDNOISE);
addEffect(FX_MODE_NOISEMETER, &mode_noisemeter, _data_FX_MODE_NOISEMETER);
addEffect(FX_MODE_NOISEFIRE, &mode_noisefire, _data_FX_MODE_NOISEFIRE);
#endif
#else
// WLED-SR
#ifdef WLED_NO_AUDIO
#error Incompatible options: WLED_NO_AUDIO and USERMOD_AUDIOREACTIVE
#endif
#ifdef WLED_DISABLE_2D
#error AUDIOREACTIVE requires 2D support.
#error AUDIOREACTIVE requires 2D support.
#endif
addEffect(FX_MODE_2DJULIA, &mode_2DJulia, _data_FX_MODE_2DJULIA);
addEffect(FX_MODE_2DGAMEOFLIFE, &mode_2Dgameoflife, _data_FX_MODE_2DGAMEOFLIFE);
@ -7672,5 +7694,5 @@ void WS2812FX::setupEffectData() {
addEffect(FX_MODE_ROCKTAVES, &mode_rocktaves, _data_FX_MODE_ROCKTAVES);
addEffect(FX_MODE_2DAKEMI, &mode_2DAkemi, _data_FX_MODE_2DAKEMI);
//addEffect(FX_MODE_CUSTOMEFFECT, &mode_customEffect, _data_FX_MODE_CUSTOMEFFECT); //WLEDSR Custom Effects
#endif
#endif // USERMOD_AUDIOREACTIVE
}

View File

@ -410,6 +410,7 @@ typedef struct Segment {
uint16_t aux0; // custom var
uint16_t aux1; // custom var
byte* data;
CRGB* leds;
private:
union {
@ -468,6 +469,7 @@ typedef struct Segment {
aux0(0),
aux1(0),
data(nullptr),
leds(nullptr),
_capabilities(0),
_dataLen(0),
_t(nullptr)
@ -484,6 +486,7 @@ typedef struct Segment {
Segment(Segment &&orig) noexcept; // move constructor
~Segment() {
if (leds) { free(leds); Serial.println(F("Freeing leds.")); }
#ifdef WLED_DEBUG
Serial.print(F("Destroying segment."));
if (name) Serial.printf(" %s (%p)", name, name);
@ -530,6 +533,7 @@ typedef struct Segment {
* Safe to call from interrupts and network requests.
*/
inline void markForReset(void) { reset = true; } // setOption(SEG_OPTION_RESET, true)
inline void setUpLeds() { if (!leds) leds = (CRGB*)malloc(sizeof(CRGB)*length()); }
// transition functions
void startTransition(uint16_t dur); // transition has to start before actual segment values change

View File

@ -154,6 +154,8 @@ void IRAM_ATTR Segment::setPixelColorXY(int x, int y, uint32_t col)
#ifndef WLED_DISABLE_2D
if (!strip.isMatrix) return; // not a matrix set-up
if (leds) leds[XY(x,y)] = col;
uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0);
if (_bri_t < 255) {
byte r = scale8(R(col), _bri_t);
@ -245,6 +247,7 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
// returns RGBW values of pixel
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
#ifndef WLED_DISABLE_2D
if (leds) return RGBW32(leds[XY(x,y)].r, leds[XY(x,y)].g, leds[XY(x,y)].b, 0);
if (getOption(SEG_OPTION_REVERSED) ) x = virtualWidth() - x - 1;
if (getOption(SEG_OPTION_REVERSED_Y)) y = virtualHeight() - y - 1;
if (getOption(SEG_OPTION_TRANSPOSED)) { uint16_t t = x; x = y; y = t; } // swap X & Y if segment transposed

View File

@ -86,6 +86,7 @@ Segment::Segment(const Segment &orig) {
if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); }
if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); }
if (orig._t) { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); }
if (orig.leds) { leds = (CRGB*)malloc(sizeof(CRGB)*length()); }
DEBUG_PRINTF(" Original data: %p (%d)\n", orig.data, (int)orig._dataLen);
DEBUG_PRINTF(" Constructed data: %p (%d)\n", data, (int)_dataLen);
}
@ -98,6 +99,7 @@ Segment::Segment(Segment &&orig) noexcept {
orig.data = nullptr;
orig._dataLen = 0;
orig._t = nullptr;
orig.leds = nullptr;
}
// copy assignment
@ -109,15 +111,18 @@ Segment& Segment::operator= (const Segment &orig) {
delete[] name;
}
if (_t) delete _t;
if (leds) free(leds);
deallocateData();
memcpy(this, &orig, sizeof(Segment));
name = nullptr;
data = nullptr;
_dataLen = 0;
_t = nullptr;
leds = nullptr;
if (orig.name) { name = new char[strlen(orig.name)+1]; if (name) strcpy(name, orig.name); }
if (orig.data) { if (allocateData(orig._dataLen)) memcpy(data, orig.data, orig._dataLen); }
if (orig._t) { _t = new Transition(orig._t->_dur, orig._t->_briT, orig._t->_cctT, orig._t->_colorT); }
if (orig.leds) { leds = (CRGB*)malloc(sizeof(CRGB)*length()); if (leds) memcpy(leds, orig.leds, sizeof(CRGB)*length()); }
DEBUG_PRINTF(" Original data: %p (%d)\n", orig.data, (int)orig._dataLen);
DEBUG_PRINTF(" Copied data: %p (%d)\n", data, (int)_dataLen);
}
@ -134,11 +139,13 @@ Segment& Segment::operator= (Segment &&orig) noexcept {
}
deallocateData(); // free old runtime data
if (_t) delete _t;
if (leds) free(leds);
memcpy(this, &orig, sizeof(Segment));
orig.name = nullptr;
orig.data = nullptr;
orig._dataLen = 0;
orig._t = nullptr;
orig.leds = nullptr;
}
return *this;
}
@ -182,6 +189,7 @@ void Segment::deallocateData() {
*/
void Segment::resetIfRequired() {
if (reset) { // (getOption(SEG_OPTION_RESET))
if (leds) { free(leds); leds = nullptr; DEBUG_PRINTLN(F("Freeing leds.")); }
next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0;
reset = false; // setOption(SEG_OPTION_RESET, false);
}
@ -442,6 +450,8 @@ void IRAM_ATTR Segment::setPixelColor(int i, uint32_t col)
}
#endif
if (leds) leds[i] = col;
uint16_t len = length();
uint8_t _bri_t = currentBri(getOption(SEG_OPTION_ON) ? opacity : 0);
if (_bri_t < 255) {
@ -532,6 +542,8 @@ uint32_t Segment::getPixelColor(uint16_t i)
}
#endif
if (leds) return RGBW32(leds[i].r, leds[i].g, leds[i].b, 0);
if (getOption(SEG_OPTION_REVERSED)) i = virtualLength() - i - 1;
i *= groupLength();
i += start;

View File

@ -607,9 +607,13 @@ function parseInfo(i) {
isM = mw>0 && mh>0;
if (!isM) {
gId("filter1D").classList.add("hide");
gId("filter2D").classList.add("hide");
//gId("filter2D").classList.add("hide");
hideModes("2D");
}
if (i.noaudio) {
gId("filterVol").classList.add("hide");
gId("filterFreq").classList.add("hide");
}
// if (!i.u || !i.u.AudioReactive) {
//gId("filterVol").classList.add("hide"); hideModes(" ♪"); // hide volume reactive effects
//gId("filterFreq").classList.add("hide"); hideModes(" ♫"); // hide frequency reactive effects
@ -2475,7 +2479,11 @@ function getPalettesData(page, callback)
function hideModes(txt)
{
for (let e of (gId('fxlist').querySelectorAll('.lstI')||[])) {
if (e.querySelector('.lstIname').innerText.indexOf(txt) >= 0) e.classList.add("hide"); //else e.classList.remove("hide");
let iT = e.querySelector('.lstIname').innerText;
let f = false;
if (txt==="2D") f = iT.indexOf("\u25A6") >= 0 && iT.indexOf("\u22EE") < 0; // 2D && !1D
else f = iT.indexOf(txt) >= 0;
if (f) e.classList.add("hide"); //else e.classList.remove("hide");
}
}
@ -2488,7 +2496,7 @@ function search(f,l=null)
for (i = (l==='pcont'?0:1); i < el.length; i++) {
var it = el[i];
var itT = it.querySelector('.lstIname').innerText.toUpperCase();
it.style.display = (itT.indexOf(f.value.toUpperCase())<0 || (!isM && l==='fxlist' && itT.indexOf("2D")>=0)) ? 'none' : '';
it.style.display = (itT.indexOf(f.value.toUpperCase())<0) ? 'none' : '';
}
}

File diff suppressed because it is too large Load Diff

View File

@ -627,6 +627,10 @@ void serializeInfo(JsonObject root)
leds[F("wv")] = totalLC & 0x02; // deprecated, true if white slider should be displayed for any segment
leds["cct"] = totalLC & 0x04; // deprecated, use info.leds.lc
#ifdef WLED_NO_AUDIO
root[F("noaudio")] = true;
#endif
root[F("str")] = syncToggleReceive;
root[F("name")] = serverDescription;

View File

@ -133,6 +133,9 @@
#endif
#ifdef USERMOD_AUDIOREACTIVE
#ifdef WLED_NO_AUDIO
#error Incompatible options: WLED_NO_AUDIO and USERMOD_AUDIOREACTIVE
#endif
#include "../usermods/audioreactive/audio_reactive.h"
#endif
@ -257,6 +260,9 @@ void registerUsermods()
#endif
#ifdef USERMOD_AUDIOREACTIVE
#ifdef WLED_NO_AUDIO
#error Incompatible options: WLED_NO_AUDIO and USERMOD_AUDIOREACTIVE
#endif
usermods.add(new AudioReactive());
#endif
}

View File

@ -383,6 +383,7 @@ uint16_t crc16(const unsigned char* data_p, size_t length) {
}
#ifndef WLED_NO_AUDIO
///////////////////////////////////////////////////////////////////////////////
// Begin simulateSound (to enable audio enhanced effects to display something)
///////////////////////////////////////////////////////////////////////////////
@ -532,3 +533,4 @@ um_data_t* simulateSound(uint8_t simulationId)
return um_data;
}
#endif

View File

@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2207303
#define VERSION 2208011
//uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG