Skip to Content

Generate drumkits from *.wav files using bash

1 reply [Last post]
marotte
Offline
Joined: 04/17/2010

I made this script to write a Foo.h2drumkit from a group of wav files. This feature build into hydrogen would be nicer for sure.

stef@grelot:~$ cat mkdrumkit.sh mkdrumkit.sh.help
#!/bin/bash

OLDDIR=`pwd`
WORKINGDIR=/tmp/mkdrumkit
NAME=$1
SAMPLES=$2
VOLUME=0.65
AUTHOR=$3
DFN=$WORKINGDIR/$NAME/drumkit.xml

# echo -e "\n"
# echo -e "Drumkit title : $NAME\n"
# echo -e "Samples :\n"
cd $SAMPLES
mkdir -p $WORKINGDIR/$NAME

echo "" > $DFN
echo "$NAME" >> $DFN
echo "$AUTHOR" >> $DFN
echo "Generated by mkdrumkit.sh (stef@nerim.net)" >> $DFN

echo "" >> $DFN

export k=0
for i in *.wav;
do
echo -e "\t" >> $DFN
echo -e "\t\t$k" >> $DFN
k=$((k+1));
echo -e "\t\t$i" >> $DFN
export n=`echo $i | cut -d. -f1`;
echo -e "\t\t$n" >> $DFN
echo -e "\t\t$VOLUME" >> $DFN
echo -e "\t\tfalse" >> $DFN
echo -e "\t\t1\n\t\t1" >> $DFN
echo -e "\t\t" >> $DFN
echo -e "\t" >> $DFN

if [ $k -gt 31 ];
then
echo "More than 32 samples ! Only the first 32 samples will be declared in the XML file";
break 2;
fi;

done;

echo "" >> $DFN
echo "" >> $DFN

cp $OLDDIR/$SAMPLES/*.wav $WORKINGDIR/$NAME

cd $WORKINGDIR
tar -cf $NAME.tar $NAME
gzip $NAME.tar
cp $WORKINGDIR/$NAME.tar.gz $OLDDIR/$NAME.h2drumkit
cd $OLDDIR

rm -rf $WORKINGDIR

echo "Drumkit $NAME.h2drumkit created with $k sample(s)"

Usage ./mkdrumkit.sh name relative_path_to_wavfiles [author]

A+

critical_max_23
Offline
Joined: 04/17/2010

Along with the Wavbreaker tool (http://huli.org/wavbreaker/index.html) this allowed me to easily (!) create Hydrogen kits from a track on a sample CD. The track was composed of many samples (drum hits) separated by silence, Wavbreaker allowed me to split it into different .wav files and this script made it very easy to create a drumkit.

This tool could be part of the default Hydrogen distribution, IMO.

Allowing an absolute path to input files, and putting the usage statement as a "-?" switch to the script would make it perfect. Maybe I'll just do that. :)