tunemidi.c: microtune a MIDI file. Author: Kees van den Doel kvdoel@cs.ubc.ca This program reads a MIDI file and creates a new MIDI file with customized tuning, specified on the command line. You tell it how many cents (1/100 of a semitone) it should change the 12 pitches, relative to equal temperament. source: tunemidi.c platform: UNIX (trivially portable, only unlink() seems nonportable) compile: cc -o tunemidi tunemidi.c usage: tunemidi c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 [infile [outfile]] c1,..,c12 are the fine tunings of pitches starting from C, in cents. Maximal +-200 cent. If no outfile specified writes on standard output. If no input file specified reads from standard input and writes on standard output. Will change tuning of input MIDI file infile. For example, if song.mid contains a MIDI file in shur in E, the F should be 40 cent sharp. tunemidi 0 0 0 0 40 0 0 0 0 0 0 song.mid song2.mid will create file song2.mid in the correct tuning. You probably also want to flatten the G and the C by 15 cent or so, with tunemidi -15 0 0 0 40 0 -15 0 0 0 0 song.mid song2.mid BUGS and limitations: Assumes that your sytnhesizer has pitch bend range set to 2 semitones up and down. You can change this in the code trivially. I should clean this up. The input file must contain ONLY MONOPHONIC TRACKS (no chords inside a track). You can have as many tracks as you want, but they must all be on different MIDI channels. This is a fundamental limitation of MIDI, since pitchbend is channelwide. I see no way around this. The input file should not contain any pitchbend commands already before processing. They will interfere with the pitchbends inserted. This should be fixed by an extra pass, removing the pitchbends already in the file. If that's important to anyone, I may fix that. You must have write permission in the directory you run tunemidi from. This is because a temporary file is created. I am definitely too lazy to worry about that. Kees