I've been playing guitar for 31 years (good lord I'm old). But I only recently got interested in learning the theory behind chord progressions. I wrote this simple piece of code to calculate major triad chord progressions in all of the keys. I suppose it could be extended easily to create minor chord progressions as well. Disclaimer: I am not sure about the music terminology I used in my comments.
use strict; sub chord_progression { # The parameter is the index of the root note in the @notes array my $i = shift; my @notes = ('C', 'C#/Db', 'D', 'D#/Eb', 'E', 'F', 'F#/Gb', 'G', 'G#/Ab', 'A', 'A#/Bb', 'B'); my @intervals = (0, 2, 4, 5, 7, 9, 11, 12); # Create a scale based on the intervals in a major scale my @scale = map {$notes[($i + $intervals[$_]) % 12]} (0..7); # Create triads. Increment each note within the scale. # All notes in the chord progression fall within the # major scale. my ($root, $third, $fifth) = (0, 2, 4); my @name = ('Maj', 'min', 'min', 'Maj', 'Maj', 'min', 'Dim', 'Maj' +); for (0..7) { printf "%6s %3s: %6s, %6s, %6s\n", $scale[$root], $name[$_], $scale[$root], $scale[$third], $scale[$fifth]; $root++; $third++; $fifth++; $root %= 7; $third %= 7; $fifth %= 7; } print "\n"; } # Call the subroutine for each note in the scale for (0..11) { chord_progression($_); }
This creates output like this:
     C Maj:      C,      E,      G
     D min:      D,      F,      A
     E min:      E,      G,      B
     F Maj:      F,      A,      C
     G Maj:      G,      B,      D
     A min:      A,      C,      E
     B Dim:      B,      D,      F
     C Maj:      C,      E,      G

 C#/Db Maj:  C#/Db,      F,  G#/Ab
 D#/Eb min:  D#/Eb,  F#/Gb, A#, Bb
     F min:      F,  G#/Ab,      C
 F#/Gb Maj:  F#/Gb, A#, Bb,  C#/Db
 G#/Ab Maj:  G#/Ab,      C,  D#/Eb
A#, Bb min: A#, Bb,  C#/Db,      F
     C Dim:      C,  D#/Eb,  F#/Gb
 C#/Db Maj:  C#/Db,      F,  G#/Ab

...

In reply to Music: Calculate Chord Progression Triads by zeno

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.