Revert "state twiddles wip"

This reverts commit 55839e7ee8.
This commit is contained in:
alex
2025-10-30 21:28:58 +00:00
parent 55839e7ee8
commit 4a158db9d2
3 changed files with 8 additions and 21 deletions
+3 -15
View File
@@ -31,7 +31,6 @@ export class Cyclist {
this.seconds_at_cps_change; // clock phase when cps was changed
this.onToggle = onToggle;
this.latency = latency; // fixed trigger time offset
this.pattern_state = {};
this.clock = createClock(
getTime,
// called slightly before each cycle
@@ -58,20 +57,9 @@ export class Cyclist {
}
// query the pattern for events
let haps = this.pattern.sortHapsByPart().queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' });
// TODO - worth checking for stateful haps before needlessly sorting?
haps = haps.sort((a, b) =>
a.part.begin
.sub(b.part.begin)
.or(a.part.end.sub(b.part.end))
.or(a.whole.begin.sub(b.whole.begin).or(a.whole.end.sub(b.whole.end))),
);
const haps = this.pattern.queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' });
haps.forEach((hap) => {
if (hap.hasOnset() || hap.context.processParts) {
let value;
[this.pattern_state, value] = hap.resolveState(this.pattern_state);
const targetTime =
(hap.part.begin - this.num_cycles_at_cps_change) / this.cps + this.seconds_at_cps_change + latency;
const duration = hap.duration / this.cps;
@@ -80,8 +68,8 @@ export class Cyclist {
const deadline = targetTime - phase;
// this onTrigger has another signature
onTrigger?.(hap, deadline, duration, this.cps, targetTime);
if (value.cps !== undefined && this.cps != value.cps) {
this.cps = value.cps;
if (hap.value.cps !== undefined && this.cps != hap.value.cps) {
this.cps = hap.value.cps;
this.num_ticks_since_cps_change = 0;
}
}
+2 -3
View File
@@ -96,15 +96,14 @@ export class Hap {
return this.context.tags?.includes(tag);
}
// Returns the hap value with any state transformation applied
resolveState(state) {
if (this.stateful && this.hasOnset()) {
console.log('stateful');
const func = this.value;
const [newState, newValue] = func(state);
return [newState, newValue];
return [newState, new Hap(this.whole, this.part, newValue, this.context, false)];
}
return [state, this.value];
return [state, this];
}
spanEquals(other) {
+3 -3
View File
@@ -127,9 +127,9 @@ describe('Hap', () => {
};
const state = { incrementme: 10 };
const ev1 = new Hap(ts(0, 1), ts(0, 1), stateful_value, {}, true);
const [state2, _] = ev1.resolveState(state);
const [state3, v3] = ev1.resolveState(state2);
expect(v3).toStrictEqual(11);
const [state2, ev2] = ev1.resolveState(state);
const [state3, ev3] = ev1.resolveState(state2);
expect(ev3).toStrictEqual(new Hap(ts(0, 1), ts(0, 1), 11, {}, false));
expect(state3).toStrictEqual({ incrementme: 12 });
});
});