We are trying to code a simple guitar hero clone for university using javax.sound.midi.
Currently we can play back a midi file with a sequencer and log the midi event that is currently played. However, we want to display the upcoming event (more specifically, the the data bytes in the MIDI message that indicate the note).
We are currently using a Sequencer to play the sounds and a Receiver and that logs the sound to the console. However, it logs it the exact moment the sound is played, not the upcoming sound.
In Sequencer class:
public void startSequencer() {
try {
sequencer.open();
Thread.sleep(2000);
sequencer.setTempoInBPM(BPM);
InputStream is = new BufferedInputStream(new FileInputStream(song));
sequencer.setSequence(is);
sequencer.getTransmitter().setReceiver(receiver);
sequencer.start();
while (sequencer.isRunning()) {
Thread.sleep(100);
}
sequencer.close();
System.out.println(receiver.getNoteOnAmount());
} catch (MidiUnavailableException | InterruptedException | IOException | InvalidMidiDataException e) {
throw new RuntimeException(e);
}
}
In Receiver class:
public void send(MidiMessage message, long timeStamp) {
//If the Status is NOTE_ON (144), process the note
if (message.getStatus() == 144) {
System,out.println(message.getMessage()[1]);
}