Python Forum
rtmidi problem after running the code x times
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
rtmidi problem after running the code x times
#2
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()
Reply


Messages In This Thread
RE: rtmidi problem after running the code x times - by philipbergwerf - Apr-04-2021, 07:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in running a code akbarza 7 815 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 485 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 619 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Different code execution times Wirbelwind94 4 887 Oct-06-2023, 12:30 PM
Last Post: snippsat
Question Running an action only between certain times alexbca 9 1,927 Mar-15-2023, 04:21 PM
Last Post: deanhystad
  Code running many times nad not just one? korenron 4 1,456 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 3,996 Jul-01-2022, 02:51 PM
Last Post: maiya
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 1,612 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  Why is this Python code running twice? mcva 5 5,485 Feb-02-2022, 10:21 AM
Last Post: mcva
  Python keeps running the old version of the code quest 2 3,951 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020