Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix naming of audio devices under PipeWire #358

Merged
merged 1 commit into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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