Debian Codegraph @

tools/faust2appls/faust2smartkeyb

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/bash
2
3 #####################################################################
4 # #
5 # SmartKeyboard App Generator for iOS and Android #
6 # (c) Romain Michon CCRMA and Grame, 2016 #
7 # #
8 #####################################################################
9
10 . faustpath
11 . usage.sh
12
13 # change if you want to get the log of what's happening
14 LOG="/dev/null"
15
16 # exit if a command fails
17 set -e
18
19 # global option variables
20 ANDROID="0"
21 IOS="0"
22 NVOICES="12"
23 POLY2="0"
24 MIDI="0"
25 OSC=""
26 EFFECT=""
27 SOURCE=0
28 REUSE=0
29 INSTALL=0
30
31 echoHelp()
32 {
33 echo "FAUST2SMARTKEYB - MUSICAL MOBILE APP GENERATOR"
34 echo ""
35 echo "faust2smartkeyb takes a Faust code as its main argument and convert it into a ready-to-use app for Android or iOS. The only two required arguments of faust2smartkeyb are a Faust file and the target platform (-android or -ios):"
36 echo ""
37
38 usage faust2smartkeyb "[options] [Faust options] <file.dsp>"
39 platform iOS, Android
40 option
41 option -android "generates an Android app"
42 option -ios "generates an iOS app"
43 option -osc
44 option -debug "activate debug mode"
45 option -effect "allow to specify an effect Faust file (e.g., -effect myEffect.dsp)"
46 option -install "install the app on the connected device (Android only)"
47 option -nvoices "specify the max number of voices"
48 option -reuse "reuse the same project source"
49 option -source "only generate the source (no compilation)"
50 option "Faust options"
51 echo "More information and tutorials at: https://ccrma.stanford.edu/~rmichon/smartKeyboard"
52 exit
53 }
54
55 if [ "$#" -eq 0 ]; then
56 echo 'Please, provide a Faust file to process !'
57 echo ''
58 echoHelp
59 fi
60
61 ###########################
62 # Processing Arguments
63 ###########################
64
65 while [ $1 ]
66 do
67 p=$1
68
69 if [ $p = "-help" ] || [ $p = "-h" ]; then
70 echoHelp
71 elif [[ -f "$p" ]]; then
72 FILE="$p"
73 elif [ $p = "-android" ]; then
74 ANDROID=1
75 elif [ $p = "-ios" ]; then
76 IOS="1"
77 elif [ $p = "-reuse" ]; then
78 REUSE=1
79 elif [ $p = "-source" ]; then
80 SOURCE=1
81 elif [ $p = "-debug" ]; then
82 LOG="/dev/stdout"
83 elif [ $p = "-install" ]; then
84 INSTALL=1
85 elif [ $p = "-osc" ]; then
86 OSC="-osc"
87 elif [ "$p" = "-effect" ]; then
88 POLY2="1"
89 shift
90 if [[ -f "$1" ]]; then
91 EFFECT=$1
92 elif [ $1 = "auto" ]; then
93 EFFECT=$1
94 else
95 echo "No file specified after -effect"
96 echoHelp
97 fi
98 elif [ $p = "-nvoices" ]; then
99 shift
100 NVOICES=$1
101 elif [ ${p:0:1} = "-" ]; then
102 OPTIONS="$OPTIONS $p"
103 elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
104 FILES="$FILES $p"
105 else
106 OPTIONS="$OPTIONS $p"
107 fi
108
109 shift
110
111 done
112
113 ###################################
114 # Configuring
115 ###################################
116
117 APPNAME=$(basename "$FILE")
118 APPNAME="${APPNAME%.dsp}"
119 APPNAME=`filename2ident "$APPNAME"`
120 BUILDDIR="faustsmartkeyb.$APPNAME"
121
122 # making sure that platform is set and generate corresponding global vars
123 if [ $ANDROID -eq 1 ]; then
124 APPFOLDER="$BUILDDIR/app/src/main"
125 elif [ $IOS -eq 1 ]; then
126 APPFOLDER="$BUILDDIR/Faust"
127 else
128 echo "Please, specify a platform: -android or -ios"
129 echoHelp
130 fi
131
132 ###############################
133 # Creating Default Project
134 ###############################
135 PLATFORM=$(uname)
136
137 if [ $REUSE -eq 0 ] || [ ! -d "$BUILDDIR" ]; then
138 if [ -d "$BUILDDIR" ]; then # if BUILDIR exists, then delete it
139 echo "Delete existing app project $BUILDDIR" > $LOG
140 rm -rf "$BUILDDIR"
141 fi
142
143 # copying new template app if no reuse
144 if [ ! -d "$BUILDDIR" ]; then
145 mkdir -p "$BUILDDIR"
146 cp -r $FAUSTARCH/smartKeyboard/LICENCE.md "$BUILDDIR"
147 if [ $ANDROID -eq 1 ]; then
148 echo "Creating a new Android project in $BUILDDIR" > $LOG
149 cp -r $FAUSTARCH/smartKeyboard/android/* "$BUILDDIR"
150
151 # change 'faust' with real *APPNAME
152
153 if [ $PLATFORM = "Darwin" ]; then
154 sed -i '' 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $BUILDDIR/app/build.gradle
155 sed -i '' 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/java/com/ccrma/faust/*
156 sed -i '' 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/AndroidManifest.xml
157 sed -i '' 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/res/layout/activity_main.xml
158 sed -i '' 's,Faust,'$APPNAME',g' $APPFOLDER/res/values/strings.xml
159 if [[ $OSC == "-osc" ]]; then
160 sed -i '' 's,OSCCTRL=false,OSCCTRL=true,g' $BUILDDIR/app/build.gradle
161 sed -i '' 's,set(OSCCTRL\ false),set(OSCCTRL\ true),g' $BUILDDIR/app/CMakeLists.txt
162 fi
163 else
164 sed -i 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $BUILDDIR/app/build.gradle
165 sed -i 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/java/com/ccrma/faust/*
166 sed -i 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/AndroidManifest.xml
167 sed -i 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/res/layout/activity_main.xml
168 sed -i 's,Faust,'$APPNAME',g' $APPFOLDER/res/values/strings.xml
169 if [[ $OSC == "-osc" ]]; then
170 sed -i 's,OSCCTRL=false,OSCCTRL=true,g' $BUILDDIR/app/build.gradle
171 sed -i 's,set(OSCCTRL\ false),set(OSCCTRL\ true),g' $BUILDDIR/app/CMakeLists.txt
172 fi
173 fi
174 mv $APPFOLDER/java/com/ccrma/faust $APPFOLDER/java/com/ccrma/$APPNAME
175 elif [ $IOS -eq 1 ]; then
176 echo "Creating a new iOS project in $BUILDDIR" > $LOG
177 cp -r $FAUSTARCH/smartKeyboard/iOS/* "$BUILDDIR"
178 if [ $PLATFORM = "Darwin" ]; then
179 sed -i '' 's,$(TARGET_NAME),'$APPNAME',g' $BUILDDIR/Faust.xcodeproj/project.pbxproj
180 sed -i '' 's,ccrma.Faust,ccrma.'$APPNAME',g' $BUILDDIR/Faust.xcodeproj/project.pbxproj
181 else
182 sed -i 's,$(TARGET_NAME),'$APPNAME',g' $BUILDDIR/Faust.xcodeproj/project.pbxproj
183 sed -i 's,ccrma.Faust,ccrma.'$APPNAME',g' $BUILDDIR/Faust.xcodeproj/project.pbxproj
184 fi
185 # Put OSC in project in all cases, even if not compiled
186 # cp -r $FAUSTARCH/osclib "$BUILDDIR"/Faust
187 fi
188 fi
189 fi
190
191 ###########################
192 # Adding DSP
193 ###########################
194
195 if [ $ANDROID -eq 1 ]; then
196 if [ -z "$EFFECT" ]; then # no effect
197 echo "Adding DSP with no effect chain to the app" > $LOG
198 faust2api -android $OSC -nvoices "$NVOICES" -nodoc $OPTIONS "$FILE" > $LOG
199 else
200 echo "Adding DSP with effect chain to the app" > $LOG
201 faust2api -android $OSC -nvoices "$NVOICES" -effect "$EFFECT" -nodoc $OPTIONS "$FILE" > $LOG
202 fi
203 unzip "dsp-faust.zip" > $LOG
204 mv "dsp-faust" "$BUILDDIR"
205 rm "dsp-faust.zip"
206 cp -r "$BUILDDIR/dsp-faust/cpp" "$APPFOLDER"
207 cp $BUILDDIR/dsp-faust/java/* "$APPFOLDER/java/com/DspFaust"
208 rm -r "$BUILDDIR/dsp-faust"
209 elif [ $IOS -eq 1 ]; then
210 if [ -z "$EFFECT" ]; then # no effect
211 echo "Adding DSP with no effect chain to the app" > $LOG
212 faust2api -ios $OSC -midi -nvoices "$NVOICES" -nodoc $OPTIONS "$FILE" > $LOG
213 else
214 echo "Adding DSP with effect chain to the app" > $LOG
215 faust2api -ios $OSC -midi -nvoices "$NVOICES" -effect "$EFFECT" -nodoc $OPTIONS "$FILE" > $LOG
216 fi
217 unzip "dsp-faust.zip" > $LOG
218 mv "dsp-faust" "$BUILDDIR"
219 rm "dsp-faust.zip"
220 cp $BUILDDIR/dsp-faust/* "$APPFOLDER"
221 rm -r "$BUILDDIR/dsp-faust"
222 fi
223
224 ###########################
225 # Compilation
226 ###########################
227
228 if [ $SOURCE -eq 0 ]; then
229 if [ $ANDROID -eq 1 ]; then
230 echo "Starting Android compilation" > $LOG
231 cd $BUILDDIR
232
233 # Try to use installed gradle instead of local ./gradlew in order
234 # to avoid potential problems when compiling in a shared folder
235 # where execution rights may not be granted (i.e. on a google VM)
236 # In order to install gradle-4.6:
237 # wget https://services.gradle.org/distributions/gradle-4.6-bin.zip
238 # unzip -d /opt/gradle gradle-4.6-bin.zip
239
240 if [ -f /opt/gradle/gradle-4.10.1/bin/gradle ]; then
241 FAUSTGRADLE=${FAUSTGRADLE:=/opt/gradle/gradle-4.10.1/bin/gradle}
242 else
243 FAUSTGRADLE=${FAUSTGRADLE:=./gradlew}
244 chmod a+x ./gradlew
245 fi
246 echo "USED GRADLE=$FAUSTGRADLE" > $LOG
247
248 $FAUSTGRADLE assembleRelease > $LOG
249 cd ..
250 cp -r $BUILDDIR/app/build/outputs/apk/release/app-release.apk $APPNAME.apk > $LOG
251 echo "An Android app \"$APPNAME.apk\" was created in the current folder"
252 elif [ $IOS -eq 1 ]; then
253 echo "Starting iOS compilation" > $LOG
254 (
255 xcodebuild -project "$BUILDDIR/Faust.xcodeproj" -target Faust PRODUCT_NAME=$APPNAME
256 cd "$BUILDDIR" && xcodebuild -scheme Faust PRODUCT_NAME=$APPNAME
257 ) > $LOG || exit 1
258 rm -rf "$APPNAME.app"
259 mv "$BUILDDIR/build/Release-iphoneos/$APPNAME.app" .
260 echo "An iOS app \"$APPNAME.app\" was created in the current folder"
261 fi
262 fi
263
264 ###########################
265 # Installation
266 ###########################
267
268 if [ $INSTALL -eq 1 ]; then
269 if [ $ANDROID -eq 1 ]; then
270 echo "Installing the app" > $LOG
271 adb install -r $APPNAME.apk
272 elif [ $ANDROID -eq 1 ]; then
273 echo "Automatic installation is only possible on Android"
274 fi
275 fi
276
277 ###########################
278 # Cleaning
279 ###########################
280
281 if [ $REUSE -eq 0 ] && [ $SOURCE -eq 0 ]; then
282 echo "Delete app project $BUILDDIR" > $LOG
283 rm -rf $BUILDDIR
284 else
285 echo "An app project $BUILDDIR was created or updated in the current directory"
286 fi