使用 javax.sound.midi 包设置乐器通道
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了和你一样的问题,尽管我们没有使用完全相同的实现来使 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