Create objects for tracking audio devices

This commit is contained in:
NeilClack
2026-06-23 11:22:21 -05:00
parent 8cd43e66e1
commit 30dd5ffdcb
+44 -7
View File
@@ -37,20 +37,34 @@ var AudioFileList = []db.AudioFile{
const triangleSize = float32(16)
type AudioDevice struct {
Label string
ID int
}
type AudioOptions struct {
// Page Attributes
Base
font *fontManager.FontEntry
textShader *shaderManager.Shader
solidShader *shaderManager.Shader
title StringItem
prompt StringItem
font *fontManager.FontEntry
textShader *shaderManager.Shader
solidShader *shaderManager.Shader
CfgPtr *db.AppConfig
// Page Textures
title StringItem
prompt StringItem
// Layout
verticalMargin int32
ItemScale float32
CfgPtr *db.AppConfig
// Audio toggle
AudioStatusToggle StringItem
// Audio Devices
AudioDevices []AudioDevice
AudioDeviceTextures []StringItem
// Volume row
VolumeLabel StringItem
volumePercent StringItem
@@ -187,6 +201,29 @@ func (p *AudioOptions) CreateAudioStatusItem() error {
return nil
}
// ── Audio Output Devices ──────────────────────────────────────────────────────
func (p *AudioOptions) GetAudioDevices() error {
numAudioDevices := sdl.GetNumAudioDevices(false)
if numAudioDevices == 0 {
return nil
}
var audioDevices = make([]AudioDevice, numAudioDevices)
for i := range numAudioDevices {
audioDevice := sdl.GetAudioDeviceName(i, false)
audioDevices = append(audioDevices, AudioDevice{Label: audioDevice, ID: i})
}
p.AudioDevices = audioDevices
for i := range audioDevices {
newAudioDeviceStringItem, err := NewStringItem(p.AudioDevices[i].Label, p.font, colors.White)
if err != nil {
return err
}
p.AudioDeviceTextures = append(p.AudioDeviceTextures, newAudioDeviceStringItem)
}
return nil
}
// ── Volume ────────────────────────────────────────────────────────────────────
func (p *AudioOptions) CreateVolumePercentItem() error {
@@ -335,7 +372,7 @@ func (p *AudioOptions) renderVolumeBar() error {
{{bx, by}, {bw, thickness}},
{{bx, by + bh - thickness}, {bw, thickness}},
{{bx, by}, {thickness, bh}},
{{bx + bw - thickness}, {thickness, bh}},
{{bx + bw - thickness, by}, {thickness, bh}},
}
for _, r := range outlineRects {
if err := p.RenderSolidColorQuad(p.solidShader, r[0], r[1], colors.Green); err != nil {