Greetings fellow monks,

I know this is probably really stupid, but a friend of mine is writing a murder mystery novel that's kinda like Twin Peaks meets geeks with shortwave radios. We were IMing about numbers stations a bit, and he wondered about whether it would be possible to take a chess game and turn the moves into a song to broadcast over shortwave.

Not being one to turn down a challenge, I said, "Possible? Anything's possible with CPAN!" So here's my attempt, rough as it is. It takes a Portable Game Notation (PGN) file, reads each game, and creates a MIDI file in the key of F. How exactly a MIDI file of a chess game broadcasted over shortwave fits into the plot, I still have no idea, and that's not my job.

The really interesting thing is that I've been listenning to some Fischer games this morning, and I'm hearing some very similar patterns toward the end-game. I'd expect a very similar openning set of sounds, but this is wicked weird.

#!/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'; }

Question: Does anyone know how to take a WAV file and convert it into MIDI? Or take a WAV file and convert it into some sort of musical notation? I'm wondering about how difficult it would be for the listenner to record the shortwave broadcast and convert it back into PGN.

gryphon
code('Perl') || die;


In reply to PGN (Chess) to MIDI by gryphon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.