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

use MIDI::Drummer::Tiny;

my $max = shift || 8;

my $d = MIDI::Drummer::Tiny->new(
    bpm   => 100,
    file  => "$0.mid",
    kick  => 'n36',
    snare => 'n40',
);

$d->score->synch(
    \&hihat,
    \&beat,
);

$d->write();

sub hihat {
    for my $beat ( 0 .. $max - 1 ) {
        # Crash every 3rd time around
        if ( $beat % 3 == 0 ) {
            $d->note( $d->eighth, $d->crash2 );
        }
        else {
            $d->note( $d->eighth, $d->closed_hh );
        }

        $d->note( $d->eighth, $d->closed_hh ) for 1 .. 9;
    }
}

sub beat {
    for my $beat ( 1 .. $max ) {
        $d->note( $d->quarter, $d->kick );
        $d->note( $d->quarter, $d->snare );
        $d->note( $d->quarter, $d->snare );
        $d->note( $d->quarter, $d->kick );
        $d->note( $d->quarter, $d->snare );
    }
}
