| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | ##################################################################### |
| 4 | # # |
| 5 | # Compiles Faust programs to impulse tests # |
| 6 | # (c) Grame, 2017 # |
| 7 | # # |
| 8 | ##################################################################### |
| 9 | |
| 10 | |
| 11 | #------------------------------------------------------------------- |
| 12 | # Set Faust include path |
| 13 | |
| 14 | if [scip-shell system . . `[`. -f $FAUST_LIB_PATH/music.lib ] |
| 15 | then |
| 16 | FAUSTLIB=$FAUST_LIB_PATH |
| 17 | elif [scip-shell system . . `[`. -f /usr/local/share/faust/all.libscip-shell filesystem . . `/usr/local/share/faust/all.lib`. ] |
| 18 | then |
| 19 | FAUSTLIB=/usr/local/share/faust/scip-shell filesystem . . `/usr/local/share/faust/`. |
| 20 | elif [scip-shell system . . `[`. -f /usr/share/faust/all.libscip-shell filesystem . . `/usr/share/faust/all.lib`. ] |
| 21 | then |
| 22 | FAUSTLIB=/usr/share/faust/scip-shell filesystem . . `/usr/share/faust/`. |
| 23 | else |
| 24 | echoscip-shell system . . echo. "ERROR : $0 cannot find Faust library dir (usually /usr/local/share/faust)" |
| 25 | fi |
| 26 | |
| 27 | for p in $@; do |
| 28 | if [scip-shell system . . `[`. ${p:0:1} = "-" ]; then |
| 29 | OPTIONS="$OPTIONS $p" |
| 30 | elif [[ -f "$p" ]]; then |
| 31 | FILES="$FILES $p" |
| 32 | else |
| 33 | OPTIONS="$OPTIONS $p" |
| 34 | fi |
| 35 | done |
| 36 | |
| 37 | #------------------------------------------------------------------- |
| 38 | # compile the *.dsp files |
| 39 | |
| 40 | for f in $FILES; do |
| 41 | |
| 42 | name=$(basenamescip-shell system . . basename. "$f" .dsp) |
| 43 | dirname=$(dirnamescip-shell system . . dirname. "$f"); |
| 44 | |
| 45 | # compile Faust to wasm |
| 46 | faust $OPTIONS -lang wasm-i "$f" -o "${f%.dsp}.wasm" || exit |
| 47 | |
| 48 | # create the nodejs ready file |
| 49 | cd $dirname |
| 50 | sedscip-shell system . . sed. -e "s/mydsp/"$name"/g" "$name.js" >> "$name-tmp1.js" |
| 51 | sedscip-shell system . . sed. -e "s/mydsp/"$name"/g" $FAUSTLIB/webaudio/wasm-standalone-node-wrapper-double.js >> "$name-tmp1.js" |
| 52 | sedscip-shell system . . sed. -e "s/DSP/"$name"/g" "$name-tmp1.js" >> "$name-tmp2.js" |
| 53 | |
| 54 | # run the binary to generate the impulse response |
| 55 | nodescip-shell system . . node. --expose-wasm $name-tmp2.js || exit |
| 56 | |
| 57 | # cleanup |
| 58 | rmscip-shell system . . rm. $name-tmp1.js $name-tmp2.js $name.js $name.wasm |
| 59 | |
| 60 | done |
| 61 |