bass clef, and better template

This commit is contained in:
2023-06-05 15:53:44 +02:00
parent 6753c417ec
commit a4750c86d3
+15 -6
View File
@@ -3,7 +3,8 @@ from __future__ import print_function
import logging
import sys
import time
from random import randrange
from string import Template
from random import randrange, choice
import subprocess
import tkinter as tk
@@ -16,7 +17,8 @@ logging.basicConfig(level=logging.INFO)
notes_sharp = ["c", "cis", "d", "dis", "e", "f", "fis", "g", "gis", "a", "ais", "b"]
lilypond = '''
lilypond = Template(
'''\\version "2.24.1"
\paper {
#(set-paper-size "a10landscape")
indent = 0\mm
@@ -26,15 +28,18 @@ lilypond = '''
oddFooterMarkup = ""
evenFooterMarkup = ""
}
'''
\\relative {
\clef ${CLEF}
${NOTE}
}
''')
window = tk.Tk()
class Trainer():
def __init__(self):
self.secret = 0
self.lb = 60
self.lb = 36 # middle C is 60
self.ub = 84 # 108
self.image = None
self.image_label = tk.Label(window)
@@ -45,7 +50,11 @@ class Trainer():
def newNote(self):
self.secret = randrange(self.lb, self.ub)
self.print()
ly = lilypond + f"{{{self.convertNote(self.secret)}}}"
if abs(60 - self.secret) <= 4:
clef = choice(["bass", "treble"])
else:
clef = "bass" if self.secret < 60 else "treble"
ly = lilypond.substitute(CLEF=clef, NOTE=f"{{{self.convertNote(self.secret)}}}")
with open("lily.txt", "w") as f:
f.write(ly)
f.close()