NAME

Music::Cadence - Generate musical cadence chords

VERSION

version 0.1307

SYNOPSIS

use Music::Cadence;

my $mc = Music::Cadence->new;

my $chords = $mc->cadence;
# [G B D], [C E G C]

$mc = Music::Cadence->new( octave => 4 );

$chords = $mc->cadence;
# [G4 B4 D4], [C4 E4 G4 C5]

$chords = $mc->cadence(
  type    => 'half',
  octave  => 0,
  leading => 2,
);
# [D F A], [G B D]

$chords = $mc->cadence(
  type      => 'imperfect',
  inversion => { 1 => 1, 2 => 1 },
);
# [B4 D4 G5], [E4 G4 C5]

$mc = Music::Cadence->new(
  key    => 'C#',
  octave => 5,
);

$chords = $mc->cadence;
# [G#5 C5 D#5], [C#5 F5 G#5 C#6]

$mc = Music::Cadence->new(
  key    => 'C#',
  octave => 5,
  format => 'midi',
);

$chords = $mc->cadence;
# [Gs5 C5 Ds5], [Cs5 F5 Gs5 Cs6]

$mc = Music::Cadence->new( format => 'midinum' );

$chords = $mc->cadence( octave => 4 );
# [67 71 62], [60 64 67 72]

$chords = $mc->cadence( octave => -1 );
# [7 11 2], [0 4 7 12]

$mc = Music::Cadence->new( seven => 1 );

$chords = $mc->cadence;
# [G B D F], [C E G A# C]

$chords = $mc->cadence(
  type   => 'evaded',
  octave => 4,
);
# [F4 G5 B5 D5], [E4 G4 A#4 C5]

DESCRIPTION

Music::Cadence generates a pair of musical cadence chords.

These chords are usually added to the end of a musical phrase, and are used to suggest a sense of anticipation, pause, finality, etc.

ATTRIBUTES

key

The key or tonal center to use, in isobase format.

Default: C

Examples: G#, Eb

scale

The modal scale to use. Default: major

Supported scales are:

ionian / major
dorian
phrygian
lydian
mixolydian
aeolian / minor
locrian

octave

The octave to either append to named chord notes, or to determine the correct midinum note number.

Default: 0

If the format is midi or the default, setting this to 0 means "do not append." Setting it to a positive integer renders the note in ISO format.

The midinum range for this attribute should an integer from -1 to 9 (giving note numbers 0 to 127).

format

The output format to use.

Default: isobase (i.e. "bare note names")

If midi, convert sharp # to s and flat b to f after chord generation.

If midinum, convert notes to their numerical MIDI equivalents.

seven

If set, use seventh chords of four notes instead of diatonic triads.

Default: 0

METHODS

new

$mc = Music::Cadence->new;  # Use defaults

$mc = Music::Cadence->new(  # Override defaults
  key    => $key,
  scale  => $scale,
  octave => $octave,
  format => $format,
  seven  => $seven,
);

Create a new Music::Cadence object.

cadence

$chords = $mc->cadence;     # Use defaults

$chords = $mc->cadence(     # Override defaults
  key       => $key,        # See above
  scale     => $scale,      # "
  octave    => $octave,     # "
  type      => $type,       # Default: perfect
  leading   => $leading,    # Default: 1
  variation => $variation,  # Default: 1
  inversion => $inversion,  # Default: 0
);

Return an array reference of the chords of the cadence type based on the given key and scale name.

Supported cadences are:

deceptive
evaded
half
imperfect
perfect
plagal

The variation applies to the deceptive and imperfect cadences.

If the type is deceptive, the variation determines the final chord. If it is set to 1, the vi chord is used. For 2, the IV chord is used.

If the type is imperfect and there is no inversion, the variation determines the kind of perfect cadence generated. For 1, the highest voice is not the tonic. For 2, the fifth chord is replaced with the seventh. So in a major key, the V chord would be replaced with the vii diminished chord.

For an imperfect cadence, if the inversion is set to a hash reference of numbered keys, the values are the types of inversions to apply to the chords of the cadence. For example:

inversion => { 1 => 2, 2 => 1 },

This means, "Apply the second inversion to the first chord of the cadence, and apply the first inversion to the second chord."

For seventh chords (of 4 notes), the third inversion can be applied.

To not apply an inversion to an inverted imperfect cadence chord, either do not include the numbered chord in the hash reference, or set its value to 0 zero.

The leading chord is a number (1-7) for the scale chord to use for the first half cadence chord. For the key of C major this is:

CM: 1
Dm: 2
Em: 3
FM: 4
GM: 5
Am: 6
Bo: 7

If an inversion is defined for the half cadence, the chords are inverted as described above for the imperfect cadence.

The evaded cadence applies inversions to seventh chords. The default (with no inversion defined) is to invert the first chord by the third inversion and the second by the first inversion.

SEE ALSO

The eg/cadence, eg/synopsis, t/01-methods.t and t/02-methods.t files in this distribution.

Moo

Music::Chord::Note

Music::Chord::Positions

Music::Note

Music::Scales

Music::ToRoman

https://en.wikipedia.org/wiki/Cadence

https://www.musictheoryacademy.com/how-to-read-sheet-music/cadences/

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by Gene Boggs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.