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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |