MIDI::Drummer::Tiny - Glorified metronome
version 0.3001
use MIDI::Drummer::Tiny; my $d = MIDI::Drummer::Tiny->new( file => 'drums.mid', bpm => 100, volume => 100, signature => '5/4', bars => 8, reverb => 0, kit => 25, # TR-808 if using GM Level 2 #kick => 36, # Override default patch #snare => 40, # " ); $d->count_in(1); # Closed hi-hat for 1 bar $d->metronome54; # 5/4 time for the number of bars $d->rest($d->whole); $d->set_time_sig('4/4'); $d->metronome44(3); # 4/4 time for 3 bars $d->flam($d->quarter, $d->snare); $d->crescendo_roll([50, 127, 1], $d->eighth, $d->thirtysecond); $d->note($d->sixteenth, $d->crash1); $d->accent_note(127, $d->sixteenth, $d->crash2); # Alternate kick and snare $d->note($d->quarter, $d->open_hh, $_ % 2 ? $d->kick : $d->snare) for 1 .. $d->beats * $d->bars; # Same but with beat-strings: $d->sync( sub { $d->pattern( instrument => $d->open_hh, patterns => [ ('1111') x $d->bars ] ) }, sub { $d->pattern( instrument => $d->snare, patterns => [ ('0101') x $d->bars ] ) }, sub { $d->pattern( instrument => $d->kick, patterns => [ ('1010') x $d->bars ] ) }, ); $d->write;
This module provides handy defaults and tools to produce a MIDI score with drum parts.
Below, the term "spec" refers to a note length duration, like an eighth or quarter note, for instance.
Default: MIDI-Drummer.mid
MIDI-Drummer.mid
Default: MIDI::Simple->new_score
MIDI::Simple->new_score
Default: 1 (Standard)
1
If you are going to play the MIDI file with a "General MIDI Level 2" soundfont, you can change kits.
8: Room 16: Power 24: Electronic 25: TR-808 26: ? 32: Jazz 40: Brush 48: Orchestra
Default: 15
15
Default: 9
9
Default: 100
100
Default: 120
120
Default: 4
4
Default: 4/4
4/4
beats / divisions
Computed from the signature, if not given in the constructor.
Computed from the signature.
$d->counter( $d->counter + $duration ); $count = $d->counter;
Beat counter of durations, where a quarter-note is equal to 1. An eighth-note is 0.5, etc.
Where the snare is by default the same as the acoustic_snare but can be overridden with the electric_snare ('n40').
'n40'
Where the kick is by default the same as the acoustic_bass but can be overridden with the electric_bass ('n36').
'n36'
$d = MIDI::Drummer::Tiny->new(%arguments);
Return a new MIDI::Drummer::Tiny object and add a time signature event to the score.
MIDI::Drummer::Tiny
$d->note( $d->quarter, $d->closed_hh, $d->kick ); $d->note( 'qn', 42, 35 ); # Same thing
Add notes to the score.
This method takes the same arguments as "Parameters for n/r/noop" in MIDI::Simple.
$d->accent_note($accent_value, $d->sixteenth, $d->snare);
Play an accented note.
For instance, this can be a "ghosted note", where the accent is a smaller number (< 50). Or a note that is greater than the normal score volume.
$d->rest( $d->quarter );
Add a rest to the score.
$d->count_in; $d->count_in($bars);
Play the closed hihat for the number of beats times the given bars. If no bars are given, the default times the number of beats is used.
$d->metronome38; $d->metronome38($bars);
Add a steady 3/8 beat to the score.
$d->metronome34; $d->metronome34($bars);
Add a steady 3/4 beat to the score.
$d->metronome44; $d->metronome44($bars); $d->metronome44($bars, $flag);
Add a steady 4/4 beat to the score.
If a flag is provided the beat is modified to include alternating eighth-note kicks.
$d->metronome44swing; $d->metronome44swing($bars);
Add a steady 4/4 swing beat to the score.
$d->metronome54; $d->metronome54($bars);
Add a 5/4 beat to the score.
$d->metronome58; $d->metronome58($bars);
Add a 5/8 beat to the score.
$d->metronome68; $d->metronome68($bars);
Add a 6/8 beat to the score.
$d->metronome74; $d->metronome74($bars);
Add a 7/4 beat to the score.
$d->metronome78; $d->metronome78($bars);
Add a 7/8 beat to the score.
$d->flam($spec); $d->flam( $spec, $patch );
Add a "flam" to the score, where a ghosted 64th gracenote is played before the primary note.
If not provided the snare is used for the patch.
$d->roll( $length, $spec ); $d->roll( $length, $spec, $patch );
Add a drum roll to the score, where the patch is played for duration length in spec increments.
$d->crescendo_roll( [$start, $end, $bezier], $length, $spec ); $d->crescendo_roll( [$start, $end, $bezier], $length, $spec, $patch );
Add a drum roll to the score, where the patch is played for duration length in spec notes, at increasing or decreasing volumes from start to end.
If true, the bezier flag will render the crescendo with a curve, rather than as a straight line.
| * | * vol | * | * |* --------------- time
$d->pattern( patterns => \@patterns ); $d->pattern( patterns => \@patterns, instrument => $d->kick ); $d->pattern( patterns => \@patterns, instrument => $d->kick, %options );
Play a given set of beat patterns with the given instrument.
The patterns are an arrayref of "beat-strings". By default these are made of contiguous ones and zeros, meaning "strike" or "rest". For example:
patterns => [qw( 0101 0101 0110 0110 )],
This method accumulates the number of beats in the object's counter attribute, if the count option is set.
The vary option is a hashref of coderefs, keyed by single character tokens, like the digits 0-9. Each coderef duration should add up to the given duration option. The single argument to the coderefs is the object itself and may be used as: my $self = shift; in yours.
my $self = shift;
Defaults:
instrument: snare patterns: [] (i.e. empty!) Options: duration: 1 (quarter-note) beats: given by constructor repeat: 4 count: 0 negate: 0 vary: 0 => sub { $self->rest( $args{duration} ) }, 1 => sub { $self->note( $args{duration}, $args{instrument} ) },
$d->set_time_sig; $d->set_time_sig('5/4'); $d->set_time_sig( '5/4', 0 );
Add a time signature event to the score, and reset the beats and divisions object attributes.
If a ratio argument is given, set the signature object attribute to it. If the 2nd argument flag is 0, the beats and divisions are not reset.
0
$d->sync(@code_refs);
This is a simple pass-through to the score synch method.
synch
This allows simultaneous playing of multiple "tracks" defined by code references.
Output the score as a MIDI file with the module "file" attribute as the file name.
The eg/* programs in this distribution. Also eg/drum-fills-advanced in the Music::Duration::Partition distribution.
Math::Bezier
MIDI::Util
Moo
Music::Duration
https://en.wikipedia.org/wiki/General_MIDI#Percussion
https://en.wikipedia.org/wiki/General_MIDI_Level_2#Drum_sounds
Gene Boggs <gene@cpan.org>
This software is copyright (c) 2022 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.
To install MIDI::Drummer::Tiny, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MIDI::Drummer::Tiny
CPAN shell
perl -MCPAN -e shell install MIDI::Drummer::Tiny
For more information on module installation, please visit the detailed CPAN module installation guide.