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_beat = 0;
my $last_fill = 0;
$d->count_in();
for my $p (1 .. $d->phrases) {
warn "last_beat $last_beat, last_fill: $last_fill\n";
if($p % 2 > 0) {
$last_beat = $d->beat(-n => 3, -fill => $last_fill);
}
else {
$last_beat = $d->beat(-n => 4);
$last_fill = $d->fill(-last => $last_fill);
}
}
$last_beat = $d->beat(-n => 3, -fill => $last_fill);
$d->pattern('fin', \&fin);
$d->beat(-n => 'fin');
$d->write;
sub fin {
my $d = shift;
$d->note($d->EIGHTH, $d->strike($d->option_strike));
$d->note($d->EIGHTH, $d->strike('Splash Cymbal', 'Bass Drum 1'));
$d->note($d->SIXTEENTH, $d->strike('Acoustic Snare')) for 0 .. 2;
$d->rest($d->SIXTEENTH);
$d->note($d->EIGHTH, $d->strike('Splash Cymbal', 'Bass Drum 1'));
$d->note($d->SIXTEENTH, $d->strike('Acoustic 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($p);
$p = $d->phrases();
Set or return the number of phrases to play.
* strike()
$strike = $d->strike('Cowbell'); # 'n56'
$strike = $d->strike('Cowbell', 'Tambourine'); # 'n56, n54')
@strike = $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 x phases (with the Pedal Hi-Hat
or whatever patch you supply) to the score.
* count_in()
$d->count_in();
$d->count_in(2); # 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()
$n = $d->rotate(1); # n38
$n = $d->rotate(2, ['Side Stick', 'Bass Drum 1']); n36
$n = $d->rotate(#, []); # n
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_strike()
$p = $d->option_strike();
$p = $d->option_strike(-patch => 'Splash Cymbal');
$p = $d->option_strike(-options => ['Mute Hi Conga','Open Hi Conga','Low Conga']);
Return a selection from a list of patches, if one is not given. If a set of optional patches is given, a random one is chosen.
* note()
$d->note('sn', 'n38');
$d->note($d->SIXTEENTH, $d->strike('Acoustic Snare'));
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()
$last_beat = $d->beat();
$last_beat = $d->beat(-n => 'foo');
$last_fill = $d->beat(-type => 'fill', -last => $last_fill);
$last_beat = $d->beat(-fill => $last_fill);
$last_beat = $d->beat(-last => $last_beat);
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()
$last_fill = $d->fill(-n => 'foo');
$last_fill = $d->fill(-last => $last_fill);
This is just an alias for $d->beat(-type => 'fill', %args)
.
* pattern()
$p = $d->pattern(1);
$p = $d->pattern('paraflamaramadiddle', $coderef);
$p = $d->pattern('paraflamaramadiddle', $coderef, -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(); # Uses the -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
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 o and creation of the drum-kit and 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.