Loading...
Searching...
No Matches
AngleNode.hpp
1#pragma once
2#include <halp/callback.hpp>
3#include <halp/controls.hpp>
4#include <halp/meta.hpp>
5namespace Nodes
6{
8{
9 halp_meta(name, "Angle mapper")
10 halp_meta(c_name, "AngleMapper")
11 halp_meta(category, "Control/Mappings")
12 halp_meta(author, "ossia score")
13 halp_meta(
14 manual_url,
15 "https://ossia.io/score-docs/processes/mapping-utilities.html#angle-mapper")
16 halp_meta(description, "Map the variation of an angle")
17 halp_meta(uuid, "9b0e21ba-965a-4aa4-beeb-60cc5128c418")
18 halp_flag(time_independent);
19
20 struct
21 {
22 halp::val_port<"in", float> in;
23 } inputs;
24 struct
25 {
26 halp::callback<"out", float> out;
27 } outputs;
28
29 std::optional<float> prev_value;
30 void operator()()
31 {
32 // returns -1, 0, 1 to say if we're going backwards, staying equal, or
33 // going forward.
34 float val = inputs.in.value;
35 if(!prev_value)
36 {
37 prev_value = val;
38 return;
39 }
40 else
41 {
42 float output;
43
44 if(prev_value < val)
45 {
46 output = 1.f;
47 prev_value = val;
48 }
49 else if(prev_value > val)
50 {
51 output = -1.f;
52 prev_value = val;
53 }
54 else
55 {
56 output = 0.f;
57 }
58
59 outputs.out(output);
60 }
61 }
62};
63}
Definition AngleNode.hpp:8