tonal-note
Advanced tools
Comparing version 1.0.0-0 to 1.0.0-1
17
index.js
@@ -49,3 +49,4 @@ /** | ||
chroma: null, | ||
midi: null | ||
midi: null, | ||
freq: null | ||
}); | ||
@@ -66,2 +67,3 @@ | ||
p.midi = p.oct !== null ? SEMI[p.step] + p.alt + 12 * (p.oct + 1) : null; | ||
p.freq = midiToFreq(p.midi); | ||
return Object.freeze(p); | ||
@@ -127,4 +129,11 @@ }; | ||
export const midiToFreq = midi => | ||
typeof midi === "number" ? Math.pow(2, (midi - 69) / 12) * 440 : null; | ||
/** | ||
* Get the frequency from midi number | ||
* | ||
* @param {Number} midi - the note midi number | ||
* @param {Number} tuning - (Optional) 440 by default | ||
* @return {Number} the frequency or null if not valid note midi | ||
*/ | ||
export const midiToFreq = (midi, tuning = 440) => | ||
typeof midi === "number" ? Math.pow(2, (midi - 69) / 12) * tuning : null; | ||
@@ -141,3 +150,3 @@ /** | ||
*/ | ||
export const freq = note => midiToFreq(props(note).midi) || midiToFreq(note); | ||
export const freq = note => props(note).freq || midiToFreq(note); | ||
@@ -144,0 +153,0 @@ const L2 = Math.log(2); |
{ | ||
"name": "tonal-note", | ||
"version": "1.0.0-0", | ||
"version": "1.0.0-1", | ||
"repository": "https://github.com/danigb/tonal/packages/note", | ||
@@ -11,3 +11,3 @@ "description": "Encode pitches using fifths/octaves", | ||
}, | ||
"main": "build/index.js", | ||
"main": "build/transpiled.js", | ||
"module": "index", | ||
@@ -14,0 +14,0 @@ "author": "danigb", |
@@ -14,2 +14,17 @@ /* global describe test expect */ | ||
test("props", () => { | ||
expect(note.props("C#3")).toEqual({ | ||
acc: "#", | ||
alt: 1, | ||
chroma: 1, | ||
letter: "C", | ||
name: "C#3", | ||
oct: 3, | ||
pc: "C#", | ||
step: 0, | ||
midi: 49, | ||
freq: 138.59131548843604 | ||
}); | ||
}); | ||
test("isNote", () => { | ||
@@ -57,3 +72,3 @@ expect(note.isNote("c")).toBe(true); | ||
test("toFreq", () => { | ||
test("freq", () => { | ||
expect(note.freq("A4")).toBe(440); | ||
@@ -60,0 +75,0 @@ expect(note.freq(69)).toBe(440); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
120915
2855
0