1
0
mirror of https://git.exozy.me/a/Never-Gonna-Give-Beep-Up synced 2024-11-25 04:37:30 +00:00
Never-Gonna-Give-Beep-Up/gen.py

36 lines
1.1 KiB
Python
Raw Normal View History

2022-10-02 19:58:49 +00:00
with open('nevergonnagiveyouup.ino') as f:
lines = f.readlines()
note_to_freq = {}
2022-10-02 20:08:10 +00:00
tempo = 150
2022-10-02 19:58:49 +00:00
with open('rickroll.sh', 'w') as f:
for line in lines:
if '#define' in line:
split = line.split()
note_to_freq[split[1]] = split[2]
elif 'NOTE' in line:
split = line.split(',')
note = True
for word in split:
word = word.replace(' ', '')
print(word)
if '//' in word or word == '\n':
continue
elif 'NOTE' in word:
f.write(f'beep -f {note_to_freq[word]}')
note = True
elif 'REST' in word:
f.write('sleep')
note = False
else:
d = int(word)
if d < 0:
d /= -1.5
2022-10-02 20:08:10 +00:00
l = (60000 * 4)/tempo/d
2022-10-02 19:58:49 +00:00
if note:
f.write(f' -l {l}\n')
else:
f.write(f' {l/1000}\n')