Skip to Content

Perl script to convert MIDI to lilypond

4 replies [Last post]
gemini
Offline
Joined: 04/17/2010

I've been working on a perl script to transform hydrogen's MIDI output to lilypond-friendly input.

It has some serious limitations:
- Only 4/4
- Normal triplets working (they do not work if there's a silence on the triplet)
- I've tested only the standard kit
- Two lines: cymbals and bass/toms/snare
- On each line, only one note at a time (no bass and snare at the same time)
- Probably more bugs...

If you want to try out: you need MIDI-perl. On debian/ubuntu:

# apt-get install libmidi-perl
# apt-get install lilypond

Export a simple hydrogen song to MIDI (let's suppose "song.midi")

$ perl drums.pl song.midi > song.ly
$ lilypond song.ly
(you should obtain "song.pdf")

Let me know if it works for you. If you can't make it work, I'll help.

gemini
Offline
Joined: 04/17/2010

Now it reads hydrogen file format (h2song).

- Now it can do 4/4, 7/8, etc...
- Fails if there are more than one hit at a time on the same line (example: no hihat and cymbal or no snare and tom at the same time...)
- Fails if there are a silence on the beginning of a triplet

I would appreciate feedback if anybody is testing this.

You will need an additional library:

# apt -get install libxml-parser-perl

usage:

$ perl drums.pl thesong.h2song > song.ly
$ lilypond song.ly
$ kpdf song.pdf

leyoy
Offline
Joined: 04/17/2010

Hi,
Thank you for your work.
I have try your 2nd script with the first demo but it's tell me:
Unknown instrument. What's wrong ?

gemini
Offline
Joined: 04/17/2010

Thanks leyoy for trying it. I know there are problems.

Try this new version. Maybe some instruments will not appear in the result.

$ perl drums.pl demo1.h2song > demo.ly
$ lilypond demo.ly
$ kpdf demo.pdf

Pappa
Offline
Joined: 04/17/2010

thanks!