score
Home
Classes
Namespaces
Files
Loading...
Searching...
No Matches
Arraymap.hpp
1
#pragma once
2
#include <Fx/MathMapping_generic.hpp>
3
#include <Fx/Types.hpp>
4
5
#include <ossia/dataflow/value_port.hpp>
6
7
#include <boost/container/static_vector.hpp>
8
9
#include <halp/layout.hpp>
10
11
namespace
Nodes::ArrayMapping
12
{
13
struct
Node
14
{
15
halp_meta(name,
"Arraymap"
)
16
halp_meta(c_name,
"ArrayMapping"
)
17
halp_meta(category,
"Control/Mappings"
)
18
halp_meta(
19
manual_url,
"https://ossia.io/score-docs/processes/exprtk.html#array-handling"
)
20
halp_meta(author,
"ossia score, ExprTK (Arash Partow)"
)
21
halp_meta(description,
"Applies a math expression to each member of an input."
);
22
halp_meta(uuid,
"1fe9c806-b601-4ee0-9fbb-0ab817c4dd87"
);
23
24
struct
ins
25
{
26
struct : halp::val_port<
"in"
, ossia::value>
27
{
28
// Messages to this port trigger a new computation cycle with updated timestamps
29
halp_flag(active_port);
30
void
update(
Node
& self) { self.trigger =
true
; }
31
} port;
32
halp::lineedit<
"Expression"
,
"x"
> expr;
33
} inputs;
34
35
struct
36
{
37
value_out port{};
38
} outputs;
39
40
struct
State
41
{
42
struct
Expr
43
{
44
void
init(
double
& cur_time,
double
& cur_deltatime,
double
& cur_pos,
double
& count)
45
{
46
expr.add_variable(
"i"
, instance);
47
expr.add_variable(
"n"
, count);
48
49
expr.add_variable(
"x"
, x);
50
expr.add_variable(
"px"
, px);
51
expr.add_variable(
"po"
, po);
52
53
expr.add_variable(
"t"
, cur_time);
54
expr.add_variable(
"dt"
, cur_deltatime);
55
expr.add_variable(
"pos"
, cur_pos);
56
expr.add_constants();
57
58
expr.register_symbol_table();
59
}
60
double
instance;
61
62
double
x;
63
double
px;
64
double
po;
65
66
ossia::math_expression expr;
67
};
68
69
boost::container::static_vector<Expr, 1024> expressions;
70
double
count{};
71
double
cur_time{};
72
double
cur_deltatime{};
73
double
cur_pos{};
74
75
int64_t last_value_time{};
76
std::string last_expression;
77
} state;
78
bool
trigger{
false
};
79
80
using
tick = halp::tick_flicks;
81
82
void
operator()(
const
tick& tk)
83
{
84
if
(!std::exchange(trigger,
false
))
85
return
;
86
GenericMathMapping<State>::run_polyphonic(
87
inputs.port.value, outputs.port.call, inputs.expr.value, tk, state);
88
}
89
90
struct
ui
91
{
92
halp_meta(layout, halp::layouts::vbox)
93
94
struct : halp::control<&ins::expr>
95
{
96
halp_flag(dynamic_size);
97
} expr;
98
};
99
};
100
}
State
Utilities for OSSIA data structures.
Definition
DeviceInterface.hpp:33
Nodes::ArrayMapping::Node::State::Expr
Definition
Arraymap.hpp:43
Nodes::ArrayMapping::Node::ins
Definition
Arraymap.hpp:25
Nodes::ArrayMapping::Node::ui
Definition
Arraymap.hpp:91
Nodes::ArrayMapping::Node
Definition
Arraymap.hpp:14