Sending and receiving MIDI sync data

1.2k views Asked by At

I want to send MMC to Cubase to tell it to start, stop and rewind, and Cubase sends timecode to my program to keep in sync. Sometimes this script works flawlessly, other times it gets blocked up somehow and stops responding, while MIDIOX shows me that Cubase continues to send MIDI timecode - not 100 per second, but 1 every 3 seconds! Could Cubase have a higher priority and so my script is not allowed to process the input, then it gets blocked? Except it doesn't help for me to flush the messages. Any ideas?

import time
import rtmidi as md
mtcin = md.MidiIn()
mout = md.MidiOut()
mtcin.ignore_types(sysex=False, timing=False)
mtcin.open_port(0)
mout.open_port(3)
event_list = [(0,123),(0.13,234,45),(1.5,345,56),(3,14)]
ind = 0
timecode = -1
mout.send_message((0xf0, 0x7f, 127, 6, 2, 0xf7))
while ind < len(event_list):
    msg = mtcin.get_message()
    if msg:
        timecode += 1
    if event_list[ind][0] <= timecode/100.0:
        print event_list[ind][1:]
        ind += 1
    time.sleep(0.001)
mout.send_message((0xf0, 0x7f, 127, 6, 1, 0xf7))
mout.send_message((0xf0, 0x7f, 127, 6, 0x44, 6, 1, 32, 0, 0, 0, 0, 0xf7))
1

There are 1 answers

1
user2045139 On

Have you tried using a callback function for incoming midi messages instead a while loop? I had a project that updated a UI based on cc messages and it was slow and out of sync when I was using get_message() in a while loop. When I switched to using callbacks everything was golden and perfectly in sync.