OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
simple_mapper.hpp
1#pragma once
2#include <ossia/detail/config.hpp>
3
4#include <ossia/dataflow/graph_node.hpp>
5#include <ossia/dataflow/port.hpp>
6#include <ossia/detail/optional.hpp>
9#include <ossia/editor/mapper/detail/mapper_visitor.hpp>
10namespace ossia
11{
12template <typename Y, typename Easing>
13struct value_mapping
14{
15 Y operator()(double ratio, Y start, Y end) const
16 {
17 return easing::ease{}(start, end, Easing{}(ratio));
18 }
19};
20}
21namespace ossia::nodes
22{
23class OSSIA_EXPORT simple_mapping final : public ossia::nonowning_graph_node
24{
25public:
26 simple_mapping()
27 {
28 m_inlets.push_back(&value_in);
29 m_inlets.push_back(&input_min);
30 m_inlets.push_back(&input_max);
31 m_inlets.push_back(&output_min);
32 m_inlets.push_back(&output_max);
33 m_inlets.push_back(&curve_in);
34 m_outlets.push_back(&value_out);
35 }
36
37 std::string label() const noexcept override { return "simple_mapping"; }
38
39 ~simple_mapping() override { }
40
41private:
42 void run(const ossia::token_request& t, ossia::exec_state_facade e) noexcept override
43 {
44 if(!m_drive)
45 return;
46
47 // TODO use correct unit / whatever ?
48 for(auto& tv : value_in.get_data())
49 {
50 if(tv.value.valid())
51 {
52 auto v
53 = ossia::apply(ossia::detail::mapper_compute_visitor{}, tv.value, m_drive.v);
54
55 op.write_value(std::move(v), tv.timestamp);
56 }
57 }
58 }
59
60 ossia::behavior m_drive;
61
62 ossia::value_inlet value_in;
63 ossia::value_inlet input_min;
64 ossia::value_inlet input_max;
65 ossia::value_inlet output_min;
66 ossia::value_inlet output_max;
67 ossia::value_inlet curve_kind;
68
69 ossia::value_outlet value_out;
70
71 using map_func
72 = float (*)(float in, float min_in, float max_in, float min_out, float max_out);
73 ossia::flat_map<std::string, map_func> m_funcs;
74};
75}
Definition git_info.h:7