#!/bin/sh

PGM="jack_bufsize"
PGMS="jack_samplerate"

buf=`$PGM | sed 's/^[^0-9]*//'`
set $buf
bufsize="$1"

buf=`$PGMS`
set $buf
rate="$1"

if [ $(($rate % 48)) = 0 ]
then
  SIZES="48 96 192 384 768 1536 3072"
  HEIGHT=230
else
  SIZES="64 128 256 512 1024 2048 4096"
  HEIGHT=230
fi

ZLINES=""
for S in $SIZES
do
  if [ ${S} = ${bufsize} ]
  then
    B=TRUE
  else
    B=FALSE
  fi

  eval "BOOL${S}=${B}"
  ZLINES="$ZLINES ${B} ${S}"
done

newbuf=`zenity --height=${HEIGHT} --list \
               --text="$bufsize samples @ $rate Hz" \
               --radiolist \
               --hide-header \
               --column "Pick" --column "Size" \
               $ZLINES
         `
if [ -n "$newbuf" ]
then
  $PGM $newbuf
  notify-send "Jackd buffer size set to $newbuf"
fi
