Skip to content

Instantly share code, notes, and snippets.

@monkut
Created January 4, 2021 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monkut/5079c866ca7455b12d6125fc013a926a to your computer and use it in GitHub Desktop.
Save monkut/5079c866ca7455b12d6125fc013a926a to your computer and use it in GitHub Desktop.
auto connect midi controller script for fluidsynth, rasbian
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