| 1 | #! /bin/bash -e |
| 2 | |
| 3 | ##################################################################### |
| 4 | # # |
| 5 | # Compiles Faust programs to JACK-GTK # |
| 6 | # (c) Grame, 2009-2019 # |
| 7 | # # |
| 8 | ##################################################################### |
| 9 | |
| 10 | . faustpath |
| 11 | . faustoptflags |
| 12 | . usage.sh |
| 13 | |
| 14 | CXXFLAGS+=" $MYGCCFLAGS -I/opt/local/include" # So that additional CXXFLAGS can be used |
| 15 | |
| 16 | ARCHFILE=$FAUSTARCH/jack-gtk.cpp |
| 17 | |
| 18 | OSCDEFS="" |
| 19 | POLY="POLY" |
| 20 | NVOICES=-1 |
| 21 | SOUNDFILE="0" |
| 22 | SOUNDFILEDEFS="" |
| 23 | SOUNDFILELIBS="" |
| 24 | PRESETDIR="auto" |
| 25 | PRESETDEFS="" |
| 26 | |
| 27 | if [[ $(uname -s) != Darwin ]]; then |
| 28 | LFLAGS+="-no-pie" |
| 29 | fi |
| 30 | |
| 31 | #------------------------------------------------------------------- |
| 32 | # Check Darwin specifics |
| 33 | # |
| 34 | if [[ $(uname) == Darwin ]]; then |
| 35 | ARCHLIB+=" -framework CoreMIDI -framework CoreFoundation -framework CoreAudio -framework AudioUnit -framework CoreServices" |
| 36 | else |
| 37 | ARCHLIB+=" `pkg-config --cflags --libs alsa`" |
| 38 | fi |
| 39 | |
| 40 | echoHelp() |
| 41 | { |
| 42 | usage faust2jack "[options] [Faust options] <file.dsp>" |
| 43 | platform Linux |
| 44 | require Jack |
| 45 | echo "Compiles Faust programs to JACK and GTK" |
| 46 | option |
| 47 | options -httpd -osc -midi -soundfile -dyn |
| 48 | option -resample "to resample soundfiles to the audio driver sample rate." |
| 49 | option "-nvoices <num>" |
| 50 | option "-effect <effect.dsp>" |
| 51 | option "-effect auto" |
| 52 | option "-preset <directory>" "add a preset manager on top of GUI and save the preset files in the given directory" |
| 53 | option "-preset auto" "add a preset manager on top of GUI and save the preset files in a system temporary directory" |
| 54 | option "Faust options" |
| 55 | exit |
| 56 | } |
| 57 | |
| 58 | if [ "$#" -eq 0 ]; then |
| 59 | echo 'Please, provide a Faust file to process !' |
| 60 | echo '' |
| 61 | echoHelp |
| 62 | fi |
| 63 | |
| 64 | #PHASE 2 : dispatch command arguments |
| 65 | while [ $1 ] |
| 66 | do |
| 67 | p=$1 |
| 68 | |
| 69 | if [ $p = "-help" ] || [ $p = "-h" ]; then |
| 70 | echoHelp |
| 71 | elif [ $p = "-nvoices" ]; then |
| 72 | POLYDEFS="-DPOLY" |
| 73 | shift |
| 74 | NVOICES=$1 |
| 75 | if [ $NVOICES -ge 0 ]; then |
| 76 | CXXFLAGS="$CXXFLAGS -DNVOICES=$NVOICES" |
| 77 | fi |
| 78 | elif [ $p = "-effect" ]; then |
| 79 | POLYDEFS="-DPOLY2" |
| 80 | POLY="POLY2" |
| 81 | shift |
| 82 | EFFECT=$1 |
| 83 | elif [ $p = "-midi" ]; then |
| 84 | MIDIDEFS="-DMIDICTRL" |
| 85 | elif [ $p = "-dyn" ]; then |
| 86 | OPTIONS="$OPTIONS -inj template-llvm.cpp" |
| 87 | LLVM_LIBS="$STRIP $FAUSTLDDIR/libfaust.a `llvm-config --link-static --ldflags --libs all --system-libs`" |
| 88 | elif [ $p = "-soundfile" ]; then |
| 89 | SOUNDFILE="1" |
| 90 | SOUNDFILEDEFS="-DSOUNDFILE" |
| 91 | SOUNDFILELIBS=`pkg-config --cflags --static --libs sndfile` |
| 92 | elif [ $p = "-resample" ]; then |
| 93 | SAMPLERATEDEFS="-DSAMPLERATE" |
| 94 | SAMPLERATELIBS=`pkg-config --cflags --static --libs samplerate` |
| 95 | elif [ $p = "-fx" ]; then |
| 96 | OPTIONS="$OPTIONS $p" |
| 97 | CXXFLAGS="$CXXFLAGS -I /usr/local/include/ap_fixed -DFIXED_POINT" |
| 98 | elif [ $p = "-osc" ]; then |
| 99 | OSCDEFS="-DOSCCTRL -lOSCFaust" |
| 100 | elif [ $p = "-httpd" ]; then |
| 101 | HTTPDEFS="-DHTTPCTRL -lHTTPDFaust" |
| 102 | HTTPLIBS=`pkg-config --cflags --libs libmicrohttpd` |
| 103 | elif [ "$p" = "-preset" ]; then |
| 104 | PRESETDEFS="-DPRESETUI" |
| 105 | shift |
| 106 | PRESETDIR=$1 |
| 107 | elif [ $p = "-ocv" ]; then |
| 108 | OCVDEFS="-DOCVCTRL -pthread" |
| 109 | OCVLIBS="opencv" |
| 110 | elif [ $p = "-arch32" ]; then |
| 111 | PROCARCH="-m32 -L/usr/lib32" |
| 112 | elif [ $p = "-arch64" ]; then |
| 113 | PROCARCH="-m64" |
| 114 | elif [ ${p:0:1} = "-" ]; then |
| 115 | OPTIONS="$OPTIONS $p" |
| 116 | elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then |
| 117 | FILES="$FILES $p" |
| 118 | else |
| 119 | OPTIONS="$OPTIONS $p" |
| 120 | fi |
| 121 | |
| 122 | shift |
| 123 | |
| 124 | done |
| 125 | |
| 126 | #------------------------------------------------------------------- |
| 127 | # compile the *.dsp files using JACK-GTK |
| 128 | # |
| 129 | for f in $FILES; do |
| 130 | |
| 131 | # compile faust to c++ |
| 132 | if [ $POLY = "POLY2" ]; then |
| 133 | if [ $EFFECT = "auto" ]; then |
| 134 | cat > effect.dsp << EndOfCode |
| 135 | adapt(1,1) = _; |
| 136 | adapt(2,2) = _,_; |
| 137 | adapt(1,2) = _ <: _,_; |
| 138 | adapt(2,1) = _,_ :> _; |
| 139 | adaptor(F,G) = adapt(outputs(F),inputs(G)); |
| 140 | process = adaptor(library("$f").process, library("$f").effect) : library("$f").effect; |
| 141 | EndOfCode |
| 142 | faust -i -json -a $ARCHFILE $OPTIONS "$f" -o "${f%.dsp}_tmp.cpp" || exit |
| 143 | faust -i -cn effect -a minimal-effect.cpp effect.dsp -o effect.h || exit |
| 144 | rm effect.dsp |
| 145 | else |
| 146 | faust -i -json -a $ARCHFILE $OPTIONS "$f" -o "${f%.dsp}_tmp.cpp" || exit |
| 147 | faust -i -cn effect -a minimal-effect.cpp "$EFFECT" -o "effect.h" || exit |
| 148 | fi |
| 149 | else |
| 150 | faust -i -a $ARCHFILE $OPTIONS "$f" -o "${f%.dsp}_tmp.cpp"|| exit |
| 151 | fi |
| 152 | |
| 153 | # add preset management |
| 154 | if [ $PRESETDIR = "auto" ]; then |
| 155 | PRESETFILE=`mktemp -t preset.XXXXXXXXXX.cpp` || exit 1 |
| 156 | echo "#define PRESETDIR \"/var/tmp/\"" > "$PRESETFILE" |
| 157 | else |
| 158 | PRESETFILE=`mktemp -t preset.XXXXXXXXXX.cpp` || exit 1 |
| 159 | echo "#define PRESETDIR \"$PRESETDIR\"" > "$PRESETFILE" |
| 160 | fi |
| 161 | cat "$PRESETFILE" "${f%.dsp}_tmp.cpp" > "${f%.dsp}.cpp" |
| 162 | rm "$PRESETFILE" "${f%.dsp}_tmp.cpp" |
| 163 | |
| 164 | # compile c++ to binary |
| 165 | ( |
| 166 | $CXX $CXXFLAGS $FAUSTTOOLSFLAGS "${f%.dsp}.cpp" `pkg-config --cflags --libs jack $OCVLIBS gtk+-2.0` $LLVM_LIBS $SOUNDFILELIBS $SAMPLERATELIBS $PROCARCH $OSCDEFS $HTTPDEFS $HTTPLIBS $OCVDEFS $MIDIDEFS $POLYDEFS $SOUNDFILEDEFS $SAMPLERATEDEFS $PRESETDEFS $ARCHLIB $LFLAGS -o "${f%.dsp}" |
| 167 | if [[ $(uname) == Darwin ]]; then |
| 168 | codesign --sign - --deep --force "${f%.dsp}" |
| 169 | fi |
| 170 | ) > /dev/null || exit |
| 171 | |
| 172 | # remove temporary files |
| 173 | rm -f "${f%.dsp}.cpp" effect.h "$f.json" |
| 174 | |
| 175 | # collect binary file name for FaustWorks |
| 176 | BINARIES="$BINARIES${f%.dsp};" |
| 177 | done |
| 178 | |
| 179 | echo $BINARIES |
| 180 |