#!/usr/bin/perl

use strict;
use warnings;
use MIDI::Tweaks 0.06 qw( EV_NOTE_PITCH is_note_on );

my $op = MIDI::Tweaks::Opus->new
  ({ from_file => shift, require_sanity => 0 });

my @pitches;
foreach my $track ( $op->tracks ) {
    # next if $track->channel == 10;
    foreach my $event ( $track->events ) {
	next unless is_note_on($event);
	$pitches[$event->[EV_NOTE_PITCH]]++;
    }
}

my @notes = (split(/ /, "C C# D D# E F F# G G# A A# B"));

for ( my $i = 0; $i < @pitches; $i++ ) {
    next unless $pitches[$i];
    printf("pitch %3d %-4s  %5d times\n",
	   $i,
	   $notes[$i%12] . (int($i/12)-2),
	   $pitches[$i]);
}
