Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
native_core_processor.hpp
Go to the documentation of this file.
1// pulp/format/native_core_processor.hpp
2//
3// A C++ `pulp::format::Processor` that owns a native-language DSP core through
4// the language-neutral C ABI (pulp/native_components/native_core.h). This is
5// the SDK seam for native-language DSP cores: a Rust / C / Zig core
6// implements the C ABI vtable; this adapter translates Pulp's C++ Processor
7// surface (StateStore params, ParameterEventQueue, BufferView, state blobs)
8// into the POD FFI structs and back.
9//
10// The adapter itself has NO Rust dependency — it bridges any core that exports a
11// `pulp_native_core_v1`. It is part of `pulp-format` and always builds; the Rust
12// binding + reference cores are the separate opt-in lane.
13//
14// RT-safety: all scratch (channel-pointer arrays, the native param-event buffer)
15// is allocated in prepare(); process() does no allocation, locking, or logging.
16#pragma once
17
19
20#include <pulp/audio/buffer.hpp>
22#include <pulp/midi/buffer.hpp>
23#include <pulp/state/store.hpp>
24
25#include <atomic>
26#include <cstdint>
27#include <optional>
28#include <string>
29#include <string_view>
30#include <vector>
31
32namespace pulp::format {
33
41public:
48
51
52 PluginDescriptor descriptor() const override;
53 void define_parameters(state::StateStore& store) override;
54 void prepare(const PrepareContext& context) override;
55 void release() override;
56 void suspend() override;
57 void resume() override;
59 const audio::BufferView<const float>& audio_input,
60 midi::MidiBuffer& midi_in,
61 midi::MidiBuffer& midi_out,
62 const ProcessContext& context) override;
63 std::vector<uint8_t> serialize_plugin_state() const override;
64 bool deserialize_plugin_state(std::span<const uint8_t> data) override;
65 int latency_samples() const override;
66 // The native core receives every automation point with its offset.
67 bool wants_sample_accurate_parameters() const override {
68 return true;
69 }
70
80 std::optional<std::string> editor_command(std::string_view request_json);
81
84 bool valid() const { return instance_ != nullptr; }
85
86private:
87 // Host-service callbacks handed to the core. `ctx` is always `this`.
88 static void* host_alloc(void* ctx, std::size_t bytes);
89 static void host_free(void* ctx, void* ptr);
90 static void host_log(void* ctx, int32_t level, const char* utf8, std::size_t len);
91 static int32_t host_push_midi_out(void* sink, const pulp_native_midi_event_v1* ev);
92 static void host_notify_latency_changed(void* ctx);
93
94 const pulp_native_core_v1* core_ = nullptr;
95 pulp_native_instance* instance_ = nullptr;
97
98 // Native parameter id-hash per Pulp ParamID (ParamID == registration index).
99 std::vector<uint64_t> paramid_to_hash_;
100
101 // Preallocated process() scratch (filled per block, never resized in RT).
102 std::vector<float*> in_ptrs_;
103 std::vector<float*> out_ptrs_;
104 std::vector<pulp_native_audio_bus_v1> in_buses_;
105 std::vector<pulp_native_audio_bus_v1> out_buses_;
106 std::vector<pulp_native_param_event_v1> event_scratch_;
107
108 PrepareContext prepare_ctx_{};
109 bool prepared_ = false;
110 std::atomic<bool> latency_changed_{false};
111};
112
113} // namespace pulp::format
Non-owning view over multi-channel audio sample data.
Definition buffer.hpp:30
void resume() override
Resume processing after a prior suspend().
bool valid() const
True once a compatible core instance was created.
Definition native_core_processor.hpp:84
NativeCoreProcessor(const pulp_native_core_v1 *core)
int latency_samples() const override
Latency in samples introduced by this processor (default 0).
bool wants_sample_accurate_parameters() const override
Whether this processor reads sample-accurate parameter automation: param_events(),...
Definition native_core_processor.hpp:67
std::vector< uint8_t > serialize_plugin_state() const override
Serialize plugin-owned state that is not part of StateStore.
void process(audio::BufferView< float > &audio_output, const audio::BufferView< const float > &audio_input, midi::MidiBuffer &midi_in, midi::MidiBuffer &midi_out, const ProcessContext &context) override
Process one buffer of audio.
void define_parameters(state::StateStore &store) override
Register parameters with the state store.
bool deserialize_plugin_state(std::span< const uint8_t > data) override
Restore plugin-owned state previously returned by serialize_plugin_state().
NativeCoreProcessor(const NativeCoreProcessor &)=delete
void release() override
Release resources.
NativeCoreProcessor & operator=(const NativeCoreProcessor &)=delete
void prepare(const PrepareContext &context) override
Prepare for processing.
std::optional< std::string > editor_command(std::string_view request_json)
Non-RT (host/UI thread) command channel into the native core's domain logic: send a JSON request,...
PluginDescriptor descriptor() const override
Return the plugin's metadata. Called once during initialization.
void suspend() override
Pause processing for a heavy main-thread operation (preset load, convolution kernel reallocation,...
Processor()
Definition processor.hpp:176
Collection of timestamped MIDI events within a single audio buffer period.
Definition buffer.hpp:31
Centralized parameter storage with lock-free value access.
Definition store.hpp:164
What the product grants a device: the quota table indexed by capability tier and live thermal state.
Definition aax_editor.hpp:31
struct pulp_native_instance pulp_native_instance
Definition native_core.h:355
Plugin metadata — declared once, immutable.
Definition plugin_descriptor.hpp:245
Definition prepare_resources.hpp:102
Process context — passed every audio callback with transport state.
Definition process_context.hpp:89
Definition native_core.h:357
Definition native_core.h:331
Definition native_core.h:206