File: faust2gen

package info (click to toggle)
faust 2.79.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 397,496 kB
  • sloc: cpp: 278,433; ansic: 116,164; javascript: 18,529; vhdl: 14,052; sh: 13,884; java: 5,900; objc: 3,852; python: 3,222; makefile: 2,655; cs: 1,672; lisp: 1,146; ruby: 954; yacc: 586; xml: 471; lex: 247; awk: 110; tcl: 26
file content (105 lines) | stat: -rwxr-xr-x 2,585 bytes parent folder | download | duplicates (2)
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
#! /bin/bash -e

#####################################################################
#                                                                   #
#               Compiles Faust programs to a fausgen~ patch         #
#               (c) Grame, 2015-2025                                #
#                                                                   #
#####################################################################

. faustpath
. faustoptflags
. usage.sh

POLY="MONO"
NVOICES=-1
MC="0"

JSFILE_PATH="ui.js"

echoHelp()
{
    usage faust2gen "[options] <file.dsp>"
    require Max/MSP SDK
    echo "Compiles Faust programs to a fausgen~/mc.faustgen patch"
    option
    option '-nvoices <num>'
    option -mc "to activate multi-channels model"
    exit
}

if [ "$#" -eq 0 ]; then
    echo 'Please, provide a Faust file to process !'
    echo ''
    echoHelp
fi

# dispatch command arguments
while [ $1 ]
do
    p=$1

    if [ $p = "-help" ] || [ $p = "-h" ]; then
       echoHelp
    elif [ $p = "-mc" ]; then
        MC="1"
    elif [[ -f "$p" ]] && [ ${p: -4} == ".dsp" ]; then
        FILES="$FILES $p"
    elif [ $p = "-nvoices" ]; then
        POLY="POLY1"
        shift
        NVOICES=$1
        if [ $NVOICES -ge 0 ]; then
            CXXFLAGS="$CXXFLAGS -DNVOICES=$NVOICES"
        fi
    else
        OPTIONS="$OPTIONS $p"
    fi

shift

done

# look for polyphonic "nvoices" metadata in the DSP file

grep "declare nvoices" $FILES && POLY="POLY1" 2>/dev/null

#-------------------------------------------------------------------
# compile the *.dsp files
#

for p in $FILES; do

    f=$(basename "$p")

    # create Max patch
    if [ $POLY = "POLY1" ]; then
    	if [ $MC = "1" ]; then
        	cat $FAUSTARCH/max-msp/mc-faustgen-wrapper-poly.maxpat > ${f%.dsp}-temp1.maxpat
        else
        	cat $FAUSTARCH/max-msp/faustgen-wrapper-poly.maxpat > ${f%.dsp}-temp1.maxpat
        fi
    else
    	if [ $MC = "1" ]; then
        	cat $FAUSTARCH/max-msp/mc-faustgen-wrapper.maxpat > ${f%.dsp}-temp1.maxpat
        else
        	cat $FAUSTARCH/max-msp/faustgen-wrapper.maxpat > ${f%.dsp}-temp1.maxpat
        fi
    fi
    sed -e "s/DSP_NAME/"${f%.dsp}"/g" ${f%.dsp}-temp1.maxpat >> ${f%.dsp}-temp2.maxpat
    sed -e "s/UI_FILE/"$JSFILE_PATH"/g" ${f%.dsp}-temp2.maxpat > ${f%.dsp}.maxpat

    # collect binary file name for FaustGIDE
    BINARIES="$BINARIES${f%.dsp}.maxpat;"

    # copy JavaScript UI file
    cp $FAUSTARCH/max-msp/ui.js .

    rm ${f%.dsp}-temp1.maxpat
    rm ${f%.dsp}-temp2.maxpat

done

BINARIES="$BINARIES ui.js"

echo $BINARIES