Mac OSX 中的 Java Midi 损坏了吗?

发布于 2024-12-16 01:28:40 字数 923 浏览 3 评论 0原文

我正在尝试在浏览器中播放 midi,并且一直在使用在 PC 上运行良好的 Java Applet。它在 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();
      }
  }
}

听起来偶尔的消息被丢弃了。就像一个音符不会触发,而一个随机音符将永远挂起。这是 OSX 中的已知问题吗?如今,Java 似乎没有得到 Apple 足够的喜爱。

如果有人有更好的解决方案在浏览器中播放 Midi,我会洗耳恭听!

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

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

横笛休吹塞上声 2024-12-23 01:28:40

这似乎是一个由两部分组成的问题。我也无法使用 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.

荭秂 2024-12-23 01:28:40

来自 mmj - Mac OS X 上的 java Midi

Apple 的 java Midi 实现显得有点三心二意。它不认为状态字节 >= 0xF0 的 MIDI 数据有效(即不适用于 sysex、MIDI 时钟、时间码等),忽略 Midi 事件上的时间戳,设备名称将默认为仅端口名称(没有提示)在该端口所属的设备上)并且可能还缺少其他类似的东西。

OS X 上的 MIDI 情况似乎很糟糕,尽管该 API 是作为替代品提供的。

From mmj - Midi for java on Mac OS X:

Apple's java Midi implementation appears a bit half-hearted. It does not consider MIDI data with status bytes >= 0xF0 to be valid (i.e. 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.

The situation on OS X seems dire re MIDI, though that API is offered as a replacement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文