Pure Data

Pure Data - or Pd - is an open source, visual computer music language. It’s popular among people who don’t already code, because it has a gentle learning curve and a block-based approach to coding.

Pd is free to download and use.

Table of contents

  1. About Pure Data
  2. Bela and Pd
    1. Libpd
    2. The Bela-Pd workflow
  3. Audio input and output channels
  4. Analog inputs and outputs
  5. Digital I/O
  6. MIDI I/O
  7. Abstractions
  8. Projects built using Pure Data and Bela
  9. Pure Data resources

About Pure Data

Pd, was developed by Miller Puckette in the 1990s for creating interactive computer music and interactive artworks. It is open source and free to download and use.

You might recognise the boxes and patching cables in the image below from Max/MSP. In fact, Pd is Max’s open-source sibling, as both were originally developed by Miller Puckette. While Max has developed into a fully-featured, commercial piece of software, Pure Data has remained free to use while managing to keep more or less the same features.

An example of simple additive synthesis in Max/MSP on the right and Pure Data on the left.

Programming in Pd

Pd is based around a ‘patcher’ or ‘dataflow’ programming logic. To program something in Pd, you create objects (the boxes), and describe the signal flow between them by creating connections using patch cables (the lines). The signal can be audio, but it can also be a number, a message, a MIDI note, and other forms of data.

Creating objects and connecting them together in a visual environment means you don’t have to write any code in order to create complex digital audio project. This makes it possible to sketch programmes for synthesis, live effects and interactive audio very quickly.

Bela and Pd

Pd is open-source software, and can be run on a huge range of computers - PCs, laptops, and smart phones can run Pd, as well as embedded devices like Bela.

Libpd

Bela uses the libPd library. This Linux library allows Pd’s core DSP functionality to run on the board. It runs “headless” - this means that the graphical part of Pd isn’t running on Bela, just the core audio part of things.

The details of how Bela and Pure Data relate.

The Bela-Pd workflow

The Bela IDE is not a Pure Data patching environment. This means you can’t create or edit graphical objects in the IDE.

Patches are created in Pure Data running on your laptop, and are then uploaded to your Bela project using the IDE. When you view a Pure Data project in the Project Explorer tab you can see the .pd files in your project. If you click on one, it will be visualised in the editor window. This is great for examining the patches in your Bela project, but you can’t edit them here.

Creating a Pd project

To create a new Pure Data project in the IDE, go to the Project Explorer tab. Click the Create New Project button at the top, and in the dialog box, select Pure Data, give your project a name, and click Create project.

This creates a blank Pure Data Bela project. In the Project Explorer tab you’ll see that the only thing in it is a file called _main.pd. The main Pd patch of your project must always be named _main.pd. You can have other Pd components, but the core patch always needs this name.

To edit this file, download it by clicking the Download button beside the file name. Then, open it in Pure Data on your computer to edit it.

Editing and uploading a Pd patch

As you develop your project you’ll make lots of edits to your _main.pd file in Pure Data on your computer. When you’re ready to test, save your _main.pd file, and drag it from the Finder to the Bela IDE and drop it anywhere on the window. This will upload and run your patch.

Tip

You don't have to stop your patch running to upload an edit. Just drag and drop your file from your computer's Finder or File Explorer into the Bela IDE, and the IDE will automatically upload and re-run it.

Running a Pd project

If your project is not already open in the IDE, go to the Project Explorer tab and click the Your projects dropdown. Click the name of your project to open it. You’ll see _main.pd visualised in the Editor window.

Then, click the Run button to build and run it. Click the Stop button to stop it.

Audio input and output channels

In Pd you can use the [adc~] and [dac~] objects for audio inputs and outputs. On Bela the stereo audio input is accessed through [adc~ 1 2], and you can send audio to the stereo output by connecting to [dac~ 1 2]. Below is an example of a simple delay effect applied to an audio input.

Analog inputs and outputs

Bela’s analog inputs and outputs can be treated like audio signals, and we use the [adc~] and [dac~] objects to receive and send this data. Bela’s audio inputs start at [adc~ 3], as the first two channels of [adc~] are audio inputs. [adc~ 3 4 5 6 7 8 9 10] creates an object to send data to all 8 of Bela’s analog inputs. You can use as many or as few of these inputs as you wish.

If you have a Bela system, you also have 8 analog outputs. The above logic applies to [dac~] for the analog outputs, and is shown here:

These inputs and outputs are sampled at audio sampling rate, so handle them as you would audio signals. If you want to print an analog or audio value, use the [snapshot~] object to make it printable at a lower rate, as shown here:

Using Pd with the CTAG multi-channel audio system

You can program the Bela-compatible CTAG multi-channel system with Pd, but there are some things to know about channel numbering. See our programming notes on the CTAG product page.

Digital I/O

Bela’s digital I/O operate in two states (HIGH or LOW), and can be read at message rate or audio rate. Unlike the analog channels which are set as either inputs or outputs, each digital pin can function as both an input or an output. This means a digital pin’s mode must be explicitly set in the patch.

The digital I/O pins are initialised by sending messages to bela_setDigital. Digital pins 0-16 are numbered 11-26, see the pin diagram for more information.

Want to see it in action? Check out the Pure Data Digital example in the Examples tab.

MIDI I/O

MIDI also works with Pure Data on Bela. Most class-compliant USB MIDI devices are compatible with Bela.

Use the [notein] and [ctlin] objects to receive midinote and CC messages from the device. See the Hello Midi example in the Examples tab to get started, and the MIDI-to-CV example to learn how to use Bela as a MIDI to CV converter.

When connected by USB, Bela shows up as a MIDI device on your computer. This means you can send MIDI messages from Bela to your favourite DAW for controlling things like VSTs. You will find Bela listed among your MIDI devices.

Abstractions

Abstractions in Pure Data are a very useful way of creating reusable patches which can be easily shared between projects. In Pure Data these are normally patches which live in the same folder as the project file or in the externals folder.

If you find yourself in a situation where you are reusing the same abstractions and patches again and again in your Bela projects then there is a way to make them accessible to all your Pure Data projects without having to re-upload them each time.

First you will need to create a Pure Data project called pd-externals. Now any abstractions which end in .pd and externals which end in .pd_linux which you drop in there will be accessible from all your Pure Data projects. More information on how to compile externals for Bela can be found here.

Projects built using Pure Data and Bela

Our blog has dozens of great projects made with Pure Data and Bela. Here’s some of our favourites:

Pure Data resources

Pure Data has a huge and active online community.

Learning resources

Upload and explore patches

Useful tools

  • cyclone, a set of MaxMSP objects cloned in Pd
  • Bela.pd by Jack Armitage, a Bela-specific Pd library
  • instrument-maker by Charles Matthews, open source framework for digital instrument building with sensors