Created
January 4, 2021 05:10
-
-
Save monkut/5079c866ca7455b12d6125fc013a926a to your computer and use it in GitHub Desktop.
auto connect midi controller script for fluidsynth, rasbian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import sleep | |
from subprocess import check_output, CalledProcessError | |
controller_identifier = 'microKEY2' | |
configured = False | |
while True: | |
aconnect_list_command = ('aconnect', '-o') | |
output_bytes = check_output(aconnect_list_command) | |
output_str = output_bytes.decode('utf8') | |
controller_attached = False | |
for line in output_str.split('\n'): | |
if controller_identifier in line: | |
controller_attached = True | |
print("{} attached".format(controller_identifier)) | |
break | |
if controller_attached and not configured: | |
# connect midi controller | |
print('connecting ...') | |
aconnect_connect_command = "aconnect '{}':0 'fluid':0".format(controller_identifier) | |
try: | |
output_bytes = check_output(aconnect_connect_command, shell=True) | |
configured = True | |
print("connected: {}".format(controller_identifier)) | |
except CalledProcessError as e: | |
print(e.args) | |
elif not controller_attached: | |
configured = False | |
sleep(1) | |
print('.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment