Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
compile_context.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <cstddef>
6#include <cstdint>
7#include <limits>
8#include <optional>
9
10namespace pulp::timeline {
11
15
58
60inline constexpr std::size_t kCompileContextKindCount = 5;
61
68 public:
70 constexpr CompileContextSubscriptions() noexcept = default;
71
73 static constexpr CompileContextSubscriptions none() noexcept {
74 return {};
75 }
76
79 bits_ = static_cast<Bits>(bits_ | mask(kind));
80 return *this;
81 }
82
84 constexpr bool reads(CompileContextKind kind) const noexcept {
85 return (bits_ & mask(kind)) != 0;
86 }
87
89 constexpr bool any() const noexcept {
90 return bits_ != 0;
91 }
92
94 constexpr bool operator==(const CompileContextSubscriptions&) const noexcept = default;
95
96 private:
102 using Bits = std::uint16_t;
103
104 static constexpr Bits mask(CompileContextKind kind) noexcept {
105 return static_cast<Bits>(Bits{1} << static_cast<unsigned>(kind));
106 }
107
108 Bits bits_ = 0;
109
110 static_assert(kCompileContextKindCount <= std::numeric_limits<Bits>::digits,
111 "CompileContextSubscriptions stores one bit per kind. Widen Bits before adding "
112 "a kind past the storage width.");
113};
114
124 public:
129 CompileContextView(const Project& project, ItemId sequence_id,
131
134 return subscriptions_;
135 }
136
139 const ChordScaleLane* chord_scale_lane() const noexcept;
140
143 const ChordScaleEvent* chord_scale_at(timebase::TickPosition position) const noexcept;
144
147 const DynamicsLane* dynamics_lane() const noexcept;
148
155 std::optional<float> dynamics_at(timebase::TickPosition position) const noexcept;
156
161 const GrooveTemplate* groove() const noexcept;
162
163 private:
164 const Sequence* sequence_ = nullptr;
165 CompileContextSubscriptions subscriptions_;
166};
167
169
170} // namespace pulp::timeline
Immutable chord/scale context lane owned by a sequence.
Definition model.hpp:386
The declared set of context kinds one content renderer reads.
Definition compile_context.hpp:67
constexpr bool reads(CompileContextKind kind) const noexcept
Returns whether kind is present in this set.
Definition compile_context.hpp:84
static constexpr CompileContextSubscriptions none() noexcept
Returns an empty subscription set.
Definition compile_context.hpp:73
constexpr bool operator==(const CompileContextSubscriptions &) const noexcept=default
Compares the complete subscribed-kind set.
constexpr bool any() const noexcept
Returns whether this set contains any context kind.
Definition compile_context.hpp:89
constexpr CompileContextSubscriptions & subscribe(CompileContextKind kind) noexcept
Adds kind to this set and returns this object for chaining.
Definition compile_context.hpp:78
constexpr CompileContextSubscriptions() noexcept=default
Constructs an empty subscription set.
const ChordScaleLane * chord_scale_lane() const noexcept
The sequence's chord/scale lane, or null when ChordScale was not declared or the sequence is not in t...
const DynamicsLane * dynamics_lane() const noexcept
The sequence's intensity lane, or null when Dynamics was not declared or the sequence is not in this ...
CompileContextView(const Project &project, ItemId sequence_id, CompileContextSubscriptions subscriptions) noexcept
Creates a borrowed view of sequence_id narrowed to subscriptions.
const GrooveTemplate * groove() const noexcept
The sequence's groove, or null when Groove was not declared or the sequence is not in this snapshot.
std::optional< float > dynamics_at(timebase::TickPosition position) const noexcept
The interpolated intensity at position, or empty when Dynamics was not declared, the lane is empty,...
const ChordScaleEvent * chord_scale_at(timebase::TickPosition position) const noexcept
The harmony in force at position, or null when ChordScale was not declared, the lane is empty,...
CompileContextSubscriptions subscriptions() const noexcept
Returns the context kinds this view permits callers to read.
Definition compile_context.hpp:133
Immutable intensity context lane owned by a sequence.
Definition model.hpp:452
Immutable sequence-owned swing, timing-offset, and accent context.
Definition model.hpp:596
Immutable root of a Timeline document and its monotonic identity domain.
Definition model.hpp:1079
Immutable identity-bearing arrangement with tracks, annotations, context, and launch scenes.
Definition model.hpp:692
CompileContextKind
A kind of timeline context a renderer's compile hook may read beyond its own clip's content.
Definition compile_context.hpp:46
constexpr std::size_t kCompileContextKindCount
Number of CompileContextKind values represented by the subscription bitset.
Definition compile_context.hpp:60
@ Dynamics
Sequence-owned intensity.
Definition compile_context.hpp:52
@ ChordScale
Definition compile_context.hpp:47
@ Groove
Definition compile_context.hpp:48
@ CrossTrackRhythm
Reserved, peer-edge. See the acyclicity note above.
Definition compile_context.hpp:54
@ EnsembleSkeleton
Reserved, peer-edge. See the acyclicity note above.
Definition compile_context.hpp:56
Definition beat_division.hpp:11
Definition program_compiler.hpp:18
STL namespace.
Harmonic statement in force from position until the next event.
Definition model.hpp:363
Nonzero monotonic identity for a Timeline-owned object.
Definition item_id.hpp:19