++benn. Now here is my adaptation that uses MIDI::Simple for creating a MIDI of it ;)

#!/usr/bin/perl ########################################### # Variable Length Markov Diddly. ########################################### use strict; use constant LENGTH => 4; # length of patte +rn key use MIDI::Simple; my %duration = ( 2 => 'qn', 4 => 'hn', 8 => 'wn', 12 => 'dwn', ); new_score; set_tempo 500000; # 1 qn => .5 seconds (500,000 microseconds) patch_change 1, 77; # Patch 76 = recorder, 77 = pan flute, 80 = whist +le, 81 = Ocarina noop "c1", "fff", "o3"; # Setup my %probs; # probabilities +of next note while (<DATA>) { # read the existin +g tunes... chomp; my @line = split /,/; my @notes = ("START") x (LENGTH); # cyclic buffer while (@line) { shift (@notes); push @notes, shift(@line).",".shift(@line); # "note,length" $probs{key(@notes)}{$notes[$#notes]}++; } shift (@notes); $probs{key(@notes)}{"END"}++; } my @notes = ("START") x LENGTH; do { shift(@notes); my %next = %{$probs{key(@notes)}}; # array of probs my @next = map {($_) x $next{$_}} keys %next; # 1 entry per 'pr +ob' push @notes, $next[int(rand(@next))]; my ($note, $dur); unless ($notes[$#notes] eq "END") { print "$notes[$#notes] "; ($note, $dur) = split',',$notes[$#notes]; ++$note; # increment once $note = uc(++$note); # increment again and then upcase it! $note = $MIDI::note2number{$note}; eval(n $duration{$dur}, $note); } } while ($notes[$#notes] ne "END"); write_score 'markov-diddly.mid'; sub key {return join("",@_[0..LENGTH-2]);} # make space-sep +arated key # a bunch of common session tunes (plus one of mine <g>) __DATA__ e2,4,e2,2,b2,2,e2,2,b2,2,e2,2,e2,2,b2,2,a2,2,fs2,2,d2,2,e2,4,e2,2,b2,4 +,cs3,2,d3,2,cs3,2,b2,2,a2,2,fs2,2,d2,2,e2,4,e2,2,b2,2,e2,2,b2,2,e2,2, +e2,2,b2,2,a2,2,fs2,2,d2,2,g2,4,g2,2,fs2,2,g2,2,a2,2,b2,2,a2,2,g2,2,fs +2,2,e2,2,d2,2 d2,2,g2,2,g2,2,b2,2,g2,2,g2,2,a2,2,g2,2,a2,2,b2,2,g2,2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d3,2,g3,4, +d3,2,b2,4,g2,2,d2,2,d2,2,d2,2,d2,6,d2,2,d2,2,d2,2,d2,4,a2,2,fs2,4,d2, +2,fs2,4,a2,2,c3,4,a2,2,fs2,4,d2,2 a2,6,a2,6,a2,2,fs2,2,d3,2,a2,2,fs2,2,d2,2,g2,6,g2,6,g2,2,e2,2,fs2,2,g3 +,2,fs2,2,e2,2,a2,6,a2,6,a2,2,fs2,2,d3,2,a2,2,fs2,2,d2,2,e2,2,fs2,2,g2 +,2,fs2,2,g2,2,e2,2,d2,12 a2,2,d2,2,d2,2,b2,2,d2,2,d2,2,c3,6,c3,2,b2,2,a2,2,g2,2,a2,2,b2,2,a2,2, +g2,2,fs2,2,g2,2,fs2,2,g2,2,e2,2,fs2,2,g2,2,a2,2,d2,2,d2,2,b2,2,d2,2,d +2,2,c3,6,c3,2,b2,2,a2,2,g2,2,a2,2,b2,2,a2,2,g2,2,fs2,2,g2,12


In reply to Re: Markov Diddly by Mr. Muskrat
in thread Markov Diddly by benn

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.