Skip to content

Commit

Permalink
Documentation for all/each, and bugfix for each (tidalcycles#1233)
Browse files Browse the repository at this point in the history
* bugfix for each(), and documentation for each() and all()
* had to hide each/all examples from tests
  • Loading branch information
yaxu authored Dec 29, 2024
1 parent 9bf0f62 commit 1e3bbc5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
26 changes: 25 additions & 1 deletion packages/core/repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,33 @@ export function repl({
const toggle = () => scheduler.toggle();
const setCps = (cps) => scheduler.setCps(cps);
const setCpm = (cpm) => scheduler.setCps(cpm / 60);

// TODO - not documented as jsdoc examples as the test framework doesn't simulate enough context for `each` and `all`..

/** Applies a function to all the running patterns. Note that the patterns are groups together into a single `stack` before the function is applied. This is probably what you want, but see `each` for
* a version that applies the function to each pattern separately.
* ```
* $: sound("bd - cp sd")
* $: sound("hh*8")
* all(fast("<2 3>"))
* ```
* ```
* $: sound("bd - cp sd")
* $: sound("hh*8")
* all(x => x.pianoroll())
* ```
*/
const all = function (transform) {
allTransform = transform;
return silence;
};
/** Applies a function to each of the running patterns separately. This is intended for future use with upcoming 'stepwise' features. See `all` for a version that applies the function to all the patterns stacked together into a single pattern.
* ```
* $: sound("bd - cp sd")
* $: sound("hh*8")
* each(fast("<2 3>"))
* ```
*/
const each = function (transform) {
eachTransform = transform;
return silence;
Expand Down Expand Up @@ -161,7 +184,8 @@ export function repl({
if (Object.keys(pPatterns).length) {
let patterns = Object.values(pPatterns);
if (eachTransform) {
patterns = patterns.map(eachTransform);
// Explicit lambda so only element (not index and array) are passed
patterns = patterns.map((x) => eachTransform(x));
}
pattern = stack(...patterns);
} else if (eachTransform) {
Expand Down
4 changes: 2 additions & 2 deletions website/src/repl/components/panel/Reference.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export function Reference() {
<div className="prose dark:prose-invert min-w-full px-1 ">
<h2>API Reference</h2>
<p>
This is the long list functions you can use! Remember that you don't need to remember all of those and that
you can already make music with a small set of functions!
This is the long list of functions you can use. Remember that you don't need to remember all of those and
that you can already make music with a small set of functions!
</p>
{visibleFunctions.map((entry, i) => (
<section key={i}>
Expand Down

0 comments on commit 1e3bbc5

Please sign in to comment.