Merge pull request 'fix: shuffle(1) returns source pattern' (#1968) from tyow/localstrudel:shuffleFix into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1968
This commit is contained in:
commit
aa49d9dcc2
2 changed files with 10 additions and 2 deletions
|
|
@ -389,7 +389,9 @@ export const randL = (n) => {
|
||||||
export const randrun = (n) => {
|
export const randrun = (n) => {
|
||||||
return signal((t, controls) => {
|
return signal((t, controls) => {
|
||||||
// Without adding 0.5, the first cycle is always 0,1,2,3,...
|
// Without adding 0.5, the first cycle is always 0,1,2,3,...
|
||||||
const rands = getRandsAtTime(t.floor().add(0.5), n, controls.randSeed);
|
let rands = getRandsAtTime(t.floor().add(0.5), n, controls.randSeed);
|
||||||
|
// Support n = 1
|
||||||
|
if (!Array.isArray(rands)) rands = [rands];
|
||||||
const nums = rands
|
const nums = rands
|
||||||
.map((n, i) => [n, i])
|
.map((n, i) => [n, i])
|
||||||
.sort((a, b) => (a[0] > b[0]) - (a[0] < b[0]))
|
.sort((a, b) => (a[0] > b[0]) - (a[0] < b[0]))
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import Fraction from 'fraction.js';
|
||||||
import { describe, it, expect, vi } from 'vitest';
|
import { describe, it, expect, vi } from 'vitest';
|
||||||
|
|
||||||
import { saw, saw2, isaw, isaw2, per, perx, cyclesPer } from '../signal.mjs';
|
import { saw, saw2, isaw, isaw2, per, perx, cyclesPer } from '../signal.mjs';
|
||||||
import { fastcat, sequence, State, TimeSpan, Hap } from '../index.mjs';
|
import { fastcat, sequence, State, TimeSpan, Hap, note } from '../index.mjs';
|
||||||
|
|
||||||
const st = (begin, end) => new State(ts(begin, end));
|
const st = (begin, end) => new State(ts(begin, end));
|
||||||
const ts = (begin, end) => new TimeSpan(Fraction(begin), Fraction(end));
|
const ts = (begin, end) => new TimeSpan(Fraction(begin), Fraction(end));
|
||||||
|
|
@ -59,3 +59,9 @@ describe('perx', () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('shuffle', () => {
|
||||||
|
it('returns original pattern if input is 1', () => {
|
||||||
|
expect(note('c d e f').sound('piano').shuffle(1).firstCycle()).toEqual(note('c d e f').sound('piano').firstCycle());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue