From 1c6e3dd9a69e4bbae2d33d97133bbcc2b1e7231b Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 17 Apr 2022 18:23:34 +0100 Subject: [PATCH 1/3] A couple of tests for continuous haps/patterns --- packages/core/test/pattern.test.mjs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index cff764eb..f2b255d2 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -36,6 +36,9 @@ import { id, ply, } from '../index.mjs'; + +import { steady } from '../signal.mjs'; + //import { Time } from 'tone'; import pkg from 'tone'; const { Time } = pkg; @@ -108,6 +111,18 @@ describe('Hap', function () { assert.deepStrictEqual(state3, { incrementme: 12 }); }); }); + describe('wholeOrPart()', () => { + const ts1 = new TimeSpan(Fraction(0), Fraction(1)); + const ts0_5 = new TimeSpan(Fraction(0), Fraction(0.5)); + const continuousHap = new Hap(undefined, ts1, 'hello'); + const discreteHap = new Hap(ts1, ts0_5, 'hello'); + it('Can pick a whole', () => { + assert.deepStrictEqual(discreteHap.wholeOrPart(), ts1); + }); + it('Can pick a part', () => { + assert.deepStrictEqual(continuousHap.wholeOrPart(), ts1); + }); + }); }); describe('Pattern', function () { @@ -399,7 +414,7 @@ describe('Pattern', function () { }); }); describe('struct()', function () { - it('Can restructure a pattern', function () { + it('Can restructure a discrete pattern', function () { assert.deepStrictEqual(sequence('a', 'b').struct(sequence(true, true, true)).firstCycle(), [ hap(ts(0, third), ts(0, third), 'a'), hap(ts(third, twothirds), ts(third, 0.5), 'a'), @@ -425,6 +440,9 @@ describe('Pattern', function () { sequence('a', ['a', silence], 'a').firstCycle(), ); }); + it('Can structure a continuous pattern', () => { + assert.deepStrictEqual(steady('a').struct(true, [true, true]).firstCycle(), sequence('a', ['a', 'a']).firstCycle()); + }); }); describe('mask()', function () { it('Can fragment a pattern', function () { From 28ebf6559ed24ea8a1e6fb7cad886d92b7b838c4 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 17 Apr 2022 18:25:38 +0100 Subject: [PATCH 2/3] Fix steady() --- packages/core/signal.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index a9f49d65..e96921c5 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -5,7 +5,7 @@ import { id } from './util.mjs'; export function steady(value) { // A continuous value - return new Pattern((span) => Hap(undefined, span, value)); + return new Pattern((state) => [new Hap(undefined, state.span, value)]); } export const signal = (func) => { From 30b74291695e94ec8e18ce42954d820e6c883986 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 17 Apr 2022 18:28:55 +0100 Subject: [PATCH 3/3] Fix appLeft/appRight to discard nonmatching events --- packages/core/pattern.mjs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 71f9755a..b8239c17 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -182,11 +182,13 @@ export class Pattern { const event_vals = pat_val.query(state.setSpan(hap_func.wholeOrPart())); for (const hap_val of event_vals) { const new_whole = hap_func.whole; - const new_part = hap_func.part.intersection_e(hap_val.part); - const new_value = hap_func.value(hap_val.value); - const new_context = hap_val.combineContext(hap_func); - const hap = new Hap(new_whole, new_part, new_value, new_context); - haps.push(hap); + const new_part = hap_func.part.intersection(hap_val.part); + if (new_part) { + const new_value = hap_func.value(hap_val.value); + const new_context = hap_val.combineContext(hap_func); + const hap = new Hap(new_whole, new_part, new_value, new_context); + haps.push(hap); + } } } return haps; @@ -203,11 +205,13 @@ export class Pattern { const hap_funcs = pat_func.query(state.setSpan(hap_val.wholeOrPart())); for (const hap_func of hap_funcs) { const new_whole = hap_val.whole; - const new_part = hap_func.part.intersection_e(hap_val.part); - const new_value = hap_func.value(hap_val.value); - const new_context = hap_val.combineContext(hap_func); - const hap = new Hap(new_whole, new_part, new_value, new_context); - haps.push(hap); + const new_part = hap_func.part.intersection(hap_val.part); + if (new_part) { + const new_value = hap_func.value(hap_val.value); + const new_context = hap_val.combineContext(hap_func); + const hap = new Hap(new_whole, new_part, new_value, new_context); + haps.push(hap); + } } } return haps;