Permalink
Browse files

Factored out midi magic

  • Loading branch information...
regality committed Apr 15, 2012
1 parent c242d34 commit ee4a1804b90a583d696db0871c3205c1d908f640
Showing with 20 additions and 18 deletions.
  1. +2 −18 compiler.js
  2. +18 −0 midi.js
View
@@ -1,4 +1,5 @@
-var assert = require('assert');
+var assert = require('assert')
+ , pitchToMIDI = require('./midi');
function compile(mus, notes) {
if (!notes) {
@@ -26,23 +27,6 @@ function compileT(mus) {
return notes;
}
-function pitchToMIDI(pitch) {
- var l = pitch[0].toLowerCase();
- switch (l) {
- case 'c': l = 0; break;
- case 'd': l = 2; break;
- case 'e': l = 4; break;
- case 'f': l = 5; break;
- case 'g': l = 7; break;
- case 'a': l = 9; break;
- case 'b': l = 11; break;
- default: l = 0;
- }
- var octave = pitch[1];
- var midi = 12 + 12 * octave + l;
- return midi;
-}
-
function setStartTimes(mus, offset) {
offset = offset || 0;
if (mus.tag === 'par') {
View
18 midi.js
@@ -0,0 +1,18 @@
+function pitchToMIDI(pitch) {
+ var l = pitch[0].toLowerCase();
+ switch (l) {
+ case 'c': l = 0; break;
+ case 'd': l = 2; break;
+ case 'e': l = 4; break;
+ case 'f': l = 5; break;
+ case 'g': l = 7; break;
+ case 'a': l = 9; break;
+ case 'b': l = 11; break;
+ default: l = 0;
+ }
+ var octave = pitch[1];
+ var midi = 12 + 12 * octave + l;
+ return midi;
+}
+
+module.exports = pitchToMIDI;

0 comments on commit ee4a180

Please sign in to comment.