Mac OSX中的Java Midi破碎了? [英] Java Midi in Mac OSX Broken?

查看:154
本文介绍了Mac OSX中的Java Midi破碎了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在浏览器中播放midi,并且一直在使用可在PC上运行良好的Java Applet。它在OSX上极不可靠,所以我写了一个简单的测试用例,它表现出同样的问题:

I'm trying to play midi within a browser, and have been using a Java Applet that works just fine on PCs. Its extremely unreliable on OSX, so I wrote a simple test case that exhibits the same problem:

import javax.sound.midi.*;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class MidiPlayer {

  public static void main(String[] args) {
      try {
          Sequencer sequencer = MidiSystem.getSequencer();
          if (sequencer == null)
              throw new MidiUnavailableException();
          sequencer.open();
          FileInputStream is = new FileInputStream("sample.mid");
          Sequence mySeq = MidiSystem.getSequence(is);
          sequencer.setSequence(mySeq);
          sequencer.start();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
}

这听起来像偶尔的消息正在下降..就像一个音符不会发射,随机音符会永远挂起。这是OSX中的已知问题吗?好像Java似乎没有从Apple那里得到足够的爱。

It sounds like the occasional message is getting dropped.. Like a noteoff won't fire, and a random note will hang on forever. Is this a known problem in OSX? Seems like Java just isn't getting enough love from Apple these days.

如果有人有更好的解决方案在浏览器中播放Midi,我全都听见了! / p>

If anyone has a better solution to playing Midi in a browser, I'm all ears!

推荐答案

这似乎是一个两部分问题。我也无法使用配备2011年中期OSX 10.7.5的iMac发送midi sysex。我找到了一个解决方法 - 首先,我必须使用mmj jar和jnilib,其次我必须告诉我的代码使用-1的时间戳,而不是使用system.currentTimeMillis()。在我的情况下,我发送实时sysex消息,因此-1的时间戳对我有用。如果您正在处理midi音符开/关等,我不知道使用什么时间戳。也许时间戳是未来几毫秒?我不知道。但我知道我必须同时使用mmj并更好地控制我的时间戳。在那之后,事情按预期工作。

This appears to be a two part problem. I too could not send midi sysex's using a mid-2011 OSX 10.7.5 equipped iMac. I did find a workaround - first, I had to use the mmj jar and jnilib's and secondly I had to tell my code to use timestamps of -1 and NOT to use system.currentTimeMillis(). In my case I'm sending realtime sysex messages, thus a timestamp of -1 works for me. I don't know what timestamp to use if you're dealing with midi note on/off's etc. Perhaps the timestamp is milliseconds into the future? I don't know. But I do know that I had to use both mmj and take better control of my timestamps. After that, things work as expected.

这篇关于Mac OSX中的Java Midi破碎了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆