Apr-03-2021, 05:01 PM
def midi_input(): class Collector(threading.Thread): def __init__(self, device, port): threading.Thread.__init__(self) self.setDaemon(True) self.port = port self.portName = device.getPortName(port) self.device = device self.quit = False def run(self): self.device.openPort(self.port) self.device.ignoreTypes(True, False, True) while True: if self.quit: return msg = self.device.getMessage(2500) if msg: if msg.isNoteOn(): if midi_record_toggle == 1: note = msg.getNoteNumber() - 20 textw.insert(textw.index(INSERT), number2pitch[note]) render('q', papercolor) dev = rtmidi.RtMidiIn() for i in range(dev.getPortCount()): device = rtmidi.RtMidiIn() print('OPENING',dev.getPortName(i)) collector = Collector(device, i) collector.start() sys.stdin.read(1) for c in collectors: c.quit = True threading.Thread(target=midi_input).start()I am running this using threading. I don't know what the risks are... The code runs fine but if I run it more than 16 times it gives an Error: 'ALSA lib seq_hw.c:466:(snd_seq_hw_open) open /dev/snd/seq failed: Cannot allocate memory. I think it doesn't close the midi port/process but I don't know how to close this correctly. I noticed that Sunvox(a really cool synth) gives the same error on midi input after I messed up with my code. Is there anything suspicious about my code? how am I supposed to use threading; I used this to make a while loop run while other functions are still working. I took the code from a GitHub page and modified it a little. Thanks!