fork download
  1. package tonedeaf;
  2. // @author Damien Bell
  3.  
  4. import javax.sound.midi.*;
  5. import java.util.Random;
  6. import java.lang.Math;
  7.  
  8. public class ToneDeaf {
  9. public static void main(String[] args) {
  10.  
  11. int[] notes = new int[127];
  12. Random generator = new Random();
  13. for(int i=0; i<126; i++){
  14. notes[i] = Math.abs(generator.nextInt()%127);
  15. }
  16. try {
  17. Synthesizer synthesizer = MidiSystem.getSynthesizer();
  18. synthesizer.open();
  19. MidiChannel channel = synthesizer.getChannels()[0];
  20.  
  21. for (int note : notes) {
  22. System.out.println(note);
  23. channel.noteOn(note, 100);
  24. try {
  25. Thread.sleep(200);
  26. } catch (InterruptedException e) {
  27. break;
  28. } finally {
  29. channel.noteOff(note);
  30. }
  31. }
  32. } catch (MidiUnavailableException e) {
  33. e.printStackTrace();
  34. }
  35. }
  36. }
  37.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty