Comparing version 0.60.0 to 0.61.0
@@ -5,4 +5,8 @@ 'use strict'; | ||
var tonalNotation = require('tonal-notation'); | ||
var tonal = require('tonal'); | ||
var tonalTranspose = require('tonal-transpose'); | ||
var tonalNote = require('tonal-note'); | ||
var tonalRange = require('tonal-range'); | ||
var tonalArray = require('tonal-array'); | ||
var isArr = Array.isArray | ||
// Order matters: use an array | ||
@@ -14,3 +18,3 @@ var MODES = ['ionian', 'dorian', 'phrygian', 'lydian', 'mixolydian', | ||
var SCALES = [0, 1, 2, 3, 4, 5, 6, 0, 5].map(function (n) { | ||
return tonal.harmonics(tonal.rotate(n, ['C', 'D', 'E', 'F', 'G', 'A', 'B'])) | ||
return tonalArray.harmonics(tonalArray.rotate(n, ['C', 'D', 'E', 'F', 'G', 'A', 'B'])) | ||
}) | ||
@@ -32,3 +36,3 @@ | ||
if (!k || !hasTonic(k)) return null | ||
return tonal.harmonize(SCALES[MODES.indexOf(k[0])], k[1]) | ||
return tonalArray.harmonize(SCALES[MODES.indexOf(k[0])], k[1]) | ||
} | ||
@@ -54,3 +58,3 @@ | ||
var i = tonalPitch.pitch(modeNum(r) - modeNum(k), 0, 1) | ||
var tonic = tonal.transpose(k[1], i) | ||
var tonic = tonalTranspose.transpose(k[1], i) | ||
return build(tonic, rel) | ||
@@ -71,4 +75,4 @@ } | ||
return alt === null ? null | ||
: alt < 0 ? tonal.range([-1, alt]).map(tonal.trFifths('F')) | ||
: tonal.range([1, alt]).map(tonal.trFifths('B')) | ||
: alt < 0 ? tonalRange.numeric([-1, alt]).map(tonalTranspose.trFifths('F')) | ||
: tonalRange.numeric([1, alt]).map(tonalTranspose.trFifths('B')) | ||
} | ||
@@ -109,14 +113,14 @@ | ||
function build (tonic, mode) { | ||
if (!tonalNotation.isStr(mode)) return null | ||
if (typeof mode !== 'string') return null | ||
var m = mode.trim().toLowerCase() | ||
if (!isKeyMode(m)) return null | ||
if (tonic === false || tonic === null) return [m, false] | ||
var t = tonal.pc(tonic) | ||
var t = tonalNote.pc(tonic) | ||
return t ? [m, t] : null | ||
} | ||
function isKey (o) { return tonalNotation.isArr(o) && isKeyMode(o[0]) } | ||
function isKey (o) { return isArr(o) && isKeyMode(o[0]) } | ||
function hasTonic (o) { return isKey(o) && o[1] } | ||
function majorKey (n) { return build(tonal.trFifths('C', n), 'major') } | ||
function majorKey (n) { return build(tonalTranspose.trFifths('C', n), 'major') } | ||
@@ -133,3 +137,3 @@ /** | ||
function fromAlter (n) { | ||
return tonalNotation.isNum(n) ? majorKey(n) : null | ||
return typeof n === 'number' ? majorKey(n) : null | ||
} | ||
@@ -161,3 +165,3 @@ | ||
function fromName (str) { | ||
if (!tonalNotation.isStr(str)) return null | ||
if (typeof str !== 'string') return null | ||
var p = str.split(/\s+/) | ||
@@ -164,0 +168,0 @@ switch (p.length) { |
25
index.js
/** | ||
* A collection of functions related to music keys. Things like keys signatures, | ||
* scales, modes, etc. | ||
* | ||
* @example | ||
* var key = require('tonal-key') | ||
* key.scale('E mixolydian') // => [ 'E', 'F#', 'G#', 'A', 'B', 'C#', 'D' ] | ||
* key.relative('minor', 'C major') // => ['minor', 'A'] | ||
* @module key | ||
@@ -6,5 +13,9 @@ */ | ||
import { parseNote, pitch, fifths } from 'tonal-pitch' | ||
import { isArr, isStr, isNum, areFlats, areSharps, toAcc } from 'tonal-notation' | ||
import { transpose, trFifths, range, pc, rotate, harmonics, harmonize } from 'tonal' | ||
import { areFlats, areSharps, toAcc } from 'tonal-notation' | ||
import { transpose, trFifths } from 'tonal-transpose' | ||
import { pc } from 'tonal-note' | ||
import { numeric } from 'tonal-range' | ||
import { rotate, harmonics, harmonize } from 'tonal-array' | ||
var isArr = Array.isArray | ||
// Order matters: use an array | ||
@@ -70,4 +81,4 @@ var MODES = ['ionian', 'dorian', 'phrygian', 'lydian', 'mixolydian', | ||
return alt === null ? null | ||
: alt < 0 ? range([-1, alt]).map(trFifths('F')) | ||
: range([1, alt]).map(trFifths('B')) | ||
: alt < 0 ? numeric([-1, alt]).map(trFifths('F')) | ||
: numeric([1, alt]).map(trFifths('B')) | ||
} | ||
@@ -108,3 +119,3 @@ | ||
export function build (tonic, mode) { | ||
if (!isStr(mode)) return null | ||
if (typeof mode !== 'string') return null | ||
var m = mode.trim().toLowerCase() | ||
@@ -132,3 +143,3 @@ if (!isKeyMode(m)) return null | ||
export function fromAlter (n) { | ||
return isNum(n) ? majorKey(n) : null | ||
return typeof n === 'number' ? majorKey(n) : null | ||
} | ||
@@ -160,3 +171,3 @@ | ||
export function fromName (str) { | ||
if (!isStr(str)) return null | ||
if (typeof str !== 'string') return null | ||
var p = str.split(/\s+/) | ||
@@ -163,0 +174,0 @@ switch (p.length) { |
{ | ||
"name": "tonal-key", | ||
"version": "0.60.0", | ||
"version": "0.61.0", | ||
"description": "Conversion between key numbers and note names", | ||
@@ -11,4 +11,4 @@ "keywords": [ | ||
"scripts": { | ||
"pretest": "rm -rf build && mkdir build && rollup -f cjs -n key -o build/tonal-key.js -- index.js", | ||
"prepublish": "npm test" | ||
"pretest": "rollup -f cjs -o build/index.js -- index.js", | ||
"test": "tape test/*.js" | ||
}, | ||
@@ -21,6 +21,9 @@ "main": "build/index.js", | ||
"dependencies": { | ||
"tonal": "^0.60.0", | ||
"tonal-notation": "^0.50.0", | ||
"tonal-pitch": "^0.60.0" | ||
"tonal-notation": "^0.61.0", | ||
"tonal-transpose": "^0.61.0", | ||
"tonal-note": "^0.61.0", | ||
"tonal-array": "^0.61.0", | ||
"tonal-range": "^0.61.0", | ||
"tonal-pitch": "^0.61.0" | ||
} | ||
} |
31244
6
705
6
+ Addedtonal-array@^0.61.0
+ Addedtonal-note@^0.61.0
+ Addedtonal-range@^0.61.0
+ Addedtonal-transpose@^0.61.0
+ Addedtonal-array@0.61.0(transitive)
+ Addedtonal-distance@0.61.0(transitive)
+ Addedtonal-filter@0.61.0(transitive)
+ Addedtonal-midi@0.61.0(transitive)
+ Addedtonal-notation@0.61.0(transitive)
+ Addedtonal-note@0.61.0(transitive)
+ Addedtonal-pitch@0.61.0(transitive)
+ Addedtonal-range@0.61.0(transitive)
+ Addedtonal-transpose@0.61.0(transitive)
- Removedtonal@^0.60.0
- Removednote-parser@1.1.0(transitive)
- Removedtonal@0.60.0(transitive)
- Removedtonal-array@0.60.0(transitive)
- Removedtonal-dictionary@0.60.0(transitive)
- Removedtonal-distance@0.60.0(transitive)
- Removedtonal-encoding@0.50.1(transitive)
- Removedtonal-filter@0.60.0(transitive)
- Removedtonal-freq@0.60.0(transitive)
- Removedtonal-interval@0.60.0(transitive)
- Removedtonal-midi@0.60.0(transitive)
- Removedtonal-notation@0.50.0(transitive)
- Removedtonal-note@0.60.0(transitive)
- Removedtonal-pitch@0.50.30.60.0(transitive)
- Removedtonal-range@0.60.0(transitive)
- Removedtonal-scale@0.60.0(transitive)
- Removedtonal-transpose@0.60.0(transitive)
Updatedtonal-notation@^0.61.0
Updatedtonal-pitch@^0.61.0