-
Notifications
You must be signed in to change notification settings - Fork 0
/
skytranscriber.py
62 lines (43 loc) · 2.1 KB
/
skytranscriber.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
input_letters = ['Q', 'W', 'E', 'R', 'T', 'A', 'S', 'D', 'F', 'G', 'Z', 'X', 'C', 'V', 'B']
valid_tokens = input_letters + ['(', ')', ' ']
rows = ['A', 'B', 'C']
input_letter_mappings = {}
# Match keyboard to piano grid mapping
for row in rows:
for column in range(1, 5+1):
note = row + str(column)
letter = input_letters.pop(0)
input_letter_mappings[letter] = note
print('NEW SONG')
song_name = input('Enter name for song: ')
with open(song_name + '.html','w+') as song_file:
song_file.write("<!DOCTYPE html>\n<html>\n<head>\n<title>My Sky Song</title><style>body {margin: 50px; font-size: 30px; font-family: monospace; line-height: 50px;}span {width: 100px; height: 100px; border-radius: 20px;}.row-A {background-color: #8ed5ff;}.row-B {background-color: #f1a3ff;}.row-C {background-color: #ffa59b;}h1 {font-family: \"Avenir\";}</style></head>")
song_file.write("<body>\n")
song_file.write("<h1>" + song_name + "</h1>" + '\n')
line = input('New line: ')
while line:
is_invalid_line = False
result = ''
current_row = ''
for token in line.upper():
if token not in valid_tokens:
print('Error: Invalid tokens, only QWERT ASDFG ZXCVB ( ) and spaces allowed.')
break
else:
if token in input_letter_mappings.keys():
note = input_letter_mappings[token]
current_row = note[0]
# Style using div
node_name = "<span class=\"row-" + current_row + "\">" + note + "</span> "
elif token == " ":
node_name = "<span class=\"marker\"> </span> "
else:
note = token
# Style using div
node_name = "<span class=\"marker\">" + note + "</span> "
result += node_name
song_file.write(result + '<br />' + '\n')
line = input('New line: ')
previous_note = ''
print("Done. Please check the file named \"" + song_name + ".html\"")
song_file.write("</body>\n</html>")