Caveat compositor: I made this in high school, before I really understood what I was doing. All counterpoint PHILOMENA is capable of realizing satisfies the first-order Markov property, so there's Viterbiesque algorithm which actually computes every legal chord progression for a given set of rules in polynomial time. The implementation described here is embarassingly suboptimal. I've coded up a version of the proper algorithm; some day I may clean it up enough to post it online. Until then, the details are left as an exercise for the reader.
PHILOMENA is a program designed to part write against a bassline based on an arbitrary set of rules. It contains a small declarative language for describing acceptable part writing rules, and can be used to generate both classical harmonic progressions and more unconventional harmonizations. And it’s on github!
PHILOMENA’s primary purpose is, naturally, to do my music homework for me, but when it is finished it should be an extremely powerful tool for describing and realizing the full scope of possible four-part harmonies.
Brute force.
More descriptively, PHILOMENA takes as input a file describing a bassline and another containing part-writing rules, and then iterates through all possible configurations of voices until it finds one matching the rules. In order to introduce variety into pieces and aid in finding more difficult solutions, there is an added 50% probability that any given chord will be rejected (this number is currently a fixed constant in the code, but will be adjustable from the rule file in future versions). If no solution is found, PHILOMENA will return to the beginning and try again. As such, the program is Ω(n) for both the length of the bassline and the number of rules. As a result of the random factor, the program is technically not guaranteed to terminate; in practice, I can usually find a solution with the root-position, major rule set in a few seconds.
The program outputs to a LilyPond file that can be used to produce a PDF or midi.
All notes are given an absolute scale degree such that the lowest Do is 0, Dis is 1, Re is 2 and 12 represents an octave above the lowest Do. A bassline file (.pmb) is just a series of these notes separated by spaces. PHILOMENA doesn’t currently support notes of different durations, though this is easily changed by editing the .ly file produced as output.
A sample bassline:
4 5 7 9 5 2 7 0
* ^0,5,7 +4 +7 +12
(if the bass has Do, Fa or So add a M3 in the tenor, a P5 in the alto and a P8 in the soprano)
* ^2,4,9 +3 +7 +12
(if the bass has Re, Mi or La add a m3 in the tenor, a P5 in the alto and a P8 in the soprano)
* ^11 +3 +6 +12
(if the bass has Ti add a m3 in the tenor, a °5 in the alto and a P8 in the soprano)
~ ^? +7 ? ? : ^? +7 ? ? ~ ^? ? +7 ? : ^? ? +7 ? ~ ^? ? ? +7 : ^? ? ? +7 ~ ? ^? +7 ? : ? ^? +7 ? ~ ? ^? ? +7 : ? ^? ? +7 ~ ? ? ^? +7 : ? ? ^? +7
~ ? ? ? 11,23,35 : ? ? ? >'1 ~ ? ? ? 11,23,35 : ? ? ? <.0
(Forbid the soprano from moving to any note that is more than a semitone greater or any lower note)