Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 235 lines (201 sloc) 6.75 KB
#!/bin/bash
################################################################################
clear && printf "Welcome to Sf2_Batch_Recording
this script let you make some nice wave files from sf2
it is only a bash script for making some samples for the SamplerBox including definition
text file.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! !
! Note, this will take a long time. A simple example: !
! !
! This script needs about 1 second to run. Because of waiting till fluidsynth is started!
! and sendmidi is connected. This will happen every note. !
! !
! You want have 127 notes in one velocity and every sample will have 14 seconds !
! !
! 14 sec sample + 1 sec script x 127 samples / 60 sec = 32 Minutes ! !
! !
! Test it first with one or two notes !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
"
################################################################################
### Some software tests #######################################################
if [[ -z $(screen -v 2>&1 | sed '/command not found/d') ]]
then
printf 'screen is not installed, try to install it via homebrew'
exit 0
fi
if [[ -z $(fluidsynth -V 2>&1 | sed '/command not found/d') ]]
then
printf 'fluidsynth is not installed, try to install it via homebrew'
exit 0
fi
if [[ -z $(sendmidi --version 2>&1 | sed '/command not found/d') ]]
then
printf 'sendmidi is not installed, try to install it via homebrew'
exit 0
fi
if [[ -z $(sox --version 2>&1 | sed '/command not found/d') ]]
then
printf 'sox is not installed, try to install it via homebrew'
exit 0
fi
### Set folder for banks, read content and ask user to choose one ##############
BKFOLDER='/Library/Audio/Sounds/Banks/'
ls $BKFOLDER > /var/tmp/Banks_
cat -n /var/tmp/Banks_
printf '\nChoose a soundbank in integer:'
read CHOOSEBANK
if [[ -z "$CHOOSEBANK" ]]
then
printf "Soundbank required....exiting\n"
exit 0
fi
SOUNDBANK=$(tail +$CHOOSEBANK /var/tmp/Banks_ | head -1)
BKFOLDER=$BKFOLDER""$SOUNDBANK
echo $BKFOLDER
SOUNDBANK=$(echo $SOUNDBANK | cut -d "." -f 1 ) # this is a small fix to make the folder name more beautiful
mkdir $SOUNDBANK
### Set velocity and make the folder ###########################################
y=-1
while [[ "$y" -lt 0 || "$y" -gt 127 ]]
do
printf '\nChoose a velocity between 0 and 127 or press enter for 127: '
read y
if [[ -z $y ]]
then
y=127
fi
done
printf "The velocity is set to $y\n"
### define key range ###########################################################
a=-1
while [[ "$a" -lt 0 || "$a" -gt 127 ]]
do
printf '\nChoose the beginning key no. between 0 and 127 or press enter for 0: '
read a
if [[ -z $a ]]
then
a=0
fi
done
printf "We will begin with key $a\n"
b=-1
while [[ "$b" -lt 0 || "$b" -gt 127 ]]
do
printf '\nChoose the end key no. between 0 and 127 or press enter for 127: '
read b
if [[ -z $b ]]
then
b=127
fi
done
printf "We will end with key $b\n"
b=$[$b+1]
### define sample length #######################################################
while [[ "$time" -lt 1 ]]
do
printf '\nChoose the sample length in full seconds(i will do 13 seconds): '
read time
done
printf "Sample length will be $time seconds\n"
### Debug play #################################################################
printf '\nDo you want to play every note past conversion? This will double the duration.
1 or enter for no '
read debug
### Fluidsynth Gain ############################################################
printf '\nPlease enter gain for fluidsynth between 0 and 5, Or press enter for gain 0.8: '
read fgain
if [[ -z $fgain ]]
then
fgain=0.8
fi
printf "Gain is set to $fgain\n"
### Sync Options ###############################################################
printf '\nHere you can cut of the file from beginning. In my mac I have a litte bit silence
on the beginning of the file for 0.1 second. That will be the default value if you press enter.
But feel free to change it to your wish. But stay in a positive value.
Type a value or press enter for my default 0.1 seconds: '
read sync
if [[ -z $sync ]]
then
sync=0.1
fi
printf "\nOk. we will cut another $sync off of the file\n"
### Effects ####################################################################
EFFECTS_FOLDER='effects/'
ls $EFFECTS_FOLDER > /var/tmp/effects_
cat -n /var/tmp/effects_
printf '\nChoose an effect in integer:'
read CHOOSE_EFFECT
if [[ -z "$CHOOSE_EFFECT" ]]
then
EFFECTS=""
printf 'recording without effects.\n'
else
EFFECTS=$(tail +$CHOOSE_EFFECT /var/tmp/effects_ | head -1)
printf "$EFFECTS will be used.\n"
fi
### Definition text file #######################################################
printf 'Writing definition file\n'
echo "%midinote_%velocity.wav" > $SOUNDBANK/definition.txt
### Working zone ###############################################################
caffeinate -dim &
while [[ "$a" != "$b" ]]
do
### Fluidsynth #########################################################
filename=$a"_"$y
printf 'start FluidSynth'
screen -d -m fluidsynth -g $fgain -a file $BKFOLDER -o audio.file.name=$SOUNDBANK/temp.raw
fluidsynth_is_running=""
while [[ -z "$fluidsynth_is_running" ]]
do
printf '.'
fluidsynth_is_running=$(pgrep fluidsynth > $SOUNDBANK/fluidsynth.pid && echo "1")
done
### Sendmidi ###########################################################
printf 'wait for sendmidi'
sendmidi dev fluidsynth 2> /var/tmp/sendmidi_con
sle=$(cat /var/tmp/sendmidi_con)
while [[ "$sle" != "" ]]
do
printf '.'
sendmidi dev fluidsynth 2> /var/tmp/sendmidi_con
sle=$(cat /var/tmp/sendmidi_con)
done
printf "sending tone -key $a -velocity $y for $time sec\n"
sendmidi dev fluidsynth on $a $y &
sleep $time
printf 'kill fluidsynth...'
killall fluidsynth
a=$[$a+1]
### Sox ################################################################
printf 'converting soundsample...'
sox -r 44100 -c 2 -b 16 -e signed-integer $SOUNDBANK/temp.raw $SOUNDBANK/temp.wav
file_length=$(sox $SOUNDBANK/temp.wav -n stat 2>&1 |grep Length |sed -n 's#^Length (seconds):[^0-9]*\([0-9.]*\)$#\1#p')
z=$(echo "$file_length-$time+$sync" | bc)
printf "trim the file from $z "
sox $SOUNDBANK/temp.wav $SOUNDBANK/$filename.wav trim $z $(< effects/$EFFECTS)
rm $SOUNDBANK/temp.raw
printf 'done\n'
if [[ $debug = 1 ]]
then
play $SOUNDBANK/$filename.wav
fi
done
killall caffeinate 1>&/dev/null &
### cleaning files ##############################################################
rm /var/tmp/Banks_
rm $SOUNDBANK/temp.*
rm $SOUNDBANK/fluidsynth.pid
unset BKFOLDER
unset SOUNDBANK
unset CHOOSEBANK
unset time
unset a
unset b
unset y
unset z
unset sle
unset debug
unset fgain
You can’t perform that action at this time.