Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lights-effects): fix beat fade out pattern not consistent #43

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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