Music Macro Language ==> Beep command
#!/usr/bin/python3
import os, sys
tone_dict = { 'c': '262',
'c#': '277',
'd' : '294',
'd#': '311',
'e': '330',
'f': '349',
'f#': '370',
'g': '392',
'g#': '415',
'a': '440',
'a#': '466',
'b': '494',
'C': '523',
'C#': '554',
'D': '587',
'D#': '622',
'E': '659',
'F': '698',
'F#': '740',
'G': '784',
'G#': '831',
'A': '880',
'A#': '932',
'B': '988',
'B#': '1046'
}
number_dict = { '0': '100000',
'1': '1200',
'2': '600',
'4': '300',
'8': '150',
'16': '75',
'32': '37.5',
'64': '18.75',
}
mml=""
if len(sys.argv) < 2:
mml = input( "Please input audio string in music macro language(MML):")
else:
mml = sys.argv[1]
tone = ""
number = ""
s = ""
repeat = False
delay = False
t1 = ''
mml += 'r'
for t in mml:
if t == 'r':
if t1 in "0123456789":
if tone in tone_dict:
s += " -n -f " + tone_dict[tone]
if number in number_dict:
s += " -l " + number_dict[number]
elif delay == True:
if number in number_dict:
s += " -D " + number_dict[number]
elif t1 in "cdefgabCDEFGAB#":
if tone in tone_dict:
s += " -n -f " + tone_dict[tone]
delay = True
tone = ""
number = ""
elif t == '#':
delay = False
if t1 in "cdefgabCDEFGAB":
tone += t
elif t1 in "0123456789":
s += " -n -f " + tone_dict[tone] + " -l " + number_dict[number]
tone = ""
number = ""
elif t in "cdefgabCDEFGAB":
delay = False
if t1 in "0123456789":
if tone in tone_dict:
s += " -n -f " + tone_dict[tone]
if number in number_dict:
s += " -l " + number_dict[number]
elif t1 in "cdefgabCDEFGAB#":
if tone in tone_dict:
s += " -n -f " + tone_dict[tone]
tone = t
number = ""
elif t in "0123456789":
number += t
t1 = t
cmd = "beep " + s[4:]
print(cmd)
os.system(cmd)