Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
compile_context_registry.hpp
Go to the documentation of this file.
1#pragma once
2
9
10#include <array>
11#include <cstddef>
12#include <cstdint>
13#include <memory>
14#include <optional>
15#include <span>
16#include <string>
17#include <string_view>
18#include <vector>
19
20namespace pulp::playback {
21
22namespace detail {
23struct CompileInvalidationData;
24struct ContextRegistryGeneration;
25} // namespace detail
26
29enum class ContentProgramOutputKind : std::uint8_t { Notes };
30
34enum class RegisteredRendererStatePolicy : std::uint8_t { Reset, CarryByItemId };
35
42 std::uint16_t velocity = 0xffff;
43 std::uint8_t pitch = 60;
44 std::uint8_t channel = 0;
45 constexpr auto operator<=>(const ContentFragmentNote&) const = default;
46};
47
52
57
59class ContentProgramFragment {
60 public:
62 create(std::vector<ContentFragmentNote> notes, timebase::TickDuration clip_duration) noexcept;
63
64 std::span<const ContentFragmentNote> notes() const noexcept {
65 return *notes_;
66 }
67
68 private:
70 std::shared_ptr<const std::vector<ContentFragmentNote>> notes) noexcept
71 : notes_(std::move(notes)) {}
72 std::shared_ptr<const std::vector<ContentFragmentNote>> notes_;
73};
74
85
86// A hook invocation is one trusted atomic compile work unit: it must not block
87// or perform unbounded work, and it must honor maximum_fragment_notes. The
88// compiler checks the returned size before admission; the registry-wide 4096
89// ceiling bounds valid fragment construction even though arbitrary hook code
90// cannot be preempted from inside this function-pointer ABI.
93 const RegisteredContentCompileInput& input, const void* context) noexcept;
94
104 std::string content_type_name;
106 // Zero plus a null hook is the legacy subscription-only declaration. It is
107 // intentionally unresolved at compile time, not silently rendered.
108 std::uint32_t schema_version = 0;
110 std::size_t maximum_fragment_notes = 0;
113 std::shared_ptr<const void> compile_context;
115 // Filled by the validated declare overload. Dispatch compares this opaque
116 // codec provenance with RegisteredContent before any value_as<T>() call.
117 std::shared_ptr<const void> schema_registry_identity;
118};
119
133
138
149 public:
150 static constexpr std::size_t kMaxRegistrations = 1024;
151 static constexpr std::size_t kMaximumFragmentNotesPerClip = 4096;
152
158
160 std::optional<ContextRegistrationError> declare(ContentRendererRegistration registration);
161
165 std::optional<ContextRegistrationError> declare(ContentRendererRegistration registration,
166 const timeline::SchemaRegistry& schemas);
167
172 subscriptions_for(std::string_view content_type_name) const noexcept;
173
177 const ContentRendererRegistration* find(const timeline::SchemaIdentity& schema) const noexcept;
179 find(const timeline::RegisteredContent& content) const noexcept;
180
181 std::size_t size() const noexcept {
182 return registrations_.size();
183 }
184
192 std::uint64_t revision() const noexcept;
193 std::shared_ptr<const void> generation_identity() const noexcept {
194 return snapshot_generation_ ? snapshot_generation_ : generation_;
195 }
196
197 private:
201
205 std::shared_ptr<const CompileContextRegistry> immutable_snapshot() const;
206
207 // Sorted by content_type_name so lookup is a binary search on a hot path.
208 std::vector<ContentRendererRegistration> registrations_;
209 std::shared_ptr<detail::ContextRegistryGeneration> generation_;
210 std::shared_ptr<const detail::ContextRegistryGeneration> snapshot_generation_;
211 std::optional<std::uint64_t> snapshot_revision_;
212};
213
226 public:
228 timeline::ItemId sequence_id,
229 const CompileContextRegistry& registry);
230
233 std::span<const timeline::ItemId> subscribers(timeline::CompileContextKind kind) const noexcept;
234
237 std::span<const timeline::ItemId> subscribers(timeline::ItemId owner_sequence,
238 timeline::CompileContextKind kind) const noexcept;
239
240 bool empty() const noexcept;
241
242 bool valid() const noexcept;
243 bool matches(const timeline::Project& project,
244 timeline::ItemId root_sequence_id) const noexcept;
245
246 private:
247 friend DirtyTrackSet resolve_dirty_tracks(const timeline::Project&, timeline::ItemId,
248 const timeline::DirtySet&,
250
251 std::shared_ptr<const detail::CompileInvalidationData> data_;
252};
253
254} // namespace pulp::playback
The declaration side of the compile-context subscription contract.
Definition compile_context_registry.hpp:148
std::optional< ContextRegistrationError > declare(ContentRendererRegistration registration)
Returns the refusal, or nothing when the registration was accepted.
const ContentRendererRegistration * find(const timeline::RegisteredContent &content) const noexcept
CompileContextRegistry(CompileContextRegistry &&other)
friend class CompileInvalidationIndex
Definition compile_context_registry.hpp:198
std::size_t size() const noexcept
Definition compile_context_registry.hpp:181
static constexpr std::size_t kMaxRegistrations
Definition compile_context_registry.hpp:150
std::shared_ptr< const void > generation_identity() const noexcept
Definition compile_context_registry.hpp:193
static constexpr std::size_t kMaximumFragmentNotesPerClip
Definition compile_context_registry.hpp:151
timeline::CompileContextSubscriptions subscriptions_for(std::string_view content_type_name) const noexcept
What the renderer for content_type_name declared.
CompileContextRegistry & operator=(CompileContextRegistry &&other)
const ContentRendererRegistration * find(const timeline::SchemaIdentity &schema) const noexcept
Finds the exact schema-version registration.
CompileContextRegistry & operator=(const CompileContextRegistry &other)
std::uint64_t revision() const noexcept
Monotonic version within this registry generation's declarations.
friend class PlaybackProgramCompiler
Definition compile_context_registry.hpp:199
CompileContextRegistry(const CompileContextRegistry &other)
friend struct CompileInvalidationInput
Definition compile_context_registry.hpp:200
std::optional< ContextRegistrationError > declare(ContentRendererRegistration registration, const timeline::SchemaRegistry &schemas)
Declares a trusted compiler after proving its exact Content schema and codec exist in the immutable s...
Bundled reverse index for nested dependencies and compile-context readers.
Definition compile_context_registry.hpp:225
static CompileInvalidationIndex build(const timeline::Project &project, timeline::ItemId sequence_id, const CompileContextRegistry &registry)
std::span< const timeline::ItemId > subscribers(timeline::CompileContextKind kind) const noexcept
Sorted, deduplicated track ids that declared a read of kind.
std::span< const timeline::ItemId > subscribers(timeline::ItemId owner_sequence, timeline::CompileContextKind kind) const noexcept
Sorted, deduplicated root track ids that read kind from owner_sequence.
bool matches(const timeline::Project &project, timeline::ItemId root_sequence_id) const noexcept
friend DirtyTrackSet resolve_dirty_tracks(const timeline::Project &, timeline::ItemId, const timeline::DirtySet &, const CompileInvalidationIndex &)
Canonical translation from transaction dirtiness to root-track compiler dirtiness.
Owned immutable note output from one off-realtime compile-hook invocation.
Definition compile_context_registry.hpp:59
std::span< const ContentFragmentNote > notes() const noexcept
Definition compile_context_registry.hpp:64
static runtime::Result< ContentProgramFragment, ContentFragmentError > create(std::vector< ContentFragmentNote > notes, timebase::TickDuration clip_duration) noexcept
Result<T, E> — either holds a T or an E, never both.
Definition result.hpp:76
The declared set of context kinds one content renderer reads.
Definition compile_context.hpp:67
The read side of the contract: a read-only window onto one pinned snapshot's context,...
Definition compile_context.hpp:123
Immutable root of a Timeline document and its monotonic identity domain.
Definition model.hpp:1079
Extension-defined typed C++ content admitted by a SchemaRegistry.
Definition clip.hpp:329
Immutable, shareable registry of Timeline schema contracts.
Definition schema_registry.hpp:189
CompileContextKind
A kind of timeline context a renderer's compile hook may read beyond its own clip's content.
Definition compile_context.hpp:46
Definition automation_program.hpp:17
Definition audio_renderer.hpp:20
runtime::Result< ContentProgramFragment, ContentFragmentError >(*)( const RegisteredContentCompileInput &input, const void *context) noexcept RegisteredContentCompileFn
Definition compile_context_registry.hpp:91
RegisteredRendererStatePolicy
Registered note fragments currently admit Reset only.
Definition compile_context_registry.hpp:34
@ CarryByItemId
Definition compile_context_registry.hpp:34
@ Reset
Definition compile_context_registry.hpp:34
ContextRegistrationErrorCode
Definition compile_context_registry.hpp:120
@ InvalidSchemaVersion
Definition compile_context_registry.hpp:124
@ InvalidFragmentQuota
Definition compile_context_registry.hpp:127
@ EmptyContentTypeName
Definition compile_context_registry.hpp:121
@ InvalidProductionDeclaration
Definition compile_context_registry.hpp:128
@ MissingCompileHook
Definition compile_context_registry.hpp:129
@ SchemaUnavailable
Definition compile_context_registry.hpp:125
@ DuplicateContentType
Definition compile_context_registry.hpp:122
@ InvalidOutputKind
Definition compile_context_registry.hpp:130
@ InvalidStatePolicy
Definition compile_context_registry.hpp:131
@ SchemaCodecUnavailable
Definition compile_context_registry.hpp:126
ContentProgramOutputKind
The immutable program-fragment family emitted by a registered compiler.
Definition compile_context_registry.hpp:29
@ Notes
Definition compile_context_registry.hpp:29
@ CapacityExceeded
Definition audio_renderer.hpp:38
ContentFragmentErrorCode
Definition compile_context_registry.hpp:48
@ InvalidNote
Definition compile_context_registry.hpp:50
@ RendererFailed
Definition compile_context_registry.hpp:49
Definition program_compiler.hpp:18
STL namespace.
How content is produced, and how honestly a render of it can be replayed.
Result<T, E> — success / failure union for fallible operations.
Definition compile_context_registry.hpp:53
ContentFragmentErrorCode code
Definition compile_context_registry.hpp:54
std::size_t note_index
Definition compile_context_registry.hpp:55
One musical note emitted by a registered content compiler.
Definition compile_context_registry.hpp:39
std::uint8_t pitch
Definition compile_context_registry.hpp:43
timebase::TickDuration duration
Definition compile_context_registry.hpp:41
std::uint16_t velocity
Definition compile_context_registry.hpp:42
std::uint8_t channel
Definition compile_context_registry.hpp:44
constexpr auto operator<=>(const ContentFragmentNote &) const =default
timebase::TickPosition start
Definition compile_context_registry.hpp:40
One content renderer's registration, reduced to the part the dirty set depends on: which content kind...
Definition compile_context_registry.hpp:103
RegisteredContentCompileFn compile
Definition compile_context_registry.hpp:114
timeline::CompileContextSubscriptions subscriptions
Definition compile_context_registry.hpp:105
std::shared_ptr< const void > compile_context
Definition compile_context_registry.hpp:113
RegisteredRendererStatePolicy state_policy
Definition compile_context_registry.hpp:111
std::string content_type_name
Definition compile_context_registry.hpp:104
std::shared_ptr< const void > schema_registry_identity
Definition compile_context_registry.hpp:117
std::uint32_t schema_version
Definition compile_context_registry.hpp:108
ContentProgramOutputKind output_kind
Definition compile_context_registry.hpp:109
timeline::ProductionDeclaration production
Definition compile_context_registry.hpp:112
std::size_t maximum_fragment_notes
Definition compile_context_registry.hpp:110
Definition compile_context_registry.hpp:134
std::string content_type_name
Definition compile_context_registry.hpp:136
ContextRegistrationErrorCode code
Definition compile_context_registry.hpp:135
Definition dirty_track_resolver.hpp:9
Bounded input presented to a trusted compiler hook on the compile worker.
Definition compile_context_registry.hpp:77
timebase::TickPosition context_start
Definition compile_context_registry.hpp:81
timebase::TickDuration clip_duration
Definition compile_context_registry.hpp:80
const timeline::RegisteredContent & content
Definition compile_context_registry.hpp:78
std::size_t maximum_fragment_notes
Definition compile_context_registry.hpp:83
timeline::CompileContextView context
Definition compile_context_registry.hpp:82
timeline::ItemId clip_id
Definition compile_context_registry.hpp:79
Definition tick.hpp:56
Definition tick.hpp:61
Nonzero monotonic identity for a Timeline-owned object.
Definition item_id.hpp:19
What a piece of content declares about its own production.
Definition production_mode.hpp:88
Versioned extension-schema identity.
Definition clip.hpp:102