Created
October 23, 2013 22:37
-
-
Save zeffii/7128072 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Note{ | |
int octave; | |
string str; | |
float volume; | |
float length; | |
fun void make( int oct, string s, float vol, float len) { | |
oct => octave; | |
s => str; | |
vol => volume; | |
len => length; | |
} | |
} | |
fun int to_note(Note n){ | |
// check if within supported range | |
if (n.str == "off") return -1; | |
if (n.octave < 0 || n.octave > 10) return -1; | |
string notes_list[]; | |
["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"] @=> notes_list; | |
// note must be in this list, else return -1 at the end | |
for (0 => int i; i < notes_list.cap(); i++){ | |
if (n.str == notes_list[i]){ | |
return (i + n.octave * 12); | |
} | |
} | |
return -1; | |
} | |
fun float int_to_freq(int n){ | |
return 440.0 * Math.pow(2, (n-69)/12); | |
} | |
Note n1; | |
"C#" => n1.str; | |
4 => n1.octave; | |
to_note(n1) => int midi_int; | |
<<< midi_int >>>; | |
int_to_freq(midi_int) => float out_freq; | |
<<< out_freq >>>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment