Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
registry.hpp
Go to the documentation of this file.
1#pragma once
2
3// Plugin registry — connects format adapters to processor factories.
4//
5// Two registration modes coexist:
6//
7// * Single-plugin bundle (the default, unchanged): one binary hosts one
8// plugin. `PULP_REGISTER_PLUGIN(factory)` sets a single global slot that
9// `registered_factory()` returns; the format adapters read it at
10// construction.
11//
12// * Multi-plugin bundle (Silent Way style): one binary hosts many plugins,
13// each exposed as its own component/class. Entries are registered with a
14// `PluginRegistration` (keyed by reverse-DNS id) and the per-component
15// entry macros bind each component to its OWN factory lexically, so no
16// global lookup happens on any instantiation path. The legacy global slot
17// is left null in this mode (a stray global read fails loudly rather than
18// silently building the wrong processor).
19//
20// Registration runs at static-init time, before the C++ runtime's own globals
21// are reliably constructed (AU bundles load registrars very early). Storage is
22// therefore a fixed-capacity array of trivially-copyable POD — no heap, no
23// std::string, and no logging on the registration path.
24
26
27#include <cstdint>
28#include <span>
29
30namespace pulp::format {
31
36 const char* id = nullptr;
38
39 // AU 4-char codes, 0 when not applicable. One plugin may be registered
40 // under multiple AU types (aumf + aumu + augn) — one entry per type, all
41 // sharing the same factory.
42 std::uint32_t au_type = 0;
43 std::uint32_t au_subtype = 0;
44 std::uint32_t au_manufacturer = 0;
45
46 // Per-plugin editor assets for multi-plugin bundles, where the binary-wide
47 // record (see editor_assets.hpp) cannot distinguish plugins. All null =
48 // fall back to the binary-wide record (the single-plugin path). A binary
49 // that sets ui_script here without declaring UI_SCRIPT on a target must
50 // call install_scripted_editor_builder() (editor_assets.hpp) once, or the
51 // editor logs the missing builder and opens AutoUi.
52 const char* ui_script = nullptr;
53 const char* ui_theme = nullptr;
54 const char* ui_asset_roots = nullptr;
55};
56
57// The legacy single global factory. Set once per single-plugin binary; returns
58// null in a multi-plugin bundle (see file header). Thread-safe: set at static
59// init, read at runtime.
61
62// Legacy single-plugin registration — sets the one global slot (last write
63// wins), exactly as before keyed registration existed. Multi-plugin bundles do
64// not use this overload: they register keyed entries and bind each component to
65// its own factory lexically, so their global slot stays null by construction.
66// (Use `PULP_REGISTER_PLUGIN` or call directly from a plugin entry.)
68
69// Keyed registration for multi-plugin bundles. Does not touch the global slot.
71
72// Look up a registered plugin by its reverse-DNS id. Null if not found.
73const PluginRegistration* find_plugin(const char* id);
74
75// All registered plugins, in registration order. Valid after static init.
76std::span<const PluginRegistration> registered_plugins();
77
78// Test-only: clear all registrations and the legacy global slot back to the
79// pristine static-init state. NOT for production use — registration is meant to
80// happen once at static init and never be torn down. Exists so a single test
81// binary can exercise the register/lookup/ambiguity logic deterministically
82// across multiple cases without one case's registrations leaking into the next.
84
85} // namespace pulp::format
86
87// Macro for plugin developers — place in ONE .cpp file per single-plugin bundle.
88#define PULP_REGISTER_PLUGIN(factory_fn) \
89 namespace { \
90 struct PulpPluginRegistrar { \
91 PulpPluginRegistrar() { ::pulp::format::register_plugin(factory_fn); } \
92 } _pulp_registrar; \
93 }
What the product grants a device: the quota table indexed by capability tier and live thermal state.
Definition aax_editor.hpp:31
std::unique_ptr< Processor >(*)() ProcessorFactory
Factory function type — plugins provide this to create processor instances.
Definition processor.hpp:1416
std::span< const PluginRegistration > registered_plugins()
ProcessorFactory & registered_factory()
void register_plugin(ProcessorFactory factory)
const PluginRegistration * find_plugin(const char *id)
void reset_registry_for_testing()
One registered plugin.
Definition registry.hpp:35
ProcessorFactory factory
Definition registry.hpp:37
std::uint32_t au_type
Definition registry.hpp:42
std::uint32_t au_manufacturer
Definition registry.hpp:44
const char * ui_script
Definition registry.hpp:52
const char * ui_asset_roots
Definition registry.hpp:54
std::uint32_t au_subtype
Definition registry.hpp:43
const char * ui_theme
Definition registry.hpp:53