Debian Codegraph @

tools/faust2appls/faust2vcvrack

raw symbols SCIP
1 #!/bin/bash -e
2
3 #####################################################################
4 # #
5 # faust2vcvrack generator #
6 # (c) Grame, 2020-2022 #
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/vcvrack/template/src/FaustModule.cpp
17
18 # exit if a command fails
19 set -e
20
21 # global option variables
22 NVOICES=1
23 POLY=""
24 SOURCE=false
25 SOUNDFILE=false
26 VERSION="2.0.0"
27
28 echoHelp()
29 {
30 echo "faust2vcvrack [-soundfile] [-source] [-nvoices <num>] [Faust options] <file.dsp>"
31 echo "Compiles Faust programs to VCV Rack modules (see https://github.com/grame-cncm/faust/tree/master-dev/architecture/vcvrack)"
32 options -soundfile
33 option "-source"
34 option "-nvoices <num>"
35 option "-version <1|2>" "to set the plugin version, 2 by default"
36 option "Faust options"
37 echo ""
38 exit
39 }
40
41 if [ "$#" -eq 0 ]; then
42 echo 'Please, provide a Faust file to process !'
43 echo ''
44 echoHelp
45 fi
46
47 ###########################
48 # Processing Arguments
49 ###########################
50
51 while [ $1 ]
52 do
53 p=$1
54 # help
55 if [ $p = "-help" ] || [ $p = "-h" ]; then
56 echoHelp
57 # -nvoices:
58 elif [ $p = "-nvoices" ]; then
59 shift
60 NVOICES=$1
61 elif [ $p = "-soundfile" ]; then
62 SOUNDFILE=true
63 elif [ $p = "-source" ]; then
64 SOURCE=true
65 elif [ $p = "-version" ]; then
66 shift
67 VERSION=$1.0.0
68 elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
69 FILE="$p"
70 # other compile options
71 else
72 OPTIONS="$OPTIONS $p"
73 fi
74
75 shift
76
77 done
78
79 createPluginJSON()
80 {
81 (
82 echo '{'
83 echo -e "\t\"slug\": \"$1\","
84 echo -e "\t\"name\": \"$1\","
85 echo -e "\t\"version\": \"$VERSION\","
86 echo -e '\t"license": "MIT",'
87 echo -e '\t"brand": "Faust",'
88 echo -e '\t"author": "GRAME",'
89 echo -e '\t"authorEmail": "[email protected]",'
90 echo -e '\t"authorUrl": "https://faust.grame.fr",'
91 echo -e '\t"pluginUrl": "",'
92 echo -e '\t"manualUrl": "",'
93 echo -e '\t"sourceUrl": "https://github.com/grame-cncm/faust",'
94 echo -e '\t"donateUrl": "",'
95 echo -e '\t"changelogUrl": "",'
96 echo -e '\t"modules": ['
97 echo -e '\t\t{'
98 echo -e "\t\t\t\"slug\": \"$1\","
99 echo -e "\t\t\t\"name\": \"$1\","
100 echo -e '\t\t\t"description": "",'
101 echo -e '\t\t\t"tags": ['
102 if [ $NVOICES -gt 1 ]; then
103 echo -e '\t\t\t\t"Polyphonic"'
104 fi
105 echo -e '\t\t\t]'
106 echo -e '\t\t}'
107 echo -e '\t]'
108 echo '}'
109 ) > "$2"
110 }
111
112 ###########################
113 # Compile the *.dsp files
114 ###########################
115
116 for p in $FILE; do
117 CUR=$(pwd)
118 f=$(basename "$p")
119 SRCDIR=$(dirname "$p")
120
121 # creates the dir
122 dspName="${f%.dsp}"
123 rm -rf "$SRCDIR/$dspName"
124 mkdir "$SRCDIR/$dspName"
125
126 # compile faust to c++
127 cp -r $FAUSTARCH/vcvrack/template/* "$SRCDIR/$dspName/"
128 faust -json -os -cn $dspName -scn rack_dsp -i -a $ARCHFILE $OPTIONS $f -o "$SRCDIR/$dspName/src/FaustModule.cpp" || exit
129
130 # add NVOICES flag
131 echo "#define NVOICES $NVOICES" | cat - "$SRCDIR/$dspName/src/FaustModule.cpp" > temp && mv temp "$SRCDIR/$dspName/src/FaustModule.cpp"
132
133 # set DSP name and polyphonic mode in plugin.json
134 createPluginJSON "$dspName" "$SRCDIR/$dspName/plugin.json"
135
136 # soundfiles handling
137 if [ $SOUNDFILE = true ]; then
138 # needed for SoundUI.h to compile
139 echo "#define __VCVRACK__" | cat - "$SRCDIR/$dspName/src/FaustModule.cpp" > temp && mv temp "$SRCDIR/$dspName/src/FaustModule.cpp"
140 echo "#define SOUNDFILE" | cat - "$SRCDIR/$dspName/src/FaustModule.cpp" > temp && mv temp "$SRCDIR/$dspName/src/FaustModule.cpp"
141
142 echo $p.json
143 # get all soundfiles from the JSON file
144 cat $p.json | awk '
145 BEGIN { FS=":"; SOFI=0; }
146 /"soundfile"/ { SOFI=1; }
147 /"url"/ {
148 if (SOFI) {
149 match($2, /"[^"]*/);
150 split(substr($2, RSTART+2, RLENGTH-3), res, ";");
151 for (x in res) print substr(res[x], 2, length(res[x])-2);
152 SOFI=0;
153 }
154 }
155 ' > $p-tmp.txt
156 # copy found soundfiles in the final binary
157 for snd in $(cat $p-tmp.txt); do
158 if [ -f $snd ]; then
159 if [ ${snd:0:1} = "/" ]; then
160 echo "Warning: soundfile with absolute path is not copied !"
161 else
162 # create destination path and possibly create directory
163 sfpath="$SRCDIR/$dspName/res/$(dirname $snd)/"
164 if ! [ -d $sfpath ]; then
165 echo "Create $sfpath"
166 mkdir -p $sfpath
167 fi
168 echo "Copy $snd in ${f%.dsp}$EXT"
169 cp $snd $sfpath
170 fi
171 else
172 echo "Error: file $snd not found !"
173 fi
174 done
175 rm $p-tmp.txt
176 fi
177
178 # compile and install plugin or keep the source folder
179 if [ $SOURCE == false ]; then
180 ( cd "$SRCDIR/$dspName" && make && make install ) > /dev/null || exit
181 rm -rf "$SRCDIR/$dspName"
182 else
183 echo "Create the $SRCDIR/$dspName folder"
184 fi
185 done