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(
-bpm => shift || 111,
-volume => shift || 121,
-phrases => shift || 2,
);
my $last_fill = 0;
$d->count_in();
for my $p (0 .. $d->phrases - 1) {
if($p % 2 > 0) {
$d->play(-n => 5);
$last_fill = $d->fill(-last => $last_fill);
}
else {
$d->play(-n => 3, -fill => $p);
}
}
$d->pattern('fin', \&fin);
$d->play(-n => 'fin');
$d->write;
sub fin {
my $d = shift;
$d->strike($d->EIGHTH, $d->kit($d->option_patch));
$d->strike($d->EIGHTH, $d->kit('Splash Cymbal'), $d->kit('Bass Drum 1'));
$d->strike($d->SIXTEENTH, $d->kit('Acoustic Snare')) for 0 .. 2;
$d->rest($d->SIXTEENTH);
$d->strike($d->EIGHTH, $d->kit('Splash Cymbal'), $d->kit('Bass Drum 1'));
$d->strike($d->SIXTEENTH, $d->kit('Acoustic Snare')) for 0 .. 2;
$d->strike($d->EIGHTH, $d->kit('Crash Cymbal 1'), $d->kit('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()
Return or set the number of phrases to play.
* kit()
Return note values for percussion names with %MIDI::notenum2percussion
.
* metronome()
Beats x Phases with the Pedal Hi-Hat
or whatever patch you supply.
* count_in()
And a-one and a-two and a-one, two, three!</Lawrence Welk> ..11</FZ>
* rotate()
Return the rotating back-beat of the rhythm. By default, this is the alternating snare and kick. This can be any number of patches you desire by providing a third array reference argument with the patch names.
* option_patch()
Return a selection from a list of patches, if one is not given.
* strike()
Add a note to the score.
* rest()
Add a rest to the score.
* play()
Play a beat or fill and return the id (a hash key) for the selected pattern. Beats and fills are both just patterns but drummers think of them as distinct animals.
This method adds a fictional, 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 => $x
argument, where $x
is the fill we just played.
For -type => 'fill'
, we append a drum-fill to the event stream and return the name of the selected fill.
Unless specifically given a pattern to play, 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.
* fill()
This is just an alias for $d->play(-type => 'fill', %args)
.
* pattern($name[, $value])
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()
This is just an alias for "write_score" in MIDI::Simple but with unimaginably intelligent bits.
CONVENIENCE METHODS
These are just meant to avoid literal strings, although tiny, and needing to remember/type MIDI variables.
* 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
.
TO DO
* Provide smoother access to the current drum-kit, beat and fill patterns.
* Move the repertoire of patterns to someplace like MIDI::Simple::Drummer::Patterns
.
* It don't mean a thing if it ain't got that swing.
* Intelligently modulate dynamics (i.e. "add nuance" like accent and crescendo).
SEE ALSO
The eg/* file(s), that come(s) 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.