diff --git a/doc.json b/doc.json index 692ba029..279769bc 100644 --- a/doc.json +++ b/doc.json @@ -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": "
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
\nExamples intervals:
\nEither number of semitones or interval string.
", + "name": "amount" + } + ], + "returns": [ + { + "description": "Pattern
" + } + ], + "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": "Transposes notes inside the scale by the number of steps.\nExpected to be called on a Pattern which already has a {@link Pattern#scale}
", + "memberof": "Pattern", + "name": "scaleTranspose", + "params": [ + { + "type": { + "names": [ + "offset" + ] + }, + "description": "number of steps inside the scale
", + "name": "offset" + } + ], + "returns": [ + { + "description": "Pattern
" + } + ], + "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": "Turns numbers into notes in the scale (zero indexed). Also sets scale for other scale operations, like {@link Pattern#scaleTranspose}.
\nThe scale name has the form "TO? N" wher
\nName of scale
", + "name": "scale" + } + ], + "returns": [ + { + "description": "Pattern
" + } + ], + "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 } ] diff --git a/packages/tonal/tonal.mjs b/packages/tonal/tonal.mjs index 05979d5e..6b82255b 100644 --- a/packages/tonal/tonal.mjs +++ b/packages/tonal/tonal.mjs @@ -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;