简体   繁体   English

Mac OSX中的Java Midi破碎了吗?

[英]Java Midi in Mac OSX Broken?

I'm trying to play midi within a browser, and have been using a Java Applet that works just fine on PCs. 我正在尝试在浏览器中播放midi,并且一直在使用可在PC上运行良好的Java Applet。 Its extremely unreliable on OSX, so I wrote a simple test case that exhibits the same problem: 它在OSX上非常不可靠,所以我写了一个简单的测试用例,它表现出同样的问题:

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

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? 这是OSX中的已知问题吗? Seems like Java just isn't getting enough love from Apple these days. 看起来Java似乎没有从Apple获得足够的爱。

If anyone has a better solution to playing Midi in a browser, I'm all ears! 如果有人有更好的解决方案在浏览器中播放Midi,我全都耳朵!

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. 我也无法使用配备2011年中期OSX 10.7.5的iMac发送midi sysex。 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(). 我确实找到了一个解决方法 - 首先,我必须使用mmj jar和jnilib,其次我必须告诉我的代码使用-1的时间戳,而不是使用system.currentTimeMillis()。 In my case I'm sending realtime sysex messages, thus a timestamp of -1 works for me. 在我的情况下,我发送实时sysex消息,因此-1的时间戳为我工作。 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? 如果您正在处理midi音符开/关等,我不知道要使用什么时间戳。也许时间戳是未来几毫秒? I don't know. 我不知道。 But I do know that I had to use both mmj and take better control of my timestamps. 但我知道我必须同时使用mmj并更好地控制我的时间戳。 After that, things work as expected. 在那之后,事情按预期工作。

From mmj - Midi for java on Mac OS X : 来自mmj - Midi for Mac OS X上的java

Apple's java Midi implementation appears a bit half-hearted. Apple的java Midi实现看起来有点半心半意。 It does not consider MIDI data with status bytes >= 0xF0 to be valid (ie does not work with sysex, MIDI clock, timecode etc.), ignores timestamps on Midi events, device names will default to only the port's name (without hints on the device this port belongs to) and there may be other things missing alike. 它不考虑状态字节> = 0xF0的MIDI数据有效(即不能使用sysex,MIDI时钟,时间码等),忽略Midi事件的时间戳,设备名称默认只有端口的名称(没有提示这个端口所属的设备)并且可能还有其他缺失的东西。

The situation on OS X seems dire re MIDI, though that API is offered as a replacement. 虽然该API作为替代品提供,但OS X上的情况似乎很糟糕。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM