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