AngleNode.hpp
1 #pragma once
2 #include <Engine/Node/SimpleApi.hpp>
3 namespace Nodes
4 {
5 namespace Direction
6 {
7 struct Node
8 {
10  {
11  static const constexpr auto prettyName = "Angle mapper";
12  static const constexpr auto objectKey = "AngleMapper";
13  static const constexpr auto category = "Control/Mappings";
14  static const constexpr auto author = "ossia score";
15  static const constexpr auto kind = Process::ProcessCategory::Mapping;
16  static const constexpr auto description = "Map the variation of an angle";
17  static const constexpr auto tags = std::array<const char*, 0>{};
18  static const uuid_constexpr auto uuid
19  = make_uuid("9b0e21ba-965a-4aa4-beeb-60cc5128c418");
20 
21  static const constexpr value_in value_ins[]{value_in{"in", false}};
22  static const constexpr value_out value_outs[]{"out"};
23  };
24 
25  struct State
26  {
27  ossia::value prev_value{};
28  };
29 
30  using control_policy = ossia::safe_nodes::default_tick;
31  static void
32  run(const ossia::value_port& p1, ossia::value_port& p2, ossia::token_request,
33  ossia::exec_state_facade, State& self)
34  {
35  // returns -1, 0, 1 to say if we're going backwards, staying equal, or
36  // going forward.
37 
38  for(const auto& val : p1.get_data())
39  {
40  if(!self.prev_value.valid())
41  {
42  self.prev_value = val.value;
43  continue;
44  }
45  else
46  {
47  ossia::value output;
48 
49  if(self.prev_value < val.value)
50  {
51  output = 1;
52  self.prev_value = val.value;
53  }
54  else if(self.prev_value > val.value)
55  {
56  output = -1;
57  self.prev_value = val.value;
58  }
59  else
60  {
61  output = 0;
62  }
63 
64  p2.write_value(std::move(output), val.timestamp);
65  }
66  }
67  }
68 };
69 }
70 }
Utilities for OSSIA data structures.
Definition: DeviceInterface.hpp:33
Definition: SimpleApi.hpp:32
Definition: AngleNode.hpp:10
Definition: AngleNode.hpp:8