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

# Plot the keys for all songs.

use Music::BachChoralHarmony;

my $bach = Music::BachChoralHarmony->new;
my $songs = $bach->parse();

my %score;
for my $id ( keys %$songs ) {
#warn(__PACKAGE__,' ',__LINE__," MARK: ",$id,"\n") if $songs->{$id}{key} eq 'A_m';
    $score{ $songs->{$id}{key} }++;
}
#exit;

use Chart::Bars;
my $chart = Chart::Bars->new( 800, 400 );

$chart->set(
    legend       => 'none',
    title        => 'Keys of All Chorales',
    x_label      => 'Key',
    y_label      => 'Songs',
    precision    => 0,
    include_zero => 'true',
);

my @sorted = sort { $score{$a} <=> $score{$b} } keys %score;
$chart->add_dataset( @sorted );
$chart->add_dataset( map { $score{$_} } @sorted );

$chart->png("$0.png");
