Improve Beat Detection

This commit is contained in:
2021-11-12 16:37:04 +01:00
parent 25f5229afe
commit bf62ceb98f
4 changed files with 104 additions and 75 deletions

View File

@@ -3,30 +3,15 @@ import { Pattern, PatternOutput, Time } from './proto';
export class ChaserPattern implements Pattern {
lastBeat: number;
lastTime: number;
constructor() {
this.lastBeat = 0;
this.lastTime = 0;
}
render(time: Time): PatternOutput {
if (time.beatRelative === null) {
this.lastBeat = 0;
return null;
}
let t = time.beatRelative;
if (t < this.lastTime) {
this.lastBeat += 1;
}
this.lastTime = t;
let head_number = this.lastBeat % 4;
let head_number = Math.floor(t % 4);
let template: MovingHeadState = {
startAddress: 0,
@@ -44,7 +29,7 @@ export class ChaserPattern implements Pattern {
let result = [];
for (let [i, startAddress] of [1, 15, 29, 43].entries()) {
result[i] = { ...template};
result[i] = { ...template };
result[i].startAddress = startAddress;
if (i === head_number) {