-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat_song.py
73 lines (53 loc) · 1.87 KB
/
format_song.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
63
64
65
66
67
68
69
70
71
72
73
from typing import List
def format():
filename = 'raw_inputs/' + input('Enter filename: ')
newLines = ''
with open(filename, 'r') as file:
# newLines += format_map(file.readlines(), newLines)
newLines += format_array(file.readlines(), newLines)
# newLines += format_progmem_array(file.readlines(), newLines)
newName = 'formatted_inputs/formatted_'+ filename
with open(newName, 'w') as file:
file.write(newLines)
def format_progmem_array(file_list: List[str], newLines: str):
for idx, line in enumerate(file_list):
line = line.rstrip('\n').split(' ')
line.pop(0)
for note_idx, elem in enumerate(line):
newLine = f'const String jingleBellBeat{idx}_{note_idx}[] = {{'
elem = elem.rstrip('\n')
newLine += f'"{elem}", '
newLine = newLine.rstrip(', ')
newLine += '};\n'
newLines += newLine
newLines += ';'
return newLines
def format_array(file_list: List[str], newLines: str):
newLines += '{\n'
for line in file_list:
line = line.rstrip('\n').split(' ')
line.pop(0)
newLine = f'{{'
for elem in line:
elem = elem.rstrip('\n')
newLine += f'"{elem}", '
newLine = newLine.rstrip(', ')
newLine += '},\n'
newLines += newLine
newLines += '};'
return newLines
def format_map(file_list: List[str], newLines: str):
newLines += '{\n'
for line in file_list:
line = line.rstrip('\n').split(' ')
newLine = f'{{{line.pop(0)}, {{'
for elem in line:
elem = elem.rstrip('\n')
newLine += f'"{elem}", '
newLine = newLine.rstrip(', ')
newLine += '}},\n'
newLines += newLine
newLines += '};'
return newLines
if __name__ == '__main__':
format()