Debian Codegraph @

tools/faust2appls/faust2ios

raw symbols SCIP
1 #! /bin/bashscip-shell filesystem . . `/bin/bash`. -e
2
3 #####################################################################
4 # #
5 # Compiles Faust programs to iOS applications #
6 # (c) Grame, 2012-2018 #
7 # #
8 #####################################################################
9
10 . faustpathscip-shell source . . faustpath.
11 . faustoptflagsscip-shell source . . faustoptflags.
12 . usage.shscip-shell source . . `usage.sh`.
13
14 ARCHFILE=$FAUSTARCH/ios-coreaudio.cpp
15
16 NOAGC="0"
17 POLY="POLY"
18 OSCCTRL="0"
19 MIDICTRL="0"
20 ALL="1"
21 EFFECT=""
22 NVOICES=-1
23 XCODE="0"
24 ARCHIVE="0"
25 SOUNDFILE="0"
26
27 echoHelpscip-shell shell shell-project 0.0.0 echoHelp().()
28 {
29 usage faust2ios "[options] [Faust options] <file.dsp>"
30 platform iOS
31 echoscip-shell system . . echo. "Compiles Faust programs to iOS applications"
32 option
33 options -midi -osc -soundfile
34 option "-nvoices <num>"
35 option "-effect <effect.dsp>"
36 option "-effect auto"
37 option -xcode "to compile and keep the intermediate Xcode project"
38 option -xcodeproj "to produce the intermediate Xcode project"
39 option -archive "to generate the archive for Apple Store"
40 option -32bits "to compile 32 bits only binary"
41 option -noagc "to deactivate audio automatic gain control"
42 option "Faust options"
43 exit
44 }
45
46 if [scip-shell system . . `[`. "$#" -eq 0 ]; then
47 echoscip-shell system . . echo. 'Please, provide a Faust file to process !'
48 echoscip-shell system . . echo. ''
49 echoHelpscip-shell shell shell-project 0.0.0 echoHelp().
50 fi
51
52 #PHASE 1 : collects files and options from the command line
53
54 while [scip-shell system . . `[`. $1 ]
55 do
56 p=$1
57
58 if [scip-shell system . . `[`. $p = "-help" ] || [scip-shell system . . `[`. $p = "-h" ]; then
59 echoHelpscip-shell shell shell-project 0.0.0 echoHelp().
60 elif [scip-shell system . . `[`. $p = "-osc" ]; then
61 OSCCTRL="1"
62 elif [scip-shell system . . `[`. $p = "-soundfile" ]; then
63 SOUNDFILE="1"
64 elif [scip-shell system . . `[`. "$p" = "-jack" ]; then
65 JACK="1"
66 elif [scip-shell system . . `[`. "$p" = "-xcode" ]; then
67 XCODE="1"
68 elif [scip-shell system . . `[`. "$p" = "-xcodeproj" ]; then
69 XCODE="2"
70 elif [scip-shell system . . `[`. "$p" = "-nvoices" ]; then
71 shift
72 NVOICES=$1
73 elif [scip-shell system . . `[`. "$p" = "-effect" ]; then
74 POLY="POLY2"
75 shift
76 EFFECT=$1
77 elif [scip-shell system . . `[`. "$p" = "-midi" ]; then
78 MIDICTRL="1"
79 elif [scip-shell system . . `[`. "$p" = "-32bits" ]; then
80 ALL="0"
81 elif [scip-shell system . . `[`. "$p" = "-noagc" ]; then
82 NOAGC="1"
83 elif [scip-shell system . . `[`. "$p" = "-archive" ]; then
84 ARCHIVE="1"
85 elif [scip-shell system . . `[`. ${p:0:1} = "-" ]; then
86 OPTIONS="$OPTIONS $p"
87 elif [[ -f "$p" ]] && [scip-shell system . . `[`. ${p: -4} == ".dsp" ]; then
88 FILES="$FILES $p"
89 else
90 OPTIONS="$OPTIONS $p"
91 fi
92
93 shift
94
95 done
96
97 addOptionsscip-shell shell shell-project 0.0.0 addOptions(). ()
98 {
99 # OSC source always copied in the project
100 cpscip-shell system . . cp. -r $FAUSTARCH/osclib "$T"
101 # FaustNode.h still has a dependency with public Faust headers, create a self-contained version
102 echoscip-shell system . . echo. "process = _;" >> "$T"/tmp.dsp
103 echoscip-shell system . . echo. "" >> "$T"/tmp.cpp
104 faust -i -inj "$T"/tmp.cpp -a $FAUSTARCH/osclib/faust/faust/osc/FaustNode.h "$T"/tmp.dsp -o "$T"/osclib/faust/faust/osc/FaustNode.h
105 rmscip-shell system . . rm. "$T"/tmp.dsp "$T"/tmp.cpp
106
107 if [scip-shell system . . `[`. "$OSCCTRL" = "1" ]; then
108 echoscip-shell system . . echo. "#define OSCCTRL 1" | catscip-shell system . . cat. - "$T/iOS/iOS-Prefix.pch" > temp && mvscip-shell system . . mv. temp "$T/iOS/iOS-Prefix.pch"
109 fi
110 if [scip-shell system . . `[`. "$MIDICTRL" = "1" ]; then
111 echoscip-shell system . . echo. "#define MIDICTRL 1" | catscip-shell system . . cat. - "$T/iOS/iOS-Prefix.pch" > temp && mvscip-shell system . . mv. temp "$T/iOS/iOS-Prefix.pch"
112 fi
113 if [scip-shell system . . `[`. $POLY = "POLY2" ]; then
114 echoscip-shell system . . echo. "#define POLY2 1" | catscip-shell system . . cat. - "$T/iOS/iOS-Prefix.pch" > temp && mvscip-shell system . . mv. temp "$T/iOS/iOS-Prefix.pch"
115 fi
116 if [scip-shell system . . `[`. "$NOAGC" = "1" ]; then
117 echoscip-shell system . . echo. "#define NOAGC 1" | catscip-shell system . . cat. - "$T/iOS/iOS-Prefix.pch" > temp && mvscip-shell system . . mv. temp "$T/iOS/iOS-Prefix.pch"
118 fi
119 if [scip-shell system . . `[`. $NVOICES -ge 0 ]; then
120 echoscip-shell system . . echo. "#define NVOICES $NVOICES" | catscip-shell system . . cat. - "$T/iOS/iOS-Prefix.pch" > temp && mvscip-shell system . . mv. temp "$T/iOS/iOS-Prefix.pch"
121 fi
122
123 # Copy libsndfile in the project
124 cpscip-shell system . . cp. -r /usr/local/lib/ios-libsndfile.ascip-shell filesystem . . `/usr/local/lib/ios-libsndfile.a`. "$T"
125
126 if [scip-shell system . . `[`. "$SOUNDFILE" = "1" ]; then
127 echoscip-shell system . . echo. "#define SOUNDFILE 1" | catscip-shell system . . cat. - "$T/iOS/iOS-Prefix.pch" > temp && mvscip-shell system . . mv. temp "$T/iOS/iOS-Prefix.pch"
128 fi
129 }
130
131 warnSoundfilescip-shell shell shell-project 0.0.0 warnSoundfile().()
132 {
133 if [scip-shell system . . `[`. "$SOUNDFILE" = "1" ]; then
134 echoscip-shell system . . echo. "Warning : -soundfile is used, you'll have to manually add the needed soundfiles in the project"
135 fi
136 }
137
138 #PHASE 2 : compile all files
139
140 for p in $FILES; do
141 S=$(dirnamescip-shell system . . dirname. "$p")
142 F=$(basenamescip-shell system . . basename. "$p")
143 P=${F%.dsp}
144 XCODEPROJ="${F%.dsp}"
145 SRCDIR=$(dirnamescip-shell system . . dirname. "$p")
146
147 T=$(mktempscip-shell system . . mktemp. -d faust.XXX)
148 cpscip-shell system . . cp. -r $FAUSTARCH/iOS/* $T
149
150 if [scip-shell system . . `[`. "$ALL" = "1" ]; then
151 echoscip-shell system . . echo. "Compile with CoreAudio support in 64/32 bits"
152 faust -i $OPTIONS -json -a $ARCHFILE "$p" -o "$T/ios-faust.h" || exit
153 addOptionsscip-shell shell shell-project 0.0.0 addOptions().
154
155 if [scip-shell system . . `[`. $POLY = "POLY2" ]; then
156 if [scip-shell system . . `[`. $EFFECT = "auto" ]; then
157 catscip-shell system . . cat. > $T/effect.dsp << EndOfCode
158 adapt(1,1) = _;
159 adapt(2,2) = _,_;
160 adapt(1,2) = _ <: _,_;
161 adapt(2,1) = _,_ :> _;
162 adaptor(F,G) = adapt(outputs(F),inputs(G));
163 process = adaptor(library("$SRCDIR/$F").process, library("$SRCDIR/$F").effect) : library("$SRCDIR/$F").effect;
164 EndOfCode
165 faust -i -json -a $ARCHFILE $OPTIONS "$p" -o "$T/${F%.dsp}_tmp.cpp" || exit
166 faust -i -cn effect -a minimal-effect.cpp "$T/effect.dsp" -o "$T/effect.h" || exit
167 rmscip-shell system . . rm. "$T/effect.dsp"
168 else
169 faust -i -json -a $ARCHFILE $OPTIONS "$p" -o "$T/${F%.dsp}_tmp.cpp" || exit
170 faust -i -cn effect -a minimal-effect.cpp "$SRCDIR/$EFFECT" -o "$T/effect.h" || exit
171 fi
172 fi
173
174 if [scip-shell system . . `[`. "$XCODE" == "2" ]; then
175 warnSoundfilescip-shell shell shell-project 0.0.0 warnSoundfile().
176 mvscip-shell system . . mv. $T $XCODEPROJ
177 # remove temporary JSON file
178 rmscip-shell system . . rm. $p.json
179 exit
180 fi
181 (
182 # Build the binary
183 xcodebuild -project "$T/iOS.xcodeproj" -target Template_CoreAudio PRODUCT_NAME=$P || exit
184 # Build the archive
185 if [scip-shell system . . `[`. "$ARCHIVE" = "1" ]; then
186 cd "$T" && xcodebuild -scheme Template_CoreAudio archive -archivePath $P.xcarchive PRODUCT_NAME=$P
187 # Correct archive generated Info.plist to properly use '$P' name
188 cd $P.xcarchive && cpscip-shell system . . cp. Info.plist Info-tmp.plist && sedscip-shell system . . sed. -e "s/Template_CoreAudio/"$P"/g" Info-tmp.plist > Info.plist && rmscip-shell system . . rm. Info-tmp.plist
189 fi
190 ) > /dev/nullscip-shell filesystem . . `/dev/null`. || exit
191 else
192 echoscip-shell system . . echo. "Compile with CoreAudio support in 32 bits"
193 faust -i $OPTIONS -json -a $ARCHFILE "$p" -o "$T/ios-faust.h" || exit
194 addOptionsscip-shell shell shell-project 0.0.0 addOptions().
195 if [scip-shell system . . `[`. "$POLY2" = "1" ]; then
196 faust -i $OPTIONS -json -cn effect -a minimal-effect.cpp $EFFECT -o "$T/effect.h" || exit
197 fi
198
199 if [scip-shell system . . `[`. "$XCODE" == "2" ]; then
200 warnSoundfilescip-shell shell shell-project 0.0.0 warnSoundfile().
201 mvscip-shell system . . mv. $T $XCODEPROJ
202 # remove temporary JSON file
203 rmscip-shell system . . rm. $p.json
204 exit
205 fi
206 (
207 # Build the binary
208 xcodebuild -project "$T/iOS.xcodeproj" -target Template_CoreAudio_32bits PRODUCT_NAME=$P || exit
209 # Build the archive
210 if [scip-shell system . . `[`. "$ARCHIVE" = "1" ]; then
211 cd "$T" && xcodebuild -scheme Template_CoreAudio_32bits archive -archivePath $P.xcarchive PRODUCT_NAME=$P
212 # Correct archive generated Info.plist to properly use '$P' name
213 cd $P.xcarchive && cpscip-shell system . . cp. Info.plist Info-tmp.plist && sedscip-shell system . . sed. -e "s/Template_CoreAudio/"$P"/g" Info-tmp.plist > Info.plist && rmscip-shell system . . rm. Info-tmp.plist
214 fi
215 ) > /dev/nullscip-shell filesystem . . `/dev/null`. || exit
216 fi
217
218 # move generated app to source directory
219 rmscip-shell system . . rm. -rf "$S/$P.app"
220 mvscip-shell system . . mv. "$T/build/Release-iphoneos/$P.app" "$S/"
221 if [scip-shell system . . `[`. "$ARCHIVE" = "1" ]; then
222 rmscip-shell system . . rm. -rf "$S/$P.xcarchive"
223 mvscip-shell system . . mv. "$T/$P.xcarchive" "$S/"
224 fi
225 if [scip-shell system . . `[`. "$XCODE" != "1" ]; then
226 rmscip-shell system . . rm. -rf "$T"
227 else
228 echoscip-shell system . . echo. "Keep Xcode project"
229 fi
230
231 if [scip-shell system . . `[`. "$SOUNDFILE" = "1" ]; then
232 # get all soundfiles from the JSON file
233 catscip-shell system . . cat. $p.json | awkscip-shell system . . awk. '
234 BEGIN { FS=":"; SOFI=0; }
235 /"soundfile"/ { SOFI=1; }
236 /"url"/ {
237 if (SOFI) {
238 match($2, /"[^"]*/);
239 split(substr($2, RSTART+2, RLENGTH-3), res, ";");
240 for (x in res) print substr(res[x], 2, length(res[x])-2);
241 SOFI=0;
242 }
243 }
244 ' > $p-tmp.txt
245 # copy found soundfiles in the final binary
246 for snd in $(catscip-shell system . . cat. $p-tmp.txt); do
247 if [scip-shell system . . `[`. -f $snd ]; then
248 if [scip-shell system . . `[`. ${snd:0:1} = "/scip-shell filesystem . . `/`." ]; then
249 echoscip-shell system . . echo. "Warning: soundfile with absolute path is not copied !"
250 else
251 #create destination path and possibly create directory
252 sfpath="$P.app/$(dirnamescip-shell system . . dirname. $snd)/"
253 if ! [scip-shell system . . `[`. -d $sfpath ]; then
254 echoscip-shell system . . echo. "Create $sfpath"
255 mkdirscip-shell system . . mkdir. $sfpath
256 fi
257 echoscip-shell system . . echo. "Copy $snd in $P.app"
258 cpscip-shell system . . cp. $snd $sfpath
259 if [scip-shell system . . `[`. "$ARCHIVE" = "1" ]; then
260 sfarchivepath="$P.xcarchive/Products/Applications/$P.app/$(dirnamescip-shell system . . dirname. $snd)/"
261 if ! [scip-shell system . . `[`. -d $sfarchivepath ]; then
262 echoscip-shell system . . echo. "Create $sfarchivepath"
263 mkdirscip-shell system . . mkdir. $sfarchivepath
264 fi
265 echoscip-shell system . . echo. "Copy $snd in $P.xcarchive/Products/Applications/$P"
266 cpscip-shell system . . cp. $snd $sfarchivepath
267 fi
268 fi
269 else
270 echoscip-shell system . . echo. "Error: file $snd not found !"
271 fi
272 done
273 rmscip-shell system . . rm. $p-tmp.txt
274 fi
275
276 # collect binary file name for FaustGIDE
277 if [scip-shell system . . `[`. "$ARCHIVE" = "1" ]; then
278 BINARIES="$BINARIES$S/$P.app; $BINARIES$S/$P.xcarchive;"
279 else
280 BINARIES="$BINARIES$S/$P.app;"
281 fi
282
283 # remove temporary JSON file
284 rmscip-shell system . . rm. $p.json
285 done
286
287 echoscip-shell system . . echo. $BINARIES