From 6e315a50edadb8a5b5dbe0a31c30bbdce5cc71fc Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Wed, 11 Jan 2023 23:28:17 +0100 Subject: [PATCH] breaking: arp use innerJoin instead of squeezeJoin --- packages/core/pattern.mjs | 18 ++++++-- test/__snapshots__/examples.test.mjs.snap | 51 +++++++++++++++++++++++ website/src/repl/tunes.mjs | 4 +- 3 files changed, 68 insertions(+), 5 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index ba33774d..e8205b63 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -735,6 +735,7 @@ export class Pattern { * Appends the given pattern(s) to the current pattern. Synonyms: .sequence .fastcat * @name seq * @memberof Pattern + * @synonyms sequence, fastcat * @example * s("hh*2").seq( * note("c2(3,8)") @@ -748,6 +749,7 @@ export class Pattern { * Appends the given pattern(s) to the next cycle. Synonym: .slowcat * @name cat * @memberof Pattern + * @synonyms slowcat * @example * s("hh*2").cat( * note("c2(3,8)") @@ -830,15 +832,25 @@ Pattern.prototype.collect = function () { ); }; -// applies func to each array of congruent haps +/** + * Selects indices in in stacked notes. + * @example + * note("<[c,eb,g]!2 [c,f,ab] [d,f,ab]>") + * .arp("0 [0,2] 1 [0,2]").slow(2) + * */ Pattern.prototype.arpWith = function (func) { return this.collect() .fmap((v) => reify(func(v))) - .squeezeJoin() + .innerJoin() .withHap((h) => new Hap(h.whole, h.part, h.value.value, h.combineContext(h.value))); }; -// applies pattern of indices to each array of congruent haps +/** + * Selects indices in in stacked notes. + * @example + * note("<[c,eb,g]!2 [c,f,ab] [d,f,ab]>") + * .arp("0 [0,2] 1 [0,2]").slow(2) + * */ Pattern.prototype.arp = function (pat) { return this.arpWith((haps) => pat.fmap((i) => haps[i % haps.length])); }; diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index e5a2ca32..67634362 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -822,6 +822,40 @@ exports[`runs examples > example "apply" example index 0 1`] = ` ] `; +exports[`runs examples > example "arp" example index 0 1`] = ` +[ + "[ 0/1 → 1/2 | note:c ]", + "[ 1/2 → 1/1 | note:c ]", + "[ 1/2 → 1/1 | note:g ]", + "[ 1/1 → 3/2 | note:eb ]", + "[ 3/2 → 2/1 | note:c ]", + "[ 3/2 → 2/1 | note:g ]", + "[ 2/1 → 5/2 | note:c ]", + "[ 5/2 → 3/1 | note:c ]", + "[ 5/2 → 3/1 | note:g ]", + "[ 3/1 → 7/2 | note:eb ]", + "[ 7/2 → 4/1 | note:c ]", + "[ 7/2 → 4/1 | note:g ]", +] +`; + +exports[`runs examples > example "arpWith" example index 0 1`] = ` +[ + "[ 0/1 → 1/2 | note:c ]", + "[ 1/2 → 1/1 | note:c ]", + "[ 1/2 → 1/1 | note:g ]", + "[ 1/1 → 3/2 | note:eb ]", + "[ 3/2 → 2/1 | note:c ]", + "[ 3/2 → 2/1 | note:g ]", + "[ 2/1 → 5/2 | note:c ]", + "[ 5/2 → 3/1 | note:c ]", + "[ 5/2 → 3/1 | note:g ]", + "[ 3/1 → 7/2 | note:eb ]", + "[ 7/2 → 4/1 | note:c ]", + "[ 7/2 → 4/1 | note:g ]", +] +`; + exports[`runs examples > example "attack" example index 0 1`] = ` [ "[ 0/1 → 1/2 | note:c3 attack:0 ]", @@ -3418,3 +3452,20 @@ exports[`runs examples > example "when" example index 0 1`] = ` "[ 11/3 → 4/1 | note:50 ]", ] `; + +exports[`runs examples > example "withValue" example index 0 1`] = ` +[ + "[ 0/1 → 1/3 | 10 ]", + "[ 1/3 → 2/3 | 11 ]", + "[ 2/3 → 1/1 | 12 ]", + "[ 1/1 → 4/3 | 10 ]", + "[ 4/3 → 5/3 | 11 ]", + "[ 5/3 → 2/1 | 12 ]", + "[ 2/1 → 7/3 | 10 ]", + "[ 7/3 → 8/3 | 11 ]", + "[ 8/3 → 3/1 | 12 ]", + "[ 3/1 → 10/3 | 10 ]", + "[ 10/3 → 11/3 | 11 ]", + "[ 11/3 → 4/1 | 12 ]", +] +`; diff --git a/website/src/repl/tunes.mjs b/website/src/repl/tunes.mjs index 9fffccab..3543cb05 100644 --- a/website/src/repl/tunes.mjs +++ b/website/src/repl/tunes.mjs @@ -857,7 +857,7 @@ export const arpoon = `// licensed with CC BY-NC-SA 4.0 https://creativecommons. await samples('github:tidalcycles/Dirt-Samples/master') "< C7 F^7 [Fm7 E7b9]>".voicings('lefthand') - .arp("[0,3] 2 [1,3] 2".fast(3)).legato(2) + .arp("[0,3] 2 [1,3] 2".fast(3).lastOf(4, fast(2))).legato(2) .add(perlin.range(0,0.2)).sub("<0 -12>/8") .note().cutoff(perlin.range(500,4000)).resonance(12) .gain("<.5 .8>*16") @@ -867,5 +867,5 @@ await samples('github:tidalcycles/Dirt-Samples/master') .s('piano').clip(1) .stack("<!2 F2 [F2 E2]>".add.out("0 -5".fast(2)).add("0,.12").note().s('sawtooth').clip(1).cutoff(300)) .slow(4) - .stack(s("bd*4, [~ [hh hh? hh?]]*2,~ [sd ~ [sd:2? bd?]]").arp("0|1").bank('RolandTR909').gain(.5).slow(2)) + .stack(s("bd*4, [~ [hh hh? hh?]]*2,~ [sd ~ [sd:2? bd?]]").bank('RolandTR909').gain(.5).slow(2)) `;