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

问题描述 投票:1回答:1

如何在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;

      }
  } 
}
java midi javax.sound.midi
1个回答
0
投票

通用MIDI标准保留鼓的第十个频道。

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

© www.soinside.com 2019 - 2024. All rights reserved.