Hi Jean,
(let* ((tones (ly:pitch-tones pitch)) (r (ly:moment-main (ly:moment-mod (ly:make-moment tones 0) (ly:make-moment 6 0))))
... using LilyPond's moment-arithmetic (number on the time axis) to deal with non-integer tone counts (numbers on the pitch axis) seems to me like a reasonable contender for an obfuscated Lily coding contest. :-) But impressive it is.
Maybe it's worth pointing out that your solution hardwires enharmonic identification (if I'm not mistaken). Of course I don't know what the OP intends to do, but in lots of real-life applications for re-tuning it's worth keeping the difference between f-sharp and g-flat alive.
As Graham pointed out, LilyPond's habit of setting pitch bends before a note and re-setting it immediately after a note whose alteration is not in 1/2 * Z leads to strange effects with the release (or reverb) of a note. This can be observed in examples involving rests between re-tuned notes. I patched my LilyPond for this: Now it never explicitly resets MIDI pitch bends, instead each and every note gets a pitch-bend command. (Which would be crazy for most applications, but is fine for my special needs involving lots of re-tuned notes.) I didn't have time to find out how to make this user-configurable. - I'm already looking forward to Graham's solution to this problem (post-processing the MIDI files using MTS messages.
Lukas
