From Code to Community: Sponsoring The Perl and Raku Conference 2025 Learn more

#!/usr/bin/env perl
use strict;
use MIDI::Util qw(setup_score midi_format);
use Music::Scales qw(get_scale_notes);
my $score = setup_score();
# get 4 notes of the C pentatonic scale
my @pitches = get_scale_notes('C', 'pentatonic');
my @notes = map { $pitches[int rand @pitches] } 1 .. 4;
# play the 8-bar progression for each note
for my $note (@notes) {
my $prog = Music::Chord::Progression->new(
scale_note => $note,
# substitute => 1,
);
my $chords = $prog->generate;
for my $chord (@$chords) {
$score->n('wn', midi_format(@$chord));
}
print $note, ': ', ddc($chords);
}
$score->write_score("$0.mid");