OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
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
15namespace ossia::nodes
16{
39class automation final : public ossia::nonowning_graph_node
40{
41public:
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
52 void swap_behavior(ossia::behavior& b) noexcept { std::swap(m_drive, b); }
53
54 const ossia::behavior& behavior() const noexcept { return m_drive; }
55
56 void reset_drive() { m_drive.reset(); }
57
58private:
59 void run(const ossia::token_request& t, ossia::exec_state_facade e) noexcept override
60 {
61 if(!m_drive)
62 return;
63 const auto [tick_start, d] = e.timings(t);
64
65 ossia::value_port& vp = *value_out;
66 vp.write_value(
67 ossia::apply(
68 ossia::detail::compute_value_visitor{t.position(), ossia::val_type::FLOAT},
69 m_drive),
70 tick_start);
71 }
72
73 ossia::behavior m_drive;
74 ossia::value_outlet value_out;
75};
76
77class float_automation final : public ossia::nonowning_graph_node
78{
79public:
80 float_automation() { m_outlets.push_back(&value_out); }
81
82 ~float_automation() override = default;
83
84 std::string label() const noexcept override { return "automation (float)"; }
85
86 void set_behavior(ossia::curve<double, float> b) { m_drive = std::move(b); }
87
88 void reset_drive() { m_drive.reset(); }
89
90private:
91 void run(const ossia::token_request& t, ossia::exec_state_facade e) noexcept override
92 {
93 const auto [tick_start, d] = e.timings(t);
94
95 ossia::value_port& vp = *value_out;
96 vp.write_value(m_drive.value_at(t.position()), tick_start);
97 }
98
100 ossia::minmax_float_outlet value_out;
101};
102
103#if defined(OSSIA_SCENARIO_DATAFLOW)
104class automation_process final : public ossia::node_process
105{
106public:
107 using ossia::node_process::node_process;
108 void start() override
109 {
110 static_cast<ossia::nodes::automation*>(node.get())->reset_drive();
111 }
112};
113#endif
114}
The curve class.
Definition curve.hpp:59
The ossia::nodes::automation class.
Definition automation.hpp:40
void swap_behavior(ossia::behavior &b) noexcept
Definition automation.hpp:52