Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MIDI instrument listing?

I have recently implemented a MIDI Beatbox from the code in Head First Java and would really like to do more with Java's MIDI capabilities. I thought that I might start by adding more, non-percussive instruments to the existing code, but I cannot seem to find a straightforward listing of the available instruments and their int keys.

Does such a listing exist anywhere for theSoundbankthat ships with the JDK?

like image 328
cornbread ninja Avatar asked Oct 18 '11 15:10

cornbread ninja


2 Answers

DYM like this?

import javax.sound.midi.*;
import javax.swing.*;

class Instruments {

    public static void main(String[] args) throws MidiUnavailableException {
        Synthesizer synthesizer = MidiSystem.getSynthesizer();
        synthesizer.open();
        Instrument[] orchestra = synthesizer.getAvailableInstruments();

        final StringBuilder sb = new StringBuilder();
        String eol = System.getProperty("line.separator");
        sb.append("The orchestra has ");
        sb.append(orchestra.length);
        sb.append(" instruments.");
        sb.append(eol);
        for (Instrument instrument : orchestra) {
            sb.append(instrument.toString());
            sb.append(eol);
        }
        synthesizer.close();

        Runnable r = new Runnable() {

            @Override
            public void run() {
                JOptionPane.showMessageDialog(null,
                        new JScrollPane(new JTextArea(sb.toString(), 20, 30)));
            }
        };
        SwingUtilities.invokeLater(r);
    }
}

Output

The orchestra has 411 instruments.
Instrument Piano (bank 0 program 0)
Instrument Bright Piano (bank 0 program 1)
Instrument Electric Grand (bank 0 program 2)
Instrument Honky Tonk Piano (bank 0 program 3)
Instrument Electric Piano 1 (bank 0 program 4)
Instrument Electric Piano 2 (bank 0 program 5)
Instrument Harpsichord (bank 0 program 6)
Instrument Clavinet (bank 0 program 7)
Instrument Celesta (bank 0 program 8)
Instrument Glockenspiel (bank 0 program 9)
...
like image 167
Andrew Thompson Avatar answered Oct 18 '22 07:10

Andrew Thompson


Here's the complete list, nevertheless. http://www.midi.org/techspecs/gm1sound.php

like image 20
Anoop Dixith Avatar answered Oct 18 '22 08:10

Anoop Dixith