2 ======================================
3 faust2pd: Pd Patch Generator for Faust
4 ======================================
6 Version 2.5, October 20, 2011
8 Albert Graef <Dr.Graef@t-online.de>
10 This package contains software which makes it easier to use Faust DSPs with Pd
11 and the Pure programming language. The main component is the faust2pd script
12 which creates GUI wrappers for Faust DSPs. The package also includes a bunch
13 of examples. The software is distributed under the GPL; see the COPYING file
16 .. note:: This faust2pd version is written in Pure and was ported from an
17 earlier version written in Pure's predecessor Q. The version of the script
18 provided here should be 100% backward-compatible to those previous
19 versions, except for the following changes:
21 - The (rarely used) -f (a.k.a. --fake-buttons) option was renamed to -b.
23 - A new -f (a.k.a. --font-size) option was added to change the font size
26 - Most command line options can now also be specified using special
27 ``[pd:...]`` tags in the Faust source.
29 Also note that you can now run the script on 64 bit systems (Q never worked
32 As of version 2.1, the faust2pd script is now compiled to a native executable
33 before installation. This makes the program start up much faster, which is a
34 big advantage because most xml files don't take long to be processed.
36 .. _Pure: http://pure-lang.googlecode.com
44 Copyright (c) 2009-2011 by Albert Graef.
46 faust2pd is free software: you can redistribute it and/or modify it under the
47 terms of the GNU General Public License as published by the Free Software
48 Foundation, either version 3 of the License, or (at your option) any later
51 faust2pd is distributed in the hope that it will be useful, but WITHOUT ANY
52 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
53 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
55 You should have received a copy of the GNU General Public License along with
56 this program. If not, see <http://www.gnu.org/licenses/>.
61 faust2pd is known to work on Linux, Mac OS X, and Windows, and there shouldn't
62 be any major roadblocks preventing it to work on other systems supported by
65 The faust2pd script is written in the Pure_ programming language and requires
66 Pure's XML module, so you need to install these to make it work. Install the
67 latest pure*.tar.gz and pure-xml*.tar.gz packages and you should be set. (Pure
68 0.47 or later is required.) Also make sure that the LLVM base package is
69 installed, as described in the Pure INSTALL file, some LLVM utilities are
70 needed to make Pure's batch compiler work.
72 To run the seqdemo example, you'll also need the Pd Pure external
73 (pd-pure*.tar.gz), also available at the Pure_ website.
75 To compile the examples, you'll need GNU C++ and make, Pd_ and, of course,
76 Faust_. Make sure you get a recent version of Faust; Faust releases >0.9.8
77 include the puredata architecture necessary to create Pd externals from Faust
80 .. _Pd: http://puredata.info
81 .. _Faust: http://faudiostream.sf.net
86 Get the latest source from
87 http://pure-lang.googlecode.com/files/faust2pd-2.5.tar.gz.
89 Run ``make`` and ``make install`` to compile and install the faust2pd program
90 on your system. You can set the installation prefix by running make as ``make
91 install prefix=/some/path``. Default installation prefix is /usr/local,
92 faust2pd is installed in the bin directory below that.
94 Optionally, you can also run ``make install-pd`` to copy the supporting Pd
95 abstractions (faust-\*.pd) to your lib/pd/extra directory, so that you can use
96 the patches generated by faust2pd without copying these abstractions to your
97 working directory. The Makefile tries to guess the prefix of your Pd
98 installation, if it guesses wrong, you can specify the prefix explicitly by
99 running make as ``make install-pd pdprefix=/some/path``.
101 The included faustxml.pure script provides access to Faust-generated dsp
102 descriptions in xml files to Pure scripts. This module is described in its own
103 appendix__ below. It may have uses beyond faust2pd, but isn't normally
104 installed. If you want to use this module, you can just copy it to your Pure
107 __ `Appendix: faustxml`_
112 Run ``make examples`` to compile the Faust examples included in this package
113 to corresponding Pd plugins. After that you should be able to run the patches
114 in the various subdirectories of the examples directory. Everything is set up
115 so that you can try the examples "in-place", without installing anything
116 except the required software as noted in Requirements_ above. You can also run
117 ``make realclean`` before ``make`` to regenerate everything from scratch (this
118 requires faust2pd, so this will only work if you already installed the Pure
121 Faust Pd plugins work in much the same way as the well-known plugin~ object
122 (which interfaces to LADSPA plugins), except that each Faust DSP is compiled
123 to its own Pd external. Under Linux, the basic compilation process is as
124 follows (taking the freeverb module from the Faust distribution as an
129 # compile the Faust source to a C++ module using the "puredata" architecture
130 faust -a puredata.cpp freeverb.dsp -o freeverb.cpp
131 # compile the C++ module to a Pd plugin
132 g++ -shared -Dmydsp=freeverb freeverb.cpp -o freeverb~.pd_linux
134 By these means, a Faust DSP named ``xyz`` with n audio inputs and m audio
135 outputs becomes a Pd object ``xyz~`` with n+1 inlets and m+1 outlets. The
136 leftmost inlet/outlet pair is for control messages only. This allows you to
137 inspect and change the controls the unit provides, as detailed below. The
138 remaining inlets and outlets are the audio inputs and outputs of the unit,
139 respectively. For instance, ``freeverb.dsp`` becomes the Pd object
140 ``freeverb~`` which, in addition to the control inlet/outlet pair, has 2 audio
143 When creating a Faust object it is also possible to specify, as optional
144 creation parameters, an extra unit name (this is explained in the following
145 section) and a sample rate. If no sample rate is specified explicitly, it
146 defaults to the sample rate at which Pd is executing. (Usually it is not
147 necessary or even desirable to override the default choice, but this might
148 occasionally be useful for debugging purposes.)
150 As already mentioned, the main ingredient of this package is a Pure script
151 named "faust2pd" which allows you to create Pd abstractions as "wrappers"
152 around Faust units. The wrappers generated by faust2pd can be used in Pd
153 patches just like any other Pd objects. They are much easier to operate than
154 the "naked" Faust plugins themselves, as they also provide "graph-on-parent"
155 GUI elements to inspect and change the control values.
157 The process to compile a plugin and build a wrapper patch is very similar to
158 what we've seen above. You only have to add the -xml option when invoking the
159 Faust compiler and run faust2pd on the resulting XML file:
163 # compile the Faust source and generate the xml file
164 faust -a puredata.cpp -xml freeverb.dsp -o freeverb.cpp
165 # compile the C++ module to a Pd plugin
166 g++ -shared -Dmydsp=freeverb freeverb.cpp -o freeverb~.pd_linux
167 # generate the Pd patch from the xml file
168 faust2pd freeverb.dsp.xml
170 Please see `Wrapping DSPs with faust2pd`_ below for further details.
172 Note that, just as with other Pd externals and abstractions, the compiled
173 .pd_linux modules and wrapper patches must be put somewhere where Pd can find
174 them. To these ends you can either move the files into the directory with the
175 patches that use the plugin, or you can put them into the lib/pd/extra
176 directory or some other directory on Pd's library path for system-wide use.
178 Also, faust2pd-generated wrappers use a number of supporting abstractions (the
179 faust-\*.pd files in the faust2pd sources), so you have to put these into the
180 directory of the main patch or install them under lib/pd/extra as well. (The
181 ``make pd-install`` step does the latter, see Installation_ above.)
186 The control inlet of a Faust plugin understands messages in one of the
189 - ``bang``, which reports all available controls of the unit on the control
190 outlet, in the form: ``type name val init min max step``, where ``type`` is
191 the type of the control as specified in the Faust source (``checkbox``,
192 ``nentry``, etc.), ``name`` its (fully qualified) name, ``val`` the current
193 value, and ``init``, ``min``, ``max``, ``step`` the initial value, minimum,
194 maximum and stepsize of the control, respectively.
196 - ``foo 0.99``, which sets the control ``foo`` to the value 0.99, and outputs
199 - Just ``foo``, which outputs the (fully qualified) name and current value of
200 the ``foo`` control on the control outlet.
202 Control names can be specified in their fully qualified form, like e.g.
203 ``/gnu/bar/foo`` which indicates the control ``foo`` in the subgroup ``bar``
204 of the topmost group ``gnu``, following the hierarchical group layout defined
205 in the Faust source. This lets you distinguish between different controls with
206 the same name which are located in different groups. To find out about all the
207 controls of a unit and their fully qualified names, you can bang the control
208 inlet of the unit as described above, and connect its control outlet to a
209 ``print`` object, which will cause the descriptions of all controls to be
210 printed in Pd's main window. (The same information can also be used, e.g., to
211 initialize GUI elements with the proper values. Patches generated with
212 faust2pd rely on this.)
214 You can also specify just a part of the control path (like ``bar/foo`` or just
215 ``foo`` in the example above) which means that the message applies to *all*
216 controls which have the given pathname as the final portion of their fully
217 qualified name. Thus, if there is more than one ``foo`` control in different
218 groups of the Faust unit then sending the message ``foo`` to the control inlet
219 will report the fully qualified name and value for each of them. Likewise,
220 sending ``foo 0.99`` will set the value of all controls named ``foo`` at once.
222 Concerning the naming of Faust controls in Pd you should also note the
225 - A unit name can be specified at object creation time, in which case the
226 given symbol is used as a prefix for all control names of the unit. E.g.,
227 the control ``/gnu/bar/foo`` of an object ``baz~`` created with ``baz~
228 baz1`` has the fully qualified name ``/baz1/gnu/bar/foo``. This lets you
229 distinguish different instances of an object such as, e.g., different voices
230 of a polyphonic synth unit.
232 - Pd's input syntax for symbols is rather restrictive. Therefore group and
233 control names in the Faust source are mangled into a form which only
234 contains alphanumeric characters and hyphens, so that the control names are
235 always legal Pd symbols. For instance, a Faust control name like ``meter #1
236 (dB)`` will become ``meter-1-dB`` which can be input directly as a symbol in
237 Pd without any problems.
239 - "Anonymous" groups and controls (groups and controls which have empty labels
240 in the Faust source) are omitted from the path specification. E.g., if
241 ``foo`` is a control located in a main group with an empty name then the
242 fully qualified name of the control is just ``/foo`` rather than ``//foo``.
243 Likewise, an anonymous control in the group ``/foo/bar`` is named just
244 ``/foo/bar`` instead of ``/foo/bar/``.
246 Last but not least, there is also a special control named ``active`` which is
247 generated automatically for your convenience. The default behaviour of this
248 control is as follows:
250 - When ``active`` is nonzero (the default), the unit works as usual.
252 - When ``active`` is zero, and the unit's number of audio inputs and outputs
253 match, then the audio input is simply passed through.
255 - When ``active`` is zero, but the unit's number of audio inputs and outputs
256 do *not* match, then the unit generates silence.
258 The ``active`` control frequently alleviates the need for special "bypass" or
259 "mute" controls in the Faust source. However, if the default behaviour of the
260 generated control is not appropriate you can also define your own custom
261 version of ``active`` explicitly in the Faust program; in this case the custom
262 version will override the default one.
267 In the examples subdirectory you'll find a bunch of sample Faust DSPs and Pd
268 patches illustrating how Faust units are used in Pd.
270 - The examples/basic/test.pd patch demonstrates the basics of operating "bare"
271 Faust plugins in Pd. You'll rarely have to do this when using the wrappers
272 generated with the faust2pd program, but it is a useful starting point to
273 take a look behind the scenes anyway.
275 - The examples/faust directory contains all the examples from (an earlier
276 version of) the Faust distribution, along with corresponding Pd wrappers
277 generated with faust2pd. Have a look at examples/faust/faustdemo.pd to see
278 some of the DSPs in action. Note that not all examples from the Faust
279 distribution are working out of the box because of name clashes with Pd
280 builtins, so we renamed those. We also edited some of the .dsp sources
281 (e.g., turning buttons into checkboxes or sliders into nentries) where this
282 seemed necessary to make it easier to operate the Pd patches.
284 - The examples/synth directory contains various plugins and patches showing
285 how to implement polyphonic synthesizers using Faust units. Take a look at
286 examples/synth/synth.pd for an example. If you have properly configured your
287 interfaces then you should be able to play the synthesizer via Pd's MIDI
290 - The examples/seqdemo/seqdemo.pd patch demonstrates how to operate a
291 multitimbral synth, built with Faust units, in an automatic fashion using a
292 pattern sequencer programmed in Pure. This example requires the Pure
293 interpreter as well as the pd-pure plugin available from
294 http://pure-lang.googlecode.com.
296 Wrapping DSPs with faust2pd
297 ===========================
299 The faust2pd script generates Pd patches from the dsp.xml files created by
300 Faust when run with the -xml option. Most of the sample patches were actually
301 created that way. After installation you can run the script as follows::
303 faust2pd [-hVbs] [-f size] [-o output-file] [-n #voices]
304 [-r max] [-X patterns] [-x width] [-y height] input-file
306 The default output filename is ``input-file`` with new extension
307 ``.pd``. Thus, ``faust2pd filename.dsp.xml`` creates a Pd patch named
308 ``filename.pd`` from the Faust XML description in ``filename.dsp.xml``.
310 The faust2pd program understands a number of options which affect the layout
311 of the GUI elements and the contents of the generated patch. Here is a brief
312 list of the available options:
314 -h, --help display a short help message and exit
315 -V, --version display the version number and exit
316 -b, --fake-buttons replace buttons (bangs) with checkboxes (toggles)
317 -f, --font-size font size for GUI elements (10 by default)
318 -n, --nvoices create a synth patch with the given number of voices
319 -o, --output-file output file name (.pd file)
320 -r, --radio-sliders radio controls for sliders
321 -s, --slider-nums sliders with additional number control
322 -X, --exclude exclude controls matching the given glob patterns
323 -x, --width maximum width of the GUI area
324 -y, --height maximum height of the GUI area
326 Just like the Faust plugin itself, the generated patch has a control
327 input/output as the leftmost inlet/outlet pair, and the remaining plugs are
328 signal inlets and outlets for each audio input/output of the Faust
329 unit. However, the control inlet/outlet pair works slightly different from
330 that of the Faust plugin. Instead of being used for control replies, the
331 control outlet of the patch simply passes through its control input (after
332 processing messages which are understood by the wrapped plugin). By these
333 means control messages can flow along with the audio signal through an entire
334 chain of Faust units. (You can find an example of this in
335 examples/faust/faustdemo.pd.) Moreover, when generating a polyphonic synth
336 patch using the -n option then there will actually be two control inlets, one
337 for note messages and one for ordinary control messages; this is illustrated
338 in the examples/synth/synth.pd example.
340 The generated patch also includes the necessary GUI elements to see and change
341 all (active and passive) controls of the Faust unit. Faust control elements
342 are mapped to Pd GUI elements in an obvious fashion, following the horizontal
343 and vertical layout specified in the Faust source. The script also adds
344 special buttons for resetting all controls to their defaults and to operate
345 the special ``active`` control.
347 This generally works very well, but you should be aware that the control GUIs
348 generated by faust2pd are somewhat hampered by the limited range of GUI
349 elements available in a vanilla Pd installation. As a remedy, faust2pd
350 provides various options to change the content of the generated wrapper and
351 work around these limitations.
353 - There are no real button widgets as required by the Faust specification,
354 so bangs are used instead. There is a global delay time for switching the
355 control from 1 back to 0, which can be changed by sending a value in
356 milliseconds to the ``faust-delay`` receiver. If you need interactive
357 control over the switching time then it is better to use checkboxes instead,
358 or you can have faust2pd automatically substitute checkboxes for all buttons
359 in a patch by invoking it with the -f a.k.a. --fake-buttons option.
361 - Sliders in Pd do not display their value in numeric form so it may be hard
362 to figure out what the current value is. Therefore faust2pd has an option -s
363 a.k.a. --slider-nums which causes it to add a number box to each slider
364 control. (This flag also applies to Faust's passive bargraph controls, as
365 these are implemented using sliders, see below.)
367 - Pd's sliders also have no provision for specifying a stepsize, so they are
368 an awkward way to input integral values from a small range. OTOH, Faust
369 doesn't support the "radio" control elements which Pd provides for that
370 purpose. As a remedy, faust2pd allows you to specify the option -r max
371 (a.k.a. --radio-sliders=max) to indicate that sliders with integral values
372 from the range 0..max-1 are to be mapped to corresponding Pd radio controls.
374 - Faust's bargraphs are emulated using sliders. Note that these are passive
375 controls which just display a value computed by the Faust unit. A different
376 background color is used for these widgets so that you can distinguish them
377 from the ordinary (active) slider controls. The values shown in passive
378 controls are sampled every 40 ms by default. You can change this value by
379 sending an appropriate message to the global ``faust-timer`` receiver.
381 - Since Pd has no "tabbed" (notebook-like) GUI element, Faust's tgroups are
382 mapped to hgroups instead. It may be difficult to present large and
383 complicated control interfaces without tabbed dialogs, though. As a remedy,
384 you can control the amount of horizontal or vertical space available for the
385 GUI area with the -x and -y (a.k.a. --width and --height) options and
386 faust2pd will then try to break rows and columns in the layout to make
387 everything fit within that area. (This feature has only been tested with
388 simple layouts so far, so beware.)
390 - You can also exclude certain controls from appearing in the GUI using the -X
391 option. This option takes a comma-separated list of shell glob patterns
392 indicating either just the names or the fully qualified paths of Faust
393 controls which are to be excluded from the GUI. For instance, the option
394 ``-X 'volume,meter*,faust/resonator?/*'`` will exclude all volume controls,
395 all controls whose names start with ``meter``, and all controls in groups
396 matching ``faust/resonator?``. (Note that the argument to -X has to be
397 quoted if it contains any wildcards such as ``*`` and ``?``, so that the
398 shell doesn't try to expand the patterns beforehand. Also note that only one
399 -X option is recognized, so you have to specify all controls to be excluded
402 - Faust group labels are not shown at all, since I haven't found an easy way
403 to draw some kind of labelled frame in Pd yet.
405 Despite these limitations, faust2pd appears to work rather well, at least for
406 the kind of DSPs found in the Faust distribution. (Still, for more complicated
407 control surfaces and interfaces to be used on stage you'll probably have to
408 edit the generated GUI layouts by hand.)
410 For convenience, all the content-related command line options mentioned above
411 can also be specified in the Faust source, as special tags in the label of the
412 toplevel group of the dsp. These take the form ``[pd:option]`` or
413 ``[pd:option=value]`` where ``option`` is any of the (long) options understood
414 by faust2pd. For instance::
416 process = vgroup("mysynth [pd:nvoices=8] [pd:slider-nums]", ...);
418 Source options carrying arguments, like ``nvoices`` in the above example, can
419 also be overridden with corresponding command line options.
424 Creating Faust plugins for use with Pd has never been easier before, so I hope
425 that you'll soon have much joy trying your Faust programs in Pd. Add Pd-Pure
426 to this, and you can program all your specialized audio and control objects
427 using two modern-style functional languages which are much more fun than
428 C/C++. Of course there's an initial learning curve to be mastered, but IMHO it
429 is well worth the effort. The bottomline is that Pd+Faust+Pure really makes an
430 excellent combo which provides you with a powerful, programmable interactive
431 environment for creating advanced computer music and multimedia applications
437 Thanks are due to Yann Orlarey for his wonderful Faust, which makes developing
438 DSP algorithms so easy and fun.
440 .. Appendix follows here.