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
|
#!/usr/bin/env python3
import random
import sys
import os
slowLength = [ 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2 ]
mediumLength = [ 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4 ]
fastLength = [ 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16 ]
notes = [ "c", "cis", "d", "dis", "e", "f", "fis", "g", "gis", "a", "ais", "b" ]
string = '\\version "2.22.1"\n\\header {\ntitle = "Die Dissonanz der Schulzeit"\nsubtitle = "Musik Klausurersatzleistung"\ncomposer = "David Penkowoj"\ncopyright = ""\ntagline = ""\n}\n\\score {\n\\fixed c\' {\n\\time 4/4\n\\tempo "Allegro" 4 = 160\n'
variationDict = {
"normal": [],
"mirror": [],
"reverse": [],
"reverseMirror": [],
}
def mirror(noteCopy):
result = []
mirrorAxisNote = noteCopy[0]
baseIndex = notes.index(mirrorAxisNote)
for note in noteCopy:
index = notes.index(note)
newNoteIndex = index + (- 2 * (index - baseIndex))
result.append(notes[newNoteIndex % len(notes)])
return result
def reverse(noteCopy):
return noteCopy[::-1]
def reverseMirror(noteCopy):
return mirror(noteCopy)[::-1]
def randomVariation(rand):
rand = random.randrange(1, 5)
if rand == 1:
return variationDict["normal"].copy(), "Grundreihe"
if rand == 2:
return variationDict["mirror"].copy(), "Umkehrung"
if rand == 3:
return variationDict["reverse"].copy(), "Krebs"
if rand == 4:
return variationDict["reverseMirror"].copy(), "Krebsumkehrung"
def getLength(notesCopy, location):
lengthList = []
if location <= 1 or location >= 7:
lengthList = slowLength.copy()
elif location >= 3 and location <= 5:
lengthList = fastLength.copy()
else:
lengthList = mediumLength.copy()
# asd
return lengthList
def changeLength(notesCopy, location):
for note in notesCopy:
index = notesCopy.index(note)
rand = random.choice(lengthList)
notesCopy[index] = (f"{note}{rand} ")
lengthList.remove(rand)
return notesCopy
def generateRows():
notesCopy = notes.copy()
random.shuffle(notesCopy)
variationDict["normal"] = notesCopy
variationDict["mirror"] = mirror(notesCopy)
variationDict["reverse"] = reverse(notesCopy)
variationDict["reverseMirror"] = reverseMirror(notesCopy)
def makeMusescore():
global string
string = "#!/usr/local/bin/xdotool\n\n"
generateRows()
for i in range(4):
articualtedVariation, variationType = randomVariation(i)
getLength(articualtedVariation, i)
variation = " ".join(articualtedVariation)
string = f"{string}type {variation}\nkey Enter\n"
with open("/tmp/klimperklamper", "w") as file:
file.write(string)
file.close()
os.system("nvim /tmp/klimperklamper")
def makePDF():
global string
generateRows()
for i in range(8):
articualtedVariation, variationType = randomVariation()
changeLength(articualtedVariation, i)
variation = " ".join(articualtedVariation)
string = f"{string}\\mark \\markup \\smaller \\italic {variationType} {variation}|\\break\n"
string = string + "}\n\\midi {} \n\\layout {\nindent = 0\\mm\n}\n}"
with open("/tmp/klimperklamper", "w") as file:
file.write(string)
file.close()
os.system("nvim /tmp/klimperklamper")
os.system("lilypond -o /tmp/klimperklamper /tmp/klimperklamper")
os.system("zathura /tmp/klimperklamper.pdf")
if __name__ == "__main__":
if sys.argv[1] == "musescore":
makeMusescore()
else:
makePDF()
|