add swing + swingBy

This commit is contained in:
Felix Roos 2024-04-01 02:59:17 +02:00
parent 7839d6b4bf
commit 8f06bc4b57

View File

@ -2110,6 +2110,24 @@ export const segment = register('segment', function (rate, pat) {
return pat.struct(pure(true)._fast(rate)).setTactus(rate);
});
/**
* The function `swingBy x n` breaks each cycle into `n` slices, and then delays events in the second half of each slice by the amount `x`, which is relative to the size of the (half) slice. So if `x` is 0 it does nothing, `0.5` delays for half the note duration, and 1 will wrap around to doing nothing again. The end result is a shuffle or swing-like rhythm
* @param {number} subdivision
* @param {number} offset
* @example
* s("hh*8").swingBy(1/3, 4)
*/
export const swingBy = register('swingBy', (swing, n, pat) => pat.inside(n, late(seq(0, swing / 2))));
/**
* Shorthand for swingBy with 1/3:
* @param {number} subdivision
* @example
* s("hh*8").swing(4)
* // s("hh*8").swingBy(1/3, 4)
*/
export const swing = register('swing', (n, pat) => pat.swingBy(1 / 3, n));
/**
* Swaps 1s and 0s in a binary pattern.
* @name invert