Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # midi_Mission_Impossible_demo.py
- #
- # Internal Speaker Beeping Module for Windows
- #
- import time
- import winsound
- # Set delay tempo
- tempo = 0.15
- # Setup Notes
- notes = {}
- notes["pause"] = 0
- notes["c"] = 1
- notes["c#"] = 2
- notes["d"] = 3
- notes["d#"] = 4
- notes["e"] = 5
- notes["f"] = 6
- notes["f#"] = 7
- notes["g"] = 8
- notes["g#"] = 9
- notes["a"] = 10
- notes["a#"] = 11
- notes["b"] = 12
- # Note Types
- note_types = {}
- note_types["sixteenth"] = 50
- note_types["eigth"] = 100
- note_types["dotted_eigth"] = 150
- note_types["quarter"] = 200
- note_types["half"] = 400
- note_types["whole"] = 800
- note_types["triplet"] = 60
- #!# End Notes Config #!#
- def play_note(octave, note, note_type):
- """Play a note at a certain octave by calculating the frequency of
- the sound it would represent on the motherboard's speaker."""
- # Match the note and note type to the dictionaries
- note = notes[note]
- note_type = note_types[note_type]
- # Chill for a bit if it's a pause
- if not note:
- time.sleep(note_type/1000)
- return
- # Calculate C for the provided octave
- frequency = 32.7032 * (2**octave)
- # Calculate the frequency of the given note
- frequency *= 1.059463094**note
- # Beep it up
- winsound.Beep(int(frequency), note_type)
- # Delay after the beep so it doesn't all run together
- time.sleep(tempo)
- def mission_impossible():
- oct = 3
- play_note(oct, "g", "half")
- play_note(oct, "g", "half")
- play_note(oct+1, "a#", "quarter")
- play_note(oct+1, "c", "quarter")
- play_note(oct, "g", "half")
- play_note(oct, "g", "half")
- play_note(oct, "f", "quarter")
- play_note(oct, "f#", "quarter")
- play_note(oct, "g", "half")
- play_note(oct, "g", "half")
- play_note(oct+1, "a#", "quarter")
- play_note(oct+1, "c", "quarter")
- play_note(oct, "g", "half")
- play_note(oct, "g", "half")
- play_note(oct, "f", "quarter")
- play_note(oct, "f#", "quarter")
- def party():
- print 'Mission Impossible'
- mission_impossible()
- if __name__ == '__main__':
- party()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement