Compare commits

...

3 Commits

4 changed files with 94 additions and 126 deletions
+3 -1
View File
@@ -2738,7 +2738,9 @@ export const { segment, seg } = register(['segment', 'seg'], function (rate, pat
* @example
* s("hh*8").swingBy(1/3, 4)
*/
export const swingBy = register('swingBy', (swing, n, pat) => pat.inside(n, late(seq(0, swing / 2))));
export const swingBy = register('swingBy', (swing, n, pat) =>
pat.inside(n, late(stack(seq(0, silence), seq(silence, swing / 2).late(swing / 2)))),
);
/**
* Shorthand for swingBy with 1/3:
+32 -62
View File
@@ -14108,106 +14108,76 @@ exports[`runs examples > example "sustain" example index 0 1`] = `
exports[`runs examples > example "swing" example index 0 1`] = `
[
"[ -1/12 ⇜ (0/1 → 1/24) | s:hh ]",
"[ 0/1 → 1/8 | s:hh ]",
"[ 1/24 ⇜ (1/8 → 1/6) | s:hh ]",
"[ (1/6 → 1/4) ⇝ 7/24 | s:hh ]",
"[ 1/6 → 7/24 | s:hh ]",
"[ 1/4 → 3/8 | s:hh ]",
"[ 7/24 ⇜ (3/8 → 5/12) | s:hh ]",
"[ (5/12 → 1/2) ⇝ 13/24 | s:hh ]",
"[ 5/12 → 13/24 | s:hh ]",
"[ 1/2 → 5/8 | s:hh ]",
"[ 13/24 ⇜ (5/8 → 2/3) | s:hh ]",
"[ (2/3 → 3/4) ⇝ 19/24 | s:hh ]",
"[ 2/3 → 19/24 | s:hh ]",
"[ 3/4 → 7/8 | s:hh ]",
"[ 19/24 ⇜ (7/8 → 11/12) | s:hh ]",
"[ (11/12 → 1/1) ⇝ 25/24 | s:hh ]",
"[ 11/12 → 25/24 | s:hh ]",
"[ 1/1 → 9/8 | s:hh ]",
"[ 25/24 ⇜ (9/8 → 7/6) | s:hh ]",
"[ (7/6 → 5/4) ⇝ 31/24 | s:hh ]",
"[ 7/6 → 31/24 | s:hh ]",
"[ 5/4 → 11/8 | s:hh ]",
"[ 31/24 ⇜ (11/8 → 17/12) | s:hh ]",
"[ (17/12 → 3/2) ⇝ 37/24 | s:hh ]",
"[ 17/12 → 37/24 | s:hh ]",
"[ 3/2 → 13/8 | s:hh ]",
"[ 37/24 ⇜ (13/8 → 5/3) | s:hh ]",
"[ (5/3 → 7/4) ⇝ 43/24 | s:hh ]",
"[ 5/3 → 43/24 | s:hh ]",
"[ 7/4 → 15/8 | s:hh ]",
"[ 43/24 ⇜ (15/8 → 23/12) | s:hh ]",
"[ (23/12 → 2/1) ⇝ 49/24 | s:hh ]",
"[ 23/12 → 49/24 | s:hh ]",
"[ 2/1 → 17/8 | s:hh ]",
"[ 49/24 ⇜ (17/8 → 13/6) | s:hh ]",
"[ (13/6 → 9/4) ⇝ 55/24 | s:hh ]",
"[ 13/6 → 55/24 | s:hh ]",
"[ 9/4 → 19/8 | s:hh ]",
"[ 55/24 ⇜ (19/8 → 29/12) | s:hh ]",
"[ (29/12 → 5/2) ⇝ 61/24 | s:hh ]",
"[ 29/12 → 61/24 | s:hh ]",
"[ 5/2 → 21/8 | s:hh ]",
"[ 61/24 ⇜ (21/8 → 8/3) | s:hh ]",
"[ (8/3 → 11/4) ⇝ 67/24 | s:hh ]",
"[ 8/3 → 67/24 | s:hh ]",
"[ 11/4 → 23/8 | s:hh ]",
"[ 67/24 ⇜ (23/8 → 35/12) | s:hh ]",
"[ (35/12 → 3/1) ⇝ 73/24 | s:hh ]",
"[ 35/12 → 73/24 | s:hh ]",
"[ 3/1 → 25/8 | s:hh ]",
"[ 73/24 ⇜ (25/8 → 19/6) | s:hh ]",
"[ (19/6 → 13/4) ⇝ 79/24 | s:hh ]",
"[ 19/6 → 79/24 | s:hh ]",
"[ 13/4 → 27/8 | s:hh ]",
"[ 79/24 ⇜ (27/8 → 41/12) | s:hh ]",
"[ (41/12 → 7/2) ⇝ 85/24 | s:hh ]",
"[ 41/12 → 85/24 | s:hh ]",
"[ 7/2 → 29/8 | s:hh ]",
"[ 85/24 ⇜ (29/8 → 11/3) | s:hh ]",
"[ (11/3 → 15/4) ⇝ 91/24 | s:hh ]",
"[ 11/3 → 91/24 | s:hh ]",
"[ 15/4 → 31/8 | s:hh ]",
"[ 91/24 ⇜ (31/8 → 47/12) | s:hh ]",
"[ (47/12 → 4/1) ⇝ 97/24 | s:hh ]",
]
`;
exports[`runs examples > example "swingBy" example index 0 1`] = `
[
"[ -1/12 ⇜ (0/1 → 1/24) | s:hh ]",
"[ 0/1 → 1/8 | s:hh ]",
"[ 1/24 ⇜ (1/8 → 1/6) | s:hh ]",
"[ (1/6 → 1/4) ⇝ 7/24 | s:hh ]",
"[ 1/6 → 7/24 | s:hh ]",
"[ 1/4 → 3/8 | s:hh ]",
"[ 7/24 ⇜ (3/8 → 5/12) | s:hh ]",
"[ (5/12 → 1/2) ⇝ 13/24 | s:hh ]",
"[ 5/12 → 13/24 | s:hh ]",
"[ 1/2 → 5/8 | s:hh ]",
"[ 13/24 ⇜ (5/8 → 2/3) | s:hh ]",
"[ (2/3 → 3/4) ⇝ 19/24 | s:hh ]",
"[ 2/3 → 19/24 | s:hh ]",
"[ 3/4 → 7/8 | s:hh ]",
"[ 19/24 ⇜ (7/8 → 11/12) | s:hh ]",
"[ (11/12 → 1/1) ⇝ 25/24 | s:hh ]",
"[ 11/12 → 25/24 | s:hh ]",
"[ 1/1 → 9/8 | s:hh ]",
"[ 25/24 ⇜ (9/8 → 7/6) | s:hh ]",
"[ (7/6 → 5/4) ⇝ 31/24 | s:hh ]",
"[ 7/6 → 31/24 | s:hh ]",
"[ 5/4 → 11/8 | s:hh ]",
"[ 31/24 ⇜ (11/8 → 17/12) | s:hh ]",
"[ (17/12 → 3/2) ⇝ 37/24 | s:hh ]",
"[ 17/12 → 37/24 | s:hh ]",
"[ 3/2 → 13/8 | s:hh ]",
"[ 37/24 ⇜ (13/8 → 5/3) | s:hh ]",
"[ (5/3 → 7/4) ⇝ 43/24 | s:hh ]",
"[ 5/3 → 43/24 | s:hh ]",
"[ 7/4 → 15/8 | s:hh ]",
"[ 43/24 ⇜ (15/8 → 23/12) | s:hh ]",
"[ (23/12 → 2/1) ⇝ 49/24 | s:hh ]",
"[ 23/12 → 49/24 | s:hh ]",
"[ 2/1 → 17/8 | s:hh ]",
"[ 49/24 ⇜ (17/8 → 13/6) | s:hh ]",
"[ (13/6 → 9/4) ⇝ 55/24 | s:hh ]",
"[ 13/6 → 55/24 | s:hh ]",
"[ 9/4 → 19/8 | s:hh ]",
"[ 55/24 ⇜ (19/8 → 29/12) | s:hh ]",
"[ (29/12 → 5/2) ⇝ 61/24 | s:hh ]",
"[ 29/12 → 61/24 | s:hh ]",
"[ 5/2 → 21/8 | s:hh ]",
"[ 61/24 ⇜ (21/8 → 8/3) | s:hh ]",
"[ (8/3 → 11/4) ⇝ 67/24 | s:hh ]",
"[ 8/3 → 67/24 | s:hh ]",
"[ 11/4 → 23/8 | s:hh ]",
"[ 67/24 ⇜ (23/8 → 35/12) | s:hh ]",
"[ (35/12 → 3/1) ⇝ 73/24 | s:hh ]",
"[ 35/12 → 73/24 | s:hh ]",
"[ 3/1 → 25/8 | s:hh ]",
"[ 73/24 ⇜ (25/8 → 19/6) | s:hh ]",
"[ (19/6 → 13/4) ⇝ 79/24 | s:hh ]",
"[ 19/6 → 79/24 | s:hh ]",
"[ 13/4 → 27/8 | s:hh ]",
"[ 79/24 ⇜ (27/8 → 41/12) | s:hh ]",
"[ (41/12 → 7/2) ⇝ 85/24 | s:hh ]",
"[ 41/12 → 85/24 | s:hh ]",
"[ 7/2 → 29/8 | s:hh ]",
"[ 85/24 ⇜ (29/8 → 11/3) | s:hh ]",
"[ (11/3 → 15/4) ⇝ 91/24 | s:hh ]",
"[ 11/3 → 91/24 | s:hh ]",
"[ 15/4 → 31/8 | s:hh ]",
"[ 91/24 ⇜ (31/8 → 47/12) | s:hh ]",
"[ (47/12 → 4/1) ⇝ 97/24 | s:hh ]",
]
`;
+17 -61
View File
@@ -2,23 +2,20 @@ import jsdoc from '../../../doc.json'; // doc.json is built with `npm run jsdoc-
const docs = jsdoc.docs.reduce((acc, obj) => Object.assign(acc, { [obj.longname]: obj }), {});
import { MiniRepl } from './MiniRepl';
/**
*
* @param {Object} arguments
* @param {number} [arguments.h] Adds a heading (like 3 for h3). Deprecated, add the heading in MDX instead.
* @returns
*/
export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasHeight, hideMiniRepl }) {
export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight }) {
const item = docs[name];
if (!item) {
console.warn(`JsDoc for ${name} not found`);
return <div>Could not load docs for ${name}</div>;
console.warn('Not found: ' + name);
return <div />;
}
const CustomHeading = h ? `h${h}` : undefined;
const description = parseAndReplaceLink(item.description ?? '');
const CustomHeading = `h${h}`;
const description =
item.description?.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => {
return `<a href="#${a.replaceAll('.', '').toLowerCase()}${b ? `-${b}` : ''}">${a}${b ? `#${b}` : ''}</a>`;
}) || '';
return (
<>
{!!h && <CustomHeading id={name}>{item.longname}</CustomHeading>}
{!!h && <CustomHeading>{item.longname}</CustomHeading>}
{!hideDescription && (
<>
{!!item.synonyms_text && (
@@ -29,43 +26,19 @@ export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasH
<div dangerouslySetInnerHTML={{ __html: description }} />
</>
)}
{item.params && item.params.length > 0 && <p className="font-bold">Arguments</p>}
<ul>
{item.params?.map(({ name, type, description }, i) => {
// Check if the param is actually the parameter of an object
const objParamSeperator = name.indexOf('.');
const isObjectParam = objParamSeperator !== -1;
return (
<li key={i} className={isObjectParam ? 'list-none' : ''}>
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
{description ? <> - {removeHtmlTags(description)}</> : ''}
</li>
);
})}
{item.params?.map((param, i) => (
<li key={i}>
{param.name} ({param.type?.names?.join('|')}): {param.description?.replace(/(<([^>]+)>)/gi, '')}
</li>
))}
</ul>
{item.returns && (
<p>
<span className="font-bold">Returns</span>{' '}
{item.returns
.map((returnValue) => {
const description = returnValue.description ? `- ${removeHtmlTags(returnValue.description)}` : '';
return `${returnValue.type?.names?.join(' | ')} ${description}`;
})
.join(' or ')}
</p>
)}
{item.examples?.length ? (
<div className="space-y-2">
{item.examples?.map((example, k) => {
const key = `${item.longname}_example_${k}`;
return hideMiniRepl ? (
<pre key={key}>{example}</pre>
) : (
<MiniRepl tune={example} key={key} {...{ punchcard, canvasHeight }} />
);
})}
{item.examples?.map((example, k) => (
<MiniRepl tune={example} key={k} {...{ punchcard, canvasHeight }} />
))}
</div>
) : (
<div />
@@ -73,20 +46,3 @@ export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasH
</>
);
}
/**
* Replaces the jsDocs link with something else.
* @param {string} string
* @param {(name:string,longname: string) => string} [replaceWith]
*/
export const parseAndReplaceLink = (string, replaceWith) => {
const jsDocsLinkRegex = /\{@link ([a-zA-Z\.#]+)\}/g;
const fun = replaceWith ?? ((name, longname) => `<a target="_blank" href="/reference#${longname}">${name}</a>`);
return string.replaceAll(jsDocsLinkRegex, (_, longname) => {
const name = [...longname.matchAll(/[a-zA-Z]*[\.#]?([a-zA-Z]+)/g)].at(0)?.at(1); //take the string after . or #
return fun(name ?? longname, longname);
});
};
const removeHtmlTags = (string) => string.replace(/(<([^>]+)>)/gi, '');
@@ -3,7 +3,6 @@ import { memo, useEffect, useMemo, useState, Fragment } from 'react';
import jsdocJson from '../../../../../doc.json';
import { Textbox } from '@src/repl/components/panel/SettingsTab';
import { settingsMap, useSettings } from '@src/settings.mjs';
import { JsDoc } from '@src/docs/JsDoc';
import { computeAvailableFunctions } from '@src/jsDocsUtils.mjs';
const availableFunctions = computeAvailableFunctions(jsdocJson);
@@ -179,7 +178,48 @@ export const Reference = memo(function Reference() {
</span>
)}
</div>
<JsDoc name={entry.longname} hideMiniRepl></JsDoc>
{!!entry.synonyms_text && (
<p>
Synonyms: <code>{entry.synonyms_text}</code>
</p>
)}
<p
dangerouslySetInnerHTML={{
// If we have an external url make sure it opens in another tab to not interrupt the player
__html: entry.description.replaceAll(/<a href="https:\/\//g, `<a target="_blank" href="https://`),
}}
></p>
{entry.params && entry.params.length > 0 && <p className="font-bold">Arguments</p>}
<ul>
{entry.params?.map(({ name, type, description }, i) => {
// Check if the param is actually the parameter of an object
const objParamSeperator = name.indexOf('.');
const isObjectParam = objParamSeperator !== -1;
return (
<li key={i} className={isObjectParam ? 'list-none' : ''}>
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
{description ? <> - {getInnerText(description)}</> : ''}
</li>
);
})}
</ul>
{entry.returns && (
<p>
<span className="font-bold">Returns</span>{' '}
{entry.returns.map(({ type, description }) => (
<>
{type?.names?.join(' | ')} {description ? <> - {getInnerText(description)}</> : ''}
</>
))}
</p>
)}
{entry.examples?.map((example, j) => (
<pre className="bg-background border border-muted" key={j}>
{example}
</pre>
))}
</section>
)) || <p className="font-sans">Search or select a tag to get started.</p>}
{detailVisibleFunctions.length > 0 && <div className="h-screen" />}