implement random choice in mini notation

this will require update to krill-parser.js (aggregated
in later commit) to work properly
This commit is contained in:
Bradford Powell 2022-07-29 18:54:53 -04:00
parent 964ee68974
commit f858d89f7b
2 changed files with 25 additions and 6 deletions

View file

@ -10,6 +10,12 @@ import { addMiniLocations } from '@strudel.cycles/eval/shapeshifter.mjs';
const { pure, Pattern, Fraction, stack, slowcat, sequence, timeCat, silence, reify } = strudel;
var _seedState = 0;
function _nextSeed() {
return _seedState++;
}
const applyOptions = (parent) => (pat, i) => {
const ast = parent.source_[i];
const options = ast.options_;
@ -84,6 +90,9 @@ export function patternifyAST(ast) {
if (alignment === 'v') {
return stack(...children);
}
if (alignment === 'r') {
return strudel.chooseInWith(strudel.rand.early(0.0001 * _nextSeed()).segment(1), children);
}
const weightedChildren = ast.source_.some((child) => !!child.options_?.weight);
if (!weightedChildren && alignment === 't') {
return slowcat(...children);