# HG changeset patch # User JShulver # Date 1351696586 0 # Node ID 5c54f5213f3d7f1f9b01711783a75c49e56c568f # Parent 9e45ae01f81e319430a85837bf174d427bfb7e7c This is a fix for the problem where some MIDI files cannot be read because they encode OFF signals as ON signals with a velocity of 0. diff -r 9e45ae01f81e -r 5c54f5213f3d MidiPlayer.class Binary file MidiPlayer.class has changed diff -r 9e45ae01f81e -r 5c54f5213f3d MidiPlayer.java --- a/MidiPlayer.java Tue Mar 27 16:54:17 2012 +0100 +++ b/MidiPlayer.java Wed Oct 31 15:16:26 2012 +0000 @@ -34,7 +34,7 @@ import javax.sound.midi.MetaMessage; import javax.sound.midi.SysexMessage; import javax.sound.midi.MetaMessage; - +import java.util.Arrays; public class MidiPlayer { /* variables */ @@ -166,7 +166,10 @@ // System.out.println("onset in ticks = " + event.getTick()+ // "; onset in microseconds = " + // ticksToMicroseconds(event.getTick())); - ons.add(ticksToMicroseconds(event.getTick())); + //if the event does not have a velocity of zero (i.e. switching a note off) + if(message.getMessage()[2] != 0) { + ons.add(ticksToMicroseconds(event.getTick())); //THEN we can add the note + } } } } @@ -191,6 +194,13 @@ // (float)event.getTick() * microsecondsPerTick); offs.add(ticksToMicroseconds(event.getTick())); } + //if we have not found a note off, + else if (message instanceof ShortMessage + && ((ShortMessage)message).getCommand() == ShortMessage.NOTE_ON + && message.getMessage()[2] == 0) { //but it is a note on with a velocity of zero + offs.add(ticksToMicroseconds(event.getTick())); //add it as an off signal + } + } } return offs;