Skip to content

Commit

Permalink
Merge pull request #358 from kdkasad-forks/fix/pipewire-device-names
Browse files Browse the repository at this point in the history
Fix naming of audio devices under PipeWire
  • Loading branch information
AXDOOMER authored Nov 12, 2022
2 parents dd5c141 + 0f361e2 commit 7563350
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 4 additions & 4 deletions cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {

if opt.list {
fmt.Println("Sources:")
sources := getSources(paClient)
sources := getSources(&ctx, paClient)
for i := range sources {
fmt.Printf("\tDevice Name: %s\n\tDevice ID: %s\n\n", sources[i].Name, sources[i].ID)
}

fmt.Println("Sinks:")
sinks := getSinks(paClient)
sinks := getSinks(&ctx, paClient)
for i := range sinks {
fmt.Printf("\tDevice Name: %s\n\tDevice ID: %s\n\n", sinks[i].Name, sinks[i].ID)
}
Expand All @@ -121,7 +121,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {
}

if opt.loadInput {
sources := getSources(paClient)
sources := getSources(&ctx, paClient)

if opt.sinkName == "" {
defaultSource, err := getDefaultSourceID(paClient)
Expand All @@ -147,7 +147,7 @@ func doCLI(opt CLIOpts, config *config, librnnoise string) {

}
if opt.loadOutput {
sinks := getSinks(paClient)
sinks := getSinks(&ctx, paClient)

if opt.sinkName == "" {
defaultSink, err := getDefaultSinkID(paClient)
Expand Down
20 changes: 14 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func removeLib(file string) {
log.Printf("Deleted temp librnnoise: %s\n", file)
}

func getSources(client *pulseaudio.Client) []device {
func getSources(ctx *ntcontext, client *pulseaudio.Client) []device {
sources, err := client.Sources()
if err != nil {
log.Printf("Couldn't fetch sources from pulseaudio\n")
Expand All @@ -138,7 +138,11 @@ func getSources(client *pulseaudio.Client) []device {
var inp device

inp.ID = sources[i].Name
inp.Name = sources[i].PropList["device.description"]
if ctx.serverInfo.servertype == servertype_pulse {
inp.Name = sources[i].PropList["device.description"]
} else {
inp.Name = sources[i].Description
}
inp.isMonitor = (sources[i].MonitorSourceIndex != 0xffffffff)
inp.rate = sources[i].SampleSpec.Rate

Expand All @@ -151,7 +155,7 @@ func getSources(client *pulseaudio.Client) []device {
return outputs
}

func getSinks(client *pulseaudio.Client) []device {
func getSinks(ctx *ntcontext, client *pulseaudio.Client) []device {
sources, err := client.Sinks()
if err != nil {
log.Printf("Couldn't fetch sources from pulseaudio\n")
Expand All @@ -168,7 +172,11 @@ func getSinks(client *pulseaudio.Client) []device {
var inp device

inp.ID = sources[i].Name
inp.Name = sources[i].PropList["device.description"]
if ctx.serverInfo.servertype == servertype_pulse {
inp.Name = sources[i].PropList["device.description"]
} else {
inp.Name = sources[i].Description
}
inp.rate = sources[i].SampleSpec.Rate

// PA_SINK_DYNAMIC_LATENCY = 0x0080U
Expand Down Expand Up @@ -207,8 +215,8 @@ func paConnectionWatchdog(ctx *ntcontext) {
ctx.paClient = paClient
go updateNoiseSupressorLoaded(ctx)

ctx.inputList = preselectDevice(ctx, getSources(ctx.paClient), ctx.config.LastUsedInput, getDefaultSourceID)
ctx.outputList = preselectDevice(ctx, getSinks(paClient), ctx.config.LastUsedOutput, getDefaultSinkID)
ctx.inputList = preselectDevice(ctx, getSources(ctx, paClient), ctx.config.LastUsedInput, getDefaultSourceID)
ctx.outputList = preselectDevice(ctx, getSinks(ctx, paClient), ctx.config.LastUsedOutput, getDefaultSinkID)

resetUI(ctx)
(*ctx.masterWindow).Changed()
Expand Down

0 comments on commit 7563350

Please sign in to comment.