This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "config/config_manager.h"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@@ -15,6 +16,7 @@ namespace radiantwave::audio {
|
||||
struct AudioDeviceItem {
|
||||
std::string raw_name; // e.g. alsa_output.pci-0000_00_1f.3.analog-stereo
|
||||
std::string friendly_name; // e.g. "Built-In Speakers"
|
||||
SDL_AudioDeviceID id = 0; // SDL playback device id (0 = synthetic fallback)
|
||||
};
|
||||
|
||||
// Maps raw technical audio device strings to user-friendly labels
|
||||
@@ -51,7 +53,18 @@ public:
|
||||
|
||||
// Audio device selection
|
||||
bool switchDevice(const std::string& raw_device_name);
|
||||
bool switchDeviceById(SDL_AudioDeviceID id);
|
||||
std::string getCurrentDevice() const;
|
||||
SDL_AudioDeviceID getCurrentDeviceId() const;
|
||||
|
||||
// Handle an SDL audio device event (SDL_EVENT_AUDIO_DEVICE_ADDED / REMOVED).
|
||||
// Returns true if the active device was affected and the mixer was recreated.
|
||||
bool handleDeviceEvent(const SDL_Event& event);
|
||||
|
||||
// Pure helper (no SDL audio open): find the playback device with the given
|
||||
// SDL id, returning its raw name ("" when not found / id invalid). Exposed
|
||||
// for tests; the real lookup is through getPlaybackDevices().
|
||||
static std::string resolvePlaybackDeviceName(SDL_AudioDeviceID id);
|
||||
|
||||
// Playback control
|
||||
bool playTrack(const std::string& wav_filename);
|
||||
@@ -84,6 +97,13 @@ private:
|
||||
void startFadeIn(int slotIndex, float seconds);
|
||||
std::string displayNameFor(const std::string& wav_filename) const;
|
||||
|
||||
// Recreates the mixer on the given playback device id (0 = system default).
|
||||
// Called with mutex_ held. Preserves playback state: whichever track was
|
||||
// playing on the active slot is reloaded and resumed at full gain, an
|
||||
// in-progress fade is restarted. Returns false on failure (previous mixer is
|
||||
// left destroyed but the app remains safe to keep running muted).
|
||||
bool recreateMixerOnDevice(SDL_AudioDeviceID targetId);
|
||||
|
||||
config::ConfigManager* configManager_ = nullptr;
|
||||
db::DatabaseManager* db_ = nullptr;
|
||||
|
||||
@@ -91,6 +111,7 @@ private:
|
||||
bool enabled_ = true;
|
||||
int volume_ = 80; // 0 - 100
|
||||
std::string currentDevice_ = "";
|
||||
SDL_AudioDeviceID currentDeviceId_ = SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK;
|
||||
std::string currentTrack_ = "";
|
||||
|
||||
MIX_Mixer* mixer_ = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user