#!/usr/bin/env perl

# Return random jazz progressions

# Unfortunately, a couple chords have a "bV" note in the base, which is not handled by this code yet...

use strict;
use warnings;

use Data::Dataset::ChordProgressions;
use Music::Scales qw(get_scale_notes);

my $n     = shift || 4;
my $note  = shift || 'C'; # Transpose chords from C to this
my $scale = shift || 'major'; # or minor

my %data = Data::Dataset::ChordProgressions::as_hash();

my @pool;
for my $type (keys %{ $data{jazz}{$scale} }) {
    push @pool, @{ $data{jazz}{$scale}{$type} };
}

my %note_map;
@note_map{ get_scale_notes('C', $scale) } = get_scale_notes($note, $scale);

for my $i (1 .. $n) {
    my $chord = $pool[int rand @pool];
    (my $named = $chord->[0]) =~ s/([A-G][#b]?)/$note_map{$1}/g;
    print "$i. $named, $chord->[1]\n";
}
