GregJ/music.js — Issue #3: Interval.fromSemitones  alterations / issues
Author: michaelhancock
Created: 2012-03-06 22:26:01+00:00
State: open

Hi,

i was trying to simulate the piano keys and ran into some problems which required changes to the Interval.fromSemitones method.

this is the code which i used to cause the issue:
````javascript
for(var i=0; i < 20; i++){
var n=Note.fromLatin("A0").add(Interval.fromSemitones(i));
console.log(i+": ",n.latin()+n.octave());
}
````
here are the alterations i made:

````javascript

MUSIC.intervals_semitones['0'] = MUSIC.intervals.unison;
MUSIC.intervals_semitones['12'] = MUSIC.intervals.octave;

Interval.fromSemitones = function(num){
if(num > 12){ // if its more than 12 semitones calc the number of octaves
var octaves = new Interval( [Math.floor(num/12),0] );
return octaves.add( new Interval(MUSIC.intervals_semitones[num%12]) );
}else{
return new Interval(MUSIC.intervals_semitones[num]);
}
}
````
sorry about the code in the post, will submit a patch when i get back to my pc, on holiday :)