summaryrefslogblamecommitdiffstats
path: root/gromka/keyboard.py
blob: 4873636e44663b46ac8766c4bdaa58bbb32356f2 (plain) (tree)







































                                                                                                                                                                                                                                      



                                                                                         





                                                         
#!/usr/bin/python3
import sys
try:
	from bs4 import BeautifulSoup
except ModuleNotFoundError:
	raise ModuleNotFoundError("beautifulsoup4 not found. emerge --ask dev-python/beautifulsoup4")

if len(sys.argv) != 2:
	raise ValueError("specify showfile in 1st argument")

with open(sys.argv[1], "r") as f:
	data = f.read();

show = BeautifulSoup(data, "xml")

buttons = "F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 Pause Ins".split(" ") + "/ 1 2 3 4 5 6 7 8 9 0 ' +".split(" ") + "Q W E R T Z U I O P Š }".split(" ") + "A S D F G H J K L Č { Ž".split(" ") + "< Y X C V B N M , . -".split(" ")
keys = {}
for button in buttons:
	keys[button] = ""

for key in show.find_all("Key") + show.find_all("MultKey") + show.find_all("DivKey"):
	keys[key.string] = ""
	for parent in key.parents:
		if parent.has_attr("Caption"):
			keys[key.string] += parent["Caption"] + " (" + parent.name + ")"
			break

for key in keys:
	print(key + ": " + keys[key])

print("\nmidi botex:")

midi = []
for x in range(0, 24):
	midi.append("")

for key in show.find_all("Input"):
	if key.has_attr("Universe") and key["Universe"] == "0" and key.has_attr("Channel") and int(key["Channel"]) >= 198 and int(key["Channel"]) <= 198 + 24:
		if midi[int(key["Channel"]) - 198] != "":
			midi[int(key["Channel"]) - 198] += ", "
		caption = ""
		if key.parent.has_attr("Caption"):
			caption = key.parent["Caption"]
		midi[int(key["Channel"]) - 198] += caption + " (" + key.parent.name + ")"

for key in range(0, 24):
	kje = " zgoraj"
	if (key >= 12):
		kje = " spodaj"
	print(str(key % 12 + 1) + kje + ": " + midi[key])