add settings UI to choose audio device
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strconv"
|
"strconv"
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
|
"supersonic/player"
|
||||||
"supersonic/ui/dialogs"
|
"supersonic/ui/dialogs"
|
||||||
"supersonic/ui/util"
|
"supersonic/ui/util"
|
||||||
"supersonic/ui/widgets"
|
"supersonic/ui/widgets"
|
||||||
@@ -305,13 +306,22 @@ func (c *Controller) ShowAboutDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) ShowSettingsDialog() {
|
func (c *Controller) ShowSettingsDialog() {
|
||||||
dlg := dialogs.NewSettingsDialog(c.App.Config)
|
devs, err := c.App.Player.ListAudioDevices()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error listing audio devices: %v", err)
|
||||||
|
devs = []player.AudioDevice{{Name: "auto", Description: "Autoselect device"}}
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg := dialogs.NewSettingsDialog(c.App.Config, devs)
|
||||||
dlg.OnReplayGainSettingsChanged = func() {
|
dlg.OnReplayGainSettingsChanged = func() {
|
||||||
c.App.PlaybackManager.SetReplayGainOptions(c.App.Config.ReplayGain)
|
c.App.PlaybackManager.SetReplayGainOptions(c.App.Config.ReplayGain)
|
||||||
}
|
}
|
||||||
dlg.OnAudioExclusiveSettingChanged = func() {
|
dlg.OnAudioExclusiveSettingChanged = func() {
|
||||||
c.App.Player.SetAudioExclusive(c.App.Config.LocalPlayback.AudioExclusive)
|
c.App.Player.SetAudioExclusive(c.App.Config.LocalPlayback.AudioExclusive)
|
||||||
}
|
}
|
||||||
|
dlg.OnAudioDeviceSettingChanged = func() {
|
||||||
|
c.App.Player.SetAudioDevice(c.App.Config.LocalPlayback.AudioDeviceName)
|
||||||
|
}
|
||||||
pop := widget.NewModalPopUp(dlg, c.MainWindow.Canvas())
|
pop := widget.NewModalPopUp(dlg, c.MainWindow.Canvas())
|
||||||
dlg.OnDismiss = func() {
|
dlg.OnDismiss = func() {
|
||||||
pop.Hide()
|
pop.Hide()
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
|
"supersonic/player"
|
||||||
"supersonic/ui/layouts"
|
"supersonic/ui/layouts"
|
||||||
|
"supersonic/ui/util"
|
||||||
"supersonic/ui/widgets"
|
"supersonic/ui/widgets"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@@ -21,15 +23,18 @@ type SettingsDialog struct {
|
|||||||
|
|
||||||
OnReplayGainSettingsChanged func()
|
OnReplayGainSettingsChanged func()
|
||||||
OnAudioExclusiveSettingChanged func()
|
OnAudioExclusiveSettingChanged func()
|
||||||
|
OnAudioDeviceSettingChanged func()
|
||||||
OnDismiss func()
|
OnDismiss func()
|
||||||
|
|
||||||
config *backend.Config
|
config *backend.Config
|
||||||
|
audioDevices []player.AudioDevice
|
||||||
|
|
||||||
content fyne.CanvasObject
|
content fyne.CanvasObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSettingsDialog(config *backend.Config) *SettingsDialog {
|
// TODO: having this depend on the player package for the AudioDevice type is kinda gross. Refactor.
|
||||||
s := &SettingsDialog{config: config}
|
func NewSettingsDialog(config *backend.Config, audioDeviceList []player.AudioDevice) *SettingsDialog {
|
||||||
|
s := &SettingsDialog{config: config, audioDevices: audioDeviceList}
|
||||||
s.ExtendBaseWidget(s)
|
s.ExtendBaseWidget(s)
|
||||||
|
|
||||||
tabs := container.NewAppTabs(
|
tabs := container.NewAppTabs(
|
||||||
@@ -133,6 +138,24 @@ func (s *SettingsDialog) createGeneralTab() *container.TabItem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SettingsDialog) createPlaybackTab() *container.TabItem {
|
func (s *SettingsDialog) createPlaybackTab() *container.TabItem {
|
||||||
|
deviceList := make([]string, len(s.audioDevices))
|
||||||
|
var selIndex int
|
||||||
|
for i, dev := range s.audioDevices {
|
||||||
|
deviceList[i] = dev.Description
|
||||||
|
if dev.Name == s.config.LocalPlayback.AudioDeviceName {
|
||||||
|
selIndex = i
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deviceSelect := widget.NewSelect(deviceList, nil)
|
||||||
|
deviceSelect.SetSelectedIndex(selIndex)
|
||||||
|
deviceSelect.OnChanged = func(_ string) {
|
||||||
|
dev := s.audioDevices[deviceSelect.SelectedIndex()]
|
||||||
|
s.config.LocalPlayback.AudioDeviceName = dev.Name
|
||||||
|
if s.OnAudioDeviceSettingChanged != nil {
|
||||||
|
s.OnAudioDeviceSettingChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
replayGainSelect := widget.NewSelect([]string{"None", "Album", "Track"}, nil)
|
replayGainSelect := widget.NewSelect([]string{"None", "Album", "Track"}, nil)
|
||||||
replayGainSelect.OnChanged = func(_ string) {
|
replayGainSelect.OnChanged = func(_ string) {
|
||||||
switch replayGainSelect.SelectedIndex() {
|
switch replayGainSelect.SelectedIndex() {
|
||||||
@@ -189,14 +212,18 @@ func (s *SettingsDialog) createPlaybackTab() *container.TabItem {
|
|||||||
audioExclusive.Checked = s.config.LocalPlayback.AudioExclusive
|
audioExclusive.Checked = s.config.LocalPlayback.AudioExclusive
|
||||||
|
|
||||||
return container.NewTabItem("Playback", container.NewVBox(
|
return container.NewTabItem("Playback", container.NewVBox(
|
||||||
|
container.New(&layouts.MaxPadLayout{PadTop: 5},
|
||||||
|
container.New(layout.NewFormLayout(),
|
||||||
|
widget.NewLabel("Audio device"), container.NewBorder(nil, nil, nil, util.NewHSpace(70), deviceSelect),
|
||||||
|
layout.NewSpacer(), container.NewHBox(audioExclusive, layout.NewSpacer()),
|
||||||
|
)),
|
||||||
|
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15}, widget.NewSeparator()),
|
||||||
widget.NewRichText(&widget.TextSegment{Text: "ReplayGain", Style: boldStyle}),
|
widget.NewRichText(&widget.TextSegment{Text: "ReplayGain", Style: boldStyle}),
|
||||||
container.New(layout.NewFormLayout(),
|
container.New(layout.NewFormLayout(),
|
||||||
widget.NewLabel("ReplayGain mode"), replayGainSelect,
|
widget.NewLabel("ReplayGain mode"), container.NewGridWithColumns(2, replayGainSelect),
|
||||||
widget.NewLabel("ReplayGain preamp"), container.NewHBox(preampGain, widget.NewLabel("dB")),
|
widget.NewLabel("ReplayGain preamp"), container.NewHBox(preampGain, widget.NewLabel("dB")),
|
||||||
widget.NewLabel("Prevent clipping"), container.NewHBox(preventClipping, layout.NewSpacer()),
|
widget.NewLabel("Prevent clipping"), container.NewHBox(preventClipping, layout.NewSpacer()),
|
||||||
),
|
),
|
||||||
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15}, widget.NewSeparator()),
|
|
||||||
container.NewHBox(audioExclusive, layout.NewSpacer()),
|
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user