Blues in C:C C C C F F C C G G C C

Ok, I blew the 7ths. Eh.

So many 3 chord songs, so little refactoring time...
Produced by:
use strict; sub build_scale { # The parameter is the key of the scale # as in "what key is a bicycle in? B flat" my $key = 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[($key + $intervals[$_]) % 12]} (0..7); return @scale; } sub blues_in { my $key = shift; my @scale = build_scale($key); #my @blues = qw( 1 1 1 1 4 4 1 1 5 4 1 1); my @blues = qw( 0 0 0 0 3 3 0 0 4 4 0 0); print "Blues in $scale[0]:", join (" ", map {$scale[$_]} @blues),"\n"; } sub chord_progression { my @scale = build_scale( shift); # 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($_); blues_in($_); }

In reply to Re: Music: Calculate Chord Progression Triads by jimX11
in thread 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.