Debian Codegraph @

tools/faust2pd/README

raw
1
2 ======================================
3 faust2pd: Pd Patch Generator for Faust
4 ======================================
5
6 Version @version@, |today|
7
8 Albert Graef <[email protected]>
9
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 Pd GUI wrappers for Faust DSPs. The package also includes a Pure
13 script faustxml.pure for parsing Faust dsp descriptions in XML or JSON format,
14 as well as a bunch of examples. The software is distributed under the GPL; see
15 the COPYING file for details.
16
17 .. note:: This faust2pd version is written in Pure and was ported from an
18 earlier version written in Pure's predecessor Q. The version of the script
19 provided here should be 100% backward-compatible to those previous
20 versions, except for the following changes:
21
22 - The (rarely used) -f (a.k.a. --fake-buttons) option was renamed to -b,
23 and a new -f (a.k.a. --font-size) option was added to change the font
24 size of the GUI elements.
25
26 - For compatibility with pd-faust, the -s (a.k.a. --slider-nums) flag is
27 enabled by default now. The corresponding option is still supported for
28 backward compatibility, and for overriding the new --no-slider-nums
29 option which can be used to disable this feature.
30
31 - Most command line options can now also be specified using special meta
32 data in the Faust source.
33
34 As of version 2.1, the faust2pd script is now compiled to a native executable
35 before installation. This makes the program start up much faster, which is a
36 big advantage because most xml and json files don't take long to be processed.
37
38 faust2pd version 2.11 and later have full support for Faust's new JSON-based
39 description format, which is generated with the -json option. The JSON-based
40 interface offers some advantages, such as accessing additional meta data in
41 the Faust source (the XML format doesn't offer this in the latest Faust
42 versions any more), and the capability to read dsp descriptions straight from
43 running dsp instances in httpd-enabled Faust applications and Grame's new
44 FaustLive environment. However, this format is only supported in the latest
45 Faust versions (Faust 0.9.70 and later, or Faust 2.0.a30 and later if you are
46 running the Faust2 development version). At the time of this writing, these
47 versions are only available in the Faust git repository.
48
49 .. _Pure: http://purelang.bitbucket.org
50
51 .. contents::
52 .. sectnum::
53
54 Copying
55 =======
56
57 Copyright (c) 2009-2014 by Albert Graef.
58
59 faust2pd is free software: you can redistribute it and/or modify it under the
60 terms of the GNU General Public License as published by the Free Software
61 Foundation, either version 3 of the License, or (at your option) any later
62 version.
63
64 faust2pd is distributed in the hope that it will be useful, but WITHOUT ANY
65 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
66 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
67
68 You should have received a copy of the GNU General Public License along with
69 this program. If not, see <http://www.gnu.org/licenses/>.
70
71 Requirements
72 ============
73
74 faust2pd is known to work on Linux, Mac OS X, and Windows, and there shouldn't
75 be any major roadblocks preventing it to work on other systems supported by
76 Pure.
77
78 The faust2pd script is written in the Pure_ programming language and requires
79 Pure's XML module, so you need to install these to make it work. Install the
80 latest pure*.tar.gz and pure-xml*.tar.gz packages and you should be set. (Pure
81 0.47 or later is required.) Also make sure that the LLVM base package is
82 installed, as described in the Pure INSTALL file, some LLVM utilities are
83 needed to make Pure's batch compiler work.
84
85 To run the seqdemo example, you'll also need the Pd Pure external
86 (pd-pure*.tar.gz), also available at the Pure_ website.
87
88 To compile the examples, you'll need GNU C++ and make, Pd_ and, of course,
89 Faust_. Make sure you get a recent version of Faust; Faust 0.9.67 or later is
90 recommended. Faust 0.9.70 and later have support for the new JSON format and
91 offer some other new and convenient capabilities, such as retrieving the JSON
92 description directly from a running dsp instance via Faust's httpd interface.
93 For the latter, you also need to have the curl_ program installed.
94
95 .. _Pd: http://puredata.info
96 .. _Faust: http://faudiostream.sf.net
97 .. _curl: http://curl.haxx.se
98
99 Installation
100 ============
101
102 Get the latest source from
103 https://bitbucket.org/purelang/pure-lang/downloads/faust2pd-@[email protected].
104
105 Run ``make`` and ``make install`` to compile and install the faust2pd program
106 on your system. You can set the installation prefix by running make as ``make
107 install prefix=/some/path``. Default installation prefix is /usr/local,
108 faust2pd is installed in the bin directory below that.
109
110 Optionally, you can also run ``make install-pd`` to copy the supporting Pd
111 abstractions (faust-\*.pd) to your lib/pd/extra directory, so that you can use
112 the patches generated by faust2pd without copying these abstractions to your
113 working directory. The Makefile tries to guess the prefix of your Pd
114 installation, if it guesses wrong, you can specify the prefix explicitly by
115 running make as ``make install-pd pdprefix=/some/path``.
116
117 The included faustxml.pure script provides access to Faust-generated dsp
118 descriptions in XML or JSON files to Pure scripts. This module is described in
119 its own appendix__ below. It may have uses beyond faust2pd, but isn't normally
120 installed. If you want to use this module, you can just copy it to your Pure
121 library directory.
122
123 __ `Appendix: faustxml`_
124
125 Quickstart
126 ==========
127
128 Run ``make examples`` to compile the Faust examples included in this package
129 to corresponding Pd plugins. After that you should be able to run the patches
130 in the various subdirectories of the examples directory. Everything is set up
131 so that you can try the examples "in-place", without installing anything
132 except the required software as noted in Requirements_ above. You can also run
133 ``make realclean`` before ``make`` to regenerate everything from scratch (this
134 requires faust2pd, so this will only work if you already installed the Pure
135 interpreter).
136
137 Faust Pd plugins work in much the same way as the well-known plugin~ object
138 (which interfaces to LADSPA plugins), except that each Faust DSP is compiled
139 to its own Pd external. Under Linux, the basic compilation process is as
140 follows (taking the freeverb module from the Faust distribution as an
141 example):
142
143 .. code-block:: sh
144
145 # compile the Faust source to a C++ module using the "puredata" architecture
146 faust -a puredata.cpp freeverb.dsp -o freeverb.cpp
147 # compile the C++ module to a Pd plugin
148 g++ -shared -Dmydsp=freeverb freeverb.cpp -o freeverb~.pd_linux
149
150 By these means, a Faust DSP named ``xyz`` with n audio inputs and m audio
151 outputs becomes a Pd object ``xyz~`` with n+1 inlets and m+1 outlets. The
152 leftmost inlet/outlet pair is for control messages only. This allows you to
153 inspect and change the controls the unit provides, as detailed below. The
154 remaining inlets and outlets are the audio inputs and outputs of the unit,
155 respectively. For instance, ``freeverb.dsp`` becomes the Pd object
156 ``freeverb~`` which, in addition to the control inlet/outlet pair, has 2 audio
157 inputs and outputs.
158
159 When creating a Faust object it is also possible to specify, as optional
160 creation parameters, an extra unit name (this is explained in the following
161 section) and a sample rate. If no sample rate is specified explicitly, it
162 defaults to the sample rate at which Pd is executing. (Usually it is not
163 necessary or even desirable to override the default choice, but this might
164 occasionally be useful for debugging purposes.)
165
166 As already mentioned, the main ingredient of this package is a Pure script
167 named "faust2pd" which allows you to create Pd abstractions as "wrappers"
168 around Faust units. The wrappers generated by faust2pd can be used in Pd
169 patches just like any other Pd objects. They are much easier to operate than
170 the "naked" Faust plugins themselves, as they also provide "graph-on-parent"
171 GUI elements to inspect and change the control values.
172
173 The process to compile a plugin and build a wrapper patch is very similar to
174 what we've seen above. You only have to add the -xml option when invoking the
175 Faust compiler and run faust2pd on the resulting XML file:
176
177 .. code-block:: sh
178
179 # compile the Faust source and generate the xml file
180 faust -a puredata.cpp -xml freeverb.dsp -o freeverb.cpp
181 # compile the C++ module to a Pd plugin
182 g++ -shared -Dmydsp=freeverb freeverb.cpp -o freeverb~.pd_linux
183 # generate the Pd patch from the xml file
184 faust2pd freeverb.dsp.xml
185
186 As of version 2.11, faust2pd can also process dsp descriptions in Faust's new
187 JSON format (-json option). Please see `Wrapping DSPs with faust2pd`_ below
188 for further details.
189
190 Note that, just as with other Pd externals and abstractions, the compiled
191 .pd_linux modules and wrapper patches must be put somewhere where Pd can find
192 them. To these ends you can either move the files into the directory with the
193 patches that use the plugin, or you can put them into the lib/pd/extra
194 directory or some other directory on Pd's library path for system-wide use.
195
196 Also, faust2pd-generated wrappers use a number of supporting abstractions (the
197 faust-\*.pd files in the faust2pd sources), so you have to put these into the
198 directory of the main patch or install them under lib/pd/extra as well. (The
199 ``make pd-install`` step does the latter, see Installation_ above.)
200
201 Control Interface
202 =================
203
204 The control inlet of a Faust plugin understands messages in one of the
205 following forms:
206
207 - ``bang``, which reports all available controls of the unit on the control
208 outlet, in the form: ``type name val init min max step``, where ``type`` is
209 the type of the control as specified in the Faust source (``checkbox``,
210 ``nentry``, etc.), ``name`` its (fully qualified) name, ``val`` the current
211 value, and ``init``, ``min``, ``max``, ``step`` the initial value, minimum,
212 maximum and stepsize of the control, respectively.
213
214 - ``foo 0.99``, which sets the control ``foo`` to the value 0.99, and outputs
215 nothing.
216
217 - Just ``foo``, which outputs the (fully qualified) name and current value of
218 the ``foo`` control on the control outlet.
219
220 Control names can be specified in their fully qualified form, like e.g.
221 ``/gnu/bar/foo`` which indicates the control ``foo`` in the subgroup ``bar``
222 of the topmost group ``gnu``, following the hierarchical group layout defined
223 in the Faust source. This lets you distinguish between different controls with
224 the same name which are located in different groups. To find out about all the
225 controls of a unit and their fully qualified names, you can bang the control
226 inlet of the unit as described above, and connect its control outlet to a
227 ``print`` object, which will cause the descriptions of all controls to be
228 printed in Pd's main window. (The same information can also be used, e.g., to
229 initialize GUI elements with the proper values. Patches generated with
230 faust2pd rely on this.)
231
232 You can also specify just a part of the control path (like ``bar/foo`` or just
233 ``foo`` in the example above) which means that the message applies to *all*
234 controls which have the given pathname as the final portion of their fully
235 qualified name. Thus, if there is more than one ``foo`` control in different
236 groups of the Faust unit then sending the message ``foo`` to the control inlet
237 will report the fully qualified name and value for each of them. Likewise,
238 sending ``foo 0.99`` will set the value of all controls named ``foo`` at once.
239
240 Concerning the naming of Faust controls in Pd you should also note the
241 following:
242
243 - A unit name can be specified at object creation time, in which case the
244 given symbol is used as a prefix for all control names of the unit. E.g.,
245 the control ``/gnu/bar/foo`` of an object ``baz~`` created with ``baz~
246 baz1`` has the fully qualified name ``/baz1/gnu/bar/foo``. This lets you
247 distinguish different instances of an object such as, e.g., different voices
248 of a polyphonic synth unit.
249
250 - Pd's input syntax for symbols is rather restrictive. Therefore group and
251 control names in the Faust source are mangled into a form which only
252 contains alphanumeric characters and hyphens, so that the control names are
253 always legal Pd symbols. For instance, a Faust control name like ``meter #1
254 (dB)`` will become ``meter-1-dB`` which can be input directly as a symbol in
255 Pd without any problems.
256
257 - "Anonymous" groups and controls (groups and controls which have empty labels
258 in the Faust source) are omitted from the path specification. E.g., if
259 ``foo`` is a control located in a main group with an empty name then the
260 fully qualified name of the control is just ``/foo`` rather than ``//foo``.
261 Likewise, an anonymous control in the group ``/foo/bar`` is named just
262 ``/foo/bar`` instead of ``/foo/bar/``.
263
264 Last but not least, there is also a special control named ``active`` which is
265 generated automatically for your convenience. The default behaviour of this
266 control is as follows:
267
268 - When ``active`` is nonzero (the default), the unit works as usual.
269
270 - When ``active`` is zero, and the unit's number of audio inputs and outputs
271 match, then the audio input is simply passed through.
272
273 - When ``active`` is zero, but the unit's number of audio inputs and outputs
274 do *not* match, then the unit generates silence.
275
276 The ``active`` control frequently alleviates the need for special "bypass" or
277 "mute" controls in the Faust source. However, if the default behaviour of the
278 generated control is not appropriate you can also define your own custom
279 version of ``active`` explicitly in the Faust program; in this case the custom
280 version will override the default one.
281
282 Examples
283 ========
284
285 In the examples subdirectory you'll find a bunch of sample Faust DSPs and Pd
286 patches illustrating how Faust units are used in Pd.
287
288 - The examples/basic/test.pd patch demonstrates the basics of operating "bare"
289 Faust plugins in Pd. You'll rarely have to do this when using the wrappers
290 generated with the faust2pd program, but it is a useful starting point to
291 take a look behind the scenes anyway.
292
293 - The examples/faust directory contains all the examples from (an earlier
294 version of) the Faust distribution, along with corresponding Pd wrappers
295 generated with faust2pd. Have a look at examples/faust/faustdemo.pd to see
296 some of the DSPs in action. Note that not all examples from the Faust
297 distribution are working out of the box because of name clashes with Pd
298 builtins, so we renamed those. We also edited some of the .dsp sources
299 (e.g., turning buttons into checkboxes or sliders into nentries) where this
300 seemed necessary to make it easier to operate the Pd patches.
301
302 - The examples/synth directory contains various plugins and patches showing
303 how to implement polyphonic synthesizers using Faust units. Take a look at
304 examples/synth/synth.pd for an example. If you have properly configured your
305 interfaces then you should be able to play the synthesizer via Pd's MIDI
306 input.
307
308 - The examples/seqdemo/seqdemo.pd patch demonstrates how to operate a
309 multitimbral synth, built with Faust units, in an automatic fashion using a
310 pattern sequencer programmed in Pure. This example requires the Pure
311 interpreter as well as the pd-pure plugin available from
312 http://purelang.bitbucket.org.
313
314 Wrapping DSPs with faust2pd
315 ===========================
316
317 The faust2pd script generates Pd patches from the dsp.xml files created by
318 Faust when run with the -xml option. Most of the sample patches were actually
319 created that way. After installation you can run the script as follows::
320
321 faust2pd [-hVbs] [-f size] [-o output-file] [-n #voices]
322 [-r max] [-X patterns] [-x width] [-y height] input-file
323
324 The default output filename is ``input-file`` with new extension
325 ``.pd``. Thus, ``faust2pd filename.dsp.xml`` creates a Pd patch named
326 ``filename.pd`` from the Faust XML description in ``filename.dsp.xml``.
327
328 JSON Support
329 ------------
330
331 As of version 2.11, faust2pd also fully supports Faust's new JSON-based
332 description format, which is generated with the -json option. In this case the
333 filename extension is ``.dsp.json``, so faust2pd is invoked as ``faust2pd
334 filename.dsp.json`` instead. Please note that this format is only supported in
335 the latest Faust versions (Faust 0.9.70 and later).
336
337 Instead of generating a JSON file with the Faust compiler, you can also read
338 the JSON description straight from a running dsp instance via the httpd
339 interface. This works with both stand-alone Faust applications which have the
340 httpd interface enabled (e.g., created with ``faust2jaqt -httpd mydsp.dsp``)
341 and instances running in Grame's FaustLive application. To these ends, you
342 just specify the URL of the running dsp instance instead of the JSON
343 filename. (To make this work, you need to have curl_ installed.)
344
345 For instance, assuming that there's a Faust dsp running locally at port 5510,
346 you can run faust2pd as follows to create a GUI patch for it: ``faust2pd
347 http://localhost:5510``. You can find out about the port a Faust dsp runs on
348 by inspecting the terminal output of a stand-alone Faust application. In
349 FaustLive, use the ``Window / View QRcode`` menu option to retrieve the IP
350 under which the httpd interface of a dsp window can be accessed. If FaustLive
351 is running locally on its default port (7777), then you can also retrieve a
352 list of dsp instances currently running in FaustLive using ``faust2pd
353 http://localhost:7777/availableInterfaces``. This prints the dsp names along
354 with their URLs on stdout.
355
356 faust2pd Options
357 ----------------
358
359 The faust2pd program understands a number of options which affect the layout
360 of the GUI elements and the contents of the generated patch. Here is a brief
361 list of the available options:
362
363 -h, --help display a short help message and exit
364 -V, --version display the version number and exit
365 -b, --fake-buttons replace buttons (bangs) with checkboxes (toggles)
366 -f, --font-size font size for GUI elements (10 by default)
367 -n, --nvoices create a synth patch with the given number of voices
368 -o, --output-file output file name (.pd file)
369 -r, --radio-sliders radio controls for sliders
370 -s, --slider-nums sliders with additional number control
371 -X, --exclude exclude controls matching the given glob patterns
372 -x, --width maximum width of the GUI area
373 -y, --height maximum height of the GUI area
374
375 Just like the Faust plugin itself, the generated patch has a control
376 input/output as the leftmost inlet/outlet pair, and the remaining plugs are
377 signal inlets and outlets for each audio input/output of the Faust
378 unit. However, the control inlet/outlet pair works slightly different from
379 that of the Faust plugin. Instead of being used for control replies, the
380 control outlet of the patch simply passes through its control input (after
381 processing messages which are understood by the wrapped plugin). By these
382 means control messages can flow along with the audio signal through an entire
383 chain of Faust units. (You can find an example of this in
384 examples/faust/faustdemo.pd.) Moreover, when generating a polyphonic synth
385 patch using the -n option then there will actually be two control inlets, one
386 for note messages and one for ordinary control messages; this is illustrated
387 in the examples/synth/synth.pd example.
388
389 The generated patch also includes the necessary GUI elements to see and change
390 all (active and passive) controls of the Faust unit. Faust control elements
391 are mapped to Pd GUI elements in an obvious fashion, following the horizontal
392 and vertical layout specified in the Faust source. The script also adds
393 special buttons for resetting all controls to their defaults and to operate
394 the special ``active`` control.
395
396 This generally works very well, but the control GUIs generated by faust2pd are
397 somewhat hampered by the limited range of GUI elements available in a vanilla
398 Pd installation. As a remedy, faust2pd provides various options to change the
399 content of the generated wrapper and work around these limitations.
400
401 - There are no real button widgets as required by the Faust specification,
402 so bangs are used instead. There is a global delay time for switching the
403 control from 1 back to 0, which can be changed by sending a value in
404 milliseconds to the ``faust-delay`` receiver. If you need interactive
405 control over the switching time then it is better to use checkboxes instead,
406 or you can have faust2pd automatically substitute checkboxes for all buttons
407 in a patch by invoking it with the -b a.k.a. --fake-buttons option.
408
409 - Sliders in Pd do not display their value in numeric form so it may be hard
410 to figure out what the current value is. Therefore faust2pd has an option -s
411 a.k.a. --slider-nums which causes it to add a number box to each slider
412 control. (This flag also applies to Faust's passive bargraph controls, as
413 these are implemented using sliders, see below. As of faust2pd 2.12, this
414 option is actually the default now, but you can still disable it with the
415 --no-slider-nums option.)
416
417 - Pd's sliders also have no provision for specifying a stepsize, so they are
418 an awkward way to input integral values from a small range. OTOH, Faust
419 doesn't support the "radio" control elements which Pd provides for that
420 purpose. As a remedy, faust2pd allows you to specify the option -r max
421 (a.k.a. --radio-sliders=max) to indicate that sliders with integral values
422 from the range 0..max-1 are to be mapped to corresponding Pd radio controls.
423
424 - Faust's bargraphs are emulated using sliders. Note that these are passive
425 controls which just display a value computed by the Faust unit. A different
426 background color is used for these widgets so that you can distinguish them
427 from the ordinary (active) slider controls. The values shown in passive
428 controls are sampled every 40 ms by default. You can change this value by
429 sending an appropriate message to the global ``faust-timer`` receiver.
430
431 - Since Pd has no "tabbed" (notebook-like) GUI element, Faust's tgroups are
432 mapped to hgroups instead. It may be difficult to present large and
433 complicated control interfaces without tabbed dialogs, though. As a remedy,
434 you can control the amount of horizontal or vertical space available for the
435 GUI area with the -x and -y (a.k.a. --width and --height) options and
436 faust2pd will then try to break rows and columns in the layout to make
437 everything fit within that area. (This feature has only been tested with
438 simple layouts so far, so beware.)
439
440 - You can also exclude certain controls from appearing in the GUI using the -X
441 option. This option takes a comma-separated list of shell glob patterns
442 indicating either just the names or the fully qualified paths of Faust
443 controls which are to be excluded from the GUI. For instance, the option
444 ``-X 'volume,meter*,faust/resonator?/*'`` will exclude all volume controls,
445 all controls whose names start with ``meter``, and all controls in groups
446 matching ``faust/resonator?``. (Note that the argument to -X has to be
447 quoted if it contains any wildcards such as ``*`` and ``?``, so that the
448 shell doesn't try to expand the patterns beforehand. Also note that only one
449 -X option is recognized, so you have to specify all controls to be excluded
450 as a single option.)
451
452 - Faust group labels are not shown at all, since I haven't found an easy way
453 to draw some kind of labelled frame in Pd yet.
454
455 Despite these limitations, faust2pd appears to work rather well, at least for
456 the kind of DSPs found in the Faust distribution. (Still, for more complicated
457 control surfaces and interfaces to be used on stage you'll probably have to
458 edit the generated GUI layouts by hand.)
459
460 For convenience, all the content-related command line options mentioned above
461 can also be specified in the Faust source, as special meta data in the label
462 of the toplevel group of the dsp. These take the form ``[pd:option]`` or
463 ``[pd:option=value]`` where ``option`` is any of the layout options understood
464 by faust2pd. For instance::
465
466 process = vgroup("mysynth [pd:nvoices=8] [pd:no-slider-nums]", ...);
467
468 Alternatively, as of faust2pd 2.11, these options can also be specified as a
469 single chunk of global meta data, using the ``faust2pd`` key. So the above can
470 also be written as::
471
472 declare faust2pd "--nvoices=8 --no-slider-nums";
473
474 Note that source options carrying arguments, like ``--nvoices`` in the above
475 example, can still be overridden with corresponding command line options. Also
476 note that all this works with the JSON format only, as meta data in the Faust
477 source isn't recorded in the XML format produced by recent Faust versions any
478 more.
479
480 Conclusion
481 ==========
482
483 Creating Faust plugins for use with Pd has never been easier before, so I hope
484 that you'll soon have much joy trying your Faust programs in Pd. Add Pd-Pure
485 to this, and you can program all your specialized audio and control objects
486 using two modern-style functional languages which are much more fun than
487 C/C++. Of course there's an initial learning curve to be mastered, but IMHO it
488 is well worth the effort. The bottomline is that Pd+Faust+Pure really makes an
489 excellent combo which provides you with a powerful, programmable interactive
490 environment for creating advanced computer music and multimedia applications
491 with ease.
492
493 Acknowledgements
494 ----------------
495
496 Thanks are due to Yann Orlarey for his wonderful Faust, which makes developing
497 DSP algorithms so easy and fun.
498
499 .. Appendix follows here.