3 #include <JS/Executor/JSAPIWrapper.hpp>
4 #include <JS/Qml/Metatypes.hpp>
5 #include <JS/Qml/QmlObjects.hpp>
6 #include <JS/Qml/ValueTypes.Qt6.hpp>
8 #include <ossia/dataflow/graph/graph_interface.hpp>
9 #include <ossia/dataflow/graph_edge.hpp>
10 #include <ossia/dataflow/graph_edge_helpers.hpp>
11 #include <ossia/dataflow/graph_node.hpp>
12 #include <ossia/dataflow/node_process.hpp>
13 #include <ossia/dataflow/port.hpp>
14 #include <ossia/detail/logger.hpp>
15 #include <ossia/detail/ssize.hpp>
16 #include <ossia/editor/scenario/time_interval.hpp>
17 #include <ossia/editor/state/message.hpp>
18 #include <ossia/editor/state/state.hpp>
20 #include <ossia-qt/invoke.hpp>
21 #include <ossia-qt/js_utilities.hpp>
22 #include <ossia-qt/time.hpp>
23 #include <ossia-qt/token_request.hpp>
26 class qml_engine_functions;
31 class js_node final :
public ossia::graph_node
34 explicit js_node(ossia::execution_state& st);
37 [[nodiscard]] std::string label()
const noexcept
override {
return "javascript"; }
39 void run(
const ossia::token_request& t, ossia::exec_state_facade) noexcept
override;
40 void setupComponent();
41 void setScript(
const QString& val);
43 ossia::execution_state& m_st;
45 QQmlEngine* m_engine{};
46 std::vector<Inlet*> m_jsInlets;
47 std::vector<std::pair<ControlInlet*, ossia::inlet_ptr>> m_ctrlInlets;
48 std::vector<std::pair<Impulse*, ossia::inlet_ptr>> m_impulseInlets;
49 std::vector<std::pair<ValueInlet*, ossia::inlet_ptr>> m_valInlets;
50 std::vector<std::pair<ValueOutlet*, ossia::outlet_ptr>> m_valOutlets;
51 std::vector<std::pair<AudioInlet*, ossia::inlet_ptr>> m_audInlets;
52 std::vector<std::pair<AudioOutlet*, ossia::outlet_ptr>> m_audOutlets;
53 std::vector<std::pair<MidiInlet*, ossia::inlet_ptr>> m_midInlets;
54 std::vector<std::pair<MidiOutlet*, ossia::outlet_ptr>> m_midOutlets;
55 JS::Script* m_object{};
56 ossia::qt::qml_engine_functions* m_execFuncs{};
57 QJSValueList m_tickCall;
58 std::size_t m_gcIndex{};
65 void setControl(std::size_t index,
const QVariant& val)
67 if(index > m_jsInlets.size())
69 if(
auto v = qobject_cast<ValueInlet*>(m_jsInlets[index]))
71 else if(
auto v = qobject_cast<ControlInlet*>(m_jsInlets[index]))
74 void impulse(std::size_t index)
76 if(index > m_jsInlets.size())
78 if(
auto v = qobject_cast<Impulse*>(m_jsInlets[index]))
85 using node_process::node_process;
87 void start()
override { js().triggerStart =
true; }
88 void stop()
override { js().triggerStop =
true; }
89 void pause()
override { js().triggerPause =
true; }
90 void resume()
override { js().triggerResume =
true; }
91 void transport_impl(ossia::time_value date)
override
93 QMetaObject::invokeMethod(
94 js().m_object,
"transport", Qt::DirectConnection,
95 Q_ARG(QVariant,
double(date.impl)));
97 void offset_impl(ossia::time_value date)
override
99 QMetaObject::invokeMethod(
100 js().m_object,
"offset", Qt::DirectConnection,
101 Q_ARG(QVariant,
double(date.impl)));
Definition: CPUNode.hpp:32
Definition: CPUNode.hpp:84