Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found