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

#!/usr/bin/env perl
use strict;
my $max = shift || 8;
my $d = MIDI::Drummer::Tiny->new(
bpm => 100,
file => "$0.mid",
kick => 'n36',
snare => 'n40',
signature => '5/4',
);
$d->sync(
\&cymbals,
\&beat,
);
$d->write();
sub cymbals {
for my $beat ( 1 .. $max ) {
if ( $beat % 3 == 0 ) {
$d->note( $d->eighth, $d->crash2 );
}
else {
$d->note( $d->eighth, $d->open_hh );
}
$d->note( $d->eighth, $d->closed_hh ) for 1 .. 9;
}
}
sub beat {
for my $beat ( 1 .. $max ) {
$d->note( $d->quarter, $d->kick );
$d->note( $d->quarter, $d->snare );
$d->note( $d->quarter, $d->snare );
$d->note( $d->quarter, $d->kick );
$d->note( $d->quarter, $d->snare );
}
}