Didn't work for you? This is a rough implementation which surely has some bugs.
Send me a message and I'll investigate. Please attach your MusicXML and a description of the problem.
Inspired by Peter Edwards' Coursera course: Write Like Mozart: An Introduction to Classical Music Composition.
Source code available @ https://github.com/greghmerrill/voice-leading