【发布时间】:2019-04-15 14:03:29
【问题描述】:
如何在 Midi 中更换乐器? 我可以将通道的值更改为最多 9,之后它会显示“通道超出范围”,这都是钢琴。例如,如何将其更改为吉他
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;
}
}
}
【问题讨论】:
-
您是否尝试过跳过第 10 频道?它通常是为鼓保留的。
标签: java midi javax.sound.midi