-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
RangeFilter.hpp
63 lines (58 loc) · 1.33 KB
/
RangeFilter.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#pragma once
#include <halp/controls.hpp>
#include <halp/mappers.hpp>
#include <halp/meta.hpp>
#include <ossia/detail/math.hpp>
namespace ao
{
/**
* @brief Filter undesired values of a sensor
*/
struct RangeFilter
{
public:
halp_meta(name, "Range Filter")
halp_meta(c_name, "range_filter")
halp_meta(category, "Control/Mappings")
halp_meta(author, "Jean-Michaël Celerier")
halp_meta(description, "Filter out values of an input outside of a numeric range")
halp_meta(
manual_url,
"https://ossia.io/score-docs/processes/mapping-utilities.html#range-filter")
halp_meta(uuid, "db16b5fa-e6b0-4f89-8210-225384dbc677")
halp_flag(cv);
halp_flag(stateless);
struct inputs_t
{
halp::spinbox_f32<"Min", halp::range{-1e6, 1e6, 0.}> min;
halp::spinbox_f32<"Max", halp::range{-1e6, 1e6, 1.}> max;
struct : halp::toggle<"Invert">
{
halp_meta(
description,
"Invert the filter operation: only let values outside the range go through.")
} invert;
} inputs;
struct
{
} outputs;
std::optional<float> operator()(float v) noexcept
{
if(inputs.invert)
{
if(v <= inputs.min || v >= inputs.max)
{
return v;
}
}
else
{
if(v >= inputs.min && v <= inputs.max)
{
return v;
}
}
return std::nullopt;
}
};
}