使用 javax.sound.midi 包设置乐器通道

发布于 2024-09-01 14:33:06 字数 596 浏览 2 评论 0原文

我在 javax.sound.midi 包中设置乐器时遇到问题。

Synthesizer synthesizer = MidiSystem.getSynthesizer();
MidiChannel[] channels = synthesizer.getChannels();

channels[0].programChange(5);
System.out.println(channels[0].getProgram());

来自文档 MidiChannel,对channels[0].programChange(int) 的调用应更改MidiChannel 设置的乐器并立即反映在channels[0].getProgram() 中。然而我的程序打印“0”,表明没有任何改变。

稍后在代码中,我使用 MidiChannel.getSequencer() 成功播放 midi 声音(尽管仅使用默认乐器)。

我是否打算尝试以错误的方式设置乐器?

I'm having trouble setting the instrument in the javax.sound.midi package.

Synthesizer synthesizer = MidiSystem.getSynthesizer();
MidiChannel[] channels = synthesizer.getChannels();

channels[0].programChange(5);
System.out.println(channels[0].getProgram());

From the documentation on MidiChannel, calls to channels[0].programChange(int) should change instrument that the MidiChannel is set to and immediately reflected in channels[0].getProgram(). However my program prints "0", indicating nothing has changed.

Later on in the code, I'm using MidiChannel.getSequencer() to play midi sound successfully (although only with the default instrument.)

Am I going about trying to set the instrument in the wrong way?

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

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

发布评论

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

评论(1

等风来 2024-09-08 14:33:06

我遇到了和你一样的问题,尽管我们没有使用完全相同的实现来使 MIDI 消息随意查看我的问题,因为它可能对你有一些用处:

在播放期间更改 Java 乐器

I came across the same problem as you, although we're not using the exact same implementation for making MIDI messages feel free to look at my question as it may be of some use to you:

Changing instrument in Java during playback

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