#!/usr/bin/env bash # Listen universal setup (macOS / Linux). # curl -fsSL https://marcusx.fun/listen/setup/sh | bash # curl -fsSL https://marcusx.fun/listen/setup/sh | bash -s performer # skip the prompt # curl -fsSL https://marcusx.fun/listen/setup/sh | bash -s producer # Role 1 Performer: sender sits ARMED (connected, mic closed, nothing sent) until the producer records; then # it plays the producer's cue (or a click on the song grid) and streams song-stamped mic frames. # Role 2 Producer: Mac = Listen AU for Logic (MarcusX > Listen): Logic's record starts the performer, take is # written aligned to ~/Music/Listen/takes. Linux = receiver into a Pulse sink + reaper-link # (REAPER's record starts the performer; aligned take placed on the track after stop). # Safe to run again. No login items, no LaunchAgents, no cron. Only password: 333333. set -euo pipefail URL="${LISTEN_URL:-https://marcusx.fun/listen}"; URL="${URL%/}" PW="${LISTEN_PW:-333333}" SETUP="${LISTEN_SETUP:-$URL/setup}" OS="$(uname -s)" if [ "$OS" = "Darwin" ]; then DIR="$HOME/Library/Application Support/Listen"; else DIR="${XDG_DATA_HOME:-$HOME/.local/share}/listen"; fi say() { printf '\033[1;33m==>\033[0m %s\n' "$*"; } die() { printf '\033[1;31mxx\033[0m %s\n' "$*" >&2; exit 1; } ask() { local q="$1" a=""; if [ -r /dev/tty ]; then read -r -p "$q" a /dev/null 2>&1 && return 0 if [ "$OS" = "Darwin" ] && command -v brew >/dev/null 2>&1; then say "installing ffmpeg (brew)"; brew install ffmpeg elif command -v apt-get >/dev/null 2>&1; then say "installing ffmpeg (apt)"; sudo apt-get install -y ffmpeg elif command -v dnf >/dev/null 2>&1; then say "installing ffmpeg (dnf)"; sudo dnf install -y ffmpeg elif command -v pacman >/dev/null 2>&1; then say "installing ffmpeg (pacman)"; sudo pacman -S --noconfirm ffmpeg fi command -v ffmpeg >/dev/null 2>&1 || die "ffmpeg is required (macOS: brew install ffmpeg). Then run this again." } stop_running() { # one sender per relay: an old one would keep kicking the new one off if [ "$1" = performer ] && [ "$OS" = "Darwin" ]; then local old="$HOME/Library/LaunchAgents/fun.marcusx.listen-sender.plist" if [ -f "$old" ]; then say "removing the old always-on LaunchAgent (it would fight this sender)"; launchctl unload "$old" 2>/dev/null || true; rm -f "$old"; fi fi if [ "$1" = performer ]; then pkill -f "$DIR/launch.py" 2>/dev/null || true pkill -f "Listen/sender.py --url" 2>/dev/null || true else pkill -f "$DIR/receiver.py" 2>/dev/null || true fi sleep 1 } performer() { [ -n "$PY" ] || die "python3 is required (macOS: xcode-select --install)." need_ffmpeg mkdir -p "$DIR" say "fetching sender into $DIR" get "$URL/sender.py" "$DIR/sender.py"; get "$URL/proto.py" "$DIR/proto.py" get "$SETUP/launch.py" "$DIR/launch.py"; get "$SETUP/listmics.py" "$DIR/listmics.py" local MIC="${LISTEN_MIC:-}" if [ -z "$MIC" ]; then mapfile_compat() { local i=0; while IFS= read -r l; do MICS[i]="$l"; i=$((i+1)); done; } MICS=(); mapfile_compat < <(cd "$DIR" && "$PY" -B listmics.py 2>/dev/null || true) if [ "${#MICS[@]}" -gt 0 ]; then echo " Microphones:"; local i=1; for m in "${MICS[@]}"; do echo " $i) $m"; i=$((i+1)); done local pick; pick="$(ask " Pick a mic [1-${#MICS[@]}, Enter = 1]: ")"; pick="${pick:-1}" [[ "$pick" =~ ^[0-9]+$ ]] && [ "$pick" -ge 1 ] && [ "$pick" -le "${#MICS[@]}" ] || pick=1 MIC="${MICS[$((pick-1))]}" fi fi stop_running performer local ARGS=(--url "$URL" --password "$PW" --daemon --armed --mic --play-cue) [ -n "$MIC" ] && ARGS+=(--mic-name "$MIC") cat > "$DIR/run.sh" </dev/null 2>&1 /dev/null || true sleep 6 if curl -fsS -H "X-Listen-Password: $PW" "$URL/health" 2>/dev/null | grep -q '"sender": *true'; then say "relay sees your sender, armed. When the producer hits record you hear the beat (or a click) and you're recording." else say "sender started; the relay has not confirmed it yet (check: curl -s $URL/health)." fi echo " Stop: pkill -f \"$DIR/launch.py\" Restart: bash \"$DIR/run.sh\" &" echo " Nothing starts at login. Run this setup again after a reboot." } producer_mac() { local C="$HOME/Library/Audio/Plug-Ins/Components/Listen.component" # rebuild whenever the published source changed (stamp = sha of the source zip), not only when missing local STAMP="$HOME/Library/Application Support/Listen/au-src.sha" SUM SUM="$(curl -fsSL -H "X-Listen-Password: $PW" "$URL/au/ListenReceiver-src.zip" 2>/dev/null | shasum -a 256 | cut -c1-16 || true)" if [ -d "$C" ] && [ -z "${FORCE:-}" ] && [ -n "$SUM" ] && [ "$(cat "$STAMP" 2>/dev/null)" = "$SUM" ] \ && auval -v aufx Lstn Mrcx 2>/dev/null | grep -q "AU VALIDATION SUCCEEDED"; then say "Listen.component is up to date and passes auval (FORCE=1 to rebuild)." else say "building + installing the Listen AU (JUCE, about 3-6 min, uses 2 cores)" local B; B="$(mktemp -t listen-build.XXXXXX)" get "$URL/au/build.sh" "$B" if LISTEN_URL="$URL" LISTEN_PW="$PW" bash "$B"; then mkdir -p "$(dirname "$STAMP")"; printf '%s\n' "$SUM" > "$STAMP" fi rm -f "$B" fi cat <<'STEPS' In Logic Pro: 1. New project (48 kHz), add one Audio track. 2. Audio FX slot > Audio Units > MarcusX > Listen. 3. Plug-in header: Side Chain = the bus with your beat + talkback (that is what the performer hears). 4. Press R to arm. Warm, moving circle = performer connected; cool and still = not yet. 5. Press Record in Logic. That starts the performer by itself (they never press anything) and the Listen track plays them live, on your song position, while you record. 6. After Stop, the aligned take is in ~/Music/Listen/takes ("lu-