2 #include <ossia/network/value/value_conversion.hpp>
4 #include <halp/callback.hpp>
5 #include <halp/controls.hpp>
6 #include <halp/meta.hpp>
7 #include <halp/sample_accurate_controls.hpp>
15 halp_meta(name,
"Midi hi-res input")
16 halp_meta(c_name,
"MidiHiResIn")
17 halp_meta(category,
"Midi")
18 halp_meta(author,
"ossia score")
20 manual_url,
"https://ossia.io/score-docs/processes/midi-utilities.html#midi-hires")
21 halp_meta(description,
"Creates a float from MSB/LSB CCs")
22 halp_meta(uuid,
"28ca746e-c304-4ba6-bd5b-78934a1dec55")
27 halp::accurate<halp::val_port<
"msb",
int>> msb;
28 halp::accurate<halp::val_port<
"lsb",
int>> lsb;
32 halp::callback<
"int",
int> i;
33 halp::callback<
"float",
float> f;
38 auto& msbs = inputs.msb.values;
39 auto& lsbs = inputs.lsb.values;
40 if(msbs.empty() && lsbs.empty())
43 const auto m = msbs.empty() ? 0 : ossia::convert<int>(msbs.rbegin()->second);
44 const auto l = lsbs.empty() ? 0 : ossia::convert<int>(lsbs.rbegin()->second);
46 outputs.i(m * 127 + l);
47 outputs.f(
double(m * 127 + l) / (128. * 128.));
53 halp_meta(name,
"Midi hi-res output")
54 halp_meta(c_name,
"MidiHiResOut")
55 halp_meta(category,
"Midi")
56 halp_meta(manual_url,
"https://ossia.io/score-docs/processes/javascript.html#midi")
57 halp_meta(author,
"ossia score")
58 halp_meta(description,
"Creates MIDI LSB/MSB from a 0-16384 or 0-1 value")
59 halp_meta(uuid,
"d6f5173b-b823-4571-b31f-660832b6132b")
63 halp::accurate<halp::val_port<
"int",
int>> i;
64 halp::accurate<halp::val_port<
"float",
float>> f;
68 halp::accurate<halp::val_port<
"msb",
int>> msb;
69 halp::accurate<halp::val_port<
"lsb",
int>> lsb;
74 for(
auto& [val, t] : inputs.i.values)
76 const int32_t v = ossia::convert<int>(val);
77 const int32_t m = ossia::clamp(int32_t(v / 127), 0, 127);
78 const int32_t l = ossia::clamp(int32_t(v - m * 127), 0, 127);
80 outputs.msb.values.emplace(t, m);
81 outputs.lsb.values.emplace(t, l);
84 for(
auto& [val, t] : inputs.f.values)
86 const float v = ossia::convert<float>(val) * (128. * 128.);
87 const int32_t m = ossia::clamp(int32_t(v / 127.), 0, 127);
88 const int32_t l = ossia::clamp(int32_t(v - m * 127), 0, 127);
90 outputs.msb.values.emplace(t, m);
91 outputs.lsb.values.emplace(t, l);
Definition: MidiHiRes.hpp:52