OSSIA
Open Scenario System for Interactive Application
automation.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
4 #include <ossia/dataflow/control_inlets.hpp>
5 #include <ossia/dataflow/graph_node.hpp>
6 #include <ossia/dataflow/node_process.hpp>
7 #include <ossia/dataflow/port.hpp>
8 #include <ossia/editor/automation/curve_value_visitor.hpp>
10 
15 namespace ossia::nodes
16 {
39 class automation final : public ossia::nonowning_graph_node
40 {
41 public:
42  automation() { m_outlets.push_back(&value_out); }
43 
44  ~automation() override = default;
45 
46  [[nodiscard]] std::string label() const noexcept override { return "automation"; }
47 
48  void set_behavior(const ossia::behavior& b) { m_drive = b; }
49 
50  void reset_drive() { m_drive.reset(); }
51 
52 private:
53  void run(const ossia::token_request& t, ossia::exec_state_facade e) noexcept override
54  {
55  if(!m_drive)
56  return;
57  const auto [tick_start, d] = e.timings(t);
58 
59  ossia::value_port& vp = *value_out;
60  vp.write_value(
61  ossia::apply(
62  ossia::detail::compute_value_visitor{t.position(), ossia::val_type::FLOAT},
63  m_drive),
64  tick_start);
65  }
66 
67  ossia::behavior m_drive;
68  ossia::value_outlet value_out;
69 };
70 
71 class float_automation final : public ossia::nonowning_graph_node
72 {
73 public:
74  float_automation() { m_outlets.push_back(&value_out); }
75 
76  ~float_automation() override = default;
77 
78  std::string label() const noexcept override { return "automation (float)"; }
79 
80  void set_behavior(ossia::curve<double, float> b) { m_drive = std::move(b); }
81 
82  void reset_drive() { m_drive.reset(); }
83 
84 private:
85  void run(const ossia::token_request& t, ossia::exec_state_facade e) noexcept override
86  {
87  const auto [tick_start, d] = e.timings(t);
88 
89  ossia::value_port& vp = *value_out;
90  vp.write_value(m_drive.value_at(t.position()), tick_start);
91  }
92 
93  ossia::curve<double, float> m_drive;
94  ossia::minmax_float_outlet value_out;
95 };
96 
97 #if defined(OSSIA_SCENARIO_DATAFLOW)
98 class automation_process final : public ossia::node_process
99 {
100 public:
101  using ossia::node_process::node_process;
102  void start() override
103  {
104  static_cast<ossia::nodes::automation*>(node.get())->reset_drive();
105  }
106 };
107 #endif
108 }
The ossia::nodes::automation class.
Definition: automation.hpp:40