Primus got me interested in creating MIDI chords in Perl. So I started researching and this is what I came up with. The BASE_NOTE can be attained in different ways depending on which module you are using. See the example.

Update: NOTE: This only creates the note values. It does not play them.

use MIDI; # for example usage my %chords = ( major => [0, 4, 7, 12], minor => [0, 3, 7, 12], major7 => [0, 4, 7, 11], minor7 => [0, 3, 7, 10], minor75 => [0, 3, 6, 10], dim => [0, 3, 6, 9], dom7 => [0, 4, 7, 10], major9 => [0, 4, 7, 11, 14], minor9 => [0, 3, 7, 10, 14], ); my $note = 'Cs5'; # C sharp, 5th octave my $base = $MIDI::note2number{$note}; # 61 my @CsMajor5 = chord($base, @{$chords{major}}); print "C sharp major chord, 5th octave: @CsMajor5\n"; # output: C sharp major chord, 5th octave: 61 65 68 73 sub chord { # BASE_NOTE is the numeric value of the first note # CHORD is a chord array my ($base, @chord) = @_; return map { $_ += $base; } @chord; }

In reply to Chord Values for MIDI by Mr. Muskrat

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.