melody.py generates random 10-note first species counterpoint melodies by first finding a random cantus firmus melody that matches a set of heuristics and then finding an appropriate counterpoint melody. A total of 16 heuristics are used for each individual melody and 4 heuristics are used to match two melodies in counterpoint. Results are outputted as MIDI files using Pyknon and then played using Timidity.
1. Try It Now! 2. Video Demonstration 3. Usage 3.1. Installation 3.1.1. Ubuntu / Debian 3.1.2. Other 3.2. Running melody.py 3.2.1. Command-line interface 3.2.2. Web interface 4. Heuristics Used 4.1. For each individual melody 4.2. To match cantus firmus melody to first species melody 5. Wish List
I've spun up an Amazon EC2 instance.
You can use melody.py through the command-line or by running a small web server. The advantage of the latter is that you'll also be able to see generated sheet music.
sudo apt-get install python3-pip timidity
pip3 install git+https://github.com/kroger/pyknon.git
If you wish to use the web interface, also run
pip3 install flask
If you wish to use the web interface, also install Flask. If you're using Internet Explorer (which supports MP3 but not WAV audio sources), make sure FFmpeg is installed.
python melody.py
will loop forever, generating new melodies continuously. Mash Ctrl-C a few times to stop it.
python app.py
Then go to localhost:5000
(or whatever port is chosen).
Both the cantus firmus and the first species must satisfy the following rules:
- No repeated notes in cantus firmus (one repetition allowed in first species).
- No leaps that are an octave or larger.
- No dissonant leaps.
- Between two and four leaps in total.
- Has a climax (highest note) that is not on the tonic or leading tone.
- Changes direction at least two times.
- No note repeated more than 3 times.
- Final note approached by a step (not a leap).
- Leaps larger than M3 must be followed by a change of direction.
- The leading tone must always be followed by the tonic.
- No more than two consecutive leaps in the same direction.
- The same interval cannot occur twice in a row.
- No noodling (that is, patterns such as N1 N2 N1 N2, for some notes N1 and N2).
- No runs of more than four consecutive notes.
- No unresolved melodic tension (that is, the start and end note of each run must be consonant together).
- No repeated three-note patterns.
Together, the cantus firmus and the first species must satisfy the following:
- No dissonant vertical intervals.
- No vertical intervals larger than a 12th (P8 + P5).
- No parallel fifths or octaves.
- No parallel three-note chains.
- minor key support
- support for other kinds of counterpoint
- support for melodies of other lengths (with rules tuned appropriately)
- ability to import existing cantus firmus (as MIDI or note array)
- minor: treating repeated notes as a single note of double duration rather than two separate notes