JFugue 5 external midi device

2019-09-03 09:24发布

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条回答
啃猪蹄的小仙女
2楼-- · 2019-09-03 10:20

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));
}
查看更多
登录 后发表回答