canonical - compute canon voices via the Music::Canon module


  $ canonical --contrary --retrograde exact c cis d
  $ canonical --transpose=12 exact c e g
  $ canonical --raw --contrary exact 1 2 3

  $ canonical modal --input=lydian --output=locrian c e g


Command line interface to mapping methods present in the Music::Canon module. Custom questions might be better answered by coding directly against Music::Canon, see the eg/ directory under the distribution of that Perl module for examples.


This script currently supports the following global command line switches. These can also be specified to each of the underlying modes.

--contrary --nocontrary

Whether to compute output line in contrary motion or not.


Emit some help information and exit.

--raw --noraw

Whether to emit output in raw pitch numbers or lilypond note names.


Use relative mode in Music::LilyPondUtil and make the input notes relative to the specified note. Without this option, the assumption is that the lilypond input is specified in absolute form:

  g d\'                 # MIDI pitches 55 62 (absolute)
  --relative=g\' g d\'  # MIDI pitches 67 74 (relative to g' or 67)
--retrograde --noretrograde

Whether to reverse the output phrase or not.


Transpose to the first note of the output phrase by the specified amount in semitones (integer) or to the specified lilypond note name.



Exact interval canon computation. No new options beyond the global ones listed above.

  $ canonical exact --transpose=e c e g

Modal interval canon computation. In addition to the global options listed above, accepts:


Scale name (see Music::Scales) or Forte Number to use for the input. A colon delimits the ascending versus descending data; commas delimit specific scale degrees. Examples:


See Music::Canon for the algorithm that maps input to output mode.


Allow non-octave scales. Necessary if the scale intervals sum up to more than 12, or if scales must repeat before the usual 12-pitch octave point.


Like --input, except for the output line.


String to use for notes or pitches that cannot be converted. If unset, defaults to x. For example, under contrary motion, using Major to Major scales, C to D via C sharp is impossible, as there is no space between C and B downwards in the output line for the chromatic C sharp:

  $ canonical --relative=c modal --contrary --undef=OOPS c cis d
  c OOPS b


A ZSH completion script is available in the zsh-compdef/ directory of the App::MusicTools distribution. Install this to a $fpath directory.


Reporting Bugs

If the bug is in the latest version, send a report to the author. Patches that fix problems or add new features are welcome.

SEE ALSO and in particular the Learning and Notation manuals should be consulted to understand lilypond note syntax. Or, use raw pitch numbers.

Music::Canon, Music::LilyPondUtil, Music::Scales


Jeremy Mates


Copyright (C) 2013 by Jeremy Mates

This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.16 or, at your option, any later version of Perl 5 you may have available.