User Tools

Site Tools


Using Arrays and Graphs

An array is simply a sequence of numbers stored in memory in Pd. When an array is created both the size of the array (number of values to store) and range of possible values can be specified. Arrays are not automatically visible in the patch (which can be cluttered enough without a table of values taking up precious screen space). Instead, arrays are subpatches of the “parent” patch. Values can be added to arrays using a variety of methods; for example, they can be computed by the patch, read from a file, and so forth. Even though the array is a subpatch, you can still modify its properties, inspect its values, and so forth.

Sometimes, however, you want to have a representation of the array on your patch. To create an array that is visualized in the patch you need a graph. Confusingly enough, you can create arrays with and without graphs, and you can create graphs with and without arrays, and there are several different ways to do each. Here we try to clearly describe the most common ways to create and use graphs.

[screenshot here?]

Create an array

There are three ways to create an array:

  • Select “Object” from the Put menu and call the object table. This object is used to add an array to a patch. It automatically creates the subpatch to store the array. However, if you select “graph-on-parent” in the subpatch properties a graph for the array will appear on the main patch. See the help on table for creation arguments.
  • Select “Graph” from the Put menu to place a graph, then select “Array” and choose “in last graph” to associate it with the graph you just placed.
  • Select “Array” from the Put menu. This will automatically create a new graph to place on the patch canvas. This brings up two dialog boxes, one for the array and one for the graph. Put the names and other creation information here.


Initializing Properties

You can initialize array properties using dialog boxes.

  • At creation time, give the array a name and size (and several miscellaneous choices)
  • Use the Properties menu to select the X and Y ranges for the array. The X range is the size of the array; for example, if the array is to store 100 elements give it an X range of 0..99. By default, the Y range is -1..1 for audio values. For control values, change the range to whatever is appropriate for the control. For example, for an array of MIDI pitch numbers you could specify a Y range of 0..127.


Storing Values in an Array

  • To initialize a small number of elements of an array, open Properties and in the array dialog, choose View List. For a newly created array, all values in the array slots will be zero. You can then double-click on each slot you wish to change and type in whatever number you want. Remember that these are stored as floating point values.
  • To initialize an array all at once, you will usually use [tabwrite] (or [tabwrite~] for audio values). See Help on this object for more information.
  • The values of an array can be initialized or changed via a graph. Simply use the mouse to draw (or change) the graph. While this is not the most precise way to put values in an array, it is a quick way to experiment with new values. Choose Draw as Polygon in the array Properties for best results.


Reading Values from an Array

  • To simply view the values in an array numerically (rather than graphically) use the View List mentioned above.
  • To read values from an array for use by subsequent portions of a patch, use the objects [tabread] or [tabread~]
  • Reading from an array repeatedly can be accomplished using the [phasor] object. This is commonly used in wavetable lookup or sampling.
  • More to come


It is possible to create a graph first, before creating the array it will display. It should also be noted that are not the only things that can be displayed as graphs. It is not necessary to associate a graph with an array.

There are two ways to create a graph:

  1. Choose Graph from the Put menu. If you are using the graph to display an array, do this before creating the array. To associate the array with the graph, use the method described above in Create an array.
  1. Select “graph on parent” when creating an array using [table]. This automatically associates the graph with an array.


When working with audio it is easy to store values in arrays that exceed the initially specified range. This won't (necessarily) cause problems in the patch, but the values will be drawn outside the bounds of the graph. This can be disturbing!

See also numeric arrays from the Pd Documentation website.

tasc/tables_and_arrays.txt · Last modified: 2009/11/06 08:24 by scarl