Skip to main content

Overview

The pd::Instance class wraps libpd and provides a C++ interface for managing Pure Data instances. It handles DSP processing, MIDI events, message passing, patch loading, and communication between the GUI and the Pure Data audio engine. Location: Source/Pd/Instance.h

Class Declaration

Constructor and Initialization

constructor
Creates a new Pure Data instance. Each instance is isolated from others.
void
Initialize Pure Data and load required libraries. Call this before using the instance.

DSP Control

void
Prepare DSP processing with specified channel counts and sample rate.Parameters:
  • nins - Number of input channels
  • nouts - Number of output channels
  • samplerate - Sample rate in Hz
void
Start or stop DSP processing.
void
Process one block of audio. Call this from your audio callback.Parameters:
  • inputs - Interleaved input audio buffer
  • outputs - Interleaved output audio buffer
Buffer size is determined by getBlockSize().
int
Get Pure Data’s block size (typically 64 samples).

Sending MIDI to Pure Data

void
Send MIDI note on message.
void
Send MIDI control change message.
void
Send MIDI program change message.
void
Send MIDI pitch bend message (value range: 0-16383).
void
Send MIDI channel aftertouch message.
void
Send MIDI polyphonic aftertouch message.
void
Send raw MIDI bytes, SysEx, or real-time messages.

Receiving MIDI from Pure Data

These are pure virtual methods that must be implemented by subclasses:
virtual
Callbacks for MIDI messages coming from Pure Data (e.g., from [noteout], [ctlout], etc.).

Sending Messages to Pure Data

void
Send bang to a receiver.Example:
void
Send float value to a receiver.Example:
void
Send symbol to a receiver.Example:
void
Send list of atoms to a receiver.Example:
void
Send named message with arguments to a receiver.Example:
void
Send message directly to a specific Pure Data object (not by name).

Patch Management

Patch::Ptr
Open a Pure Data patch file. Returns a smart pointer to the loaded patch.Example:
SmallArray<pd::Patch::Ptr>
Array of all currently opened patches.

Message Listeners

void
Register/unregister listeners for messages from specific Pure Data objects.

Thread Safety

void
Lock/unlock the audio thread mutex. Use this when accessing Pure Data from the GUI thread.Example:
void
Enqueue a function to be executed safely from the message thread.Example:

Symbol Generation

t_symbol*
Generate a Pure Data symbol from a string. Symbols are interned (unique).

Console and Logging

void
Log messages to the plugdata console.
std::deque&
Access console message queues.

Virtual Methods (Must Implement)

virtual
Receive system messages from Pure Data.
virtual
Called when console needs updating.
virtual
Called when patch title changes.

Properties

void*
Pointer to the underlying libpd instance.
void*
Pure Data receiver for system messages.
void*
Pure Data receiver for parameter messages.
CriticalSection const
Mutex for thread-safe audio operations.

Usage Example

See Also

  • PluginProcessor - Inherits from pd::Instance
  • pd::Patch - Patch management
  • pd::Atom - Pure Data atom wrapper
  • MessageListener - Message listening interface