diff --git a/packages/core/signal.mjs b/packages/core/signal.mjs index bd6815e2..7309a19f 100644 --- a/packages/core/signal.mjs +++ b/packages/core/signal.mjs @@ -114,6 +114,14 @@ const timeToRands = (t, n) => timeToRandsPrime(timeToIntSeed(t), n); * */ +/** + * A discrete pattern of numbers from 0 to n-1 + * @example + * run(4).scale('C4 major').note() + * // "0 1 2 3".scale('C4 major').note() + */ +export const run = (n) => saw.range(0, n).floor().segment(n); + /** * A continuous pattern of random numbers, between 0 and 1. * diff --git a/packages/core/test/pattern.test.mjs b/packages/core/test/pattern.test.mjs index 2a91e142..a4c04e80 100644 --- a/packages/core/test/pattern.test.mjs +++ b/packages/core/test/pattern.test.mjs @@ -44,6 +44,7 @@ import { ply, rev, time, + run, } from '../index.mjs'; import { steady } from '../signal.mjs'; @@ -908,6 +909,11 @@ describe('Pattern', () => { ); }); }); + describe('run', () => { + it('Can run', () => { + expect(run(4).firstCycle()).toStrictEqual(sequence(0, 1, 2, 3).firstCycle()); + }); + }); describe('linger', () => { it('Can linger on the first quarter of a cycle', () => { expect(sequence(0, 1, 2, 3, 4, 5, 6, 7).linger(0.25).firstCycle()).toStrictEqual( diff --git a/test/__snapshots__/examples.test.mjs.snap b/test/__snapshots__/examples.test.mjs.snap index 717d713b..f9156bc3 100644 --- a/test/__snapshots__/examples.test.mjs.snap +++ b/test/__snapshots__/examples.test.mjs.snap @@ -3118,6 +3118,27 @@ exports[`runs examples > example "round" example index 0 1`] = ` ] `; +exports[`runs examples > example "run" example index 0 1`] = ` +[ + "[ 0/1 → 1/4 | note:C4 ]", + "[ 1/4 → 1/2 | note:D4 ]", + "[ 1/2 → 3/4 | note:E4 ]", + "[ 3/4 → 1/1 | note:F4 ]", + "[ 1/1 → 5/4 | note:C4 ]", + "[ 5/4 → 3/2 | note:D4 ]", + "[ 3/2 → 7/4 | note:E4 ]", + "[ 7/4 → 2/1 | note:F4 ]", + "[ 2/1 → 9/4 | note:C4 ]", + "[ 9/4 → 5/2 | note:D4 ]", + "[ 5/2 → 11/4 | note:E4 ]", + "[ 11/4 → 3/1 | note:F4 ]", + "[ 3/1 → 13/4 | note:C4 ]", + "[ 13/4 → 7/2 | note:D4 ]", + "[ 7/2 → 15/4 | note:E4 ]", + "[ 15/4 → 4/1 | note:F4 ]", +] +`; + exports[`runs examples > example "s" example index 0 1`] = ` [ "[ 0/1 → 1/2 | s:bd ]", diff --git a/website/src/docs/JsDoc.jsx b/website/src/docs/JsDoc.jsx index f0c3b900..88a775a5 100644 --- a/website/src/docs/JsDoc.jsx +++ b/website/src/docs/JsDoc.jsx @@ -4,7 +4,7 @@ import { MiniRepl } from './MiniRepl'; const getTag = (title, item) => item.tags?.find((t) => t.title === title)?.text; -export function JsDoc({ name, h = 3, hideDescription }) { +export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight }) { const item = docs[name]; if (!item) { console.warn('Not found: ' + name); @@ -40,7 +40,7 @@ export function JsDoc({ name, h = 3, hideDescription }) { {item.examples?.length ? (