Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
After much refactoring, the first prototype of an Android port of Pd fell into five main pieces: Pd itself; a thin wrapper on top of Pd that turns it into an embeddable audio library; Java bindings for this library; some platform-specific glue that ties the Java bindings into the audio architecture of Android and provides some common utilities; and the top-level application code. This structure turned out to be highly versatile and applicable to a range of uses far beyond Android, and virtually all libpd-based applications adhere to the same layer model (Figure 4-1).
In the strictest sense, the term libpd only refers to the second layer (the library wrapper for Pd), but we will play fast and loose with the terminology and include language bindings and audio glue when we talk about libpd.
In this model, each layer only communicates with the layers immediately next to it. Pure Data is written in C, using custom datatypes. The libpd wrapper is also written in C, but its API uses standard datatypes as much as possible. In those few cases where libpd exposes pointers to a Pd-specific datatype, it also provides convenience functions that allow developers to treat those pointers as opaque, without requiring any knowledge of the underlying datatype. The language bindings do away with custom datatypes altogether and exclusively use built-in types of the target language, such as floats, strings, arrays, and lists.
We won’t be writing any code in this chapter, but if you want to
download a copy of libpd for closer examination, you can open a terminal
and say git clone
git://github.com/libpd/libpd.git. Keep in mind,
however, that in subsequent chapters we’ll pull in a separate copy of
libpd as a submodule of Android or iOS projects. If you clone libpd now,
you’ll have two copies of it later, and you’ll need to be careful not to
get them mixed up.