From fe80b803f8afbcab81e25334563ae28f0962cab1 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sun, 4 Apr 2021 23:14:30 +0100 Subject: [PATCH] Sort audio outputs --- helpers/device_manager.py | 12 ++++++------ server.py | 2 +- templates/config.html | 10 ++++++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/helpers/device_manager.py b/helpers/device_manager.py index e628db0..2c146f9 100644 --- a/helpers/device_manager.py +++ b/helpers/device_manager.py @@ -1,4 +1,4 @@ -from typing import Any, Dict +from typing import Any, Dict, List import sounddevice as sd from helpers.os_environment import isMacOS @@ -10,7 +10,7 @@ class DeviceManager(): return device["max_output_channels"] > 0 @classmethod - def _getDevices(cls) -> sd.DeviceList: + def _getAudioDevices(cls) -> sd.DeviceList: # To update the list of devices # Sadly this doesn't work on MacOS. if not isMacOS(): @@ -20,7 +20,7 @@ class DeviceManager(): return devices @classmethod - def getOutputs(cls) -> sd.DeviceList: - outputs: sd.DeviceList = filter(cls._isOutput, cls._getDevices()) - - return outputs + def getAudioOutputs(cls) -> List[Dict]: + outputs: List[Dict] = list(filter(cls._isOutput, cls._getAudioDevices())) + outputs = sorted(outputs, key=lambda k: k['name']) + return [{"name": None}] + outputs diff --git a/server.py b/server.py index 1cdcb8a..36ec92d 100644 --- a/server.py +++ b/server.py @@ -130,7 +130,7 @@ def ui_config(): for i in range(state.state["num_channels"]): channel_states.append(status(i)) - outputs = DeviceManager.getOutputs() + outputs = DeviceManager.getAudioOutputs() data = { 'channels': channel_states, diff --git a/templates/config.html b/templates/config.html index 33f5e8d..c35127c 100644 --- a/templates/config.html +++ b/templates/config.html @@ -1,9 +1,15 @@ {% extends 'base.html' %} {% block content_inner %} +

Audio Outputs

- Set Channel 0 Set Channel 1 Set Channel 2 - System Default Output
+ {% for output in data.outputs %} - Set Channel 0 Set Channel 1 Set Channel 2 - {{output.name}}
+ + Set for: + {% for channel in data.channels %} + Channel {{channel.channel}} + {% endfor %} + - {% if output.name %}{{output.name}}{% else %}System Default Output{% endif %}
{% endfor %}
{% endblock %}