Bash script for font renaming

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:

1 Like

this is a great script, I was thinking of writting a script that created folders if all the files where in the root of the font directory. though I just did it manually it’s a bit more involved than what this is cause it requires to create the folder, then move the files into the folder. great work man.

Yeah I had to think about it. I figured make the first loop write to root, then only if there’s more coming, make the subfolder, move the 01 we just wrote into it, and write to the subfolder for the duration of the effect name. If just the 1 sound, no folder is created and the sound lives in root.

I havent tested the newer script (proffie to better proffie) yet, but your first iteration works freaking great. Tested a proffie to cfx conversion, and it spit out my new files into a new folder in like 5sec.

I tired using the plector/cfx font converter tool they built, but for some reason I could never get it to work. This one NoSloppy made is way way way better

1 Like

Credit also to Mormegil on Discord r/lightsabers who started it with Proffie to Xeno. I just went nuts with it. Glad it helps!
Proffie to Proffie is the base I’d like to use for the rest as opposed to how they are. Arrays is the key I think (hash table) to plop in the sound names…

The one thing i noticed though…when converting from proffie to CFX…it spits out the first “swing” file with no # at the end. I believe all CFX swing files always have a # at the end, starting with “swing1”

According to LINK’s post, some should have no number for #1.

Yes, for some sounds.

But for CFX, ‘swing’ in particular he only wrote “swing 1-99”. If the first one swing didn’t require a number value, he would have wrote:

swing
swing 2-99

Thanks for the catch. That cheeky ‘i’.
Here’s the updated swng case for PtoC

				swng*([0-9]).wav)
				targetfile=$(printf %q "swing$swngcounter.wav")
				swngcounter=$((swngcounter+1))
				target="./$targetpath/$targetfile"
				if [ "$verbosity" = "1" ]; then
					echo "Converting ${src} to ${target}"
				fi
				rsync -ab "${src}" "${target}"
				;;

perfecto!.. that did the trick! thank you!

Update to this script.
Renamed to SoundFontNamingConverter2.5.
Changes:

Now just double click either
SoundFontNamingConverter.command for Mac/Linux,
SoundFontNamingConverter.bat for Windows (w/Linux subsystem installed/enabled)

  • Proffie to (proper) Proffie update: if your source Proffie font was missing a config.ini or smoothsw.ini file, the default versions of them will be added to the converted version for you :slight_smile: It will also copy over any files in the font root that are not renamed/organized sounds. This includes .ini files, .txt, .bmp images, styles in .h files…anything not .wav.
  • Tracks are moved as-is, since they typically are named without without numerical sequence. *Note that if you have other stored files in subfolders (like an Extras folder or alternate ignition sounds for example), these will need to be handled manually, as they are not really core font contents anyway.
  • Removed renaming to Proffie from other boards because they’re already supported by hybrid_font in ProffieOS.
    GitHub - NoSloppy/SoundFontNamingConverter: Script to automate cross-platform saber sound fonts.

hi @NoSloppy, I was going to have a play with your ingenious program but i seem to have fallen short at the first hurdle.
any idea’s what could be causing this?

the main file is on my desktop.

To run on windows, you need to install Ubuntu for windows . Check this:

2 Likes

thank you.
i thought i was missing something :+1:

1 Like

all is working as it should now.
thank you.

2 Likes

Updated SoundFontNamingConverter to v2.7.6 .
Fixed the Proffie-to-proper-Proffie script for handling Extras and Tracks folders found on root.

Hey Brian, great work! Have you considered adding Verso to the list? It’s a pretty well loved board.

Yeah, unfortunately as more versions got added, the code has bloated a lot.

The code should be written in a more reusable way by using arrays and then picking the arguments from a simple list of file names from source and target.
Right now, EVERY SINGLE sound gets processed in it’s own little routine and it’s a tedious mess. Uniqueness per board (like CFX doesn’t have melt) requires the forethought of how to handle it, and making that a universal process to just loop over sounds is what I haven’t wrapped my head around yet.

The Proffie-to-proper-Proffie bit is more along the lines of how they should ALL get processed. That works like a charm and is much less code than the other board formats.

TL;DR
If you provide the full list of what verso uses to me, I can add it sloppily for now.

Ah OK. I’ll try and compile something.