#!/usr/bin/perl use strict; use warnings; use Chess::PGN::Parse; use MIDI::Simple; my $pgn = new Chess::PGN::Parse 'games.pgn' or die $!; while ($pgn->read_game) { $pgn->parse_game; my @song = (); new_score; set_tempo 275000; noop 'c1', 'f'; foreach (@{$pgn->moves}) { if ($_ eq 'O-O') { push @song, 8, 'qn', 'F', 8, 'hn', 'F'; } elsif ($_ eq 'O-O-O') { push @song, 8, 'qn', 'F', 8, 'qn', 'F', 8, 'hn', 'F'; } else { foreach (split('')) { if (tr/KQBN/FGAB/) { push @song, 4, 'qn', $_; } elsif (tr/Rabcdef/CDEFGAB/) { push @song, 5, 'qn', $_; } elsif (tr/gh1234/CDEFGA/) { push @song, 6, 'qn', $_; } elsif (tr/5678/BCDE/) { push @song, 7, 'qn', $_; } elsif (tr/x\+/CE/) { push @song, 8, 'qn', $_; } } $song[-2] = 'hn'; } } while (@song) { noop 'o' . shift @song; my ($l, $n) = (shift @song, shift @song); $n = 'Bf' if ($n eq 'B'); n $l, $n; } write_score join('_', $pgn->white, $pgn->black) . '.mid'; }