The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Music::Tension::Counterpoint - interval tests for strict counterpoint

SYNOPSIS

  use Music::Tension::Counterpoint;
  my $cpt = Music::Tension::Counterpoint->new;

  # tritone, dissonant
  $cpt->pitches(0, 6);      # 0

  # perfect fifth, consonant
  $cpt->pitches(0, 7);      # 1

  # A below D, negative fourth, dissonant
  $cpt->pitches(74, 69);    # 0

  # D F E D against A C B A at each possible offset
  my @tensions = $cpt->offset_tensions(
      [qw/62 65 64 62/], [qw/69 72 71 69/]
  );

  # what offsets from offset_tensions are all consonant?
  my @consonant_offsets = $cpt->usable_offsets(
      [qw/62 65 64 62/], [qw/69 72 71 69/]
  );

  # consideration of chords (or pitch sets)
  $cpt->vertical( [qw/60 64 67 72/] );  # 1
  $cpt->vertical( [qw/60 64 66 72/] );  # 0

DESCRIPTION

Strict counterpoint rates intervals as acceptable or not acceptable depending on the horizontal or vertical intervals involved. There may be allowances for certain vertical dissonances that can be resolved by ties or suspensions, and there may be allowances for dissonances that use an interval larger than an octave, but then maybe negative points for letting the voices wander too far apart. Anyways, rating intervals in a boolean fashion is possible with this module.

If you need more complexity consider instead Music::Tension::Cope, or perhaps copy and modify this code to suit the rules system in question. The allowed intervals can be customized via tensions and interior.

CAVEATS

No consideration of mode is made; chromatic intervals alien to a particular mode (or scale) may be rated as consonant by this module. Music::Scales could help with modal considerations.

This module is fixed to a 12 tone system.

METHODS

Any method may croak if something is awry with the input. Methods are inherited from the parent class, Music::Tension.

new optional params

Constructor. Accepts optional parameters that specify alternate values instead of the defaults.

  • big_dissonance is a boolean that controls whether dissonant intervals greater than an octave are allowed. They are allowed by default.

  • interior must be a hash reference that must contain all intervals from 0 to 11 inclusive. This hash is used to check interior voice intervals (if any) in the pitch set (chord) passed to the vertical method. The default values follow Norden 1969 and are more relaxed than what tensions permits.

    The values for the intervals are treated as booleans where 0 indicates dissonance and 1 consonance.

  • octave_allow is a boolean that indicates whether the octave is allowed. Octaves are allowed by default. This flag is necessary because a rules system might disallow the unison of two notes but allow for octaves of the same; octaves would otherwise be modulated down and treated as a unison.

  • tensions must be a hash reference that must contain all intervals from -11 to 11 inclusive. The default values are typical but may need to be adjusted for melodic use or different opinions of counterpoint, such as the style that treats the perfect fourth as consonant.

    The values for the intervals are treated as booleans where 0 indicates dissonance and 1 consonance.

pitches pitch1, pitch2

Accepts two pitches (integers) and returns a boolean indicating whether the interval formed is consonant or not. If pitch1 is higher than pitch2 a negative interval will be used; this is why tensions requires negative interval values.

usable_offsets phrase1, phrase2

Calls offset_tensions (from Music::Tension) with the given phrases (array references of integers) and returns a list of the non-zero offsets that have only consonant intervals between the two phrases. If any; otherwise, the empty list is returned.

This is suitable for canon, fugue, or imitation where having a phrase (possibly one that has been fiddled with according to various rules set down many centuries ago) that can be used with the original phrase at different offsets is desirable.

See eg/dorian-fugue-subject in this module's distribution for an example use of this method.

vertical pset

Accepts an array reference that should be a list of integers. Returns a boolean indicating whether the pitches are consonant or not. The lowest (or root) pitch will be checked for consonance (via pitches, and thus the tensions table) against every higher pitch. The other pitches, if possible, will each be checked against any higher pitches using the interior interval table.

Interior pitches will also follow the rules for octave_allow and big_dissonance.

MELODY

Allowed horizontal (melodic) intervals depend on the rule system; Norden 1969 allows for:

  use constant { DISS => 0, CONS => 1 };

  my $melody = Music::Tension::Counterpoint->new(
      octave_allow => 1, # octaves are okay
      tensions     => {
          0   => DISS,   # repeated notes
          1   => CONS,   # minor second
          2   => CONS,   # major second
          3   => CONS,   # minor third
          4   => CONS,   # major third
          5   => CONS,   # fourth
          6   => CONS,   # the evil, evil tritone
          7   => CONS,   # fifth
          8   => CONS,   # minor sixth
          9   => DISS,   # major sixth
          10  => DISS,   # minor seventh
          11  => DISS,   # major seventh
          -1  => CONS,
          -2  => CONS,
          -3  => CONS,
          -4  => CONS,
          -5  => CONS,
          -6  => CONS,
          -7  => CONS,
          -8  => CONS,
          -9  => DISS,
          -10 => DISS,
          -11 => DISS,
      }
  );
  
  # repeated note, not okay (okay in 1st species)
  $melody->pitches( 60, 60 );     # 0

Norden however recommends a direction change and step following a tritone leap, various restrictions to avoid outlining certain chords over multiple horizontal intervals, and other such complications. Those would need more code to support. Other authors restrict the use of tritone leaps in melody as being difficult to sing, or may allow for upwards leaps of a minor 6th but not downwards ones, etc.

SEE ALSO

  • "Fundamental Counterpoint", Hugo Norden, 1969.

  • "Polyphonic Dissonance", Jeremy Mates, 2019. https://github.com/thrig/music/musicref

  • "The Study of Fugue", Alfred Mann, 1965.

AUTHOR

thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2021 by Jeremy Mates

https://opensource.org/licenses/BSD-3-Clause