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

# Plot the keys for all songs.

#use lib map { "$ENV{HOME}/sandbox/$_/lib" } qw(Music-BachChoralHarmony); # local author libs
use Music::BachChoralHarmony;

#my $data_file = 'share/jsbach_chorals_harmony.data'; # local author files
#my $key_title = 'share/jsbach_BWV_keys_titles.txt';  # "
my $bach = Music::BachChoralHarmony->new(
#    data_file => $data_file,
#    key_title => $key_title,
);
my $songs = $bach->parse();

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

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

$chart->set(
    legend       => 'none',
    title        => 'Keys of 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");
