diff options
author | davidpkj <davidpenkow1@gmail.com> | 2022-12-03 22:26:26 +0100 |
---|---|---|
committer | davidpkj <davidpenkow1@gmail.com> | 2022-12-03 22:26:26 +0100 |
commit | 5d4a749b7c51649bcd3953cd1686856408d08121 (patch) | |
tree | d0ddab7d5ee206e9b4403d4f177d942ec1608aa0 /scripts/.local/bin/personal/klimperklamper | |
parent | 4f7ccffecdfa36c5e531654b8eec44199935d497 (diff) |
Merge in dotfiles
Diffstat (limited to 'scripts/.local/bin/personal/klimperklamper')
-rwxr-xr-x | scripts/.local/bin/personal/klimperklamper | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/scripts/.local/bin/personal/klimperklamper b/scripts/.local/bin/personal/klimperklamper new file mode 100755 index 0000000..6bd15ad --- /dev/null +++ b/scripts/.local/bin/personal/klimperklamper @@ -0,0 +1,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() + |