mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 05:38:35 +00:00
test jsdoc
This commit is contained in:
parent
f469e48970
commit
2348d056cb
1
.gitignore
vendored
1
.gitignore
vendored
@ -27,4 +27,5 @@ node_modules/
|
||||
repl-parcel
|
||||
mytunes.ts
|
||||
doc
|
||||
out
|
||||
.parcel-cache
|
||||
140
api.md
Normal file
140
api.md
Normal file
@ -0,0 +1,140 @@
|
||||
## Classes
|
||||
|
||||
<dl>
|
||||
<dt><a href="#Pattern">Pattern</a></dt>
|
||||
<dd><p>Class representing a pattern.</p></dd>
|
||||
</dl>
|
||||
|
||||
## Functions
|
||||
|
||||
<dl>
|
||||
<dt><a href="#pure">pure(value)</a> ⇒ <code><a href="#Pattern">Pattern</a></code></dt>
|
||||
<dd><p>A discrete value that repeats once per cycle:</p></dd>
|
||||
<dt><a href="#stack">stack(...items)</a> ⇒ <code><a href="#Pattern">Pattern</a></code></dt>
|
||||
<dd><p>The given items are played at the same time at the same length:</p></dd>
|
||||
<dt><a href="#slowcat">slowcat(...items)</a> ⇒ <code><a href="#Pattern">Pattern</a></code></dt>
|
||||
<dd><p>Concatenation: combines a list of patterns, switching between them successively, one per cycle:</p>
|
||||
<p>synonyms: [cat](#cat)</p></dd>
|
||||
<dt><a href="#slowcatPrime">slowcatPrime(...items)</a> ⇒ <code><a href="#Pattern">Pattern</a></code></dt>
|
||||
<dd><p>Concatenation: combines a list of patterns, switching between them successively, one per cycle. Unlike slowcat, this version will skip cycles.</p></dd>
|
||||
<dt><a href="#fastcat">fastcat(...items)</a> ⇒ <code><a href="#Pattern">Pattern</a></code></dt>
|
||||
<dd><p>Concatenation: as with [slowcat](#slowcat), but squashes a cycle from each pattern into one cycle</p>
|
||||
<p>Synonyms: [seq](#seq), [sequence](#sequence)</p></dd>
|
||||
<dt><a href="#cat">cat()</a></dt>
|
||||
<dd><p>See [slowcat](#slowcat)</p></dd>
|
||||
<dt><a href="#timeCat">timeCat(...items)</a> ⇒ <code><a href="#Pattern">Pattern</a></code></dt>
|
||||
<dd><p>Like [fastcat](#fastcat), but where each step has a temporal weight:</p></dd>
|
||||
<dt><a href="#sequence">sequence()</a></dt>
|
||||
<dd><p>See [fastcat](#fastcat)</p></dd>
|
||||
<dt><a href="#seq">seq()</a></dt>
|
||||
<dd><p>See [fastcat](#fastcat)</p></dd>
|
||||
</dl>
|
||||
|
||||
<a name="pure"></a>
|
||||
|
||||
## pure(value) ⇒ [<code>Pattern</code>](#Pattern)
|
||||
<p>A discrete value that repeats once per cycle:</p>
|
||||
|
||||
**Kind**: global function
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| value | <code>any</code> | <p>The value to repeat</p> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
pure('e4')
|
||||
```
|
||||
<a name="stack"></a>
|
||||
|
||||
## stack(...items) ⇒ [<code>Pattern</code>](#Pattern)
|
||||
<p>The given items are played at the same time at the same length:</p>
|
||||
|
||||
**Kind**: global function
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| ...items | <code>any</code> | <p>The items to stack</p> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
stack(g3, b3, [e4, d4])
|
||||
```
|
||||
<a name="slowcat"></a>
|
||||
|
||||
## slowcat(...items) ⇒ [<code>Pattern</code>](#Pattern)
|
||||
<p>Concatenation: combines a list of patterns, switching between them successively, one per cycle:</p>
|
||||
<p>synonyms: [cat](#cat)</p>
|
||||
|
||||
**Kind**: global function
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| ...items | <code>any</code> | <p>The items to concatenate</p> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
slowcat(e5, b4, [d5, c5])
|
||||
```
|
||||
<a name="slowcatPrime"></a>
|
||||
|
||||
## slowcatPrime(...items) ⇒ [<code>Pattern</code>](#Pattern)
|
||||
<p>Concatenation: combines a list of patterns, switching between them successively, one per cycle. Unlike slowcat, this version will skip cycles.</p>
|
||||
|
||||
**Kind**: global function
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| ...items | <code>any</code> | <p>The items to concatenate</p> |
|
||||
|
||||
<a name="fastcat"></a>
|
||||
|
||||
## fastcat(...items) ⇒ [<code>Pattern</code>](#Pattern)
|
||||
<p>Concatenation: as with [slowcat](#slowcat), but squashes a cycle from each pattern into one cycle</p>
|
||||
<p>Synonyms: [seq](#seq), [sequence](#sequence)</p>
|
||||
|
||||
**Kind**: global function
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| ...items | <code>any</code> | <p>The items to concatenate</p> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
fastcat(e5, b4, [d5, c5])
|
||||
sequence(e5, b4, [d5, c5])
|
||||
seq(e5, b4, [d5, c5])
|
||||
```
|
||||
<a name="cat"></a>
|
||||
|
||||
## cat()
|
||||
<p>See [slowcat](#slowcat)</p>
|
||||
|
||||
**Kind**: global function
|
||||
<a name="timeCat"></a>
|
||||
|
||||
## timeCat(...items) ⇒ [<code>Pattern</code>](#Pattern)
|
||||
<p>Like [fastcat](#fastcat), but where each step has a temporal weight:</p>
|
||||
|
||||
**Kind**: global function
|
||||
|
||||
| Param | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| ...items | <code>Array</code> | <p>The items to concatenate</p> |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
timeCat([3,e3],[1, g3])
|
||||
```
|
||||
<a name="sequence"></a>
|
||||
|
||||
## sequence()
|
||||
<p>See [fastcat](#fastcat)</p>
|
||||
|
||||
**Kind**: global function
|
||||
<a name="seq"></a>
|
||||
|
||||
## seq()
|
||||
<p>See [fastcat](#fastcat)</p>
|
||||
|
||||
**Kind**: global function
|
||||
6
jsdoc.config.json
Normal file
6
jsdoc.config.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"source": {
|
||||
"includePattern": ".+\\.(js(doc|x)?|mjs)$"
|
||||
},
|
||||
"plugins": ["plugins/markdown"]
|
||||
}
|
||||
1128
package-lock.json
generated
1128
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,9 @@
|
||||
"setup": "npm i && npm run bootstrap && cd repl && npm i",
|
||||
"repl": "cd repl && npm run start",
|
||||
"osc": "cd packages/osc && npm run server",
|
||||
"build": "cd repl && npm run build"
|
||||
"build": "cd repl && npm run build",
|
||||
"jsdoc": "jsdoc packages/core/pattern.mjs -c jsdoc.config.json",
|
||||
"jsdoc2md": "jsdoc2md packages/core/pattern.mjs -c jsdoc.config.json > api.md"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
@ -34,6 +36,8 @@
|
||||
"homepage": "https://strudel.tidalcycles.org",
|
||||
"devDependencies": {
|
||||
"events": "^3.3.0",
|
||||
"jsdoc": "^3.6.10",
|
||||
"jsdoc-to-markdown": "^7.1.1",
|
||||
"lerna": "^4.0.0",
|
||||
"mocha": "^9.1.4"
|
||||
}
|
||||
|
||||
@ -12,12 +12,26 @@ import State from './state.mjs';
|
||||
import { isNote, toMidi, compose, removeUndefineds, flatten, id, listRange, curry, mod } from './util.mjs';
|
||||
import drawLine from './drawLine.mjs';
|
||||
|
||||
/** @class Class representing a pattern. */
|
||||
export class Pattern {
|
||||
// the following functions will get patternFactories as nested functions:
|
||||
/**
|
||||
* Create a pattern.
|
||||
* @param {function} query - The function that maps a State to Haps .
|
||||
*/
|
||||
constructor(query) {
|
||||
this.query = query;
|
||||
}
|
||||
|
||||
/**
|
||||
* query events insude the tiven time span
|
||||
*
|
||||
* @param {Fraction | number} begin from time
|
||||
* @param {Fraction | number} end to time
|
||||
* @returns Hap[]
|
||||
* @example
|
||||
* const pattern = sequence('a', ['b', 'c']);
|
||||
* const events = pattern.queryArc(0, 1);
|
||||
*/
|
||||
queryArc(begin, end) {
|
||||
return this.query(new State(new TimeSpan(begin, end)));
|
||||
}
|
||||
@ -838,8 +852,14 @@ Pattern.prototype.factories = {
|
||||
// Nothing
|
||||
export const silence = new Pattern((_) => []);
|
||||
|
||||
/** A discrete value that repeats once per cycle:
|
||||
*
|
||||
* @param {any} value - The value to repeat
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* pure('e4')
|
||||
*/
|
||||
export function pure(value) {
|
||||
// A discrete value that repeats once per cycle
|
||||
function query(state) {
|
||||
return state.span.spanCycles.map((subspan) => new Hap(Fraction(subspan.begin).wholeCycle(), subspan, value));
|
||||
}
|
||||
@ -859,8 +879,13 @@ export function reify(thing) {
|
||||
return pure(thing);
|
||||
}
|
||||
|
||||
// Basic functions for combining patterns
|
||||
|
||||
/** The given items are played at the same time at the same length:
|
||||
*
|
||||
* @param {...any} items - The items to stack
|
||||
* @return {Pattern}
|
||||
* @example
|
||||
* stack(g3, b3, [e4, d4])
|
||||
*/
|
||||
export function stack(...pats) {
|
||||
// Array test here is to avoid infinite recursions..
|
||||
pats = pats.map((pat) => (Array.isArray(pat) ? sequence(...pat) : reify(pat)));
|
||||
@ -868,10 +893,17 @@ export function stack(...pats) {
|
||||
return new Pattern(query);
|
||||
}
|
||||
|
||||
/** Concatenation: combines a list of patterns, switching between them successively, one per cycle:
|
||||
*
|
||||
* synonyms: {@link cat}
|
||||
*
|
||||
* @param {...any} items - The items to concatenate
|
||||
* @return {Pattern}
|
||||
* @example
|
||||
* slowcat(e5, b4, [d5, c5])
|
||||
*
|
||||
*/
|
||||
export function slowcat(...pats) {
|
||||
// Concatenation: combines a list of patterns, switching between them
|
||||
// successively, one per cycle.
|
||||
|
||||
// Array test here is to avoid infinite recursions..
|
||||
pats = pats.map((pat) => (Array.isArray(pat) ? sequence(...pat) : reify(pat)));
|
||||
|
||||
@ -892,9 +924,11 @@ export function slowcat(...pats) {
|
||||
return new Pattern(query)._splitQueries();
|
||||
}
|
||||
|
||||
/** Concatenation: combines a list of patterns, switching between them successively, one per cycle. Unlike slowcat, this version will skip cycles.
|
||||
* @param {...any} items - The items to concatenate
|
||||
* @return {Pattern}
|
||||
*/
|
||||
export function slowcatPrime(...pats) {
|
||||
// Concatenation: combines a list of patterns, switching between them
|
||||
// successively, one per cycle. Unlike slowcat, this version will skip cycles.
|
||||
pats = pats.map(reify);
|
||||
const query = function (state) {
|
||||
const pat_n = Math.floor(state.span.begin) % pats.length;
|
||||
@ -904,18 +938,33 @@ export function slowcatPrime(...pats) {
|
||||
return new Pattern(query)._splitQueries();
|
||||
}
|
||||
|
||||
/** Concatenation: as with {@link slowcat}, but squashes a cycle from each pattern into one cycle
|
||||
*
|
||||
* Synonyms: {@link seq}, {@link sequence}
|
||||
*
|
||||
* @param {...any} items - The items to concatenate
|
||||
* @return {Pattern}
|
||||
* @example
|
||||
* fastcat(e5, b4, [d5, c5])
|
||||
* sequence(e5, b4, [d5, c5])
|
||||
* seq(e5, b4, [d5, c5])
|
||||
*/
|
||||
export function fastcat(...pats) {
|
||||
// Concatenation: as with slowcat, but squashes a cycle from each
|
||||
// pattern into one cycle
|
||||
return slowcat(...pats)._fast(pats.length);
|
||||
}
|
||||
|
||||
/** See {@link slowcat} */
|
||||
export function cat(...pats) {
|
||||
return slowcat(...pats);
|
||||
}
|
||||
|
||||
/** Like {@link fastcat}, but where each step has a temporal weight:
|
||||
* @param {...Array} items - The items to concatenate
|
||||
* @return {Pattern}
|
||||
* @example
|
||||
* timeCat([3,e3],[1, g3])
|
||||
*/
|
||||
export function timeCat(...timepats) {
|
||||
// Like cat, but where each step has a temporal 'weight'
|
||||
const total = timepats.map((a) => a[0]).reduce((a, b) => a.add(b), Fraction(0));
|
||||
let begin = Fraction(0);
|
||||
const pats = [];
|
||||
@ -927,11 +976,12 @@ export function timeCat(...timepats) {
|
||||
return stack(...pats);
|
||||
}
|
||||
|
||||
/** See {@link fastcat} */
|
||||
export function sequence(...pats) {
|
||||
return fastcat(...pats);
|
||||
}
|
||||
|
||||
// shorthand for sequence
|
||||
/** See {@link fastcat} */
|
||||
export function seq(...pats) {
|
||||
return fastcat(...pats);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user