Hi. Ok, so someone on Discord came up with a little script to rename Proffie sound fonts to Xenopixel format.
I thought it would be useful to be able to convert all sorts of ways, so I made it do:
CFX to Proffie
CFX to Xenopixel
Proffie to CFX
Proffie to Xenopixel
Xenopixel to CFX
Xenopixel to Proffie
While it works fine, I mostly just copied the first block and repeated for other sound effect names (with a few caveats for 8char max and weird CFX stuff etc…)
It’s totally redundant and not elegant coding, and after dabbling with ProffieOS for a good while now, I know a bit more of what should be going on …in theory though.
I have Fredrik’s voice in my head like “Use the force, Luke!”, reverb and all, telling me there’s a better way to program it.
I spent a good bunch of hours self educating on bash (syntax and parameter expansion mostly) and now I’m about to look into making arrays the fix for the long drawn out code, as opposed to a case for every possible sound doing the same thing over and over.
I thought I’d share, as this is just as much open source as anything else, so if anyone feels compelled to look at some simple task programming, here’s your chance.
Starting with the latest that I did tonight, in prep for streamlining the rest, I did “Proffie to better Proffie.” Since the input and output names are all the same, it’s more straight forward than needing to read from an array and keep track of indices and stuff. It’s a loop that just runs through the folder contents until it’s done, taking into account adding leading zeros when appropriate, subfolders when appropriate, and not making a mess of empty folders or subfoldered singles.
#!/bin/sh
shopt -s extglob
IFS=$'\n'
echo "You chose Proffie to Proffie Soundfont renaming."
echo "Do you wish to rename a single soundfont (enter '1') or a folder containing several soundfonts in subfolders (enter '2')?"
echo "If you choose 2, Make sure each sub-folder only contains one soundfont. Otherwise the soundfonts will get mixed!"
read selection
if [ "$selection" = "1" ]; then
echo "You chose to rename a single soundfont. Please enter the name of the font folder containting the soundfont files."
echo "You may need to enter the path if it's a subfolder of where you are (such as 'SoundfontMaker/Font')"
read input
dirs=$(find "$input" -maxdepth 0 -type d)
echo "Found the following soundfont folder:"
echo $dirs
echo "Does this folder only contain one soundfont? (y/n)"
read input2
if [ "$input2" = "y" ]; then
echo "Continuing renaming"
else
echo "Aborting program"
exit
fi
elif [ "$selection" = "2" ]; then
echo "You chose to rename several soundfonts. Each soundfont must be in a single subfolder."
echo "Please enter the name of the folder containing the soundfont folders."
read input
dirs=$(find "$input" -mindepth 1 -maxdepth 1 -type d)
echo "Found the following directories for soundfonts:"
echo $dirs
echo "Does each of these folders only contain one soundfont? (y/n)"
read input2
if [ "$input2" = "y" ]; then
echo "Continuing renaming"
else
echo "Aborting program"
exit
fi
else
echo "Your selection is invalid. Aborting program"
exit
fi
echo "Do you wish a detailed renaming progess report ('1') or only the imporant steps ('2')?"
echo "Warning, the detailed report may produce a lot of console output!"
read verbosity
if [ "$verbosity" = "1" ]; then
echo "Logging progress to console"
else
echo "Logging only important steps"
fi
for dir in ${dirs[@]}; do
sounds=$(find "$dir" -type f -name '*.wav')
echo Converting soundfont in "${dir}".
targetpath="Converted_to_Proffie"
mkdir -p "${targetpath}/${dir}"
counter=1
oldeffect="old"
for src in ${sounds[@]}; do
# Strip digits, path, and extension from filename
effectfile="${src//[0-9]/}"
effect="${effectfile##*/}"
effect="${effect%.*}"
# Reset counter for new effect type
if [[ "$effect" != "$oldeffect" ]]; then
counter=1
fi
# Make subfolder for multiples, or leave single in root
if [ $counter = 2 ]; then
mkdir -p "${targetpath}/${dir}/${effect}"
mv "${target}" "./${targetpath}/${dir}/${effect}/${targetfile}"
echo "Moving ${targetfile} into ${dir}/${effect} subfolder"
fi
# Check if leading zero is needed
if [ "${#effect}" -gt 6 ] || [ "$counter" -gt 9 ]; then
targetfile=$(printf %q "${effect}$counter.wav")
else
targetfile=$(printf %q "${effect}0$counter.wav")
fi
# Set path for single or multiple sounds
if [ $counter -ge 2 ]; then
target="./${targetpath}/${dir}/${effect}/${targetfile}"
else
target="./${targetpath}/${dir}/${targetfile}"
fi
if [ "$verbosity" = "1" ]; then
echo "Converting ${src} to ${target}"
fi
rsync -ab "${src}" "${target}"
# increment counter for next effect sound
counter=$((counter+1))
oldeffect="${effect}"
done
echo Coverted soundfont saved in "${targetpath}"
done
The rest of the craziness is here: