Converts a MIDI number into a note name in scientific pitch notation - Java javax.sound.midi

Java examples for javax.sound.midi:MidiSystem

Description

Converts a MIDI number into a note name in scientific pitch notation

Demo Code


//package com.java2s;
import java.util.Arrays;

import java.util.List;

public class Main {
    private static List<String> numList = Arrays.asList(new String[] { "C",
            "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" });

    /**//  w  w w  .  ja  v a  2  s  .  c o m
     * Converts a MIDI number into a note name in scientific pitch notation
     * @param number - the MIDI number of the note
     * @return the note name in scientific pitch notation (e.g., A4, C#3, F#5)
     */
    public static String noteNumberToName(int number) {
        int octave = (number / 12) - 1;
        int noteIdx = number % 12;
        return (numList.get(noteIdx)).toUpperCase() + octave;
    }
}

Related Tutorials