Programming with Pd—A Simple Example
From Johannes Kreidler’s Programming Electronic Music in Pd (pd-tutorial.com)
Once you have started Pd, the main Pd window appears on the monitor. Open a new programming window by clicking the File menu and then New (or press ⌘-N).
A new window opens. Add an object box under Put > Object (or press ⌘-1).
… you should see a blue box attached to the mouse cursor …
Then click somewhere on the blank white surface in the new window to decouple the mouse from the object box. Type this into the box: "osc~ 440" (NOTE: make sure you type a tilde after "osc," not a dash).
To accept what you have typed into the box, click anywhere outside the box on the white surface. Note how the blue disappears and the box and its text become black:
(The sign "~" means "tilde"; you'll use this often in Pd.)
You now see a rectangular box with little black rectangles in the top and bottom corners. The upper rectangles are called "inlets", the bottom rectangle is an "outlet".
If you place the cursor onto the outlet rectangle, it changes to a circle (which resembles an open socket for a cable).
Because you haven't created an object to which you can attach this cable yet, the cable vanishes when you release the mouse button. Make another object just as you did the previous one and call it "dac~". Position it below the "osc~" object by clicking it once so that it turns blue and moving the mouse with the mouse button held. Turn your headphones down very low. Then start a cable from the outlet on "osc~" and connect it to the left inlet on "dac~". The cursor changes into a circle when it is over the inlet.
Release the mouse button. The "cable" now connects "osc~ 440" to "dac~". You should hear a tone. If not, verify in the Pd main monitor window that there is a check next to "DSP". If not, check the box with a mouse click:
(The "DSP" function allows you to program in Pd without generating sound. This can save the computer much unnecessary processing power — though this is probably a non-issue with most computers these days. Turning it off can also be useful when you want to make adjustments to your patch, but don't want to be distracted by the sound. Think of it as a "mute" button.)
We hear a tone. To be specific, it is A4, also called the A440, the standard concert tuning pitch that has a frequency of 440 Hertz.
Now connect the outlet from "osc~ 440" with the right inlet of "dac~" as well.
We hear a tone. To be specific, it is A4, also called the A440, the standard concert tuning pitch that has a frequency of 440 Hertz.
Now connect the outlet from "osc~ 440" with the right inlet of "dac~" as well.
You should hear sound from both of the computer's speakers. Now create a number box (Put > Number or with key command ⌘-3) and attach its outlet to the inlet on the object named "osc~". Then you need to change into what is called "Execute mode" (Edit > Edit mode (uncheck), or use key command ⌘-E; the cursor should turn from a pointing hand into an arrow). Click on the number box, hold the mouse button, and move the mouse up and down:
This changes the numbers and the pitch. The value should be at least 100 before you can probably hear the signal. Another way to enter values into the number box is to click on the number box, enter a value on the keyboard, and press ENTER.
Now change back to the other mode, the "Edit mode" (Edit > Edit mode (checked), or use key command ⌘-E). Move the cursor, which should have changed back to a hand, over the connection between "osc~" and "dac~". The cursor becomes an X. Click on it, which will turn the cable blue.
Then go to Edit > Cut or simply press the delete key. This terminates the connection. Cut the other connection to "dac~" as well. Now create a new object where the cables used to be: "*~ 0" and connect it to the other objects as shown (note the space between the tilde and the zero!):
Let's make some more room: Enlarge the window by clicking on its lower right corner, holding the mouse button, and pulling it down and to the right.
Then click on the lower right part of the white background near the "dac~" object, hold the mouse button, and draw a rectangle that includes the "dac~" and the "*~" objects.
This is how you select a part of a patch. (You can also delete boxes this way. After selecting a portion of the patch, go to Edit > Cut or press the delete key.)
When you release the mouse button, both objects appear in blue. Click on one of these selected objects, hold the mouse button, and pull them down to free up more space.
To deselect these blue objects, just click anywhere on the white background.
Next create two "Message" boxes (Put > Message or press ⌘-2) as below and enter "0" in one and "1" in the other. Connect them to the left inlet of the star/tilde object.
Change back to execute mode (Edit > Edit mode (uncheck), or ⌘-E) and click (with headphones low) on the two message boxes in turn: clicking 1 turns the sound on, clicking 0 turns it off.