Convert Midi Note Numbers To Name and Octave

In JFugue, the Note class has a utility method that does exactly this - see public static String getStringForNote(byte noteValue).

EDIT: As of JFugue 5.0 and later, the Note class has several utility methods for getting a string representation from a MIDI note value:

  • getToneString(byte noteValue) converts a value of 60 to the string C5
  • getToneStringWithoutOctave(byte noteValue) converts a value of 60 to the string C
  • getPercussionString(byte noteValue) converts a value of 60 to the string "[AGOGO]"

These replace the original getStringForNote() method.


I'm not convinced your suggestion is that tedious. It's really just a divide-and-modulo operation, one gets the octave, the other gets the note.

octave = int (notenum / 12) - 1;
note = substring("C C#D D#E F F#G G#A A#B ",(notenum % 12) * 2, 2);

In real Java, as opposed to that pseudo-code above, you can use something like:

public class Notes {
  public static void main(String [] args) {
    String notes = "C C#D D#E F F#G G#A A#B ";
    int octv;
    String nt;
    for (int noteNum = 0; noteNum < 128; noteNum++) {
      octv = noteNum / 12 - 1;
      nt = notes.substring((noteNum % 12) * 2, (noteNum % 12) * 2 + 2);
      System.out.println("Note # " + noteNum + " = octave " + octv + ", note " + nt);
    }
  }
}