miller-book/node67.html

232 lines
7.7 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<!--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>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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-->
<A NAME="tex2html1543"
HREF="node68.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
SRC="next.png"></A>
<A NAME="tex2html1537"
HREF="node58.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
SRC="up.png"></A>
<A NAME="tex2html1531"
HREF="node66.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
SRC="prev.png"></A>
<A NAME="tex2html1539"
HREF="node4.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
SRC="contents.png"></A>
<A NAME="tex2html1541"
HREF="node201.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html1544"
HREF="node68.html">Examples</A>
<B> Up:</B> <A NAME="tex2html1538"
HREF="node58.html">Automation and voice management</A>
<B> Previous:</B> <A NAME="tex2html1532"
HREF="node66.html">Voice tags</A>
&nbsp; <B> <A NAME="tex2html1540"
HREF="node4.html">Contents</A></B>
&nbsp; <B> <A NAME="tex2html1542"
HREF="node201.html">Index</A></B>
<BR>
<BR>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION00870000000000000000"></A>
<A NAME="sect4.encapsulation"></A>
<BR>
Encapsulation in Pd
</H1>
<P>
The examples for this chapter will use Pd's
<A NAME="4703"></A><I>encapsulation</I>
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
<A NAME="4705"></A>
<I>subpatches</I>,
which are separate patches encapsulated inside the boxes. These come in
two types:
<I>one-off subpatches</I> and
<A NAME="4708"></A><A NAME="4709"></A><I>abstractions</I>.
In either case the subpatch appears as an object box in another patch,
called the
<A NAME="4711"></A><I>parent</I>.
<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
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).
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 $}">:
<A NAME="4903"></A><A NAME="4904"></A>create inlets for the object box containing the subpatch. The
<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$\ }">:
<A NAME="4905"></A><A NAME="4906"></A>Corresponding objects for output from subpatches.
<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
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
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>
<DIV ALIGN="CENTER"><A NAME="fig04.11"></A><A NAME="4885"></A>
<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>
<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
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
<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="[*]"
SRC="crossref.png"></A>). That
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-->
<A NAME="tex2html1543"
HREF="node68.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
SRC="next.png"></A>
<A NAME="tex2html1537"
HREF="node58.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
SRC="up.png"></A>
<A NAME="tex2html1531"
HREF="node66.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
SRC="prev.png"></A>
<A NAME="tex2html1539"
HREF="node4.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
SRC="contents.png"></A>
<A NAME="tex2html1541"
HREF="node201.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
SRC="index.png"></A>
<BR>
<B> Next:</B> <A NAME="tex2html1544"
HREF="node68.html">Examples</A>
<B> Up:</B> <A NAME="tex2html1538"
HREF="node58.html">Automation and voice management</A>
<B> Previous:</B> <A NAME="tex2html1532"
HREF="node66.html">Voice tags</A>
&nbsp; <B> <A NAME="tex2html1540"
HREF="node4.html">Contents</A></B>
&nbsp; <B> <A NAME="tex2html1542"
HREF="node201.html">Index</A></B>
<!--End of Navigation Panel-->
<ADDRESS>
Miller Puckette
2006-12-30
</ADDRESS>
</BODY>
</HTML>