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) 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)
|
m, err := regexp.Compile(match)
|
||||||
if err != nil {
|
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
|
var resp proto.GetSinkInputInfoListReply
|
||||||
if err := p.client.RawRequest(&proto.GetSinkInputInfoList{}, &resp); err != nil {
|
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 {
|
for _, info := range resp {
|
||||||
|
@ -56,13 +56,24 @@ func (p pulseAudioClient) GetSinkInputVolume(match string) (vol float64, muted b
|
||||||
|
|
||||||
sinkBase, err := p.getSinkReferenceVolumeByIndex(info.SinkIndex)
|
sinkBase, err := p.getSinkReferenceVolumeByIndex(info.SinkIndex)
|
||||||
if err != nil {
|
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")
|
||||||
|
}
|
||||||
|
|
||||||
|
idx = append(idx, info.SinkInputIndex)
|
||||||
|
max = sinkBase
|
||||||
|
muted = muted || info.Muted
|
||||||
|
vol = math.Max(vol, p.unifyChannelVolumes(info.ChannelVolumes)/float64(sinkBase))
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, false, 0, 0, errPulseNoSuchDevice
|
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) {
|
func (p pulseAudioClient) GetSinkVolume(match string) (vol float64, muted bool, idx uint32, max uint32, err error) {
|
||||||
|
@ -110,26 +121,28 @@ func (p pulseAudioClient) GetSourceVolume(match string) (vol float64, muted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p pulseAudioClient) SetSinkInputVolume(match string, mute string, vol float64, absolute bool) error {
|
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 {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Unable to get current state of sink input")
|
return errors.Wrap(err, "Unable to get current state of sink input")
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmds []proto.RequestArgs
|
var cmds []proto.RequestArgs
|
||||||
|
|
||||||
switch mute {
|
for _, stateIdx := range stateIdxs {
|
||||||
case "true":
|
switch mute {
|
||||||
cmds = append(cmds, &proto.SetSinkInputMute{SinkInputIndex: stateIdx, Mute: true})
|
case "true":
|
||||||
case "false":
|
cmds = append(cmds, &proto.SetSinkInputMute{SinkInputIndex: stateIdx, Mute: true})
|
||||||
cmds = append(cmds, &proto.SetSinkInputMute{SinkInputIndex: stateIdx, Mute: false})
|
case "false":
|
||||||
case "toggle":
|
cmds = append(cmds, &proto.SetSinkInputMute{SinkInputIndex: stateIdx, Mute: false})
|
||||||
cmds = append(cmds, &proto.SetSinkInputMute{SinkInputIndex: stateIdx, Mute: !stateMute})
|
case "toggle":
|
||||||
}
|
cmds = append(cmds, &proto.SetSinkInputMute{SinkInputIndex: stateIdx, Mute: !stateMute})
|
||||||
|
}
|
||||||
|
|
||||||
if absolute && vol >= 0 {
|
if absolute && vol >= 0 {
|
||||||
cmds = append(cmds, &proto.SetSinkInputVolume{SinkInputIndex: stateIdx, ChannelVolumes: proto.ChannelVolumes{uint32(vol * float64(stateSteps))}})
|
cmds = append(cmds, &proto.SetSinkInputVolume{SinkInputIndex: stateIdx, ChannelVolumes: proto.ChannelVolumes{uint32(vol * float64(stateSteps))}})
|
||||||
} else if vol != 0 {
|
} else if vol != 0 {
|
||||||
cmds = append(cmds, &proto.SetSinkInputVolume{SinkInputIndex: stateIdx, ChannelVolumes: proto.ChannelVolumes{uint32(math.Max(0, stateVol+vol) * float64(stateSteps))}})
|
cmds = append(cmds, &proto.SetSinkInputVolume{SinkInputIndex: stateIdx, ChannelVolumes: proto.ChannelVolumes{uint32(math.Max(0, stateVol+vol) * float64(stateSteps))}})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
|
@ -223,7 +236,7 @@ func (p pulseAudioClient) unifyChannelVolumes(v proto.ChannelVolumes) float64 {
|
||||||
return float64(v[0])
|
return float64(v[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
var vMin = float64(v[0])
|
vMin := float64(v[0])
|
||||||
for i := 1; i < len(v); i++ {
|
for i := 1; i < len(v); i++ {
|
||||||
vMin = math.Min(vMin, float64(v[i]))
|
vMin = math.Min(vMin, float64(v[i]))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue