Comparing version 1.0.0 to 2.0.0
16
index.js
var coords = require('notecoord'); | ||
var accidentals = { | ||
'bb': -2, | ||
'b': -1, | ||
'': 0, | ||
'#': 1, | ||
'x': 2 | ||
}; | ||
var accval = require('accidental-value'); | ||
var A4 = [3, 3]; | ||
@@ -39,11 +34,10 @@ module.exports = function helmholtz(name) { | ||
var accidentalValue = accidentals[parts[3].toLowerCase()]; | ||
var accidentalValue = accval.interval([parts[3].toLowerCase()]); | ||
var coord = coords(note.toLowerCase()); | ||
// The interval of going one semitone up is [-4, 7] (octaves, fifths) | ||
coord[0] += octave; | ||
coord[0] += -4 * accidentalValue; | ||
coord[1] += 7 * accidentalValue; | ||
coord[0] += accidentalValue[0] - A4[0]; | ||
coord[1] += accidentalValue[1] - A4[1]; | ||
return coord; | ||
}; |
{ | ||
"name": "helmholtz", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Parses note names in Helmholtz format", | ||
@@ -29,2 +29,6 @@ "main": "index.js", | ||
"homepage": "https://github.com/saebekassebil/helmholtz", | ||
"dependencies": { | ||
"accidental-value": "^1.0.0", | ||
"notecoord": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
@@ -31,0 +35,0 @@ "tape": "^2.13.3" |
@@ -5,3 +5,3 @@ # helmholtz | ||
[Helmholtz pitch notation](http://en.wikipedia.org/wiki/Helmholtz_pitch_notation) | ||
returning intervals in octaves and fifths relative to C0 (or `C,,`) | ||
returning intervals in octaves and fifths relative to A4 (or `a'`) | ||
@@ -11,5 +11,6 @@ ```js | ||
helmholtz(',,C') // -> [ 0, 0 ] | ||
helmholtz('d#\'') // -> [ -1, 9 ] | ||
helmholtz('a\'\') // -> [ 4, 3 ] | ||
helmholtz('a\'') // -> [ 0, 0 ] | ||
helmholtz(',,C') // -> [ -3, -3 ] | ||
helmholtz('d#\'') // -> [ -4, 6 ] | ||
helmholtz('a\'\'') // -> [ 1, 0 ] | ||
``` | ||
@@ -26,5 +27,5 @@ | ||
Takes a `note` string in the Helmholtz notation and returns an array | ||
describing the interval of that note relative to C0. The returned interval is | ||
describing the interval of that note relative to A4. The returned interval is | ||
in the format `[octaves, fifths]` - that is, an array consisting of two | ||
numbers, the first the number of octaves to jump, the second the number of | ||
fifths to jump from C0 to land at the desired note. | ||
fifths to jump from A4 to land at the desired note. |
@@ -5,10 +5,10 @@ var test = require('tape'), | ||
test('parsing helmholtz notation', function(t) { | ||
t.deepEqual(helmholtz('a\''), [3, 3]); | ||
t.deepEqual(helmholtz(',,C'), [0, 0]); | ||
t.deepEqual(helmholtz('c#'), [-1, 7]); | ||
t.deepEqual(helmholtz('D'), [1, 2]); | ||
t.deepEqual(helmholtz('Ebb,,'), [6, -10]); | ||
t.deepEqual(helmholtz('gx\'\'\''), [-2, 15]); | ||
t.deepEqual(helmholtz('fb'), [8, -8]); | ||
t.deepEqual(helmholtz('a\''), [0, 0]); | ||
t.deepEqual(helmholtz(',,C'), [-3, -3]); | ||
t.deepEqual(helmholtz('c#'), [-4, 4]); | ||
t.deepEqual(helmholtz('D'), [-2, -1]); | ||
t.deepEqual(helmholtz('Ebb,,'), [3, -13]); | ||
t.deepEqual(helmholtz('gx\'\'\''), [-5, 12]); | ||
t.deepEqual(helmholtz('fb'), [5, -11]); | ||
t.end(); | ||
}); |
4746
7
29
2
46
+ Addedaccidental-value@^1.0.0
+ Addednotecoord@^1.0.1
+ Addedaccidental-value@1.0.0(transitive)
+ Addednotecoord@1.1.0(transitive)