Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
host_surfaces.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <string>
5#include <string_view>
6
7namespace pulp::dataplane {
8
41 public:
42 virtual ~HostParamSurface() = default;
43
46 bool has_param(std::string_view key) {
47 assert_call_context("has_param");
48 return do_has_param(key);
49 }
50
53 double get_param(std::string_view key) {
54 assert_call_context("get_param");
55 return do_get_param(key);
56 }
57
60 void set_param(std::string_view key, double normalized) {
61 assert_call_context("set_param");
62 do_set_param(key, normalized);
63 }
64
65 void begin_gesture(std::string_view key) {
66 assert_call_context("begin_gesture");
68 }
69
70 void end_gesture(std::string_view key) {
71 assert_call_context("end_gesture");
72 do_end_gesture(key);
73 }
74
80 std::string param_display_text(std::string_view key, double normalized) {
81 assert_call_context("param_display_text");
82 return do_param_display_text(key, normalized);
83 }
84
107 int param_step_count(std::string_view key) {
108 assert_call_context("param_step_count");
109 return do_param_step_count(key);
110 }
111
112 protected:
113 virtual bool do_has_param(std::string_view key) = 0;
114 virtual double do_get_param(std::string_view key) = 0;
115 virtual void do_set_param(std::string_view key, double normalized) = 0;
116 virtual void do_begin_gesture(std::string_view key) = 0;
117 virtual void do_end_gesture(std::string_view key) = 0;
118 virtual std::string do_param_display_text(std::string_view key, double normalized) = 0;
119
123 virtual int do_param_step_count(std::string_view key) {
124 (void)key;
125 return 0;
126 }
127
128 private:
131 static void assert_call_context(const char* op);
132};
133
155inline double param_index_to_normalized(int index, int step_count) {
156 if (step_count <= 1)
157 return 0.0;
158 const int clamped = index < 0 ? 0 : (index > step_count - 1 ? step_count - 1 : index);
159 return static_cast<double>(clamped) / static_cast<double>(step_count - 1);
160}
161
166inline int param_normalized_to_index(double normalized, int step_count) {
167 if (step_count <= 1)
168 return 0;
169 const double clamped = normalized < 0.0 ? 0.0 : (normalized > 1.0 ? 1.0 : normalized);
170 return static_cast<int>(std::lround(clamped * static_cast<double>(step_count - 1)));
171}
172
181 public:
182 virtual ~HostActionSurface() = default;
183
184 bool send_host_action(std::string_view action, std::string_view args_json) {
185 assert_call_context("send_host_action");
186 return do_send_host_action(action, args_json);
187 }
188
189 protected:
190 virtual bool do_send_host_action(std::string_view action, std::string_view args_json) = 0;
191
192 private:
193 static void assert_call_context(const char* op);
194};
195
196} // namespace pulp::dataplane
A framework-agnostic host command channel.
Definition host_surfaces.hpp:180
bool send_host_action(std::string_view action, std::string_view args_json)
Definition host_surfaces.hpp:184
virtual ~HostActionSurface()=default
virtual bool do_send_host_action(std::string_view action, std::string_view args_json)=0
A framework-agnostic, native-view-facing runtime parameter accessor.
Definition host_surfaces.hpp:40
std::string param_display_text(std::string_view key, double normalized)
Host-formatted display of a normalized value, e.g.
Definition host_surfaces.hpp:80
virtual void do_end_gesture(std::string_view key)=0
virtual bool do_has_param(std::string_view key)=0
virtual double do_get_param(std::string_view key)=0
virtual void do_set_param(std::string_view key, double normalized)=0
virtual std::string do_param_display_text(std::string_view key, double normalized)=0
bool has_param(std::string_view key)
Live membership test — the single source of truth for "is this keybound right now".
Definition host_surfaces.hpp:46
int param_step_count(std::string_view key)
Number of distinct values the HOST's parameter exposes for key — the authoritative cardinality of a d...
Definition host_surfaces.hpp:107
void begin_gesture(std::string_view key)
Definition host_surfaces.hpp:65
virtual int do_param_step_count(std::string_view key)
Defaults to 0 ("continuous / no index domain") so a host surface implemented outside this repo keeps ...
Definition host_surfaces.hpp:123
void set_param(std::string_view key, double normalized)
Write a normalized [0, 1] value.
Definition host_surfaces.hpp:60
virtual ~HostParamSurface()=default
void end_gesture(std::string_view key)
Definition host_surfaces.hpp:70
double get_param(std::string_view key)
Current normalized [0, 1] value of key.
Definition host_surfaces.hpp:53
virtual void do_begin_gesture(std::string_view key)=0
Definition audio_bridge.hpp:9
double param_index_to_normalized(int index, int step_count)
Map a discrete parameter's value index to a normalized [0, 1] value.
Definition host_surfaces.hpp:155
int param_normalized_to_index(double normalized, int step_count)
Inverse of param_index_to_normalized: the nearest value index for a normalized [0,...
Definition host_surfaces.hpp:166