Closed
Description
I was trying to make a experimental computer keyboard from a Midi keyboard and was using this code:
import binascii
import os
from evdev import uinput, ecodes as e
import jack
from subprocess import Popen
Keys={
"3c":"a",
"3e":"s",
"40":"d",
"41":"f",
"43":"g",
"48":"a",
"4a":"s",
"4c":"d",
"4d":"f",
"4f":"g",
"51":"DOWN",
"52":"up",
"53":"left",
"54":"right",
"54":"enter",
"55":"backspace",
"56":"p",
}
def press(key):
pid=os.fork()
if pid==0:
with uinput.UInput() as ui:
eval("ui.write(e.EV_KEY, e.KEY_" + key.upper() +", 1)")
ui.syn()
setup = ['a2j', 'a2jmidid -e']
a2j = [Popen(cmd, shell=True) for cmd in setup]
client=jack.Client("VirtualControl")
inp=client.midi_inports.register("Input")
@client.set_process_callback
def process(frames):
for offset, data in inp.incoming_midi_events():
midihex = binascii.hexlify(data).decode()
if(midihex!='f8'):
pressed = midihex[0:2] =='90'
code=midihex[2:4]
intensity=midihex[4:6]
if pressed:
press(Keys[code])
#print(midihex)
#print('{0}: 0x{1}'.format(client.last_frame_time + offset, sbinascii.hexlify(data).decode()))
#press("b")
with client:
print('#' * 80)
print('press Return to quit')
print('#' * 80)
input()
Problem is that it crashes right after i press one or two keys. With the error:
File "/usr/local/lib/python3.6/dist-packages/jack.py", line 1787, in incoming_midi_events
assert not err, err
AssertionError: -105
This fork is there because i first thought it was something related with the small delay on the simulated keypress. If i just use print it works fine. What is causing this issue? The keys get inputed and then it crashes.
I noticed your code:
for i in range(_lib.jack_midi_get_event_count(buf)):
err = _lib.jack_midi_event_get(event, buf, i)
# TODO: proper error handling if this ever happens:
assert not err, err
yield event.time, _ffi.buffer(event.buffer, event.size)
I just noticed that if I simply comment out the assert line my script works! I don't know what it does so.... Ill keep this way for now.
Metadata
Metadata
Assignees
Labels
No labels