mirror of
https://github.com/Luzifer/streamdeck.git
synced 2024-12-20 17:51:21 +00:00
Add support for sources
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
2fd1279eb3
commit
554b090890
2 changed files with 44 additions and 15 deletions
|
@ -23,11 +23,15 @@ func (d displayElementPulseVolume) Display(ctx context.Context, idx int, attribu
|
||||||
return errors.New("PulseAudio client not initialized")
|
return errors.New("PulseAudio client not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
sinkMatch, sinkOK := attributes["sink"].(string)
|
devType, ok := attributes["device"].(string)
|
||||||
sinkOK = sinkOK && sinkMatch != ""
|
if !ok {
|
||||||
|
return errors.New("Missing 'device' attribute")
|
||||||
|
}
|
||||||
|
|
||||||
sinkInputMatch, sinkInputOK := attributes["sink_input"].(string)
|
match, ok := attributes["match"].(string)
|
||||||
sinkInputOK = sinkInputOK && sinkInputMatch != ""
|
if !ok {
|
||||||
|
return errors.New("Missing 'match' attribute")
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
@ -36,16 +40,19 @@ func (d displayElementPulseVolume) Display(ctx context.Context, idx int, attribu
|
||||||
volume float64
|
volume float64
|
||||||
)
|
)
|
||||||
|
|
||||||
switch {
|
switch devType {
|
||||||
|
|
||||||
case (sinkInputOK && sinkOK) || (!sinkInputOK && !sinkOK):
|
case "input":
|
||||||
return errors.New("Exactly one of 'sink' and 'sink_input' must be specified")
|
volume, mute, err = pulseClient.GetSinkInputVolume(match)
|
||||||
|
|
||||||
case sinkInputOK:
|
case "sink":
|
||||||
volume, mute, err = pulseClient.GetSinkInputVolume(sinkInputMatch)
|
volume, mute, err = pulseClient.GetSinkVolume(match)
|
||||||
|
|
||||||
case sinkOK:
|
case "source":
|
||||||
volume, mute, err = pulseClient.GetSinkVolume(sinkMatch)
|
volume, mute, err = pulseClient.GetSourceVolume(match)
|
||||||
|
|
||||||
|
default:
|
||||||
|
return errors.Errorf("Unsupported device type: %q", devType)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ func (p pulseAudioClient) GetSinkInputVolume(match string) (float64, bool, error
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
sinkBase, err := p.getSinkBaseVolumeByIndex(info.SinkIndex)
|
sinkBase, err := p.getSinkReferenceVolumeByIndex(info.SinkIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, false, errors.Wrap(err, "Unable to get sink base volume")
|
return 0, false, errors.Wrap(err, "Unable to get sink base volume")
|
||||||
}
|
}
|
||||||
|
@ -81,19 +81,41 @@ func (p pulseAudioClient) GetSinkVolume(match string) (float64, bool, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
return p.unifyChannelVolumes(info.ChannelVolumes) / float64(info.BaseVolume), info.Mute, nil
|
return p.unifyChannelVolumes(info.ChannelVolumes) / float64(info.NumVolumeSteps), info.Mute, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0, false, errPulseNoSuchDevice
|
return 0, false, errPulseNoSuchDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p pulseAudioClient) getSinkBaseVolumeByIndex(idx uint32) (float64, error) {
|
func (p pulseAudioClient) GetSourceVolume(match string) (float64, bool, error) {
|
||||||
|
m, err := regexp.Compile(match)
|
||||||
|
if err != nil {
|
||||||
|
return 0, false, errors.Wrap(err, "Unable to compile given match RegEx")
|
||||||
|
}
|
||||||
|
|
||||||
|
var resp proto.GetSourceInfoListReply
|
||||||
|
if err := p.client.RawRequest(&proto.GetSourceInfoList{}, &resp); err != nil {
|
||||||
|
return 0, false, errors.Wrap(err, "Unable to list sources")
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, info := range resp {
|
||||||
|
if !m.MatchString(info.SourceName) && !m.MatchString(info.Device) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.unifyChannelVolumes(info.ChannelVolumes) / float64(info.NumVolumeSteps), info.Mute, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, false, errPulseNoSuchDevice
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p pulseAudioClient) getSinkReferenceVolumeByIndex(idx uint32) (float64, error) {
|
||||||
var resp proto.GetSinkInfoReply
|
var resp proto.GetSinkInfoReply
|
||||||
if err := p.client.RawRequest(&proto.GetSinkInfo{SinkIndex: idx}, &resp); err != nil {
|
if err := p.client.RawRequest(&proto.GetSinkInfo{SinkIndex: idx}, &resp); err != nil {
|
||||||
return 0, errors.Wrap(err, "Unable to get sink")
|
return 0, errors.Wrap(err, "Unable to get sink")
|
||||||
}
|
}
|
||||||
|
|
||||||
return float64(resp.BaseVolume), nil
|
return float64(resp.NumVolumeSteps), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p pulseAudioClient) unifyChannelVolumes(v proto.ChannelVolumes) float64 {
|
func (p pulseAudioClient) unifyChannelVolumes(v proto.ChannelVolumes) float64 {
|
||||||
|
|
Loading…
Reference in a new issue