Sort audio outputs

This commit is contained in:
Matthew Stratford 2021-04-04 23:14:30 +01:00
parent ccb5886698
commit fe80b803f8
3 changed files with 15 additions and 9 deletions

View file

@ -1,4 +1,4 @@
from typing import Any, Dict from typing import Any, Dict, List
import sounddevice as sd import sounddevice as sd
from helpers.os_environment import isMacOS from helpers.os_environment import isMacOS
@ -10,7 +10,7 @@ class DeviceManager():
return device["max_output_channels"] > 0 return device["max_output_channels"] > 0
@classmethod @classmethod
def _getDevices(cls) -> sd.DeviceList: def _getAudioDevices(cls) -> sd.DeviceList:
# To update the list of devices # To update the list of devices
# Sadly this doesn't work on MacOS. # Sadly this doesn't work on MacOS.
if not isMacOS(): if not isMacOS():
@ -20,7 +20,7 @@ class DeviceManager():
return devices return devices
@classmethod @classmethod
def getOutputs(cls) -> sd.DeviceList: def getAudioOutputs(cls) -> List[Dict]:
outputs: sd.DeviceList = filter(cls._isOutput, cls._getDevices()) outputs: List[Dict] = list(filter(cls._isOutput, cls._getAudioDevices()))
outputs = sorted(outputs, key=lambda k: k['name'])
return outputs return [{"name": None}] + outputs

View file

@ -130,7 +130,7 @@ def ui_config():
for i in range(state.state["num_channels"]): for i in range(state.state["num_channels"]):
channel_states.append(status(i)) channel_states.append(status(i))
outputs = DeviceManager.getOutputs() outputs = DeviceManager.getAudioOutputs()
data = { data = {
'channels': channel_states, 'channels': channel_states,

View file

@ -1,9 +1,15 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content_inner %} {% block content_inner %}
<h3 class="h5">Audio Outputs</h3>
<code> <code>
<a href="/player/0/output/none">Set Channel 0</a> <a href="/player/1/output/none">Set Channel 1</a> <a href="/player/2/output/none">Set Channel 2</a> - System Default Output<br>
{% for output in data.outputs %} {% for output in data.outputs %}
<a href="/player/0/output/{{output.name}}">Set Channel 0</a> <a href="/player/1/output/{{output.name}}">Set Channel 1</a> <a href="/player/2/output/{{output.name}}">Set Channel 2</a> - {{output.name}}<br>
Set for:
{% for channel in data.channels %}
<a href="/player/{{channel.channel}}/output/none">Channel {{channel.channel}}</a>
{% endfor %}
- {% if output.name %}{{output.name}}{% else %}System Default Output{% endif %}<br>
{% endfor %} {% endfor %}
</code> </code>
{% endblock %} {% endblock %}