//start -> Settings -> Control Panel -> Sounds -> volume up import javax.sound.midi.MidiChannel; import javax.sound.midi.MidiSystem; import javax.sound.midi.MidiUnavailableException; import javax.sound.midi.Synthesizer; public class Beethoven1 { static Synthesizer synthesizer; static MidiChannel channel; static final int C = 60, //Middle C. Lowest is 0; highest is 127. D = 62, E = 64, //only a half step between E and F F = 65, G = 67, A = 68, B = 69; static { try { synthesizer = MidiSystem.getSynthesizer(); synthesizer.open(); } catch (MidiUnavailableException e) { System.err.println("couldn't get Synthesizer"); e.printStackTrace(); System.exit(1); } // Find a non-null channel. MidiChannel[] channels = synthesizer.getChannels(); int c; //channel number for (c = 0; channels[c] == null; ++c) { if (c >= channels.length) { System.err.println("All channels null"); synthesizer.close(); System.exit(2); } } channel = channels[c]; } public static void main(String[] args) { //Volume is 127; .400 seconds per note. play(E, 127, 400); play(E, 127, 400); play(F, 127, 400); play(G, 127, 400); play(G, 127, 400); play(F, 127, 400); play(E, 127, 400); play(D, 127, 400); play(C, 127, 400); play(C, 127, 400); play(D, 127, 400); play(E, 127, 400); play(E, 127, 400); play(D, 127, 400); play(D, 127, 400); synthesizer.close(); } // The following five lines are needed to get the above play to work. static void play(int pitch, int volume, long duration) { channel.noteOn(pitch, volume); sleep(duration); channel.noteOff(pitch); } // The following eight lines are needed to get the above sleep to work. static void sleep(long milliseconds) { try { Thread.sleep(milliseconds); } catch (InterruptedException e) { System.err.println(e.getMessage()); } } }