Skip to content

Commit

Permalink
fix(lights-effects): fix beat fade out pattern not consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoronex committed Feb 4, 2025
1 parent 760bdb6 commit 10dccc3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
60 changes: 31 additions & 29 deletions src/modules/lights/effects/color/beat-fade-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,44 +109,46 @@ export default class BeatFadeOut extends LightsEffect<BeatFadeOutProps> {
this.beatLength = event.beat.duration * 1000;
}

getCurrentColor(fixture: LightsGroupFixture, i: number) {
const { colors } = this.props;
const progression = this.getProgression(new Date(), fixture);

const phase = progression * this.getEffectNrFixtures();
const index = Math.round(phase % this.nrSteps);

return colors[index];
}

applyColorToFixture(
p: LightsGroupPars | LightsGroupMovingHeadRgbs | LightsGroupMovingHeadWheels,
i: number,
) {
const { enableFade } = this.props;
const beatProgression = enableFade
? Math.max(1 - (new Date().getTime() - this.lastBeat) / this.beatLength, 0)
: 1;

const color = this.getCurrentColor(p, i);
if (color == null) {
p.fixture.resetColor();
} else {
p.fixture.setBrightness(beatProgression);
p.fixture.setColor(color);
}
}

tick(): LightsGroup {
super.tick();

const progressions: { id: number; value: string }[] = [];

[
...this.lightsGroup.pars,
...this.lightsGroup.movingHeadRgbs,
...this.lightsGroup.movingHeadWheels,
]
.sort((a, b) => a.positionX - b.positionX)
.forEach(this.applyColorToFixture.bind(this));
.forEach((p, i) => {
const { enableFade } = this.props;
const beatProgression = enableFade
? Math.max(1 - (new Date().getTime() - this.lastBeat) / this.beatLength, 0)
: 1;

const { colors } = this.props;
const progression = this.getProgression(new Date(), p);

const phase = Math.round(progression * this.getEffectNrFixtures());
const index = phase % this.nrSteps;

const color = colors[index];
if (color == null) {
p.fixture.resetColor();
} else {
p.fixture.setBrightness(beatProgression);
p.fixture.setColor(color);
}

progressions.push({
id: i,
// value: `${progression.toFixed(3)} (${Math.round(phase).toString().padStart(2, '0')} -> ${index})`,
value: index.toString(),
});
});

const outputString = progressions.map((v) => `${v.id}: ${v.value}`).join(' | ');
// console.log(outputString);

return this.lightsGroup;
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/lights/effects/lights-effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default abstract class LightsEffect<P = {}> {
if (!this.progressionStrategy) return 0;

let progression = 1 - this.progressionStrategy.getProgression(currentTick);
if (this.patternDirection === LightsEffectDirection.FORWARDS) {
if (this.patternDirection === LightsEffectDirection.BACKWARDS) {
progression = 1 - progression;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import LightsGroupFixture from '../../../entities/lights-group-fixture';

export default class EffectProgressionMapCenteredSquaredStrategy extends EffectProgressionMapStrategy {
public getNrFixtures(): number {
return (this.lightsGroup.gridSizeX + this.lightsGroup.gridSizeY) / 2;
return Math.round((this.lightsGroup.gridSizeX + this.lightsGroup.gridSizeY) / 2) - 1;
}

public getProgression(progression: number, fixture: LightsGroupFixture): number {
Expand Down

0 comments on commit 10dccc3

Please sign in to comment.