Debian Codegraph @

tools/faust2appls/faust2alsa

raw symbols SCIP
1 #! /bin/bash -e
2
3 #####################################################################
4 # #
5 # Compiles Faust programs to alsa-gtk #
6 # (c) Grame, 2009-2025 #
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/alsa-gtk.cpp
17 OSCDEFS=""
18 POLY="POLY"
19 NVOICES=-1
20 EFFECT=""
21 SOUNDFILE="0"
22 SOUNDFILEDEFS=""
23 SOUNDFILELIBS=""
24
25 if [[ $(uname -s) != Darwin ]]; then
26 LFLAGS+="-no-pie"
27 fi
28
29 echoHelp()
30 {
31 usage faust2alsa "[options] [Faust options] <file.dsp>"
32 platform Linux
33 require Alsa
34 echo "Compiles Faust programs to ALSA and GTK"
35 option
36 options -httpd -osc -midi -qrcode -soundfile
37 option "-nvoices <num>"
38 option "-effect <effect.dsp>"
39 option "-effect auto"
40 option "Faust options"
41 exit
42 }
43
44 if [ "$#" -eq 0 ]; then
45 echo 'Please, provide a Faust file to process !'
46 echo ''
47 echoHelp
48 fi
49
50 #-------------------------------------------------------------------
51 # Analyze command arguments :
52 # faust options -> OPTIONS
53 # if -omp : -openmp or -fopenmp -> OPENMP
54 # existing *.dsp files -> FILES
55 #
56
57 # dispatch command arguments
58 while [ $1 ]
59 do
60 p=$1
61
62 if [ $p = "-help" ] || [ $p = "-h" ]; then
63 echoHelp
64 elif [ $p = "-nvoices" ]; then
65 POLYDEFS="-DPOLY"
66 shift
67 NVOICES=$1
68 if [ $NVOICES -ge 0 ]; then
69 CXXFLAGS="$CXXFLAGS -DNVOICES=$NVOICES"
70 fi
71 elif [ $p = "-soundfile" ]; then
72 SOUNDFILE="1"
73 SOUNDFILEDEFS="-DSOUNDFILE"
74 SOUNDFILELIBS=`pkg-config --cflags --static --libs sndfile`
75 elif [ $p = "-effect" ]; then
76 POLYDEFS="-DPOLY2"
77 POLY="POLY2"
78 shift
79 EFFECT=$1
80 elif [ $p = "-midi" ]; then
81 MIDIDEFS="-DMIDICTRL"
82 elif [ $p = "-osc" ]; then
83 OSCDEFS="-DOSCCTRL -lOSCFaust"
84 YPATH="-L/usr/local/lib"
85 elif [ $p = "-httpd" ]; then
86 HTTPDEFS="-DHTTPCTRL -lHTTPDFaust"
87 HTTPLIBS=`pkg-config --cflags --libs libmicrohttpd`
88 YPATH="-L/usr/local/lib"
89 elif [ $p = "-arch32" ]; then
90 PROCARCH="-m32 -L/usr/lib32"
91 elif [ $p = "-arch64" ]; then
92 PROCARCH="-m64"
93 elif [ ${p:0:1} = "-" ]; then
94 OPTIONS="$OPTIONS $p"
95 elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
96 FILES="$FILES $p"
97 else
98 OPTIONS="$OPTIONS $p"
99 fi
100
101 shift
102
103 done
104
105 #-------------------------------------------------------------------
106 # compile the *.dsp files using ALSA and GTK on linux
107 #
108 for f in $FILES; do
109
110 # compile faust to c++
111 if [ $POLY = "POLY2" ]; then
112 if [ $EFFECT = "auto" ]; then
113 cat > effect.dsp << EndOfCode
114 adapt(1,1) = _;
115 adapt(2,2) = _,_;
116 adapt(1,2) = _ <: _,_;
117 adapt(2,1) = _,_ :> _;
118 adaptor(F,G) = adapt(outputs(F),inputs(G));
119 process = adaptor(library("$f").process, library("$f").effect) : library("$f").effect;
120 EndOfCode
121 faust -i -json -a $ARCHFILE $OPTIONS "$f" -o "$f.cpp" || exit
122 faust -i -cn effect -a minimal-effect.cpp effect.dsp -o effect.h || exit
123 rm effect.dsp
124 else
125 faust -i -json -a $ARCHFILE $OPTIONS "$f" -o "$f.cpp" || exit
126 faust -i -cn effect -a minimal-effect.cpp "$EFFECT" -o "effect.h" || exit
127 fi
128 else
129 faust -i -a $ARCHFILE $OPTIONS "$f" -o "$f.cpp" || exit
130 fi
131
132 # compile c++ to binary
133 (
134 $CXX $CXXFLAGS $FAUSTTOOLSFLAGS $OMP "$f.cpp" `pkg-config --cflags --libs alsa gtk+-2.0` $SOUNDFILELIBS $PROCARCH $YPATH $OSCDEFS $HTTPDEFS $HTTPLIBS $POLYDEFS $MIDIDEFS $SOUNDFILEDEFS $LFLAGS -o "${f%.dsp}"
135 )> /dev/null || exit
136 rm -f "$f.cpp" effect.h "$f.json"
137
138 # collect binary file name for FaustWorks
139 BINARIES="$BINARIES${f%.dsp};"
140 done
141
142 echo $BINARIES