From 076f169c29412e40211200acad85a438a0e6b180 Mon Sep 17 00:00:00 2001 From: bklronin Date: Mon, 1 Jul 2024 10:08:24 +0200 Subject: [PATCH] - Added wait for devices if none connected --- ashost.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ashost.py b/ashost.py index cc677a8..b9936ff 100644 --- a/ashost.py +++ b/ashost.py @@ -6,6 +6,19 @@ import os import time import mido +def check_devices() -> tuple: + # Retrieve the list of available input devices + devices_in = mido.get_input_names() + devices_out = mido.get_output_names() + + devices_in = remove_through_ports(devices_in) + devices_out = remove_through_ports(devices_out) + print("Available MIDI input devices:", devices_in) + + return devices_in, devices_out + + + def match_device_name(input_name, output_list): # Function to match device names flexibly for device in output_list: @@ -139,13 +152,13 @@ def relay_midi_host_to_out(host_name, devices_out): main_run() def main_run(): - # Retrieve the list of available input devices - devices_in = mido.get_input_names() - devices_out = mido.get_output_names() - devices_in = remove_through_ports(devices_in) - devices_out = remove_through_ports(devices_out) - print("Available MIDI input devices:", devices_in) + devices_in, devices_out = check_devices() + + # Check if at least one and one output device is connected + while len(devices_in) < 1 and len(devices_out) < 1: + time.sleep(3) + main_run() base_frequency = 130 # Starting frequency in Hz increment = 50 # Frequency increment for each device