Merge branch 'refactor-ws2812fx' into mapping12soundsim

This commit is contained in:
ewowi 2022-07-11 11:05:49 +02:00
commit d5523615ef
6 changed files with 1924 additions and 1809 deletions

View File

@ -6012,8 +6012,9 @@ static const char *_data_FX_MODE_2DDRIFTROSE PROGMEM = "2D Drift Rose@Fade,Blur;
//Currently 3 types defined, to be finetuned and new types added
typedef enum UM_SoundSimulations {
UMS_BeatSin = 0,
UMS_10_3,
UMS_14_3
UMS_WeWillRockYou = 1,
UMS_10_3 = 2,
UMS_14_3 = 3
} um_soundSimulations_t;
static um_data_t* um_data = nullptr;
@ -6090,6 +6091,38 @@ um_data_t* simulateSound(uint8_t simulationId)
// fftResult[i] = (beatsin8(120, 0, 255) + (256/16 * i)) % 256;
sampleAvg = fftResult[8];
break;
case UMS_WeWillRockYou:
if (ms%2000 < 200) {
sampleAvg = random8(255);
for (int i = 0; i<5; i++)
fftResult[i] = random8(255);
}
else if (ms%2000 < 400) {
sampleAvg = 0;
for (int i = 0; i<16; i++)
fftResult[i] = 0;
}
else if (ms%2000 < 600) {
sampleAvg = random8(255);
for (int i = 5; i<11; i++)
fftResult[i] = random8(255);
}
else if (ms%2000 < 800) {
sampleAvg = 0;
for (int i = 0; i<16; i++)
fftResult[i] = 0;
}
else if (ms%2000 < 1000) {
sampleAvg = random8(255);
for (int i = 11; i<16; i++)
fftResult[i] = random8(255);
}
else {
sampleAvg = 0;
for (int i = 0; i<16; i++)
fftResult[i] = 0;
}
break;
case UMS_10_3:
for (int i = 0; i<16; i++)
fftResult[i] = inoise8(beatsin8(90 / (i+1), 0, 200)*15 + (ms>>10), ms>>3);
@ -6164,7 +6197,7 @@ uint16_t mode_ripplepeak(void) { // * Ripple peak. By Andrew Tuli
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t samplePeak = *(uint8_t*)um_data->u_data[5];
float FFT_MajorPeak = *(float*) um_data->u_data[6];
@ -6254,7 +6287,7 @@ uint16_t mode_2DSwirl(void) {
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*) um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6299,7 +6332,7 @@ uint16_t mode_2DWaverly(void) {
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*) um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6354,7 +6387,7 @@ uint16_t mode_gravcenter(void) { // Gravcenter. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6405,7 +6438,7 @@ uint16_t mode_gravcentric(void) { // Gravcentric. By Andrew
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6460,7 +6493,7 @@ uint16_t mode_gravimeter(void) { // Gravmeter. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6505,7 +6538,7 @@ uint16_t mode_gravimeter(void) { // Gravmeter. By Andrew Tuline.
Gravity* gravcen = reinterpret_cast<Gravity*>(SEGENV.data);
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6571,7 +6604,7 @@ uint16_t mode_juggles(void) { // Juggles. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAgc = *(float*)um_data->u_data[2];
@ -6594,7 +6627,7 @@ uint16_t mode_matripix(void) { // Matripix. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
int16_t sampleRaw = *(int16_t*)um_data->u_data[3];
@ -6626,7 +6659,7 @@ uint16_t mode_midnoise(void) { // Midnoise. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6668,7 +6701,7 @@ uint16_t mode_noisefire(void) { // Noisefire. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6697,7 +6730,7 @@ uint16_t mode_noisemeter(void) { // Noisemeter. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6736,7 +6769,7 @@ uint16_t mode_pixelwave(void) { // Pixelwave. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
int16_t sampleRaw = *(int16_t*)um_data->u_data[3];
@ -6776,7 +6809,7 @@ uint16_t mode_plasmoid(void) { // Plasmoid. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -6817,7 +6850,7 @@ uint16_t mode_puddlepeak(void) { // Puddlepeak. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAgc = *(float*)um_data->u_data[2];
uint8_t samplePeak = *(uint8_t*)um_data->u_data[5];
@ -6861,7 +6894,7 @@ uint16_t mode_puddles(void) { // Puddles. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
int16_t sampleRaw = *(int16_t*)um_data->u_data[3];
@ -6895,7 +6928,7 @@ uint16_t mode_pixels(void) { // Pixels. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAgc = *(float*)um_data->u_data[2];
uint16_t *myVals = (uint16_t*)um_data->u_data[14];
@ -6929,7 +6962,7 @@ uint16_t mode_binmap(void) {
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
#ifdef SR_DEBUG
uint8_t *maxVol = (uint8_t*)um_data->u_data[9];
@ -7004,7 +7037,7 @@ uint16_t mode_blurz(void) { // Blurz. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[8];
if (!fftResult) return mode_static();
@ -7041,7 +7074,7 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[8];
if (!fftResult) return mode_static();
@ -7074,7 +7107,7 @@ uint16_t mode_freqmap(void) { // Map FFT_MajorPeak to SEGLEN.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -7108,7 +7141,7 @@ uint16_t mode_freqmatrix(void) { // Freqmatrix. By Andreas Plesch
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAgc = *(float*)um_data->u_data[2];
float FFT_MajorPeak = *(float*)um_data->u_data[6];
@ -7161,7 +7194,7 @@ static const char *_data_FX_MODE_FREQMATRIX PROGMEM = " ♫ Freqmatrix@Time dela
uint16_t mode_freqpixels(void) { // Freqpixel. By Andrew Tuline.
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -7206,7 +7239,7 @@ uint16_t mode_freqwave(void) { // Freqwave. By Andreas Pleschun
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -7270,7 +7303,7 @@ uint16_t mode_gravfreq(void) { // Gravfreq. By Andrew Tuline.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -7318,7 +7351,7 @@ uint16_t mode_noisemove(void) { // Noisemove. By: Andrew Tuli
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[8];
if (!fftResult) return mode_static();
@ -7344,7 +7377,7 @@ uint16_t mode_rocktaves(void) { // Rocktaves. Same note from eac
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -7391,7 +7424,7 @@ uint16_t mode_waterfall(void) { // Waterfall. By: Andrew Tulin
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
float sampleAvg = *(float*)um_data->u_data[0];
uint8_t soundAgc = *(uint8_t*)um_data->u_data[1];
@ -7451,7 +7484,7 @@ uint16_t mode_2DGEQ(void) { // By Will Tatam. Code reduction by Ewoud Wijma.
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[8];
if (!fftResult) return mode_static();
@ -7515,7 +7548,7 @@ uint16_t mode_2DFunkyPlank(void) { // Written by ??? Adapted by Wil
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
// add support for no audio data
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[8];
if (!fftResult) return mode_static();
@ -7610,7 +7643,7 @@ uint16_t mode_2DAkemi(void) {
um_data_t *um_data;
if (!usermods.getUMData(&um_data, USERMOD_ID_AUDIOREACTIVE)) {
um_data = simulateSound(UMS_BeatSin);
um_data = simulateSound(SEGMENT.soundSim);
}
uint8_t *fftResult = (uint8_t*)um_data->u_data[8];
float base = fftResult[0]/255.0f;

View File

@ -90,7 +90,7 @@ uint32_t color_add(uint32_t,uint32_t);
#define SEGMENT strip._segments[strip.getCurrSegmentId()]
#define SEGENV strip._segment_runtimes[strip.getCurrSegmentId()]
#define SEGCOLOR(x) strip.segColor(x)
#define SEGLEN strip._virtualSegmentLength
#define SEGLEN strip.getMappingLength()
#define SPEED_FORMULA_L (5U + (50U*(255U - SEGMENT.speed))/SEGLEN)
// some common colors
@ -399,6 +399,8 @@ typedef struct Segment { // 40 (44 in memory) bytes
uint8_t custom1, custom2, custom3; // custom FX parameters
uint16_t startY; // start Y coodrinate 2D (top)
uint16_t stopY; // stop Y coordinate 2D (bottom)
uint8_t soundSim;
uint8_t mapping12;
char *name;
color_transition transition;
@ -499,6 +501,13 @@ typedef struct Segment_runtime { // 23 (24 in memory) bytes
typedef enum mapping1D2D {
M12_Pixels = 0,
M12_VerticalBar = 1,
M12_CenterCircle = 2,
M12_CenterBlock = 3
} mapping1D2D_t;
// main "strip" class
class WS2812FX { // 96 bytes
typedef uint16_t (*mode_ptr)(void); // pointer to mode function
@ -664,6 +673,9 @@ class WS2812FX { // 96 bytes
inline void setPixelColorXY(int x, int y, byte r, byte g, byte b, byte w = 0) { setPixelColorXY(x, y, RGBW32(r,g,b,w)); } // automatically inline
inline void setPixelColorXY(int x, int y, CRGB c) { setPixelColorXY(x, y, c.red, c.green, c.blue); }
uint16_t
getMappingLength();
uint32_t
getPixelColorXY(uint16_t, uint16_t);

View File

@ -238,6 +238,24 @@ void Segment::setPixelColorXY(float x, float y, uint32_t col, bool aa)
#endif
}
uint16_t IRAM_ATTR WS2812FX::getMappingLength() {
switch (SEGMENT.mapping12) {
case M12_Pixels:
return SEGMENT.virtualWidth() * SEGMENT.virtualHeight();
break;
case M12_VerticalBar:
return SEGMENT.virtualWidth();
break;
case M12_CenterCircle:
return (SEGMENT.virtualWidth() + SEGMENT.virtualHeight()) / 4; // take half of the average width
break;
case M12_CenterBlock:
return (SEGMENT.virtualWidth() + SEGMENT.virtualHeight()) / 4; // take half of the average width
break;
}
return SEGMENT.virtualWidth() * SEGMENT.virtualHeight();
}
// returns RGBW values of pixel
uint32_t Segment::getPixelColorXY(uint16_t x, uint16_t y) {
#ifndef WLED_DISABLE_2D

View File

@ -746,6 +746,24 @@ function populateSegments(s)
<input type="checkbox" id="seg${i}${isM?'tp':'mi'}" onchange="${(isM?'setTp(':'setMi(')+i})" ${isM?(inst.tp?"checked":""):(inst.mi?"checked":"")}>
<span class="checkmark schk"></span>
</label>
<label class="check revchkl">
1D2D Mapping
<select id="seg${i}mp12" onchange="setMp12(${i})">
<option value="0" ${inst.mp12==0?' selected':''}>Pixel</option>
<option value="1" ${inst.mp12==1?' selected':''}>Vertical Bar</option>
<option value="2" ${inst.mp12==2?' selected':''}>Centre Circle</option>
<option value="3" ${inst.mp12==3?' selected':''}>Center block</option>
</select><br>
</label>
<label class="check revchkl">
Sound simulation
<select id="seg${i}ssim" onchange="setSSim(${i})">
<option value="0" ${inst.ssim==0?' selected':''}>BeatSin</option>
<option value="1" ${inst.ssim==1?' selected':''}>WeWillRockYou</option>
<option value="2" ${inst.ssim==2?' selected':''}>U10_3</option>
<option value="3" ${inst.ssim==3?' selected':''}>U14_3</option>
</select><br>
</label>
<div class="del">
<button class="btn btn-xs" id="segr${i}" title="Repeat until end" onclick="rptSeg(${i})"><i class="icons btn-icon">&#xe22d;</i></button>
<button class="btn btn-xs" id="segd${i}" title="Delete" onclick="delSeg(${i})"><i class="icons btn-icon">&#xe037;</i></button>
@ -1952,6 +1970,20 @@ function setMiY(s)
requestJson(obj);
}
function setMp12(s)
{
var value = gId(`seg${s}mp12`).selectedIndex;
var obj = {"seg": {"id": s, "mp12": value}};
requestJson(obj);
}
function setSSim(s)
{
var value = gId(`seg${s}ssim`).selectedIndex;
var obj = {"seg": {"id": s, "ssim": value}};
requestJson(obj);
}
function setTp(s)
{
var tp = gId(`seg${s}tp`).checked;

File diff suppressed because it is too large Load Diff

View File

@ -172,6 +172,9 @@ void deserializeSegment(JsonObject elem, byte it, byte presetId)
getVal(elem[F("c1")], &seg.custom1);
getVal(elem[F("c2")], &seg.custom2);
getVal(elem[F("c3")], &seg.custom3);
getVal(elem[F("ssim")], &seg.soundSim);
getVal(elem[F("mp12")], &seg.mapping12);
JsonArray iarr = elem[F("i")]; //set individual LEDs
if (!iarr.isNull()) {
@ -454,6 +457,8 @@ void serializeSegment(JsonObject& root, Segment& seg, byte id, bool forPreset, b
root[F("mY")] = seg.getOption(SEG_OPTION_MIRROR_Y);
root[F("tp")] = seg.getOption(SEG_OPTION_TRANSPOSED);
}
root[F("ssim")] = seg.soundSim;
root[F("mp12")] = seg.mapping12;
}
void serializeState(JsonObject root, bool forPreset, bool includeBri, bool segmentBounds)