Document remaining functions

This commit is contained in:
Václav Volhejn 2025-10-12 16:07:11 +02:00
parent d516d765d5
commit c62428ca27
25 changed files with 179 additions and 94 deletions

View file

@ -889,7 +889,7 @@ export class Pattern {
/**
* Writes the content of the current event to the console (visible in the side menu).
* @tags visualizers
* @tags visualization
* @name log
* @memberof Pattern
* @example
@ -904,7 +904,7 @@ export class Pattern {
/**
* A simplified version of `log` which writes all "values" (various configurable parameters)
* within the event to the console (visible in the side menu).
* @tags visualizers
* @tags visualization
* @name logValues
* @memberof Pattern
* @example
@ -938,7 +938,7 @@ export class Pattern {
* source pattern to be looped, and for an (optional) given function to be
* applied. False values result in the corresponding part of the source pattern
* to be played unchanged.
* @tags structure
* @tags temporal
* @name into
* @memberof Pattern
* @example
@ -1066,6 +1066,7 @@ function _composeOp(a, b, func) {
* Assumes a pattern of numbers. Adds the given number to each item in the pattern.
* @name add
* @memberof Pattern
* @tags math
* @example
* // Here, the triad 0, 2, 4 is shifted by different amounts
* n("0 2 4".add("<0 3 4 0>")).scale("C:major")
@ -1076,7 +1077,6 @@ function _composeOp(a, b, func) {
* note("c3 e3 g3".add("<0 5 7 0>"))
* // Behind the scenes, the notes are converted to midi numbers:
* // note("48 52 55".add("<0 5 7 0>"))
* @tags math
*/
add: [numeralArgs((a, b) => a + b)], // support string concatenation
/**
@ -1084,6 +1084,7 @@ function _composeOp(a, b, func) {
* Like add, but the given numbers are subtracted.
* @name sub
* @memberof Pattern
* @tags math
* @example
* n("0 2 4".sub("<0 1 2 3>")).scale("C4:minor")
* // See add for more information.
@ -1094,6 +1095,7 @@ function _composeOp(a, b, func) {
* Multiplies each number by the given factor.
* @name mul
* @memberof Pattern
* @tags math
* @example
* "<1 1.5 [1.66, <2 2.33>]>*4".mul(150).freq()
*/
@ -1103,6 +1105,7 @@ function _composeOp(a, b, func) {
* Divides each number by the given factor.
* @name div
* @memberof Pattern
* @tags math
*/
div: [numeralArgs((a, b) => a / b)],
mod: [numeralArgs(_mod)],
@ -1189,7 +1192,7 @@ function _composeOp(a, b, func) {
/**
* Applies the given structure to the pattern:
*
* @tags structure
* @tags temporal
* @example
* note("c,eb,g")
* .struct("x ~ x ~ ~ x ~ x ~ ~ ~ x ~ x ~ ~")
@ -1204,7 +1207,7 @@ function _composeOp(a, b, func) {
/**
* Returns silence when mask is 0 or "~"
*
* @tags structure
* @tags temporal
* @example
* note("c [eb,g] d [eb,g]").mask("<1 [0 1]>")
*/
@ -1217,7 +1220,7 @@ function _composeOp(a, b, func) {
/**
* Resets the pattern to the start of the cycle for each onset of the reset pattern.
*
* @tags structure
* @tags temporal
* @example
* s("[<bd lt> sd]*2, hh*8").reset("<x@3 x(5,8)>")
*/
@ -1231,7 +1234,7 @@ function _composeOp(a, b, func) {
* Restarts the pattern for each onset of the restart pattern.
* While reset will only reset the current cycle, restart will start from cycle 0.
*
* @tags structure
* @tags temporal
* @example
* s("[<bd lt> sd]*2, hh*8").restart("<x@3 x(5,8)>")
*/
@ -1352,7 +1355,7 @@ export function sequenceP(pats) {
/**
* The given items are played at the same time at the same length.
*
* @tags structure
* @tags temporal
* @return {Pattern}
* @synonyms polyrhythm, pr
* @example
@ -1566,14 +1569,9 @@ export function fastcat(...pats) {
return result;
}
/** See `fastcat` */
export function sequence(...pats) {
return fastcat(...pats);
}
/** Like **cat**, but the items are crammed into one cycle.
* @tags combiners
* @synonyms sequence, fastcat
* @synonyms seq, fastcat
* @example
* seq("e5", "b4", ["d5", "c5"]).note()
* // "e5 b4 [d5 c5]".note()
@ -1584,6 +1582,9 @@ export function sequence(...pats) {
* note("c4(5,8)")
* )
*/
export function sequence(...pats) {
return fastcat(...pats);
}
export function seq(...pats) {
return fastcat(...pats);
@ -1877,7 +1878,7 @@ export const ratio = register('ratio', (pat) =>
// Structural and temporal transformations
/** Compress each cycle into the given timespan, leaving a gap
* @tags structure
* @tags temporal
* @example
* cat(
* s("bd sd").compress(.25,.75),
@ -1899,7 +1900,7 @@ export const { compressSpan, compressspan } = register(['compressSpan', 'compres
/**
* speeds up a pattern like fast, but rather than it playing multiple times as fast would it instead leaves a gap in the remaining space of the cycle. For example, the following will play the sound pattern "bd sn" only once but compressed into the first half of the cycle, i.e. twice as fast.
* @tags structure
* @tags temporal
* @name fastGap
* @synonyms fastgap
* @example
@ -1937,7 +1938,7 @@ export const { fastGap, fastgap } = register(['fastGap', 'fastgap'], function (f
/**
* Similar to `compress`, but doesn't leave gaps, and the 'focus' can be bigger than a cycle
* @tags structure
* @tags temporal
* @example
* s("bd hh sd hh").focus(1/4, 3/4)
*/
@ -1955,7 +1956,7 @@ export const { focusSpan, focusspan } = register(['focusSpan', 'focusspan'], fun
});
/** The ply function repeats each event the given number of times.
* @tags structure
* @tags temporal
* @example
* s("bd ~ sd cp").ply("<1 2 3>")
*/
@ -1970,7 +1971,7 @@ export const ply = register('ply', function (factor, pat) {
/**
* Speed up a pattern by the given factor. Used by "*" in mini notation.
*
* @tags structure
* @tags temporal
* @name fast
* @synonyms density
* @memberof Pattern
@ -1995,7 +1996,7 @@ export const { fast, density } = register(
/**
* Both speeds up the pattern (like 'fast') and the sample playback (like 'speed').
* @tags structure
* @tags temporal
* @example
* s("bd sd:2").hurry("<1 2 4 3>").slow(1.5)
*/
@ -2006,7 +2007,7 @@ export const hurry = register('hurry', function (r, pat) {
/**
* Slow down a pattern over the given number of cycles. Like the "/" operator in mini notation.
*
* @tags structure
* @tags temporal
* @name slow
* @synonyms sparsity
* @memberof Pattern
@ -2024,7 +2025,7 @@ export const { slow, sparsity } = register(['slow', 'sparsity'], function (facto
/**
* Carries out an operation 'inside' a cycle.
* @tags structure
* @tags temporal
* @example
* "0 1 2 3 4 3 2 1".inside(4, rev).scale('C major').note()
* // "0 1 2 3 4 3 2 1".slow(4).rev().fast(4).scale('C major').note()
@ -2035,7 +2036,7 @@ export const inside = register('inside', function (factor, f, pat) {
/**
* Carries out an operation 'outside' a cycle.
* @tags structure
* @tags temporal
* @example
* "<[0 1] 2 [3 4] 5>".outside(4, rev).scale('C major').note()
* // "<[0 1] 2 [3 4] 5>".fast(4).rev().slow(4).scale('C major').note()
@ -2046,7 +2047,7 @@ export const outside = register('outside', function (factor, f, pat) {
/**
* Applies the given function every n cycles, starting from the last cycle.
* @tags structure
* @tags temporal
* @name lastOf
* @memberof Pattern
* @param {number} n how many cycles
@ -2063,7 +2064,7 @@ export const lastOf = register('lastOf', function (n, func, pat) {
/**
* Applies the given function every n cycles, starting from the first cycle.
* @tags structure
* @tags temporal
* @name firstOf
* @memberof Pattern
* @param {number} n how many cycles
@ -2075,7 +2076,7 @@ export const lastOf = register('lastOf', function (n, func, pat) {
/**
* An alias for `firstOf`
* @tags structure
* @tags temporal
* @name every
* @memberof Pattern
* @param {number} n how many cycles
@ -2092,7 +2093,7 @@ export const { firstOf, every } = register(['firstOf', 'every'], function (n, fu
/**
* Like layer, but with a single function:
* @tags structure
* @tags temporal
* @name apply
* @example
* "<c3 eb3 g3>".scale('C minor').apply(scaleTranspose("0,2,4")).note()
@ -2104,7 +2105,7 @@ export const apply = register('apply', function (func, pat) {
/**
* Plays the pattern at the given cycles per minute.
* @tags structure
* @tags temporal
* @deprecated
* @example
* s("<bd sd>,hh*2").cpm(90) // = 90 bpm
@ -2117,7 +2118,7 @@ export const cpm = register('cpm', function (cpm, pat) {
/**
* Nudge a pattern to start earlier in time. Equivalent of Tidal's <~ operator
*
* @tags structure
* @tags temporal
* @name early
* @memberof Pattern
* @param {number | Pattern} cycles number of cycles to nudge left
@ -2138,7 +2139,7 @@ export const early = register(
/**
* Nudge a pattern to start later in time. Equivalent of Tidal's ~> operator
*
* @tags structure
* @tags temporal
* @name late
* @memberof Pattern
* @param {number | Pattern} cycles number of cycles to nudge right
@ -2159,7 +2160,7 @@ export const late = register(
/**
* Plays a portion of a pattern, specified by the beginning and end of a time span. The new resulting pattern is played over the time period of the original pattern:
*
* @tags structure
* @tags temporal
* @example
* s("bd*2 hh*3 [sd bd]*2 perc").zoom(0.25, 0.75)
* // s("hh*3 [sd bd]*2") // equivalent
@ -2186,7 +2187,7 @@ export const { zoomArc, zoomarc } = register(['zoomArc', 'zoomarc'], function (a
/**
* Splits a pattern into the given number of slices, and plays them according to a pattern of slice numbers.
* Similar to `slice`, but slices up patterns rather than sound samples.
* @tags structure
* @tags temporal
* @param {number} number of slices
* @param {number} slices to play
* @example
@ -2214,7 +2215,7 @@ export const bite = register(
/**
* Selects the given fraction of the pattern and repeats that part to fill the remainder of the cycle.
* @tags structure
* @tags temporal
* @param {number} fraction fraction to select
* @example
* s("lt ht mt cp, [hh oh]*2").linger("<1 .5 .25 .125>")
@ -2235,7 +2236,7 @@ export const linger = register(
/**
* Samples the pattern at a rate of n events per cycle. Useful for turning a continuous pattern into a discrete one.
* @tags structure
* @tags temporal
* @name segment
* @synonyms seg
* @param {number} segments number of segments per cycle
@ -2248,7 +2249,7 @@ export const { segment, seg } = register(['segment', 'seg'], function (rate, pat
/**
* 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
* @tags structure
* @tags temporal
* @param {number} subdivision
* @param {number} offset
* @example
@ -2258,7 +2259,7 @@ export const swingBy = register('swingBy', (swing, n, pat) => pat.inside(n, late
/**
* Shorthand for swingBy with 1/3:
* @tags structure
* @tags temporal
* @param {number} subdivision
* @example
* s("hh*8").swing(4)
@ -2268,7 +2269,7 @@ export const swing = register('swing', (n, pat) => pat.swingBy(1 / 3, n));
/**
* Swaps 1s and 0s in a binary pattern.
* @tags structure
* @tags temporal
* @name invert
* @synonyms inv
* @example
@ -2286,7 +2287,7 @@ export const { invert, inv } = register(
/**
* Applies the given function whenever the given pattern is in a true state.
* @tags structure
* @tags temporal
* @name when
* @memberof Pattern
* @param {Pattern} binary_pat
@ -2301,7 +2302,7 @@ export const when = register('when', function (on, func, pat) {
/**
* Superimposes the function result on top of the original pattern, delayed by the given time.
* @tags structure
* @tags temporal
* @name off
* @memberof Pattern
* @param {Pattern | number} time offset time
@ -2318,7 +2319,7 @@ export const off = register('off', function (time_pat, func, pat) {
* Returns a new pattern where every other cycle is played once, twice as
* fast, and offset in time by one quarter of a cycle. Creates a kind of
* breakbeat feel.
* @tags structure
* @tags temporal
* @returns Pattern
*/
export const brak = register('brak', function (pat) {
@ -2328,7 +2329,7 @@ export const brak = register('brak', function (pat) {
/**
* Reverse all haps in a pattern
*
* @tags structure
* @tags temporal
* @name rev
* @memberof Pattern
* @returns Pattern
@ -2362,7 +2363,7 @@ export const rev = register(
/** Like press, but allows you to specify the amount by which each
* event is shifted. pressBy(0.5) is the same as press, while
* pressBy(1/3) shifts each event by a third of its timespan.
* @tags structure
* @tags temporal
* @example
* stack(s("hh*4"),
* s("bd mt sd ht").pressBy("<0 0.5 0.25>")
@ -2374,7 +2375,7 @@ export const pressBy = register('pressBy', function (r, pat) {
/**
* Syncopates a rhythm, by shifting each event halfway into its timespan.
* @tags structure
* @tags temporal
* @example
* stack(s("hh*4"),
* s("bd mt sd ht").every(4, press)
@ -2386,7 +2387,7 @@ export const press = register('press', function (pat) {
/**
* Silences a pattern.
* @tags structure
* @tags temporal
* @example
* stack(
* s("bd").hush(),
@ -2399,7 +2400,7 @@ Pattern.prototype.hush = function () {
/**
* Applies `rev` to a pattern every other cycle, so that the pattern alternates between forwards and backwards.
* @tags structure
* @tags temporal
* @example
* note("c d e g").palindrome()
*/
@ -2414,7 +2415,7 @@ export const palindrome = register(
/**
* Jux with adjustable stereo width. 0 = mono, 1 = full stereo.
* @tags structure
* @tags temporal
* @name juxBy
* @synonyms juxby
* @example
@ -2436,7 +2437,7 @@ export const { juxBy, juxby } = register(['juxBy', 'juxby'], function (by, func,
/**
* The jux function creates strange stereo effects, by applying a function to a pattern, but only in the right-hand channel.
* @tags structure
* @tags temporal
* @example
* s("bd lt [~ ht] mt cp ~ bd hh").jux(rev)
* @example
@ -2450,7 +2451,7 @@ export const jux = register('jux', function (func, pat) {
/**
* Superimpose and offset multiple times, applying the given function each time.
* @tags structure
* @tags temporal
* @name echoWith
* @synonyms echowith, stutWith, stutwith
* @param {number} times how many times to repeat
@ -2470,7 +2471,7 @@ export const { echoWith, echowith, stutWith, stutwith } = register(
/**
* Superimpose and offset multiple times, gradually decreasing the velocity
* @tags structure
* @tags temporal
* @name echo
* @memberof Pattern
* @returns Pattern
@ -2486,7 +2487,7 @@ export const echo = register('echo', function (times, time, feedback, pat) {
/**
* Deprecated. Like echo, but the last 2 parameters are flipped.
* @tags structure
* @tags temporal
* @name stut
* @param {number} times how many times to repeat
* @param {number} feedback velocity multiplicator for each iteration
@ -2508,7 +2509,7 @@ export const applyN = register('applyN', function (n, func, p) {
/**
* The plyWith function repeats each event the given number of times, applying the given function to each event.\n
* @tags structure
* @tags temporal
* @name plyWith
* @synonyms plywith
* @param {number} factor how many times to repeat
@ -2531,7 +2532,7 @@ export const plyWith = register(['plyWith', 'plywith'], function (factor, func,
/**
* The plyForEach function repeats each event the given number of times, applying the given function to each event.
* This version of ply uses the iteration index as an argument to the function, similar to echoWith.
* @tags structure
* @tags temporal
* @name plyForEach
* @synonyms plyforeach
* @param {number} factor how many times to repeat
@ -2553,7 +2554,7 @@ export const plyForEach = register(['plyForEach', 'plyforeach'], function (facto
/**
* Divides a pattern into a given number of subdivisions, plays the subdivisions in order, but increments the starting subdivision each cycle. The pattern wraps to the first subdivision after the last subdivision is played.
* @tags structure
* @tags temporal
* @name iter
* @memberof Pattern
* @returns Pattern
@ -2581,7 +2582,7 @@ export const iter = register(
/**
* Like `iter`, but plays the subdivisions in reverse order. Known as iter' in tidalcycles
* @tags structure
* @tags temporal
* @name iterBack
* @synonyms iterback
* @memberof Pattern
@ -2600,7 +2601,7 @@ export const { iterBack, iterback } = register(
/**
* Repeats each cycle the given number of times.
* @tags structure
* @tags temporal
* @name repeatCycles
* @memberof Pattern
* @returns Pattern
@ -2624,7 +2625,7 @@ export const { repeatCycles } = register(
/**
* Divides a pattern into a given number of parts, then cycles through those parts in turn, applying the given function to each part in turn (one part per cycle).
* @tags structure
* @tags temporal
* @name chunk
* @synonyms slowChunk, slowchunk
* @memberof Pattern
@ -2656,7 +2657,7 @@ export const { chunk, slowchunk, slowChunk } = register(
/**
* Like `chunk`, but cycles through the parts in reverse order. Known as chunk' in tidalcycles
* @tags structure
* @tags temporal
* @name chunkBack
* @synonyms chunkback
* @memberof Pattern
@ -2677,7 +2678,7 @@ export const { chunkBack, chunkback } = register(
/**
* Like `chunk`, but the cycles of the source pattern aren't repeated
* for each set of chunks.
* @tags structure
* @tags temporal
* @name fastChunk
* @synonyms fastchunk
* @memberof Pattern
@ -2698,7 +2699,7 @@ export const { fastchunk, fastChunk } = register(
/**
* Like `chunk`, but the function is applied to a looped subcycle of the source pattern.
* @tags structure
* @tags temporal
* @name chunkInto
* @synonyms chunkinto
* @memberof Pattern
@ -2712,7 +2713,7 @@ export const { chunkinto, chunkInto } = register(['chunkinto', 'chunkInto'], fun
/**
* Like `chunkInto`, but moves backwards through the chunks.
* @tags structure
* @tags temporal
* @name chunkBackInto
* @synonyms chunkbackinto
* @memberof Pattern
@ -2743,7 +2744,7 @@ export const bypass = register(
/**
* Loops the pattern inside an `offset` for `cycles`.
* If you think of the entire span of time in cycles as a ribbon, you can cut a single piece and loop it.
* @tags structure
* @tags temporal
* @name ribbon
* @synonyms rib
* @param {number} offset start point of loop in cycles
@ -2772,7 +2773,7 @@ export const hsl = register('hsl', (h, s, l, pat) => {
/**
* Tags each Hap with an identifier. Good for filtering. The function populates Hap.context.tags (Array).
* @name tag
* @tags structure
* @tags temporal
* @noAutocomplete
* @param {string} tag anything unique
*/
@ -2783,7 +2784,7 @@ Pattern.prototype.tag = function (tag) {
/**
* Filters haps using the given function
* @name filter
* @tags structure
* @tags temporal
* @param {Function} test function to test Hap
* @example
* s("hh!7 oh").filter(hap => hap.value.s==='hh')
@ -2793,7 +2794,7 @@ export const filter = register('filter', (test, pat) => pat.withHaps((haps) => h
/**
* Filters haps by their begin time
* @name filterWhen
* @tags structure
* @tags temporal
* @noAutocomplete
* @param {Function} test function to test Hap.whole.begin
*/
@ -2802,7 +2803,7 @@ export const filterWhen = register('filterWhen', (test, pat) => pat.filter((h) =
/**
* Use within to apply a function to only a part of a pattern.
* @name within
* @tags structure
* @tags temporal
* @param {number} start start within cycle (0 - 1)
* @param {number} end end within cycle (0 - 1). Must be > start
* @param {Function} func function to be applied to the sub-pattern
@ -2877,7 +2878,7 @@ export function _match(span, hap_p) {
* *Experimental*
*
* Speeds a pattern up or down, to fit to the given number of steps per cycle.
* @tags structure
* @tags temporal
* @example
* sound("bd sd cp").pace(4)
* // The same as sound("{bd sd cp}%4") or sound("<bd sd cp>*4")
@ -2919,7 +2920,7 @@ export function _polymeterListSteps(steps, ...args) {
* *Experimental*
*
* Aligns the steps of the patterns, creating polymeters. The patterns are repeated until they all fit the cycle. For example, in the below the first pattern is repeated twice, and the second is repeated three times, to fit the lowest common multiple of six steps.
* @tags structure
* @tags temporal
* @synonyms pm
* @example
* // The same as note("{c eb g, c2 g2}%6")
@ -3037,7 +3038,7 @@ export function stepalt(...groups) {
*
* Takes the given number of steps from a pattern (dropping the rest).
* A positive number will take steps from the start of a pattern, and a negative number from the end.
* @tags structure
* @tags temporal
* @return {Pattern}
* @example
* "bd cp ht mt".take("2").sound()
@ -3082,7 +3083,7 @@ export const take = stepRegister('take', function (i, pat) {
*
* Drops the given number of steps from a pattern.
* A positive number will drop steps from the start of a pattern, and a negative number from the end.
* @tags structure
* @tags temporal
* @return {Pattern}
* @example
* "tha dhi thom nam".drop("1").sound().bank("mridangam")
@ -3111,7 +3112,7 @@ export const drop = stepRegister('drop', function (i, pat) {
* `extend` is similar to `fast` in that it increases its density, but it also increases the step count
* accordingly. So `stepcat("a b".extend(2), "c d")` would be the same as `"a b a b c d"`, whereas
* `stepcat("a b".fast(2), "c d")` would be the same as `"[a b] [a b] c d"`.
* @tags structure
* @tags temporal
* @example
* stepcat(
* sound("bd bd - cp").extend(2),
@ -3126,7 +3127,7 @@ export const extend = stepRegister('extend', function (factor, pat) {
* *Experimental*
*
* Expands the step size of the pattern by the given factor.
* @tags structure
* @tags temporal
* @example
* sound("tha dhi thom nam").bank("mridangam").expand("3 2 1 1 2 3").pace(8)
*/
@ -3138,7 +3139,7 @@ export const expand = stepRegister('expand', function (factor, pat) {
* *Experimental*
*
* Contracts the step size of the pattern by the given factor. See also `expand`.
* @tags structure
* @tags temporal
* @example
* sound("tha dhi thom nam").bank("mridangam").contract("3 2 1 1 2 3").pace(8)
*/
@ -3193,7 +3194,7 @@ export const shrinklist = (amount, pat) => pat.shrinklist(amount);
* Progressively shrinks the pattern by 'n' steps until there's nothing left, or if a second value is given (using mininotation list syntax with `:`),
* that number of times.
* A positive number will progressively drop steps from the start of a pattern, and a negative number from the end.
* @tags structure
* @tags temporal
* @return {Pattern}
* @example
* "tha dhi thom nam".shrink("1").sound()
@ -3233,7 +3234,7 @@ export const shrink = register(
* Progressively grows the pattern by 'n' steps until the full pattern is played, or if a second value is given (using mininotation list syntax with `:`),
* that number of times.
* A positive number will progressively grow steps from the start of a pattern, and a negative number from the end.
* @tags structure
* @tags temporal
* @return {Pattern}
* @example
* "tha dhi thom nam".grow("1").sound()
@ -3552,7 +3553,9 @@ export const { loopAtCps, loopatcps } = register(['loopAtCps', 'loopatcps'], fun
return _loopAt(factor, pat, cps);
});
/** exposes a custom value at query time. basically allows mutating state without evaluation */
/** exposes a custom value at query time. basically allows mutating state without evaluation
* @tags internals
*/
export const ref = (accessor) =>
pure(1)
.withValue(() => reify(accessor()))
@ -3589,7 +3592,7 @@ Pattern.prototype.xfade = function (pos, b) {
* creates a structure pattern from divisions of a cycle
* especially useful for creating rhythms
* @name beat
* @tags structure
* @tags temporal
* @example
* s("bd").beat("0,7,10", 16)
* @example
@ -3666,7 +3669,7 @@ export const _morph = (from, to, by) => {
* sine.slow(8) // slowly morph between the rhythms
* )
* )
* @tags structure
* @tags temporal
*/
export const morph = (frompat, topat, bypat) => {
frompat = reify(frompat);