BAPSicle/helpers/device_manager.py

28 lines
616 B
Python
Raw Normal View History

2020-11-03 21:24:45 +00:00
import sounddevice as sd
import importlib
from os_environment import isMacOS
class DeviceManager():
@classmethod
def _isOutput(self, device):
return device["max_output_channels"] > 0
@classmethod
def _getDevices(self):
# To update the list of devices
# Sadly this doesn't work on MacOS.
if not isMacOS():
sd._terminate()
sd._initialize()
devices = sd.query_devices()
return devices
@classmethod
def getOutputs(self):
outputs = filter(self._isOutput, self._getDevices())
return outputs
# TODO: Maybe some hotplug event triggers support for the players?