Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found