-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableV2.py
189 lines (145 loc) · 4.67 KB
/
tableV2.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from noteV2 import Note
from musiqueV2 import Musique
import os
def main2():
musique = Musique()
musique.load("saves/test.txt")
musique.displayTable()
def main():
notes_o = open("notes/note.txt", "r")
note = "INIT"
accords = []
while note != "" and note != "\n":
note = notes_o.readline()
if note != "" and note != "\n":
accords.append(Note(note))
notes_o = input("chaine : ")
notes = notes_o.split(" ")
mu = input("saisir nom musique : ")
a = input("Saisir accordage : ")
try:
os.mkdir("musiques/"+mu)
except :
print(mu + " already exits")
path = "musiques/"+mu
if a != "" and len(a) == 6:
musique = Musique(mu, accordage=a, path=path)
else:
musique = Musique(mu, path=path)
a = "EADGBe"
chaine = open(path+"/chaine_"+mu+".txt", "w")
chaine.write(a+"\n")
chaine.write(notes_o)
chaine.close()
for n in notes:
if getAccord(n, accords) is not None:
musique.addNote(getAccord(n, accords))
else:
new = createNote(n)
if new is not None:
musique.addNote(new)
# musique.displayTable()
# musique.displayDiag()
musique.saveTable()
musique.saveDiag()
musique.saveProject()
def getAccord(name, accord):
for a in accord:
if a.getName() == name:
return a
return None
def createNote(note, accordage):
cordes = accordage
if 2 <= len(note) <= 3 and note.upper() != "LF" and note.upper() != "END":
for c in cordes:
if note.find(c, 0) != -1:
if len(note) == 3:
if note[1].isdigit() and note[2].isdigit():
nb = cordes.index(c)
n = note + ":" + note + "|" + createCase(nb, note[1]+note[2]) + "|" + createDoights(nb)
return Note(n)
elif len(note) == 2:
if note[1].isdigit():
nb = cordes.index(c)
n = note + ":" + note + "|" + createCase(nb, note[1]) + "|" + createDoights(nb)
return Note(n)
elif len(note) > 3 and note.upper() != "LF" and note.upper() != "END":
cords = []
c = 1
while c < len(note):
corde = "" + note[c-1]
while c < len(note) and cordes.find(note[c]) < 0:
corde += note[c]
c += 1
c += 1
cords.append(corde)
if len(cords) <= 6:
accord = ["x", "x", "x", "x", "x", "x"]
for c in cords:
n = cordes.find(c[0])
if n != -1:
accord[n] = c.replace(c[0], "")
no = note + ":" + note + "|"
for a in range(0, len(accord)-1):
no += accord[a] + ","
no += accord[len(accord)-1] + "|"
# print(no)
maxi = Note.maxi(accord)
mini = Note.mini(accord)
doights = ["0", "0", "0", "0", "0", "0"]
d = [1, 2, 3, 4]
for ca in range(mini, maxi+1):
for co in range(0, 6):
if accord[co].isdigit():
if int(accord[co]) == ca:
if len(d) > 0:
doights[co] = str(d[0])
d.remove(d[0])
else:
return
for d in doights:
no += d
return Note(no)
elif note.upper() == "LF" or note.upper() == "END":
return Note(note + ":" + note + "|" + "x,x,x,x,x,x" + "|" + "000000")
return None
def createCase(n, c):
note = ""
for i in range(0, 5):
if n == i:
note += c+","
else:
note += "x,"
i = 5
if n == i:
note += c
else:
note += "x"
return note
def createDoights(n):
doight = ""
for i in range(0, 6):
if i == n:
doight += "1"
else:
doight += "0"
return doight
if __name__ == '__main__':
main()
def main1(notes, musique):
notes_o = open("notes/note.txt", "r")
note = "INIT"
accords = []
while note != "" and note != "\n":
note = notes_o.readline()
if note != "" and note != "\n":
accords.append(Note(note))
notes = notes.split(" ")
musique.emptyNotes()
for n in notes:
if getAccord(n, accords) is not None:
musique.addNote(getAccord(n, accords))
else:
new = createNote(n, musique.getAccordage())
if new is not None:
musique.addNote(new)