NAME
MIDI::Simple::Drummer - Glorified Metronome
ABSTRACT
Is there a drummer in the house?
SYNOPSIS
use MIDI::Simple::Drummer;
my $d = MIDI::Simple::Drummer->new;
# A glorified metronome:
$d->count_in;
$d->beat for 1 .. $d->phrases;
$d->fill;
# A smarter drummer:
my $beat = 0;
my $fill = 0;
$d->count_in;
for my $p (1 .. $d->phrases) {
if($p % 2 > 0) {
$beat = $d->beat(-n => 3, -fill => $fill);
}
else {
$beat = $d->beat(-n => 4);
$fill = $d->fill(-last => $fill);
}
}
$d->beat(-last => $beat, -fill => $fill);
$d->fill(-n => 'end', -pattern => \&fin);
$d->write;
sub fin {
my $d = shift;
$d->note($d->EIGHTH, $d->option_strike;
$d->note($d->EIGHTH, $d->strike('Splash Cymbal', 'Bass Drum 1'));
$d->note($d->SIXTEENTH, $d->snare) for 0 .. 2; # TODO backbeat[0]
$d->rest($d->SIXTEENTH);
$d->note($d->EIGHTH, $d->strike('Splash Cymbal', 'Bass Drum 1'));
$d->note($d->SIXTEENTH, $d->snare) for 0 .. 2;
$d->note($d->EIGHTH, $d->strike('Crash Cymbal 1', 'Bass Drum 1'));
}
DESCRIPTION
This module is embroyonic but may yet grow into a giant reptilian monster that smashes Tokyo.
Until then, this is just meant to be a robotic drummer and hide the MIDI::Simple parameters.
METHODS
* new()
my $d = MIDI::Simple::Drummer->new(%arguments);
Far away in a distant galaxy... But nevermind that, Luke. Use The Source.
* phrases()
$d->phrases($x);
$x = $d->phrases();
Set or return the number of phrases to play.
* beats()
$d->beats($x);
$x = $d->beats();
Set or return the number of beats per measure.
* strike()
$x = $d->strike('Cowbell'); # 'n56'
$x = $d->strike('Cowbell', 'Tambourine'); # 'n56, n54'
@x = $d->strike('Cowbell', 'Tambourine'); # ('n56', 'n54')
Return note values for percussion names with %MIDI::notenum2percussion
in either list or scalar context.
* metronome()
$d->metronome();
$d->metronome('Mute Triangle');
Add beats * phases (with the Pedal Hi-Hat
or whatever patch you supply) to the score.
* count_in()
$d->count_in();
$d->count_in(2); # Number of bars.
$d->count_in(1, 'Side Stick'); # Bars and patch.
And a-one and a-two and a-one, two, three!</Lawrence Welk> ..11</FZ>
If No arguments are provided, the Closed Hi-Hat
is used.
* rotate()
$x = $d->rotate(3);
$x = $d->rotate(5, ['Mute Hi Conga', 'Open Hi Conga', 'Low Conga']);
Return the rotating back-beat of the rhythm based on the beat number, given by the first argument. By default, this is the alternating snare and kick. This can be any number of patches you desire by providing an array reference argument with the patch names.
* option_strike()
$p = $d->option_strike();
$p = $d->option_strike(-options => ['Mute Hi Conga','Open Hi Conga','Low Conga']);
Return a note value from a list of patches (by default the crash cymbals). If another set of patches is given, one of those is chosen at random.
* note()
$d->note($d->SIXTEENTH, $d->snare);
$d->note('sn', 'n38');
Add a note to the score. This is just a pass-through to "n" in MIDI::Simple.
* rest()
$d->rest($d->SIXTEENTH);
$d->rest('sn');
Add a rest to the score. This is just a pass-through to "r" in MIDI::Simple.
* beat()
$x = $d->beat();
$x = $d->beat(-n => 'foo');
$x = $d->beat(-last => $x);
$x = $d->beat(-fill => $x);
$x = $d->beat(-type => 'fill');
$x = $d->beat(-n => 'bar', -pattern => \&bar);
Play a beat or fill and return the id for the selected pattern. Beats and fills are both just patterns but drummers think of them as distinct animals.
This method adds an anecdotal "beat" to the event stream. You can indicate that we filled in the previous bar, and do something exciting like crash on the first beat, by supplying the -fill => $y
argument, where $y
is the fill we just played. Similarly, the -last => $z
argument indicates that $z
is the last beat we played, so that we can maintain "context sensitivity."
Unless specifically given a pattern to play with the -n
argument, we try to play something different each time, so if the pattern is the same as the -last
, or if there is no given pattern to play, another is chosen.
For -type => 'fill'
, we append a drum-fill to the event stream. See the "fill" in MIDI::Simple::Drummer section for this shortcut.
* fill()
$x = $d->fill(-n => 'foo');
$x = $d->fill(-last => $x);
$x = $d->fill(-n => 'bar', -pattern => \&bar);
This is just an alias for $d->beat(-type => 'fill', %args)
.
* pattern()
$x = $d->pattern(1);
$x = $d->pattern(paraflamaramadiddle => \&code, -type => 'fill');
Return the code reference to the named pattern. If a second, coderef argument is provided, the named pattern is assigned to it. A third set of named arguments can be supplied, like -type => 'fill'
to select a fill. Otherwise a beat pattern is assumed.
* write()
$x = $d->write(); # Use the preset -file attribute.
$x = $d->write('Buddy-Rich.mid');
This is just an alias for "write_score" in MIDI::Simple but with unimaginably intelligent bits. It returns the name of the written file if successful.
CONVENIENCE METHODS
These are just meant to avoid literal strings, although tiny, and needing to remember/type MIDI variables.
* WHOLE
$d->WHOLE();
Return 'wn'
.
* HALF
Return 'hn'
.
* QUARTER
Return 'qn'
.
* EIGHTH
Return 'en'
.
* SIXTEENTH
Return 'sn'
.
* _p2n()
Return %MIDI::percussion2notenum
a la "GOODIES" in MIDI.
* _n2p()
Return the inverse: %MIDI::notenum2percussion
.
* tick()
$x = $d->tick;
$x = $d->tick('Mute Triangle');
Strike or set the "tick" patch. By default, this is the Closed Hi-Hat
.
* snare()
$x = $d->snare;
$x = $d->snare('Electric Snare');
Strike or set the "snare" patch. By default, this is the Acoustic Snare
.
* kicktick()
$x = $d->kicktick;
$x = $d->snare(['Bass Drum 1', 'Side Stick']);
Strike or set the "snare" patch. By default, this is the Acoustic Snare
.
TO DO
* Provide smoother drum-kit and pattern access and creation.
* It don't mean a thing if it ain't got that swing.
* Intelligently modulate dynamics (i.e. "add nuance" like accent and crescendo).
* Move the repertoire of patterns to someplace like an XML file to include with the distribution.
SEE ALSO
The eg/* and t/* files, that come with this distribution.
MIDI::Simple itself.
http://maps.google.com/maps?q=mike+avery+joplin - my drum teacher.
POSSIBLY HANDY
AUTHOR AND COPYRIGHT
Gene Boggs <gene@cpan.org>
Copyright 2009, Gene Boggs, All Rights Reserved.
LICENSE
This program is free software; you can redistribute or modify it under the same terms as Perl itself.