0

很长一段时间以来一直在尝试使用 jFugue 5 将序列发送到 midi 设备:

     MusicReceiver device = getDeviceByName("name");

     Player player = new Player(); 
     Pattern pattern = new Pattern("A");    

     device.sendSequence(player.getSequence(pattern));

不能超越"device.sendSequence"上的"Unhandled exception type MidiUnavailableException "

     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));
      }
4

1 回答 1

0

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));
}
于 2015-02-23T21:44:10.803 回答