- cleanup
This commit is contained in:
parent
809cd8a46d
commit
d8e837963b
21
ashost.py
21
ashost.py
@ -15,7 +15,7 @@ def match_device_name(input_name, output_list):
|
||||
return None
|
||||
|
||||
|
||||
def determine_host(devices_in):
|
||||
def determine_host(devices_in: list) -> str:
|
||||
master = None
|
||||
"""
|
||||
Determine the host by listening for 'start' messages on input ports.
|
||||
@ -29,9 +29,6 @@ def determine_host(devices_in):
|
||||
# Open all the input ports
|
||||
inports = [mido.open_input(device) for device in devices_in]
|
||||
|
||||
# Create a MultiPort to listen on all input ports
|
||||
#ports = MultiPort(inports, True)
|
||||
|
||||
print("Listening for messages...")
|
||||
try:
|
||||
while not master:
|
||||
@ -46,7 +43,7 @@ def determine_host(devices_in):
|
||||
print("Interrupted by user.")
|
||||
|
||||
finally:
|
||||
# Ensure all ports are closed
|
||||
# Ensure all ports are closed, important to not get a stuck script without errors
|
||||
for port in inports:
|
||||
port.close()
|
||||
print("Closed all input ports.")
|
||||
@ -65,7 +62,7 @@ def relay_midi_host_to_out(host_name, devices_out):
|
||||
#host_name = f'{host_name}'
|
||||
reset = False
|
||||
# Open the input port
|
||||
print("Opening Input ffsk", host_name)
|
||||
print("Opening Input", host_name)
|
||||
|
||||
input_port = mido.open_input(host_name)
|
||||
output_ports = [mido.open_output(device) for device in devices_out]
|
||||
@ -80,19 +77,15 @@ def relay_midi_host_to_out(host_name, devices_out):
|
||||
#print("Entering loop", input_port.iter_pending() )
|
||||
for message in input_port.iter_pending():
|
||||
read_message = str(message)
|
||||
#spread_the_word = MultiPort(output_ports)
|
||||
#print(read_message)
|
||||
|
||||
if 'start' in read_message or 'stop' in read_message:
|
||||
for dev in output_ports:
|
||||
dev.send(message)
|
||||
recent_messages.append(read_message)
|
||||
#print("SS")
|
||||
|
||||
elif 'clock' in read_message:
|
||||
for dev in output_ports:
|
||||
dev.send(message)
|
||||
#print("clock")
|
||||
|
||||
# Keep only the last 3 messages
|
||||
if len(recent_messages) > 3:
|
||||
@ -100,9 +93,6 @@ def relay_midi_host_to_out(host_name, devices_out):
|
||||
|
||||
# Check if the last 3 messages are all 'stop'
|
||||
if recent_messages[-3:] == ['stop time=0', 'stop time=0', 'stop time=0']:
|
||||
#print("Received 'stop' three times in a row")
|
||||
# Perform the desired action when 'stop' is received three times in a row
|
||||
# For example, resetting the list
|
||||
recent_messages.clear()
|
||||
|
||||
reset = True
|
||||
@ -118,7 +108,6 @@ def relay_midi_host_to_out(host_name, devices_out):
|
||||
print(input_port)
|
||||
|
||||
for port in output_ports:
|
||||
#port.reset()
|
||||
port.close()
|
||||
print(port)
|
||||
print("Closed all MIDI ports.")
|
||||
@ -134,7 +123,7 @@ def main_run():
|
||||
devices_out = mido.get_output_names()
|
||||
print("Available MIDI input devices:", devices_in)
|
||||
|
||||
# Call the function to start receiving messages from all devices
|
||||
# Listen for devices that send start and return the host name
|
||||
midi_host_in = determine_host(devices_in)
|
||||
print(midi_host_in)
|
||||
|
||||
@ -149,8 +138,6 @@ def main_run():
|
||||
if midi_host_in:
|
||||
relay_midi_host_to_out(midi_host_in, devices_out)
|
||||
|
||||
print("mido died")
|
||||
|
||||
main_run()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user