#!/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,
);
#use Data::Dumper;local$Data::Dumper::Indent=1;local$Data::Dumper::Terse=1;local$Data::Dumper::Sortkeys=1;
#die Dumper($d->p2n);

$d->count_in();

my $last_fill = 0;

for(0 .. $d->phrases - 1) {
    if($_ % 2 > 0) {
        $d->play(-n => 5);
#        $last_fill = $d->play(-type => 'fill');
#        $last_fill = $d->fill(-n => 3);
        $last_fill = $d->fill(-last => $last_fill);
    }
    else {
        $d->play(-n => 3, -fill => $_);
    }
}

#fin($d);
$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'));
}
