From e62d5759e74a544a1d9e56e89b630a08fb825829 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Mon, 10 Jun 2024 00:00:43 -0400 Subject: [PATCH 1/6] revert --- packages/superdough/worklets.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/superdough/worklets.mjs b/packages/superdough/worklets.mjs index b06513e79..62697ef9c 100644 --- a/packages/superdough/worklets.mjs +++ b/packages/superdough/worklets.mjs @@ -463,4 +463,4 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor { } } -registerProcessor('supersaw-oscillator', SuperSawOscillatorProcessor); +registerProcessor('supersaw-oscillator', SuperSawOscillatorProcessor); \ No newline at end of file From fdd167d62dbe8fce8d883b389acaa6c18d90f0b4 Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sat, 13 Jul 2024 13:20:05 -0400 Subject: [PATCH 2/6] working --- packages/core/controls.mjs | 2 +- packages/core/pattern.mjs | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/packages/core/controls.mjs b/packages/core/controls.mjs index 94f46f44a..d2198765d 100644 --- a/packages/core/controls.mjs +++ b/packages/core/controls.mjs @@ -1525,7 +1525,7 @@ export const { cps } = registerControl('cps'); * note("c a f e").s("piano").clip("<.5 1 2>") * */ -export const { clip, legato } = registerControl('clip', 'legato'); +export const { clip } = registerControl('clip'); /** * Sets the duration of the event in cycles. Similar to clip / legato, it also cuts samples off at the end if they exceed the duration. diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 5e2066220..454c6af1c 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1729,6 +1729,72 @@ export const { compressSpan, compressspan } = register(['compressSpan', 'compres return pat._compress(span.begin, span.end); }); +/** + * fills in the gap between consecutive notes + * + * @name legato + * @memberof Pattern + * @param {Pattern | number | array} legato relative note length + * @returns Pattern + * @example + * s("sawtooth").euclid(11,16).legato("<1 .5>")._pianoroll() + * @example + * // second array parameter is "lookahead" which is the number of cycles in the future to query for the next event + * s("supersaw").euclid(7,16).legato("1:<1 .15>")._pianoroll() + */ +export const legato = register('legato', function (legato, pat) { + let multiplier = legato; + let lookahead = 1; + if (Array.isArray(legato)) { + multiplier = legato[0] ?? 1; + lookahead = legato[1] ?? lookahead; + } + + let spanEnd; + return pat + .withQuerySpan((span) => { + spanEnd = span.end; + return span.withEnd((e) => { + return e.add(lookahead); + }); + }) + .withHaps((haps) => { + const newHaps = []; + haps + .sort((a, b) => { + return a.part.begin.sub(b.part.begin).valueOf(); + }) + .forEach((hap, i) => { + const nextHap = haps[i + 1]; + const partbegin = hap.part.begin; + let partend = hap.part.end; + const wholebegin = hap.whole.begin; + // filter out haps that were not part of the original span + if (wholebegin.gte(spanEnd)) { + return; + } + let wholeend = hap.whole.end; + if (nextHap != null) { + partend = nextHap.part.begin; + wholeend = nextHap.whole.begin; + } + + let wholeduration = wholeend.sub(wholebegin).mul(multiplier); + let partduration = partend.sub(partbegin).mul(multiplier); + + partend = partbegin.add(partduration); + wholeend = wholebegin.add(wholeduration); + + const newPart = new TimeSpan(partbegin, partend); + const newWhole = new TimeSpan(wholebegin, wholeend); + + newHaps.push(new Hap(newWhole, newPart, hap.value, hap.context)); + }); + return newHaps; + }); +}); + + /** * speeds up a pattern like fast, but rather than it playing multiple times as fast would it instead leaves a gap in the remaining space of the cycle. For example, the following will play the sound pattern "bd sn" only once but compressed into the first half of the cycle, i.e. twice as fast. * @name fastGap From 308eda677c1bfb984be028fff53ad37c57b9730e Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sat, 13 Jul 2024 13:21:43 -0400 Subject: [PATCH 3/6] add tests --- packages/core/pattern.mjs | 1 - test/__snapshots__/examples.test.mjs.snap | 82 +++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 454c6af1c..6a41e78fa 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1794,7 +1794,6 @@ export const legato = register('legato', function (legato, pat) { }); }); - /** * speeds up a pattern like fast, but rather than it playing multiple times as fast would it instead leaves a gap in the remaining space of the cycle. For example, the following will play the sound pattern "bd sn" only once but compressed into the first half of the cycle, i.e. twice as fast. * @name fastGap diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 3c1e39f8e..dab0cc861 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -3953,6 +3953,88 @@ exports[`runs examples > example "layer" example index 0 1`] = ` ] `; +exports[`runs examples > example "legato" example index 0 1`] = ` +[ + "[ 0/1 → 1/8 | s:sawtooth ]", + "[ 1/8 → 3/16 | s:sawtooth ]", + "[ 3/16 → 5/16 | s:sawtooth ]", + "[ 5/16 → 3/8 | s:sawtooth ]", + "[ 3/8 → 1/2 | s:sawtooth ]", + "[ 1/2 → 9/16 | s:sawtooth ]", + "[ 9/16 → 11/16 | s:sawtooth ]", + "[ 11/16 → 3/4 | s:sawtooth ]", + "[ 3/4 → 7/8 | s:sawtooth ]", + "[ 7/8 → 15/16 | s:sawtooth ]", + "[ 15/16 → 1/1 | s:sawtooth ]", + "[ 1/1 → 17/16 | s:sawtooth ]", + "[ 9/8 → 37/32 | s:sawtooth ]", + "[ 19/16 → 5/4 | s:sawtooth ]", + "[ 21/16 → 43/32 | s:sawtooth ]", + "[ 11/8 → 23/16 | s:sawtooth ]", + "[ 3/2 → 49/32 | s:sawtooth ]", + "[ 25/16 → 13/8 | s:sawtooth ]", + "[ 27/16 → 55/32 | s:sawtooth ]", + "[ 7/4 → 29/16 | s:sawtooth ]", + "[ 15/8 → 61/32 | s:sawtooth ]", + "[ 31/16 → 63/32 | s:sawtooth ]", + "[ 2/1 → 17/8 | s:sawtooth ]", + "[ 17/8 → 35/16 | s:sawtooth ]", + "[ 35/16 → 37/16 | s:sawtooth ]", + "[ 37/16 → 19/8 | s:sawtooth ]", + "[ 19/8 → 5/2 | s:sawtooth ]", + "[ 5/2 → 41/16 | s:sawtooth ]", + "[ 41/16 → 43/16 | s:sawtooth ]", + "[ 43/16 → 11/4 | s:sawtooth ]", + "[ 11/4 → 23/8 | s:sawtooth ]", + "[ 23/8 → 47/16 | s:sawtooth ]", + "[ 47/16 → 3/1 | s:sawtooth ]", + "[ 3/1 → 49/16 | s:sawtooth ]", + "[ 25/8 → 101/32 | s:sawtooth ]", + "[ 51/16 → 13/4 | s:sawtooth ]", + "[ 53/16 → 107/32 | s:sawtooth ]", + "[ 27/8 → 55/16 | s:sawtooth ]", + "[ 7/2 → 113/32 | s:sawtooth ]", + "[ 57/16 → 29/8 | s:sawtooth ]", + "[ 59/16 → 119/32 | s:sawtooth ]", + "[ 15/4 → 61/16 | s:sawtooth ]", + "[ 31/8 → 125/32 | s:sawtooth ]", + "[ 63/16 → 127/32 | s:sawtooth ]", +] +`; + +exports[`runs examples > example "legato" example index 1 1`] = ` +[ + "[ 0/1 → 3/16 | s:supersaw ]", + "[ 3/16 → 5/16 | s:supersaw ]", + "[ 5/16 → 7/16 | s:supersaw ]", + "[ 7/16 → 5/8 | s:supersaw ]", + "[ 5/8 → 3/4 | s:supersaw ]", + "[ 3/4 → 7/8 | s:supersaw ]", + "[ 7/8 → 1/1 | s:supersaw ]", + "[ 1/1 → 19/16 | s:supersaw ]", + "[ 19/16 → 21/16 | s:supersaw ]", + "[ 21/16 → 23/16 | s:supersaw ]", + "[ 23/16 → 13/8 | s:supersaw ]", + "[ 13/8 → 7/4 | s:supersaw ]", + "[ 7/4 → 15/8 | s:supersaw ]", + "[ 15/8 → 2/1 | s:supersaw ]", + "[ 2/1 → 35/16 | s:supersaw ]", + "[ 35/16 → 37/16 | s:supersaw ]", + "[ 37/16 → 39/16 | s:supersaw ]", + "[ 39/16 → 21/8 | s:supersaw ]", + "[ 21/8 → 11/4 | s:supersaw ]", + "[ 11/4 → 23/8 | s:supersaw ]", + "[ 23/8 → 3/1 | s:supersaw ]", + "[ 3/1 → 51/16 | s:supersaw ]", + "[ 51/16 → 53/16 | s:supersaw ]", + "[ 53/16 → 55/16 | s:supersaw ]", + "[ 55/16 → 29/8 | s:supersaw ]", + "[ 29/8 → 15/4 | s:supersaw ]", + "[ 15/4 → 31/8 | s:supersaw ]", + "[ 31/8 → 4/1 | s:supersaw ]", +] +`; + exports[`runs examples > example "leslie" example index 0 1`] = ` [ "[ 0/1 → 1/1 | n:0 s:supersquare leslie:0 ]", From 4e3898877777ad88e998c3a816b423a6c442489b Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Sat, 13 Jul 2024 23:31:56 -0400 Subject: [PATCH 4/6] formatting --- packages/superdough/worklets.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/superdough/worklets.mjs b/packages/superdough/worklets.mjs index 62697ef9c..b06513e79 100644 --- a/packages/superdough/worklets.mjs +++ b/packages/superdough/worklets.mjs @@ -463,4 +463,4 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor { } } -registerProcessor('supersaw-oscillator', SuperSawOscillatorProcessor); \ No newline at end of file +registerProcessor('supersaw-oscillator', SuperSawOscillatorProcessor); From 18d4fe0785124b38d6241505509d75d49117491f Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Thu, 8 Aug 2024 00:05:19 -0400 Subject: [PATCH 5/6] change legato to fill --- packages/core/pattern.mjs | 18 +++++++++++------- packages/core/timespan.mjs | 4 ++++ packages/draw/animate.mjs | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 6a41e78fa..0097d2321 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -1732,17 +1732,17 @@ export const { compressSpan, compressspan } = register(['compressSpan', 'compres /** * fills in the gap between consecutive notes * - * @name legato + * @name fill * @memberof Pattern - * @param {Pattern | number | array} legato relative note length + * @param {Pattern | number | array} fill relative note length * @returns Pattern * @example - * s("sawtooth").euclid(11,16).legato("<1 .5>")._pianoroll() + * s("sawtooth").euclid(11,16).fill("<1 .5>")._pianoroll() * @example * // second array parameter is "lookahead" which is the number of cycles in the future to query for the next event - * s("supersaw").euclid(7,16).legato("1:<1 .15>")._pianoroll() + * s("supersaw").euclid(7,16).fill("1:<1 .15>")._pianoroll() */ -export const legato = register('legato', function (legato, pat) { +export const fill = register('fill', function (legato, pat) { let multiplier = legato; let lookahead = 1; if (Array.isArray(legato)) { @@ -1751,12 +1751,16 @@ export const legato = register('legato', function (legato, pat) { } let spanEnd; + let spanBegin; return pat .withQuerySpan((span) => { spanEnd = span.end; + spanBegin = span.begin; + return span.withEnd((e) => { return e.add(lookahead); - }); + }) + // .withBegin(e => e.sub(lookahead)); }) .withHaps((haps) => { const newHaps = []; @@ -1770,7 +1774,7 @@ export const legato = register('legato', function (legato, pat) { let partend = hap.part.end; const wholebegin = hap.whole.begin; // filter out haps that were not part of the original span - if (wholebegin.gte(spanEnd)) { + if (wholebegin.gte(spanEnd) || wholebegin.lt(spanBegin)) { return; } let wholeend = hap.whole.end; diff --git a/packages/core/timespan.mjs b/packages/core/timespan.mjs index 4cbfb999a..07875a5a1 100644 --- a/packages/core/timespan.mjs +++ b/packages/core/timespan.mjs @@ -61,6 +61,10 @@ export class TimeSpan { // Applies given function to the end time of the timespan""" return new TimeSpan(this.begin, func_time(this.end)); } + withBegin(func_time) { + // Applies given function to the end time of the timespan""" + return new TimeSpan(func_time(this.begin), this.end); + } withCycle(func_time) { // Like withTime, but time is relative to relative to the cycle (i.e. the diff --git a/packages/draw/animate.mjs b/packages/draw/animate.mjs index d85081519..b31630a10 100644 --- a/packages/draw/animate.mjs +++ b/packages/draw/animate.mjs @@ -53,7 +53,7 @@ Pattern.prototype.animate = function ({ callback, sync = false, smear = 0.5 } = return silence; }; -export const { x, y, w, h, angle, r, fill, smear } = createParams('x', 'y', 'w', 'h', 'angle', 'r', 'fill', 'smear'); +export const { x, y, w, h, angle, r, fill, smear } = createParams('x', 'y', 'w', 'h', 'angle', 'r', 'smear'); export const rescale = register('rescale', function (f, pat) { return pat.mul(x(f).w(f).y(f).h(f)); From dd12b49f4db71b82cbf8e7cf72e1a0e593999a6a Mon Sep 17 00:00:00 2001 From: "Jade (Rose) Rowland" Date: Tue, 13 Aug 2024 15:00:16 -0400 Subject: [PATCH 6/6] withduration --- packages/core/timespan.mjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/core/timespan.mjs b/packages/core/timespan.mjs index 07875a5a1..81db8aac0 100644 --- a/packages/core/timespan.mjs +++ b/packages/core/timespan.mjs @@ -65,6 +65,10 @@ export class TimeSpan { // Applies given function to the end time of the timespan""" return new TimeSpan(func_time(this.begin), this.end); } + withDuration(func_time) { + const duration = this.end.sub(this.begin) + return new TimeSpan(this.begin, this.begin.add(func_time(duration))) + } withCycle(func_time) { // Like withTime, but time is relative to relative to the cycle (i.e. the