JFugue 5 external midi device

那年仲夏 提交于 2019-12-12 01:27:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!