tonal-note
Advanced tools
Comparing version 1.1.0 to 1.1.2
@@ -23,3 +23,3 @@ 'use strict'; | ||
* Note.oct("G3") // => 3 | ||
* | ||
* | ||
* // part of tonal | ||
@@ -44,4 +44,4 @@ * const Tonal = require("tonal") | ||
* Get a list of note names (pitch classes) within a octave | ||
* | ||
* @param {string} accTypes - (Optional, by default " b#"). A string with the | ||
* | ||
* @param {string} accTypes - (Optional, by default " b#"). A string with the | ||
* accidentals types: " " means no accidental, "#" means sharps, "b" mean flats, | ||
@@ -66,8 +66,8 @@ * can be conbined (see examples) | ||
/** | ||
* Split a string into tokens related to note parts. | ||
* It returns an array of strings `[letter, accidental, octave, modifier]` | ||
* | ||
* Split a string into tokens related to note parts. | ||
* It returns an array of strings `[letter, accidental, octave, modifier]` | ||
* | ||
* It always returns an array | ||
* | ||
* @param {String} str | ||
* | ||
* @param {String} str | ||
* @return {Array} an array of note tokens | ||
@@ -127,3 +127,3 @@ * @example | ||
* Get note properties. It returns an object with the following information: | ||
* | ||
* | ||
* - name {String}: the note name. The letter is always in uppercase | ||
@@ -139,8 +139,8 @@ * - letter {String}: the note letter, always in uppercase | ||
* - freq {Number}: the frequency using an equal temperament at 440Hz | ||
* | ||
* | ||
* This function *always* returns an object with all this properties, but if it"s | ||
* not a valid note all properties will be null. | ||
* | ||
* | ||
* The returned object can"t be mutated. | ||
* | ||
* | ||
* @param {String} note - the note name in scientific notation | ||
@@ -161,3 +161,3 @@ * @return {Object} an object with the properties (or an object will all properties | ||
* using # or b | ||
* | ||
* | ||
* Can be used to test if a string is a valid note name. | ||
@@ -203,3 +203,3 @@ * | ||
* Get the frequency from midi number | ||
* | ||
* | ||
* @param {Number} midi - the note midi number | ||
@@ -232,3 +232,3 @@ * @param {Number} tuning - (Optional) 440 by default | ||
* contain decimals (with two digits precission) | ||
* | ||
* | ||
* @param {Number} frequency | ||
@@ -274,3 +274,3 @@ * @return {Number} | ||
* Given a step number return it"s letter (0 = C, 1 = D, 2 = E) | ||
* @param {number} step | ||
* @param {number} step | ||
* @return {string} the letter | ||
@@ -287,3 +287,3 @@ * @example | ||
* Given an alteration number, return the accidentals | ||
* @param {Number} alt | ||
* @param {Number} alt | ||
* @return {String} | ||
@@ -296,3 +296,3 @@ * @example | ||
/** | ||
* Creates a note name in scientific notation from note properties, | ||
* Creates a note name in scientific notation from note properties, | ||
* and optionally another note name. | ||
@@ -303,7 +303,10 @@ * It receives an object with: | ||
* - oct: (optional) the octave | ||
* | ||
* Optionally it receives another note as a "base", meaning that any prop not explicitly | ||
* received on the first parameter will be taken from that base note. That way it can be used | ||
* received on the first parameter will be taken from that base note. That way it can be used | ||
* as an immutable "set" operator for a that base note | ||
* | ||
* @function | ||
* @param {Object} props - the note properties | ||
* @param {String} baseNote - (Optional) note to build the result from. If given, it returns | ||
* @param {String} [baseNote] - note to build the result from. If given, it returns | ||
* the result of applying the given props to this note. | ||
@@ -316,3 +319,3 @@ * @return {String} the note name in scientific notation or null if not valid properties | ||
* Note.from({ step: 7 }) // => null | ||
* Note.from({alt: 1, oct: 3}, "C4") // => "C3" | ||
* Note.from({alt: 1, oct: 3}, "C4") // => "C#3" | ||
*/ | ||
@@ -364,4 +367,4 @@ var from = function (fromProps, baseNote) { | ||
/** | ||
* Simplify the note: find an enhramonic note with less accidentals. | ||
* | ||
* Simplify the note: find an enhramonic note with less accidentals. | ||
* | ||
* @param {String} note - the note to be simplified | ||
@@ -391,4 +394,4 @@ * @param {boolean} useSameAccType - (optional, true by default) set to true | ||
* Get the simplified and enhramonic note of the given one. | ||
* | ||
* @param {String} note | ||
* | ||
* @param {String} note | ||
* @return {String} the enhramonic note | ||
@@ -395,0 +398,0 @@ * @example |
@@ -19,3 +19,3 @@ /** | ||
* Note.oct("G3") // => 3 | ||
* | ||
* | ||
* // part of tonal | ||
@@ -40,4 +40,4 @@ * const Tonal = require("tonal") | ||
* Get a list of note names (pitch classes) within a octave | ||
* | ||
* @param {string} accTypes - (Optional, by default " b#"). A string with the | ||
* | ||
* @param {string} accTypes - (Optional, by default " b#"). A string with the | ||
* accidentals types: " " means no accidental, "#" means sharps, "b" mean flats, | ||
@@ -62,8 +62,8 @@ * can be conbined (see examples) | ||
/** | ||
* Split a string into tokens related to note parts. | ||
* It returns an array of strings `[letter, accidental, octave, modifier]` | ||
* | ||
* Split a string into tokens related to note parts. | ||
* It returns an array of strings `[letter, accidental, octave, modifier]` | ||
* | ||
* It always returns an array | ||
* | ||
* @param {String} str | ||
* | ||
* @param {String} str | ||
* @return {Array} an array of note tokens | ||
@@ -123,3 +123,3 @@ * @example | ||
* Get note properties. It returns an object with the following information: | ||
* | ||
* | ||
* - name {String}: the note name. The letter is always in uppercase | ||
@@ -135,8 +135,8 @@ * - letter {String}: the note letter, always in uppercase | ||
* - freq {Number}: the frequency using an equal temperament at 440Hz | ||
* | ||
* | ||
* This function *always* returns an object with all this properties, but if it"s | ||
* not a valid note all properties will be null. | ||
* | ||
* | ||
* The returned object can"t be mutated. | ||
* | ||
* | ||
* @param {String} note - the note name in scientific notation | ||
@@ -157,3 +157,3 @@ * @return {Object} an object with the properties (or an object will all properties | ||
* using # or b | ||
* | ||
* | ||
* Can be used to test if a string is a valid note name. | ||
@@ -199,3 +199,3 @@ * | ||
* Get the frequency from midi number | ||
* | ||
* | ||
* @param {Number} midi - the note midi number | ||
@@ -228,3 +228,3 @@ * @param {Number} tuning - (Optional) 440 by default | ||
* contain decimals (with two digits precission) | ||
* | ||
* | ||
* @param {Number} frequency | ||
@@ -270,3 +270,3 @@ * @return {Number} | ||
* Given a step number return it"s letter (0 = C, 1 = D, 2 = E) | ||
* @param {number} step | ||
* @param {number} step | ||
* @return {string} the letter | ||
@@ -283,3 +283,3 @@ * @example | ||
* Given an alteration number, return the accidentals | ||
* @param {Number} alt | ||
* @param {Number} alt | ||
* @return {String} | ||
@@ -292,3 +292,3 @@ * @example | ||
/** | ||
* Creates a note name in scientific notation from note properties, | ||
* Creates a note name in scientific notation from note properties, | ||
* and optionally another note name. | ||
@@ -299,7 +299,10 @@ * It receives an object with: | ||
* - oct: (optional) the octave | ||
* | ||
* Optionally it receives another note as a "base", meaning that any prop not explicitly | ||
* received on the first parameter will be taken from that base note. That way it can be used | ||
* received on the first parameter will be taken from that base note. That way it can be used | ||
* as an immutable "set" operator for a that base note | ||
* | ||
* @function | ||
* @param {Object} props - the note properties | ||
* @param {String} baseNote - (Optional) note to build the result from. If given, it returns | ||
* @param {String} [baseNote] - note to build the result from. If given, it returns | ||
* the result of applying the given props to this note. | ||
@@ -312,3 +315,3 @@ * @return {String} the note name in scientific notation or null if not valid properties | ||
* Note.from({ step: 7 }) // => null | ||
* Note.from({alt: 1, oct: 3}, "C4") // => "C3" | ||
* Note.from({alt: 1, oct: 3}, "C4") // => "C#3" | ||
*/ | ||
@@ -360,4 +363,4 @@ export var from = function (fromProps, baseNote) { | ||
/** | ||
* Simplify the note: find an enhramonic note with less accidentals. | ||
* | ||
* Simplify the note: find an enhramonic note with less accidentals. | ||
* | ||
* @param {String} note - the note to be simplified | ||
@@ -387,4 +390,4 @@ * @param {boolean} useSameAccType - (optional, true by default) set to true | ||
* Get the simplified and enhramonic note of the given one. | ||
* | ||
* @param {String} note | ||
* | ||
* @param {String} note | ||
* @return {String} the enhramonic note | ||
@@ -391,0 +394,0 @@ * @example |
53
index.js
@@ -19,3 +19,3 @@ /** | ||
* Note.oct("G3") // => 3 | ||
* | ||
* | ||
* // part of tonal | ||
@@ -40,4 +40,4 @@ * const Tonal = require("tonal") | ||
* Get a list of note names (pitch classes) within a octave | ||
* | ||
* @param {string} accTypes - (Optional, by default " b#"). A string with the | ||
* | ||
* @param {string} accTypes - (Optional, by default " b#"). A string with the | ||
* accidentals types: " " means no accidental, "#" means sharps, "b" mean flats, | ||
@@ -63,8 +63,8 @@ * can be conbined (see examples) | ||
/** | ||
* Split a string into tokens related to note parts. | ||
* It returns an array of strings `[letter, accidental, octave, modifier]` | ||
* | ||
* Split a string into tokens related to note parts. | ||
* It returns an array of strings `[letter, accidental, octave, modifier]` | ||
* | ||
* It always returns an array | ||
* | ||
* @param {String} str | ||
* | ||
* @param {String} str | ||
* @return {Array} an array of note tokens | ||
@@ -118,3 +118,3 @@ * @example | ||
* Get note properties. It returns an object with the following information: | ||
* | ||
* | ||
* - name {String}: the note name. The letter is always in uppercase | ||
@@ -130,8 +130,8 @@ * - letter {String}: the note letter, always in uppercase | ||
* - freq {Number}: the frequency using an equal temperament at 440Hz | ||
* | ||
* | ||
* This function *always* returns an object with all this properties, but if it"s | ||
* not a valid note all properties will be null. | ||
* | ||
* | ||
* The returned object can"t be mutated. | ||
* | ||
* | ||
* @param {String} note - the note name in scientific notation | ||
@@ -152,3 +152,3 @@ * @return {Object} an object with the properties (or an object will all properties | ||
* using # or b | ||
* | ||
* | ||
* Can be used to test if a string is a valid note name. | ||
@@ -194,3 +194,3 @@ * | ||
* Get the frequency from midi number | ||
* | ||
* | ||
* @param {Number} midi - the note midi number | ||
@@ -220,3 +220,3 @@ * @param {Number} tuning - (Optional) 440 by default | ||
* contain decimals (with two digits precission) | ||
* | ||
* | ||
* @param {Number} frequency | ||
@@ -262,3 +262,3 @@ * @return {Number} | ||
* Given a step number return it"s letter (0 = C, 1 = D, 2 = E) | ||
* @param {number} step | ||
* @param {number} step | ||
* @return {string} the letter | ||
@@ -275,3 +275,3 @@ * @example | ||
* Given an alteration number, return the accidentals | ||
* @param {Number} alt | ||
* @param {Number} alt | ||
* @return {String} | ||
@@ -285,3 +285,3 @@ * @example | ||
/** | ||
* Creates a note name in scientific notation from note properties, | ||
* Creates a note name in scientific notation from note properties, | ||
* and optionally another note name. | ||
@@ -292,7 +292,10 @@ * It receives an object with: | ||
* - oct: (optional) the octave | ||
* | ||
* Optionally it receives another note as a "base", meaning that any prop not explicitly | ||
* received on the first parameter will be taken from that base note. That way it can be used | ||
* received on the first parameter will be taken from that base note. That way it can be used | ||
* as an immutable "set" operator for a that base note | ||
* | ||
* @function | ||
* @param {Object} props - the note properties | ||
* @param {String} baseNote - (Optional) note to build the result from. If given, it returns | ||
* @param {String} [baseNote] - note to build the result from. If given, it returns | ||
* the result of applying the given props to this note. | ||
@@ -305,3 +308,3 @@ * @return {String} the note name in scientific notation or null if not valid properties | ||
* Note.from({ step: 7 }) // => null | ||
* Note.from({alt: 1, oct: 3}, "C4") // => "C3" | ||
* Note.from({alt: 1, oct: 3}, "C4") // => "C#3" | ||
*/ | ||
@@ -347,4 +350,4 @@ export const from = (fromProps = {}, baseNote = null) => { | ||
/** | ||
* Simplify the note: find an enhramonic note with less accidentals. | ||
* | ||
* Simplify the note: find an enhramonic note with less accidentals. | ||
* | ||
* @param {String} note - the note to be simplified | ||
@@ -371,4 +374,4 @@ * @param {boolean} useSameAccType - (optional, true by default) set to true | ||
* Get the simplified and enhramonic note of the given one. | ||
* | ||
* @param {String} note | ||
* | ||
* @param {String} note | ||
* @return {String} the enhramonic note | ||
@@ -375,0 +378,0 @@ * @example |
{ | ||
"name": "tonal-note", | ||
"version": "1.1.0", | ||
"version": "1.1.2", | ||
"repository": "https://github.com/danigb/tonal/packages/note", | ||
@@ -5,0 +5,0 @@ "description": "Parse and manipulate music notes in scientific notation", |
@@ -43,3 +43,2 @@ <a name="module_Note"></a> | ||
* [`.altToAcc`](#module_Note.altToAcc) ⇒ <code>String</code> | ||
* [`.from`](#module_Note.from) ⇒ <code>String</code> | ||
* [`.build`](#module_Note.build) | ||
@@ -54,2 +53,3 @@ * [`.simplify`](#module_Note.simplify) ⇒ <code>String</code> | ||
* [`.oct(note)`](#module_Note.oct) ⇒ <code>Integer</code> | ||
* [`.from(props, [baseNote])`](#module_Note.from) ⇒ <code>String</code> | ||
* [`.fromMidi(midi, useSharps)`](#module_Note.fromMidi) ⇒ <code>string</code> | ||
@@ -66,3 +66,3 @@ | ||
| --- | --- | --- | | ||
| accTypes | <code>string</code> | (Optional, by default " b#"). A string with the accidentals types: " " means no accidental, "#" means sharps, "b" mean flats, can be conbined (see examples) | | ||
| accTypes | <code>string</code> | (Optional, by default " b#"). A string with the accidentals types: " " means no accidental, "#" means sharps, "b" mean flats, can be conbined (see examples) | | ||
@@ -190,31 +190,2 @@ **Example** | ||
``` | ||
<a name="module_Note.from"></a> | ||
## `Note.from` ⇒ <code>String</code> | ||
Creates a note name in scientific notation from note properties, | ||
and optionally another note name. | ||
It receives an object with: | ||
- step: the note step (0 = C, 1 = D, ... 6 = B) | ||
- alt: (optional) the alteration. Negative numbers are flats, positive sharps | ||
- oct: (optional) the octave | ||
Optionally it receives another note as a "base", meaning that any prop not explicitly | ||
received on the first parameter will be taken from that base note. That way it can be used | ||
as an immutable "set" operator for a that base note | ||
**Kind**: static constant of [<code>Note</code>](#module_Note) | ||
**Returns**: <code>String</code> - the note name in scientific notation or null if not valid properties | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| props | <code>Object</code> | the note properties | | ||
| baseNote | <code>String</code> | (Optional) note to build the result from. If given, it returns the result of applying the given props to this note. | | ||
**Example** | ||
```js | ||
Note.from({ step: 5 }) // => "A" | ||
Note.from({ step: 1, acc: -1 }) // => "Db" | ||
Note.from({ step: 2, acc: 2, oct: 2 }) // => "E##2" | ||
Note.from({ step: 7 }) // => null | ||
Note.from({alt: 1, oct: 3}, "C4") // => "C3" | ||
``` | ||
<a name="module_Note.build"></a> | ||
@@ -267,4 +238,4 @@ | ||
## `Note.tokenize(str)` ⇒ <code>Array</code> | ||
Split a string into tokens related to note parts. | ||
It returns an array of strings `[letter, accidental, octave, modifier]` | ||
Split a string into tokens related to note parts. | ||
It returns an array of strings `[letter, accidental, octave, modifier]` | ||
@@ -379,2 +350,32 @@ It always returns an array | ||
``` | ||
<a name="module_Note.from"></a> | ||
## `Note.from(props, [baseNote])` ⇒ <code>String</code> | ||
Creates a note name in scientific notation from note properties, | ||
and optionally another note name. | ||
It receives an object with: | ||
- step: the note step (0 = C, 1 = D, ... 6 = B) | ||
- alt: (optional) the alteration. Negative numbers are flats, positive sharps | ||
- oct: (optional) the octave | ||
Optionally it receives another note as a "base", meaning that any prop not explicitly | ||
received on the first parameter will be taken from that base note. That way it can be used | ||
as an immutable "set" operator for a that base note | ||
**Kind**: static method of [<code>Note</code>](#module_Note) | ||
**Returns**: <code>String</code> - the note name in scientific notation or null if not valid properties | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| props | <code>Object</code> | the note properties | | ||
| [baseNote] | <code>String</code> | note to build the result from. If given, it returns the result of applying the given props to this note. | | ||
**Example** | ||
```js | ||
Note.from({ step: 5 }) // => "A" | ||
Note.from({ step: 1, acc: -1 }) // => "Db" | ||
Note.from({ step: 2, acc: 2, oct: 2 }) // => "E##2" | ||
Note.from({ step: 7 }) // => null | ||
Note.from({alt: 1, oct: 3}, "C4") // => "C#3" | ||
``` | ||
<a name="module_Note.fromMidi"></a> | ||
@@ -381,0 +382,0 @@ |
396
55341
6
1218