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  } port;
31  halp::lineedit<"Expression", "x"> expr;
32  } inputs;
33 
34  struct
35  {
36  value_out port{};
37  } outputs;
38 
39  struct State
40  {
41  struct Expr
42  {
43  void init(double& cur_time, double& cur_deltatime, double& cur_pos)
44  {
45  expr.add_variable("i", instance);
46 
47  expr.add_variable("x", x);
48  expr.add_variable("px", px);
49  expr.add_variable("po", po);
50 
51  expr.add_variable("t", cur_time);
52  expr.add_variable("dt", cur_deltatime);
53  expr.add_variable("pos", cur_pos);
54  expr.add_constants();
55 
56  expr.register_symbol_table();
57  }
58  double instance;
59 
60  double x;
61  double px;
62  double po;
63 
64  ossia::math_expression expr;
65  };
66 
67  boost::container::static_vector<Expr, 1024> expressions;
68  double cur_time{};
69  double cur_deltatime{};
70  double cur_pos{};
71 
72  int64_t last_value_time{};
73  std::string last_expression;
74  } state;
75 
76  using tick = halp::tick_flicks;
77 
78  void operator()(const tick& tk)
79  {
80  GenericMathMapping<State>::run_polyphonic(
81  inputs.port.value, outputs.port.call, inputs.expr.value, tk, state);
82  }
83 
84  struct ui
85  {
86  halp_meta(layout, halp::layouts::vbox)
87 
88  struct : halp::control<&ins::expr>
89  {
90  halp_flag(dynamic_size);
91  } expr;
92  };
93 };
94 }
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Definition: Arraymap.hpp:42
Definition: Arraymap.hpp:25
Definition: Arraymap.hpp:85
Definition: Arraymap.hpp:14