Skip to content

Commit 837476d

Browse files
authored
Merge pull request #738 from PlummersSoftwareLLC/pdpwopr
Add PDPWOPR project. PDPCMX effect. New Audio engine.
2 parents b6e522b + e462b21 commit 837476d

33 files changed

+2085
-2009
lines changed

include/effects.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
#define EFFECT_MATRIX_SILON 160
150150
#define EFFECT_MATRIX_PDPGRID 161
151151
#define EFFECT_MATRIX_AUDIOSPIKE 162
152-
152+
#define EFFECT_MATRIX_PDPCMX 163
153153
// Hexagon Effects
154154
#define EFFECT_HEXAGON_OUTER_RING 201
155155

include/effects/matrix/PatternAnimatedGIF.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class PatternAnimatedGIF : public LEDStripEffect
154154
static void screenClearCallback(void)
155155
{
156156
auto& g = *(g_ptrSystem->EffectManager().g());
157-
g.fillScreen(g.to16bit(g_gifDecoderState._bkColor));
157+
g.Clear(g_gifDecoderState._bkColor);
158158
}
159159

160160
// We decide when to update the screen, so this is a no-op

include/effects/matrix/PatternPulse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class PatternPulsar : public BeatEffectBase, public LEDStripEffect
185185

186186
const int maxNewStarsPerFrame = 8;
187187
for (int i = 0; i < maxNewStarsPerFrame; i++)
188-
if (random(4) < g_Analyzer._VURatio)
188+
if (random(4) < g_Analyzer.VURatio())
189189
g()->drawPixel(random(MATRIX_WIDTH), random(MATRIX_HEIGHT), RandomSaturatedColor());
190190

191191

include/effects/matrix/spectrumeffects.h

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ class InsulatorSpectrumEffect : public LEDStripEffect, public BeatEffectBase, pu
7777

7878
virtual void Draw() override
7979
{
80-
auto peaks = g_Analyzer.GetPeakData();
80+
// Use const reference to avoid copying PeakData
81+
const PeakData & peaks = g_Analyzer.Peaks();
8182

8283
for (int band = 0; band < min(NUM_BANDS, NUM_FANS); band++)
8384
{
8485
CRGB color = ColorFromPalette(_Palette, ::map(band, 0, min(NUM_BANDS, NUM_FANS), 0, 255) + beatsin8(1) );
8586
color = color.fadeToBlackBy(255 - 255 * peaks[band]);
86-
color = color.fadeToBlackBy((2.0 - g_Analyzer._VURatio) * 228);
87+
color = color.fadeToBlackBy((2.0 - g_Analyzer.VURatio()) * 228);
8788
DrawRingPixels(0, FAN_SIZE * peaks[band], color, NUM_FANS-1-band, 0);
8889
}
8990

@@ -104,7 +105,7 @@ class InsulatorSpectrumEffect : public LEDStripEffect, public BeatEffectBase, pu
104105

105106

106107
// REVIEW(davepl) This might look interesting if it didn't erase...
107-
bool bFlash = g_Analyzer._VURatio > 1.99 && span > 1.9 && elapsed > 0.25;
108+
bool bFlash = g_Analyzer.VURatio() > 1.99 && span > 1.9 && elapsed > 0.25;
108109

109110
_allParticles.push_back(SpinningPaletteRingParticle(iInsulator, 0, _Palette, 256.0/FAN_SIZE, 4, -0.5, RING_SIZE_0, 0, LINEARBLEND, true, 1.0, bFlash ? max(0.12f, elapsed/8) : 0));
110111
}
@@ -116,7 +117,7 @@ class VUMeter
116117

117118
// DrawVUPixels
118119
//
119-
// Draw i-th pixel in row y
120+
// Draw i-th pixel in row yVU
120121

121122
virtual void DrawVUPixels(std::vector<std::shared_ptr<GFXBase>> & GFX, int i, int yVU, int fadeBy = 0, const CRGBPalette16 * pPalette = nullptr)
122123
{
@@ -153,7 +154,7 @@ class VUMeter
153154
const int MAX_FADE = 256;
154155

155156
int xHalf = GFX[0]->width()/2-1;
156-
int bars = g_Analyzer._VURatioFade / 2.0 * xHalf;
157+
int bars = g_Analyzer.VURatioFade() / 2.0 * xHalf;
157158
bars = min(bars, xHalf);
158159

159160
EraseVUMeter(GFX, bars, yVU);
@@ -163,14 +164,14 @@ class VUMeter
163164
msPeakVU = millis();
164165
iPeakVUy = bars;
165166
}
166-
else if (millis() - msPeakVU > MS_PER_SECOND / 2)
167+
else if (millis() - msPeakVU > MILLIS_PER_SECOND / 2)
167168
{
168169
iPeakVUy = 0;
169170
}
170171

171172
if (iPeakVUy > 1)
172173
{
173-
int fade = MAX_FADE * (millis() - msPeakVU) / (float) MS_PER_SECOND * 2;
174+
int fade = MAX_FADE * (millis() - msPeakVU) / (float) MILLIS_PER_SECOND * 2;
174175
DrawVUPixels(GFX, iPeakVUy, yVU, fade);
175176
DrawVUPixels(GFX, iPeakVUy-1, yVU, fade);
176177
}
@@ -206,7 +207,7 @@ class VUMeterVertical : public VUMeter
206207
const int MAX_FADE = 256;
207208

208209
int size = GFX[0]->width();
209-
int bars = g_Analyzer._VURatioFade / 2.0 * size;
210+
int bars = g_Analyzer.VURatioFade() / 2.0 * size;
210211
bars = min(bars, size);
211212

212213
EraseVUMeter(GFX, bars, yVU);
@@ -216,14 +217,14 @@ class VUMeterVertical : public VUMeter
216217
msPeakVU = millis();
217218
iPeakVUy = bars;
218219
}
219-
else if (millis() - msPeakVU > MS_PER_SECOND / 2)
220+
else if (millis() - msPeakVU > MILLIS_PER_SECOND / 2)
220221
{
221222
iPeakVUy = 0;
222223
}
223224

224225
if (iPeakVUy > 1)
225226
{
226-
int fade = MAX_FADE * (millis() - msPeakVU) / (float) MS_PER_SECOND * 2;
227+
int fade = MAX_FADE * (millis() - msPeakVU) / (float) MILLIS_PER_SECOND * 2;
227228
DrawVUPixels(GFX, iPeakVUy, yVU, fade);
228229
DrawVUPixels(GFX, iPeakVUy-1, yVU, fade);
229230
}
@@ -333,18 +334,18 @@ class SpectrumAnalyzerEffect : public LEDStripEffect, virtual public VUMeter
333334
// bar 16, for example, it will take all of bar 4 and none of bar 5. For bar 17, it will take 3/4 of bar 4 and 1/4 of bar 5.
334335

335336
int ib = iBar % barsPerBand;
336-
value = (g_Analyzer._peak1Decay[iBand] * (barsPerBand - ib) + g_Analyzer._peak1Decay[iNextBand] * (ib) ) / barsPerBand * (pGFXChannel->height() - 1);
337-
value2 = (g_Analyzer._peak2Decay[iBand] * (barsPerBand - ib) + g_Analyzer._peak2Decay[iNextBand] * (ib) ) / barsPerBand * pGFXChannel->height();
337+
value = (g_Analyzer.Peak2Decay(iBand) * (barsPerBand - ib) + g_Analyzer.Peak2Decay(iNextBand) * (ib) ) / barsPerBand * (pGFXChannel->height() - 1);
338+
value2 = (g_Analyzer.Peak2Decay(iBand) * (barsPerBand - ib) + g_Analyzer.Peak2Decay(iNextBand) * (ib) ) / barsPerBand * pGFXChannel->height();
338339
}
339340
else
340341
{
341342
// One to one case, just use the actual band value we mapped to
342343

343-
value = g_Analyzer._peak1Decay[iBand] * (pGFXChannel->height() - 1);
344-
value2 = g_Analyzer._peak2Decay[iBand] * pGFXChannel->height();
344+
value = g_Analyzer.Peak2Decay(iBand) * (pGFXChannel->height() - 1);
345+
value2 = g_Analyzer.Peak2Decay(iBand) * pGFXChannel->height();
345346
}
346347

347-
debugV("Band: %d, Value: %f\n", iBar, g_Analyzer._peak1Decay[iBar] );
348+
debugV("Band: %d, Value: %f\n", iBar, g_Analyzer.Peak2Decay(iBar) );
348349

349350
if (value > pGFXChannel->height())
350351
value = pGFXChannel->height();
@@ -389,11 +390,11 @@ class SpectrumAnalyzerEffect : public LEDStripEffect, virtual public VUMeter
389390
{
390391
const int PeakFadeTime_ms = 1000;
391392

392-
unsigned long msPeakAge = millis() - g_Analyzer._lastPeak1Time[iBand];
393+
unsigned long msPeakAge = millis() - g_Analyzer.LastPeak1Time(iBand);
393394
if (msPeakAge > PeakFadeTime_ms)
394395
msPeakAge = PeakFadeTime_ms;
395396

396-
float agePercent = (float) msPeakAge / (float) MS_PER_SECOND;
397+
float agePercent = (float) msPeakAge / (float) MILLIS_PER_SECOND;
397398
uint8_t fadeAmount = std::min(255.0f, agePercent * 256);
398399
colorHighlight.fadeToBlackBy(fadeAmount);
399400
pGFXChannel->drawLine(xOffset, max(0, yOffset-1), xOffset + barWidth - 1, max(0, yOffset-1), colorHighlight);
@@ -487,8 +488,8 @@ class SpectrumAnalyzerEffect : public LEDStripEffect, virtual public VUMeter
487488
{
488489
// The peaks and their decay rates are global, so we load up our values every time we display so they're current
489490

490-
g_Analyzer._peak1DecayRate = _peak1DecayRate;
491-
g_Analyzer._peak2DecayRate = _peak2DecayRate;
491+
// Load decay rates into analyzer
492+
g_Analyzer.SetPeakDecayRates(_peak1DecayRate, _peak2DecayRate);
492493
}
493494

494495
virtual void Draw() override
@@ -628,8 +629,8 @@ class WaveformEffect : public LEDStripEffect
628629
{
629630
int top = g_ptrSystem->EffectManager().IsVUVisible() ? 1 : 0;
630631
g()->MoveInwardX(top); // Start on Y=1 so we don't shift the VU meter
631-
DrawSpike(MATRIX_WIDTH-1, g_Analyzer._VURatio/2.0);
632-
DrawSpike(0, g_Analyzer._VURatio/2.0);
632+
DrawSpike(MATRIX_WIDTH-1, g_Analyzer.VURatio()/2.0);
633+
DrawSpike(0, g_Analyzer.VURatio()/2.0);
633634
}
634635
};
635636

@@ -704,7 +705,7 @@ class GhostWave : public WaveformEffect
704705

705706
// VURatio is too fast, VURatioFade looks too slow, but averaged between them is just right
706707

707-
float audioLevel = (g_Analyzer._VURatioFade + g_Analyzer._VURatio) / 2;
708+
float audioLevel = (g_Analyzer.VURatioFade() + g_Analyzer.VURatio()) / 2;
708709

709710
// Offsetting by 0.25, which is a very low ratio, helps keep the line thin when sound is low
710711
//audioLevel = (audioLevel - 0.25) / 1.75;
@@ -800,7 +801,7 @@ class SpectrumBarEffect : public LEDStripEffect, public BeatEffectBase
800801
{
801802
// Draw the spike
802803

803-
auto value = g_Analyzer.BeatEnhance(SPECTRUMBARBEAT_ENHANCE) * g_Analyzer._peak1Decay[iBand];
804+
auto value = g_Analyzer.BeatEnhance(SPECTRUMBARBEAT_ENHANCE) * g_Analyzer.Peak2Decay(iBand);
804805
auto top = std::max(0.0f, halfHeight - value * halfHeight);
805806
auto bottom = std::min(MATRIX_HEIGHT-1.0f, halfHeight + value * halfHeight + 1);
806807
auto x1 = halfWidth - ((iBand * 2 + offset) % halfWidth);
@@ -826,8 +827,7 @@ class SpectrumBarEffect : public LEDStripEffect, public BeatEffectBase
826827

827828
// Set the peak decay rates to something that looks good for this effect
828829

829-
g_Analyzer._peak1DecayRate = kPeakDecaySpectrumBar;
830-
g_Analyzer._peak2DecayRate = kPeakDecaySpectrumBar;
830+
g_Analyzer.SetPeakDecayRates(kPeakDecaySpectrumBar, kPeakDecaySpectrumBar);
831831

832832
// This effect doesn't clear during drawing, so we need to clear to start the frame
833833

include/effects/strip/faneffects.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -397,24 +397,22 @@ class FanBeatEffect : public LEDStripEffect
397397

398398
void OnBeat()
399399
{
400-
int passes = g_Analyzer._VURatio;
400+
int passes = (int)g_Analyzer.VURatio();
401401
for (int iPass = 0; iPass < passes; iPass++)
402402
{
403403
int iFan = random(0, NUM_FANS);
404-
int passes = random(1, g_Analyzer._VURatio);
404+
int innerPasses = random(1, (int)g_Analyzer.VURatio());
405405
CRGB c = CHSV(random(0, 255), 255, 255);
406406

407-
for (int iPass = 0; iPass < passes; iPass++)
407+
for (int iInnerPass = 0; iInnerPass < innerPasses; iInnerPass++)
408408
{
409409
DrawFanPixels(0, FAN_SIZE, c, Sequential, iFan++);
410410
}
411411
}
412412

413413
CRGB c = CHSV(random(0, 255), 255, 255);
414414
for (int i = NUM_FANS * FAN_SIZE; i < NUM_LEDS; i++)
415-
{
416415
g()->setPixel(i, c);
417-
}
418416
}
419417

420418
void DrawEffect()
@@ -424,21 +422,21 @@ class FanBeatEffect : public LEDStripEffect
424422

425423
if (latch)
426424
{
427-
if (g_Analyzer._VURatio < minVUSeen)
428-
minVUSeen = g_Analyzer._VURatio;
425+
if (g_Analyzer.VURatio() < minVUSeen)
426+
minVUSeen = g_Analyzer.VURatio();
429427
}
430428

431-
if (g_Analyzer._VURatio < 0.25f) // Crossing center going up
429+
if (g_Analyzer.VURatio() < 0.25f) // Crossing center going up
432430
{
433431
latch = true;
434-
minVUSeen = g_Analyzer._VURatio;
432+
minVUSeen = g_Analyzer.VURatio();
435433
}
436434

437435
if (latch)
438436
{
439-
if (g_Analyzer._VURatio > 1.5f)
437+
if (g_Analyzer.VURatio() > 1.5f)
440438
{
441-
if (random_range(1.0f, 3.0f) < g_Analyzer._VURatio)
439+
if (random_range(1.0f, 3.0f) < g_Analyzer.VURatio())
442440
{
443441
latch = false;
444442
OnBeat();
@@ -589,7 +587,7 @@ class PaletteReelEffect : public LEDStripEffect
589587
{
590588
for (int i = 0; i < NUM_FANS; i++)
591589
{
592-
if (random(0, 100) < 50 * g_Analyzer._VURatio) // 40% Chance of attempting to do something
590+
if (random(0, 100) < 50 * g_Analyzer.VURatio()) // 40% Chance of attempting to do something
593591
{
594592
int action = random(0, 3); // Generate a random outcome
595593
if (action == 0 || action == 3)
@@ -598,7 +596,7 @@ class PaletteReelEffect : public LEDStripEffect
598596
}
599597
else if (action == 1)
600598
{
601-
if (g_Analyzer._VURatio > 0.5f)
599+
if (g_Analyzer.VURatio() > 0.5f)
602600
{
603601
if (ReelDir[i] == 0)
604602
{
@@ -613,7 +611,7 @@ class PaletteReelEffect : public LEDStripEffect
613611
}
614612
else if (action == 2)
615613
{
616-
if (g_Analyzer._VURatio > 0.5f)
614+
if (g_Analyzer.VURatio() > 0.5f)
617615
{
618616
if (ReelDir[i] == 0) // 2 -> Spin Forwards, or accel if already doing so
619617
{
@@ -634,7 +632,7 @@ class PaletteReelEffect : public LEDStripEffect
634632
{
635633
for (int i = 0; i < NUM_FANS; i++)
636634
{
637-
ReelPos[i] = (ReelPos[i] + ReelDir[i] * (2 + g_Analyzer._VURatio));
635+
ReelPos[i] = (ReelPos[i] + ReelDir[i] * (2 + g_Analyzer.VURatio()));
638636
if (ReelPos[i] < 0)
639637
ReelPos[i] += FAN_SIZE;
640638
if (ReelPos[i] >= FAN_SIZE)

include/effects/strip/fireeffect.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "musiceffect.h"
3636
#include "soundanalyzer.h"
3737
#include "systemcontainer.h"
38+
#include <numeric>
3839

3940
class FireEffect : public LEDStripEffect
4041
{
@@ -181,9 +182,9 @@ class FireEffect : public LEDStripEffect
181182

182183
for (int i = 0; i < LEDCount; i++)
183184
{
184-
auto sum = 0;
185-
for (int j = 0; j < CellsPerLED; j++)
186-
sum += heat[i*CellsPerLED + j];
185+
auto begin = &heat[i * CellsPerLED];
186+
auto end = begin + CellsPerLED;
187+
int sum = std::accumulate(begin, end, 0);
187188
auto avg = sum / CellsPerLED;
188189

189190
#if LANTERN
@@ -317,7 +318,7 @@ class MusicalPaletteFire : public PaletteFlameEffect, protected BeatEffectBase
317318
}
318319
else
319320
{
320-
GenerateSparks(g_Analyzer._VURatio * 50);
321+
GenerateSparks(g_Analyzer.VURatio() * 50);
321322
}
322323
}
323324

@@ -570,7 +571,7 @@ class SmoothFireEffect : public LEDStripEffect
570571
{
571572
for (int k = _cLEDs - 1; k >= 3; k--)
572573
{
573-
float amount = 0.2f + g_Analyzer._VURatio; // MIN(0.85f, _Drift * deltaTime);
574+
float amount = 0.2f + g_Analyzer.VURatio(); // MIN(0.85f, _Drift * deltaTime);
574575
float c0 = 1.0f - amount;
575576
float c1 = amount * 0.33f;
576577
float c2 = c1;
@@ -760,9 +761,9 @@ class BaseFireEffect : public LEDStripEffect
760761
int cellsPerLED = CellCount / LEDCount;
761762
for (int i = 0; i < LEDCount; i++)
762763
{
763-
int sum = 0;
764-
for (int iCell = 0; iCell < cellsPerLED; iCell++)
765-
sum += heat[i * cellsPerLED + iCell];
764+
auto begin = &heat[i * cellsPerLED];
765+
auto end = begin + cellsPerLED;
766+
int sum = std::accumulate(begin, end, 0);
766767
int avg = sum / cellsPerLED;
767768
CRGB color = MapHeatToColor(heat[avg]);
768769
int j = bReversed ? (LEDCount - 1 - i) : i;

0 commit comments

Comments
 (0)