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; }

Replies are listed 'Best First'.
Chord Values for MIDI::Simple
by Mr. Muskrat (Canon) on Feb 13, 2003 at 17:25 UTC
    Here is a MIDI::Simple version:
    use MIDI::Simple; 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], ); sub chord { # chord(NOTE, CHORD); # NOTE is the base note of the chord (numeric or name) # CHORD is a reference to the chord array # uses MIDI::Simple's interval procedure # returns a list of notes (numeric or name) based on the format of NOT +E my ($note, $chord) = @_; return interval $chord, $note; } my $note = 'Cs5'; # C sharp, 5th octave (D flat) my @CsMajor5 = chord2($note, $chords{major}); print "C sharp major chord, 5th octave: @CsMajor5\n"; # displays: C sharp major chord, 5th octave: Df5 F5 Af5 Df6
Re: Chord Values for MIDI
by Anonymous Monk on Feb 12, 2003 at 22:07 UTC
    Cool but where can i get MIDI.pm? I tried doing this:
    C:\>ppm PPM interactive shell (2.1.5) - type 'help' for available commands. PPM> install MIDI Install package 'MIDI?' (y/N): y Installing package 'MIDI'... Error installing package 'MIDI': Could not locate a PPD file for packa +ge MIDI PPM> quit Quit!
    Can you help?

      ActiveState has it listed as MIDI-Perl.

      So just do ppm install MIDI-Perl and it should install for you.

        That worked thanks. But I don't hear any sound? I have speakers and can hear most stuff (i.e. Realplayer and stuff off the net) Do I need special hardware too?