diff options
author | lawl <github@dumbinter.net> | 2020-07-05 00:38:30 +0200 |
---|---|---|
committer | lawl <github@dumbinter.net> | 2020-07-05 00:38:30 +0200 |
commit | e758ce0ac70f6e7ecdfee64f3c3c7090713e83f6 (patch) | |
tree | 996bc0d52afdfb290e0fa69ebc5adbf6f57fb0ec /main.go | |
parent | d29abc7a0d4cca46d3d6e217f763d4e521b03244 (diff) | |
download | noisetorch-e758ce0ac70f6e7ecdfee64f3c3c7090713e83f6.tar.gz noisetorch-e758ce0ac70f6e7ecdfee64f3c3c7090713e83f6.zip |
big bang
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 102 |
1 files changed, 102 insertions, 0 deletions
@@ -0,0 +1,102 @@ +package main + +import ( + "image" + "io/ioutil" + "log" + "os" + + "github.com/aarzilli/nucular/font" + + "github.com/lawl/pulseaudio" + + "github.com/aarzilli/nucular" + "github.com/aarzilli/nucular/style" +) + +//go:generate go run scripts/embedlibrnnoise.go + +type input struct { + ID string + Name string + isMonitor bool + checked bool +} + +func main() { + + f, err := os.OpenFile("/tmp/noiseui.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) + if err != nil { + log.Fatalf("error opening file: %v\n", err) + } + defer f.Close() + log.SetOutput(f) + log.Println("Application starting.") + + initializeConfigIfNot() + rnnoisefile := dumpLib() + defer removeLib(rnnoisefile) + + ui := uistate{} + ui.config = readConfig() + ui.librnnoise = rnnoisefile + + paClient, err := pulseaudio.NewClient() + defer paClient.Close() + + ui.paClient = paClient + if err != nil { + log.Fatalf("Couldn't create pulseaudio client\n") + } + + go updateNoiseSupressorLoaded(paClient, &ui.noiseSupressorState) + + sources, err := paClient.Sources() + if err != nil { + log.Fatalf("Couldn't fetch sources from pulseaudio\n") + } + + inputs := make([]input, 0) + for i := range sources { + if sources[i].Name == "nui_mic_remap" { + continue + } + + var inp input + + inp.ID = sources[i].Name + inp.Name = sources[i].PropList["device.description"] + inp.isMonitor = (sources[i].MonitorSourceIndex != 0xffffffff) + + inputs = append(inputs, inp) + } + + ui.inputList = inputs + + wnd := nucular.NewMasterWindowSize(0, "NoiseUI", image.Point{550, 300}, func(w *nucular.Window) { + updatefn(w, &ui) + }) + style := style.FromTheme(style.DarkTheme, 2.0) + style.Font = font.DefaultFont(16, 1) + wnd.SetStyle(style) + wnd.Main() + +} + +func dumpLib() string { + f, err := ioutil.TempFile("", "librnnoise-*.so") + if err != nil { + log.Fatalf("Couldn't open temp file for librnnoise\n") + } + f.Write(libRNNoise) + log.Printf("Wrote temp librnnoise to: %s\n", f.Name()) + return f.Name() +} + +func removeLib(file string) { + err := os.Remove(file) + if err != nil { + log.Printf("Couldn't delete temp librnnoise: %v\n", err) + } + log.Printf("Deleted temp librnnoise: %s\n", file) +} |