Class MIDIFileInputStream

java.lang.Object
java.io.InputStream
java.io.FilterInputStream
java.io.BufferedInputStream
com.softsynth.midifile.MIDIFileInputStream
All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable

public class MIDIFileInputStream
extends java.io.BufferedInputStream
MIDI File Parser.
Parse tracks and events from an InputStream and pass the information to a MIDIFileListener.
Author:
Phil Burk (C) 1999 SoftSynth.com
See Also:
MIDIFileListener
  • Constructor Summary

    Constructors
    Constructor Description
    MIDIFileInputStream​(java.io.InputStream stream)  
  • Method Summary

    Modifier and Type Method Description
    void addMIDIFileListener​(MIDIFileListener listener)
    Request that information from the parser be passed to this listener.
    void handleBeginTrack​(int index)
    Called at the beginning of each track
    void handleEndTrack​(int index)
    Called at the end of each track
    void handleHeader​(int format, int numTracks, short division)
    Called when the header is parsed.
    void handleMetaEvent​(int ticks, int type, byte[] b)
    Called when a MetaEvent is encountered.
    void handleSysExF0​(int ticks, byte[] b)
    Called when an F0 SysEx event is encountered.
    void handleSysExF7​(int ticks, byte[] b)
    Called when an F7 SysEx event is encountered.
    static java.lang.String IDToString​(int ID)
    Convert a 4 character IFF ID to a String
    void parse()  
    int read()
    Override read method with one that counts bytes.
    int read​(byte[] b)  
    int readIntBig()
    Read 32 bit signed integer assuming Big Endian byte order.
    short readShortBig()
    Read 16 bit signed short assuming Big Endian byte order.
    void removeMIDIFileListener​(MIDIFileListener listener)  

    Methods inherited from class java.io.BufferedInputStream

    available, close, mark, markSupported, read, reset, skip

    Methods inherited from class java.io.InputStream

    nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MIDIFileInputStream

      public MIDIFileInputStream​(java.io.InputStream stream)
  • Method Details

    • addMIDIFileListener

      public void addMIDIFileListener​(MIDIFileListener listener)
      Request that information from the parser be passed to this listener.
    • removeMIDIFileListener

      public void removeMIDIFileListener​(MIDIFileListener listener)
    • read

      public int read() throws java.io.IOException
      Override read method with one that counts bytes.
      Overrides:
      read in class java.io.BufferedInputStream
      Throws:
      java.io.IOException
    • read

      public int read​(byte[] b) throws java.io.IOException
      Overrides:
      read in class java.io.FilterInputStream
      Throws:
      java.io.IOException
    • readIntBig

      public int readIntBig() throws java.io.IOException
      Read 32 bit signed integer assuming Big Endian byte order.
      Throws:
      java.io.IOException
    • readShortBig

      public short readShortBig() throws java.io.IOException
      Read 16 bit signed short assuming Big Endian byte order.
      Throws:
      java.io.IOException
    • IDToString

      public static java.lang.String IDToString​(int ID)
      Convert a 4 character IFF ID to a String
    • handleHeader

      public void handleHeader​(int format, int numTracks, short division)
      Called when the header is parsed.
      Parameters:
      format - Format of file. 0, 1 or 2.
      numTracks -
      division -
    • handleBeginTrack

      public void handleBeginTrack​(int index)
      Called at the beginning of each track
      Parameters:
      index - Track index starting at zero
    • handleEndTrack

      public void handleEndTrack​(int index)
      Called at the end of each track
      Parameters:
      index - Track index starting at zero
    • handleSysExF0

      public void handleSysExF0​(int ticks, byte[] b)
      Called when an F0 SysEx event is encountered.
      Parameters:
      ticks - MIDIFile time-stamp
      b - bytes read from file for SysEx. May be null.
    • handleSysExF7

      public void handleSysExF7​(int ticks, byte[] b)
      Called when an F7 SysEx event is encountered.
      Parameters:
      ticks - MIDIFile time-stamp
      b - bytes read from file for SysEx. May be null.
    • handleMetaEvent

      public void handleMetaEvent​(int ticks, int type, byte[] b)
      Called when a MetaEvent is encountered.
      Parameters:
      ticks - MIDIFile time-stamp
      type - MetaEvent type, from 0 to 127.
      b - bytes read from file for SysEx. May be null.
    • parse

      public void parse() throws java.io.IOException
      Throws:
      java.io.IOException