#!/usr/bin/perl
use strict;
use warnings;

use MIDI::Simple::Drummer;
my $d = MIDI::Simple::Drummer->new(
    -bpm     => shift || 111,
    -volume  => shift || 121,
    -phrases => shift || 2,
);

my $beat = 0;
my $fill = 0;

$d->count_in();

for my $p (1 .. $d->phrases) {
    warn "p: $p, beat $beat, fill: $fill\n";
    if($p % 2 > 0) {
        $beat = $d->beat(-name => 'rock_3', -fill => $fill);
        $fill = $d->fill(-last => $fill);
    }
    else {
        $beat = $d->beat(-name => 'rock_4');
        $fill = $d->fill(-last => $fill);
    }
}
#$beat = $d->beat(-last => $beat, -fill => $fill);
#fin($d); # This is perfectly reasonable but not as sexy.
$d->pattern(end => \&fin, -type => 'fill');
$d->fill(-name => 'end');
#$d->crash;

$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;
    $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'));
}
