Apr-04-2021, 07:07 PM
I found the solution to this problem. I made a variable 'midiswitch' that is standard set to 1 and when the program closes it is set to 0. The while loop checks if the variable is 0 and closes the loop if so.
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 midiswitch == 0: return msg = self.device.getMessage(2500) if msg: if msg.isNoteOn(): if midi_record_toggle == 1: note = msg.getNoteNumber() - 20 if shiftkey == 0: textw.insert(textw.index(INSERT), number2pitch[note]) elif shiftkey == 1: textw.insert(textw.index(INSERT), '_'+number2pitch[note]) renderkey() dev = rtmidi.RtMidiIn() for i in range(dev.getPortCount()): device = rtmidi.RtMidiIn() print('OPENING',dev.getPortName(i)) collector = Collector(device, i) collector.start() threading.Thread(target=midi_input).start()