Often in applications it is desirable to use some auxiliary sound effects, for example, to peep with a speaker in case of an error or play a melody for a new letter.
Not everyone knows that a large library of sounds is built into any computer that has a sound card. All sound cards support MIDI
audio playback (see
ru.wikipedia.org/wiki/MIDI ) and these are 128 standard and 40 percussion instruments.
What is MIDI is a standard for commands to control synthesizer or other audio playback devices. Those. In .mp3, for example, the digitized sound is stored and in the .mid files only the notes that the sound card plays.
I have published a library for easy access to play MIDI sound:
')

Source code with an example of use as well as the compiled library can be downloaded at
http://code.google.com/p/easy-midi/Advantages of MIDI : there is in any computer, it contains 128 ordinary and 40 percussion instruments played by the music processor and does not affect the performance of the played music can be interactively changed (if you understand what is sharp different from the flat).
Disadvantages : the sound is completely dependent on the sound card and may differ on different computers.
An example of a simple call (plays in a separate thread):
Tools.playNote(Note.p93_7_La, Note.i127_Gunshot,127, 2000); Tools.playDrum(Drum.d39_Hand_Clap, 127, 2000);
For convenience, the names of the notes and conventional instruments are given by constants in the Note.java file, the names of the percussion instruments in the Drum.java file.
In addition to playing individual notes, small music fragments can be played using the library. An example of a small riff
int bassVoice=Note.i33_Electric_Bass_finger; Drum hat=new Drum(4, Drum.d42_Closed_Hi_Hat,64); Drum snare=new Drum(4, Drum.d38_Acoustic_Snare); Drum bass=new Drum(4, Drum.d35_Acoustic_Bass_Drum); Phrase p1=new Phrase() .chord(new Chord(8).drum(hat).drum(bass) .note(8, Note.p28_2_Mi, bassVoice)) .chord(new Chord(8).drum(hat) .note(8, Note.p28_2_Mi, bassVoice)) .chord(new Chord(8).drum(hat).drum(snare) .note(8, Note.p28_2_Mi, bassVoice)) .chord(new Chord(8).drum(hat) .note(8, Note.p28_2_Mi, bassVoice)) .chord(new Chord(8).drum(hat).drum(bass) .note(8, Note.p28_2_Mi, bassVoice)) .chord(new Chord(8).drum(hat).drum(bass) .note(8, Note.p28_2_Mi, bassVoice)) .chord(new Chord(8).drum(hat).drum(snare) .note(8, Note.p34_2_La_Diese, bassVoice)) .chord(new Chord(8).drum(hat) .note(8, Note.p35_2_Si, bassVoice)) ; Ticker ti = new Ticker(120, p1); ti.restart();
Class descriptions
Tools - contains playNote and playDrum methods for playing single sounds
Ticker - phrase player
Phrase - a musical phrase, contains a set of chords
Chord - chord, contains the height and duration of notes of ordinary and percussion instruments of a chord
Drum - description of the percussion instrument in the chord
Note - description of the usual instrument in the chord