[PD] First time PD troubles: A programmers confusion.

Frank Barknecht fbar at footils.org
Fri Nov 9 00:07:45 CET 2007


Hallo,
Timothy Sikes hat gesagt: // Timothy Sikes wrote:

> Until I got to the flow of control ones.  It's the one where the
> counter counts up to ten, then stops, with another that is a counter
> that goes up by one, and you clear it by pressing the -1 button.

Maybe attached counting.pd tutorial helps a bit, it's more verbose.

> Remember, I program,  so if it could be explained as if I were
> programming, that would probably help me.  I don't understand what
> the term 'bang' refers to in these examples, along with why certain
> 'inlets' connect to certain 'outlets',  or the flow of control in
> the programs, or where the 'count' variable is and how to manipulate
> it.  I feel that once I understand these things, I'll be able to
> have loads of fun with PD. 

You feel right: I'd say, understanding execution order, the trigger
object and hot and cold inlets are *the* imporant next steps now for
you.

I'll give it a shot: 

Message objects (I only talk about these now) in Pd talk to each other
by sending each other messages through patch cords into inlets. The
objects generate messages on their outlets.  Almost every object
reacts to certain special messages (float-messages, symbol-messages,
"meta-messages" like "open filename" or "set tablename" etc.) and also
to the bang-message, which is like a default message saying "do your
thing, object, and do it now!" 

Example: The [float] or [f] object for example accepts two kinds of
messages in its first inlet: float-messages (numbers) and the "bang"
message.  Float messages will set the stored number and output it. The
bang message will not change the stored number but only make the [f]
object "do its thing" which is: output the stored number.

So far that should have been easy, now the tricky part: In almost
every object only the first inlet will make the object generate
output. (Exceptions are the time-objects [timer], [realtime])

This inlet is called the "hot inlet". Other inlets that don't generate
output are "cold inlets". 

With this knowledge, you can already understand the counter idiom, if
you closely watch what is happening at each object with every step or
bang. Here's the counter idiom in ASCII:

 [f 0]x[+ 1]
 |
 [print result]

Note: The outlet of [f] is connected to the "hot" left inlet of the [+
1], but the outlet of [+ 1] is connected to the "cold" right inlet of
the [f]. 

First step: "bang" the [f]

  What happens is, that the stored number, 0 at first, is sent to the
  [+ 1] which adds 1 so we get 1 and immediatly (because the inlet of
  [+ 1] was hot) sends the 1 back to the [f]. At this time, the 1 is
  sent into a cold inlet, so the [f] only stores the 1 but doesn't
  generate any further output and execution stops here.

Second step: "bang" the [f] again

  Now the [f] has a 1 stored, which will be sent to the [+ 1] which
  adds 1 again so we get 2. Immediatly (because the inlet was hot) the
  2 gets sent to the cold inlet of the [f], is stored there and we're
  done again.

Further steps go on and on like this.

An interesting alternative step now is resetting the counter: You do
this for example by sending a "0" to the [float]'s *cold* inlet, the
right one. This will not generate any output, but only set the stored
number so that the whole system is ready to start again at 'First
step: "bang" the [f]'

As soon as you understand the counter idiom, you have made a huge step
to understand Pd in general. After that try to understand the [trigger]
object and how outlets "fire" in right to left order and how this
ideally fits the right-to-left order of cold-to-hot inlets. But that's
homework until the next lesson. ;)

Ciao
-- 
 Frank Barknecht                                     _ ______footils.org__
-------------- next part --------------
A non-text attachment was scrubbed...
Name: counting.pd
Type: application/puredata
Size: 10238 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20071109/d33c7cf1/attachment.bin>


More information about the Pd-list mailing list