[LAU] Converting Midi file data to play on guitar

Edgar Aichinger edogawa at aon.at
Tue Mar 10 17:42:32 EDT 2009

Am Dienstag 10 März 2009 schrieb Nathanael Anderson:
> I'm working on some python scripts to mangle midi input data from a file,
> and am hoping I can get some input from others that have thought about it as
> well. These are some major issues and possible solutions I've seen.
> 1. When a chord is seen in the midi file: the correct voicing of the chord
> must be found on the guitar neck, and where multiple, which to use must be
> decided.
> 2. When picking notes: if based off a chord, that chord should be
> identified, so the user knows how to position their hand for the playing to
> feel natural.
> 3. When playing lead riff's, try to smoothly move between scale positions,
> and not stay on just 1 string.

About ten years ago (on Atari/MiNT) I wrote a C program similar to this, but 
for baroque lute tabulature... I wanted it to help me transform any midifile 
I was interested in, be it classical orchestral or chamber works, piano works 
or pieces for classical guitar, in a semi-automatic way, to Wayne Cripp's 
lutetab code, and it worked out surprisingly good, given that I was a 
lousy DIY hacker ;) (I don't really code anymore).

I didn't care much about 2) and 3) but for 1) I came up with an algorithm like 
 - determine the string on which the pitch can be played at the lowest fret 
 - check if this string is used already, and if yes move this note to the next 
   (lower) string

For notes lower than the instrument range (13 course lute goes down to A, a 5th 
lower than guitar) I chose to just place a comment in the tab output, so that I 
would be able to decide afterwards what to do with that note (transpose up an 
octave, skip it, whatever).

Since it's been a long time now I can't remember how I dealt with files 
containing more than one track, but I somehow managed to merge them into a 
single tabulature, I have for example produced nice tabulatures of the 
accompaniment of the first three movements of Pergolesi's Stabat Mater.
For these of course I had to prepare the midifiles, remove the voice tracks 
and transpose to a key suitable to the lute.

Other problems I've encountered and I'm not sure if or how I solved them:
 - the bar/beat counting got screwed up sometimes, especially with grace notes 
 - of course, I had to remove double notes when boiling down ensemble works
 - there are different lute tunings, I only dealt with standard baroque 
   d-minor tuning
 - on the lute, the diatonic basses (lower than the 6th course) are tuned to 
   the key of the piece

The thing is based on the ancient midifile(3) lib by Tim Thompson et al. which 
is a little gem IMHO. The library parses the midifile, all you have to do is 
to write a few callback functions for the events you're interested in. Some 
example code is in the archive, and it took me just a few days to come up with 
something useful.

I never seriously thought about releasing it, even after I compared it's 
output's quality to what Django can do (an impressive M$ tabulature editor, 
mainly for historic fretted instruments, the demo from 
http://musickshandmade.com/lute/pages/django runs quite well in wine) and 
found that I was doing pretty well. :) 

I'm sure there are stupid things in there and it's not at all in a releasable 
state, but if you are interested I'll share the code...

> Sofware I'm workikng with
> pyrtmidi: live midi input data
> pythonmidi: file midi input data
> pychorelib: identify chords based on notes played in midi files/streams
> Sofware I've looked at that somewhat relates to this:
> dguitar
> kguitar
> neither dguitar or kguitar support any intelligent handling for guitars to
> actually make loading a midi file and playing from it useable.
> Why python?
> 1. I want to be able to have the output data from this be useable by other
> software.
> 2. I'm playing around with some idea's in blender, hence using python makes
> sense.
> Why not python?
> 1. I'm a bit new to python
> 2. I'd rather be coding in perl ;)
> Any feedback, links to similar work, or ideas are greatly appriciated.
> Nathanael


More information about the Linux-audio-user mailing list