Setting instrument channels using the javax.sound.midi package

旧巷老猫 提交于 2019-12-10 07:04:13

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/2828820/setting-instrument-channels-using-the-javax-sound-midi-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!