diff --git a/ui.go b/ui.go index c83e31a..8dca8a5 100644 --- a/ui.go +++ b/ui.go @@ -222,7 +222,7 @@ func (b *Barnard) CommandPlayFile(ui *uiterm.Ui, cmd string) { b.Client.EnableStereoEncoder() // Auto-start transmission if not already transmitting - if !b.Tx { + if !b.Tx && b.Stream != nil { err := b.Stream.StartSource(b.UserConfig.GetInputDevice()) if err != nil { b.AddOutputLine(fmt.Sprintf("Error starting transmission: %s", err.Error())) @@ -277,7 +277,14 @@ func (b *Barnard) setTransmit(ui *uiterm.Ui, val int) { b.Notify("micdown", "me", "") b.Tx = false b.UpdateGeneralStatus(" Idle ", false) - b.Stream.StopSource() + if b.ToneTest { + if b.toneTestStop != nil { + close(b.toneTestStop) + b.toneTestStop = nil + } + } else if b.Stream != nil { + b.Stream.StopSource() + } } else if b.Connected == false { b.Notify("error", "me", "no tx while disconnected") b.Tx = false @@ -289,23 +296,36 @@ func (b *Barnard) setTransmit(ui *uiterm.Ui, val int) { b.UpdateGeneralStatus("cannot transmit in muted channel", true) } else { b.Tx = true - err := b.Stream.StartSource(b.UserConfig.GetInputDevice()) - if err != nil { - b.Notify("error", "me", err.Error()) - b.UpdateGeneralStatus(err.Error(), true) - } else { + if b.ToneTest { + b.toneTestStop = make(chan struct{}) + go StartToneGenerator(b.Client, b.toneTestStop) b.Notify("micup", "me", "") b.UpdateGeneralStatus(" Tx ", true) + } else { + err := b.Stream.StartSource(b.UserConfig.GetInputDevice()) + if err != nil { + b.Notify("error", "me", err.Error()) + b.UpdateGeneralStatus(err.Error(), true) + } else { + b.Notify("micup", "me", "") + b.UpdateGeneralStatus(" Tx ", true) + } } } } func (b *Barnard) OnMicVolumeDown(ui *uiterm.Ui, key uiterm.Key) { + if b.ToneTest || b.Stream == nil { + return + } b.Stream.SetMicVolume(-0.1, true) b.UserConfig.SetMicVolume(b.Stream.GetMicVolume()) } func (b *Barnard) OnMicVolumeUp(ui *uiterm.Ui, key uiterm.Key) { + if b.ToneTest || b.Stream == nil { + return + } b.Stream.SetMicVolume(0.1, true) b.UserConfig.SetMicVolume(b.Stream.GetMicVolume()) }