Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # midi_is_possible_demo2.py
- #
- # Internal Speaker Beeping Module for Windows
- #
- import time
- import winsound
- # Setup Notes
- notes = {}
- notes['pause'] = 0
- notes['p'] = 0
- notes['r'] = 0
- notes['.'] = 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
- notes['c#'] = 1
- notes['d#'] = 3
- notes['e#'] = 5
- notes['f#'] = 6
- notes['g#'] = 8
- notes['a#'] = 10
- notes['b#'] = 12
- # Note Types
- note_types = {}
- note_types[5] = 50
- note_types[1] = 100
- note_types[6] = 150
- note_types[2] = 200
- note_types[4] = 400
- note_types[8] = 800
- note_types[3] = 60
- dur = {}
- dur["sixteenth"] = 50
- dur["eighth"] = 100
- dur["dotted_eighth"] = 150
- dur["quarter"] = 200
- dur["half"] = 400
- dur["whole"] = 800
- dur["triplet"] = 60
- dur["16"] = 50
- dur["8"] = 100
- dur[".2"] = 150
- dur["4"] = 200
- dur["2"] = 400
- dur["1"] = 800
- dur["3"] = 60
- #!# End Notes Config #!#
- aaa=''
- def rw_notes(octave, note, note_type):
- global aaa
- if '#' in note:
- freq=note[0]
- else:
- freq=note.upper()
- dur_ = dur[note_type]
- aaa+=str(octave)+str(freq)+str(dur_)
- def play_midi(array,tempo=0):
- """Play a note at a certain octave by calculating the frequency of
- the sound it would represent on the motherboard's speaker."""
- while 1:
- try:
- print array[:3]
- octave, note, note_type = array[0],array[1],array[2]
- array = array[3:]
- # Match the note and note type to the dictionaries
- note = notes[note]
- note_type = note_types[int(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**int(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/600.00)
- except: break
- #
- ### Mission Impossible
- play_midi('3G43G43a24C23G43G43F23f23G43G43a24C23G43G43F23f2',80)
- #print aaa
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement