tonal-distance
Advanced tools
Comparing version 0.66.0 to 0.69.0
@@ -7,9 +7,24 @@ 'use strict'; | ||
/** | ||
* Functions to calculate distances between notes | ||
* | ||
* @example | ||
* // using node's require | ||
* var distance = require('tonal-distance') | ||
* distance.interval('C4', 'G4') // => '5P' | ||
* | ||
* @example | ||
* // using ES6 import | ||
* import { interval, semitones } from 'tonal-distance' | ||
* semitones('C' ,'D') // => 2 | ||
* | ||
* @module distance | ||
*/ | ||
// substract two pitches | ||
function substr (a, b) { | ||
if (!a || !b || a[1].length !== b[1].length) return null | ||
var f = tonalPitch.fifths(b) - tonalPitch.fifths(a) | ||
var f = tonalPitch.fifths(b) - tonalPitch.fifths(a); | ||
if (tonalPitch.isPC(a)) return tonalPitch.pitch(f, -Math.floor(f * 7 / 12), 1) | ||
var o = tonalPitch.focts(b) - tonalPitch.focts(a) | ||
var d = tonalPitch.height(b) - tonalPitch.height(a) < 0 ? -1 : 1 | ||
var o = tonalPitch.focts(b) - tonalPitch.focts(a); | ||
var d = tonalPitch.height(b) - tonalPitch.height(a) < 0 ? -1 : 1; | ||
return tonalPitch.pitch(d * f, d * o, d) | ||
@@ -39,5 +54,5 @@ } | ||
if (arguments.length === 1) return function (b) { return interval(a, b) } | ||
var pa = tonalPitch.asPitch(a) | ||
var pb = tonalPitch.asPitch(b) | ||
var i = substr(pa, pb) | ||
var pa = tonalPitch.asPitch(a); | ||
var pb = tonalPitch.asPitch(b); | ||
var i = substr(pa, pb); | ||
// if a and b are in array notation, no conversion back | ||
@@ -59,3 +74,3 @@ return a === pa && b === pb ? i : tonalPitch.strIvl(i) | ||
function semitones (a, b) { | ||
var i = substr(tonalPitch.asPitch(a), tonalPitch.asPitch(b)) | ||
var i = substr(tonalPitch.asPitch(a), tonalPitch.asPitch(b)); | ||
return i ? tonalPitch.height(i) : null | ||
@@ -65,2 +80,2 @@ } | ||
exports.interval = interval; | ||
exports.semitones = semitones; | ||
exports.semitones = semitones; |
{ | ||
"name": "tonal-distance", | ||
"version": "0.66.0", | ||
"version": "0.69.0", | ||
"description": "Find distances between musical notes", | ||
@@ -14,3 +14,3 @@ "keywords": [ | ||
"pretest": "rollup -f cjs -o build/index.js -- index.js", | ||
"test": "tape test/*.js" | ||
"test": "jest --coverage" | ||
}, | ||
@@ -23,4 +23,4 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"tonal-pitch": "^0.66.0" | ||
"tonal-pitch": "^0.69.0" | ||
} | ||
} |
9288
177
+ Addedtonal-encoding@0.69.7(transitive)
+ Addedtonal-pitch@0.69.7(transitive)
- Removedtonal-encoding@0.66.0(transitive)
- Removedtonal-pitch@0.66.0(transitive)
Updatedtonal-pitch@^0.69.0