tonal-interval
Advanced tools
Comparing version 1.0.0-pre6 to 1.0.0
@@ -13,7 +13,7 @@ 'use strict'; | ||
* | ||
* - standard shorthand notation: type and number, for example: 'M3', 'd-4' | ||
* - inverse shorthand notation: number and then type, for example: '3M', '-4d' | ||
* - standard shorthand notation: type and number, for example: "M3", "d-4" | ||
* - inverse shorthand notation: number and then type, for example: "3M", "-4d" | ||
* | ||
* The problem with the standard shorthand notation is that some strings can be | ||
* parsed as notes or intervals, for example: 'A4' can be note A in 4th octave | ||
* parsed as notes or intervals, for example: "A4" can be note A in 4th octave | ||
* or an augmented four. To remove ambiguity, the prefered notation in tonal is the | ||
@@ -27,7 +27,12 @@ * inverse shortand notation. | ||
* ```js | ||
* import * as interval from 'tonal-interval' | ||
* // or const interval = require('tonal-interval') | ||
* interval.semitones('4P') // => 5 | ||
* interval.invert('3m') // => '6M' | ||
* interval.simplify('9m') // => '2m' | ||
* // es6 | ||
* import * as Interval from "tonal-interval" | ||
* // es5 | ||
* const Interval = require("tonal-interval") | ||
* // part of tonal | ||
* import { Interval } from "tonal" | ||
* | ||
* Interval.semitones("4P") // => 5 | ||
* Interval.invert("3m") // => "6M" | ||
* Interval.simplify("9m") // => "2m" | ||
* ``` | ||
@@ -41,3 +46,3 @@ * | ||
* | ||
* @module interval | ||
* @module Interval | ||
*/ | ||
@@ -59,7 +64,7 @@ // shorthand tonal notation (with quality after number) | ||
* @example | ||
* tonal.interval.names() // => [ '1P', '2m', '2M', '3m', '3M', '4P', '5P', '6m', '6M', '7m', '7M', '8P' ] | ||
* tonal.interval.names("P") // => [ '1P', '4P', '5P', '8P' ] | ||
* tonal.interval.names("PM") // => [ '1P', '2M', '3M', '4P', '5P', '6M', '7M', '8P' ] | ||
* tonal.interval.names("Pm") // => [ '1P', '2m', '3m', '4P', '5P', '6m', '7m', '8P' ] | ||
* t.interval.names("d") // => [] | ||
* Interval.names() // => [ "1P", "2m", "2M", "3m", "3M", "4P", "5P", "6m", "6M", "7m", "7M", "8P" ] | ||
* Interval.names("P") // => [ "1P", "4P", "5P", "8P" ] | ||
* Interval.names("PM") // => [ "1P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ] | ||
* Interval.names("Pm") // => [ "1P", "2m", "3m", "4P", "5P", "6m", "7m", "8P" ] | ||
* Interval.names("d") // => [] | ||
*/ | ||
@@ -85,4 +90,3 @@ var names = function (types) { return typeof types !== "string" | ||
semitones: null, | ||
chroma: null, | ||
ic: null | ||
chroma: null | ||
}); | ||
@@ -126,3 +130,2 @@ | ||
p.chroma = ((p.dir * (SIZES[p.step] + p.alt)) % 12 + 12) % 12; | ||
p.ic = CLASSES[p.chroma]; | ||
return Object.freeze(p); | ||
@@ -163,5 +166,5 @@ }; | ||
* @example | ||
* interval.num('m2') // => 2 | ||
* interval.num('P9') // => 9 | ||
* interval.num('P-4') // => -4 | ||
* Interval.num("m2") // => 2 | ||
* Interval.num("P9") // => 9 | ||
* Interval.num("P-4") // => -4 | ||
*/ | ||
@@ -171,3 +174,3 @@ var num = function (str) { return props(str).num; }; | ||
/** | ||
* Get interval name. Can be used to test if it's an interval. It accepts intervals | ||
* Get interval name. Can be used to test if it"s an interval. It accepts intervals | ||
* as pitch or string in shorthand notation or tonal notation. It returns always | ||
@@ -180,4 +183,4 @@ * intervals in tonal notation. | ||
* @example | ||
* interval.name('m-3') // => '-3m' | ||
* interval.name('3') // => null | ||
* Interval.name("m-3") // => "-3m" | ||
* Interval.name("3") // => null | ||
*/ | ||
@@ -193,6 +196,6 @@ var name = function (str) { return props(str).name; }; | ||
* @example | ||
* import { semitones } from 'tonal-interval' | ||
* semitones('P4') // => 5 | ||
* import { semitones } from "tonal-interval" | ||
* semitones("P4") // => 5 | ||
* // or using tonal | ||
* tonal.interval.semitones('P5') // => 7 | ||
* Tonal.Interval.semitones("P5") // => 7 | ||
*/ | ||
@@ -218,5 +221,2 @@ var semitones = function (str) { return props(str).semitones; }; | ||
* | ||
* As paramter you can pass an interval in shorthand notation, an interval in | ||
* array notation or the number of semitones of the interval | ||
* | ||
* @function | ||
@@ -227,7 +227,11 @@ * @param {String|Integer} interval - the interval or the number of semitones | ||
* @example | ||
* interval.ic('P8') // => 0 | ||
* interval.ic('m6') // => 4 | ||
* ['P1', 'M2', 'M3', 'P4', 'P5', 'M6', 'M7'].map(ic) // => [0, 2, 4, 5, 5, 3, 1] | ||
* Interval.ic("P8") // => 0 | ||
* Interval.ic("m6") // => 4 | ||
* Interval.ic(10) // => 2 | ||
* ["P1", "M2", "M3", "P4", "P5", "M6", "M7"].map(ic) // => [0, 2, 4, 5, 5, 3, 1] | ||
*/ | ||
var ic = function (str) { return props(str).ic; }; | ||
var ic = function (ivl) { | ||
if (typeof ivl === "string") { ivl = props(ivl).chroma; } | ||
return typeof ivl === "number" ? CLASSES[ivl % 12] : null; | ||
}; | ||
@@ -250,4 +254,4 @@ /** | ||
* @example | ||
* interval.build({ step: 1, alt: -1, oct: 0, dir: 1 }) // => "1d" | ||
* interval.build({ num: 9, alt: -1 }) // => '9m' | ||
* Interval.build({ step: 1, alt: -1, oct: 0, dir: 1 }) // => "1d" | ||
* Interval.build({ num: 9, alt: -1 }) // => "9m" | ||
*/ | ||
@@ -278,7 +282,7 @@ var build = function (ref) { | ||
* @example | ||
* interval.simplify('9M') // => '2M' | ||
* ['8P', '9M', '10M', '11P', '12P', '13M', '14M', '15P'].map(interval.simplify) | ||
* // => [ '8P', '2M', '3M', '4P', '5P', '6M', '7M', '8P' ] | ||
* interval.simplify('2M') // => '2M' | ||
* interval.simplify('-2M') // => '7m' | ||
* Interval.simplify("9M") // => "2M" | ||
* ["8P", "9M", "10M", "11P", "12P", "13M", "14M", "15P"].map(Interval.simplify) | ||
* // => [ "8P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ] | ||
* Interval.simplify("2M") // => "2M" | ||
* Interval.simplify("-2M") // => "7m" | ||
*/ | ||
@@ -301,4 +305,4 @@ var simplify = function (str) { | ||
* @example | ||
* interval.invert('3m') // => '6M' | ||
* interval.invert('2M') // => '7m' | ||
* Interval.invert("3m") // => "6M" | ||
* Interval.invert("2M") // => "7m" | ||
*/ | ||
@@ -320,3 +324,3 @@ var invert = function (str) { | ||
* Get interval name from semitones number. Since there are several interval | ||
* names for the same number, the name it's arbitraty, but deterministic. | ||
* names for the same number, the name it"s arbitraty, but deterministic. | ||
* | ||
@@ -327,6 +331,6 @@ * @function | ||
* @example | ||
* import { fromSemitones } from 'tonal-interval' | ||
* fromSemitones(7) // => '5P' | ||
* import { fromSemitones } from "tonal-interval" | ||
* fromSemitones(7) // => "5P" | ||
* // or using tonal | ||
* tonal.fromSemitones(-7) // => '-5P' | ||
* Tonal.Distance.fromSemitones(-7) // => "-5P" | ||
*/ | ||
@@ -333,0 +337,0 @@ var fromSemitones = function (num) { |
@@ -9,7 +9,7 @@ /** | ||
* | ||
* - standard shorthand notation: type and number, for example: 'M3', 'd-4' | ||
* - inverse shorthand notation: number and then type, for example: '3M', '-4d' | ||
* - standard shorthand notation: type and number, for example: "M3", "d-4" | ||
* - inverse shorthand notation: number and then type, for example: "3M", "-4d" | ||
* | ||
* The problem with the standard shorthand notation is that some strings can be | ||
* parsed as notes or intervals, for example: 'A4' can be note A in 4th octave | ||
* parsed as notes or intervals, for example: "A4" can be note A in 4th octave | ||
* or an augmented four. To remove ambiguity, the prefered notation in tonal is the | ||
@@ -23,7 +23,12 @@ * inverse shortand notation. | ||
* ```js | ||
* import * as interval from 'tonal-interval' | ||
* // or const interval = require('tonal-interval') | ||
* interval.semitones('4P') // => 5 | ||
* interval.invert('3m') // => '6M' | ||
* interval.simplify('9m') // => '2m' | ||
* // es6 | ||
* import * as Interval from "tonal-interval" | ||
* // es5 | ||
* const Interval = require("tonal-interval") | ||
* // part of tonal | ||
* import { Interval } from "tonal" | ||
* | ||
* Interval.semitones("4P") // => 5 | ||
* Interval.invert("3m") // => "6M" | ||
* Interval.simplify("9m") // => "2m" | ||
* ``` | ||
@@ -37,3 +42,3 @@ * | ||
* | ||
* @module interval | ||
* @module Interval | ||
*/ | ||
@@ -55,7 +60,7 @@ // shorthand tonal notation (with quality after number) | ||
* @example | ||
* tonal.interval.names() // => [ '1P', '2m', '2M', '3m', '3M', '4P', '5P', '6m', '6M', '7m', '7M', '8P' ] | ||
* tonal.interval.names("P") // => [ '1P', '4P', '5P', '8P' ] | ||
* tonal.interval.names("PM") // => [ '1P', '2M', '3M', '4P', '5P', '6M', '7M', '8P' ] | ||
* tonal.interval.names("Pm") // => [ '1P', '2m', '3m', '4P', '5P', '6m', '7m', '8P' ] | ||
* t.interval.names("d") // => [] | ||
* Interval.names() // => [ "1P", "2m", "2M", "3m", "3M", "4P", "5P", "6m", "6M", "7m", "7M", "8P" ] | ||
* Interval.names("P") // => [ "1P", "4P", "5P", "8P" ] | ||
* Interval.names("PM") // => [ "1P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ] | ||
* Interval.names("Pm") // => [ "1P", "2m", "3m", "4P", "5P", "6m", "7m", "8P" ] | ||
* Interval.names("d") // => [] | ||
*/ | ||
@@ -81,4 +86,3 @@ export var names = function (types) { return typeof types !== "string" | ||
semitones: null, | ||
chroma: null, | ||
ic: null | ||
chroma: null | ||
}); | ||
@@ -122,3 +126,2 @@ | ||
p.chroma = ((p.dir * (SIZES[p.step] + p.alt)) % 12 + 12) % 12; | ||
p.ic = CLASSES[p.chroma]; | ||
return Object.freeze(p); | ||
@@ -159,5 +162,5 @@ }; | ||
* @example | ||
* interval.num('m2') // => 2 | ||
* interval.num('P9') // => 9 | ||
* interval.num('P-4') // => -4 | ||
* Interval.num("m2") // => 2 | ||
* Interval.num("P9") // => 9 | ||
* Interval.num("P-4") // => -4 | ||
*/ | ||
@@ -167,3 +170,3 @@ export var num = function (str) { return props(str).num; }; | ||
/** | ||
* Get interval name. Can be used to test if it's an interval. It accepts intervals | ||
* Get interval name. Can be used to test if it"s an interval. It accepts intervals | ||
* as pitch or string in shorthand notation or tonal notation. It returns always | ||
@@ -176,4 +179,4 @@ * intervals in tonal notation. | ||
* @example | ||
* interval.name('m-3') // => '-3m' | ||
* interval.name('3') // => null | ||
* Interval.name("m-3") // => "-3m" | ||
* Interval.name("3") // => null | ||
*/ | ||
@@ -189,6 +192,6 @@ export var name = function (str) { return props(str).name; }; | ||
* @example | ||
* import { semitones } from 'tonal-interval' | ||
* semitones('P4') // => 5 | ||
* import { semitones } from "tonal-interval" | ||
* semitones("P4") // => 5 | ||
* // or using tonal | ||
* tonal.interval.semitones('P5') // => 7 | ||
* Tonal.Interval.semitones("P5") // => 7 | ||
*/ | ||
@@ -214,5 +217,2 @@ export var semitones = function (str) { return props(str).semitones; }; | ||
* | ||
* As paramter you can pass an interval in shorthand notation, an interval in | ||
* array notation or the number of semitones of the interval | ||
* | ||
* @function | ||
@@ -223,7 +223,11 @@ * @param {String|Integer} interval - the interval or the number of semitones | ||
* @example | ||
* interval.ic('P8') // => 0 | ||
* interval.ic('m6') // => 4 | ||
* ['P1', 'M2', 'M3', 'P4', 'P5', 'M6', 'M7'].map(ic) // => [0, 2, 4, 5, 5, 3, 1] | ||
* Interval.ic("P8") // => 0 | ||
* Interval.ic("m6") // => 4 | ||
* Interval.ic(10) // => 2 | ||
* ["P1", "M2", "M3", "P4", "P5", "M6", "M7"].map(ic) // => [0, 2, 4, 5, 5, 3, 1] | ||
*/ | ||
export var ic = function (str) { return props(str).ic; }; | ||
export var ic = function (ivl) { | ||
if (typeof ivl === "string") { ivl = props(ivl).chroma; } | ||
return typeof ivl === "number" ? CLASSES[ivl % 12] : null; | ||
}; | ||
@@ -246,4 +250,4 @@ /** | ||
* @example | ||
* interval.build({ step: 1, alt: -1, oct: 0, dir: 1 }) // => "1d" | ||
* interval.build({ num: 9, alt: -1 }) // => '9m' | ||
* Interval.build({ step: 1, alt: -1, oct: 0, dir: 1 }) // => "1d" | ||
* Interval.build({ num: 9, alt: -1 }) // => "9m" | ||
*/ | ||
@@ -274,7 +278,7 @@ export var build = function (ref) { | ||
* @example | ||
* interval.simplify('9M') // => '2M' | ||
* ['8P', '9M', '10M', '11P', '12P', '13M', '14M', '15P'].map(interval.simplify) | ||
* // => [ '8P', '2M', '3M', '4P', '5P', '6M', '7M', '8P' ] | ||
* interval.simplify('2M') // => '2M' | ||
* interval.simplify('-2M') // => '7m' | ||
* Interval.simplify("9M") // => "2M" | ||
* ["8P", "9M", "10M", "11P", "12P", "13M", "14M", "15P"].map(Interval.simplify) | ||
* // => [ "8P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ] | ||
* Interval.simplify("2M") // => "2M" | ||
* Interval.simplify("-2M") // => "7m" | ||
*/ | ||
@@ -297,4 +301,4 @@ export var simplify = function (str) { | ||
* @example | ||
* interval.invert('3m') // => '6M' | ||
* interval.invert('2M') // => '7m' | ||
* Interval.invert("3m") // => "6M" | ||
* Interval.invert("2M") // => "7m" | ||
*/ | ||
@@ -316,3 +320,3 @@ export var invert = function (str) { | ||
* Get interval name from semitones number. Since there are several interval | ||
* names for the same number, the name it's arbitraty, but deterministic. | ||
* names for the same number, the name it"s arbitraty, but deterministic. | ||
* | ||
@@ -323,6 +327,6 @@ * @function | ||
* @example | ||
* import { fromSemitones } from 'tonal-interval' | ||
* fromSemitones(7) // => '5P' | ||
* import { fromSemitones } from "tonal-interval" | ||
* fromSemitones(7) // => "5P" | ||
* // or using tonal | ||
* tonal.fromSemitones(-7) // => '-5P' | ||
* Tonal.Distance.fromSemitones(-7) // => "-5P" | ||
*/ | ||
@@ -329,0 +333,0 @@ export var fromSemitones = function (num) { |
96
index.js
@@ -9,7 +9,7 @@ /** | ||
* | ||
* - standard shorthand notation: type and number, for example: 'M3', 'd-4' | ||
* - inverse shorthand notation: number and then type, for example: '3M', '-4d' | ||
* - standard shorthand notation: type and number, for example: "M3", "d-4" | ||
* - inverse shorthand notation: number and then type, for example: "3M", "-4d" | ||
* | ||
* The problem with the standard shorthand notation is that some strings can be | ||
* parsed as notes or intervals, for example: 'A4' can be note A in 4th octave | ||
* parsed as notes or intervals, for example: "A4" can be note A in 4th octave | ||
* or an augmented four. To remove ambiguity, the prefered notation in tonal is the | ||
@@ -23,7 +23,12 @@ * inverse shortand notation. | ||
* ```js | ||
* import * as interval from 'tonal-interval' | ||
* // or const interval = require('tonal-interval') | ||
* interval.semitones('4P') // => 5 | ||
* interval.invert('3m') // => '6M' | ||
* interval.simplify('9m') // => '2m' | ||
* // es6 | ||
* import * as Interval from "tonal-interval" | ||
* // es5 | ||
* const Interval = require("tonal-interval") | ||
* // part of tonal | ||
* import { Interval } from "tonal" | ||
* | ||
* Interval.semitones("4P") // => 5 | ||
* Interval.invert("3m") // => "6M" | ||
* Interval.simplify("9m") // => "2m" | ||
* ``` | ||
@@ -37,3 +42,3 @@ * | ||
* | ||
* @module interval | ||
* @module Interval | ||
*/ | ||
@@ -55,7 +60,7 @@ // shorthand tonal notation (with quality after number) | ||
* @example | ||
* tonal.interval.names() // => [ '1P', '2m', '2M', '3m', '3M', '4P', '5P', '6m', '6M', '7m', '7M', '8P' ] | ||
* tonal.interval.names("P") // => [ '1P', '4P', '5P', '8P' ] | ||
* tonal.interval.names("PM") // => [ '1P', '2M', '3M', '4P', '5P', '6M', '7M', '8P' ] | ||
* tonal.interval.names("Pm") // => [ '1P', '2m', '3m', '4P', '5P', '6m', '7m', '8P' ] | ||
* t.interval.names("d") // => [] | ||
* Interval.names() // => [ "1P", "2m", "2M", "3m", "3M", "4P", "5P", "6m", "6M", "7m", "7M", "8P" ] | ||
* Interval.names("P") // => [ "1P", "4P", "5P", "8P" ] | ||
* Interval.names("PM") // => [ "1P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ] | ||
* Interval.names("Pm") // => [ "1P", "2m", "3m", "4P", "5P", "6m", "7m", "8P" ] | ||
* Interval.names("d") // => [] | ||
*/ | ||
@@ -82,4 +87,3 @@ export const names = types => | ||
semitones: null, | ||
chroma: null, | ||
ic: null | ||
chroma: null | ||
}); | ||
@@ -123,3 +127,2 @@ | ||
p.chroma = ((p.dir * (SIZES[p.step] + p.alt)) % 12 + 12) % 12; | ||
p.ic = CLASSES[p.chroma]; | ||
return Object.freeze(p); | ||
@@ -160,5 +163,5 @@ }; | ||
* @example | ||
* interval.num('m2') // => 2 | ||
* interval.num('P9') // => 9 | ||
* interval.num('P-4') // => -4 | ||
* Interval.num("m2") // => 2 | ||
* Interval.num("P9") // => 9 | ||
* Interval.num("P-4") // => -4 | ||
*/ | ||
@@ -168,3 +171,3 @@ export const num = str => props(str).num; | ||
/** | ||
* Get interval name. Can be used to test if it's an interval. It accepts intervals | ||
* Get interval name. Can be used to test if it"s an interval. It accepts intervals | ||
* as pitch or string in shorthand notation or tonal notation. It returns always | ||
@@ -177,4 +180,4 @@ * intervals in tonal notation. | ||
* @example | ||
* interval.name('m-3') // => '-3m' | ||
* interval.name('3') // => null | ||
* Interval.name("m-3") // => "-3m" | ||
* Interval.name("3") // => null | ||
*/ | ||
@@ -190,6 +193,6 @@ export const name = str => props(str).name; | ||
* @example | ||
* import { semitones } from 'tonal-interval' | ||
* semitones('P4') // => 5 | ||
* import { semitones } from "tonal-interval" | ||
* semitones("P4") // => 5 | ||
* // or using tonal | ||
* tonal.interval.semitones('P5') // => 7 | ||
* Tonal.Interval.semitones("P5") // => 7 | ||
*/ | ||
@@ -215,5 +218,2 @@ export const semitones = str => props(str).semitones; | ||
* | ||
* As paramter you can pass an interval in shorthand notation, an interval in | ||
* array notation or the number of semitones of the interval | ||
* | ||
* @function | ||
@@ -224,7 +224,11 @@ * @param {String|Integer} interval - the interval or the number of semitones | ||
* @example | ||
* interval.ic('P8') // => 0 | ||
* interval.ic('m6') // => 4 | ||
* ['P1', 'M2', 'M3', 'P4', 'P5', 'M6', 'M7'].map(ic) // => [0, 2, 4, 5, 5, 3, 1] | ||
* Interval.ic("P8") // => 0 | ||
* Interval.ic("m6") // => 4 | ||
* Interval.ic(10) // => 2 | ||
* ["P1", "M2", "M3", "P4", "P5", "M6", "M7"].map(ic) // => [0, 2, 4, 5, 5, 3, 1] | ||
*/ | ||
export const ic = str => props(str).ic; | ||
export const ic = ivl => { | ||
if (typeof ivl === "string") ivl = props(ivl).chroma; | ||
return typeof ivl === "number" ? CLASSES[ivl % 12] : null; | ||
}; | ||
@@ -247,4 +251,4 @@ /** | ||
* @example | ||
* interval.build({ step: 1, alt: -1, oct: 0, dir: 1 }) // => "1d" | ||
* interval.build({ num: 9, alt: -1 }) // => '9m' | ||
* Interval.build({ step: 1, alt: -1, oct: 0, dir: 1 }) // => "1d" | ||
* Interval.build({ num: 9, alt: -1 }) // => "9m" | ||
*/ | ||
@@ -268,7 +272,7 @@ export const build = ({ num, step, alt, oct = 1, dir } = {}) => { | ||
* @example | ||
* interval.simplify('9M') // => '2M' | ||
* ['8P', '9M', '10M', '11P', '12P', '13M', '14M', '15P'].map(interval.simplify) | ||
* // => [ '8P', '2M', '3M', '4P', '5P', '6M', '7M', '8P' ] | ||
* interval.simplify('2M') // => '2M' | ||
* interval.simplify('-2M') // => '7m' | ||
* Interval.simplify("9M") // => "2M" | ||
* ["8P", "9M", "10M", "11P", "12P", "13M", "14M", "15P"].map(Interval.simplify) | ||
* // => [ "8P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ] | ||
* Interval.simplify("2M") // => "2M" | ||
* Interval.simplify("-2M") // => "7m" | ||
*/ | ||
@@ -291,4 +295,4 @@ export const simplify = str => { | ||
* @example | ||
* interval.invert('3m') // => '6M' | ||
* interval.invert('2M') // => '7m' | ||
* Interval.invert("3m") // => "6M" | ||
* Interval.invert("2M") // => "7m" | ||
*/ | ||
@@ -310,3 +314,3 @@ export const invert = str => { | ||
* Get interval name from semitones number. Since there are several interval | ||
* names for the same number, the name it's arbitraty, but deterministic. | ||
* names for the same number, the name it"s arbitraty, but deterministic. | ||
* | ||
@@ -317,6 +321,6 @@ * @function | ||
* @example | ||
* import { fromSemitones } from 'tonal-interval' | ||
* fromSemitones(7) // => '5P' | ||
* import { fromSemitones } from "tonal-interval" | ||
* fromSemitones(7) // => "5P" | ||
* // or using tonal | ||
* tonal.fromSemitones(-7) // => '-5P' | ||
* Tonal.Distance.fromSemitones(-7) // => "-5P" | ||
*/ | ||
@@ -323,0 +327,0 @@ export const fromSemitones = num => { |
{ | ||
"name": "tonal-interval", | ||
"version": "1.0.0-pre6", | ||
"version": "1.0.0", | ||
"description": "Music interval creation and manipulation", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/danigb/tonal/packages/interval", |
179
README.md
@@ -1,4 +0,4 @@ | ||
<a name="module_interval"></a> | ||
<a name="module_Interval"></a> | ||
# interval | ||
# Interval | ||
[![npm version](https://img.shields.io/npm/v/tonal-interval.svg)](https://www.npmjs.com/package/tonal-interval) | ||
@@ -11,7 +11,7 @@ [![tonal](https://img.shields.io/badge/tonal-interval-yellow.svg)](https://www.npmjs.com/browse/keyword/tonal) | ||
- standard shorthand notation: type and number, for example: 'M3', 'd-4' | ||
- inverse shorthand notation: number and then type, for example: '3M', '-4d' | ||
- standard shorthand notation: type and number, for example: "M3", "d-4" | ||
- inverse shorthand notation: number and then type, for example: "3M", "-4d" | ||
The problem with the standard shorthand notation is that some strings can be | ||
parsed as notes or intervals, for example: 'A4' can be note A in 4th octave | ||
parsed as notes or intervals, for example: "A4" can be note A in 4th octave | ||
or an augmented four. To remove ambiguity, the prefered notation in tonal is the | ||
@@ -25,7 +25,12 @@ inverse shortand notation. | ||
```js | ||
import * as interval from 'tonal-interval' | ||
// or const interval = require('tonal-interval') | ||
interval.semitones('4P') // => 5 | ||
interval.invert('3m') // => '6M' | ||
interval.simplify('9m') // => '2m' | ||
// es6 | ||
import * as Interval from "tonal-interval" | ||
// es5 | ||
const Interval = require("tonal-interval") | ||
// part of tonal | ||
import { Interval } from "tonal" | ||
Interval.semitones("4P") // => 5 | ||
Interval.invert("3m") // => "6M" | ||
Interval.simplify("9m") // => "2m" | ||
``` | ||
@@ -40,21 +45,21 @@ | ||
* [interval](#module_interval) | ||
* [`.names`](#module_interval.names) ⇒ <code>Array</code> | ||
* [`.props(interval)`](#module_interval.props) ⇒ <code>Object</code> | ||
* [`.num(interval)`](#module_interval.num) ⇒ <code>Integer</code> | ||
* [`.name(interval)`](#module_interval.name) ⇒ <code>String</code> | ||
* [`.semitones(ivl)`](#module_interval.semitones) ⇒ <code>Integer</code> | ||
* [`.chroma(str)`](#module_interval.chroma) ⇒ <code>Number</code> | ||
* [`.ic(interval)`](#module_interval.ic) ⇒ <code>Integer</code> | ||
* [`.build(props)`](#module_interval.build) ⇒ <code>String</code> | ||
* [`.simplify(interval)`](#module_interval.simplify) ⇒ <code>String</code> | ||
* [`.invert(interval)`](#module_interval.invert) ⇒ <code>String</code> | ||
* [`.fromSemitones(num)`](#module_interval.fromSemitones) ⇒ <code>String</code> | ||
* [Interval](#module_Interval) | ||
* [`.names`](#module_Interval.names) ⇒ <code>Array</code> | ||
* [`.props(interval)`](#module_Interval.props) ⇒ <code>Object</code> | ||
* [`.num(interval)`](#module_Interval.num) ⇒ <code>Integer</code> | ||
* [`.name(interval)`](#module_Interval.name) ⇒ <code>String</code> | ||
* [`.semitones(ivl)`](#module_Interval.semitones) ⇒ <code>Integer</code> | ||
* [`.chroma(str)`](#module_Interval.chroma) ⇒ <code>Number</code> | ||
* [`.ic(interval)`](#module_Interval.ic) ⇒ <code>Integer</code> | ||
* [`.build(props)`](#module_Interval.build) ⇒ <code>String</code> | ||
* [`.simplify(interval)`](#module_Interval.simplify) ⇒ <code>String</code> | ||
* [`.invert(interval)`](#module_Interval.invert) ⇒ <code>String</code> | ||
* [`.fromSemitones(num)`](#module_Interval.fromSemitones) ⇒ <code>String</code> | ||
<a name="module_interval.names"></a> | ||
<a name="module_Interval.names"></a> | ||
## `interval.names` ⇒ <code>Array</code> | ||
## `Interval.names` ⇒ <code>Array</code> | ||
List basic (perfect, major, minor) interval names within a octave | ||
**Kind**: static constant of [<code>interval</code>](#module_interval) | ||
**Kind**: static constant of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>Array</code> - the interval names | ||
@@ -68,11 +73,11 @@ | ||
```js | ||
tonal.interval.names() // => [ '1P', '2m', '2M', '3m', '3M', '4P', '5P', '6m', '6M', '7m', '7M', '8P' ] | ||
tonal.interval.names("P") // => [ '1P', '4P', '5P', '8P' ] | ||
tonal.interval.names("PM") // => [ '1P', '2M', '3M', '4P', '5P', '6M', '7M', '8P' ] | ||
tonal.interval.names("Pm") // => [ '1P', '2m', '3m', '4P', '5P', '6m', '7m', '8P' ] | ||
t.interval.names("d") // => [] | ||
Interval.names() // => [ "1P", "2m", "2M", "3m", "3M", "4P", "5P", "6m", "6M", "7m", "7M", "8P" ] | ||
Interval.names("P") // => [ "1P", "4P", "5P", "8P" ] | ||
Interval.names("PM") // => [ "1P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ] | ||
Interval.names("Pm") // => [ "1P", "2m", "3m", "4P", "5P", "6m", "7m", "8P" ] | ||
Interval.names("d") // => [] | ||
``` | ||
<a name="module_interval.props"></a> | ||
<a name="module_Interval.props"></a> | ||
## `interval.props(interval)` ⇒ <code>Object</code> | ||
## `Interval.props(interval)` ⇒ <code>Object</code> | ||
Get interval properties. It returns an object with: | ||
@@ -92,3 +97,3 @@ | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>Object</code> - the interval in the form [number, alt] | ||
@@ -100,8 +105,8 @@ | ||
<a name="module_interval.num"></a> | ||
<a name="module_Interval.num"></a> | ||
## `interval.num(interval)` ⇒ <code>Integer</code> | ||
## `Interval.num(interval)` ⇒ <code>Integer</code> | ||
Get the number of the interval | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
@@ -114,14 +119,14 @@ | Param | Type | Description | | ||
```js | ||
interval.num('m2') // => 2 | ||
interval.num('P9') // => 9 | ||
interval.num('P-4') // => -4 | ||
Interval.num("m2") // => 2 | ||
Interval.num("P9") // => 9 | ||
Interval.num("P-4") // => -4 | ||
``` | ||
<a name="module_interval.name"></a> | ||
<a name="module_Interval.name"></a> | ||
## `interval.name(interval)` ⇒ <code>String</code> | ||
Get interval name. Can be used to test if it's an interval. It accepts intervals | ||
## `Interval.name(interval)` ⇒ <code>String</code> | ||
Get interval name. Can be used to test if it"s an interval. It accepts intervals | ||
as pitch or string in shorthand notation or tonal notation. It returns always | ||
intervals in tonal notation. | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>String</code> - the interval name or null if not valid interval | ||
@@ -135,11 +140,11 @@ | ||
```js | ||
interval.name('m-3') // => '-3m' | ||
interval.name('3') // => null | ||
Interval.name("m-3") // => "-3m" | ||
Interval.name("3") // => null | ||
``` | ||
<a name="module_interval.semitones"></a> | ||
<a name="module_Interval.semitones"></a> | ||
## `interval.semitones(ivl)` ⇒ <code>Integer</code> | ||
## `Interval.semitones(ivl)` ⇒ <code>Integer</code> | ||
Get size in semitones of an interval | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>Integer</code> - the number of semitones or null if not an interval | ||
@@ -153,14 +158,14 @@ | ||
```js | ||
import { semitones } from 'tonal-interval' | ||
semitones('P4') // => 5 | ||
import { semitones } from "tonal-interval" | ||
semitones("P4") // => 5 | ||
// or using tonal | ||
tonal.interval.semitones('P5') // => 7 | ||
Tonal.Interval.semitones("P5") // => 7 | ||
``` | ||
<a name="module_interval.chroma"></a> | ||
<a name="module_Interval.chroma"></a> | ||
## `interval.chroma(str)` ⇒ <code>Number</code> | ||
## `Interval.chroma(str)` ⇒ <code>Number</code> | ||
Get the chroma of the interval. The chroma is a number between 0 and 7 | ||
that represents the position within an octave (pitch set) | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
@@ -171,5 +176,5 @@ | Param | Type | | ||
<a name="module_interval.ic"></a> | ||
<a name="module_Interval.ic"></a> | ||
## `interval.ic(interval)` ⇒ <code>Integer</code> | ||
## `Interval.ic(interval)` ⇒ <code>Integer</code> | ||
Get the [interval class](https://en.wikipedia.org/wiki/Interval_class) | ||
@@ -181,6 +186,3 @@ number of a given interval. | ||
As paramter you can pass an interval in shorthand notation, an interval in | ||
array notation or the number of semitones of the interval | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>Integer</code> - A value between 0 and 6 | ||
@@ -194,9 +196,10 @@ | ||
```js | ||
interval.ic('P8') // => 0 | ||
interval.ic('m6') // => 4 | ||
['P1', 'M2', 'M3', 'P4', 'P5', 'M6', 'M7'].map(ic) // => [0, 2, 4, 5, 5, 3, 1] | ||
Interval.ic("P8") // => 0 | ||
Interval.ic("m6") // => 4 | ||
Interval.ic(10) // => 2 | ||
["P1", "M2", "M3", "P4", "P5", "M6", "M7"].map(ic) // => [0, 2, 4, 5, 5, 3, 1] | ||
``` | ||
<a name="module_interval.build"></a> | ||
<a name="module_Interval.build"></a> | ||
## `interval.build(props)` ⇒ <code>String</code> | ||
## `Interval.build(props)` ⇒ <code>String</code> | ||
Given a interval property object, get the interval name | ||
@@ -212,3 +215,3 @@ | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>String</code> - the interval name | ||
@@ -222,11 +225,11 @@ | ||
```js | ||
interval.build({ step: 1, alt: -1, oct: 0, dir: 1 }) // => "1d" | ||
interval.build({ num: 9, alt: -1 }) // => '9m' | ||
Interval.build({ step: 1, alt: -1, oct: 0, dir: 1 }) // => "1d" | ||
Interval.build({ num: 9, alt: -1 }) // => "9m" | ||
``` | ||
<a name="module_interval.simplify"></a> | ||
<a name="module_Interval.simplify"></a> | ||
## `interval.simplify(interval)` ⇒ <code>String</code> | ||
## `Interval.simplify(interval)` ⇒ <code>String</code> | ||
Get the simplified version of an interval. | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>String</code> - the simplified interval | ||
@@ -240,15 +243,15 @@ | ||
```js | ||
interval.simplify('9M') // => '2M' | ||
['8P', '9M', '10M', '11P', '12P', '13M', '14M', '15P'].map(interval.simplify) | ||
// => [ '8P', '2M', '3M', '4P', '5P', '6M', '7M', '8P' ] | ||
interval.simplify('2M') // => '2M' | ||
interval.simplify('-2M') // => '7m' | ||
Interval.simplify("9M") // => "2M" | ||
["8P", "9M", "10M", "11P", "12P", "13M", "14M", "15P"].map(Interval.simplify) | ||
// => [ "8P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ] | ||
Interval.simplify("2M") // => "2M" | ||
Interval.simplify("-2M") // => "7m" | ||
``` | ||
<a name="module_interval.invert"></a> | ||
<a name="module_Interval.invert"></a> | ||
## `interval.invert(interval)` ⇒ <code>String</code> | ||
## `Interval.invert(interval)` ⇒ <code>String</code> | ||
Get the inversion (https://en.wikipedia.org/wiki/Inversion_(music)#Intervals) | ||
of an interval. | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>String</code> - the inverted interval | ||
@@ -262,12 +265,12 @@ | ||
```js | ||
interval.invert('3m') // => '6M' | ||
interval.invert('2M') // => '7m' | ||
Interval.invert("3m") // => "6M" | ||
Interval.invert("2M") // => "7m" | ||
``` | ||
<a name="module_interval.fromSemitones"></a> | ||
<a name="module_Interval.fromSemitones"></a> | ||
## `interval.fromSemitones(num)` ⇒ <code>String</code> | ||
## `Interval.fromSemitones(num)` ⇒ <code>String</code> | ||
Get interval name from semitones number. Since there are several interval | ||
names for the same number, the name it's arbitraty, but deterministic. | ||
names for the same number, the name it"s arbitraty, but deterministic. | ||
**Kind**: static method of [<code>interval</code>](#module_interval) | ||
**Kind**: static method of [<code>Interval</code>](#module_Interval) | ||
**Returns**: <code>String</code> - the interval name | ||
@@ -281,6 +284,6 @@ | ||
```js | ||
import { fromSemitones } from 'tonal-interval' | ||
fromSemitones(7) // => '5P' | ||
import { fromSemitones } from "tonal-interval" | ||
fromSemitones(7) // => "5P" | ||
// or using tonal | ||
tonal.fromSemitones(-7) // => '-5P' | ||
Tonal.Distance.fromSemitones(-7) // => "-5P" | ||
``` |
@@ -114,3 +114,3 @@ var ivl = require("../index"); | ||
test("get interval class", () => { | ||
test("interval class", () => { | ||
let result = [0, 2, 4, 5, 5, 3, 1, 0]; | ||
@@ -125,2 +125,6 @@ expect($("1P 2M 3M 4P 5P 6M 7M 8P").map(ivl.ic)).toEqual(result); | ||
expect(ivl.ic("blah")).toBe(null); | ||
const semitones = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; | ||
const ics = [0, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0]; | ||
expect(semitones.map(ivl.ic)).toEqual(ics); | ||
}); | ||
@@ -127,0 +131,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
46857
1062
1
273