Skip to content

Commit

Permalink
Hopefully pick the appropriate audio driver for fluidsynth
Browse files Browse the repository at this point in the history
  • Loading branch information
jpetazzo committed Mar 13, 2018
1 parent f267a93 commit 9625d35
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion fluidsynth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import glob
import logging
import os
import mido
import re
import subprocess
Expand Down Expand Up @@ -48,8 +49,33 @@ def __init__(self):
print("Suggestion: 'cd soundfonts; ./download-soundfonts.sh'")
exit(1)

# Try to detect which sound driver to use.
audio_driver = os.environ.get("GRIODE_AUDIO_DRIVER")
if audio_driver is None:
uid = os.getuid()
pulseaudio_pidfile = "/run/user/{}/pulse/pid".format(uid)
if os.path.isfile(pulseaudio_pidfile):
try:
pulseaudio_pid = int(open(pulseaudio_pidfile).read())
except:
logging.exception("Could not read pulseaudio PID")
pulseaudio_pid = None
if pulseaudio_pid is not None:
if os.path.isdir("/proc/{}".format(pulseaudio_pid)):
audio_driver = "pulseaudio"
if audio_driver is None:
if sys.platform == "linux":
audio_driver = "alsa"
if sys.platform == "darwin":
audio_driver = "coreaudio"
if audio_driver is None:
logging.error("Could not determine audio driver.")
logging.error("Please set GRIODE_AUDIO_DRIVER.")
exit(1)
logging.info("Using audio driver: {}".format(audio_driver))

popen_args = [
"fluidsynth", "-s", "-a", "pulseaudio",
"fluidsynth", "-s", "-a", audio_driver,
"-o", "synth.midi-bank-select=mma",
"-o", "synth.sample-rate=44100",
"-c", "8", "-p", "griode"
Expand Down

0 comments on commit 9625d35

Please sign in to comment.