From 58dc46b4452ee156c4dffe07d8889fd4541013d6 Mon Sep 17 00:00:00 2001 From: Bradford Powell Date: Sat, 13 Aug 2022 21:55:17 -0400 Subject: [PATCH] change "stride"/"offset" of successive degradeBy/chooseIn This avoids (without fixing) #184). Note that the offset in tidal is currently 0.0001, but using this would result in excess correlation between sequential uses of random, which would manifest in failure of the 'supports the randome choice operator with nesting' test. So I just used 0.0002 instead --- packages/mini/mini.mjs | 5 +++-- repl/src/test/__snapshots__/tunes.test.mjs.snap | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/mini/mini.mjs b/packages/mini/mini.mjs index c6b1d50e..416203e2 100644 --- a/packages/mini/mini.mjs +++ b/packages/mini/mini.mjs @@ -11,6 +11,7 @@ import { addMiniLocations } from '@strudel.cycles/eval/shapeshifter.mjs'; const { pure, Pattern, Fraction, stack, slowcat, sequence, timeCat, silence, reify } = strudel; var _seedState = 0; +const randOffset = 0.0002; function _nextSeed() { return _seedState++; @@ -28,7 +29,7 @@ const applyOptions = (parent) => (pat, i) => { case 'bjorklund': return pat.euclid(operator.arguments_.pulse, operator.arguments_.step, operator.arguments_.rotation); case 'degradeBy': - return reify(pat)._degradeByWith(strudel.rand.early(Math.PI * _nextSeed()).segment(1), operator.arguments_.amount); + return reify(pat)._degradeByWith(strudel.rand.early(randOffset * _nextSeed()).segment(1), operator.arguments_.amount); // TODO: case 'fixed-step': "%" } console.warn(`operator "${operator.type_}" not implemented`); @@ -91,7 +92,7 @@ export function patternifyAST(ast) { return stack(...children); } if (alignment === 'r') { - return strudel.chooseInWith(strudel.rand.early(Math.PI * _nextSeed()).segment(1), children); + return strudel.chooseInWith(strudel.rand.early(randOffset * _nextSeed()).segment(1), children); } const weightedChildren = ast.source_.some((child) => !!child.options_?.weight); if (!weightedChildren && alignment === 't') { diff --git a/repl/src/test/__snapshots__/tunes.test.mjs.snap b/repl/src/test/__snapshots__/tunes.test.mjs.snap index d833c751..47a2b223 100644 --- a/repl/src/test/__snapshots__/tunes.test.mjs.snap +++ b/repl/src/test/__snapshots__/tunes.test.mjs.snap @@ -318,10 +318,10 @@ exports[`renders tunes > tune: bossa 1`] = ` exports[`renders tunes > tune: bossaRandom 1`] = ` [ - "0/1 -> 1/2: {\\"note\\":\\"G4\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5601851851851851}", - "0/1 -> 1/2: {\\"note\\":\\"B4\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5787037037037037}", - "0/1 -> 1/2: {\\"note\\":\\"C5\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5833333333333333}", - "0/1 -> 1/2: {\\"note\\":\\"E5\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.6018518518518519}", + "0/1 -> 1/4: {\\"note\\":\\"G4\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5601851851851851}", + "0/1 -> 1/4: {\\"note\\":\\"B4\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5787037037037037}", + "0/1 -> 1/4: {\\"note\\":\\"C5\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5833333333333333}", + "0/1 -> 1/4: {\\"note\\":\\"E5\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.6018518518518519}", "3/4 -> 1/1: {\\"note\\":\\"G4\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5601851851851851}", "3/4 -> 1/1: {\\"note\\":\\"B4\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5787037037037037}", "3/4 -> 1/1: {\\"note\\":\\"C5\\",\\"clip\\":1,\\"s\\":\\"piano\\",\\"pan\\":0.5833333333333333}",