| 1 | #! /bin/bash -e |
| 2 | |
| 3 | ##################################################################### |
| 4 | # # |
| 5 | # Compiles Faust programs to SVG plotters # |
| 6 | # (c) Grame, 2023 # |
| 7 | # # |
| 8 | ##################################################################### |
| 9 | |
| 10 | . faustpath |
| 11 | . faustoptflags |
| 12 | . usage.sh |
| 13 | |
| 14 | CXXFLAGS+=" $MYGCCFLAGS" # So that additional CXXFLAGS can be used |
| 15 | |
| 16 | ARCHFILE=$FAUSTARCH/svgplot/svgplot.cpp |
| 17 | ARCHLIB+=" -pthread" |
| 18 | |
| 19 | FAUSTFLOAT=float |
| 20 | SOUNDFILELIBS="" |
| 21 | |
| 22 | echoHelp() { |
| 23 | usage faust2svgplot "[options] [Faust options] <file.dsp>" |
| 24 | echo "Compiles Faust programs to SVG plotters, additional control parameters depend of the DSP, the following 2 options are given at runtime (see https://github.com/grame-cncm/faust/tree/master-dev/architecture/svgplot):" |
| 25 | option "-r <rate>" "change the sample rate (default is 44100 Hz)" |
| 26 | option |
| 27 | option -double "generates code with samples of type 'double'." |
| 28 | option -soundfile |
| 29 | option "Faust options" |
| 30 | exit |
| 31 | } |
| 32 | |
| 33 | if [ "$#" -eq 0 ]; then |
| 34 | echo 'Please, provide a Faust file to process !' |
| 35 | echo '' |
| 36 | echoHelp |
| 37 | fi |
| 38 | |
| 39 | #------------------------------------------------------------------- |
| 40 | # Analyze command arguments : |
| 41 | # faust options -> OPTIONS |
| 42 | # existing *.dsp files -> FILES |
| 43 | # |
| 44 | |
| 45 | # dispatch command arguments |
| 46 | for p in $@; do |
| 47 | |
| 48 | if [ $p = "-help" ] || [ $p = "-h" ]; then |
| 49 | echoHelp |
| 50 | elif [ $p = "-double" ]; then |
| 51 | OPTIONS="$OPTIONS $p" |
| 52 | FAUSTFLOAT="double" |
| 53 | elif [ $p = "-soundfile" ]; then |
| 54 | CXXFLAGS="$CXXFLAGS -DSOUNDFILE" |
| 55 | SOUNDFILELIBS=`pkg-config --cflags --static --libs sndfile` |
| 56 | elif [ ${p:0:1} = "-" ]; then |
| 57 | OPTIONS="$OPTIONS $p" |
| 58 | elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then |
| 59 | FILES="$FILES $p" |
| 60 | else |
| 61 | OPTIONS="$OPTIONS $p" |
| 62 | fi |
| 63 | done |
| 64 | |
| 65 | #------------------------------------------------------------------- |
| 66 | # compile the *.dsp files |
| 67 | |
| 68 | for f in $FILES; do |
| 69 | |
| 70 | # compile Faust to c++ |
| 71 | faust -i -a $ARCHFILE -cn mydsp $OPTIONS "$f" -o "$f.cpp" || exit |
| 72 | |
| 73 | # compile c++ to binary |
| 74 | ( |
| 75 | $CXX $CXXFLAGS "$f.cpp" $PROCARCH $LLVM_LIBS $ARCHLIB $SOUNDFILELIBS $OMP -DFAUSTFLOAT=$FAUSTFLOAT -o "${f%.dsp}" |
| 76 | ) > /dev/null || exit |
| 77 | rm "$f.cpp" |
| 78 | |
| 79 | # collect binary file name for FaustWorks |
| 80 | BINARIES="$BINARIES${f%.dsp};" |
| 81 | done |
| 82 | |
| 83 | echo $BINARIES |