1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
#! /bin/bash -e
#####################################################################
# #
# Compile a Faust program to an android app #
# (c) Romain Michon CCRMA and Grame, 2014 #
# (c) Yann Orlarey Grame, 2015 #
# #
#####################################################################
. faustpath
. faustoptflags
# change if you want to get the log of what's happening
LOG="/dev/null"
# FAUSTGRADLE environement variable. By default we use ./gradlew
FAUSTGRADLE=${FAUSTGRADLE:=./gradlew}
# exit if a command fails
set -e
# Global variables for file and options
FILE=
INSTALL=0
SOURCE=0
SWIG=0
FAUST=0
KEYBOARD=0
REUSE=0
SOUNDFILE=0
# PHASE 2 : dispatch command arguments
for p in $@; do
if [ $p = "-swig" ]; then
SWIG=1
fi
if [[ -f "$p" ]]; then
FILE="$p"
elif [ $p = "-install" ]; then
INSTALL=1
elif [ $p = "-soundfile" ]; then
SOUNDFILE="1"
elif [ $p = "-source" ]; then
SOURCE=1
elif [ $p = "-faust" ]; then
FAUST=1
elif [ $p = "-reuse" ]; then
REUSE=1
elif [ $p = "-keyboard" ]; then
KEYBOARD=1
elif [ $p = "-debug" ]; then
LOG="/dev/stdout"
elif [ "$p" = "-noagc" ]; then
NOAGC="1"
elif [ $p = "-h" ]; then
echo "Usage: faust2android [-install] [-source] [-swig] [-faust] [-reuse] [-soundfile] [-debug] [additional Faust options (-vec -vs 8...)] <file.dsp>"
echo "Use '-install' once compilation is over, installs the generated app on the Android device connected to the computer."
echo "Use '-source' creates an eclipse project of the app in the current directory."
echo "Use '-swig' regenerate the C++ and the JAVA interface for the native portion of the app."
echo "Use '-faust' only carries out the Faust compilation and install the generated C++ file in the JNI folder."
echo "Use '-reuse' keep build directory and reuse it to speedup compilation."
echo "Use '-soundfile' when compiling DSP using 'soundfile' primitive, to add needed resources"
echo "Use '-debug' verbose output."
exit
elif [ ${p:0:1} = "-" ]; then
OPTIONS="$OPTIONS $p"
else
OPTIONS="$OPTIONS $p"
fi
done
# only carry out the faust compilation
if [ $FAUST -eq 1 ]; then
faust $OPTIONS -i -a api/DspFaust.cpp "$FILE" -o "app/src/main/cpp/DspFaust.cpp"
exit 1
fi
# Create the temporary directory where compilation will take place
APPNAME=$(basename "$FILE")
APPNAME="${APPNAME%.dsp}"
BUILDDIR="faustandro.$APPNAME"
APPFOLDER="$BUILDDIR/app/src/main"
JNIFOLDER="$APPFOLDER/cpp"
if [ $REUSE -eq 0 ]; then
if [ -d "$BUILDDIR" ]; then
echo "Delete existing Android project $BUILDDIR" > $LOG
rm -rf "$BUILDDIR"
fi
fi
if [ ! -d "$BUILDDIR" ]; then
echo "Creating new Android project $BUILDDIR" > $LOG
mkdir -p "$BUILDDIR"
cp -r $FAUSTLIB/android/* "$BUILDDIR"
install -d $JNIFOLDER
# Copy include files *.h if any (ignore any error here)
(cp *.h $JNIFOLDER 2> $LOG) || true
# change 'faust' with real *APPNAME
PLATFORM=$(uname)
if [ $PLATFORM = "Darwin" ]; then
sed -i '' 's,com.faust,com.'$APPNAME',g' $BUILDDIR/app/build.gradle
if [ "$NOAGC" = "1" ]; then
sed -i '' 's,-DDISABLE_AGC,'-DDISABLE_AGC',g' $BUILDDIR/app/build.gradle
else
sed -i '' 's,-DDISABLE_AGC,'',g' $BUILDDIR/app/build.gradle
fi
sed -i '' 's,com.faust,com.'$APPNAME',g' $APPFOLDER/java/com/faust/*
sed -i '' 's,com.faust,com.'$APPNAME',g' $APPFOLDER/java/com/triggertrap/seekarc/*
sed -i '' 's,com.faust,com.'$APPNAME',g' $APPFOLDER/AndroidManifest.xml
sed -i '' 's,com.faust,com.'$APPNAME',g' $APPFOLDER/res/layout/*
sed -i '' 's,1,'$APPNAME',g' $APPFOLDER/res/values/strings.xml
else
sed -i 's,com.faust,com.'$APPNAME',g' $BUILDDIR/app/build.gradle
if [ "$NOAGC" = "1" ]; then
sed -i 's,-DDISABLE_AGC,'-DDISABLE_AGC',g' $BUILDDIR/app/build.gradle
else
sed -i 's,-DDISABLE_AGC,'',g' $BUILDDIR/app/build.gradle
fi
sed -i 's,com.faust,com.'$APPNAME',g' $APPFOLDER/java/com/faust/*
sed -i 's,com.faust,com.'$APPNAME',g' $APPFOLDER/java/com/triggertrap/seekarc/*
sed -i 's,com.faust,com.'$APPNAME',g' $APPFOLDER/AndroidManifest.xml
sed -i 's,com.faust,com.'$APPNAME',g' $APPFOLDER/res/layout/*
sed -i 's,1,'$APPNAME',g' $APPFOLDER/res/values/strings.xml
fi
mv $APPFOLDER/java/com/faust $APPFOLDER/java/com/$APPNAME
# TODO wrong: should be checked
if [ $SWIG -eq 1 ]; then
rm -rf $APPFOLDER/java/com/dsp_faust || true
mkdir -p $APPFOLDER/java/com/dsp_faust
swig -java -package com.dsp_faust -includeall -verbose -outdir $APPFOLDER/java/com/dsp_faust -c++ -I$FAUSTINC -I/System/Library/Frameworks/JavaVM.framework/Headers -I$JNIFOLDER -o $JNIFOLDER/java_interface_wrap.cpp $BUILDDIR/dsp_faust_interface.i
fi
else
echo "Reusing existing Android project $BUILDDIR" > $LOG
fi
# Copying the Faust API files in the project
cp $FAUSTLIB/api/DspFaust.h $JNIFOLDER
cp $FAUSTLIB/api/android/jni/java_interface_wrap.cpp $JNIFOLDER
mkdir $APPFOLDER/java/com/DspFaust
cp $FAUSTLIB/api/android/jni/*.java $APPFOLDER/java/com/DspFaust
# Compile the Faust code for the NDK
faust $OPTIONS -i -json -a api/DspFaust.cpp "$FILE" -o "$JNIFOLDER/DspFaust.cpp" || exit
# Add soundfile support if needed
if [ $SOUNDFILE -eq 1 ]; then
cat $APPNAME.dsp.json | awk '
BEGIN { FS=":"; SOFI=0; }
/"soundfile"/ { SOFI=1; }
/"url"/ {
if (SOFI) {
match($2, /"[^"]*/);
split(substr($2, RSTART+2, RLENGTH-3), res, ";");
for (x in res) print substr(res[x], 2, length(res[x])-2);
SOFI=0;
}
}
' > $APPNAME-tmp.txt
for snd in $(cat $APPNAME-tmp.txt); do
if [ -f $snd ]; then
if [ ${snd:0:1} = "/" ]; then
echo "Warning: soundfile with absolute path is not copied !"
else
#create destination path and possibly create directory
sfpath="$APPFOLDER/assets"
if ! [ -d $sfpath ]; then
echo "Create $sfpath"
mkdir $sfpath
fi
echo "Copy $snd in apk"
cp $snd $sfpath
fi
else
echo "Error: file $snd not found !"
fi
done
if [ $PLATFORM = "Darwin" ]; then
sed -i '' 's,__CURRENT_ANDROID_PACKAGE__,com.'$APPNAME',g' $APPFOLDER/cpp/DspFaust.cpp
else
sed -i 's,__CURRENT_ANDROID_PACKAGE__,com.'$APPNAME',g' $APPFOLDER/cpp/DspFaust.cpp
fi
mv $BUILDDIR/app/CMakeLists_sndfile.txt $BUILDDIR/app/CMakeLists.txt
rm $APPNAME-tmp.txt
else
rm $BUILDDIR/app/CMakeLists_sndfile.txt
rm -r $BUILDDIR/app/lib # that's soooo dirty but that will do for now...
fi
rm $APPNAME.dsp.json
# Run Gradle
cd $BUILDDIR
chmod a+x ./gradlew
$FAUSTGRADLE assembleRelease > $LOG
cd ..
cp -r $BUILDDIR/app/build/outputs/apk/release/app-release.apk $APPNAME.apk
# ****************
# TREAT OPTIONS
# ****************
if [ $INSTALL -eq 1 ]; then
adb install -r $APPNAME.apk
fi
if [ $SOURCE -eq 1 ]; then
rm -rf faustApp
mv $BUILDDIR faustApp
echo "An Android studio project named faustApp was created." > $LOG
else
if [ $REUSE -eq 0 ]; then
echo "Delete Android project $BUILDDIR" > $LOG
rm -rf $BUILDDIR
fi
fi
echo "$APPNAME.apk;"
|