Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
modulation_matrix.hpp
Go to the documentation of this file.
1#pragma once
2
3// Modulation-matrix data model.
4//
5// Pure data layer — stores a set of source→destination modulation routes
6// with per-route depth / bipolar / curve. The canvas widget owns drag-connect,
7// depth sliders, and bipolar toggles elsewhere; this header keeps the data
8// model reusable by code paths that aren't UI (e.g. batch preset tools) and
9// lets the audio engine read routes without pulling in view/ headers.
10//
11// IDs are plugin-supplied opaque integers. By convention sources use
12// Processor parameter IDs or MPE expression tags, and destinations use
13// parameter IDs. The matrix does not mint or validate them.
14
15#include <cstddef>
16#include <cstdint>
17#include <optional>
18#include <vector>
19
20namespace pulp::view {
21
22using ModSourceId = uint32_t;
23using ModDestinationId = uint32_t;
24
25enum class ModCurve : uint8_t {
26 Linear = 0,
30 SCurve = 4,
31};
32
33struct ModRoute {
36 float depth = 0.0f;
37 bool bipolar = false;
39
40 bool operator==(const ModRoute& other) const {
41 return source == other.source
42 && destination == other.destination
43 && depth == other.depth
44 && bipolar == other.bipolar
45 && curve == other.curve;
46 }
47};
48
50public:
55 std::size_t add(const ModRoute& route);
56
58 void remove(std::size_t index);
59
63
66 std::optional<std::size_t> find(ModSourceId source,
67 ModDestinationId destination) const;
68
69 std::size_t size() const { return routes_.size(); }
70 bool empty() const { return routes_.empty(); }
71 void clear() { routes_.clear(); }
72
73 const std::vector<ModRoute>& routes() const { return routes_; }
74
78 std::vector<uint8_t> serialize() const;
79
82 bool deserialize(const uint8_t* data, std::size_t size);
83
84private:
85 std::vector<ModRoute> routes_;
86};
87
88} // namespace pulp::view
Definition modulation_matrix.hpp:49
void remove(std::size_t index)
Remove a route by index. No-op if out of range.
std::optional< std::size_t > find(ModSourceId source, ModDestinationId destination) const
Look up a route by (source, destination).
const std::vector< ModRoute > & routes() const
Definition modulation_matrix.hpp:73
bool empty() const
Definition modulation_matrix.hpp:70
bool deserialize(const uint8_t *data, std::size_t size)
Restore from a blob produced by serialize().
void remove_by_destination(ModDestinationId destination)
Remove all routes touching destination.
std::vector< uint8_t > serialize() const
Serialize to a compact binary blob (route count + routes in order).
void clear()
Definition modulation_matrix.hpp:71
std::size_t add(const ModRoute &route)
Add a route.
std::size_t size() const
Definition modulation_matrix.hpp:69
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
ModCurve
Definition modulation_matrix.hpp:25
@ Logarithmic
Definition modulation_matrix.hpp:28
@ Linear
Definition modulation_matrix.hpp:26
@ Quadratic
Definition modulation_matrix.hpp:29
@ SCurve
Definition modulation_matrix.hpp:30
@ Exponential
Definition modulation_matrix.hpp:27
uint32_t ModSourceId
Definition modulation_matrix.hpp:22
uint32_t ModDestinationId
Definition modulation_matrix.hpp:23
Definition modulation_matrix.hpp:33
ModDestinationId destination
Definition modulation_matrix.hpp:35
bool operator==(const ModRoute &other) const
Definition modulation_matrix.hpp:40
float depth
-1.0 .. 1.0 (bipolar sources) or 0.0..1.0
Definition modulation_matrix.hpp:36
bool bipolar
true: source is interpreted as -1..+1
Definition modulation_matrix.hpp:37
ModSourceId source
Definition modulation_matrix.hpp:34
ModCurve curve
Definition modulation_matrix.hpp:38