Add audio device menu button
Some checks failed
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linux32 flags:32 name:Linux GCC 32 os:ubuntu-latest]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linux64 flags:64 name:Linux GCC x64 os:ubuntu-latest]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linuxarm32 flags:arm32 name:Linux GCC ARM 32 os:ubuntu-latest]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:linuxarm64 flags:arm64 name:Linux GCC ARM 64 os:ubuntu-latest]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:macos name:macOS Apple Silicon os:macos-14]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:win32 flags:-A Win32 name:Windows VS2022 Win32 os:windows-2022]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:win64 flags:-A x64 name:Windows VS2022 x64 os:windows-2022]) (push) Has been cancelled
CD / ${{ matrix.platform.name }} ${{ matrix.config.name }} (map[flags:-DBUILD_SHARED_LIBS=FALSE name:Static], map[artifact_name:winarm64 flags:-A ARM64 name:Windows VS2022 ARM os:windows-2022]) (push) Has been cancelled
CD / Create Pi Mono Setup (push) Has been cancelled
CD / Publishing (push) Has been cancelled

Adds a basic button that cycles through the available audio output devices.
This commit is contained in:
Neptune
2025-01-30 00:12:14 -07:00
committed by Lorenzooone
parent 981acaa420
commit 7288cf163a
3 changed files with 37 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ enum AudioMenuOutAction{
AUDIO_MENU_OUTPUT_DEC,
AUDIO_MENU_OUTPUT_INC,
AUDIO_MENU_RESTART,
AUDIO_MENU_NEXT_DEVICE,
};
class AudioMenu : public OptionSelectionMenu {

View File

@@ -1,5 +1,7 @@
#include "AudioMenu.hpp"
#include "SFML/Audio/PlaybackDevice.hpp"
#define NUM_TOTAL_MENU_OPTIONS (sizeof(pollable_options)/sizeof(pollable_options[0]))
struct AudioMenuOptionInfo {
@@ -37,12 +39,19 @@ static const AudioMenuOptionInfo audio_restart_option = {
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = AUDIO_MENU_NO_ACTION,
.out_action = AUDIO_MENU_RESTART};
static const AudioMenuOptionInfo audio_next_device_option = {
.base_name = "Output Device", .false_name = "",
.is_inc = false, .dec_str = "", .inc_str = "", .inc_out_action = AUDIO_MENU_NO_ACTION,
.out_action = AUDIO_MENU_NEXT_DEVICE};
static const AudioMenuOptionInfo* pollable_options[] = {
&audio_volume_option,
&audio_mute_option,
&audio_max_latency_option,
&audio_output_type_option,
&audio_restart_option,
&audio_next_device_option,
};
AudioMenu::AudioMenu(bool font_load_success, sf::Font &text_font) : OptionSelectionMenu(){
@@ -135,6 +144,11 @@ void AudioMenu::prepare(float menu_scaling_factor, int view_size_x, int view_siz
case AUDIO_MENU_MUTE:
this->labels[index]->setText(this->setTextOptionBool(real_index, audio_data->get_mute()));
break;
case AUDIO_MENU_NEXT_DEVICE:
if (std::optional<std::string> cur_dev = sf::PlaybackDevice::getDevice()) {
this->labels[index]->setText(this->setTextOptionString(real_index, *cur_dev));
}
break;
default:
break;
}

View File

@@ -1,4 +1,7 @@
#include <iostream>
#include "frontend.hpp"
#include "SFML/Audio/PlaybackDevice.hpp"
#define FPS_WINDOW_SIZE 64
@@ -1371,6 +1374,25 @@ void WindowScreen::poll(bool do_everything) {
case AUDIO_MENU_RESTART:
this->audio_data->request_audio_restart();
break;
case AUDIO_MENU_NEXT_DEVICE:
if (std::optional<std::string> cur_dev = sf::PlaybackDevice::getDevice()) {
std::cout << *cur_dev << std::endl;
int idx = 0;
auto audio_devices = sf::PlaybackDevice::getAvailableDevices();
for (const std::string& device : audio_devices) {
if (device == *cur_dev) {
break;
}
idx++;
}
idx = std::max((idx + 1) % static_cast<int>(audio_devices.size()), 0);
std::cout << "next device: " << audio_devices.at(idx) << std::endl;
if (sf::PlaybackDevice::setDevice(audio_devices.at(idx))) {
std::cout << "Device selected: " << audio_devices.at(idx) << std::endl;
// this->audio_data->request_audio_restart();
}
}
break;
default:
break;
}