Debian Codegraph @

tools/faust2appls/faust2nodejs

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 #!/bin/bash
2
3 #####################################################################
4 # #
5 # Generates a nodejs native addon from a Faust object #
6 # (c) Romain Michon CCRMA and Grame, 2017 #
7 # #
8 #####################################################################
9
10 . faustpath
11 . faustoptflags
12 . usage.sh
13
14 # exit if a command fails
15 set -e
16
17 # global option variables
18 NVOICES=""
19 MIDI=""
20 SOUNDFILE=""
21 OSC=""
22 EFFECT=""
23 DRIVER=""
24 ELECTRON_VERSION=""
25 SOURCE="0"
26 LOG="/dev/null"
27
28 # compilation flags for the different targets
29 OSC_CFLAGS=""
30 OSC_LIBFLAGS=""
31 JACK_LIBRARIES_FLAGS="\`pkg-config --cflags --libs jack sndfile\`"
32 ALSA_LIBRARIES_FLAGS="\`pkg-config --cflags --libs alsa\` -pthread"
33 COREAUDIO_LIBRARIES_FLAGS="\`pkg-config --cflags --static --libs sndfile\` -framework CoreAudio -framework AudioUnit -framework CoreServices -framework CoreMIDI -framework CoreFoundation"
34 # TODO: missing rtaudio, portaudio, etc.
35
36 # useful variables
37 PLATFORM=$(uname)
38
39 echoHelp ()
40 {
41 usage faust2nodejs "[driver] [Faust options] <file.dsp>"
42 echo "Generate Faust-based nodejs native addons. The generated addons can embed most of the audio engines supported by Faust: ALSA, JACK, CoreAudio, RtAudio, PortAudio, etc. Since faust2nodejs essentially acts as a wrapper to faust2api, it offers the same features than this system (MIDI and OSC support, polyphony, separate effect file, etc.)."
43 echo
44 echo "The following drivers are available: -coreaudio // -alsa // -jack // -portaudio // -rtaudio // -dummy. For example, to create a native nodejs addon with a JACK audio engine, run: faust2nodjs -jack faustFile.dsp"
45 echo
46 echo "The following options are inherited directly from faust2api and can be used with faust2nodejs:"
47 option
48 options -osc -midi -soundfile
49 option "-nvoices <num>"
50 option "-effect <effect.dsp>"
51 option -source "generates the source of the addon without compiling it"
•52 option "-electronv <VERSION>" "allows you to specify the current version of electron if generating an addon for this framework"
53 option -debug "prints compilation output"
54 option "Faust options"
55 exit
56 }
57
58 if [ "$#" -eq 0 ]; then
59 echo 'Please, provide a Faust file to process !'
60 echo ''
61 echoHelp
62 fi
63
64 # dispatch command arguments
65 while [ $1 ]
66 do
67 p=$1
68 if [ $p = "-help" ] || [ $p = "-h" ]; then
69 echoHelp
70 elif [[ -f "$p" ]]; then
71 FILE="$p"
72 elif [ $p = "-coreaudio" ] || [ $p = "-alsa" ] || [ $p = "-jack" ] || [ $p = "-portaudio" ] || [ $p = "-rtaudio" ] || [ $p = "-dummy" ] ; then
73 DRIVER=$p
74 elif [ "$p" = "-effect" ]; then
75 shift
76 EFFECT="-effect "$1
77 elif [ "$p" = "-midi" ]; then
78 MIDI="-midi"
79 elif [ "$p" = "-soundfile" ]; then
80 SOUNDFILE="-soundfile"
81 elif [ "$p" = "-osc" ]; then
82 OSC="-osc"
83 OSC_CFLAGS="-DOSCCTR"
84 OSC_LIBFLAGS="-lOSCFaust -pthread"
85 elif [ "$p" = "-debug" ]; then
86 LOG="/dev/stdout"
87 elif [ "$p" = "-source" ]; then
88 SOURCE="1"
89 elif [ $p = "-nvoices" ]; then
90 shift
91 NVOICES="-nvoices "$1
92 elif [ $p = "-electronv" ]; then
93 shift
94 ELECTRON_VERSION="--target="$1" --dist-url=https://atom.io/download/electron"
95 elif [ ${p:0:1} = "-" ]; then
96 OPTIONS="$OPTIONS $p"
97 elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
98 FILES="$FILES $p"
99 else
100 OPTIONS="$OPTIONS $p"
101 fi
102 shift
103 done
104
105 NODE_NAME="${FILE%.dsp}"
106 NODE_FOLDER=$NODE_NAME"-faustnode"
107
108 # Creating project folder
109 mkdir $NODE_FOLDER
110
111 # Generating DSP engine
112 cd $NODE_FOLDER
113 faust2api $DRIVER -nodoc -nozip $MIDI $SOUNDFILE $OSC $NVOICES $EFFECT $OPTIONS "../"$FILE &> $LOG || exit 1
114
115 # Copying template files
116 cp "$FAUSTARCH/nodejs/binding.gyp" .
117 cp "$FAUSTARCH/nodejs/DspFaustNode.cpp" .
118 cp "$FAUSTARCH/nodejs/DspFaustNode.h" .
119 cp "$FAUSTARCH/nodejs/faust.cpp" .
120 cp "$FAUSTARCH/nodejs/README.md" .
121
122 # Customizing configuration file
123 # TODO: for now only ported compilation flags for alsa and JACK: missing
124 # portaudio, rtaudio, and coreaudio
125 if [ "$DRIVER" = "-jack" ]; then
126 if [ $PLATFORM = "Darwin" ]; then
127 sed -i "" "s/__CFLAGS__/$MYGCCFLAGS $FAUSTTOOLSFLAGS $OMP $OSC_CFLAGS/g" binding.gyp
128 sed -i "" "s/__LIBFLAGS__/$JACK_LIBRARIES_FLAGS $OSC_LIBFLAGS/g" binding.gyp
129 else
130 sed -i "s/__CFLAGS__/$MYGCCFLAGS $FAUSTTOOLSFLAGS $OMP $OSC_CFLAGS/g" binding.gyp
131 sed -i "s/__LIBFLAGS__/$JACK_LIBRARIES_FLAGS $OSC_LIBFLAGS/g" binding.gyp
132 fi
133 elif [ "$DRIVER" = "-alsa" ]; then
134 sed -i "s/__CFLAGS__/$MYGCCFLAGS $FAUSTTOOLSFLAGS $OMP $OSC_CFLAGS/g" binding.gyp
135 sed -i "s/__LIBFLAGS__/$JACK_LIBRARIES_FLAGS $OSC_LIBFLAGS/g" binding.gyp
136 elif [ "$DRIVER" = "-coreaudio" ]; then
137 sed -i "" "s/__CFLAGS__/$MYGCCFLAGS $FAUSTTOOLSFLAGS $OMP $OSC_CFLAGS/g" binding.gyp
138 sed -i "" "s/__LIBFLAGS__/$COREAUDIO_LIBRARIES_FLAGS $OSC_LIBFLAGS/g" binding.gyp
139 fi
140
141 node-gyp $ELECTRON_VERSION configure &> $LOG || exit 1
142
143 if [ $SOURCE = "0" ]; then
144 cd build
145 make &> $LOG || exit 1
146 cd ../..
147 cp $NODE_FOLDER/build/Release/faust.node $NODE_NAME.node
148 rm -rf $NODE_FOLDER
149 echo "A native nodejs node \"$NODE_NAME.node\" was generated in the current folder."
150 else
151 echo "A $NODE_FOLDER folder containing the source of the native Faust node was generated in the current folder. Please refer to the README in it for compilation instructions."
152 fi