public
Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

wavdir2sfz - create sfz soundfonts from directory containing wav audiofiles with notes in their filenames

View wavdir2sfz
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#!/bin/bash
# Copyright 2012, Leon van Kammen (Coder of Salvation), All rights reserved.
#
# Native instrument comes with a huge library of sounds (The Maschine Library) for Maschine.
# Wouldnt it be nice if non-maschine owners can use these instruments?
# Lot of times when I see multisamples in directories, I'd like to have an .sfz soundfont for them
# (instead of playing it with some kind of massivegui vst/pluginplayer).
# A typical directory could look like :
#
# Samples/Instrument/Bass1/Bass1 c1.wav
# Samples/Instrument/Bass1/Bass1 c2.wav
# Samples/Instrument/Bass1/Bass1 e#3.wav
# Samples/Instrument/Bass1/Bass1 f4.wav
#
# With this tool you can easily create .sfz instruments from directories
#
# Usages: $ wavdir2sfz Samples/Instrument/Bass1 ../ > sfz/Bass1.sfz
# $ wavdir2sfz Samples/Instrument/Bass1 ../ | sed 's/\//\\/g' > sfz/Bass1_windows.sfz
#
# if you know your way with shellscript, its easy to recursively do this in batch
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY Coder of Salvation ``AS IS'' AND ANY EXPRESS OR IMPLIED
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and documentation are those of the
# authors and should not be interpreted as representing official policies, either expressed
# or implied, of Coder of Salvation
#
indir="$1"
prefix="$2"
wavs=""
dir_instrument=""
notes=("c" "c#" "d" "d#" "e" "f" "f#" "g" "g#" "a" "a#" "b")
loadindexes=("|" "/" "-" "\\")
loadindex=0
detected=0
notemap=""
header='<group> lovel=1 hivel=127
ampeg_release=0.300000
'
 
_checkpaths(){
[ ! -d "$indir" ] && (echo "dir '$indir' not found"; exit )
dir_instrument=$(dirname "$indir")
}
 
_pump(){
size=${#loadindexes[@]}
((size=size-1))
if [[ $loadindex < $size ]]; then ((loadindex=loadindex+1)); else loadindex=0; fi
}
 
_notemap(){
echo "$1";exit
}
 
generate(){
_checkpaths
wavs=$(find "$indir" -name "*wav*")
printf "C0" > /tmp/notelast
current=""
echo "$header"
[ -f /tmp/notemap ] && rm /tmp/notemap
for j in {1..6}; do
for(( i = 0; i < "${#notes[@]}"; i++ )); do
printf "$wavs" | while read file; do
wav=$(basename "$file");
( tput el; printf "\r[${loadindexes[$loadindex]}] scanning notes...${notes[i]}$j "
if [[ ${wav,,} = *"${notes[i]}$j"* ]]; then
printf "$wav found!\n"; printf "$notemap\n${notes[i]^^}$j|$(cat /tmp/notelast)|$file" >> /tmp/notemap;
printf "${notes[i]^^}$j" > /tmp/notelast
fi
) 1>&2
done
_pump
done
done
tail -n+2 /tmp/notemap | while read line; do
 
note=$(echo "$line" | cut -d\| -f1)
last=$(echo "$line" | cut -d\| -f2)
file=$(echo "$line" | cut -d\| -f3)
printf "<region> sample=$prefix$file\nlokey=$last\nhikey=$note\npitch_keycenter=$note\n\n"
done
}
 
generate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.