NAME
Music::SimpleDrumMachine - Simple 16th-note-phrase Drummer
VERSION
version 0.0301
SYNOPSIS
use Music::SimpleDrumMachine ();
my $dm = Music::SimpleDrumMachine->new( # use defaults
port_name => 'midi device',
);
# OR:
$dm = Music::SimpleDrumMachine->new(
port_name => 'midi device',
bpm => 100,
next_part => 'part_A',
parts => {
part_A => \&part_A,
part_B => \&part_B,
},
fills => { fill_A => \&fill_A },
next_fill => 'fill_A',
verbose => 1,
);
sub part_A {
print "part A\n";
my %patterns = (
hihat => [qw(1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0)],
kick => [qw(1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1)],
snare => [qw(0 0 0 0 1 0 0 0 0 0 0 0 1 0 1 0)],
);
my $next = 'part_B';
return $next, \%patterns;
}
sub part_B {
print "part B\n";
my %patterns = (
hihat => [qw(1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)],
kick => [qw(1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0)],
snare => [qw(0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0)],
);
my $next = 'part_A';
return $next, \%patterns;
}
sub fill_A {
print "fill_A\n";
my %patterns = (
snare => [qw(1 0 1 0 1 1 1 1 0 1 0 1 1 0 1 0)],
hihat => [ (0) x 16 ],
open => [ (0) x 16 ],
kick => [ (0) x 16 ],
tom => [ (0) x 16 ],
);
my $next = 'fill_A';
return $next, \%patterns;
}
DESCRIPTION
Music::SimpleDrumMachine is a simple 16th-note-phrase drummer. By invoking this module, your MIDI device will begin playing in real-time.
ATTRIBUTES
add_drums
add_drums => \%drums,
Add an array-ref of hash-refs of the form [{ drum => 'name', num => midi_num, chan => channel }] to the known drums in the constructor. The chan key is optional and is only necessary if you want to assign a drum to a specific channel.
beats
$beats = $dm->beats;
The number of beats in a phrase.
Default: 16
bpm
$bpm = $dm->bpm;
The beats per minute.
Default: 120
chan
$chan = $dm->chan;
The MIDI channel.
If the channel is set to -1, multi-timbral mode is turned on and channels 0, 1, ... and up are used, instead of a single channel for all the percussion.
Default: 9
divisions
$divisions = $dm->divisions;
The number of divisions of a quarter-note into the number of beat-notes. For the default, this is the number of divisions of a quarter-note to get 16ths.
Default: 4
drums
$drums = $dm->drums;
$dm->drums($drums);
The known drums.
Default:
kick => { num => 36, chan => ..., pat => [] },
snare => { num => 38, chan => ..., pat => [] },
hihat => { num => 42, chan => ..., pat => [] },
open => { num => 46, chan => ..., pat => [] },
crash => { num => 49, chan => ..., pat => [] },
fills
$fills = $dm->fills;
$dm->fills($fills);
List of code-refs of the fills to play.
Default: [\&_default_fill]
filling
$filling = $dm->filling;
$dm->filling($boolean);
Do we fill between parts?
next_fill
$next_fill = $dm->next_fill;
$dm->next_fill($next_fill);
Name of the fill to play first and set subsequently in a fill.
Default: '_default_fill'
next_part
$next_part = $dm->next_part;
$dm->next_part($next_part);
Name of the part to play first and set subsequently in a part.
Default: '_default_part'
notes
$notes = $dm->notes;
$dm->notes($notes);
The notes to set for each drum - why not?
Default: [60, 64, 67]
parts
$parts = $dm->parts;
$dm->parts($parts);
List of code-refs of the parts to play.
Default: [\&_default_part]
port_name
$port = $dm->port_name;
The name of the MIDI output port.
Default: usb
ppqn
$ppqn = $dm->ppqn;
The "pulses per quarter-note" or "clocks per beat."
Default: 24
prefill_part
$prefill_part = $dm->prefill_part;
Code-ref of the part to play for 1/2-bar fills.
Default: \&_default_part
verbose
$verbose = $dm->verbose;
Show progress.
METHODS
new
$dm = Music::SimpleDrumMachine->new(verbose => 1);
Create a new Music::SimpleDrumMachine object.
SEE ALSO
The eg/*.pl programs in this distribution.
AUTHOR
Gene Boggs <gene.boggs@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Gene Boggs.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.