
-----------------------------------
beard0
Mon Oct 31, 2005 4:36 pm

Fixing turing's Music.Play
-----------------------------------
Got the idea for this from an old topic that was brought up again, but implimented it in a more useful way.

I made a module containing Play that is compatible with Turing's Music.Play, but doesn't cut off the last note.  It also adds some features.
note: to acheive dotted ntoes, use the module MyMusic
    import Str, Music
    export SetZero, SetWhole, Play, BGPlay
    var zeroNote : nat := 262
    var octave := 0
    var whole : nat := 1000
    var curDuration := 1 / 4
    var waiting := ""

    fcn note (x : int) : int
        result round (zeroNote * 2 ** (x / 12 + octave))
    end note

    proc SetZero (n : nat)
        zeroNote := n
    end SetZero

    proc SetWhole (n : nat)
        whole := n
    end SetWhole

    proc Play (m : string)
        var n : int
        var doplay := false
        var i : int := 0
        loop
            i += 1
            exit when i > length (m)
            doplay := false
            if m (i) = ">" then
                octave += 1
            elsif m (i) = "gpf+p8f[3,8]e-6p8e")
MyMusic.Play ("8p4ccdg6f+p8f4e-8e")
MyMusic.Play ("6p[5,16]>c8c2c