gpt4 book ai didi

java - 如何在Java MIDI程序中更改乐器

转载 作者:太空宇宙 更新时间:2023-11-04 09:43:34 26 4
gpt4 key购买 nike

如何更改 Midi 中的乐器?我可以将 channel 的值更改为最多 9,之后它会显示“ channel 超出范围”,这都是钢琴。例如,我怎样才能将其更改为吉他

  public noteplay()
throws InvalidMidiDataException,MidiUnavailableException
{
bpm =80;
beatLength = 1;
theTimeMelody = 0;
theTimeBass =0;
seq = new Sequence(Sequence.PPQ,3);
trkBass = seq.createTrack();
trkMelody = seq.createTrack();
}
public void melody(int volume)
throws InvalidMidiDataException,MidiUnavailableException

{

int list1[] = { 56,59,60,63,56,59,60,63, 61,64,65,68,61,64,65,68, 56,59,60,63,56,59,60,63, 63,66,67,70,73,66,67,70,};

for (int pitch : list1)
{
ShortMessage onMsg = new ShortMessage();
onMsg.setMessage(ShortMessage.NOTE_ON, 0, pitch, 80);

ShortMessage offMsg = new ShortMessage();
offMsg.setMessage(ShortMessage.NOTE_OFF, 0, pitch, 90);

trkBass.add(new MidiEvent(onMsg,theTimeBass));
trkBass.add(new MidiEvent(offMsg,theTimeBass+beatLength));
theTimeBass += beatLength;

}
}
}

最佳答案

通用 MIDI 标准为鼓保留了第十个 channel 。

您可以将其他十五个 channel 用于旋律乐器。

关于java - 如何在Java MIDI程序中更改乐器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55690935/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com