File: faust2smartkeyb

package info (click to toggle)
faust 2.14.4~repack2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 276,136 kB
  • sloc: cpp: 231,578; ansic: 15,403; sh: 10,871; java: 6,917; objc: 4,085; makefile: 3,002; cs: 1,077; ruby: 951; python: 885; xml: 550; yacc: 516; lex: 233; lisp: 201
file content (282 lines) | stat: -rwxr-xr-x 8,660 bytes parent folder | download
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/bash

#####################################################################
#                                                                   #
#          SmartKeyboard App Generator for iOS and Android          #
#               (c) Romain Michon CCRMA and Grame, 2016             #
#                                                                   #
#####################################################################

. faustpath

# 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 option variables
ANDROID="0"
IOS="0"
NVOICES="12"
POLY2="0"
MIDI="0"
OSC=""
EFFECT=""
SOURCE=0
REUSE=0
INSTALL=0

echoHelp ()
{
	echo "FAUST2SMARTKEYB - MUSICAL MOBILE APP GENERATOR"
	echo ""
	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):"
	echo ""
	echo "faust2smartkeyb -ios mySynth.dsp"
	echo "or"
	echo "faust2smartkeyb -android mySynth.dsp"
	echo ""
	echo "OPTIONS:"
	echo ""
	echo "-android: generate an Android app"
	echo "-ios: generate an iOS app"
	echo "-debug: activate debug mode"
	echo "-effect: allow to specify an effect Faust file (e.g., -effect myEffect.dsp)"
	echo "-help: dispay this help page"
	echo "-install: install the app on the connected device (Android only)"
	echo "-nvoices: specify the max number of voices"
	echo "-reuse: reuse the same project source"
	echo "-source: only generate the source (no compilation)"
	echo "-osc: adds OSC support to the app"
	echo ""
	echo "More information and tutorials at: https://ccrma.stanford.edu/~rmichon/smartKeyboard"
}

###########################
# Processing Arguments
###########################

while [ $1 ]
do
	p=$1

    if [ $p = "-help" ]; then
		echoHelp
		exit 0
    elif [[ -f "$p" ]]; then
		FILE="$p"
    elif [ $p = "-android" ]; then
		ANDROID=1
    elif [ $p = "-ios" ]; then
		IOS="1"
	elif [ $p = "-reuse" ]; then
		REUSE=1
	elif [ $p = "-source" ]; then
		SOURCE=1
	elif [ $p = "-debug" ]; then
		LOG="/dev/stdout"
	elif [ $p = "-install" ]; then
		INSTALL=1
	elif [ $p = "-osc" ]; then
		OSC="-osc"
    elif [ "$p" = "-effect" ]; then
        POLY2="1"
		shift
		if [[ -f "$1" ]]; then
			EFFECT=$1
		elif [ $1 = "auto" ]; then
			EFFECT=$1
		else
			echo "No file specified after -effect"
			echoHelp
			exit 1
		fi
    elif [ $p = "-nvoices" ]; then
		shift
		NVOICES=$1
    elif [ ${p:0:1} = "-" ]; then
        OPTIONS="$OPTIONS $p"
    elif [[ -f "$p" ]]; then
        FILES="$FILES $p"
    else
        OPTIONS="$OPTIONS $p"
    fi

shift

done

# Options post processing
#if [ -z "$OSC" ]; then
#	echo "No osc"
#	OSC=""
#fi

if [ -z $FILE ]; then
    echo "Please, provide a Faust file to process"
    exit 1
fi

###################################
# Configuring
###################################

APPNAME=$(basename "$FILE")
APPNAME="${APPNAME%.dsp}"
BUILDDIR="faustsmartkeyb.$APPNAME"

# making sure that platform is set and generate corresponding global vars
if [ $ANDROID -eq 1 ]; then
	APPFOLDER="$BUILDDIR/app/src/main"
elif [ $IOS -eq 1 ]; then
	APPFOLDER="$BUILDDIR/Faust"
else
	echo "Please, specify a platform: -android or -ios"
	echoHelp
	exit 1
fi

###############################
# Creating Default Project
###############################
PLATFORM=$(uname)

if [ $REUSE -eq 0 ] || [ ! -d "$BUILDDIR" ]; then
	if [ -d "$BUILDDIR" ]; then # if BUILDIR exists, then delete it
		echo "Delete existing app project $BUILDDIR" > $LOG
		rm -rf "$BUILDDIR"
	fi

	# copying new template app if no reuse
	if [ ! -d "$BUILDDIR" ]; then
		mkdir -p "$BUILDDIR"
		cp -r $FAUSTLIB/smartKeyboard/LICENCE.md "$BUILDDIR"
		if [ $ANDROID -eq 1 ]; then
			echo "Creating a new Android project in $BUILDDIR" > $LOG
			cp -r $FAUSTLIB/smartKeyboard/android/* "$BUILDDIR"

			# change 'faust' with real *APPNAME

			if [ $PLATFORM = "Darwin" ]; then
				sed -i '' 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $BUILDDIR/app/build.gradle
				sed -i '' 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/java/com/ccrma/faust/*
				sed -i '' 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/AndroidManifest.xml
				sed -i '' 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/res/layout/activity_main.xml
				sed -i '' 's,Faust,'$APPNAME',g' $APPFOLDER/res/values/strings.xml
				if [[ $OSC == "-osc" ]]; then
					sed -i '' 's,OSCCTRL=false,OSCCTRL=true,g' $BUILDDIR/app/build.gradle
					sed -i '' 's,set(OSCCTRL\ false),set(OSCCTRL\ true),g' $BUILDDIR/app/CMakeLists.txt
				fi
			else
				sed -i 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $BUILDDIR/app/build.gradle
				sed -i 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/java/com/ccrma/faust/*
				sed -i 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/AndroidManifest.xml
				sed -i 's,com.ccrma.faust,com.ccrma.'$APPNAME',g' $APPFOLDER/res/layout/activity_main.xml
				sed -i 's,Faust,'$APPNAME',g' $APPFOLDER/res/values/strings.xml
				if [[ $OSC == "-osc" ]]; then
					sed -i 's,OSCCTRL=false,OSCCTRL=true,g' $BUILDDIR/app/build.gradle
					sed -i 's,set(OSCCTRL\ false),set(OSCCTRL\ true),g' $BUILDDIR/app/CMakeLists.txt
				fi
			fi
			mv $APPFOLDER/java/com/ccrma/faust $APPFOLDER/java/com/ccrma/$APPNAME
		elif [ $IOS -eq 1 ]; then
			echo "Creating a new iOS project in $BUILDDIR" > $LOG
			cp -r $FAUSTLIB/smartKeyboard/iOS/* "$BUILDDIR"
			if [ $PLATFORM = "Darwin" ]; then
				sed -i '' 's,$(TARGET_NAME),'$APPNAME',g' $BUILDDIR/Faust.xcodeproj/project.pbxproj
				sed -i '' 's,ccrma.Faust,ccrma.'$APPNAME',g' $BUILDDIR/Faust.xcodeproj/project.pbxproj
			else
				sed -i 's,$(TARGET_NAME),'$APPNAME',g' $BUILDDIR/Faust.xcodeproj/project.pbxproj
				sed -i 's,ccrma.Faust,ccrma.'$APPNAME',g' $BUILDDIR/Faust.xcodeproj/project.pbxproj
			fi
            # Put OSC in project in all cases, even if not compiled
            # cp -r $FAUSTLIB/osclib "$BUILDDIR"/Faust
        fi
	fi
fi

###########################
# Adding DSP
###########################

if [ $ANDROID -eq 1 ]; then
	if [ -z "$EFFECT" ]; then # no effect
		echo "Adding DSP with no effect chain to the app" > $LOG
		faust2api -android $OSC -nvoices "$NVOICES" -nodoc $OPTIONS "$FILE" > $LOG
	else
		echo "Adding DSP with effect chain to the app" > $LOG
		faust2api -android $OSC -nvoices "$NVOICES" -effect "$EFFECT" -nodoc $OPTIONS "$FILE" > $LOG
	fi
	unzip "dsp-faust.zip" > $LOG
	mv "dsp-faust" "$BUILDDIR"
	rm "dsp-faust.zip"
	cp -r "$BUILDDIR/dsp-faust/cpp" "$APPFOLDER"
	cp $BUILDDIR/dsp-faust/java/* "$APPFOLDER/java/com/DspFaust"
	rm -r "$BUILDDIR/dsp-faust"
elif [ $IOS -eq 1 ]; then
	if [ -z "$EFFECT" ]; then # no effect
		echo "Adding DSP with no effect chain to the app" > $LOG
		faust2api -ios $OSC -midi -nvoices "$NVOICES" -nodoc $OPTIONS "$FILE" > $LOG
	else
		echo "Adding DSP with effect chain to the app" > $LOG
		faust2api -ios $OSC -midi -nvoices "$NVOICES" -effect "$EFFECT" -nodoc $OPTIONS "$FILE" > $LOG
	fi
	unzip "dsp-faust.zip" > $LOG
	mv "dsp-faust" "$BUILDDIR"
	rm "dsp-faust.zip"
	cp $BUILDDIR/dsp-faust/* "$APPFOLDER"
	rm -r "$BUILDDIR/dsp-faust"
fi

###########################
# Compilation
###########################

if [ $SOURCE -eq 0 ]; then
	if [ $ANDROID -eq 1 ]; then
		echo "Starting Android compilation" > $LOG
		cd $BUILDDIR
		chmod a+x ./gradlew
		$FAUSTGRADLE assembleRelease > $LOG
		cd ..
		cp -r $BUILDDIR/app/build/outputs/apk/release/app-release.apk $APPNAME.apk > $LOG
		echo "An Android app \"$APPNAME.apk\" was created in the current folder"
	elif [ $IOS -eq 1 ]; then
		echo "Starting iOS compilation" > $LOG
		(
			xcodebuild -project "$BUILDDIR/Faust.xcodeproj" -target Faust PRODUCT_NAME=$APPNAME
			cd "$BUILDDIR" && xcodebuild -scheme Faust PRODUCT_NAME=$APPNAME
		)  > $LOG || exit 1
		rm -rf "$APPNAME.app"
    	mv "$BUILDDIR/build/Release-iphoneos/$APPNAME.app" .
		echo "An iOS app \"$APPNAME.app\" was created in the current folder"
	fi
fi

###########################
# Installation
###########################

if [ $INSTALL -eq 1 ]; then
	if [ $ANDROID -eq 1 ]; then
		echo "Installing the app" > $LOG
		adb install -r $APPNAME.apk
	elif [ $ANDROID -eq 1 ]; then
		echo "Automatic installation is only possible on Android"
	fi
fi

###########################
# Cleaning
###########################

if [ $REUSE -eq 0 ] && [ $SOURCE -eq 0 ]; then
	echo "Delete app project $BUILDDIR" > $LOG
	rm -rf $BUILDDIR
else
	echo "An app project $BUILDDIR was created or updated in the current directory"
fi