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 
9 namespace Nodes::ArrayGenerator
10 {
11 struct 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)
38  {
39  expr.add_variable("i", instance);
40 
41  expr.add_variable("po", po);
42 
43  expr.add_variable("t", cur_time);
44  expr.add_variable("dt", cur_deltatime);
45  expr.add_variable("pos", cur_pos);
46  expr.add_constants();
47 
48  expr.register_symbol_table();
49  }
50  double instance;
51 
52  double po;
53 
54  ossia::math_expression expr;
55  };
56 
57  boost::container::static_vector<Expr, 1024> expressions;
58  double cur_time{};
59  double cur_deltatime{};
60  double cur_pos{};
61 
62  int64_t last_value_time{};
63  std::string last_expression;
64  } state;
65 
66  ossia::exec_state_facade ossia_state;
67 
68  using tick = halp::tick_flicks;
69  void operator()(const tick& tk)
70  {
71  GenericMathMapping<State>::run_polyphonic(
72  inputs.sz.value, outputs.port.call, inputs.expr.value, tk, state);
73  }
74 
75  struct ui
76  {
77  halp_meta(layout, halp::layouts::vbox)
78 
79  struct : halp::control<&ins::expr>
80  {
81  halp_flag(dynamic_size);
82  } expr;
83  halp::control<&ins::sz> sz;
84  };
85 };
86 }
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Definition: Arraygen.hpp:36
Definition: Arraygen.hpp:23
Definition: Arraygen.hpp:76
Definition: Arraygen.hpp:12