This is a command-line MIDI file parser that converts most MIDI files into note arrays for use on the LayerOne Demoscene Board.
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)
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...};
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...};
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
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.
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...};
This project was inspired by mr1337357 who created a parser for their 2015 Demo.