次のコードがあります。ここでは、シーケンサーを作成し、シーケンスを指定し、シーケンスに新しいトラックを指定し、MidiEvents をトラックに書き込み、sequencer.start() を呼び出すときにシーケンスを再生しようとします。私は何を間違っていますか?
public static void main(String args[]) {
try {
Sequencer sequencer = MidiSystem.getSequencer();
sequencer.setTempoInBPM(96);
sequencer.setTickPosition(0);
Sequence seq = new Sequence(Sequence.PPQ, 5);
sequencer.setSequence(seq);
sequencer.open();
Track mainTrack = seq.createTrack();
sequencer.recordEnable(mainTrack, 0);
sequencer.startRecording();
ShortMessage msg = new ShortMessage();
ShortMessage msg2 = new ShortMessage();
msg.setMessage(ShortMessage.NOTE_ON, 0, 60, 100);
msg2.setMessage(ShortMessage.NOTE_OFF, 0, 60, 100);
mainTrack.add(new MidiEvent(msg, 0));s
mainTrack.add(new MidiEvent(msg2, 400));
Thread.sleep(5000);
sequencer.stopRecording();
sequencer.start();
Thread.sleep(5000);
sequencer.close();
} catch (MidiUnavailableException | InvalidMidiDataException |
InterruptedException e) {
System.err.println(e.getMessage());
}
}