Loading...
Searching...
No Matches
MicroMapping.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 <halp/layout.hpp>
8
9namespace Nodes::MicroMapping
10{
11struct Node
12{
13 halp_meta(name, "Micromap")
14 halp_meta(c_name, "MicroMapping")
15 halp_meta(category, "Control/Mappings")
16 halp_meta(
17 manual_url, "https://ossia.io/score-docs/processes/exprtk.html#exprtk-support")
18 halp_meta(author, "ossia score, ExprTK (Arash Partow)")
19 halp_meta(description, "Applies a math expression to an input.")
20 halp_meta(uuid, "25c64b87-a44a-4fed-9f60-0a48906fd3ec")
21
22 struct ins
23 {
24 struct : halp::val_port<"in", ossia::value>
25 {
26 // Messages to this port trigger a new computation cycle with updated timestamps
27 // FIXME not implemented yet
28 halp_flag(active_port);
29 void update(Node& self) { self.trigger = true; }
30 } port;
31 halp::lineedit<"Expression", "x / 127"> expr;
32 } inputs;
33
34 struct
35 {
36 value_out port{};
37 } outputs;
38
39 struct State
40 {
41 State()
42 {
43 xv.resize(1024);
44 pxv.resize(1024);
45 pov.resize(1024);
46 expr.add_vector("xv", xv);
47 expr.add_vector("pxv", pxv);
48 expr.add_vector("pov", pov);
49
50 expr.add_variable("x", x);
51 expr.add_variable("px", px);
52 expr.add_variable("po", po);
53
54 expr.add_variable("t", cur_time);
55 expr.add_variable("dt", cur_deltatime);
56 expr.add_variable("pos", cur_pos);
57 expr.add_constants();
58
59 expr.register_symbol_table();
60 }
61
62 std::vector<double> xv;
63 std::vector<double> pxv;
64 std::vector<double> pov;
65
66 double x{};
67 double px{};
68 double po{};
69
70 double cur_time{};
71 double cur_deltatime{};
72 double cur_pos{};
73
74 ossia::math_expression expr;
75 int64_t last_value_time{};
76
77 //bool ok = false;
78 } state;
79
80 halp::setup setup;
81 bool trigger{false};
82 void prepare(halp::setup s) { setup = s; }
83
84 using tick = halp::tick_flicks;
85
86 void operator()(const tick& tk)
87 {
88 if(!std::exchange(trigger, false))
89 return;
90 auto& self = this->state;
91 if(!self.expr.set_expression(this->inputs.expr))
92 return;
93
94 if(self.expr.has_variable("xv"))
96 inputs.port.value, outputs.port.call, tk, state);
97 else
99 inputs.port.value, outputs.port.call, tk, state);
100 }
101
102 struct ui
103 {
104 halp_meta(layout, halp::layouts::vbox)
105
106 struct : halp::control<&ins::expr>
107 {
108 halp_flag(dynamic_size);
109 } expr;
110 };
111};
112}
Utilities for OSSIA data structures.
Definition DeviceInterface.hpp:33
Definition MathMapping_generic.hpp:12
Definition MicroMapping.hpp:103
Definition MicroMapping.hpp:12