static MidiDevice getConnectedDevice(Sequencer sequencer) { List<Transmitter> trans = sequencer.getTransmitters(); log(" sequencer has " + trans.size() + " opened transmitters:"); for (Transmitter tr: trans) { Receiver r = tr.getReceiver(); log(" " + getClassStr(tr) + " connected to " + getClassStr(r)); if (r instanceof MidiDeviceReceiver) { MidiDeviceReceiver recv = (MidiDeviceReceiver)r; MidiDevice dev = recv.getMidiDevice(); log(" - receiver of " + getClassStr(dev)); return dev; } else { log(" - does NOT implement MidiDeviceReceiver"); } } return null; }
private void init() throws MidiUnavailableException { devIn = MidiSystem.getMidiDevice(inInfo); devIn.open(); devOut = MidiSystem.getMidiDevice(outInfo); devOut.open(); midiIn = new MidiInput(); devIn.getTransmitter().setReceiver(midiIn); midiOut = (MidiDeviceReceiver)devOut.getReceiver(); //MIDI Message Sender Thread: midiTx = new Thread(() -> { while(true) { int size; while((size=cue.size()) > 0) { MidiMessage msg; synchronized(this) { msg = cue.get(0); cue.remove(0); } midiOut.send(msg, -1); if(size > 10000) { //Keep array under 10,000... synchronized(this) { size=cue.size(); while(size > 50) { cue.remove(size-1); size--; }} debug("Buffer had to be force-cleared!"); } if(Thread.interrupted()) return; } if(Thread.interrupted()) return; }}); midiTx.setPriority(1); midiTx.start(); programMode(); setAll(-1); //Reset LaunchPad Lights. }