add preamp to EQ
This commit is contained in:
@@ -186,6 +186,7 @@ func (a *App) setupMPV() error {
|
||||
a.Player.SetAudioExclusive(a.Config.LocalPlayback.AudioExclusive)
|
||||
|
||||
eq := &player.ISO15BandEqualizer{
|
||||
EQPreamp: a.Config.LocalPlayback.EqualizerPreamp,
|
||||
Disabled: !a.Config.LocalPlayback.EqualizerEnabled,
|
||||
}
|
||||
copy(eq.BandGains[:], a.Config.LocalPlayback.GraphicEqualizerBands)
|
||||
|
||||
@@ -75,6 +75,7 @@ type LocalPlaybackConfig struct {
|
||||
InMemoryCacheSizeMB int
|
||||
Volume int
|
||||
EqualizerEnabled bool
|
||||
EqualizerPreamp float64
|
||||
GraphicEqualizerBands []float64
|
||||
}
|
||||
|
||||
@@ -158,6 +159,7 @@ func DefaultConfig(appVersionTag string) *Config {
|
||||
InMemoryCacheSizeMB: 30,
|
||||
Volume: 100,
|
||||
EqualizerEnabled: false,
|
||||
EqualizerPreamp: 0,
|
||||
GraphicEqualizerBands: make([]float64, 15),
|
||||
},
|
||||
Scrobbling: ScrobbleConfig{
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
type Equalizer interface {
|
||||
IsEnabled() bool
|
||||
Preamp() float64
|
||||
Curve() EqualizerCurve
|
||||
Type() string
|
||||
// Returns the band frequencies as strings friendly for display
|
||||
@@ -18,6 +19,7 @@ type Equalizer interface {
|
||||
|
||||
type ISO15BandEqualizer struct {
|
||||
Disabled bool
|
||||
EQPreamp float64
|
||||
BandGains [15]float64
|
||||
}
|
||||
|
||||
@@ -32,6 +34,10 @@ func (i *ISO15BandEqualizer) IsEnabled() bool {
|
||||
return !i.Disabled
|
||||
}
|
||||
|
||||
func (i *ISO15BandEqualizer) Preamp() float64 {
|
||||
return i.EQPreamp
|
||||
}
|
||||
|
||||
func (i *ISO15BandEqualizer) Curve() EqualizerCurve {
|
||||
fC := float64(25)
|
||||
curve := make([]EqualizerBand, 0, len(i.BandGains))
|
||||
|
||||
+12
-1
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/dweymouth/go-mpv"
|
||||
@@ -507,7 +508,17 @@ func (p *Player) SetEqualizer(eq Equalizer) error {
|
||||
if eq == nil || !eq.IsEnabled() {
|
||||
return p.mpv.SetPropertyString("af", "")
|
||||
}
|
||||
return p.mpv.SetPropertyString("af", eq.Curve().String())
|
||||
af := ""
|
||||
if math.Abs(eq.Preamp()) > 0.01 {
|
||||
af = fmt.Sprintf("volume=volume=%0.1fdB", eq.Preamp())
|
||||
}
|
||||
eqAF := eq.Curve().String()
|
||||
if af == "" {
|
||||
af = eqAF
|
||||
} else if eqAF != "" {
|
||||
af = fmt.Sprintf("%s,%s", af, eqAF)
|
||||
}
|
||||
return p.mpv.SetPropertyString("af", af)
|
||||
}
|
||||
|
||||
func (p *Player) Equalizer() Equalizer {
|
||||
|
||||
@@ -464,6 +464,7 @@ func (c *Controller) ShowSettingsDialog(themeUpdateCallbk func(), themeFiles map
|
||||
// currently we only have one equalizer type
|
||||
eq := c.App.Player.Equalizer().(*player.ISO15BandEqualizer)
|
||||
eq.Disabled = !c.App.Config.LocalPlayback.EqualizerEnabled
|
||||
eq.EQPreamp = c.App.Config.LocalPlayback.EqualizerPreamp
|
||||
copy(eq.BandGains[:], c.App.Config.LocalPlayback.GraphicEqualizerBands)
|
||||
c.App.Player.SetEqualizer(eq)
|
||||
}
|
||||
|
||||
@@ -14,20 +14,21 @@ import (
|
||||
type GraphicEqualizer struct {
|
||||
widget.BaseWidget
|
||||
|
||||
OnChanged func(band int, gain float64)
|
||||
OnChanged func(band int, gain float64)
|
||||
OnPreampChanged func(gain float64)
|
||||
|
||||
container *fyne.Container
|
||||
}
|
||||
|
||||
func NewGraphicEqualizer(bandFreqs []string, bandGains []float64) *GraphicEqualizer {
|
||||
func NewGraphicEqualizer(preamp float64, bandFreqs []string, bandGains []float64) *GraphicEqualizer {
|
||||
g := &GraphicEqualizer{}
|
||||
g.ExtendBaseWidget(g)
|
||||
g.buildSliders(bandFreqs, bandGains)
|
||||
g.buildSliders(preamp, bandFreqs, bandGains)
|
||||
|
||||
return g
|
||||
}
|
||||
|
||||
func (g *GraphicEqualizer) buildSliders(bands []string, bandGains []float64) {
|
||||
func (g *GraphicEqualizer) buildSliders(preamp float64, bands []string, bandGains []float64) {
|
||||
rng := container.NewVBox(
|
||||
newCaptionTextSizeLabel("+12", fyne.TextAlignTrailing),
|
||||
layout.NewSpacer(),
|
||||
@@ -35,7 +36,16 @@ func (g *GraphicEqualizer) buildSliders(bands []string, bandGains []float64) {
|
||||
layout.NewSpacer(),
|
||||
newCaptionTextSizeLabel("-12", fyne.TextAlignTrailing),
|
||||
)
|
||||
bandSliders := container.New(layouts.NewGridLayoutWithColumnsAndPadding(16, -16))
|
||||
bandSliders := container.New(layouts.NewGridLayoutWithColumnsAndPadding(len(bands)+2, -16))
|
||||
pre := newCaptionTextSizeLabel("Pre", fyne.TextAlignCenter)
|
||||
preampSlider := newEQSlider()
|
||||
preampSlider.SetValue(preamp)
|
||||
preampSlider.OnChanged = func(f float64) {
|
||||
if g.OnPreampChanged != nil {
|
||||
g.OnPreampChanged(f)
|
||||
}
|
||||
}
|
||||
bandSliders.Add(container.NewBorder(nil, pre, nil, nil, preampSlider))
|
||||
bandSliders.Add(container.NewBorder(nil, widget.NewLabel(""), nil, nil, rng))
|
||||
for i, band := range bands {
|
||||
s := newEQSlider()
|
||||
@@ -55,7 +65,7 @@ func (g *GraphicEqualizer) buildSliders(bands []string, bandGains []float64) {
|
||||
}
|
||||
g.container = container.NewMax(
|
||||
container.NewBorder(nil, widget.NewLabel(""), nil, nil,
|
||||
container.NewBorder(nil, nil, util.NewHSpace(35), util.NewHSpace(5),
|
||||
container.NewBorder(nil, nil, util.NewHSpace(5), util.NewHSpace(5),
|
||||
container.NewVBox(
|
||||
layout.NewSpacer(),
|
||||
myTheme.NewThemedRectangle(theme.ColorNameInputBackground),
|
||||
|
||||
@@ -337,8 +337,10 @@ func (s *SettingsDialog) createEqualizerTab(eqBands []string) *container.TabItem
|
||||
}
|
||||
})
|
||||
enabled.Checked = s.config.LocalPlayback.EqualizerEnabled
|
||||
geq := NewGraphicEqualizer(eqBands, s.config.LocalPlayback.GraphicEqualizerBands) // TODO: This should probably be an argument?
|
||||
debouncer := util.NewDebouncer(200*time.Millisecond, func() {
|
||||
geq := NewGraphicEqualizer(s.config.LocalPlayback.EqualizerPreamp,
|
||||
eqBands,
|
||||
s.config.LocalPlayback.GraphicEqualizerBands)
|
||||
debouncer := util.NewDebouncer(350*time.Millisecond, func() {
|
||||
if s.OnEqualizerSettingsChanged != nil {
|
||||
s.OnEqualizerSettingsChanged()
|
||||
}
|
||||
@@ -347,6 +349,10 @@ func (s *SettingsDialog) createEqualizerTab(eqBands []string) *container.TabItem
|
||||
s.config.LocalPlayback.GraphicEqualizerBands[b] = g
|
||||
debouncer()
|
||||
}
|
||||
geq.OnPreampChanged = func(g float64) {
|
||||
s.config.LocalPlayback.EqualizerPreamp = g
|
||||
debouncer()
|
||||
}
|
||||
cont := container.NewBorder(container.NewHBox(enabled), nil, nil, nil, geq)
|
||||
return container.NewTabItem("Equalizer", cont)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user