Improve Beat Detection
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user