Skip to main content

A Cython wrapper for libpd (Pure Data) with built-in audio support

Project description

cypd: Cython wrapper for libpd

A Cython-based Python wrapper for libpd (Pure Data as an embeddable audio library) with built-in audio support via miniaudio.

Features

  • Full libpd API: Comprehensive access to libpd functionality including patches, messaging, arrays, MIDI, and callbacks
  • Built-in audio: Integrated miniaudio backend for easy audio playback
  • Flexible architecture: Use the built-in audio or integrate your own audio system
  • Thread-safe audio: Audio processing runs in a separate thread with proper nogil handling
  • Modern build system: Uses scikit-build-core with CMake

Installation

pip install cypd

Build from source

Prerequisites

  • Python 3.10+
  • uv (recommended) or pip
  • CMake 3.15+
  • C compiler (clang/gcc)
# Clone the repository
git clone https://github.com/shakfu/cypd.git
cd cypd

# Build libpd and miniaudio dependencies
./scripts/setup.sh

# Install with uv
uv sync

# Or install with pip
pip install -e .

Quick Start

Using the built-in audio

from cypd import audio

# Play a patch for 4 seconds
audio.play("my_patch.pd", "/path/to/patches", duration_ms=4000)

Manual control

import cypd
from cypd import audio

# Initialize libpd
cypd.init()
cypd.init_audio(1, 2, 44100)  # 1 input, 2 outputs, 44100 Hz

# Initialize audio backend
audio.init_audio(44100, 1, 2)

# Open a patch
patch_id = cypd.open_patch("my_patch.pd", "/path/to/patches")

# Start audio and enable DSP
audio.start()
cypd.dsp(True)

# Let it play
audio.sleep(4000)  # 4 seconds

# Cleanup
cypd.dsp(False)
audio.stop()
audio.terminate()
cypd.close_patch(patch_id)

Sending messages to Pure Data

import cypd

cypd.init()
patch_id = cypd.open_patch("my_patch.pd", ".")

# Send a bang
cypd.send_bang("my_receiver")

# Send a float
cypd.send_float("frequency", 440.0)

# Send a symbol
cypd.send_symbol("my_receiver", "hello")

# Send a list
cypd.send_list("my_receiver", 1, 2, 3, "foo", "bar")

# Send a typed message
cypd.send_message("my_receiver", "set", 1, 2, 3)

cypd.close_patch(patch_id)

Receiving messages from Pure Data

import cypd

def my_float_callback(receiver, value):
    print(f"Received float {value} from {receiver}")

def my_bang_callback(receiver):
    print(f"Received bang from {receiver}")

cypd.init()
cypd.set_float_callback(my_float_callback)
cypd.set_bang_callback(my_bang_callback)

# Subscribe to a sender
cypd.subscribe("my_sender")

# ... run your patch ...

cypd.unsubscribe("my_sender")

MIDI

import cypd

cypd.init()
patch_id = cypd.open_patch("my_synth.pd", ".")
cypd.init_audio(1, 2, 44100)

# Send MIDI note on (channel, pitch, velocity)
cypd.noteon(0, 60, 100)  # Middle C, velocity 100

# Send MIDI note off
cypd.noteon(0, 60, 0)  # velocity 0 = note off

# Control change
cypd.controlchange(0, 1, 64)  # Modulation wheel

# Pitch bend
cypd.pitchbend(0, 0)  # Center position

cypd.close_patch(patch_id)

Array access

import cypd

cypd.init()
patch_id = cypd.open_patch("with_array.pd", ".")

# Get array size
size = cypd.array_size("my_array")
print(f"Array size: {size}")

# Resize array
cypd.resize_array("my_array", 1024)

cypd.close_patch(patch_id)

API Reference

Initialization

  • init() - Initialize libpd
  • init_audio(in_channels, out_channels, sample_rate) - Initialize audio rendering
  • release() - Shutdown libpd and release resources

Patches

  • open_patch(name, dir) - Open a patch, returns patch ID
  • close_patch(patch_id) - Close a patch
  • add_to_search_path(path) - Add to abstraction search path
  • clear_search_path() - Clear the search path

Audio

  • get_blocksize() - Get pd's block size (always 64)
  • dsp(on) - Enable/disable DSP processing

Messaging

  • send_bang(receiver) - Send a bang
  • send_float(receiver, value) - Send a float
  • send_symbol(receiver, symbol) - Send a symbol
  • send_list(receiver, *args) - Send a list
  • send_message(receiver, msg, *args) - Send a typed message
  • subscribe(source) - Subscribe to messages from a sender
  • unsubscribe(source) - Unsubscribe from a sender
  • exists(receiver) - Check if a receiver exists

Callbacks

  • set_print_callback(func) - Set print hook
  • set_bang_callback(func) - Set bang receive hook
  • set_float_callback(func) - Set float receive hook
  • set_symbol_callback(func) - Set symbol receive hook
  • set_list_callback(func) - Set list receive hook
  • set_message_callback(func) - Set typed message receive hook

MIDI

  • noteon(channel, pitch, velocity) - Send note on
  • controlchange(channel, controller, value) - Send control change
  • programchange(channel, value) - Send program change
  • pitchbend(channel, value) - Send pitch bend
  • aftertouch(channel, value) - Send aftertouch
  • polyaftertouch(channel, pitch, value) - Send poly aftertouch

Arrays

  • array_size(name) - Get array size
  • resize_array(name, size) - Resize an array

Audio Module (cypd.audio)

  • init_audio(sample_rate, channels_in, channels_out) - Initialize miniaudio
  • start() - Start audio playback
  • stop() - Stop audio playback
  • terminate() - Shutdown audio
  • is_running() - Check if audio is running
  • sleep(milliseconds) - Sleep for duration
  • play(patch, dir, duration_ms, ...) - Convenience function to play a patch
  • get_version() - Get miniaudio version string

Development

# Run tests
make test

# Build
make build

# Clean
make clean

Architecture

The project consists of two Cython extension modules:

  • _libpd: Core libpd wrapper providing the full API
  • _audio: Miniaudio-based audio backend

The _audio module obtains a function pointer to libpd_process_float from _libpd at runtime, ensuring both modules share the same libpd instance (avoiding issues with static library symbol duplication).

License

See LICENSE file.

Acknowledgments

  • libpd - Pure Data as an embeddable library
  • miniaudio - Single-file audio playback and capture library
  • Pure Data - The original visual programming language for audio

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cypd-0.1.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cypd-0.1.0-cp314-cp314t-macosx_11_0_arm64.whl (884.8 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

cypd-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cypd-0.1.0-cp314-cp314-macosx_15_0_arm64.whl (893.0 kB view details)

Uploaded CPython 3.14macOS 15.0+ ARM64

cypd-0.1.0-cp314-cp314-macosx_11_0_arm64.whl (871.6 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

cypd-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cypd-0.1.0-cp313-cp313-macosx_15_0_arm64.whl (891.5 kB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

cypd-0.1.0-cp313-cp313-macosx_11_0_arm64.whl (870.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

cypd-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cypd-0.1.0-cp312-cp312-macosx_15_0_arm64.whl (892.7 kB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

cypd-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (872.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

cypd-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cypd-0.1.0-cp311-cp311-macosx_15_0_arm64.whl (892.9 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

cypd-0.1.0-cp311-cp311-macosx_11_0_arm64.whl (875.2 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

cypd-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cypd-0.1.0-cp310-cp310-macosx_15_0_arm64.whl (893.3 kB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

cypd-0.1.0-cp310-cp310-macosx_11_0_arm64.whl (875.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

cypd-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

cypd-0.1.0-cp39-cp39-macosx_11_0_arm64.whl (875.7 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file cypd-0.1.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2b86964ff33744943bd56bf67fccf2d487ad64a7ea6dd59f6b1bb2b216869a44
MD5 d19625bcc1f12dcfc248c7d5d12d70b3
BLAKE2b-256 79fbb9b0c9ff6bb192847ae2deb7b0ed418a883a31d2f969b4668bcdd2969487

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c99c9fbb4e7393b1f3df416ac4eb432cf19f7f71146804f8778a91ef50bb66dc
MD5 f80c2fe9a05cc9c65383e471d969059d
BLAKE2b-256 a8e82a1f853dce1157718283fd44423023b7ec639e41d153f8d375f98c575502

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3914e483736fb1692ad65959bb580771e623265ec76265dd3f760510114872c3
MD5 951a513d378ba41dfc2429d70ccef356
BLAKE2b-256 834c2d01be8f8933e80cf1f94c53a61e0cddbe70d57bdfa7b911ba8bf6338b9d

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp314-cp314-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp314-cp314-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 1c6860e4b9ff5ddbed1565ca4e86701698f489efca32ac368f5b76a5154d7f43
MD5 8fc3fe1fb7f3666c3e9535dcc5ab8d45
BLAKE2b-256 5d44fb39290f29650115b23957592c6355b2452ade613a938595c3b48ce114d5

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6f21613aeaf990456c4d8e18742fa141af7c5cdbc92279be0cd67cfca6d27d7
MD5 0b3e526a121625ee85f53efdc9587803
BLAKE2b-256 1ade4f266b51ddcaa7079af9f75415cf922709132fc45e76a2b9271b26dd1f5f

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f9fb28c4ebac48d6977979693b812b959ac33c369110a5743564d0edd434953a
MD5 80a276b2e7e0aa7939de41d76d8672d4
BLAKE2b-256 03f236ff770caab57102577c9015a4037f9ca1d13cc9be5cfffa480e383a1576

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 6d08a5f4f1ae56b4951ebf5564a0fccd7be0e854b9961a1d6486ccd13605de82
MD5 cb38816f6ac3c48570226868987953f8
BLAKE2b-256 51f3d100798bc5813fdcb0d033e4123336f89a8dc04811a8b12468e517301f17

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f99c83b6bab4e798bc67acb46b0d3e0db969a7466dbce52957f715820021b406
MD5 4d0c11525334d169136c7357183032dc
BLAKE2b-256 2b569477252079815197a585da691a36dc84d95ed2bd8c5c1ff455ab378dcf2b

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 99f958b19a1d0f97b942b86337d3a07bba7e722e10858fa769528f1dd9b5c827
MD5 426d1f84b4865de701ab9e33e05816ea
BLAKE2b-256 6ddd26d786b436d672be59d3990165b9657918a7a834edd705d19e00c6fdaf1e

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5425501688aed402fa1bb8df230f36f3ac409ab08fcab6ed2900b0c355a437f6
MD5 82853caec7dd8bd0a20cbe47e79c98a3
BLAKE2b-256 35f8e76bef15b95714c6e2f8ce5446e498b163711794f30fbb4e9ddaa43d5af2

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b9466de61b91088145e7daca30f5d06398b463fdef2c9233493f73b6ba14931a
MD5 6aa276f8ddd01e24a28350cf82af2b7e
BLAKE2b-256 083716241b49422dab72e46ebccbafd34b95f3cd6a0ddf95fb7e2295a15f5c53

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f7d75889dcf658b9cb3c8879abb6f2ab462630877e806844b8401429cbe4acbf
MD5 e1c23a88738bf42170720d7feb632664
BLAKE2b-256 f522c548719060bbfb022570b8236aba828b1bcd5a41814f68eb89acf6fa8802

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 7dd3553996c8340ad005d3b7cadd6696105bf09116fc5f614eec6ff8e8bb3bc0
MD5 b3da8570715c95be1b90a96606768534
BLAKE2b-256 ae187d4d9d91e522532668bfbe7a1725f320dc4f7cee35e65cb9532db55f1e32

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c0d144c69365d06cc8e682fd14cf85f04898943a661942616cbe9d79f2c85533
MD5 3c947b95964ee281d0c9906c25561649
BLAKE2b-256 c901b86c4c36d2747bc65544d1409300f49bede735ed56236d51135ee98cab0f

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 123b6cf3343485a1df21d723d90a589d7466ae3f8096735323bf10b2efeef82e
MD5 42c0d3e5f3f7286bd087a4133757292d
BLAKE2b-256 b46082f5061ed38b18fb033286210f44045b63909b4063f49550cab6daaf0d4f

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 57b7b11b6f3a682e25c55abef6fc01e24e8115644898184ffed3847ed84d77cf
MD5 efef7096c8cd28bd6b157e92181108be
BLAKE2b-256 1c38c345c0bc5374d4bc9040a5006dbc652c8ce6b2536d538b8482fcff9e8323

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ec695e0f2f927aab13556529376d75e3d2ac8a4e579f6737d439797340a1dedf
MD5 8a83d0cf119b5862454078cbbc3fcbb8
BLAKE2b-256 253cf79760e17903758be2eb504ae0cd2109671f06c2c06751b4f65590b43ed4

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for cypd-0.1.0-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cd343b0f5dc339074024b8af1f35c875c66b8de93016864a9ed3264a84e135ee
MD5 132c4916f455148ac3452e7ce952988f
BLAKE2b-256 060c656c664538f7cb964529e3b89d04b526fcbf2d8a92f5540418d7e913d76a

See more details on using hashes here.

File details

Details for the file cypd-0.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: cypd-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 875.7 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for cypd-0.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 66f58c109e151d7c73c2e5caeeeda52db81f3624e93151ee57228bc2a68f8590
MD5 9619a3a61a929c4390579675e652b8e4
BLAKE2b-256 54d7abbbf1317cf67d8a9bad334ae81cc2d22813b5485744fa9513e97c7462f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page