Loading...
Searching...
No Matches
Arraygen.hpp
1#pragma once
2#include <Fx/MathMapping_generic.hpp>
3#include <Fx/Types.hpp>
4
5#include <boost/container/static_vector.hpp>
6
7#include <halp/layout.hpp>
8
9namespace Nodes::ArrayGenerator
10{
11struct Node
12{
13 halp_meta(name, "Arraygen")
14 halp_meta(c_name, "ArrayGenerator")
15 halp_meta(category, "Control/Generators")
16 halp_meta(
17 manual_url, "https://ossia.io/score-docs/processes/exprtk.html#array-handling")
18 halp_meta(author, "ossia score, ExprTK (Arash Partow)")
19 halp_meta(description, "Applies a math expression to each member of an input.");
20 halp_meta(uuid, "cf3df02f-a563-4e92-a739-b321d3a84252");
21
22 struct ins
23 {
24 halp::lineedit<"Expression", "i"> expr;
25 halp::spinbox_i32<"Size", halp::irange{0, 1024, 12}> sz;
26 } inputs;
27
28 struct
29 {
30 value_out port{};
31 } outputs;
32
33 struct State
34 {
35 struct Expr
36 {
37 void init(double& cur_time, double& cur_deltatime, double& cur_pos, double& count)
38 {
39 expr.add_variable("i", instance);
40 expr.add_variable("n", count);
41
42 expr.add_variable("po", po);
43
44 expr.add_variable("t", cur_time);
45 expr.add_variable("dt", cur_deltatime);
46 expr.add_variable("pos", cur_pos);
47 expr.add_constants();
48
49 expr.register_symbol_table();
50 }
51 double instance;
52
53 double po;
54
55 bool initialized{};
56
57 ossia::math_expression expr;
58 };
59
60 boost::container::static_vector<Expr, 1024> expressions;
61 double count{};
62 double cur_time{};
63 double cur_deltatime{};
64 double cur_pos{};
65
66 int64_t last_value_time{};
67 std::string last_expression;
68 bool last_expression_ok{};
69 } state;
70
71 ossia::exec_state_facade ossia_state;
72
73 using tick = halp::tick_flicks;
74 void operator()(const tick& tk)
75 {
76 GenericMathMapping<State>::run_polyphonic(
77 inputs.sz.value, outputs.port.call, inputs.expr.value, tk, state);
78 }
79
80 struct ui
81 {
82 halp_meta(layout, halp::layouts::vbox)
83
84 struct : halp::control<&ins::expr>
85 {
86 halp_flag(dynamic_size);
87 } expr;
88 halp::control<&ins::sz> sz;
89 };
90};
91}
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:35
Definition Arraygen.hpp:23
Definition Arraygen.hpp:81
Definition Arraygen.hpp:12