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 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
|
#! /bin/bash -e
#####################################################################
# #
# Compiles Faust programs to JUCE standalone or plugin #
# (c) Grame, 2016-2021 #
# #
#####################################################################
. faustpath
. faustoptflags
. usage.sh
CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used
DEBUG=false
echoHelp()
{
usage faust2juce "[options] [Faust options] <file.dsp>"
require Juce
echo "Compiles Faust programs to JUCE standalones or plugins (see https://github.com/grame-cncm/faust/tree/master-dev/architecture/juce)"
option
options -osc -midi -soundfile
option "-nvoices <num>"
option "-effect <effect.dsp>"
option "-effect auto"
option -standalone "to produce a standalone project, otherwise a plugin project is generated"
option -"vst2sdkdir <folder>" "to set directory to VST 2 SDK."
option -"jucemodulesdir <folder>" "to set JUCE modules directory to <folder>, such as ~/JUCE/modules"
option -disable-splash-screen "to disable the JUCE splash screen (license is required)."
option -jsynth "to use JUCE polyphonic Synthesizer instead of Faust polyphonic code"
option -llvm "to use the LLVM compilation chain (OSX and Linux for now)"
option -magic "to generate a project using the PluginGuiMagic GUI builder"
option "Faust options"
exit
}
if [ "$#" -eq 0 ]; then
echo 'Please, provide a Faust file to process !'
echo ''
echoHelp
fi
#-------------------------------------------------------------------
#PHASE 1 : dispatch command arguments
#-------------------------------------------------------------------
OSCLIB=""
POLY="POLY"
DEF=""
EFFECT=""
NVOICES=-1
STANDALONE="0"
IS_SYNTH="0"
IS_MIDI="0"
IS_LLVM="0"
JUCE_POLY="0"
FAUSTFLOAT="float"
JUCER=""
VST2_SDK="" # The directory containing "plugininterfaces/vst2.x/aeffect.h"
BUILD_VST2="0" # By default, don't build VST2
JUCE_MODULES_DIR="\.\.\/\.\.\/modules" # By default, the generated folder is supposed to be copied in JUCE/examples folder
PLUGIN_FORMATS="buildAU,buildAUv3,buildVST3,buildStandalone" # can append "buildVST"
PLUGIN_CHARACTERISTICS=""
DISPLAY_SPLASH_SCREEN="1"
while [ $1 ]
do
p=$1
if [ $p = "--help" ] || [ $p = "-help" ] || [ $p = "-h" ]; then
echoHelp
fi
if [ "$p" = -debug ]; then
DEBUG=true
elif [ $p = "-nvoices" ]; then
shift
IS_SYNTH="1"
NVOICES=$1
elif [ $p = "-standalone" ]; then
STANDALONE="1"
elif [ $p = "-effect" ]; then
DEF+="POLY2 "
POLY="POLY2"
shift
EFFECT=$1
elif [ $p = "-vst2sdkdir" ]; then
shift
VST2_SDK=$(echo $1 | sed -e 's/\//\\\//g')
if [ $VST2_SDK != "" ]; then
PLUGIN_FORMATS+=",buildVST"
BUILD_VST2="1"
fi
elif [ $p = "-jucemodulesdir" ]; then
shift
JUCE_MODULES_DIR=$(echo $1 | sed -e 's/\//\\\//g')
elif [ $p = "-disable-splash-screen" ]; then
DISPLAY_SPLASH_SCREEN="0"
elif [ $p = "-jsynth" ]; then
DEF+="JUCE_POLY "
JUCE_POLY="1"
elif [ $p = "-midi" ]; then
DEF+="MIDICTRL "
IS_MIDI="1"
elif [ $p = "-osc" ]; then
DEF+="OSCCTRL "
elif [ $p = "-llvm" ]; then
IS_LLVM="1"
elif [ $p = "-magic" ]; then
DEF+="PLUGIN_MAGIC "
elif [ $p = "-soundfile" ]; then
DEF+="SOUNDFILE "
elif [ ${p:0:1} = "-" ]; then
if [ $p = "-double" ]; then
FAUSTFLOAT="double"
fi
OPTIONS="$OPTIONS $p"
elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
FILES="$FILES $p"
else
OPTIONS="$OPTIONS $p"
fi
shift
done
# configure JUCER file
if [ $STANDALONE = "1" ]; then
if [ $IS_LLVM = "1" ]; then
JUCER="standalone-llvm.jucer"
else
JUCER="standalone.jucer"
fi
else
if [ $IS_LLVM = "1" ]; then
JUCER="plugin-llvm.jucer"
else
JUCER="plugin.jucer"
fi
fi
if [ $STANDALONE = "1" ] && [ $JUCE_POLY = "1" ]; then
echo "Cannot use -standalone with -jsynth"
exit
fi
if [ $POLY = "POLY2" ] && [ $JUCE_POLY = "1" ]; then
echo "Cannot use -effect with -jsynth"
exit
fi
# IS_SYNTH may have previously been set to "1" by the "-nvoices" command line option
if [ "$IS_SYNTH" == "0" ]; then
# look for polyphonic "nvoices" metadata in the DSP file
if [ $(cat $FILES | grep -c "nvoices:") -ne 0 ] || [ $(cat $FILES | grep -c "declare nvoices") -ne 0 ]
then
# a variation of the string "nvoices" was found
IS_SYNTH="1"
fi
fi
# Set PLUGIN_CHARACTERISTICS, and the order matters.
if [ $IS_SYNTH = "1" ]; then
PLUGIN_CHARACTERISTICS+=",pluginIsSynth"
fi
if [ $IS_MIDI = "1" ]; then
PLUGIN_CHARACTERISTICS+=",pluginProducesMidiOut,pluginWantsMidiIn"
fi
# Don't allow PLUGIN_CHARACTERISTICS to start with a comma
if [ ${PLUGIN_CHARACTERISTICS::1}="," ]; then
PLUGIN_CHARACTERISTICS="${PLUGIN_CHARACTERISTICS:1}"
fi
#-------------------------------------------------------------------
# compile the *.dsp files
#-------------------------------------------------------------------
for p in $FILES; do
CUR=$(pwd)
f=$(basename "$p")
SRCDIR=$(dirname "$p")
# creates the dir
dspName="${f%.dsp}"
SUB_TYPE=$(shasum $p)
SUB_TYPE=${SUB_TYPE:0:4}
rm -rf "$SRCDIR/$dspName"
if [ $STANDALONE = "0" ]; then
cp -r "$FAUSTARCH/juce/plugin" "$SRCDIR/$dspName/"
# setting plugin name to match the dsp
sed -e "s/SUB_TYPE/$SUB_TYPE/g" "$SRCDIR/$dspName/$JUCER" >> "$SRCDIR/$dspName/$dspName-temp.jucer"
else
cp -r "$FAUSTARCH/juce/standalone" "$SRCDIR/$dspName/"
# setting project name to match the dsp
sed -e "s/ProjectTitle/$dspName/g" "$SRCDIR/$dspName/$JUCER" >> "$SRCDIR/$dspName/$dspName-temp.jucer"
fi
# setting the preprocessing definitions
sed -e "s/PreProcDef/$DEF/g" "$SRCDIR/$dspName/$dspName-temp.jucer" >> "$SRCDIR/$dspName/$dspName-temp0.jucer"
sed -e "s/APPL_NAME/$dspName/g" "$SRCDIR/$dspName/$dspName-temp0.jucer" >> "$SRCDIR/$dspName/$dspName-temp1.jucer"
# MIDI
sed -e "s/IS_MIDI/$IS_MIDI/g" "$SRCDIR/$dspName/$dspName-temp1.jucer" >> "$SRCDIR/$dspName/$dspName-temp2.jucer"
# SYNTH
sed -e "s/IS_SYNTH/$IS_SYNTH/g" "$SRCDIR/$dspName/$dspName-temp2.jucer" >> "$SRCDIR/$dspName/$dspName-temp3.jucer"
# FAUSTFLOAT
sed -e "s/FAUST_FLOAT/$FAUSTFLOAT/g" "$SRCDIR/$dspName/$dspName-temp3.jucer" >> "$SRCDIR/$dspName/$dspName-temp4.jucer"
# JUCE_MODULES_DIR
sed -e "s/JUCE_MODULES_DIR_DEFAULT/$JUCE_MODULES_DIR/g" "$SRCDIR/$dspName/$dspName-temp4.jucer" >> "$SRCDIR/$dspName/$dspName-temp5.jucer"
# VST2_SDK
sed -e "s/VST2_SDK_DEFAULT/$VST2_SDK/g" "$SRCDIR/$dspName/$dspName-temp5.jucer" >> "$SRCDIR/$dspName/$dspName-temp6.jucer"
sed -e "s/BUILD_VST2_DEFAULT/$BUILD_VST2/g" "$SRCDIR/$dspName/$dspName-temp6.jucer" >> "$SRCDIR/$dspName/$dspName-temp7.jucer"
# PLUGIN_FORMATS
sed -e "s/PLUGIN_FORMATS_DEFAULT/$PLUGIN_FORMATS/g" "$SRCDIR/$dspName/$dspName-temp7.jucer" >> "$SRCDIR/$dspName/$dspName-temp8.jucer"
# PLUGIN_CHARACTERISTICS
sed -e "s/PLUGIN_CHARACTERISTICS_DEFAULT/$PLUGIN_CHARACTERISTICS/g" "$SRCDIR/$dspName/$dspName-temp8.jucer" >> "$SRCDIR/$dspName/$dspName-temp9.jucer"
# DISPLAY_SPLASH_SCREEN
sed -e "s/DISPLAY_SPLASH_SCREEN_DEFAULT/$DISPLAY_SPLASH_SCREEN/g" "$SRCDIR/$dspName/$dspName-temp9.jucer" >> "$SRCDIR/$dspName/$dspName-temp10.jucer"
# possibly set NVOICES value
if [ $NVOICES -ge 0 ]; then
sed -e "s/NUM_VOICES/$NVOICES/g" "$SRCDIR/$dspName/$dspName-temp10.jucer" >> "$SRCDIR/$dspName/$dspName.jucer"
else
cp "$SRCDIR/$dspName/$dspName-temp10.jucer" "$SRCDIR/$dspName/$dspName.jucer"
fi
# standalone or plugin mode
if [ $STANDALONE = "0" ]; then
rm "$SRCDIR/$dspName/plugin-llvm.jucer" "$SRCDIR/$dspName/plugin.jucer"
else
rm "$SRCDIR/$dspName/standalone-llvm.jucer" "$SRCDIR/$dspName/standalone.jucer"
fi
rm "$SRCDIR/$dspName/$dspName-temp.jucer" "$SRCDIR/$dspName/$dspName-temp0.jucer"
rm "$SRCDIR/$dspName/$dspName-temp1.jucer" "$SRCDIR/$dspName/$dspName-temp2.jucer"
rm "$SRCDIR/$dspName/$dspName-temp3.jucer" "$SRCDIR/$dspName/$dspName-temp4.jucer"
rm "$SRCDIR/$dspName/$dspName-temp5.jucer" "$SRCDIR/$dspName/$dspName-temp6.jucer"
rm "$SRCDIR/$dspName/$dspName-temp7.jucer" "$SRCDIR/$dspName/$dspName-temp8.jucer"
rm "$SRCDIR/$dspName/$dspName-temp9.jucer" "$SRCDIR/$dspName/$dspName-temp10.jucer"
# standalone of plugin mode
if [ $STANDALONE = "0" ]; then
if [ $IS_LLVM = "1" ]; then
faust -inj "$FAUSTINC/faust/dsp/llvm-dsp-adapter.h" -uim -i -a "$FAUSTARCH/juce/juce-plugin.cpp" $OPTIONS "$SRCDIR/$f" -o "$SRCDIR/$dspName/FaustPluginProcessor.cpp" || exit
dynamic-faust $OPTIONS "$SRCDIR/$f" -o "$SRCDIR/$dspName/dynamic.o"
else
faust -scn base_dsp -uim -i -a "$FAUSTARCH/juce/juce-plugin.cpp" $OPTIONS "$SRCDIR/$f" -o "$SRCDIR/$dspName/FaustPluginProcessor.cpp" || exit
fi
else
if [ $IS_LLVM = "1" ]; then
faust -inj "$FAUSTINC/faust/dsp/llvm-dsp-adapter.h" -i -a "$FAUSTARCH/juce/juce-standalone.cpp" $OPTIONS "$SRCDIR/$f" -o "$SRCDIR/$dspName/FaustAudioApplication.cpp" || exit
dynamic-faust $OPTIONS "$SRCDIR/$f" -o "$SRCDIR/$dspName/dynamic.o"
else
faust -scn base_dsp -i -a "$FAUSTARCH/juce/juce-standalone.cpp" $OPTIONS "$SRCDIR/$f" -o "$SRCDIR/$dspName/FaustAudioApplication.cpp" || exit
fi
fi
if [ $POLY = "POLY2" ]; then
if [ $EFFECT = "auto" ]; then
cat > "$SRCDIR/$dspName/effect.dsp" << EndOfCode
adapt(1,1) = _;
adapt(2,2) = _,_;
adapt(1,2) = _ <: _,_;
adapt(2,1) = _,_ :> _;
adaptor(F,G) = adapt(outputs(F),inputs(G));
process = adaptor(library("$SRCDIR/$f").process, library("$SRCDIR/$f").effect) : library("$SRCDIR/$f").effect;
EndOfCode
faust -scn base_dsp -i -cn effect -a minimal-effect.cpp "$SRCDIR/$dspName/effect.dsp" -o "$SRCDIR/$dspName/effect.h" || exit
rm "$SRCDIR/$dspName/effect.dsp"
else
faust -scn base_dsp -i -cn effect -a minimal-effect.cpp "$SRCDIR/$EFFECT" -o "$SRCDIR/$dspName/effect.h" || exit
fi
fi
done
|