We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Simple Midi note number to note name method
Page Index Toggle Pages: 1
Simple Midi note number to note name method (Read 438 times)
Simple Midi note number to note name method
Nov 12th, 2008, 8:23pm
 
All,

Not sure if this is the best way to do this, but here is a simple method to create a map of midi note numbers to their equal-tempered counterparts:

Code:

private Map<String, Integer> mapNotes(){
Map<String, Integer> noteMap = new HashMap<String, Integer>();
String[] noteNames =
{"C","C#","Db","D","D#","Eb","E","F","F#","Gb","G","G#","Ab","A","A#","Bb","B"};

for (int noteNumber=0; noteNumber<128;){
for (Integer range=-1; range<10; range++){
for (String nextNote : noteNames){
if (nextNote.contains("b")) noteNumber--;
noteMap.put(nextNote + range.toString(), noteNumber);
noteNumber++;
}
}
}
return noteMap;
}


This was written in eclipse, so mileage may vary in the PDE, you may need to tweak the method definition. This is a simple way to map these values, then pull them out via note name, rather than having to look at a midi implementation guide to get the correct note number for the note you want.
Re: Simple Midi note number to note name method
Reply #1 - Nov 13th, 2008, 11:14pm
 
I expanded this into a full class now, with lookups for note number and note name. You can download it here:

http://www.grantmuller.com/?p=38
Page Index Toggle Pages: 1