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

NAME

Music::Chord::Progression - Create network transition chord progressions

VERSION

version 0.0609

SYNOPSIS

  use Music::Chord::Progression;
  use MIDI::Util qw(setup_score midi_format);

  my $prog = Music::Chord::Progression->new;

  my $chord_type = $prog->substitution('m'); # m7 or mM7

  my $progression = $prog->generate;

  my $score = setup_score();
  for my $chord (@$progression) {
      $score->n('wn', midi_format(@$chord));
  }

DESCRIPTION

Music::Chord::Progression creates network transition chord progressions.

This module can also perform limited jazz chord substitutions, if requested in the constructor.

ATTRIBUTES

max

The number of chords to generate in a phrase.

Default: 8

net

The network transitions between chords of the progression.

The keys must start with 1 and be contiguous to the end.

Ending on 12 keys all the notes of the chromatic scale. Ending on 7 represents diatonic notes, given the scale_name.

If you do not wish a scale note to be chosen, include it among the keys, but do not refer to it and do not give it any neighbors. Thus, in the first example, the 7th degree of the scale will never be chosen.

Default:

  { 1 => [qw( 1 2 3 4 5 6 )],
    2 => [qw( 3 4 5 )],
    3 => [qw( 1 2 4 6 )],
    4 => [qw( 1 3 5 6 )],
    5 => [qw( 1 4 6 )],
    6 => [qw( 1 2 4 5 )],
    7 => [] }

A contrived chromatic example where each note connects to every note:

  { 1  => [1 .. 12],
    2  => [1 .. 12],
    3  => [1 .. 12],
    4  => [1 .. 12],
    5  => [1 .. 12],
    6  => [1 .. 12],
    7  => [1 .. 12],
    8  => [1 .. 12],
    9  => [1 .. 12],
    10 => [1 .. 12],
    11 => [1 .. 12],
    12 => [1 .. 12],
  }

chord_map

The chord names of each scale position.

The number of items in this list must be equal to the number of keys in the net.

Default: [ '', 'm', 'm', '', '', 'm', 'dim' ] (major scale)

Here '' refers to the major chord and 'm' means minor.

Here are the known chord mappings:

  chromatic  => [ ('m') x 12 ],
  major      => [ '',    'm',   'm',   '',    '',    'm',   'dim' ],
  ionian     => [ '',    'm',   'm',   '',    '',    'm',   'dim' ],
  dorian     => [ 'm',   'm',   '',    '',    'm',   'dim', ''    ],
  phrygian   => [ 'm',   '',    '',    'm',   'dim', '',    'm'   ],
  lydian     => [ '',    '',    'm',   'dim', '',    'm',   'm'   ],
  mixolydian => [ '',    'm',   'dim', '',    'm',   'm',   ''    ],
  minor      => [ 'm',   'dim', '',    'm',   'm',   '',    ''    ],
  aeolian    => [ 'm',   'dim', '',    'm',   'm',   '',    ''    ],
  locrian    => [ 'dim', '',    'm',   'm',   '',    '',    'm'   ],

If chord_map is not defined and a known scale_name is given to the constructor, the corresponding chord_map above, will be used.

Alternative example:

  [ 'M7', 'm7', 'm7', 'M7', '7', 'm7', 'dim7' ]

The known chord names are listed in the source of Music::Chord::Note.

scale_name

The name of the scale.

Default: major

Please see "SCALES" in Music::Scales for the allowed scale names.

scale_note

The (uppercase) name of the scale starting note with an optional # or b accidental.

Default: C

scale

The scale notes. This is a computed attribute.

Default: [C D E F G A B]

octave

The octave of the scale.

Default: 4

tonic

Set the start of the progression.

If this is given as 1 the tonic chord starts the progression. If given as 0 a neighbor of the tonic is chosen. If given as -1 a random net key is chosen.

Default: 1

resolve

Set the end of the progression.

If this is given as 1 the tonic chord ends the progression. If given as 0 a neighbor of the last chord is chosen. If given as -1 a random net key is chosen.

Default: 1

substitute

Perform jazz chord substitution.

Default: 0

Rules:

Any chord can be changed to a dominant
Any dominant chord can be changed to a 9, 11, or 13
Any chord can be changed to a chord a tritone away

sub_cond

The subroutine to determine if a chord substitution should happen.

Default: sub { int rand 4 == 0 } (25% of the time)

flat

Use flats instead of sharps in the generated chords.

Default: 0

graph

The network transition Graph object. This is a computed attribute.

Default: Graph::Directed->new

phrase

The generated phrase of named chords. This is a computed attribute.

chords

The generated phrase of individual note chords. This is a computed attribute.

verbose

Show the progress and chosen values.

METHODS

new

  $prog = Music::Chord::Progression->new; # Use the defaults

  $prog = Music::Chord::Progression->new( # Override the defaults
    max        => 4,
    net        => { 1 => [...], ... 7 => [...] },
    chord_map  => ['m','dim','','m','m','',''],
    scale_name => 'minor',
    scale_note => 'A',
    octave     => 5,
    tonic      => 0,
    resolve    => -1,
    flat       => 1,
    substitute => 1,
    verbose    => 1,
  );

Create a new Music::Chord::Progression object.

generate

  $chords = $prog->generate;

Generate a fresh chord progression and set the phrase and chords attributes.

substitution

  $substitute = $prog->substitution($chord_type);

Perform a jazz substitution on the given the chord type.

SEE ALSO

The t/01-methods.t test and eg/* example files

Carp

Data::Dumper::Compact

Graph

Moo

Music::Chord::Note

Music::Scales

AUTHOR

Gene Boggs <gene@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2020-2023 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.