2022-04-12 22:02:59 -03:00
<!DOCTYPE html>
2022-04-12 21:54:18 -03:00
<!-- Converted with LaTeX2HTML 2002 - 2 - 1 (1.71)
original version by: Nikos Drakos, CBLU, University of Leeds
* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
< HTML >
< HEAD >
2022-04-12 22:02:59 -03:00
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" >
2022-04-12 21:54:18 -03:00
< TITLE > Encapsulation in Pd< / TITLE >
< META NAME = "description" CONTENT = "Encapsulation in Pd" >
< META NAME = "keywords" CONTENT = "book" >
< META NAME = "resource-type" CONTENT = "document" >
< META NAME = "distribution" CONTENT = "global" >
< META NAME = "Generator" CONTENT = "LaTeX2HTML v2002-2-1" >
< META HTTP-EQUIV = "Content-Style-Type" CONTENT = "text/css" >
< LINK REL = "STYLESHEET" HREF = "book.css" >
< LINK REL = "next" HREF = "node68.html" >
< LINK REL = "previous" HREF = "node66.html" >
< LINK REL = "up" HREF = "node58.html" >
< LINK REL = "next" HREF = "node68.html" >
< / HEAD >
< BODY >
<!-- Navigation Panel -->
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1543"
2022-04-12 21:54:18 -03:00
HREF="node68.html">
< IMG WIDTH = "37" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "next"
2022-04-12 22:02:59 -03:00
SRC="next.png">< / A >
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1537"
2022-04-12 21:54:18 -03:00
HREF="node58.html">
< IMG WIDTH = "26" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "up"
2022-04-12 22:02:59 -03:00
SRC="up.png">< / A >
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1531"
2022-04-12 21:54:18 -03:00
HREF="node66.html">
< IMG WIDTH = "63" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "previous"
2022-04-12 22:02:59 -03:00
SRC="prev.png">< / A >
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1539"
2022-04-12 21:54:18 -03:00
HREF="node4.html">
< IMG WIDTH = "65" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "contents"
2022-04-12 22:02:59 -03:00
SRC="contents.png">< / A >
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1541"
2022-04-12 21:54:18 -03:00
HREF="node201.html">
< IMG WIDTH = "43" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "index"
2022-04-12 22:02:59 -03:00
SRC="index.png">< / A >
2022-04-12 21:54:18 -03:00
< BR >
2022-04-12 23:32:40 -03:00
< B > Next:< / B > < A ID = "tex2html1544"
2022-04-12 21:54:18 -03:00
HREF="node68.html">Examples< / A >
2022-04-12 23:32:40 -03:00
< B > Up:< / B > < A ID = "tex2html1538"
2022-04-12 21:54:18 -03:00
HREF="node58.html">Automation and voice management< / A >
2022-04-12 23:32:40 -03:00
< B > Previous:< / B > < A ID = "tex2html1532"
2022-04-12 21:54:18 -03:00
HREF="node66.html">Voice tags< / A >
2022-04-12 23:32:40 -03:00
< B > < A ID = "tex2html1540"
2022-04-12 21:54:18 -03:00
HREF="node4.html">Contents< / A > < / B >
2022-04-12 23:32:40 -03:00
< B > < A ID = "tex2html1542"
2022-04-12 21:54:18 -03:00
HREF="node201.html">Index< / A > < / B >
< BR >
< BR >
<!-- End of Navigation Panel -->
2022-04-12 23:32:40 -03:00
< H1 > < A ID = "SECTION00870000000000000000" > < / A >
< A ID = "sect4.encapsulation" > < / A >
2022-04-12 21:54:18 -03:00
< BR >
Encapsulation in Pd
< / H1 >
< P >
The examples for this chapter will use Pd's
2022-04-12 23:32:40 -03:00
< A ID = "4703" > < / A > < I > encapsulation< / I >
2022-04-12 21:54:18 -03:00
mechanism, which permits the building of patches that
may be reused any number of times. One or more object boxes in a Pd patch may
be
2022-04-12 23:32:40 -03:00
< A ID = "4705" > < / A >
2022-04-12 21:54:18 -03:00
< I > subpatches< / I > ,
which are separate patches encapsulated inside the boxes. These come in
two types:
< I > one-off subpatches< / I > and
2022-04-12 23:32:40 -03:00
< A ID = "4708" > < / A > < A ID = "4709" > < / A > < I > abstractions< / I > .
2022-04-12 21:54:18 -03:00
In either case the subpatch appears as an object box in another patch,
called the
2022-04-12 23:32:40 -03:00
< A ID = "4711" > < / A > < I > parent< / I > .
2022-04-12 21:54:18 -03:00
< P >
2022-04-12 23:17:03 -03:00
If you type "pd" or "pd my-name" into an object box, this creates a one-off
2022-04-12 21:54:18 -03:00
subpatch. The contents of the subpatch are saved as part of the parent patch,
in one file. If you make several copies of a subpatch you may change them
individually. On the other hand, you can invoke an abstraction by typing into
2022-04-12 23:17:03 -03:00
the box the name of a Pd patch saved to a file (without the ".pd" extension).
2022-04-12 21:54:18 -03:00
In this situation Pd will read that file into the subpatch. In this way,
changes to the file propagate everywhere the abstraction is invoked.
< P >
A subpatch (either one-off or abstraction) may have inlets and outlets that
appear on the box in the parent patch. This is specified using the following
objects:
< P >
< BR > <!-- MATH
$\fbox{ $ \mathrm{inlet} $}$
-->
< IMG
WIDTH="50" HEIGHT="41" ALIGN="MIDDLE" BORDER="0"
SRC="img374.png"
ALT="\fbox{ $ \mathrm{inlet} $}">,
<!-- MATH
$\fbox{ $ \mathrm{inlet}\sim $}$
-->
< IMG
WIDTH="67" HEIGHT="41" ALIGN="MIDDLE" BORDER="0"
SRC="img375.png"
ALT="\fbox{ $ \mathrm{inlet}\sim $}">:
2022-04-12 23:32:40 -03:00
< A ID = "4903" > < / A > < A ID = "4904" > < / A > create inlets for the object box containing the subpatch. The
2022-04-12 21:54:18 -03:00
< TT > inlet~< / TT > version creates an inlet for audio signals, whereas
< TT > inlet< / TT > creates one for control streams. In either case, whatever
comes to the inlet of the box in the parent patch comes out of the
< TT > inlet< / TT > or < TT > inlet~< / TT > object in the subpatch.
< P >
< BR > <!-- MATH
$\fbox{ $\mathrm{outlet}$\ }$
-->
< IMG
WIDTH="65" HEIGHT="41" ALIGN="MIDDLE" BORDER="0"
SRC="img376.png"
ALT="\fbox{ $\mathrm{outlet}$\ }">,
<!-- MATH
$\fbox{ $\mathrm{outlet}\sim$\ }$
-->
< IMG
WIDTH="82" HEIGHT="41" ALIGN="MIDDLE" BORDER="0"
SRC="img377.png"
ALT="\fbox{ $\mathrm{outlet}\sim$\ }">:
2022-04-12 23:32:40 -03:00
< A ID = "4905" > < / A > < A ID = "4906" > < / A > Corresponding objects for output from subpatches.
2022-04-12 21:54:18 -03:00
< P >
Pd provides an argument-passing mechanism so that you can parametrize different
2022-04-12 23:17:03 -03:00
invocations of an abstraction. If in an object box you type "$1",
it is expanded to mean "the first creation argument in my box on the
parent patch", and similarly for "$2" and so on. The text in
2022-04-12 21:54:18 -03:00
an object box is interpreted at the time the box is created, unlike the
2022-04-12 23:17:03 -03:00
text in a message box. In message boxes, the same "$1" means "the
2022-04-12 21:54:18 -03:00
first argument of the message I just received" and is interpreted whenever
a new message comes in.
< P >
An example of an abstraction, using inlets, outlets, and parametrization, is
shown in Figure < A HREF = "#fig04.11" > 4.11< / A > . In part (a), a patch invokes
< TT > plusminus< / TT > in an object box, with a creation argument equal to 5. The number 8 is fed to
the < TT > plusminus< / TT > object, and out comes the sum and difference of 8
and 5.
< P >
2022-04-12 23:32:40 -03:00
< DIV ALIGN = "CENTER" > < A ID = "fig04.11" > < / A > < A ID = "4885" > < / A >
2022-04-12 21:54:18 -03:00
< TABLE >
< CAPTION ALIGN = "BOTTOM" > < STRONG > Figure 4.11:< / STRONG >
Pd's abstraction mechanism: (a) invoking the abstraction,
< TT > plusminus< / TT > with 5 as a creation argument; (b) the contents of the
file,
2022-04-12 23:17:03 -03:00
"plusminus.pd".< / CAPTION >
2022-04-12 21:54:18 -03:00
< TR > < TD > < IMG
WIDTH="353" HEIGHT="134" BORDER="0"
SRC="img378.png"
ALT="\begin{figure}\psfig{file=figs/fig04.11.ps}\end{figure}">< / TD > < / TR >
< / TABLE >
< / DIV >
< P >
The < TT > plusminus< / TT > object is not defined by Pd, but is rather defined
2022-04-12 23:17:03 -03:00
by the patch residing in the file named "plusminus.pd". This patch is shown
2022-04-12 21:54:18 -03:00
in part (b) of the figure. The one < TT > inlet< / TT > and
two < TT > outlet< / TT > objects correspond to the inlets and outlets of
2022-04-12 23:17:03 -03:00
the < TT > plusminus< / TT > object. The two "$1" arguments (to the
2022-04-12 21:54:18 -03:00
< TT > +< / TT > and < TT > -< / TT > objects) are replaced by 5 (the creation argument of the
< TT > plusminus< / TT > object).
< P >
We have already seen one abstraction in the examples: the < TT > output~< / TT > object introduced in Figure < A HREF = "node16.html#fig01.10" > 1.10< / A > (Page < A HREF = "node16.html#fig01.10" > < IMG ALIGN = "BOTTOM" BORDER = "1" ALT = "[*]"
2022-04-12 22:02:59 -03:00
SRC="crossref.png">< / A > ). That
2022-04-12 21:54:18 -03:00
example also shows that an abstraction may display controls as part of its box
on the parent patch; see the Pd documentation for a description of this
feature.
< P >
< HR >
<!-- Navigation Panel -->
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1543"
2022-04-12 21:54:18 -03:00
HREF="node68.html">
< IMG WIDTH = "37" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "next"
2022-04-12 22:02:59 -03:00
SRC="next.png">< / A >
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1537"
2022-04-12 21:54:18 -03:00
HREF="node58.html">
< IMG WIDTH = "26" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "up"
2022-04-12 22:02:59 -03:00
SRC="up.png">< / A >
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1531"
2022-04-12 21:54:18 -03:00
HREF="node66.html">
< IMG WIDTH = "63" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "previous"
2022-04-12 22:02:59 -03:00
SRC="prev.png">< / A >
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1539"
2022-04-12 21:54:18 -03:00
HREF="node4.html">
< IMG WIDTH = "65" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "contents"
2022-04-12 22:02:59 -03:00
SRC="contents.png">< / A >
2022-04-12 23:32:40 -03:00
< A ID = "tex2html1541"
2022-04-12 21:54:18 -03:00
HREF="node201.html">
< IMG WIDTH = "43" HEIGHT = "24" ALIGN = "BOTTOM" BORDER = "0" ALT = "index"
2022-04-12 22:02:59 -03:00
SRC="index.png">< / A >
2022-04-12 21:54:18 -03:00
< BR >
2022-04-12 23:32:40 -03:00
< B > Next:< / B > < A ID = "tex2html1544"
2022-04-12 21:54:18 -03:00
HREF="node68.html">Examples< / A >
2022-04-12 23:32:40 -03:00
< B > Up:< / B > < A ID = "tex2html1538"
2022-04-12 21:54:18 -03:00
HREF="node58.html">Automation and voice management< / A >
2022-04-12 23:32:40 -03:00
< B > Previous:< / B > < A ID = "tex2html1532"
2022-04-12 21:54:18 -03:00
HREF="node66.html">Voice tags< / A >
2022-04-12 23:32:40 -03:00
< B > < A ID = "tex2html1540"
2022-04-12 21:54:18 -03:00
HREF="node4.html">Contents< / A > < / B >
2022-04-12 23:32:40 -03:00
< B > < A ID = "tex2html1542"
2022-04-12 21:54:18 -03:00
HREF="node201.html">Index< / A > < / B >
<!-- End of Navigation Panel -->
< ADDRESS >
Miller Puckette
2006-12-30
< / ADDRESS >
< / BODY >
< / HTML >