Created
July 29, 2013 15:07
-
-
Save ykrkn/6105003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void runMidi() throws MidiUnavailableException, InvalidMidiDataException, InterruptedException{ | |
MidiDevice.Info[] mdi = MidiSystem.getMidiDeviceInfo(); | |
MidiDevice out = null; | |
for(MidiDevice.Info info : mdi){ | |
System.out.println(info); | |
if("Microsoft GS Wavetable Synth".equals(info.getName())){ | |
out = MidiSystem.getMidiDevice(info); | |
} | |
} | |
if(null == out) return; | |
out.open(); | |
Receiver rcv = out.getReceiver(); | |
ShortMessage message = new ShortMessage(); | |
int rnd = 0; | |
for(;;){ | |
rnd = (int)(Math.random()*12); | |
message.setMessage(ShortMessage.NOTE_ON, 0x9, 0x24+rnd, 0x7f); | |
//rcv.send(message, -1); | |
message.setMessage(ShortMessage.NOTE_ON, 0x0, 0x24+rnd, 0x7f); | |
rcv.send(message, -1); | |
Thread.sleep(100); | |
message.setMessage(ShortMessage.NOTE_OFF, 0x0, 0x24+rnd, 0x7f); | |
rcv.send(message, -1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment