flref-fl.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/env bash
  2. # flref-fl.sh — renders FL Studio projects with FL itself (command line: FL64.exe /R /Ewav /O<folder> <project>)
  3. # into a reference cache, one FL instance at a time. FL output is never committed.
  4. #
  5. # usage: flref-fl.sh <list-of-flp-paths> [cache-dir]
  6. # list: one Linux path per line (/mnt/c/...); the cache keeps <cache>/fl/<group>/<name>.wav, where <group> is the
  7. # project's folder relative to FL's Data dir with spaces replaced by '_'. Existing renders are kept (delete to redo).
  8. # env: FL_ROOT (default: /mnt/c/Program Files/Image-Line/FL Studio 2026), FLREF_TIMEOUT (seconds per project, 900)
  9. set -u
  10. LIST="$1"
  11. CACHE="${2:-/mnt/c/Users/kauan/lynx-test/flref}"
  12. FL_ROOT="${FL_ROOT:-/mnt/c/Program Files/Image-Line/FL Studio 2026}"
  13. TMO="${FLREF_TIMEOUT:-900}"
  14. LOG="$CACHE/fl/render.log"
  15. mkdir -p "$CACHE/fl"
  16. flRunning () { tasklist.exe /FI "IMAGENAME eq FL64.exe" /NH < /dev/null 2> /dev/null | grep -qi 'FL64.exe'; }
  17. # the Windows PID of the FL64.exe running now (this script starts FL only when no other one runs)
  18. flPid () { tasklist.exe /FI "IMAGENAME eq FL64.exe" /FO CSV /NH < /dev/null 2> /dev/null | tr -d '\r' | awk -F'","' 'NF>1{print $2; exit}'; }
  19. pause1 () { timeout 1 tail -f /dev/null; } # (no sleep builtin needed)
  20. while IFS= read -r flp <&3; do
  21. [[ -z "$flp" ]] && continue
  22. rel="${flp#"$FL_ROOT/Data/"}"
  23. group=$(dirname "$rel" | tr ' /' '_-')
  24. name=$(basename "$flp" .flp)
  25. out="$CACHE/fl/$group"
  26. mkdir -p "$out"
  27. [[ -s "$out/$name.wav" ]] && continue
  28. # another FL (e.g. an agent driving FL's UI) — wait for it, up to 30 minutes, then give up
  29. waited=0
  30. while flRunning; do
  31. (( waited == 0 )) && echo "$(date +%T) waiting: FL64.exe already running" >> "$LOG"
  32. (( waited++ > 1800 )) && { echo "$(date +%T) ABORT: another FL64.exe kept running" >> "$LOG"; exit 3; }
  33. pause1
  34. done
  35. start=$(date +%s.%N)
  36. "$FL_ROOT/FL64.exe" /R /Ewav "/O$(wslpath -w "$out")" "$(wslpath -w "$flp")" < /dev/null > /dev/null 2>&1 &
  37. # the launcher may return before FL exits: wait for FL64.exe to appear, then to disappear
  38. for _ in $(seq 1 20); do flRunning && break; pause1; done
  39. pid=$(flPid)
  40. status=ok
  41. while flRunning; do
  42. if (( $(date +%s) - ${start%.*} > TMO )); then
  43. [[ -n "$pid" ]] && taskkill.exe /F /PID "$pid" < /dev/null > /dev/null 2>&1; status=timeout; pause1; rm -f "$out/$name.wav"; break
  44. fi
  45. pause1
  46. done
  47. wait
  48. secs=$(awk -v a="$start" -v b="$(date +%s.%N)" 'BEGIN{print b-a}')
  49. [[ -s "$out/$name.wav" ]] || status="$status-nowav"
  50. printf '%s\t%s\t%.1f\t%s\n' "$(date +%T)" "$status" "$secs" "$group/$name" >> "$LOG"
  51. done 3< "$LIST"