Skip to content

Commit dcf4eaa

Browse files
committed
add ability to convert pitch to number
1 parent 79f1377 commit dcf4eaa

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

nathansununiversity_02.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
// http://nathansuniversity.com/music.html
22
// this file supposed to work with node.js
33
//
4+
5+
var convertPitch = function(pitch) {
6+
var dict = {c: 0, d: 2, e: 4, f: 5, g: 7, a: 9, b: 11};
7+
if (pitch.length === 2 && dict[pitch[0]] !== undefined) {
8+
return 12 * (1 + parseInt(pitch[1])) + dict[pitch[0]];
9+
}
10+
};
11+
412
// following compile function is from last lesson
513
var compile = function (expr) {
614

@@ -11,6 +19,9 @@ var compile = function (expr) {
1119
(function(expr) {
1220
if (expr.tag === 'note' || expr.tag === 'rest') {
1321
expr.start = time || ref;
22+
if (expr.pitch) {
23+
expr.pitch = convertPitch(expr.pitch);
24+
}
1425
result.push(expr);
1526

1627
time += expr.dur;

0 commit comments

Comments
 (0)