Hi, I'm new to python, and I work on a little program fpr my rapsberry pi.
This scenario here is a little Midi sysex app for my Roland D-50 Synthesizer.
With an usb attached number keypad I can type numbers from 0 to 9 and the referenced Midi sysex file would be send out to my Roland D-50 Synthesizer.
This therefore works as expected. But now I want to improove my little python programm for the processing of 2 digits taken from the usb number keypad.
In theory the behavior should be as follow:
We check for 2 digits first, If one enters 23 we do in a "elif content == "23":" block the magic. But if one has typed only 1 digit we trigger the elif block for 1 digit. Problem for me is, I don't know how to check for 1 or 2 digits in the code.
Here is my code:
#!/usr/bin/env python
import select
import termios
import tty
import sys
import datetime
import os
class mylocontrol(object):
def __init__(self):
self.checkkeys()
def showcontent(self,content):
if content == "1":
os.system("/usr/bin/amidi -p hw:1,0,0 -s /work/MIDI/d50_00.syx")
elif content == "2":
os.system("/usr/bin/amidi -p hw:1,0,0 -s /work/MIDI/PND50-02.syx")
def getkey(self):
old_settings = termios.tcgetattr(sys.stdin)
tty.setraw(sys.stdin.fileno())
select.select([sys.stdin], [], [], 0)
answer = sys.stdin.read(1)
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings)
return answer
def checkkeys(self):
while True:
answer=self.getkey()
if "|" in answer:
break
else:
ret = self.showcontent(answer)
mylo = mylocontrol()
Maybe someone could help me out!