From 17a8a4b900211b4b2172c5195cd512611d691aaf Mon Sep 17 00:00:00 2001 From: bklronin Date: Sat, 29 Jun 2024 20:59:50 +0200 Subject: [PATCH] - Added OP-1 compatibilty (as good as possible via "continue" command instead of start. --- ashost.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ashost.py b/ashost.py index bb077d4..455ac8f 100644 --- a/ashost.py +++ b/ashost.py @@ -46,7 +46,7 @@ def determine_host(devices_in: list) -> str: for port in inports: for message in port.iter_pending(): #print(f"Received message: ({port.name}, {message})") - if 'start' in str(message): + if 'start' in str(message) or 'continue' in str(message): master = port.name break @@ -83,31 +83,40 @@ def relay_midi_host_to_out(host_name, devices_out): recent_messages = [] try: - print(reset) + last_stop_time = 0 + debounce_delay = 0.05 # 50 milliseconds debounce time + while not reset: # Process all pending messages for message in input_port.iter_pending(): read_message = str(message) - #print(read_message) + #current_time = time.time() - if 'start' in read_message or 'stop' in read_message: + if 'clock' in read_message: + for dev in output_ports: + dev.send(message) + + if 'start' in read_message or 'continue' in read_message: for dev in output_ports: dev.send(message) recent_messages.append(read_message) - elif 'clock' in read_message: + elif 'stop' in read_message: + #if current_time - last_stop_time > debounce_delay: for dev in output_ports: dev.send(message) + recent_messages.append(read_message) + #last_stop_time = current_time + #print(recent_messages) # Keep only the last 3 messages if len(recent_messages) > 3: recent_messages.pop(0) # Check if the last 3 messages are all 'stop' - if recent_messages[-3:] == ['stop time=0', 'stop time=0', 'stop time=0']: + if len(recent_messages) >= 3 and all(msg.startswith('stop') for msg in recent_messages[-3:]): print("Exiting", recent_messages) recent_messages.clear() - reset = True break