mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-20 09:41:19 +00:00
Update all instances of the sink input matched
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
c417556178
commit
05c9852c24
1 changed files with 33 additions and 20 deletions
|
@ -38,15 +38,15 @@ func newPulseAudioClient() (*pulseAudioClient, error) {
|
|||
|
||||
func (p pulseAudioClient) Close() { p.client.Close() }
|
||||
|
||||
func (p pulseAudioClient) GetSinkInputVolume(match string) (vol float64, muted bool, idx uint32, max uint32, err error) {
|
||||
func (p pulseAudioClient) GetSinkInputVolume(match string) (vol float64, muted bool, idx []uint32, max uint32, err error) {
|
||||
m, err := regexp.Compile(match)
|
||||
if err != nil {
|
||||
return 0, false, 0, 0, errors.Wrap(err, "Unable to compile given match RegEx")
|
||||
return 0, false, nil, 0, errors.Wrap(err, "Unable to compile given match RegEx")
|
||||
}
|
||||
|
||||
var resp proto.GetSinkInputInfoListReply
|
||||
if err := p.client.RawRequest(&proto.GetSinkInputInfoList{}, &resp); err != nil {
|
||||
return 0, false, 0, 0, errors.Wrap(err, "Unable to list sink inputs")
|
||||
return 0, false, nil, 0, errors.Wrap(err, "Unable to list sink inputs")
|
||||
}
|
||||
|
||||
for _, info := range resp {
|
||||
|
@ -56,13 +56,24 @@ func (p pulseAudioClient) GetSinkInputVolume(match string) (vol float64, muted b
|
|||
|
||||
sinkBase, err := p.getSinkReferenceVolumeByIndex(info.SinkIndex)
|
||||
if err != nil {
|
||||
return 0, false, 0, 0, errors.Wrap(err, "Unable to get sink base volume")
|
||||
return 0, false, nil, 0, errors.Wrap(err, "Unable to get sink base volume")
|
||||
}
|
||||
|
||||
return p.unifyChannelVolumes(info.ChannelVolumes) / float64(sinkBase), info.Muted, info.SinkInputIndex, sinkBase, nil
|
||||
if max != 0 && sinkBase != max {
|
||||
return 0, false, nil, 0, errors.New("found different sink bases")
|
||||
}
|
||||
|
||||
return 0, false, 0, 0, errPulseNoSuchDevice
|
||||
idx = append(idx, info.SinkInputIndex)
|
||||
max = sinkBase
|
||||
muted = muted || info.Muted
|
||||
vol = math.Max(vol, p.unifyChannelVolumes(info.ChannelVolumes)/float64(sinkBase))
|
||||
}
|
||||
|
||||
if len(idx) == 0 {
|
||||
return 0, false, nil, 0, errPulseNoSuchDevice
|
||||
}
|
||||
|
||||
return vol, muted, idx, max, nil
|
||||
}
|
||||
|
||||
func (p pulseAudioClient) GetSinkVolume(match string) (vol float64, muted bool, idx uint32, max uint32, err error) {
|
||||
|
@ -110,13 +121,14 @@ func (p pulseAudioClient) GetSourceVolume(match string) (vol float64, muted bool
|
|||
}
|
||||
|
||||
func (p pulseAudioClient) SetSinkInputVolume(match string, mute string, vol float64, absolute bool) error {
|
||||
stateVol, stateMute, stateIdx, stateSteps, err := p.GetSinkInputVolume(match)
|
||||
stateVol, stateMute, stateIdxs, stateSteps, err := p.GetSinkInputVolume(match)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Unable to get current state of sink input")
|
||||
}
|
||||
|
||||
var cmds []proto.RequestArgs
|
||||
|
||||
for _, stateIdx := range stateIdxs {
|
||||
switch mute {
|
||||
case "true":
|
||||
cmds = append(cmds, &proto.SetSinkInputMute{SinkInputIndex: stateIdx, Mute: true})
|
||||
|
@ -131,6 +143,7 @@ func (p pulseAudioClient) SetSinkInputVolume(match string, mute string, vol floa
|
|||
} else if vol != 0 {
|
||||
cmds = append(cmds, &proto.SetSinkInputVolume{SinkInputIndex: stateIdx, ChannelVolumes: proto.ChannelVolumes{uint32(math.Max(0, stateVol+vol) * float64(stateSteps))}})
|
||||
}
|
||||
}
|
||||
|
||||
for _, cmd := range cmds {
|
||||
if err := p.client.RawRequest(cmd, nil); err != nil {
|
||||
|
@ -223,7 +236,7 @@ func (p pulseAudioClient) unifyChannelVolumes(v proto.ChannelVolumes) float64 {
|
|||
return float64(v[0])
|
||||
}
|
||||
|
||||
var vMin = float64(v[0])
|
||||
vMin := float64(v[0])
|
||||
for i := 1; i < len(v); i++ {
|
||||
vMin = math.Min(vMin, float64(v[i]))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue