audiodrivers
This commit is contained in:
parent
9d6babd722
commit
678ac77842
1 changed files with 24 additions and 3 deletions
|
|
@ -1,8 +1,13 @@
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
from importlib import resources
|
from importlib import resources
|
||||||
|
import sys
|
||||||
|
|
||||||
import fluidsynth
|
try:
|
||||||
|
import fluidsynth
|
||||||
|
except ImportError:
|
||||||
|
print("Error: The 'pyfluidsynth' python package is missing.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
from atonatui.constants import NOTE_TO_MIDI, GENERAL_MIDI_PROGRAMS, SOUNDFONTS
|
from atonatui.constants import NOTE_TO_MIDI, GENERAL_MIDI_PROGRAMS, SOUNDFONTS
|
||||||
from atonatui.settings_mixin import Settings
|
from atonatui.settings_mixin import Settings
|
||||||
|
|
@ -10,8 +15,24 @@ from atonatui.settings_mixin import Settings
|
||||||
|
|
||||||
class AudioMixin:
|
class AudioMixin:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
try:
|
||||||
self.fs = fluidsynth.Synth()
|
self.fs = fluidsynth.Synth()
|
||||||
self.fs.start(driver="alsa" if os.name != "nt" else "dsound")
|
except OSError:
|
||||||
|
print("\n[!] Error: FluidSynth system library not found.", file=sys.stderr)
|
||||||
|
print("Please install the system fluidysnth package first:", file=sys.stderr)
|
||||||
|
print(" - Arch Linux: sudo pacman -S fluidsynth", file=sys.stderr)
|
||||||
|
print(" - Ubuntu/Debian: sudo apt install fluidsynth\n", file=sys.stderr)
|
||||||
|
print(" - mac: brew install fluidsynth\n", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if sys.platform == "darkwin" or sys.platform == "darwin":
|
||||||
|
audio_driver = "coreaudio"
|
||||||
|
elif os.name == "nt":
|
||||||
|
audio_driver = "dsound"
|
||||||
|
else:
|
||||||
|
audio_driver = "alsa"
|
||||||
|
|
||||||
|
self.fs.start(driver=audio_driver)
|
||||||
|
|
||||||
self.sf_id = None
|
self.sf_id = None
|
||||||
self.update_sf(SOUNDFONTS[Settings.INSTRUMENT])
|
self.update_sf(SOUNDFONTS[Settings.INSTRUMENT])
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue