I needed a way to quickly and easily create simple drum kit .sfz files for use with Linuxsampler. I had found a perl script called makesfz.pl that I failed to get to work and I couldn't find a suitable script or app within these forums or linked to on linuxsampler.org so I wrote the following little bash script that scans for wav files in the current dir then writes out a corresponding .sfz file for every wav found, mapping that sample to MIDI note 0.
Otherwise you can run it like 'makesfz.sh 1' in which case it simply creates one big .sfz named after the containing folder which assigns each sample to a MIDI note ('key'), ascending through the filenames alphabetically and pairing these with a progressively higher MIDI note (Linuxsampler 'key') so it is recommended that you name your files like:
000-kick.wav
001-snare.wav
etc. etc. so you know which sample will be assigned to which key although this isn't a requirement.
I hope others will find this script useful. The LS devs are free to improve and include this script with LS should they wish to do so.
Dan
UPDATES
3rd Jan 2012
Following feedback on LAU I have just updated the script to include the 'loop_mode=one_shot' option and tidied it up a bit too.
23rd Jan 2012
Added command line switch of '1' to create one big sfz, otherwise default to creating one per wav
1st Feb 2012
Added quotes to variables to fix problem when running 'makesfz 1' from a directory with spaces in it
Code: Select all
#!/bin/bash
#
# makesfz.sh
#
# Running 'makesfz.sh' with no or any other parameter than 1 will create a .sfz
# file for every wav file in the present dir. mapping the wav to MIDI note 0.
#
# Alternatively, 'makesfz.sh 1' reads all wav files in the current dir and creates
# a single .sfz named after the present folder mapping each sample to a MIDI note.
#
#
# by Dan MacDonald 2012
key=0
if [ "$1" = "1" ]; then
rm -f "${PWD##*/}".sfz
echo -e "# This file was auto-generated by makesfz.sh\n\n<group>\nloop_mode=one_shot\n" > "${PWD##*/}".sfz
for wavs in *.wav
do
echo -e "<region>\nsample=$wavs\nkey=$key\nlovel=0 hivel=127\n" >> "${PWD##*/}".sfz
key=$(($key+1))
done
else
for wavs in *.wav
do
echo -e "# This file was auto-generated by makesfz.sh\n\n<group>\nloop_mode=one_shot\n" > $wavs.sfz
echo -e "<region>\nsample=$wavs\nkey=0\nlovel=0 hivel=127\n" >> $wavs.sfz
done
fi