Skip to content

thedeltaflyer/l1midiparser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LayerOne Demoscene MIDI Parser

This is a command-line MIDI file parser that converts most MIDI files into note arrays for use on the LayerOne Demoscene Board.

Installation

To use this tool, clone this repo (or just download midiparser.py)

This tool requires the python midi library. This can be installed via pip:

>> pip install python-midi

Or manually from the python-midi github

I always recommend using a virtualenv to contain python project libraries (Guide)

Basic Usage

Basic output

To output an array of notes to stdout:

>> python midiparser.py /path/to/midi/file.mid
__prog__ unsigned short song_ch1f[] __attribute__((space(prog))) = {
1,1,1,E3,E3,E3,Ab3,Ab3,Ab3,Ab3...};

Sample rate

In this context "sample rate" refers to the fidelity of the exported array. By default the tool downsamples the MIDI data so that there is 1 note per "beat" where a "beat" is defined by the MIDI file's resolution. By setting an integer "sample rate" using the -s flag sets what fraction of the resolution constitutes a note.

For example, a value of 2 will output one note for every half-beat in the MIDI file.

As you increase this value, the number of notes produced by the same MIDI file increases. I recommend that you set this as low as possible for the quality of music you desire.

I have found that values of 4-16 work well for most files.

>> ./midiparser.py /path/to/midi/file.mid -s 1
__prog__ unsigned short song_ch1f[] __attribute__((space(prog))) = {
1,1,1,E3,E3,E3,Ab3,Ab3,Ab3,Ab3...};
>> ./midiparser.py /path/to/midi/file.mid -s 2
__prog__ unsigned short song_ch1f[] __attribute__((space(prog))) = {
1,1,1,1,1,1,E3,E3,E3,E3,E3,E3,Ab3,Ab3,Ab3,Ab3,Ab3,Ab3,Ab3,Ab3...};

Saving to a file

To have the data saved to a file use the -o flag:

>> ./midiparser.py /path/to/midi/file.mid -o output_file.h
Output saved to: /path/to/cwd/output_file.h

Including vector data

To include MIDI vector data in addition to notes, use the -v flag:

>> ./midiparser.py /path/to/midi/file.mid -v
__prog__ unsigned short song_ch1f[] __attribute__((space(prog))) = {
1,1,1,E3,E3,E3,Ab3,Ab3,Ab3,Ab3...};

__prog__ unsigned short song_ch1a[] __attribute__((space(prog))) = {
0,0,0,95,95,95,95,95,95,95...};

Note: For now, notes and vectors are all MIDI features this parser supports. For most LayerOne Demoscene Board applications, you will only need notes.

Custom variable prefix

The default output uses the variable name song_ch as the "prefix". To set a custom prefix, use the -p flag:

>> ./midiparser.py /path/to/midi/file.mid -p my_prefix
__prog__ unsigned short my_prefix1f[] __attribute__((space(prog))) = {
1,1,1,E3,E3,E3,Ab3,Ab3,Ab3,Ab3...};

Credits

Links

People

Inspiration

This project was inspired by mr1337357 who created a parser for their 2015 Demo.

About

MIDI Parser for the LayerOne Demoscene Board

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages