Skip to content

Instantly share code, notes, and snippets.

@libasoles
Created May 20, 2019 23:21
Show Gist options
  • Save libasoles/5f157f8580ad5c558279c6e50447f505 to your computer and use it in GitHub Desktop.
Save libasoles/5f157f8580ad5c558279c6e50447f505 to your computer and use it in GitHub Desktop.
Connect microKey to Fluid Synth (with ALSA aconnect)
# run as: python microKey2FluidSynth.py
import os
import re
alsaOutputs = os.popen("aconnect -o").readlines()
def getKeyboardClientID():
return getClientID("microKEY") # could be any other
def getFluidSynthClientID():
return getClientID("FLUID Synth")
def getClientID(condition):
conditions = ["client", condition]
for line in alsaOutputs:
if all(condition in line for condition in conditions):
clientStr = line.split(":")[0]
clientID = re.search('\d+', clientStr).group(0)
return clientID
return -1
keyboardID = getKeyboardClientID()
fluidSynthID = getFluidSynthClientID()
command = "aconnect {}:0 {}:0".format(keyboardID, fluidSynthID)
print(os.popen(command).read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment