Skip to content

bhaeussermann/MidiReader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MidiReader

A simple zero-dependency Java library for reading events from a Midi file.

The MidiReader class creates an Iterator that reads all of the tracks in the Midi file at once (for synchronous multiple-track files). It mixes the Midi events into a single sequence so that the events are retrieved in chronological order.

This library is ideal for simple applications. If you are looking for something more sophisticated, then javax.sound.midi.spi.MidiFileReader might be a better option.

Trivial disclosure: This project was created and used for playing music with floppy drives. See my YouTube channel.

Example usage

The following example reads the specified Midi file to find all MidiEvent's of type MetaMidiEvent that represent lyrics, and prints them to the console in real time. Commenting the Thread.sleep() line will output the entire song's lyrics at once.

MidiReader reader = new MidiReader("[ path to your midi file that contains lyrics ]");
try
{
    MidiFileInfo midiFileInfo = reader.getMidiFileInfo();
    for (MidiEvent nextEvent : reader)
    {
        long delayMillis = nextEvent.getDeltaTime() * midiFileInfo.getMicrosecondsPerTick() / 1000;
        Thread.sleep(delayMillis);
        if ((nextEvent instanceof MetaMidiEvent) && (((MetaMidiEvent) nextEvent).getMetaEventType()==MetaEventType.LYRIC))
            System.out.print(((MetaMidiEvent) nextEvent).getContentAsString());
    }
}
finally
{
    try
    {
        reader.close();
    } 
    catch (IOException e) {}
}

Links

Here is a list of the most crucial resources that I used while developing the library:

About

A simple Java library for reading events from a Midi file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages