问题
Been trying for a long time to send a sequence to a midi device with jFugue 5:
MusicReceiver device = getDeviceByName("name");
Player player = new Player();
Pattern pattern = new Pattern("A");
device.sendSequence(player.getSequence(pattern));
Can't go beyong "Unhandled exception type MidiUnavailableException" on "device.sendSequence".
static MidiDevice.Info getDeviceInfoByName(String name) {
for (MidiDevice.Info info : MidiSystem.getMidiDeviceInfo()) {
if (info.getName().equals(name)) {
return info;
}
}
return null;
}
static MusicReceiver getDeviceByName(String name) {
return new MusicReceiver((MidiDevice) getDeviceInfoByName(name));
}
回答1:
You are trying to cast an instance of MidiDevice.Info
that you get from your getDeviceByInfo
to a MidiDevice
. Replace your getDeviceByName
function with the following:
static MusicReceiver getDeviceByName(String name)
throws MidiUnavailableException {
MidiDevice.Info info = getDeviceInfoByName(name);
return new MusicReceiver(MidiSystem.getMidiDevice(info));
}
来源:https://stackoverflow.com/questions/28682795/jfugue-5-external-midi-device