Correct cantus firmus


CA1 cantus firmus correction algorithm analyses and corrects a melody (cantus firmus) by searching for minimum combination of changes, which result in minimum rule violations penalty. Each note in cantus firmus should have the same note length and there should be no pauses inside. Example of cantus firmus:

Cantus firmus ("fixed song") is a pre-existing melody forming the basis of a polyphonic composition. It is also used to write counterpoint exercises by superimposing additional voices above or below it.

The rules that are used for cantus firmus correction are the same as used for CF1 cantus firmus generation algorithm. They can be enabled or disabled by user and their severities can be changed. For generating and correction of cantus firmus mainly Cantus and Melody rule groups are used. By default the rules are tuned to produce a vocal cantus firmus starting and ending with a tonic note.

Melody (cantus firmus) can be uploaded in a MIDI file (notes may have different length, but there should be no pauses inside).

There can be multiple cantus firmi in an uploaded file, but there must be pause between adjacent cantus firmi. Multiple cantus firmi in one file is only recommended for advanced users, because it increases complexity and makes debugging more difficult.

Only two modes are supported:

  • Natural major
  • Melodic minor

Correction parameters

Key generator input parameters:

  • Enable or disable rules, change their severities
  • Time for correction

Due to the nature of algorithm and large number of rules used, correcting long melody can take long. Time needed to correct cantus increases with the length of cantus. If time needed to correct cantus exceeds specified limit, best found correction will be returned. You will find mistakes in PDF file. You can decrease number of mistakes left after correction by increaseing time parameter.

In expert mode user can also change other parameter in text configuration:

  • Specify if uploaded cantus firmus is for for soprano (cantus_high=1) or bass (cantus_high=0) voice. By default cantus firmus is considered to be for bass. Changing this parameter results in minor changes of some rules (first notes, cadential progression in the middle of cantus firmus) - which are also noted in comments to these rules.

Other parameters in config should be changed only if you know what you are doing.

Correction results

Corrected melody is output in MIDI and PDF files in a separate staff above initial melody. Notes, that were corrected, are circled in source melody:

The lower staff will show mistakes that were detected in source melody. If you see no mistakes in corrected melody, this means that correction process was able to finish.


Problem Solution
Correction takes long Try decreasing allowed time for correction. If resulting corrected melody shows many mistakes, you will need to increase time and wait.
Correction fails with error First try to restart the processing. If this does not help, try to unroll your latest changes, which could result in the error. In Expert mode on the Config tab you will find history of all your changes under the Save button. Pay attention that due to complex correction algorithms, some combinations of rules severities can result in unexpected behaviour. Try to set rules severities back to their default values or create new correction task. If you applied any changes previously, you will find default values in "Rule changes" box under the rules tree on the Settings tab. Also, keep in mind that trying to correct too long cantus can result in mistakes in corrected melody due to timeout. Try decreasing length of cantus or increasing allowed time for correction in settings.

If you cannot find solution to your problem, please create support request (menu Support)


See playback section.

How algorithm works

Correction algorithm uses same SWA algorithm, that is described in CF1 cantus generation algorithm.

The only important difference is that instead of trying to generate a new cantus, system tries to find cantus with not only has minimum rule penalty, but also has minimum difference from the source melody by calculating Distance from source melody (each changed note adds penalty of 3 point + 1 point for each semitone of change). For example changing one note from C to E note will add 7 to distance (which is 3 for one note and 4 for 4 semitones). This means that if there are multiple variants with same rule penalty, the variant with least distance from source melody will be selected.

The longer correction time is specified in the file settings, the more precise result you will get. Even if solution is found without any mistakes, there is always a small probability of finding a better solution without mistakes, which is closer to source melody. The general approach used in SWA algorithm (note variants are ordered by increasing distance penalty from source melody) usually guarantees that the first solution without mistakes will have lowest distance penalty or close to lowest.