$ show sebpiq/WebPd
WebPd is a compiler and runtime system that translates Pure Data (Pd) audio patches into JavaScript or WebAssembly, enabling real-time audio synthesis and processing in web browsers and Node.js environments. The codebase is structured as a TypeScript monorepo with a CLI tool (`webpd`), a browser runtime using AudioWorklet, and a comprehensive library of Pd object implementations (147+ objects). The core compilation pipeline parses `.pd` files, resolves abstractions, optimizes DSP graphs, and generates self-contained output formats including `.js`, `.wasm`, `.wav`, and standalone HTML apps. The architecture is modular: the `src/nodes/` directory contains individual builder and runtime implementations for each Pd object (osc~, dac~, filters, delay lines, message objects, etc.), all following a consistent `NodeBuilder` pattern with `translateArgs` and `build` methods. The compiler (`src/compile-dsp-graph/`) handles graph transformations like implicit signal mixing and message-to-signal conversion. The runtime layer (`src/environments/browser/`) provides initialization, AudioWorklet integration, and message passing between JavaScript and the compiled patch. The codebase demonstrates strong engineering practices with extensive parameterized tests that verify both JavaScript and WebAssembly outputs against golden fixtures. However, it is in alpha status (v1.0.0-alpha.14) with many incomplete features (e.g., `readsf~` state machine, `list` operations, `expr` if-form) and several TODO comments. The project relies on internal packages (`@webpd/compiler`, `@webpd/pd-parser`) that require coordinated builds, and some generated code strings are embedded in runtime files, creating potential maintenance friction. Despite these caveats, the compiler design, test infrastructure, and Pd compatibility are noteworthy.
The LLM identified 6 files worth highlighting for reuse:
Provides core runtime utilities for Pd objects: `bangUtils` (bang message handling), `msgUtils` (message parsing/sending), and helper functions for signal and message processing. This module is injected as a dependency into generated code and is reusable for implementing Pd-compatible audio/message nodes in any JavaScript or WebAssembly project.
Core compiler module that converts a resolved Pd patch JSON into a DSP graph representation. It recursively traverses subpatches, resolves connections, and implicitly inserts nodes for signal mixing (`_mixer~`), message-to-signal conversion (`sig~`), and message routing (`_routemsg`). This pattern of automatic node insertion for implicit behavior is reusable for any audio graph compiler targeting message/signal duality.
Exports `proxyAsModuleWithBindings` and `proxyWithEngineNameMapping` – a generic proxy-based binding system that maps raw compiled module exports (JavaScript or WebAssembly) to a user-friendly API. It handles function naming, parameter lifting/lowering, and serialization between JS and WASM memory. This pattern is reusable for any project that needs to wrap compiled code with a clean JavaScript interface.
Provides geometry utilities for Pure Data GUI: `makeTranslationTransform`, `sumPoints`, `computeRectanglesIntersection`, `isPointInsideRectangle`, and rectangle overlap detection. These functions are self-contained, pure math operations with no dependencies, making them reusable for any 2D canvas or SVG layout system that needs hit-testing and coordinate transforms.
Defines standard cold inlet message receivers (`coldFloatInlet`, `coldStringInlet`, `coldFloatInletWithSetter`) used across many Pd objects. These encapsulate the pattern of handling a float or symbol message at a cold inlet with optional state setter. The pattern is reusable for any audio/message node system that needs consistent inlet behavior.
Provides test utilities including `NODE_IMPLEMENTATION_TEST_PARAMETERS` (parameterization over targets and bit depths), `buildNode`, `testNodeTranslateArgs`, `testNodeBuild`, and helpers for generating test graphs and frames. This enables running the same test suite against both JavaScript and WebAssembly compiled outputs, a reusable pattern for cross-platform audio DSP testing.