connect replaygain config UI to config object
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
"supersonic/backend"
|
"supersonic/backend"
|
||||||
|
"supersonic/ui/layouts"
|
||||||
"supersonic/ui/widgets"
|
"supersonic/ui/widgets"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@@ -124,18 +125,78 @@ func (s *SettingsDialog) createGeneralTab() *container.TabItem {
|
|||||||
|
|
||||||
func (s *SettingsDialog) createPlaybackTab() *container.TabItem {
|
func (s *SettingsDialog) createPlaybackTab() *container.TabItem {
|
||||||
replayGainSelect := widget.NewSelect([]string{"None", "Album", "Track"}, nil)
|
replayGainSelect := widget.NewSelect([]string{"None", "Album", "Track"}, nil)
|
||||||
|
replayGainSelect.OnChanged = func(_ string) {
|
||||||
|
switch replayGainSelect.SelectedIndex() {
|
||||||
|
case 0:
|
||||||
|
s.config.ReplayGain.Mode = backend.ReplayGainNone
|
||||||
|
case 1:
|
||||||
|
s.config.ReplayGain.Mode = backend.ReplayGainAlbum
|
||||||
|
case 2:
|
||||||
|
s.config.ReplayGain.Mode = backend.ReplayGainTrack
|
||||||
|
}
|
||||||
|
s.onReplayGainSettingsChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
// set initially selected option
|
||||||
|
switch s.config.ReplayGain.Mode {
|
||||||
|
case backend.ReplayGainAlbum:
|
||||||
|
replayGainSelect.SetSelectedIndex(1)
|
||||||
|
case backend.ReplayGainTrack:
|
||||||
|
replayGainSelect.SetSelectedIndex(2)
|
||||||
|
default:
|
||||||
|
replayGainSelect.SetSelectedIndex(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
preampGain := widgets.NewTextRestrictedEntry(func(curText string, r rune) bool {
|
||||||
|
return (curText == "" && r == '-') ||
|
||||||
|
(curText == "" && unicode.IsDigit(r)) ||
|
||||||
|
((curText == "-" || curText == "0") && unicode.IsDigit(r))
|
||||||
|
})
|
||||||
|
preampGain.SetMinCharWidth(2)
|
||||||
|
preampGain.OnChanged = func(text string) {
|
||||||
|
if f, err := strconv.ParseFloat(text, 64); err == nil {
|
||||||
|
s.config.ReplayGain.PreampGainDB = f
|
||||||
|
s.onReplayGainSettingsChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
initVal := math.Round(s.config.ReplayGain.PreampGainDB)
|
||||||
|
if initVal < -9 {
|
||||||
|
initVal = -9
|
||||||
|
} else if initVal > 9 {
|
||||||
|
initVal = 9
|
||||||
|
}
|
||||||
|
preampGain.Text = strconv.Itoa(int(initVal))
|
||||||
|
|
||||||
|
preventClipping := widget.NewCheckWithData("", binding.BindBool(&s.config.ReplayGain.PreventClipping))
|
||||||
|
preventClipping.OnChanged = func(_ bool) { s.onReplayGainSettingsChanged() }
|
||||||
|
|
||||||
|
audioExclusive := widget.NewCheckWithData("Audio exclusive mode", binding.BindBool(&s.config.LocalPlayback.AudioExclusive))
|
||||||
|
audioExclusive.OnChanged = func(_ bool) { s.onAudioExclusiveSettingsChanged() }
|
||||||
|
|
||||||
return container.NewTabItem("Playback", container.NewVBox(
|
return container.NewTabItem("Playback", container.NewVBox(
|
||||||
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"), replayGainSelect,
|
||||||
widget.NewLabel("Prevent clipping"), widget.NewCheckWithData("", binding.BindBool(&s.config.ReplayGain.PreventClipping)),
|
widget.NewLabel("ReplayGain preamp"), container.NewHBox(preampGain, widget.NewLabel("dB")),
|
||||||
|
widget.NewLabel("Prevent clipping"), container.NewHBox(preventClipping, layout.NewSpacer()),
|
||||||
),
|
),
|
||||||
widget.NewSeparator(),
|
container.New(&layouts.MaxPadLayout{PadLeft: 15, PadRight: 15}, widget.NewSeparator()),
|
||||||
widget.NewCheckWithData("Audio exclusive mode", binding.BindBool(&s.config.LocalPlayback.AudioExclusive)),
|
container.NewHBox(audioExclusive, layout.NewSpacer()),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SettingsDialog) onReplayGainSettingsChanged() {
|
||||||
|
if s.OnReplayGainSettingsChanged != nil {
|
||||||
|
s.OnReplayGainSettingsChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SettingsDialog) onAudioExclusiveSettingsChanged() {
|
||||||
|
if s.OnAudioExclusiveSettingChanged != nil {
|
||||||
|
s.OnAudioExclusiveSettingChanged()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SettingsDialog) CreateRenderer() fyne.WidgetRenderer {
|
func (s *SettingsDialog) CreateRenderer() fyne.WidgetRenderer {
|
||||||
return widget.NewSimpleRenderer(s.content)
|
return widget.NewSimpleRenderer(s.content)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user