Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
native_core.hpp
Go to the documentation of this file.
1// pulp/native_components/native_core.hpp — C++ conveniences over the C ABI.
2//
3// This header adds NOTHING to the ABI. It is optional sugar for the C++ side
4// of the boundary: the canonical contract is native_core.h. Everything here is
5// header-only, constexpr/inline, and must never appear in a struct that crosses
6// the FFI.
7#pragma once
8
10
11#include <cstddef>
12#include <cstdint>
13#include <string_view>
14#include <type_traits>
15
17
18inline constexpr std::uint32_t kAbiVersion = PULP_NATIVE_CORE_ABI_VERSION;
19
20// FNV-1a (64-bit) over UTF-8 id bytes — the SINGLE definition of parameter
21// identity hashing for both the host and any binding generator. Case-sensitive,
22// computed over the exact byte sequence. Must match the algorithm documented in
23// native_core.h (offset basis 0xcbf29ce484222325, prime 0x100000001b3).
24inline constexpr std::uint64_t param_id_hash(std::string_view id) noexcept {
25 std::uint64_t h = 0xcbf29ce484222325ULL;
26 for (char c : id) {
27 h ^= static_cast<std::uint64_t>(static_cast<unsigned char>(c));
28 h *= 0x100000001b3ULL;
29 }
30 return h;
31}
32
33// True when a vtable advertises a compatible ABI. Additive growth is tolerated:
34// a newer host accepts an older, smaller `size` as long as the major
35// abi_version matches (decision 5).
36inline bool is_compatible(const pulp_native_core_v1* core) noexcept {
37 return core != nullptr && core->abi_version == kAbiVersion &&
38 core->size >= offsetof(pulp_native_core_v1, descriptor);
39}
40
41// Every type that crosses the boundary must be a C-compatible POD: standard
42// layout (stable field offsets) and trivially copyable (memcpy-safe). If any of
43// these fire, the struct grew a non-POD member and the ABI is no longer C.
44static_assert(std::is_standard_layout_v<pulp_native_descriptor_v1>);
45static_assert(std::is_trivially_copyable_v<pulp_native_descriptor_v1>);
46static_assert(std::is_standard_layout_v<pulp_native_param_v1>);
47static_assert(std::is_trivially_copyable_v<pulp_native_param_v1>);
48static_assert(std::is_standard_layout_v<pulp_native_param_event_v1>);
49static_assert(std::is_trivially_copyable_v<pulp_native_param_event_v1>);
50static_assert(std::is_standard_layout_v<pulp_native_param_event_view_v1>);
51static_assert(std::is_standard_layout_v<pulp_native_audio_bus_v1>);
52static_assert(std::is_standard_layout_v<pulp_native_audio_io_v1>);
53static_assert(std::is_standard_layout_v<pulp_native_midi_event_v1>);
54static_assert(std::is_standard_layout_v<pulp_native_midi_view_v1>);
55static_assert(std::is_standard_layout_v<pulp_native_state_span_v1>);
56static_assert(std::is_standard_layout_v<pulp_native_state_out_v1>);
57static_assert(std::is_standard_layout_v<pulp_native_bus_layout_v1>);
58static_assert(std::is_standard_layout_v<pulp_native_prepare_v1>);
59static_assert(std::is_standard_layout_v<pulp_native_process_context_v1>);
60static_assert(std::is_standard_layout_v<pulp_native_process_v1>);
61static_assert(std::is_standard_layout_v<pulp_native_host_services_v1>);
62static_assert(std::is_standard_layout_v<pulp_native_core_v1>);
63
64} // namespace pulp::native_components
Definition native_core.hpp:16
constexpr std::uint64_t param_id_hash(std::string_view id) noexcept
Definition native_core.hpp:24
bool is_compatible(const pulp_native_core_v1 *core) noexcept
Definition native_core.hpp:36
constexpr std::uint32_t kAbiVersion
Definition native_core.hpp:18
#define PULP_NATIVE_CORE_ABI_VERSION
Definition native_core.h:56
Definition native_core.h:357