OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
forward_node.hpp
1#pragma once
2#include <ossia/dataflow/audio_port.hpp>
3#include <ossia/dataflow/graph_node.hpp>
4#include <ossia/dataflow/midi_port.hpp>
5#include <ossia/dataflow/port.hpp>
6namespace ossia::nodes
7{
8class forward_node : public ossia::nonowning_graph_node
9{
10public:
11 forward_node()
12 {
13 m_inlets.push_back(&audio_in);
14 // m_inlets.push_back(&midi_in);
15 m_outlets.push_back(&audio_out);
16 // m_outlets.push_back(&midi_out);
17 }
18
19 [[nodiscard]] std::string label() const noexcept override { return "forward_node"; }
20 void run(const token_request& t, exec_state_facade) noexcept override
21 {
22 // OPTIMIZEME : we copy the ins & outs of the token more
23 // than necessary
24 {
25 ossia::audio_port& i = *audio_in;
26 ossia::audio_port& o = *audio_out;
27 if(!audio_out.has_gain)
28 {
29 o = i;
30 }
31 else
32 {
33 switch(i.channels())
34 {
35 case 0:
36 return;
37
38 case 1:
39 process_audio_out_mono(i, audio_out);
40 break;
41
42 default:
43 process_audio_out_general(i, audio_out);
44 break;
45 }
46 }
47 }
48 // {
49 // auto i = midi_in.target<ossia::midi_port>();
50 // auto o = midi_out.target<ossia::midi_port>();
51 // o->messages = i->messages;
52 // }
53 }
54
55 ossia::audio_inlet audio_in;
56 // ossia::midi_inlet midi_in;
57 ossia::audio_outlet audio_out;
58 // ossia::midi_outlet midi_out;
59};
60
61class interval final : public forward_node
62{
63public:
64 using forward_node::forward_node;
65
66 ~interval()
67 {
68 if(m_inlets.size() == 4)
69 {
70 delete m_inlets[1];
71 delete m_inlets[2];
72 delete m_inlets[3];
73 m_inlets.resize(1);
74 }
75 }
76 [[nodiscard]] std::string label() const noexcept override { return "Interval"; }
77
78 void run(const token_request& t, exec_state_facade f) noexcept override
79 {
80 forward_node::run(t, f);
81 if(m_inlets.size() >= 4)
82 {
83 {
84 ossia::value_port& vp = *m_inlets[1]->target<ossia::value_port>();
85 if(auto& data = vp.get_data(); !data.empty())
86 {
87 tempo = ossia::convert<float>(data.back().value);
88 }
89 }
90 {
91 ossia::value_port& vp = *m_inlets[3]->target<ossia::value_port>();
92 if(auto& data = vp.get_data(); !data.empty())
93 {
94 float seek_ms = ossia::convert<float>(data.back().value);
95 seek = ossia::flicks_per_millisecond<double> * seek_ms;
96 }
97 }
98 }
99 }
100
101 static const constexpr float no_tempo = -1000.f;
102 float tempo{no_tempo};
103 int64_t seek{std::numeric_limits<int64_t>::min()};
104};
105class loop final : public forward_node
106{
107public:
108 using forward_node::forward_node;
109 [[nodiscard]] std::string label() const noexcept override { return "Loop"; }
110};
111class scenario final : public forward_node
112{
113public:
114 using forward_node::forward_node;
115 [[nodiscard]] std::string label() const noexcept override { return "Scenario"; }
116};
117}