OSSIA
Open Scenario System for Interactive Application
step.hpp
1 #pragma once
2 #include <ossia/dataflow/graph_node.hpp>
3 #include <ossia/dataflow/port.hpp>
4 #include <ossia/detail/pod_vector.hpp>
5 
6 namespace ossia::nodes
7 {
8 class step final : public ossia::graph_node
9 {
10 public:
11  step() { m_outlets.push_back(new ossia::value_outlet); }
12 
13  ~step() override = default;
14 
15  void run(const ossia::token_request& t, ossia::exec_state_facade e) noexcept override
16  {
17  // We want to send a trigger for each value change that happened between
18  // last_t and now
19  if(t.forward())
20  {
21  auto& port = *m_outlets[0]->target<ossia::value_port>();
22  const int64_t d = dur.impl * e.samplesToModel();
23  int64_t quo = std::floor(double(t.date.impl) / d);
24  int64_t prev_step = d * quo;
25 
26  while(t.in_range(time_value{prev_step}))
27  {
28  port.write_value(
29  values[quo % values.size()],
30  t.to_physical_time_in_tick(prev_step, e.modelToSamples()));
31  prev_step += d;
32  quo++;
33  }
34  }
35  }
36  ossia::float_vector values;
37  ossia::time_value dur{};
38 
39  [[nodiscard]] std::string label() const noexcept override { return "Step"; }
40 };
41 }
The time_value class.
Definition: ossia/editor/scenario/time_value.hpp:28