diff --git a/examples/Raw/Shell.hpp b/examples/Raw/Shell.hpp new file mode 100644 index 00000000..64000c9b --- /dev/null +++ b/examples/Raw/Shell.hpp @@ -0,0 +1,58 @@ +#pragma once + +/* SPDX-License-Identifier: GPL-3.0-or-later */ + +#include +#include +#include +namespace examples +{ +struct Shell +{ + static consteval auto name() { return "Shell command"; } + static consteval auto c_name() { return "avnd_shell"; } + static consteval auto category() { return "Script"; } + static consteval auto uuid() { return "7e4ae744-1825-4f1c-9fc9-675e41f316bc"; } + + // This tag is an indication that the operator() should only called on + // the first tick, not on every tick + enum + { + single_exec + }; + + struct + { + struct + { + static constexpr auto name() { return "Script"; } + static constexpr auto language() { return "shell"; } + enum widget + { + textedit + }; + + struct range + { + const std::string_view init = "#!/bin/bash\n"; + }; + std::string value; + } command; + } inputs; + + struct + { + } outputs; + + void operator()() { worker.request(std::move(inputs.command.value)); } + + struct worker + { + std::function request; + static void work(std::string&& s) + { + std::thread{[code = std::move(s)] { ::system(code.c_str()); }}.detach(); + } + } worker; +}; +} diff --git a/include/avnd/binding/ossia/data_node.hpp b/include/avnd/binding/ossia/data_node.hpp index 6778f421..feaace2d 100644 --- a/include/avnd/binding/ossia/data_node.hpp +++ b/include/avnd/binding/ossia/data_node.hpp @@ -1,5 +1,7 @@ #pragma once #include +#include + namespace oscr { @@ -10,11 +12,21 @@ class safe_node : public safe_node_base> public: using safe_node_base>::safe_node_base; + bool exec_once{}; + constexpr bool scan_audio_input_channels() { return false; } OSSIA_MAXIMUM_INLINE void run(const ossia::token_request& tk, ossia::exec_state_facade st) noexcept override { + if constexpr(avnd::tag_single_exec) + { + if(std::exchange(exec_once, true)) + { + return; + } + } + auto [start, frames] = st.timings(tk); if(!this->prepare_run(tk, start, frames)) diff --git a/include/avnd/concepts/temporality.hpp b/include/avnd/concepts/temporality.hpp new file mode 100644 index 00000000..31040f2e --- /dev/null +++ b/include/avnd/concepts/temporality.hpp @@ -0,0 +1,18 @@ +#pragma once + +/* SPDX-License-Identifier: GPL-3.0-or-later OR BSL-1.0 OR CC0-1.0 OR CC-PDCC OR 0BSD */ + +#include +#include +#include + +namespace avnd +{ +/** + * @brief single_exec tag: the 'process' method should only be called once + * per execution. + * + * Example: in ossia, this means that the processor can be assigned to a state. + */ +AVND_DEFINE_TAG(single_exec) +}