[breaking change] Sample signals from query onset, rather than midpoint (#1278)

This changes almost everything involving signals, including all use of random numbers.
This commit is contained in:
Alex McLean 2025-02-05 15:10:53 +00:00 committed by GitHub
parent 018d1ccd31
commit 49e9b84962
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6446 additions and 6462 deletions

View File

@ -16,7 +16,7 @@ export function steady(value) {
} }
export const signal = (func) => { export const signal = (func) => {
const query = (state) => [new Hap(undefined, state.span, func(state.span.midpoint()))]; const query = (state) => [new Hap(undefined, state.span, func(state.span.begin))];
return new Pattern(query); return new Pattern(query);
}; };
@ -158,7 +158,7 @@ const timeToRands = (t, n) => timeToRandsPrime(timeToIntSeed(t), n);
* n(run(4)).scale("C4:pentatonic") * n(run(4)).scale("C4:pentatonic")
* // n("0 1 2 3").scale("C4:pentatonic") * // n("0 1 2 3").scale("C4:pentatonic")
*/ */
export const run = (n) => saw.range(0, n).floor().segment(n); export const run = (n) => saw.range(0, n).round().segment(n);
/** /**
* Creates a pattern from a binary number. * Creates a pattern from a binary number.

View File

@ -736,21 +736,15 @@ describe('Pattern', () => {
describe('signal()', () => { describe('signal()', () => {
it('Can make saw/saw2', () => { it('Can make saw/saw2', () => {
expect(saw.struct(true, true, true, true).firstCycle()).toStrictEqual( expect(saw.struct(true, true, true, true).firstCycle()).toStrictEqual(
sequence(1 / 8, 3 / 8, 5 / 8, 7 / 8).firstCycle(), sequence(0, 1 / 4, 1 / 2, 3 / 4).firstCycle(),
); );
expect(saw2.struct(true, true, true, true).firstCycle()).toStrictEqual( expect(saw2.struct(true, true, true, true).firstCycle()).toStrictEqual(sequence(-1, -0.5, 0, 0.5).firstCycle());
sequence(-3 / 4, -1 / 4, 1 / 4, 3 / 4).firstCycle(),
);
}); });
it('Can make isaw/isaw2', () => { it('Can make isaw/isaw2', () => {
expect(isaw.struct(true, true, true, true).firstCycle()).toStrictEqual( expect(isaw.struct(true, true, true, true).firstCycle()).toStrictEqual(sequence(1, 0.75, 0.5, 0.25).firstCycle());
sequence(7 / 8, 5 / 8, 3 / 8, 1 / 8).firstCycle(),
);
expect(isaw2.struct(true, true, true, true).firstCycle()).toStrictEqual( expect(isaw2.struct(true, true, true, true).firstCycle()).toStrictEqual(sequence(1, 0.5, 0, -0.5).firstCycle());
sequence(3 / 4, 1 / 4, -1 / 4, -3 / 4).firstCycle(),
);
}); });
}); });
describe('_setContext()', () => { describe('_setContext()', () => {
@ -888,7 +882,7 @@ describe('Pattern', () => {
.squeezeJoin() .squeezeJoin()
.queryArc(3, 4) .queryArc(3, 4)
.map((x) => x.value), .map((x) => x.value),
).toStrictEqual([Fraction(3.5)]); ).toStrictEqual([Fraction(3)]);
}); });
}); });
describe('ply', () => { describe('ply', () => {

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff