tonal jsdoc

This commit is contained in:
Felix Roos 2022-05-21 21:52:45 +02:00
parent 6b26f999e4
commit f2b5dcf466
2 changed files with 179 additions and 1 deletions

115
doc.json
View File

@ -2153,6 +2153,119 @@
"___id": "T000002R000868",
"___s": true
},
{
"comment": "/**\n * Change the pitch of each value by the given amount. Expects numbers or note strings as values.\n * The amount can be given as a number of semitones or as a string in interval short notation.\n * If you don't care about enharmonic correctness, just use numbers. Otherwise, pass the interval of\n * the form: ST where S is the degree number and T the type of interval with\n *\n * - M = major\n * - m = minor\n * - P = perfect\n * - A = augmented\n * - d = diminished\n *\n * Examples intervals:\n *\n * - 1P = unison = 0\n * - 3M = major third\n * - 3m = minor third\n * - 4P = perfect fourth\n * - 4A = augmented fourth\n * - 5P = perfect fifth\n * - 5d = diminished fifth\n *\n * @param {string | number} amount Either number of semitones or interval string.\n * @returns Pattern\n * @memberof Pattern\n * @name transpose\n * @example\n * \"c2 c3\".fast(2).transpose(\"<0 -2 5 3>\".slow(2)).transpose(0)\n * @example\n * \"c2 c3\".fast(2).transpose(\"<1P -2M 4P 3m>\".slow(2)).transpose(0)\n */",
"meta": {
"filename": "tonal.mjs",
"lineno": 45,
"columnno": 0,
"path": "/home/felix/projects/strudel/packages/tonal",
"code": {}
},
"description": "<p>Change the pitch of each value by the given amount. Expects numbers or note strings as values.\nThe amount can be given as a number of semitones or as a string in interval short notation.\nIf you don't care about enharmonic correctness, just use numbers. Otherwise, pass the interval of\nthe form: ST where S is the degree number and T the type of interval with</p>\n<ul>\n<li>M = major</li>\n<li>m = minor</li>\n<li>P = perfect</li>\n<li>A = augmented</li>\n<li>d = diminished</li>\n</ul>\n<p>Examples intervals:</p>\n<ul>\n<li>1P = unison = 0</li>\n<li>3M = major third</li>\n<li>3m = minor third</li>\n<li>4P = perfect fourth</li>\n<li>4A = augmented fourth</li>\n<li>5P = perfect fifth</li>\n<li>5d = diminished fifth</li>\n</ul>",
"params": [
{
"type": {
"names": [
"string",
"number"
]
},
"description": "<p>Either number of semitones or interval string.</p>",
"name": "amount"
}
],
"returns": [
{
"description": "<p>Pattern</p>"
}
],
"memberof": "Pattern",
"name": "transpose",
"examples": [
"\"c2 c3\".fast(2).transpose(\"<0 -2 5 3>\".slow(2)).transpose(0)",
"\"c2 c3\".fast(2).transpose(\"<1P -2M 4P 3m>\".slow(2)).transpose(0)"
],
"scope": "static",
"longname": "Pattern.transpose",
"kind": "member",
"___id": "T000002R003677",
"___s": true
},
{
"comment": "/**\n * Transposes notes inside the scale by the number of steps.\n * Expected to be called on a Pattern which already has a {@link Pattern#scale}\n *\n * @memberof Pattern\n * @name scaleTranspose\n * @param {offset} offset number of steps inside the scale\n * @returns Pattern\n * @example\n * \"-8 [2,4,6]\"\n * .scale('C4 bebop major')\n * .scaleTranspose(\"<0 -1 -2 -3 -4 -5 -6 -4>\")\n */",
"meta": {
"filename": "tonal.mjs",
"lineno": 98,
"columnno": 0,
"path": "/home/felix/projects/strudel/packages/tonal",
"code": {}
},
"description": "<p>Transposes notes inside the scale by the number of steps.\nExpected to be called on a Pattern which already has a {@link Pattern#scale}</p>",
"memberof": "Pattern",
"name": "scaleTranspose",
"params": [
{
"type": {
"names": [
"offset"
]
},
"description": "<p>number of steps inside the scale</p>",
"name": "offset"
}
],
"returns": [
{
"description": "<p>Pattern</p>"
}
],
"examples": [
"\"-8 [2,4,6]\"\n.scale('C4 bebop major')\n.scaleTranspose(\"<0 -1 -2 -3 -4 -5 -6 -4>\")"
],
"scope": "static",
"longname": "Pattern.scaleTranspose",
"kind": "member",
"___id": "T000002R003681",
"___s": true
},
{
"comment": "/**\n * Turns numbers into notes in the scale (zero indexed). Also sets scale for other scale operations, like {@link Pattern#scaleTranspose}.\n *\n * The scale name has the form \"TO? N\" wher\n *\n * - T = Tonic\n * - O = Octave (optional, defaults to 3)\n * - N = Name of scale, available names can be found [here](https://github.com/tonaljs/tonal/blob/main/packages/scale-type/data.ts).\n *\n * @memberof Pattern\n * @name scale\n * @param {string} scale Name of scale\n * @returns Pattern\n * @example \n * \"0 2 4 6 4 2\"\n * .scale(seq('C2 major', 'C2 minor').slow(2))\n */",
"meta": {
"filename": "tonal.mjs",
"lineno": 124,
"columnno": 0,
"path": "/home/felix/projects/strudel/packages/tonal",
"code": {}
},
"description": "<p>Turns numbers into notes in the scale (zero indexed). Also sets scale for other scale operations, like {@link Pattern#scaleTranspose}.</p>\n<p>The scale name has the form &quot;TO? N&quot; wher</p>\n<ul>\n<li>T = Tonic</li>\n<li>O = Octave (optional, defaults to 3)</li>\n<li>N = Name of scale, available names can be found <a href=\"https://github.com/tonaljs/tonal/blob/main/packages/scale-type/data.ts\">here</a>.</li>\n</ul>",
"memberof": "Pattern",
"name": "scale",
"params": [
{
"type": {
"names": [
"string"
]
},
"description": "<p>Name of scale</p>",
"name": "scale"
}
],
"returns": [
{
"description": "<p>Pattern</p>"
}
],
"examples": [
"\"0 2 4 6 4 2\"\n.scale(seq('C2 major', 'C2 minor').slow(2))"
],
"scope": "static",
"longname": "Pattern.scale",
"kind": "member",
"___id": "T000002R003683",
"___s": true
},
{
"kind": "package",
"longname": "package:undefined",
@ -2232,7 +2345,7 @@
"/home/felix/projects/strudel/packages/xen/tunejs.js",
"/home/felix/projects/strudel/packages/xen/xen.mjs"
],
"___id": "T000002R013973",
"___id": "T000002R013976",
"___s": true
}
]

View File

@ -42,6 +42,38 @@ function scaleOffset(scale, offset, note) {
}
// Pattern.prototype._transpose = function (intervalOrSemitones: string | number) {
/**
* Change the pitch of each value by the given amount. Expects numbers or note strings as values.
* The amount can be given as a number of semitones or as a string in interval short notation.
* If you don't care about enharmonic correctness, just use numbers. Otherwise, pass the interval of
* the form: ST where S is the degree number and T the type of interval with
*
* - M = major
* - m = minor
* - P = perfect
* - A = augmented
* - d = diminished
*
* Examples intervals:
*
* - 1P = unison = 0
* - 3M = major third
* - 3m = minor third
* - 4P = perfect fourth
* - 4A = augmented fourth
* - 5P = perfect fifth
* - 5d = diminished fifth
*
* @param {string | number} amount Either number of semitones or interval string.
* @returns Pattern
* @memberof Pattern
* @name transpose
* @example
* "c2 c3".fast(2).transpose("<0 -2 5 3>".slow(2)).transpose(0)
* @example
* "c2 c3".fast(2).transpose("<1P -2M 4P 3m>".slow(2)).transpose(0)
*/
Pattern.prototype._transpose = function (intervalOrSemitones) {
return this._withHap((hap) => {
const interval = !isNaN(Number(intervalOrSemitones))
@ -63,6 +95,20 @@ Pattern.prototype._transpose = function (intervalOrSemitones) {
// e.g. `stack(c3).superimpose(transpose(slowcat(7, 5)))` or
// or even `stack(c3).superimpose(transpose.slowcat(7, 5))` or
/**
* Transposes notes inside the scale by the number of steps.
* Expected to be called on a Pattern which already has a {@link Pattern#scale}
*
* @memberof Pattern
* @name scaleTranspose
* @param {offset} offset number of steps inside the scale
* @returns Pattern
* @example
* "-8 [2,4,6]"
* .scale('C4 bebop major')
* .scaleTranspose("<0 -1 -2 -3 -4 -5 -6 -4>")
*/
Pattern.prototype._scaleTranspose = function (offset /* : number | string */) {
return this._withHap((hap) => {
if (!hap.context.scale) {
@ -74,6 +120,25 @@ Pattern.prototype._scaleTranspose = function (offset /* : number | string */) {
return hap.withValue(() => scaleOffset(hap.context.scale, Number(offset), hap.value));
});
};
/**
* Turns numbers into notes in the scale (zero indexed). Also sets scale for other scale operations, like {@link Pattern#scaleTranspose}.
*
* The scale name has the form "TO? N" wher
*
* - T = Tonic
* - O = Octave (optional, defaults to 3)
* - N = Name of scale, available names can be found [here](https://github.com/tonaljs/tonal/blob/main/packages/scale-type/data.ts).
*
* @memberof Pattern
* @name scale
* @param {string} scale Name of scale
* @returns Pattern
* @example
* "0 2 4 6 4 2"
* .scale(seq('C2 major', 'C2 minor').slow(2))
*/
Pattern.prototype._scale = function (scale /* : string */) {
return this._withHap((hap) => {
let note = hap.value;