Skip to content

Instantly share code, notes, and snippets.

@ykrkn
Created July 29, 2013 15:07
Show Gist options
  • Save ykrkn/6105003 to your computer and use it in GitHub Desktop.
Save ykrkn/6105003 to your computer and use it in GitHub Desktop.
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