-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.py
More file actions
55 lines (47 loc) · 1.48 KB
/
processor.py
File metadata and controls
55 lines (47 loc) · 1.48 KB
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
basic_notes = ['do', 'reb', 're', 'mib', 'mi', 'fa', 'solb', 'sol', 'lab', 'la', 'sib', 'si']
note_id = {}
notes = basic_notes.copy()
for note in basic_notes:
temp = list(note)
temp[0] = temp[0].upper()
temp = ''.join(temp)
notes.append(temp)
for note in basic_notes:
temp = list(note)
temp[0] = temp[0].upper()
temp[1] = temp[1].upper()
if (len(temp) > 2 and temp[2].lower() == 'l'):
temp[2] = temp[2].upper()
temp = ''.join(temp)
notes.append(temp)
for i in range(len(notes)):
note_id[notes[i]] = i
def process_text(txt, lim):
if ((lim in note_id) == False):
return f"Error: Invalid symbol for lowest note"
lowest = 100
cur_line = 1
txt = txt.split("\n")
for line in txt:
cur_word = 1
note_list = line.split()
for note in note_list:
if ((note in note_id) == False):
return f"Error: Invalid note on line {cur_line}, word {cur_word}: {note}"
nid = note_id[note]
lowest = min(lowest, nid)
cur_word += 1
cur_line += 1
res = ""
lim = note_id[lim]
for line in txt:
note_list = line.split()
for note in note_list:
nid = note_id[note]
target = nid - lowest + lim
if (target >= len(notes)):
return f"Error: Selected lowest note is too high. Please select a lower one"
res += notes[target]
res += " "
res += "\n"
return res