[Unit]
# SuperDirt / SuperCollider as a managed unit rather than "a thing running in a
# terminal somewhere".
#
# Why (2026-07-27): an evening was lost to silent orbits, and the one place the
# real error was printed — sclang's post window — was a bare /dev/pts/3. Not
# readable by tooling, not readable after the terminal closes, gone on a crash.
# Meanwhile the process itself was fragile: owned by a terminal, killable by a
# stray probe, unrestartable without PLN's hands.
#
# As a unit we get, for free:
#   * `systemctl --user restart parvagues-sc` — safe, repeatable, scriptable
#   * the post window in the JOURNAL: `journalctl --user -u parvagues-sc`
#     so the boot log can be PARSED into readiness state (midi claimed,
#     synthdefs compiled, sample banks registered) instead of squinted at
#   * survives terminal close, sandbox teardown, and SSH logout
#   * one obvious place for The Bridge to show status and offer restart
#
# QT_QPA_PLATFORM=offscreen is load-bearing, not cosmetic: a Qt-linked sclang
# dies with the display stack, which is how an overnight suspend used to kill
# the music (fixed in d834667). Headless sclang has no such dependency.
Description=ParVagues SuperDirt (sclang start_and_midi.scd, headless)
After=pipewire.service
Wants=pipewire.service

[Service]
Type=simple
WorkingDirectory=/home/pln/Work/Sound/Tidal
Environment=QT_QPA_PLATFORM=offscreen
# scsynth wants a real-time-capable environment; systemd's default limits are
# lower than a login shell's.
LimitRTPRIO=95
LimitMEMLOCK=infinity
LimitNICE=-20
ExecStart=/usr/bin/sclang start_and_midi.scd
# Deliberately NOT Restart=always: if the boot script fails, a restart loop
# would spam the MIDI graph and hide the failure. Fail loudly, restart on
# purpose. Audio gear should never flap.
Restart=no
# Give the post window to the journal, tagged so it is easy to filter.
StandardOutput=journal
StandardError=journal
SyslogIdentifier=parvagues-sc

[Install]
WantedBy=default.target
