expose MPV ReplayGain options
This commit is contained in:
@@ -104,6 +104,14 @@ func (m libmpv) SetProperty(name string, format MPVFormat, value any) error {
|
|||||||
return toMPVError(C.mpv_set_property(m.handle, cname, C.mpv_format(format), p))
|
return toMPVError(C.mpv_set_property(m.handle, cname, C.mpv_format(format), p))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m libmpv) SetPropertyString(name, value string) error {
|
||||||
|
cname := C.CString(name)
|
||||||
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
cvalue := C.CString(value)
|
||||||
|
defer C.free(unsafe.Pointer(cvalue))
|
||||||
|
return toMPVError(C.mpv_set_property_string(m.handle, cname, cvalue))
|
||||||
|
}
|
||||||
|
|
||||||
func (m libmpv) GetProperty(name string, format MPVFormat) (any, error) {
|
func (m libmpv) GetProperty(name string, format MPVFormat) (any, error) {
|
||||||
cname := C.CString(name)
|
cname := C.CString(name)
|
||||||
defer C.free(unsafe.Pointer(cname))
|
defer C.free(unsafe.Pointer(cname))
|
||||||
|
|||||||
@@ -38,12 +38,30 @@ const (
|
|||||||
SeekRelativePercent
|
SeekRelativePercent
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// One of "no", "track", or "album"
|
||||||
|
type ReplayGainMode string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ReplayGainNone ReplayGainMode = "no"
|
||||||
|
ReplayGainTrack ReplayGainMode = "track"
|
||||||
|
ReplayGainAlbum ReplayGainMode = "album"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Replay Gain options (argument to SetReplayGainOptions).
|
||||||
|
type ReplayGainOptions struct {
|
||||||
|
Mode ReplayGainMode
|
||||||
|
FallbackGain float64
|
||||||
|
PreampGain float64
|
||||||
|
}
|
||||||
|
|
||||||
// Player encapsulates the mpv instance and provides functions
|
// Player encapsulates the mpv instance and provides functions
|
||||||
// to control it and to check its status.
|
// to control it and to check its status.
|
||||||
type Player struct {
|
type Player struct {
|
||||||
mpv libmpv
|
mpv libmpv
|
||||||
initialized bool
|
initialized bool
|
||||||
vol int
|
vol int
|
||||||
|
replayGainOpts ReplayGainOptions
|
||||||
|
haveRGainOpts bool
|
||||||
status Status
|
status Status
|
||||||
seeking bool
|
seeking bool
|
||||||
curPlaylistPos int64
|
curPlaylistPos int64
|
||||||
@@ -99,6 +117,9 @@ func (p *Player) Init(audioExclusive bool) error {
|
|||||||
if audioExclusive {
|
if audioExclusive {
|
||||||
m.SetOptionString("audio-exclusive", "yes")
|
m.SetOptionString("audio-exclusive", "yes")
|
||||||
}
|
}
|
||||||
|
if p.haveRGainOpts {
|
||||||
|
p.SetReplayGainOptions(p.replayGainOpts)
|
||||||
|
}
|
||||||
|
|
||||||
if p.clientName != "" {
|
if p.clientName != "" {
|
||||||
m.SetOptionString("audio-client-name", p.clientName)
|
m.SetOptionString("audio-client-name", p.clientName)
|
||||||
@@ -232,6 +253,26 @@ func (p *Player) SetVolume(vol int) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets the ReplayGain options of the player.
|
||||||
|
// Unlike most Player functions, SetReplayGainOptions can be called
|
||||||
|
// before Init, to set the initial volume of the player on startup.
|
||||||
|
func (p *Player) SetReplayGainOptions(options ReplayGainOptions) error {
|
||||||
|
p.replayGainOpts = options
|
||||||
|
p.haveRGainOpts = true
|
||||||
|
if p.initialized {
|
||||||
|
if err := p.mpv.SetPropertyString("replaygain", string(options.Mode)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := p.mpv.SetProperty("replaygain-preamp", MPVFormatDouble, options.PreampGain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := p.mpv.SetProperty("replaygain-fallback", MPVFormatDouble, options.FallbackGain); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Gets the current volume of the player.
|
// Gets the current volume of the player.
|
||||||
func (p *Player) GetVolume() int {
|
func (p *Player) GetVolume() int {
|
||||||
return p.vol
|
return p.vol
|
||||||
|
|||||||
Reference in New Issue
Block a user