Measured rather than guessed: the whole repository was cross-compiled for
linux/amd64 and the gaps closed one by one. There were fewer than expected.
Flex and TCI were never Windows-specific — they carried //go:build windows by
inheritance and import nothing but net and gorilla/websocket. Untagged, no code
change. The two backends a Linux operator is most likely to own were already
portable.
Audio was 560 lines, not 2287: only devices.go and engine.go touch WASAPI, while
manager.go, recorder.go, wav.go and mp3.go were pure Go wearing the tag by
association. The whole platform surface is seven functions, now implemented a
second time on PulseAudio through github.com/jfreymuth/pulse — pure Go over the
server socket, so the no-cgo rule survives, and PipeWire answers the same
protocol. The fixed 16 kHz mono format and the server-side resampling mirror
what AUTOCONVERTPCM does on Windows, for the same reason.
OmniRig is the only real loss, and its backend still EXISTS off Windows rather
than being compiled out of app.go: a settings database is portable, so an
operator moving a profile across keeps "omnirig" saved and must be told to pick
a native backend instead of meeting a nil one.
The parts where Linux is not Windows, and where a compile-only stub would have
been a silent bug:
- data dir: still beside the binary, but ~/.local/share/OpsLog/data when that
folder belongs to the system — decided by trying the write, because /opt and
/usr/local are writable on some stations and not others.
- single instance: an flock, not a pid file. The kernel drops it however the
process dies, so a crash leaves nothing to delete by hand. This is the guard
that stops two instances fighting over the rig frequency.
- update: simpler here. Unix renames over a running binary, so the deferred
swap the Windows path needs a detached helper for is unreachable.
- tasklist/taskkill become /proc and SIGTERM; the boot log moves out of /tmp,
which is wiped exactly when the evidence is wanted.
- serial ports sorted naturally: /dev/ttyUSB10 was landing between USB1 and
USB2, the same trap COM10 fell into.
release.ps1 now cross-builds and vets for linux before it builds the exe, and
refuses the release if that fails — a port rots one unguarded x/sys/windows call
at a time.
Nothing has been executed on Linux yet: Wails needs webkit2gtk and cgo there, so
the binary must be built on Linux. scripts/linux-setup.sh checks the machine and
does it; BUILDING-LINUX.md is the manual version.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
100 lines
3.1 KiB
Go
100 lines
3.1 KiB
Go
//go:build linux
|
|
|
|
package audio
|
|
|
|
// devices_linux.go — audio endpoints on Linux, through PulseAudio.
|
|
//
|
|
// PulseAudio and not ALSA, for two reasons that both matter here. ALSA's C
|
|
// library needs cgo, and OpsLog is a pure-Go build; and PulseAudio is the API
|
|
// that is actually present on a ham's desktop — PipeWire, which most current
|
|
// distributions ship, answers the PulseAudio protocol through pipewire-pulse,
|
|
// so one client speaks to both. github.com/jfreymuth/pulse implements that
|
|
// protocol in Go over the server's Unix socket, so nothing is linked in.
|
|
//
|
|
// The endpoint id we persist is the sink/source NAME
|
|
// ("alsa_input.usb-Icom_Inc._IC-7610-00.analog-stereo"), never the numeric
|
|
// index: the index is assigned at boot in device-arrival order and moves the
|
|
// moment a rig is plugged in before a headset.
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/jfreymuth/pulse"
|
|
)
|
|
|
|
// pulseClient opens a short-lived connection to the local sound server. Each
|
|
// call gets its own: the connection is a Unix socket to a server that may be
|
|
// restarted underneath us (a PipeWire update, a user logging the session out
|
|
// and in), and holding one open for the lifetime of the app means every later
|
|
// call fails until OpsLog itself restarts.
|
|
func pulseClient() (*pulse.Client, error) {
|
|
c, err := pulse.NewClient(pulse.ClientApplicationName("OpsLog"))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot reach the sound server (is PulseAudio or PipeWire running?): %w", err)
|
|
}
|
|
return c, nil
|
|
}
|
|
|
|
// ListInputDevices returns the capture sources.
|
|
//
|
|
// Monitor sources (".monitor", what a given output is playing) are kept rather
|
|
// than filtered out. They look like clutter until you meet the operator whose
|
|
// rig audio reaches OpsLog through a virtual cable — on Linux that is a
|
|
// null-sink and its monitor, and hiding it would hide the only device that
|
|
// works for them.
|
|
func ListInputDevices() ([]Device, error) {
|
|
c, err := pulseClient()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer c.Close()
|
|
|
|
srcs, err := c.ListSources()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defID := ""
|
|
if d, err := c.DefaultSource(); err == nil && d != nil {
|
|
defID = d.ID()
|
|
}
|
|
out := make([]Device, 0, len(srcs))
|
|
for _, s := range srcs {
|
|
out = append(out, Device{ID: s.ID(), Name: endpointLabel(s.Name(), s.ID()), Default: s.ID() == defID})
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// ListOutputDevices returns the render sinks.
|
|
func ListOutputDevices() ([]Device, error) {
|
|
c, err := pulseClient()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer c.Close()
|
|
|
|
sinks, err := c.ListSinks()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defID := ""
|
|
if d, err := c.DefaultSink(); err == nil && d != nil {
|
|
defID = d.ID()
|
|
}
|
|
out := make([]Device, 0, len(sinks))
|
|
for _, s := range sinks {
|
|
out = append(out, Device{ID: s.ID(), Name: endpointLabel(s.Name(), s.ID()), Default: s.ID() == defID})
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// endpointLabel prefers the server's human description ("USB Audio CODEC
|
|
// Analog Stereo") and falls back to the raw name, which is ugly but still
|
|
// identifies the device — an empty entry in the dropdown identifies nothing.
|
|
func endpointLabel(desc, id string) string {
|
|
if d := strings.TrimSpace(desc); d != "" {
|
|
return d
|
|
}
|
|
return id
|
|
}
|