如何控制MIDI通道的音量

发布于 2024-12-13 19:32:01 字数 703 浏览 6 评论 0原文

我有这个代码:

Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
Instrument[] instrument = synthesizer.getDefaultSoundbank().getInstruments();
synthesizer.loadInstrument(instrument[29]);
MidiChannel[] channels = synthesizer.getChannels();
MidiChannel channel = channels[1];
channel.programChange(29);
channel.noteOn(noteNumber, 127);
Teszthang.sleep(2000);
channel.noteOff(noteNumber);

这是一个示例,以最大音量(127)播放声音 2 秒。但我想控制频道的音量,比如2秒后,音量再过2秒淡出。我怎么能这么做呢?我知道这些方法:

channel.controlChange(controller, value);
channel.setPolyPressure(noteNumber, pressure);

但这些方法不会改变任何音量!我不知道如何使用这些方法。在播放 noteOn() 后,如何更改频道的音量?

I have this code:

Synthesizer synthesizer = MidiSystem.getSynthesizer();
synthesizer.open();
Instrument[] instrument = synthesizer.getDefaultSoundbank().getInstruments();
synthesizer.loadInstrument(instrument[29]);
MidiChannel[] channels = synthesizer.getChannels();
MidiChannel channel = channels[1];
channel.programChange(29);
channel.noteOn(noteNumber, 127);
Teszthang.sleep(2000);
channel.noteOff(noteNumber);

so this is an example, to play a sound in max volume (127) for 2 seconds. but i want to control the channel's volume, like after 2 seconds, the volume fade out in an another 2 seconds. How could I do that? I know these methods:

channel.controlChange(controller, value);
channel.setPolyPressure(noteNumber, pressure);

but these don't change any volume! I don't know how to use these methods. How could I change the channel's volume after the noteOn() while it has been playing?

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

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

发布评论

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

评论(2

糖粟与秋泊 2024-12-20 19:32:01

您可以使用 CC 7 设置频道音量。

channel.controlChange(7, value);

请参阅:http://improv.sapp.org/doc/class/MidiOutput /controllers/controllers.html

You can use CC 7 for setting channel volume.

channel.controlChange(7, value);

see: http://improv.sapp.org/doc/class/MidiOutput/controllers/controllers.html

天煞孤星 2024-12-20 19:32:01

有时,MIDI 文件中有一些音量事件,因此您无法更改通道音量。
获取序列后,删除这些事件:

Track[] tracks = sequence.getTracks();
for (Track track : tracks){
for(int i = 0; i < track.size(); i++){
    if(!track.remove(track.get(i))){
        System.out.println("MIDI Event not removed");
    }
}}

Sometimes you have some volume events in the midi file so you cannot change channel volume.
After getting the sequence, remove these events :

Track[] tracks = sequence.getTracks();
for (Track track : tracks){
for(int i = 0; i < track.size(); i++){
    if(!track.remove(track.get(i))){
        System.out.println("MIDI Event not removed");
    }
}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文