summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzachir <zachir@librem.one>2023-03-17 03:00:41 -0500
committerzachir <zachir@librem.one>2023-03-17 03:00:41 -0500
commitd2cf065754c149a7af67ec3c4c8ba4c1af8b01b8 (patch)
treef79a5b342be01a09a33b6a7656b48a34c469f7d2
parent23536c99c7c608376556008f44934c6e848b17ba (diff)
add script to launch reaper with specified PIPEWIRE_LATENCY
-rwxr-xr-xrl129
1 files changed, 129 insertions, 0 deletions
diff --git a/rl b/rl
new file mode 100755
index 0000000..3275d11
--- /dev/null
+++ b/rl
@@ -0,0 +1,129 @@
+#!/bin/bash
+
+#{{{ printhelp
+printhelp () {
+ printf "rl: launch REAPER with a specified PIPEWIRE latency (to a point).\n"
+ printf " this sets the PIPEWIRE_LATENCY variable for REAPER; as such, it\n"
+ printf " does not necessarily set the period size and sample rate, but\n"
+ printf " rather calculates based on the ratio and what values are "
+ printf "available,\n"
+ printf " -h) printf this help message\n"
+ printf " -f) force using the provided rate even if PIPEWIRE_LATENCY is "
+ printf "already set.\n"
+ printf " -w) use Wayland menu (bemenu)\n"
+ printf " -x) use X11 menu (dmenu)\n"
+ printf " -a ARG) provide ARG as an argument for REAPER\n"
+ printf " -d ARG) provide ARG as an argument for dmenu/bemenu\n"
+ printf " -p ARG) sets the period size to ARG\n"
+ printf " -s ARG) sets the sample rate to ARG\n"
+ exit
+}
+#}}}
+
+#{{{ message
+message () {
+ if [[ -t 0 ]]; then
+ printf "$@\n"
+ else
+ notify-send "rl" "$@"
+ fi
+}
+#}}}
+
+#{{{ getopts
+unset DARG RARG USE_SERVER
+while getopts "hfwxa:d:p:s:" o; do case "${o}" in
+ f) FORCE="YES" ;;
+ x) USE_SERVER="X11" ;;
+ w) USE_SERVER="WAY" ;;
+ a) RARG="$OPTARG $RARG" ;;
+ d) DARG="$OPTARG $DARG";;
+ p) PERIOD_SIZE="$OPTARG" ;;
+ s) SAMPLE_RATE="$OPTARG" ;;
+ *) printhelp ;;
+esac done
+#}}}
+
+#{{{ Check display server if -w or -x not provided
+if [ -z "$USE_SERVER" ]; then
+ if [ -n "$WAYLAND_DISPLAY" ]; then
+ DMENU="bemenu"
+ elif [ -n "$DISPLAY" ]; then
+ DMENU="dmenu"
+ else
+ printf "Can't tell if Wayland or X; what gives?\n"
+ exit 1
+ fi
+else
+ case "$USE_SERVER" in
+ X11) DMENU="dmenu" ;;
+ WAY) DMENU="bemenu" ;;
+ *) printf "Can't tell if Wayland or X; what gives?\n" ;;
+ esac
+ unset USE_SERVER
+fi
+#}}}
+
+#{{{ Check if pipewire exists and is running
+if type pipewire >/dev/null 2>&1; then
+ if ! pgrep -x pipewire >/dev/null 2>&1; then
+ printf "pipewire is not running; this is not going to work!\n"
+ exit 1
+ fi
+else
+ if ! pgrep -x pipewire >/dev/null 2>&1; then
+ printf "Cannot find pipewire in path, and it is not running; is it "
+ printf "installed?\n"
+ exit 1
+ fi
+fi
+#}}}
+
+#{{{ main
+#{{{ if PIPEWIRE_LATENCY is already set
+if [ -n "$PIPEWIRE_LATENCY" ]; then
+ [ -z "$FORCE" ] && \
+ FORCE="$(echo "YES NO" | \
+ $DMENU -p "Override PIPEWIRE_LATENCY VALUE of ${PIPEWIRE_LATENCY}?" $DARG)"
+ case "$FORCE" in
+ YES|yes) unset FORCE ;;
+ NO|no)
+ message "Using existing PIPEWIRE_LATENCY=${PIPEWIRE_LATENCY}..."
+ unset DMENU DARG FORCE
+ reaper $RARG
+ unset RARG
+ ;;
+ *)
+ unset DMENU DARG RARG FORCE
+ message "Did not understand value."
+ exit 1
+ ;;
+ esac
+fi
+#}}}
+[ -z "$PERIOD_SIZE" ] && \
+ PERIOD_SIZE="$(echo "16
+32
+64
+128
+256
+512
+1024" | $DMENU -p "Period size: " $DARG)"
+if [ -z "$PERIOD_SIZE" ]; then
+ message "PERIOD_SIZE not set; will not continue."
+ exit 1
+fi
+[ -z "$SAMPLE_RATE" ] && \
+ SAMPLE_RATE="$(echo "44100
+48000
+88200
+96000
+176400
+192000" | $DMENU -p "Sample rate: " $DARG)"
+if [ -z "$SAMPLE_RATE" ]; then
+ message "SAMPLE_RATE not set; will not continue."
+ exit 1
+fi
+PIPEWIRE_LATENCY="${PERIOD_SIZE}/${SAMPLE_RATE}" reaper $RARG
+unset PERIOD_SIZE SAMPLE_RATE DMENU DARG RARG
+#}}}