#!/usr/bin/perl
use strict;
use warnings;
use MIDI::Simple::Drummer::Rock;

my $d = MIDI::Simple::Drummer::Rock->new(
    -bpm     => shift || 111,
    -volume  => shift || 121,
    -phrases => shift || 2,
    -file    => "$0.mid",
);

my ($beat, $fill) = (0, 0);

$d->count_in;

for my $p (1 .. $d->phrases) {
    if($p % 2 > 0) {
        $beat = $d->beat(-name => 2.3, -fill => $fill);
        $beat = $d->beat(-name => 2.3);
    }
    else {
        $beat = $d->beat(-name => 2.4);   # TODO [2,4,5]
        $fill = $d->fill(-last => $fill);
    }
}

#fin($d); # <- Perfectly reasonable but use the API:
$d->patterns('end fill' => \&fin);
$d->fill(-name => 'end');

$d->write;

sub fin {
    my $d = shift;
    $d->note('en', $d->crash) for 1 .. 2;
    $d->note('sn', $d->snare) for 0 .. 2;
    $d->rest('sn');
    $d->note('ten', $d->kick) for 1 .. 2;
    $d->note('en', $d->strike('Splash Cymbal', $d->name_of('kick')));
}
