Move audio device to DeviceManager
This commit is contained in:
parent
c1e88fcf71
commit
94e01aa144
2 changed files with 29 additions and 7 deletions
27
helpers/device_manager.py
Normal file
27
helpers/device_manager.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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?
|
|
@ -2,10 +2,10 @@ import multiprocessing
|
||||||
import player
|
import player
|
||||||
from flask import Flask, render_template, send_from_directory, request
|
from flask import Flask, render_template, send_from_directory, request
|
||||||
import json
|
import json
|
||||||
import sounddevice as sd
|
|
||||||
import setproctitle
|
import setproctitle
|
||||||
import logging
|
import logging
|
||||||
from helpers.os_environment import isMacOS
|
from helpers.os_environment import isMacOS
|
||||||
|
from helpers.device_manager import DeviceManager
|
||||||
|
|
||||||
setproctitle.setproctitle("BAPSicle - Server")
|
setproctitle.setproctitle("BAPSicle - Server")
|
||||||
|
|
||||||
|
@ -55,12 +55,7 @@ def ui_config():
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
channel_states.append(status(i))
|
channel_states.append(status(i))
|
||||||
|
|
||||||
devices = sd.query_devices()
|
outputs = DeviceManager.getOutputs()
|
||||||
outputs = []
|
|
||||||
|
|
||||||
for device in devices:
|
|
||||||
if device["max_output_channels"] > 0:
|
|
||||||
outputs.append(device)
|
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'channels': channel_states,
|
'channels': channel_states,
|
||||||
|
|
Loading…
Reference in a new issue