Skip to content

Instantly share code, notes, and snippets.

@f4iey
Last active March 13, 2023 22:19
Show Gist options
  • Save f4iey/49bfdfe2dbf8e3f167de215c978bdfe4 to your computer and use it in GitHub Desktop.
Save f4iey/49bfdfe2dbf8e3f167de215c978bdfe4 to your computer and use it in GitHub Desktop.
ZSH script to automate naming convention, RAW conversion, sending and select to saber. Depends on `sox` and `sendtosaber`
#!/bin/zsh
# Automation script to convert all wav sounds with Nuntis's paradigm to RAW
# First, we sort every sound into a correct directory
echo -e """
_____ _____ _____ ___ _____ _____ _____ _____ _____
|__ | __| | |_ | __| _ | __ | __| __ |
| __|__ | | _|__ | | __ -| __| -|
|_____|_____|__|__|___|_____|__|__|_____|_____|__|__|
"""
if [[ ! -d clash && -d swing && -d poweron && -d poweroff && -d smoothH && -d smoothL ]]
then
mkdir CLASH SWING POWERON POWEROFF SMOOTHSWINGH SMOOTHSWINGL result_raw
echo -e "Workdirs created...\nRun the script again to start conversion and transfer!" && exit 1
fi
for k in CLASH SWING POWERON POWEROFF SMOOTHSWINGH SMOOTHSWINGL HUM; do
cd $k
convert_all $k
mv $k/raw/* result_raw/
done
for k in CLASH SWING POWERON POWEROFF SMOOTHSWINGH SMOOTHSWINGL HUM; do
writetosaber $k
done
for k in CLASH SWING POWERON POWEROFF SMOOTHSWINGH SMOOTHSWINGL HUM; do
autoselect $k
done
echo -e "Script finished\n"
function convert_all {
# Arg needs to be name prefix e.g SMOOTHL / CLASH...
mkdir raw
for i in {1..$(ls -1 | wc -l)}; do
mv $(ls -1I '${1}*' | sed -n 1p) ${1}*_${i}_0.wav
sox --clobber ${1}_${i}_0.wav -t raw -b 16 -c 1 -r 44100 raw/${1}_${i}_0.RAW
done
cd ..
}
function writetosaber {
cd result_raw
sendtosaber -erase-all
for i in {1..$(ls -1I ${1}* | wc -l)}; do
sendtosaber -s ${1}_${i}_0.RAW
done
echo "Flash complete! Please select your sound before power cycling!"
cd ..
}
function autoselect {
# Auto selects sounds written
# No need to open Gilthoniel
cd result_raw
prefix=""
case $1 in
"CLASH")
prefix="CL"
;;
"SWING")
prefix="SW"
;;
"POWERON")
prefix="ON"
;;
"POWEROFF")
prefix="OFF"
;;
"SMOOTHSWINGH")
prefix="SMA"
;;
"SMOOTHSWINGL")
prefix="SMB"
;;
"HUM")
prefix="HUM"
;;
esac
rawFiles=""
for i in {1..$(ls -1I ${1}* | wc -l)}; do
rawFiles=${rawFiles},${1}_${i}_0.RAW
done
rawFiles=$(echo ${rawFiles} | sed 's/^.//')
sendtosaber -s -t s${prefix}=${rawFiles}
echo -e "Autoselection for ${1} files completed!\n"
cd ..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment