forked from saebekassebil/scientific-notation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
22 lines (16 loc) · 637 Bytes
/
Copy pathindex.js
File metadata and controls
22 lines (16 loc) · 637 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var coords = require('notecoord');
var accval = require('accidental-value');
module.exports = function scientific(name) {
var format = /^([a-h])(x|#|bb|b?)(-?\d*)/i;
var parser = name.match(format);
if (!(parser && name === parser[0] && parser[3].length)) return;
var noteName = parser[1];
var octave = +parser[3];
var accidental = parser[2].length ? parser[2].toLowerCase() : '';
var accidentalValue = accval.interval(accidental);
var coord = coords(noteName.toLowerCase());
coord[0] += octave;
coord[0] += accidentalValue[0] - coords.A4[0];
coord[1] += accidentalValue[1] - coords.A4[1];
return coord;
};