On 17 Dec 2004 15:53:51 -0800, rumours say that "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> might have written:

>> The BASICs of my youth also supported graphics and sounds.
>>
>>   PLAY "CGFED>C<GFED>C<GFEFB"
>
>Now wait a minute, shouldn't that be...
>
>PLAY "CGFED>C<GFED>C<GFEFD" ?  :^)

You tell us :)

***
music.py -- assuming winsound exists
***

import winsound
semi= 2**(1.0/12.0)
notes= {}
middle_A= 440.0

# set up the note map
# small case letters are the sharpened versions

for coeff, note in enumerate("CcDdEFfGgAaB*"):
    notes[note]= middle_A*semi**(coeff-9) # known middle A is at index 9

assert str(notes["*"]) == str(notes["C"]*2) # use str to drop digits
del notes['*']

modifiers= {'<': 0.5, '>': 2.0} # octave modifier

def play(sequence):
    """Play a sequence of notes."""
    octave=1.0
    for note in sequence:
        try: # to play a note
            winsound.Beep(int(round(notes[note]*octave)), 200)
        except KeyError: # well, it wasn't
            octave *= modifiers[note]

if __name__ == "__main__":
    play("CGFED>C<GFED>C<GFEFD")

***
Disclaimer:
***

I had a ZX Spectrum, and then a QL [1], and never had any BASIC having a
"PLAY" command, so the code above makes some assumptions (e.g. check the
meaning of ">" and "<" for example if I got them correctly).


[1] and then I "inherited" a Stride with an 68010 from a student friend
who finished studies and got drafted, who himself had it borrowed from
the company of a friend of his so that he would develop code that could
be used by the company, and in general all my troubles seem to come from
exposure to Unix in my puberty, but that's another story :)
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to